Commit 878401d9 authored by pali's avatar pali
Browse files

bluetooth: Set initial A2DP profile which bluez already activated

Bluez and remote device decide which A2DP codec would use. Use this
selected A2DP codec as initial profile in pulseaudio.

In most cases it is either last used codec or codec with higher priority by
defined by remote device.

To detect which A2DP profile was activated by bluez, look at bluez
transport state.
parent efef94a8
......@@ -2085,6 +2085,50 @@ static void add_card_profile(pa_bluetooth_profile_t profile, pa_card_new_data *d
pa_hashmap_put(data->profiles, cp->name, cp);
static void choose_initial_profile(struct userdata *u) {
struct pa_bluetooth_transport *transport;
pa_card_profile *iter_profile;
pa_card_profile *profile;
void *state;
pa_log_debug("Looking for A2DP profile which has active bluez transport for card %s", u->card->name);
profile = NULL;
/* Try to find the best A2DP profile with active transport */
PA_HASHMAP_FOREACH(iter_profile, u->card->profiles, state) {
transport = u->device->transports[*(pa_bluetooth_profile_t *)PA_CARD_PROFILE_DATA(iter_profile)];
/* Ignore profiles without active bluez transport */
if (!transport || transport->state == PA_BLUETOOTH_TRANSPORT_STATE_DISCONNECTED)
/* Ignore non-A2DP profiles */
if (!pa_startswith(iter_profile->name, "a2dp_"))
pa_log_debug("%s has active bluez transport", iter_profile->name);
if (!profile || iter_profile->priority > profile->priority)
profile = iter_profile;
/* When there is no active A2DP bluez transport, fallback to core pulseaudio function for choosing initial profile */
if (!profile) {
pa_log_debug("No A2DP profile with bluez active transport was found for card %s", u->card->name);
/* Do same job as pa_card_choose_initial_profile() */
pa_log_info("Setting initial A2DP profile '%s' for card %s", profile->name, u->card->name);
u->card->active_profile = profile;
u->card->save_profile = false;
/* Let policy modules override the default. */
pa_hook_fire(&u->card->core->hooks[PA_CORE_HOOK_CARD_CHOOSE_INITIAL_PROFILE], u->card);
/* Run from main thread */
static int add_card(struct userdata *u) {
const pa_bluetooth_device *d;
......@@ -2207,7 +2251,7 @@ static int add_card(struct userdata *u) {
u->card->userdata = u;
u->card->set_profile = set_profile_cb;
p = PA_CARD_PROFILE_DATA(u->card->active_profile);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment