bluez5: Ensure codec_id comparison is against codec of right type

G722 codec id for ASHA is chosen arbitrarily to be different from
A2DP and BAP codec IDs. ASHA spec does not specify a codec ID like
A2DP/BAP.

In places where codec_id comparisons are done, ensure that the check
is done against the codec of the right type viz. A2DP/BAP/ASHA.
This commit is contained in:
Sanchayan Maity 2025-01-08 17:52:24 +05:30 committed by Wim Taymans
parent c7496c847f
commit b1e4799ea6

View file

@ -2496,12 +2496,13 @@ bool spa_bt_device_supports_media_codec(struct spa_bt_device *device, const stru
{ SPA_BLUETOOTH_AUDIO_CODEC_APTX_LL_DUPLEX, SPA_BT_FEATURE_A2DP_DUPLEX },
{ SPA_BLUETOOTH_AUDIO_CODEC_FASTSTREAM_DUPLEX, SPA_BT_FEATURE_A2DP_DUPLEX },
};
bool is_a2dp = !codec->bap && !codec->asha;
size_t i;
if (!is_media_codec_enabled(device->monitor, codec))
return false;
if (!device->adapter->a2dp_application_registered && !codec->bap) {
if (!device->adapter->a2dp_application_registered && is_a2dp) {
/* Codec switching not supported: only plain SBC allowed */
return (codec->codec_id == A2DP_CODEC_SBC && spa_streq(codec->name, "sbc") &&
device->adapter->legacy_endpoints_registered);
@ -4113,6 +4114,8 @@ static int setup_asha_transport(struct spa_bt_remote_endpoint *remote_endpoint,
for (int i = 0; media_codecs[i]; i++) {
const struct media_codec *mcodec = media_codecs[i];
if (!mcodec->asha)
continue;
if (!spa_streq(mcodec->name, "g722"))
continue;
codec = mcodec;
@ -5099,6 +5102,8 @@ static DBusHandlerResult object_manager_handler(DBusConnection *c, DBusMessage *
if (codec->bap != is_bap)
continue;
if (codec->asha)
continue;
if (!is_media_codec_enabled(monitor, codec))
continue;