From b91864eb37b2b906ff66c1c0fb191790c18e1e03 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Mon, 16 Jun 2025 21:20:26 +0300 Subject: [PATCH] bluez5: don't crash on codecs without caps_preference_cmp E.g. LDAC doesn't have that. Add the missing guard that was accidentally dropped in the rewrite. Also explicitly filter out non-A2DP/BAP codecs that can't be used in ensure_media_codec --- spa/plugins/bluez5/bluez5-dbus.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/spa/plugins/bluez5/bluez5-dbus.c b/spa/plugins/bluez5/bluez5-dbus.c index ddfe7a350..6796bf49c 100644 --- a/spa/plugins/bluez5/bluez5-dbus.c +++ b/spa/plugins/bluez5/bluez5-dbus.c @@ -4763,6 +4763,9 @@ int spa_bt_device_ensure_media_codec(struct spa_bt_device *device, const struct } for (i = 0; codecs[i] != NULL; ++i) { + if (codecs[i]->kind != MEDIA_CODEC_BAP && codecs[i]->kind != MEDIA_CODEC_A2DP) + continue; + if (spa_bt_device_supports_media_codec(device, codecs[i], device->connected_profiles)) { codec = codecs[i]; break; @@ -4827,8 +4830,10 @@ int spa_bt_device_ensure_media_codec(struct spa_bt_device *device, const struct } /* Sort in codec preference order */ - codec_switch_cmp_sw = sw; - qsort(sw->paths, num_eps, sizeof(*sw->paths), codec_switch_cmp); + if (codec->caps_preference_cmp) { + codec_switch_cmp_sw = sw; + qsort(sw->paths, num_eps, sizeof(*sw->paths), codec_switch_cmp); + } /* Pick at most one source and one sink endpoint, if corresponding profiles are * set */