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 <libin.yang@intel.com>
This commit is contained in:
Libin Yang 2020-09-16 08:31:06 -04:00
parent c1a7e3c59d
commit 8f60c91beb

View file

@ -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 */