[pulseaudio-commits] [Git][pulseaudio/pulseaudio][master] 2 commits: bluetooth: Check support for encoding and decoding separately
PulseAudio Marge Bot
gitlab at gitlab.freedesktop.org
Thu Jan 21 15:05:29 UTC 2021
PulseAudio Marge Bot pushed to branch master at PulseAudio / pulseaudio
Commits:
519052e7 by Marijn Suijten at 2021-01-21T15:03:37+01:00
bluetooth: Check support for encoding and decoding separately
As suggested in [1]:
This way it is possible for a codec to have both the encoding and
decoding part optional, instead of getting both or nothing (where PA
theoretically supports both).
In addition this cleans up code that was previously checking the
existence of a function pointer, or nothing at all (switch_codec).
[1]: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/440#note_768146
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/479>
- - - - -
ac33a01f by Marijn Suijten at 2021-01-21T15:03:39+01:00
bluetooth: Add missing can_be_supported check to is_codec_available
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/479>
- - - - -
8 changed files:
- src/modules/bluetooth/a2dp-codec-api.h
- src/modules/bluetooth/a2dp-codec-aptx-gst.c
- src/modules/bluetooth/a2dp-codec-ldac-gst.c
- src/modules/bluetooth/a2dp-codec-sbc.c
- src/modules/bluetooth/a2dp-codec-util.c
- src/modules/bluetooth/a2dp-codec-util.h
- src/modules/bluetooth/bluez5-util.c
- src/modules/bluetooth/module-bluez5-device.c
Changes:
=====================================
src/modules/bluetooth/a2dp-codec-api.h
=====================================
@@ -49,7 +49,7 @@ typedef struct pa_a2dp_codec {
bool support_backchannel;
/* Returns true if the codec can be supported on the system */
- bool (*can_be_supported)(void);
+ bool (*can_be_supported)(bool for_encoding);
/* Returns true if codec accepts capabilities, for_encoding is true when
* capabilities are used for encoding */
=====================================
src/modules/bluetooth/a2dp-codec-aptx-gst.c
=====================================
@@ -33,25 +33,27 @@
#include "a2dp-codec-gst.h"
#include "rtp.h"
-static bool can_be_supported(void) {
+static bool can_be_supported(bool for_encoding) {
GstElementFactory *element_factory;
- element_factory = gst_element_factory_find("openaptxenc");
- if (element_factory == NULL) {
- pa_log_info("aptX encoder not found");
- return false;
- }
+ if (for_encoding) {
+ element_factory = gst_element_factory_find("openaptxenc");
+ if (element_factory == NULL) {
+ pa_log_info("aptX encoder not found");
+ return false;
+ }
- gst_object_unref(element_factory);
+ gst_object_unref(element_factory);
+ } else {
+ element_factory = gst_element_factory_find("openaptxdec");
+ if (element_factory == NULL) {
+ pa_log_info("aptX decoder not found");
+ return false;
+ }
- element_factory = gst_element_factory_find("openaptxdec");
- if (element_factory == NULL) {
- pa_log_info("aptX decoder not found");
- return false;
+ gst_object_unref(element_factory);
}
- gst_object_unref(element_factory);
-
return true;
}
=====================================
src/modules/bluetooth/a2dp-codec-ldac-gst.c
=====================================
@@ -33,9 +33,12 @@
#include "a2dp-codec-gst.h"
#include "rtp.h"
-static bool can_be_supported(void) {
+static bool can_be_supported(bool for_encoding) {
GstElementFactory *element_factory;
+ if (!for_encoding)
+ return false;
+
element_factory = gst_element_factory_find("ldacenc");
if (element_factory == NULL) {
pa_log_info("LDAC encoder not found");
=====================================
src/modules/bluetooth/a2dp-codec-sbc.c
=====================================
@@ -53,7 +53,7 @@ struct sbc_info {
uint8_t max_bitpool;
};
-static bool can_be_supported(void) {
+static bool can_be_supported(bool for_encoding) {
return true;
}
=====================================
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;
=====================================
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);
=====================================
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;
}
@@ -2108,21 +2108,21 @@ static DBusHandlerResult object_manager_handler(DBusConnection *c, DBusMessage *
char *endpoint;
a2dp_codec = pa_bluetooth_a2dp_codec_iter(i);
- if (!a2dp_codec->can_be_supported())
- continue;
codec_id = a2dp_codec->id.codec_id;
- capabilities_size = a2dp_codec->fill_capabilities(capabilities);
- pa_assert(capabilities_size != 0);
- if (a2dp_codec->decode_buffer != NULL) {
+ if (a2dp_codec->can_be_supported(false)) {
+ capabilities_size = a2dp_codec->fill_capabilities(capabilities);
+ pa_assert(capabilities_size != 0);
endpoint = pa_sprintf_malloc("%s/%s", A2DP_SINK_ENDPOINT, a2dp_codec->name);
append_a2dp_object(&array, endpoint, PA_BLUETOOTH_UUID_A2DP_SINK, codec_id,
capabilities, capabilities_size);
pa_xfree(endpoint);
}
- if (a2dp_codec->encode_buffer != NULL) {
+ if (a2dp_codec->can_be_supported(true)) {
+ capabilities_size = a2dp_codec->fill_capabilities(capabilities);
+ pa_assert(capabilities_size != 0);
endpoint = pa_sprintf_malloc("%s/%s", A2DP_SOURCE_ENDPOINT, a2dp_codec->name);
append_a2dp_object(&array, endpoint, PA_BLUETOOTH_UUID_A2DP_SOURCE, codec_id,
capabilities, capabilities_size);
@@ -2222,16 +2222,13 @@ pa_bluetooth_discovery* pa_bluetooth_discovery_get(pa_core *c, int headset_backe
count = pa_bluetooth_a2dp_codec_count();
for (i = 0; i < count; i++) {
a2dp_codec = pa_bluetooth_a2dp_codec_iter(i);
- if (!a2dp_codec->can_be_supported())
- continue;
-
- if (a2dp_codec->decode_buffer != NULL) {
+ if (a2dp_codec->can_be_supported(false)) {
endpoint = pa_sprintf_malloc("%s/%s", A2DP_SINK_ENDPOINT, a2dp_codec->name);
endpoint_init(y, endpoint);
pa_xfree(endpoint);
}
- if (a2dp_codec->encode_buffer != NULL) {
+ if (a2dp_codec->can_be_supported(true)) {
endpoint = pa_sprintf_malloc("%s/%s", A2DP_SOURCE_ENDPOINT, a2dp_codec->name);
endpoint_init(y, endpoint);
pa_xfree(endpoint);
@@ -2316,16 +2313,13 @@ void pa_bluetooth_discovery_unref(pa_bluetooth_discovery *y) {
for (i = 0; i < count; i++) {
a2dp_codec = pa_bluetooth_a2dp_codec_iter(i);
- if (!a2dp_codec->can_be_supported())
- continue;
-
- if (a2dp_codec->decode_buffer != NULL) {
+ if (a2dp_codec->can_be_supported(false)) {
endpoint = pa_sprintf_malloc("%s/%s", A2DP_SINK_ENDPOINT, a2dp_codec->name);
endpoint_done(y, endpoint);
pa_xfree(endpoint);
}
- if (a2dp_codec->encode_buffer != NULL) {
+ if (a2dp_codec->can_be_supported(true)) {
endpoint = pa_sprintf_malloc("%s/%s", A2DP_SOURCE_ENDPOINT, a2dp_codec->name);
endpoint_done(y, endpoint);
pa_xfree(endpoint);
=====================================
src/modules/bluetooth/module-bluez5-device.c
=====================================
@@ -2307,7 +2307,7 @@ static char *list_codecs(struct userdata *u) {
a2dp_codec = pa_bluetooth_a2dp_codec_iter(i);
if (memcmp(key, &a2dp_codec->id, sizeof(pa_a2dp_codec_id)) == 0) {
- if (a2dp_codec->can_be_supported()) {
+ if (a2dp_codec->can_be_supported(is_a2dp_sink)) {
pa_message_params_begin_list(param);
pa_message_params_write_string(param, a2dp_codec->name);
@@ -2383,13 +2383,13 @@ static int bluez5_device_message_handler(const char *object_path, const char *me
return -PA_ERR_INVALID;
}
- if (!codec->can_be_supported()) {
+ is_a2dp_sink = u->profile == PA_BLUETOOTH_PROFILE_A2DP_SINK;
+
+ if (!u->a2dp_codec->can_be_supported(is_a2dp_sink)) {
pa_log_info("Codec not found on system");
return -PA_ERR_NOTSUPPORTED;
}
- is_a2dp_sink = u->profile == PA_BLUETOOTH_PROFILE_A2DP_SINK;
-
/*
* We need to check if we have valid sink or source endpoints which
* were registered during the negotiation process. If we do, then we
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/compare/8816b6b05bca6069a77e7068957b0eb041fb4055...ac33a01f30d54b23e9eb264b5fb13022d1c2bdce
--
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/compare/8816b6b05bca6069a77e7068957b0eb041fb4055...ac33a01f30d54b23e9eb264b5fb13022d1c2bdce
You're receiving this email because of your account on gitlab.freedesktop.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/pulseaudio-commits/attachments/20210121/9c8c6bfd/attachment-0001.htm>
More information about the pulseaudio-commits
mailing list