aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2013-10-26 20:40:57 -0400
committerLars Uebernickel <lars.uebernickel@canonical.com>2013-10-26 20:40:57 -0400
commitf20f87c277dc55a99cace2a3e80797d796265f51 (patch)
tree322e99a5103ef4f54da0e5a54197fb640a7d2645
parent81c82dca758bf30134e2483dfa897de0baecf647 (diff)
downloadayatana-indicator-sound-f20f87c277dc55a99cace2a3e80797d796265f51.tar.gz
ayatana-indicator-sound-f20f87c277dc55a99cace2a3e80797d796265f51.tar.bz2
ayatana-indicator-sound-f20f87c277dc55a99cace2a3e80797d796265f51.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.
-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 18c407f..e50e8e6 100644
--- a/src/volume-control.vala
+++ b/src/volume-control.vala
@@ -119,12 +119,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)
@@ -182,15 +184,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 ()
@@ -260,19 +272,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 ()