From ac33a01f30d54b23e9eb264b5fb13022d1c2bdce Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Wed, 20 Jan 2021 00:07:48 +0100 Subject: [PATCH] bluetooth: Add missing can_be_supported check to is_codec_available Part-of: --- src/modules/bluetooth/a2dp-codec-util.c | 11 ++++++----- src/modules/bluetooth/a2dp-codec-util.h | 2 +- src/modules/bluetooth/bluez5-util.c | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/modules/bluetooth/a2dp-codec-util.c b/src/modules/bluetooth/a2dp-codec-util.c index d3d763bcb..645dc364d 100644 --- a/src/modules/bluetooth/a2dp-codec-util.c +++ b/src/modules/bluetooth/a2dp-codec-util.c @@ -89,15 +89,16 @@ void pa_bluetooth_a2dp_codec_gst_init(void) { #endif } -bool pa_bluetooth_a2dp_codec_is_codec_available(const pa_a2dp_codec_id *id, bool is_a2dp_sink) { +bool pa_bluetooth_a2dp_codec_is_available(const pa_a2dp_codec_id *id, bool is_a2dp_sink) { unsigned int i; unsigned int count = pa_bluetooth_a2dp_codec_count(); + const pa_a2dp_codec *a2dp_codec; for (i = 0; i < count; i++) { - if (memcmp(id, &pa_a2dp_codecs[i]->id, sizeof(pa_a2dp_codec_id)) == 0) { - return (is_a2dp_sink && pa_a2dp_codecs[i]->encode_buffer != NULL) - || (!is_a2dp_sink && pa_a2dp_codecs[i]->decode_buffer != NULL); - } + a2dp_codec = pa_bluetooth_a2dp_codec_iter(i); + if (memcmp(id, &a2dp_codec->id, sizeof(pa_a2dp_codec_id)) == 0 + && a2dp_codec->can_be_supported(is_a2dp_sink)) + return true; } return false; diff --git a/src/modules/bluetooth/a2dp-codec-util.h b/src/modules/bluetooth/a2dp-codec-util.h index 3c6b8008e..7b8d0cc87 100644 --- a/src/modules/bluetooth/a2dp-codec-util.h +++ b/src/modules/bluetooth/a2dp-codec-util.h @@ -32,7 +32,7 @@ const pa_a2dp_codec *pa_bluetooth_a2dp_codec_iter(unsigned int i); const pa_a2dp_codec *pa_bluetooth_get_a2dp_codec(const char *name); /* Check if the given codec can be supported in A2DP_SINK or A2DP_SOURCE */ -bool pa_bluetooth_a2dp_codec_is_codec_available(const pa_a2dp_codec_id *id, bool is_a2dp_sink); +bool pa_bluetooth_a2dp_codec_is_available(const pa_a2dp_codec_id *id, bool is_a2dp_sink); /* Initialise GStreamer */ void pa_bluetooth_a2dp_codec_gst_init(void); diff --git a/src/modules/bluetooth/bluez5-util.c b/src/modules/bluetooth/bluez5-util.c index e49145ab7..d70876195 100644 --- a/src/modules/bluetooth/bluez5-util.c +++ b/src/modules/bluetooth/bluez5-util.c @@ -1335,7 +1335,7 @@ static void parse_remote_endpoint_properties(pa_bluetooth_discovery *y, const ch a2dp_codec_id->vendor_codec_id = 0; } - if (!pa_bluetooth_a2dp_codec_is_codec_available(a2dp_codec_id, pa_streq(uuid, PA_BLUETOOTH_UUID_A2DP_SINK))) { + if (!pa_bluetooth_a2dp_codec_is_available(a2dp_codec_id, pa_streq(uuid, PA_BLUETOOTH_UUID_A2DP_SINK))) { pa_xfree(a2dp_codec_id); return; }