From cd24fe2fe90846bb9989fd7977aa9581319b63ae Mon Sep 17 00:00:00 2001 From: Ashok Sidipotu Date: Tue, 15 Aug 2023 07:13:20 +0530 Subject: [PATCH] bluez5: A2DP and BAP profiles to enumerate only codec profiles This avoids the potential confusion when both codecless and codec profiles are enumerated for A2DP. Give base name to highest priority profile, so that best codec can be selected at command line with out knowing which codecs are actually supported. --- spa/plugins/bluez5/bluez5-device.c | 42 ++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/spa/plugins/bluez5/bluez5-device.c b/spa/plugins/bluez5/bluez5-device.c index bb7db13a5..3dec1e0aa 100644 --- a/spa/plugins/bluez5/bluez5-device.c +++ b/spa/plugins/bluez5/bluez5-device.c @@ -1467,19 +1467,8 @@ static uint32_t get_index_from_profile(struct impl *this, uint32_t profile, enum if (profile == DEVICE_PROFILE_OFF || profile == DEVICE_PROFILE_AG) return profile; - if (profile == DEVICE_PROFILE_A2DP) { - if (codec == 0 || (this->bt_dev->connected_profiles & SPA_BT_PROFILE_MEDIA_SOURCE)) - return profile; - + if ((profile == DEVICE_PROFILE_A2DP) || (profile == DEVICE_PROFILE_BAP)) return codec + DEVICE_PROFILE_LAST; - } - - if (profile == DEVICE_PROFILE_BAP) { - if (codec == 0) - return profile; - - return codec + DEVICE_PROFILE_LAST; - } if (profile == DEVICE_PROFILE_HSP_HFP) { if (codec == 0 || (this->bt_dev->connected_profiles & SPA_BT_PROFILE_HFP_AG)) @@ -1607,6 +1596,11 @@ static struct spa_pod *build_profile(struct impl *this, struct spa_pod_builder * if (!(profile & SPA_BT_PROFILE_A2DP_SINK)) { return NULL; } + + /* A2DP will only enlist codec profiles */ + if (!codec) + return NULL; + name = spa_bt_profile_name(profile); n_sink++; if (codec) { @@ -1617,7 +1611,15 @@ static struct spa_pod *build_profile(struct impl *this, struct spa_pod_builder * return NULL; } name_and_codec = spa_aprintf("%s-%s", name, media_codec->name); - name = name_and_codec; + + /* + * Give base name to highest priority profile, so that best codec can be + * selected at command line with out knowing which codecs are actually + * supported + */ + if (idx != 0) + name = name_and_codec; + if (profile == SPA_BT_PROFILE_A2DP_SINK && !media_codec->duplex_codec) { desc_and_codec = spa_aprintf(_("High Fidelity Playback (A2DP Sink, codec %s)"), media_codec->description); @@ -1645,6 +1647,10 @@ static struct spa_pod *build_profile(struct impl *this, struct spa_pod_builder * size_t idx; const struct media_codec *media_codec; + /* BAP will only enlist codec profiles */ + if (codec == 0) + return NULL; + if (profile == 0) return NULL; @@ -1671,7 +1677,15 @@ static struct spa_pod *build_profile(struct impl *this, struct spa_pod_builder * return NULL; } name_and_codec = spa_aprintf("%s-%s", name, media_codec->name); - name = name_and_codec; + + /* + * Give base name to highest priority profile, so that best codec can be + * selected at command line with out knowing which codecs are actually + * supported + */ + if (idx != 0) + name = name_and_codec; + switch (profile) { case SPA_BT_PROFILE_BAP_SINK: desc_and_codec = spa_aprintf(_("High Fidelity Playback (BAP Sink, codec %s)"),