card: move profile selection after pa_card_new()

I want module-alsa-card to set the availability of unavailable
profiles before the initial card profile gets selected, so that the
selection logic can use correct availability information.
module-alsa-card initializes the jack state after calling
pa_card_new(), however, and the profile selection happens in
pa_card_new(). This patch solves that by moving parts of pa_card_new()
to pa_card_choose_initial_profile() and pa_card_put().

pa_card_choose_initial_profile() applies the profile selection policy,
so module-alsa-card can first call pa_card_new(), then initialize the
jack state, and then call pa_card_choose_initial_profile(). After that
module-alsa-card can still override the profile selection policy, in
case module-alsa-card was loaded with the "profile" argument. Finally,
pa_card_put() finalizes the card creation.

An alternative solution would have been to move the jack
initialization to happen before pa_card_new() and use pa_card_new_data
instead of pa_card in the jack initialization code, but I disliked
that idea (I want to get rid of the "new data" pattern eventually).

The order in which the initial profile policy is applied is reversed
in this patch. Previously the first one to set it won, now the last
one to set it wins. I think this is better, because if you have N
parties that want to set the profile, we avoid checking N times
whether someone else has already set the profile.
This commit is contained in:
Tanu Kaskinen 2015-10-23 12:59:53 +03:00
parent 18d44b9759
commit 7b62601401
8 changed files with 146 additions and 72 deletions

View file

@ -2238,7 +2238,7 @@ static int add_card(struct userdata *u) {
pa_bluez4_profile_t *d;
pa_bluez4_form_factor_t ff;
char *n;
const char *default_profile;
const char *profile_str;
const pa_bluez4_device *device;
const pa_bluez4_uuid *uuid;
@ -2298,16 +2298,6 @@ static int add_card(struct userdata *u) {
*d = PA_BLUEZ4_PROFILE_OFF;
pa_hashmap_put(data.profiles, p->name, p);
if ((default_profile = pa_modargs_get_value(u->modargs, "profile", NULL))) {
if (pa_hashmap_get(data.profiles, default_profile))
pa_card_new_data_set_profile(&data, default_profile);
else {
pa_log("Profile '%s' not valid or not supported by device.", default_profile);
pa_card_new_data_done(&data);
return -1;
}
}
u->card = pa_card_new(u->core, &data);
pa_card_new_data_done(&data);
@ -2319,6 +2309,25 @@ static int add_card(struct userdata *u) {
u->card->userdata = u;
u->card->set_profile = card_set_profile;
pa_card_choose_initial_profile(u->card);
/* If the "profile" modarg is given, we have to override whatever the usual
* policy chose in pa_card_choose_initial_profile(). */
profile_str = pa_modargs_get_value(u->modargs, "profile", NULL);
if (profile_str) {
pa_card_profile *profile;
profile = pa_hashmap_get(u->card->profiles, profile_str);
if (!profile) {
pa_log("No such profile: %s", profile_str);
return -1;
}
pa_card_set_profile(u->card, profile, false);
}
pa_card_put(u->card);
d = PA_CARD_PROFILE_DATA(u->card->active_profile);
if (*d != PA_BLUEZ4_PROFILE_OFF && (!device->transports[*d] ||