diff --git a/spa/plugins/bluez5/bluez5-dbus.c b/spa/plugins/bluez5/bluez5-dbus.c index fcd980a85..814df97e7 100644 --- a/spa/plugins/bluez5/bluez5-dbus.c +++ b/spa/plugins/bluez5/bluez5-dbus.c @@ -1552,7 +1552,7 @@ static bool device_props_ready(struct spa_bt_device *device) return device->adapter && device->address; } -bool spa_bt_device_supports_a2dp_codec(struct spa_bt_device *device, const struct a2dp_codec *codec) +bool spa_bt_device_supports_a2dp_codec(struct spa_bt_device *device, const struct a2dp_codec *codec, bool sink) { struct spa_bt_monitor *monitor = device->monitor; struct spa_bt_remote_endpoint *ep; @@ -1588,6 +1588,13 @@ bool spa_bt_device_supports_a2dp_codec(struct spa_bt_device *device, const struc } spa_list_for_each(ep, &device->remote_endpoint_list, device_link) { + const enum spa_bt_profile profile = spa_bt_profile_from_uuid(ep->uuid); + const enum spa_bt_profile expected = sink ? + SPA_BT_PROFILE_A2DP_SINK : SPA_BT_PROFILE_A2DP_SOURCE; + + if (profile != expected) + continue; + if (a2dp_codec_check_caps(codec, ep->codec, ep->capabilities, ep->capabilities_len, &ep->monitor->default_audio_info, &monitor->global_settings)) return true; @@ -1596,7 +1603,7 @@ bool spa_bt_device_supports_a2dp_codec(struct spa_bt_device *device, const struc return false; } -const struct a2dp_codec **spa_bt_device_get_supported_a2dp_codecs(struct spa_bt_device *device, size_t *count) +const struct a2dp_codec **spa_bt_device_get_supported_a2dp_codecs(struct spa_bt_device *device, size_t *count, bool sink) { struct spa_bt_monitor *monitor = device->monitor; const struct a2dp_codec * const * const a2dp_codecs = monitor->a2dp_codecs; @@ -1612,7 +1619,7 @@ const struct a2dp_codec **spa_bt_device_get_supported_a2dp_codecs(struct spa_bt_ j = 0; for (i = 0; a2dp_codecs[i] != NULL; ++i) { - if (spa_bt_device_supports_a2dp_codec(device, a2dp_codecs[i])) { + if (spa_bt_device_supports_a2dp_codec(device, a2dp_codecs[i], sink)) { supported_codecs[j] = a2dp_codecs[i]; ++j; } @@ -2933,7 +2940,7 @@ int spa_bt_device_ensure_a2dp_codec(struct spa_bt_device *device, const struct a } for (i = 0; codecs[i] != NULL; ++i) { - if (spa_bt_device_supports_a2dp_codec(device, codecs[i])) { + if (spa_bt_device_supports_a2dp_codec(device, codecs[i], true)) { preferred_codec = codecs[i]; break; } diff --git a/spa/plugins/bluez5/bluez5-device.c b/spa/plugins/bluez5/bluez5-device.c index 8852e1891..5a23ea440 100644 --- a/spa/plugins/bluez5/bluez5-device.c +++ b/spa/plugins/bluez5/bluez5-device.c @@ -915,7 +915,7 @@ static void profiles_changed(void *userdata, uint32_t prev_profiles, uint32_t pr if (this->bt_dev->connected_profiles & SPA_BT_PROFILE_A2DP_SINK) { free(this->supported_codecs); this->supported_codecs = spa_bt_device_get_supported_a2dp_codecs( - this->bt_dev, &this->supported_codec_count); + this->bt_dev, &this->supported_codec_count, true); } switch (this->profile) { @@ -1130,7 +1130,7 @@ static void set_initial_profile(struct impl *this) 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); + this->bt_dev, &this->supported_codec_count, true); /* Prefer A2DP, then HFP, then null, but select AG if the device appears not to have A2DP_SINK or any HEAD_UNIT profile */ diff --git a/spa/plugins/bluez5/defs.h b/spa/plugins/bluez5/defs.h index 2bdace5d3..c27faffa7 100644 --- a/spa/plugins/bluez5/defs.h +++ b/spa/plugins/bluez5/defs.h @@ -490,8 +490,8 @@ int spa_bt_device_add_profile(struct spa_bt_device *device, enum spa_bt_profile int spa_bt_device_connect_profile(struct spa_bt_device *device, enum spa_bt_profile profile); int spa_bt_device_check_profiles(struct spa_bt_device *device, bool force); int spa_bt_device_ensure_a2dp_codec(struct spa_bt_device *device, const struct a2dp_codec * const *codecs); -bool spa_bt_device_supports_a2dp_codec(struct spa_bt_device *device, const struct a2dp_codec *codec); -const struct a2dp_codec **spa_bt_device_get_supported_a2dp_codecs(struct spa_bt_device *device, size_t *count); +bool spa_bt_device_supports_a2dp_codec(struct spa_bt_device *device, const struct a2dp_codec *codec, bool sink); +const struct a2dp_codec **spa_bt_device_get_supported_a2dp_codecs(struct spa_bt_device *device, size_t *count, bool sink); int spa_bt_device_ensure_hfp_codec(struct spa_bt_device *device, unsigned int codec); int spa_bt_device_supports_hfp_codec(struct spa_bt_device *device, unsigned int codec); int spa_bt_device_release_transports(struct spa_bt_device *device);