card: move profile selection after pa_card_new()
authorTanu Kaskinen <tanuk@iki.fi>
Fri, 23 Oct 2015 09:59:53 +0000 (12:59 +0300)
committerTanu Kaskinen <tanuk@iki.fi>
Tue, 28 Jun 2016 13:55:42 +0000 (16:55 +0300)
commit7b62601401495684b1ea0b6dce63d76e10da38e4
treeb00d53b34b4b377635d370dc67a27caa814db6f7
parent18d44b97594233f97d26daf1aaf5e7c953ed3843
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.
src/modules/alsa/module-alsa-card.c
src/modules/bluetooth/module-bluez4-device.c
src/modules/bluetooth/module-bluez5-device.c
src/modules/macosx/module-coreaudio-device.c
src/modules/module-card-restore.c
src/pulsecore/card.c
src/pulsecore/card.h
src/pulsecore/core.h