Skip to content

Add support for bluetooth A2DP codecs and codec switching

Admin note

This MR is based on the work of someone who published their work based on the principles of free software - and the strict legal terms of the PulseAudio software base - which include the right to freely distribute, copy, and modify. After being banned due to abusive behaviour, the author attempted to 'withdraw permission' for anyone to use their code, which is not legally valid. They have posted further personally abusive comments within this MR, which have been deleted.

Whilst the original MR contains many comments on non-technical topics - both offering personal abuse as well as conciliatory offers to 'mediate' with the submitter - any such comments on this MR will be immediately deleted. Please keep comments on this MR to technical matters only. Thankyou.

[original MR content follows]

Original MR comment

EDIT: This patch series was based on the closed MR !227 (closed) but has now been updated to not include any of the patches from the author as requested.

Primary changes in comparison are

  1. Refactoring out the codec switching and D-Bus RegisterApplication API support in separate patches.
  2. Instead of tying codec switching to A2DP profiles, profile implementation is not touched at all and allows codec switching via messaging API. For this, a message handler is registered by module-bluez5-device.
  3. Adds support for aptX and LDAC via GStreamer. AAC support has also been tested but will follow later as the patch adding support for the same in GStreamer upstream is under review. See here. Note that LDAC support here does not support Adaptive Bit Rate (ABR). This will also follow later once we add support for this upstream.
  4. GStreamer plugins for aptX, LDAC and WIP AAC depend on the libraries libopenaptx, libldac and fdkaac. Also since the upstream support isn't available in a released GStreamer version yet, for now, this can only be tested in a gst-build environment. We hope the AAC support will be merged soon and LDAC and aptX via GStreamer which are already merged should be available from v1.20.

For codec switch, running one of the following from the command line, will switch the codec.

pacmd send-message /card/bluez_card.XX_XX_XX_XX_XX_XX/bluez switch-codec {"ldac_hq"}
pacmd send-message /card/bluez_card.XX_XX_XX_XX_XX_XX/bluez switch-codec {"ldac_mq"}
pacmd send-message /card/bluez_card.XX_XX_XX_XX_XX_XX/bluez switch-codec {"ldac_sq"}
pacmd send-message /card/bluez_card.XX_XX_XX_XX_XX_XX/bluez switch-codec {"aptx_hd"}
pacmd send-message /card/bluez_card.XX_XX_XX_XX_XX_XX/bluez switch-codec {"aptx"}
pacmd send-message /card/bluez_card.XX_XX_XX_XX_XX_XX/bluez switch-codec {"sbc"}

The name passed above in {" "} is matched against pa_a2dp_codec->name. Note that the match is case sensitive. A valid bluetooth devices needs to be passed in place of XX_XX_XX_XX_XX_XX, for eg. 4C_BC_98_80_01_9B.

To test the above in gst-build, the following steps need to be performed. Am assuming build has been specified as the build directory.

  1. Clone the gst-build repository and follow the instructions there to build GStreamer and it's modules.
  2. Once the build is complete, run the following command while in gst-build directory.
ninja -C build devenv

This sets up a kind of virtual environment where the latest GStreamer plugins will be available.

  1. Considering a freshly cloned PulseAudio repository in $HOME with this branch selected or patches applied, now run the following commands.
cd ~/pulseaudio
meson -Dbluez5-gstreamer=enabled build
ninja -C build
  1. Once the build is complete, cd to the build directory.
cd build
src/daemon/pulseaudio -n -F src/daemon/ -p $PWD/src/modules/ -v

Note that since the GStreamer plugins themselves depend on native codecs, libldac and libopenaptx should be installed on system beforehand.

Edited by Sanchayan Maity

Merge request reports