[gnome-control-center] sound: Move running input streams when default source is changed



commit fe69f4f1355ae7816d601bb11c155904d9dd86fe
Author: David Henningsson <david henningsson canonical com>
Date:   Fri Apr 27 11:15:52 2012 +0200

    sound: Move running input streams when default source is changed
    
    When changing the default input source, active recording streams
    are not moved. This patch will fix that, which will make input
    and output behaviour consistent.
    
    As a bonus, it will not destroy pulseaudio's input database when
    changing default sink anymore.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=674925

 panels/sound/gvc-mixer-control.c |   58 ++++++++++++++++++++++++++++++++------
 1 files changed, 49 insertions(+), 9 deletions(-)
---
diff --git a/panels/sound/gvc-mixer-control.c b/panels/sound/gvc-mixer-control.c
index 3568386..0fcb107 100644
--- a/panels/sound/gvc-mixer-control.c
+++ b/panels/sound/gvc-mixer-control.c
@@ -80,7 +80,8 @@ struct GvcMixerControlPrivate
         GHashTable       *clients;
         GHashTable       *cards;
 
-        GvcMixerStream   *new_default_stream; /* new default stream, used in gvc_mixer_control_set_default_sink () */
+        GvcMixerStream   *new_default_sink_stream; /* new default sink stream, used in gvc_mixer_control_set_default_sink () */
+        GvcMixerStream   *new_default_source_stream; /* new default source stream, used in gvc_mixer_control_set_default_source () */
 
         GvcMixerControlState state;
 };
@@ -133,15 +134,15 @@ gvc_mixer_control_get_event_sink_input (GvcMixerControl *control)
 
 static void
 gvc_mixer_control_stream_restore_cb (pa_context *c,
+				     GvcMixerStream *new_stream,
                                      const pa_ext_stream_restore_info *info,
                                      int eol,
-                                     void *userdata)
+                                     GvcMixerControl *control)
 {
         pa_operation *o;
-        GvcMixerControl *control = (GvcMixerControl *) userdata;
         pa_ext_stream_restore_info new_info;
 
-        if (eol || control->priv->new_default_stream == NULL)
+        if (eol || new_stream == NULL)
                 return;
 
         new_info.name = info->name;
@@ -149,7 +150,7 @@ gvc_mixer_control_stream_restore_cb (pa_context *c,
         new_info.volume = info->volume;
         new_info.mute = info->mute;
 
-        new_info.device = gvc_mixer_stream_get_name (control->priv->new_default_stream);
+        new_info.device = gvc_mixer_stream_get_name (new_stream);
 
         o = pa_ext_stream_restore_write (control->priv->pa_context,
                                          PA_UPDATE_REPLACE,
@@ -162,11 +163,35 @@ gvc_mixer_control_stream_restore_cb (pa_context *c,
                 return;
         }
 
-        g_debug ("Changed default device for %s to %s", info->name, info->device);
+        g_debug ("Changed default device for %s to %s", info->name, new_info.device);
 
         pa_operation_unref (o);
 }
 
+static void
+gvc_mixer_control_stream_restore_sink_cb (pa_context *c,
+                                          const pa_ext_stream_restore_info *info,
+                                          int eol,
+                                          void *userdata)
+{
+        GvcMixerControl *control = (GvcMixerControl *) userdata;
+        if (!g_str_has_prefix(info->name, "sink-input-by"))
+                return;
+        gvc_mixer_control_stream_restore_cb (c, control->priv->new_default_sink_stream, info, eol, control);
+}
+
+static void
+gvc_mixer_control_stream_restore_source_cb (pa_context *c,
+                                            const pa_ext_stream_restore_info *info,
+                                            int eol,
+                                            void *userdata)
+{
+        GvcMixerControl *control = (GvcMixerControl *) userdata;
+        if (!g_str_has_prefix(info->name, "source-output-by"))
+                return;
+        gvc_mixer_control_stream_restore_cb (c, control->priv->new_default_source_stream, info, eol, control);
+}
+
 gboolean
 gvc_mixer_control_set_default_sink (GvcMixerControl *control,
                                     GvcMixerStream  *stream)
@@ -188,11 +213,11 @@ gvc_mixer_control_set_default_sink (GvcMixerControl *control,
 
         pa_operation_unref (o);
 
-        control->priv->new_default_stream = stream;
-        g_object_add_weak_pointer (G_OBJECT (stream), (gpointer *) &control->priv->new_default_stream);
+        control->priv->new_default_sink_stream = stream;
+        g_object_add_weak_pointer (G_OBJECT (stream), (gpointer *) &control->priv->new_default_sink_stream);
 
         o = pa_ext_stream_restore_read (control->priv->pa_context,
-                                        gvc_mixer_control_stream_restore_cb,
+                                        gvc_mixer_control_stream_restore_sink_cb,
                                         control);
 
         if (o == NULL) {
@@ -226,6 +251,21 @@ gvc_mixer_control_set_default_source (GvcMixerControl *control,
 
         pa_operation_unref (o);
 
+        control->priv->new_default_source_stream = stream;
+        g_object_add_weak_pointer (G_OBJECT (stream), (gpointer *) &control->priv->new_default_source_stream);
+
+        o = pa_ext_stream_restore_read (control->priv->pa_context,
+                                        gvc_mixer_control_stream_restore_source_cb,
+                                        control);
+
+        if (o == NULL) {
+                g_warning ("pa_ext_stream_restore_read() failed: %s",
+                           pa_strerror (pa_context_errno (control->priv->pa_context)));
+                return FALSE;
+        }
+
+        pa_operation_unref (o);
+
         return TRUE;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]