diff --git a/spa/plugins/bluez5/a2dp-codec-aptx.c b/spa/plugins/bluez5/a2dp-codec-aptx.c index c7c5bd497..d1bf24fb0 100644 --- a/spa/plugins/bluez5/a2dp-codec-aptx.c +++ b/spa/plugins/bluez5/a2dp-codec-aptx.c @@ -86,6 +86,10 @@ static int codec_select_config(const struct a2dp_codec *codec, uint32_t flags, memcpy(&conf, caps, sizeof(conf)); + if (codec->vendor.vendor_id != conf.info.vendor_id || + codec->vendor.codec_id != conf.info.codec_id) + return -ENOTSUP; + if (conf.frequency & APTX_SAMPLING_FREQ_48000) conf.frequency = APTX_SAMPLING_FREQ_48000; else if (conf.frequency & APTX_SAMPLING_FREQ_44100) diff --git a/spa/plugins/bluez5/a2dp-codec-ldac.c b/spa/plugins/bluez5/a2dp-codec-ldac.c index ab1b5e8d4..ccd2453f7 100644 --- a/spa/plugins/bluez5/a2dp-codec-ldac.c +++ b/spa/plugins/bluez5/a2dp-codec-ldac.c @@ -138,8 +138,10 @@ static int codec_select_config(const struct a2dp_codec *codec, uint32_t flags, return -EINVAL; memcpy(&conf, caps, sizeof(conf)); - conf.info.vendor_id = LDAC_VENDOR_ID; - conf.info.codec_id = LDAC_CODEC_ID; + + if (codec->vendor.vendor_id != conf.info.vendor_id || + codec->vendor.codec_id != conf.info.codec_id) + return -ENOTSUP; if (conf.frequency & LDACBT_SAMPLING_FREQ_044100) conf.frequency = LDACBT_SAMPLING_FREQ_044100; diff --git a/spa/plugins/bluez5/a2dp-codecs.c b/spa/plugins/bluez5/a2dp-codecs.c index 67fa9bdcf..e2de0bb21 100644 --- a/spa/plugins/bluez5/a2dp-codecs.c +++ b/spa/plugins/bluez5/a2dp-codecs.c @@ -10,6 +10,24 @@ #include "a2dp-codecs.h" +bool a2dp_codec_check_caps(const struct a2dp_codec *codec, unsigned int codec_id, const void *caps, size_t caps_size) +{ + uint8_t config[A2DP_MAX_CAPS_SIZE]; + int res; + + if (codec_id != codec->codec_id) + return false; + + if (caps == NULL) + return false; + + res = codec->select_config(codec, 0, caps, caps_size, NULL, config); + if (res < 0) + return false; + + return ((size_t)res == caps_size); +} + #if ENABLE_MP3 const a2dp_mpeg_t bluez_a2dp_mpeg = { .layer = diff --git a/spa/plugins/bluez5/a2dp-codecs.h b/spa/plugins/bluez5/a2dp-codecs.h index fc57b8836..79b5a7fce 100644 --- a/spa/plugins/bluez5/a2dp-codecs.h +++ b/spa/plugins/bluez5/a2dp-codecs.h @@ -377,4 +377,6 @@ struct a2dp_codec { extern const struct a2dp_codec **a2dp_codecs; +bool a2dp_codec_check_caps(const struct a2dp_codec *codec, unsigned int codec_id, const void *caps, size_t caps_size); + #endif