bluez5: set initial profile based on what's connected at startup

Set initial device profile according to what's connected at startup,
rather than having media-session try to set it to A2DP (and fail, if the
profile was not connected, resulting to startup in null profile).

This avoids making a codec switch at device startup (we'll stay with
what BlueZ autoconnected us to, usually the previously used codec).
This commit is contained in:
Pauli Virtanen 2021-02-10 21:30:15 +02:00 committed by Wim Taymans
parent 3c0821775f
commit beaec3d003
2 changed files with 37 additions and 1 deletions

View file

@ -502,6 +502,41 @@ static uint32_t get_index_from_profile(struct impl *this, uint32_t profile, cons
return SPA_ID_INVALID;
}
static void set_initial_profile(struct impl *this)
{
struct spa_bt_transport *t;
int i;
/* Prefer A2DP, then HFP, then null */
for (i = SPA_BT_PROFILE_A2DP_SINK; i <= SPA_BT_PROFILE_A2DP_SOURCE; i <<= 1) {
if (!(this->bt_dev->connected_profiles & i))
continue;
t = find_transport(this, i, NULL);
if (t) {
this->profile = 1;
this->selected_a2dp_codec = t->a2dp_codec;
return;
}
}
for (i = SPA_BT_PROFILE_HSP_HS; i <= SPA_BT_PROFILE_HFP_AG; i <<= 1) {
if (!(this->bt_dev->connected_profiles & i))
continue;
t = find_transport(this, i, NULL);
if (t) {
this->profile = 2;
this->selected_a2dp_codec = NULL;
return;
}
}
this->profile = 0;
this->selected_a2dp_codec = NULL;
}
static struct spa_pod *build_profile(struct impl *this, struct spa_pod_builder *b,
uint32_t id, uint32_t index, uint32_t profile_index, const struct a2dp_codec *codec)
{
@ -1133,6 +1168,8 @@ impl_init(const struct spa_handle_factory *factory,
spa_bt_device_add_listener(this->bt_dev, &this->bt_dev_listener, &bt_dev_events, this);
set_initial_profile(this);
return 0;
}

View file

@ -377,7 +377,6 @@ static void device_update(void *data)
&device->device_listener,
&bluez5_device_events, device);
set_profile(device, 1);
sm_object_sync_update(&device->sdevice->obj);
}