diff --git a/spa/plugins/bluez5/bluez5-device.c b/spa/plugins/bluez5/bluez5-device.c index 6499bed42..030402826 100644 --- a/spa/plugins/bluez5/bluez5-device.c +++ b/spa/plugins/bluez5/bluez5-device.c @@ -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; } diff --git a/src/examples/media-session/bluez-monitor.c b/src/examples/media-session/bluez-monitor.c index 28ed94b3d..e8ca56f98 100644 --- a/src/examples/media-session/bluez-monitor.c +++ b/src/examples/media-session/bluez-monitor.c @@ -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); }