aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2013-10-28 17:43:01 +0000
committerTarmac <Unknown>2013-10-28 17:43:01 +0000
commit712c11842d70600af595b706a03a77df628d981d (patch)
tree2b53b8c903a3072214bc43aba97032e40ca9addf /src
parentdd48ee78afe56d2db5fa22de62a4808eb5fc8276 (diff)
parentf20f87c277dc55a99cace2a3e80797d796265f51 (diff)
downloadayatana-indicator-sound-712c11842d70600af595b706a03a77df628d981d.tar.gz
ayatana-indicator-sound-712c11842d70600af595b706a03a77df628d981d.tar.bz2
ayatana-indicator-sound-712c11842d70600af595b706a03a77df628d981d.zip
VolumeControl: don't pass vala closures into libpulse
Libpulse's vala bindings don't specify that callbacks passed into some of its functions (e.g., get_server_info) can be called after the function returns. Vala thus frees closure data after these functions return. This can't easily be fixed in the bindings, because libpulse doesn't provide variants of these functions with destroy_notifies. This patch works around this problem by only passing non-closure functions into libpulse. Fixes: https://bugs.launchpad.net/bugs/1244386. Approved by Charles Kerr, PS Jenkins bot.
Diffstat (limited to 'src')
-rw-r--r--src/volume-control.vala44
1 files changed, 29 insertions, 15 deletions
diff --git a/src/volume-control.vala b/src/volume-control.vala
index 4ca9537..c6db38c 100644
--- a/src/volume-control.vala
+++ b/src/volume-control.vala
@@ -128,12 +128,14 @@ public class VolumeControl : Object
context.get_server_info (server_info_cb_for_props);
}
+ private void update_source_get_server_info_cb (PulseAudio.Context c, PulseAudio.ServerInfo? i) {
+ if (i != null)
+ context.get_source_info_by_name (i.default_source_name, source_info_cb);
+ }
+
private void update_source ()
{
- context.get_server_info ( (c, i) => {
- if (i != null)
- context.get_source_info_by_name (i.default_source_name, source_info_cb);
- });
+ context.get_server_info (update_source_get_server_info_cb);
}
private void source_output_info_cb (Context c, SourceOutputInfo? i, int eol)
@@ -199,15 +201,25 @@ public class VolumeControl : Object
warning( "pa_context_connect() failed: %s\n", PulseAudio.strerror(context.errno()));
}
+ void sink_info_list_callback_set_mute (PulseAudio.Context context, PulseAudio.SinkInfo? sink, int eol) {
+ if (sink != null)
+ context.set_sink_mute_by_index (sink.index, true, null);
+ }
+
+ void sink_info_list_callback_unset_mute (PulseAudio.Context context, PulseAudio.SinkInfo? sink, int eol) {
+ if (sink != null)
+ context.set_sink_mute_by_index (sink.index, false, null);
+ }
+
/* Mute operations */
public void set_mute (bool mute)
{
return_if_fail (context.get_state () == Context.State.READY);
- context.get_sink_info_list ((context, sink, eol) => {
- if (sink != null)
- context.set_sink_mute_by_index (sink.index, mute, null);
- });
+ if (mute)
+ context.get_sink_info_list (sink_info_list_callback_set_mute);
+ else
+ context.get_sink_info_list (sink_info_list_callback_unset_mute);
}
public void toggle_mute ()
@@ -277,19 +289,21 @@ public class VolumeControl : Object
mic_volume_changed (_mic_volume);
}
+ void set_mic_volume_get_server_info_cb (PulseAudio.Context c, PulseAudio.ServerInfo? i) {
+ if (i != null) {
+ unowned CVolume cvol = CVolume ();
+ cvol = vol_set (cvol, 1, double_to_volume (_mic_volume));
+ c.set_source_volume_by_name (i.default_source_name, cvol, set_mic_volume_success_cb);
+ }
+ }
+
public void set_mic_volume (double volume)
{
return_if_fail (context.get_state () == Context.State.READY);
_mic_volume = volume;
- context.get_server_info ( (c, i) => {
- if (i != null) {
- unowned CVolume cvol = CVolume ();
- cvol = vol_set (cvol, 1, double_to_volume (_mic_volume));
- c.set_source_volume_by_name (i.default_source_name, cvol, set_mic_volume_success_cb);
- }
- });
+ context.get_server_info (set_mic_volume_get_server_info_cb);
}
public double get_volume ()