From 844317a1f54eef904c128ffd9fffa392158b550b Mon Sep 17 00:00:00 2001 From: David Henningsson Date: Fri, 8 Nov 2013 08:30:25 +0100 Subject: [PATCH] gvc-mixer-control: Move ACTIVE_INPUT_UPDATE notification to avoid infinite loop In some cases, we can get an infinite loop like this (in sound settings) : set_default_source -> active_input_update -> on_input_selection_changed -> control_change_input -> set_default_source To work around this do what we already do on the sink side, move the ACTIVE_INPUT_UPDATE signal from set_default_source to its callers, so that direct calls to set_default_source from outside in the library do not cause the signal to be emitted. BugLink: https://bugs.launchpad.net/bugs/1131220 Signed-off-by: David Henningsson --- gvc-mixer-control.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/gvc-mixer-control.c b/gvc-mixer-control.c index b270523..bddf346 100644 --- a/gvc-mixer-control.c +++ b/gvc-mixer-control.c @@ -352,13 +352,6 @@ gvc_mixer_control_set_default_source (GvcMixerControl *control, pa_operation_unref (o); - /* source change successful, update the UI. */ - input = gvc_mixer_control_lookup_device_from_stream (control, stream); - g_signal_emit (G_OBJECT (control), - signals[ACTIVE_INPUT_UPDATE], - 0, - gvc_mixer_ui_device_get_id (input)); - return TRUE; } @@ -678,7 +671,14 @@ gvc_mixer_control_change_input (GvcMixerControl *control, /* Handle a network sink as a portless/cardless device */ if (!gvc_mixer_ui_device_has_ports (input)) { g_debug ("Did we try to move to a software/bluetooth source ?"); - if (! gvc_mixer_control_set_default_source (control, stream)) { + if (gvc_mixer_control_set_default_source (control, stream)) + /* source change successful, update the UI. */ + input = gvc_mixer_control_lookup_device_from_stream (control, stream); + g_signal_emit (G_OBJECT (control), + signals[ACTIVE_INPUT_UPDATE], + 0, + gvc_mixer_ui_device_get_id (input)); + else { g_warning ("Failed to set default source with stream from input %s", gvc_mixer_ui_device_get_description (input)); } @@ -702,7 +702,21 @@ gvc_mixer_control_change_input (GvcMixerControl *control, if (stream != default_stream) { g_debug ("change-input - attempting to swap over to stream %s", gvc_mixer_stream_get_description (stream)); - gvc_mixer_control_set_default_source (control, stream); + if (gvc_mixer_control_set_default_source (control, stream)) { + /* source change successful, update the UI. */ + input = gvc_mixer_control_lookup_device_from_stream (control, stream); + g_signal_emit (G_OBJECT (control), + signals[ACTIVE_INPUT_UPDATE], + 0, + gvc_mixer_ui_device_get_id (input)); + } else { + /* If the move failed for some reason reset the UI. */ + input = gvc_mixer_control_lookup_device_from_stream (control, default_stream); + g_signal_emit (G_OBJECT (control), + signals[ACTIVE_INPUT_UPDATE], + 0, + gvc_mixer_ui_device_get_id (input)); + } } } -- 1.7.9.5