bluez5: create device handle before profile negotiation started so that profile handler can retrieve per-device settings

This commit is contained in:
Huang-Huang Bao 2021-03-14 14:06:50 +08:00 committed by Wim Taymans
parent e7cecaaea6
commit af8272fe08
5 changed files with 140 additions and 80 deletions

View file

@ -410,8 +410,20 @@ static void profiles_changed(void *userdata, uint32_t prev_profiles, uint32_t pr
emit_info(this, false);
}
static void set_initial_profile(struct impl *this);
static void device_connected(void *userdata, bool connected) {
struct impl *this = userdata;
spa_log_debug(this->log, "connected: %d", connected);
if (connected ^ (this->profile != 0))
set_initial_profile(this);
}
static const struct spa_bt_device_events bt_dev_events = {
SPA_VERSION_BT_DEVICE_EVENTS,
.connected = device_connected,
.codec_switched = codec_switched,
.profiles_changed = profiles_changed,
};
@ -540,6 +552,11 @@ static void set_initial_profile(struct impl *this)
struct spa_bt_transport *t;
int i;
if (this->supported_codecs)
free(this->supported_codecs);
this->supported_codecs = spa_bt_device_get_supported_a2dp_codecs(
this->bt_dev, &this->supported_codec_count);
/* Prefer A2DP, then HFP, then null */
for (i = SPA_BT_PROFILE_A2DP_SINK; i <= SPA_BT_PROFILE_A2DP_SOURCE; i <<= 1) {
@ -1248,8 +1265,6 @@ impl_init(const struct spa_handle_factory *factory,
this->info.params = this->params;
this->info.n_params = 4;
this->supported_codecs = spa_bt_device_get_supported_a2dp_codecs(this->bt_dev, &this->supported_codec_count);
spa_bt_device_add_listener(this->bt_dev, &this->bt_dev_listener, &bt_dev_events, this);
set_initial_profile(this);