card: Ensure we still pick a profile even if it's unavailable.

f434087e42 introduced the potential to not select a card profile if
all the profiles were marked as unavailable.

While this is very unlikely, it's a theoretical posibility, so if the
initial choice of a profile fails, try harder.
This commit is contained in:
Colin Guthrie 2013-11-15 09:33:37 +01:00 committed by Tanu Kaskinen
parent e9d760b555
commit 84af39f289

View file

@ -202,6 +202,12 @@ pa_card *pa_card_new(pa_core *core, pa_card_new_data *data) {
if (!c->active_profile || profile->priority > c->active_profile->priority) if (!c->active_profile || profile->priority > c->active_profile->priority)
c->active_profile = profile; c->active_profile = profile;
} }
/* If all profiles are not available, then we still need to pick one */
if (!c->active_profile) {
PA_HASHMAP_FOREACH(profile, c->profiles, state)
if (!c->active_profile || profile->priority > c->active_profile->priority)
c->active_profile = profile;
}
pa_assert(c->active_profile); pa_assert(c->active_profile);
} }