From 40e72e02eb938b5c1150ce79e691efc5118770c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Paulo=20Rechi=20Vita?= Date: Thu, 13 Dec 2018 13:07:08 -0800 Subject: [PATCH] module-alsa-card: Update the active profile's availability last The previous commit introduces logic in module-switch-on-port-available that may change a card's active profile when its availability changes to PA_AVAILABLE_NO. To choose the new active profile, it needs a consistent view of the new availability of all profiles, so this commit changes the order which the ALSA driver updates all profiles' availability to ensure the active profile is last. This is not generic enough to cover cases were we may want to take an action on availability changes of profiles other than the active one that also need a consistent view of all profiles' availability. But we don't have any callbacks implementing such action at the moment. --- src/modules/alsa/module-alsa-card.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/modules/alsa/module-alsa-card.c b/src/modules/alsa/module-alsa-card.c index 041d53121..473248767 100644 --- a/src/modules/alsa/module-alsa-card.c +++ b/src/modules/alsa/module-alsa-card.c @@ -368,6 +368,7 @@ static int report_jack_state(snd_mixer_elem_t *melem, unsigned int mask) { pa_alsa_jack *jack; struct temp_port_avail *tp, *tports; pa_card_profile *profile; + pa_available_t active_available = PA_AVAILABLE_UNKNOWN; pa_assert(u); @@ -463,6 +464,8 @@ static int report_jack_state(snd_mixer_elem_t *melem, unsigned int mask) { * * If there are no output ports at all, but the profile contains at least * one sink, then the output is considered to be available. */ + if (u->card->active_profile) + active_available = u->card->active_profile->available; PA_HASHMAP_FOREACH(profile, u->card->profiles, state) { pa_device_port *port; void *state2; @@ -492,9 +495,18 @@ static int report_jack_state(snd_mixer_elem_t *melem, unsigned int mask) { if ((has_input_port && !found_available_input_port) || (has_output_port && !found_available_output_port)) available = PA_AVAILABLE_NO; - pa_card_profile_set_available(profile, available); + /* We want to update the active profile's status last, so logic that + * may change the active profile based on profile availability status + * has an updated view of all profiles' availabilities. */ + if (profile == u->card->active_profile) + active_available = available; + else + pa_card_profile_set_available(profile, available); } + if (u->card->active_profile) + pa_card_profile_set_available(u->card->active_profile, active_available); + pa_xfree(tports); return 0; }