[gnome-control-center] sound: update the profile list after getting the signal from gvc



commit 9b81e0ee4522ca27ca3ffe9a7d9fb4583f507752
Author: Hui Wang <hui wang canonical com>
Date:   Fri Sep 4 17:06:27 2020 +0800

    sound: update the profile list after getting the signal from gvc
    
    In the ubuntu 20.04, we found a regression on HDMI audio. We plug a
    HDMI/DP monitor, the output device is the speaker in the output device
    combo box, then we select the HDMI from the combo box, the output
    device is switched to HDMI audio successfully, but the configuration
    box is empty. This will not happen in the ubuntu 18.04, the profile
    will show hdmi-stereo in this situation. So I think this is a
    regression.
    
    When problem happens, I could see the errors from log:
    Gvc:    DEBUG: Matching profile for 'output:analog-stereo' is '(null)'
    Gvc:    DEBUG: Matching profile for 'output:analog-stereo' is '(null)'
    Gvc:    DEBUG: Matching profile for 'output:analog-stereo' is '(null)'
    
    Through debugging, I found the cc_profile_combo_box_set_device() is
    called too early. In the ubuntu 18.04, this function is called after
    pulseaudio changes the active_profile, but in the ubuntu 20.04, it is
    called ahead of pulseaudio changes the active_profile.
    
    To fix it, add a signal callback function, after pulseaudio changes
    the active_profile, this callback function will be called, then call
    cc_profile_combo_box_set_device().
    
    Signed-off-by: Hui Wang <hui wang canonical com>

 panels/sound/cc-sound-panel.c | 44 +++++++++++++++++++++++++++++++++++++------
 1 file changed, 38 insertions(+), 6 deletions(-)
---
diff --git a/panels/sound/cc-sound-panel.c b/panels/sound/cc-sound-panel.c
index 7a7e20b7d..200df4388 100644
--- a/panels/sound/cc-sound-panel.c
+++ b/panels/sound/cc-sound-panel.c
@@ -99,9 +99,6 @@ output_device_changed_cb (CcSoundPanel *self)
   gboolean can_fade = FALSE, has_lfe = FALSE;
 
   device = cc_device_combo_box_get_device (self->output_device_combo_box);
-  cc_profile_combo_box_set_device (self->output_profile_combo_box, self->mixer_control, device);
-  gtk_widget_set_visible (GTK_WIDGET (self->output_profile_row),
-                          cc_profile_combo_box_get_profile_count (self->output_profile_combo_box) > 1);
 
   if (device != NULL)
     stream = gvc_mixer_control_get_stream_from_device (self->mixer_control, device);
@@ -133,9 +130,6 @@ input_device_changed_cb (CcSoundPanel *self)
   GvcMixerStream *stream = NULL;
 
   device = cc_device_combo_box_get_device (self->input_device_combo_box);
-  cc_profile_combo_box_set_device (self->input_profile_combo_box, self->mixer_control, device);
-  gtk_widget_set_visible (GTK_WIDGET (self->input_profile_row),
-                          cc_profile_combo_box_get_profile_count (self->input_profile_combo_box) > 1);
 
   if (device != NULL)
     stream = gvc_mixer_control_get_stream_from_device (self->mixer_control, device);
@@ -147,6 +141,34 @@ input_device_changed_cb (CcSoundPanel *self)
     gvc_mixer_control_change_input (self->mixer_control, device);
 }
 
+static void
+output_device_update_cb (CcSoundPanel *self,
+                         guint         id)
+{
+  GvcMixerUIDevice *device;
+  gboolean has_multi_profiles;
+
+  device = cc_device_combo_box_get_device (self->output_device_combo_box);
+  cc_profile_combo_box_set_device (self->output_profile_combo_box, self->mixer_control, device);
+  has_multi_profiles = (cc_profile_combo_box_get_profile_count (self->output_profile_combo_box) > 1);
+  gtk_widget_set_visible (GTK_WIDGET (self->output_profile_row),
+                          has_multi_profiles);
+}
+
+static void
+input_device_update_cb (CcSoundPanel *self,
+                         guint         id)
+{
+  GvcMixerUIDevice *device;
+  gboolean has_multi_profiles;
+
+  device = cc_device_combo_box_get_device (self->input_device_combo_box);
+  cc_profile_combo_box_set_device (self->input_profile_combo_box, self->mixer_control, device);
+  has_multi_profiles = (cc_profile_combo_box_get_profile_count (self->input_profile_combo_box) > 1);
+  gtk_widget_set_visible (GTK_WIDGET (self->input_profile_row),
+                          has_multi_profiles);
+}
+
 static void
 test_output_configuration_button_clicked_cb (CcSoundPanel *self)
 {
@@ -263,4 +285,14 @@ cc_sound_panel_init (CcSoundPanel *self)
   cc_subwoofer_slider_set_mixer_control (self->subwoofer_slider, self->mixer_control);
   cc_device_combo_box_set_mixer_control (self->input_device_combo_box, self->mixer_control, FALSE);
   cc_device_combo_box_set_mixer_control (self->output_device_combo_box, self->mixer_control, TRUE);
+  g_signal_connect_object (self->mixer_control,
+                           "active-output-update",
+                           G_CALLBACK (output_device_update_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
+  g_signal_connect_object (self->mixer_control,
+                           "active-input-update",
+                           G_CALLBACK (input_device_update_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
 }


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