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
This commit is contained in:
Pauli Virtanen 2025-06-16 21:20:26 +03:00 committed by Arun Raghavan
parent cad0523617
commit b91864eb37

View file

@ -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) { 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)) { if (spa_bt_device_supports_media_codec(device, codecs[i], device->connected_profiles)) {
codec = codecs[i]; codec = codecs[i];
break; break;
@ -4827,8 +4830,10 @@ int spa_bt_device_ensure_media_codec(struct spa_bt_device *device, const struct
} }
/* Sort in codec preference order */ /* Sort in codec preference order */
codec_switch_cmp_sw = sw; if (codec->caps_preference_cmp) {
qsort(sw->paths, num_eps, sizeof(*sw->paths), codec_switch_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 /* Pick at most one source and one sink endpoint, if corresponding profiles are
* set */ * set */