aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2013-09-30 17:54:22 +0000
committerTarmac <Unknown>2013-09-30 17:54:22 +0000
commit91c06e1edbe3f7f25aaad1905733ae690e4fdf26 (patch)
tree4c9f5a92b354439079ed0db68f926024dbb8a226
parentd7d198149d259d80d2f4e9e0de36fbd41fcbe9bb (diff)
parent86719275d89bb2c48d1cc9451f6add1918ee0f75 (diff)
downloadayatana-indicator-sound-91c06e1edbe3f7f25aaad1905733ae690e4fdf26.tar.gz
ayatana-indicator-sound-91c06e1edbe3f7f25aaad1905733ae690e4fdf26.tar.bz2
ayatana-indicator-sound-91c06e1edbe3f7f25aaad1905733ae690e4fdf26.zip
Reconnect when pulseaudio terminates (or crashes). Fixes: https://bugs.launchpad.net/bugs/1231942.
Approved by Ted Gould, PS Jenkins bot.
-rw-r--r--src/volume-control.vala65
1 files changed, 40 insertions, 25 deletions
diff --git a/src/volume-control.vala b/src/volume-control.vala
index 9475f53..18c407f 100644
--- a/src/volume-control.vala
+++ b/src/volume-control.vala
@@ -46,21 +46,7 @@ public class VolumeControl : Object
if (loop == null)
loop = new PulseAudio.GLibMainLoop ();
- var props = new Proplist ();
- props.sets (Proplist.PROP_APPLICATION_NAME, "Ubuntu Audio Settings");
- props.sets (Proplist.PROP_APPLICATION_ID, "com.canonical.settings.sound");
- props.sets (Proplist.PROP_APPLICATION_ICON_NAME, "multimedia-volume-control");
- props.sets (Proplist.PROP_APPLICATION_VERSION, "0.1");
-
- context = new PulseAudio.Context (loop.get_api(), null, props);
-
- context.set_state_callback (context_state_callback);
-
- if (context.connect(null, Context.Flags.NOFAIL, null) < 0)
- {
- warning( "pa_context_connect() failed: %s\n", PulseAudio.strerror(context.errno()));
- return;
- }
+ this.reconnect_to_pulse ();
}
/* PulseAudio logic*/
@@ -153,18 +139,47 @@ public class VolumeControl : Object
private void context_state_callback (Context c)
{
- if (c.get_state () == Context.State.READY)
- {
- c.subscribe (PulseAudio.Context.SubscriptionMask.SINK |
- PulseAudio.Context.SubscriptionMask.SOURCE |
- PulseAudio.Context.SubscriptionMask.SOURCE_OUTPUT);
- c.set_subscribe_callback (context_events_cb);
- update_sink ();
- update_source ();
- this.ready = true;
+ switch (c.get_state ()) {
+ case Context.State.READY:
+ c.subscribe (PulseAudio.Context.SubscriptionMask.SINK |
+ PulseAudio.Context.SubscriptionMask.SOURCE |
+ PulseAudio.Context.SubscriptionMask.SOURCE_OUTPUT);
+ c.set_subscribe_callback (context_events_cb);
+ update_sink ();
+ update_source ();
+ this.ready = true;
+ break;
+
+ case Context.State.FAILED:
+ case Context.State.TERMINATED:
+ this.reconnect_to_pulse ();
+ break;
+
+ default:
+ this.ready = false;
+ break;
}
- else
+ }
+
+ void reconnect_to_pulse ()
+ {
+ if (this.ready) {
+ this.context.disconnect ();
+ this.context = null;
this.ready = false;
+ }
+
+ var props = new Proplist ();
+ props.sets (Proplist.PROP_APPLICATION_NAME, "Ubuntu Audio Settings");
+ props.sets (Proplist.PROP_APPLICATION_ID, "com.canonical.settings.sound");
+ props.sets (Proplist.PROP_APPLICATION_ICON_NAME, "multimedia-volume-control");
+ props.sets (Proplist.PROP_APPLICATION_VERSION, "0.1");
+
+ this.context = new PulseAudio.Context (loop.get_api(), null, props);
+ this.context.set_state_callback (context_state_callback);
+
+ if (context.connect(null, Context.Flags.NOFAIL, null) < 0)
+ warning( "pa_context_connect() failed: %s\n", PulseAudio.strerror(context.errno()));
}
/* Mute operations */