From 8f60c91beb74a39758969d1df462f806b4424728 Mon Sep 17 00:00:00 2001 From: Libin Yang Date: Wed, 16 Sep 2020 08:31:06 -0400 Subject: [PATCH] module-switch-on-port-available: check default sink/source before switch When a port is unplugged, pa will scan all the ports and pick up the highest priorirty port and switch to that port. This will cause the issue described in https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/issues/984 Let's image there are 2 sinks: hdmi sink, speaker+headphone sink. The speaker is selected as the output port. When unplugging the HDMI, we hope the speaker is still the default output port. But actually, PA will switch to the headphone if headphone's priority is higher than speaker. This patches will check if the sink/source is the default sink/source firstly. Signed-off-by: Libin Yang --- src/modules/module-switch-on-port-available.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/module-switch-on-port-available.c b/src/modules/module-switch-on-port-available.c index 2fa7e4d62..1ea835ac5 100644 --- a/src/modules/module-switch-on-port-available.c +++ b/src/modules/module-switch-on-port-available.c @@ -186,6 +186,7 @@ struct port_pointers { bool is_possible_profile_active; bool is_preferred_profile_active; bool is_port_active; + bool is_default; /* is the sink/source default one */ }; static const char* profile_name_for_dir(pa_card_profile *cp, pa_direction_t dir) { @@ -223,6 +224,7 @@ static struct port_pointers find_port_pointers(pa_device_port *port) { pp.is_preferred_profile_active = pp.is_possible_profile_active && (!port->preferred_profile || pa_safe_streq(port->preferred_profile, profile_name_for_dir(card->active_profile, port->direction))); pp.is_port_active = (pp.sink && pp.sink->active_port == port) || (pp.source && pp.source->active_port == port); + pp.is_default = (pp.sink && pp.sink == pp.sink->core->default_sink) || (pp.source && pp.source == pp.source->core->default_source); return pp; } @@ -257,7 +259,7 @@ static void switch_from_port(pa_device_port *port) { pa_device_port *p, *best_port = NULL; void *state; - if (!pp.is_port_active) + if (!pp.is_port_active || !pp.is_default) return; /* Already deselected */ /* Try to find a good enough port to switch to */