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.
This commit is contained in:
João Paulo Rechi Vita 2018-12-13 13:07:08 -08:00 committed by Tanu Kaskinen
parent 30a551bbc4
commit 40e72e02eb

View File

@ -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;
}