Compiling LHDCv5 Support for PipeWire on Debian 13

Published 2026-12-06 12:20 3221 words 17 min read

Madobi Nanami avatar

Madobi Nanami

Nanami 的个人技术博客,记录网络、运维、虚拟化与逆向的实践。

Introduction I recently switched both my desktop and laptop over to Debian 13, leaving Windows behind for good. Since I use OPPO Enco X3 Bluetooth earbuds, I checked the codec database and found that...

Introduction

I recently switched both my desktop and laptop over to Debian 13, leaving Windows behind for good. Since I use OPPO Enco X3 Bluetooth earbuds, I checked the codec database and found that they support LHDCv5. After looking into it, I learned that PipeWire can be compiled from source to add LHDCv5 codec support—so I got right to work.

Environment

      _,met$$$$$gg.            nanami114@NanamiWork-Laptop   
   ,g$$$$$$$$$$$$$$$P.         ---------------------------   
 ,g$$P"        """Y$$.".       OS: Debian GNU/Linux 13.8 (trixie) x86_64   
,$$P'              `$$$.       Host: 21TL ThinkBook 16 G7+ IAH   
',$$P       ,ggs.     `$$b:    Kernel: 7.3.4+deb13-amd64   
`d$$'     ,$P"'   .    $$$     Uptime: 2 days, 11 hours, 32 mins   
$$P      d$'     ,    $$P      Packages: 1 (pipx), 195 (pip), 5 (cargo), 10 (npm), 3969 (dpkg), 25 (steam), 32 (flatpak-system)   
$$:      $$.   -    ,d$$'      Shell: zsh 5.9   
$$;      Y$b._   _,d$P'        Resolution: 2560x1440, 3200x2000, 2560x1440   
Y$$.    `.`"Y$$$$P"'           DE: Plasma 6.3.6 [KF 6.13.0] [Qt 6.8.2] (wayland)   
`$$b      "-.__                WM: kwin_wayland_wr   
 `Y$$                          Theme: Breeze-Dark [GTK2/3]   
  `Y$$.                        Icons: klassy [GTK2/3]   
    `$$b.                      Cursor: catppuccin-macchiato-rosewater-cursors [GTK2/3]   
      `Y$$b.                   Terminal: konsole   
         `"Y$b._               CPU: Intel Ultra 9 285H (16) @ 5.4GHz   
             `"""              GPU: Intel Graphics]   
                               GPU: NVIDIA GeForce RTX 5060 Max-Q / Mobile   
                               Memory: 21.48 GiB / 30.78 GiB (69%)   
                               Network: 1 Gbps   
                               BIOS: LENOVO 1.55 (12/22/2025)

Disclaimer

Everything in this article was verified on my own machine and has not been broadly tested. Any loss caused by improper operation, missing backups, or other issues while following these steps is unrelated to this article or to me.


Let’s Start

1. Preparing the Upstream Codec Source and Build Environment

1.1 Cloning the Source Code

There are several repositories that provide LHDC support for PipeWire; I picked an actively maintained one (repository). Clone the entire repository locally first:

git clone https://github.com/DBeidachazi/liblhdcv5

This project builds a native Linux shared library wrapping Android 17’s system/audio/codecs/lhdcv5 Rust encoder and the lhdcv5BT.h C ABI. At the same time, clone the PipeWire source code:

git clone https://gitlab.freedesktop.org/pipewire/pipewire

1.2 Preparing the Build Environment

liblhdcv5 requires git, make, gcc, and cargo/rustc; PipeWire SPA plugins require meson, ninja, and pkg-config. Install all of them in one go:

apt install git gcc g++ make cmake meson ninja cargo rustc pkg-config

Once installed, check the toolchain versions:

> rustc --version && cargo --version
rustc 1.99.0 (b940084d7 2026-09-28)
cargo 1.99.0 (5f94df478 2026-08-27)

The AOSP LHDCv5 encoder core is written in Rust, and its aosp/Cargo.toml specifies a minimum of rust-version = "1.82". Your installed version must be newer than that. If your version is too old, try enabling trixie-backports.

After verifying the versions, pre-fetch the locked Rust dependencies:

CARGO_HOME=./.cargo-home cargo fetch --manifest-path ./liblhdcv5/aosp/Cargo.toml --locked

Once fetched, you are ready to start building.

2. Building the PipeWire Backend with LHDCv5 Support

2.1 Building liblhdcv5.so and lhdcv5.pc

Build both with make:

CARGO_HOME=./.cargo-home make -C ./liblhdcv5 PREFIX=/usr/local LIBDIR=/usr/local/lib/x86_64-linux-gnu

Build output

make: Entering directory '/home/nanami114/workspace/lhdc/liblhdcv5'
cd aosp && RUSTFLAGS=" -C relocation-model=pic -C target-feature=-fma" cargo build --release --locked --lib
   Compiling proc-macro2 v1.0.106
   Compiling quote v1.0.46
   Compiling unicode-ident v1.0.24
   Compiling memchr v2.8.2
   Compiling once_cell v1.21.4
   Compiling libc v0.2.186
   Compiling log v0.4.33
   Compiling regex-syntax v0.8.11
   Compiling lazy_static v1.5.0
   Compiling thiserror v2.0.18
   Compiling cfg-if v1.0.4
   Compiling zerocopy v0.8.52
   Compiling pin-project-lite v0.2.17
   Compiling humantime v2.3.0
   Compiling termcolor v1.4.1
   Compiling nu-ansi-term v0.50.3
   Compiling sharded-slab v0.1.7
   Compiling thread_local v1.1.9
   Compiling smallvec v1.15.2
   Compiling tracing-core v0.1.36
   Compiling aho-corasick v1.1.4
   Compiling tracing-log v0.2.0
   Compiling tracing-subscriber v0.3.23
   Compiling syn v2.0.118
   Compiling is-terminal v0.4.17
   Compiling regex-automata v0.4.14
   Compiling zerocopy-derive v0.8.52
   Compiling thiserror-impl v2.0.18
   Compiling tracing-attributes v0.1.31
   Compiling regex v1.12.4
   Compiling env_logger v0.10.2
   Compiling tracing v0.1.44
   Compiling lhdcv5 v0.1.0 (/home/nanami114/workspace/lhdc/liblhdcv5/aosp)
    Finished `release` profile [optimized] target(s) in 5.72s
mkdir -p build
install -Dm644 log.h build/log/log.h
cc -Wall -Wextra -O3  -fPIC -ffunction-sections -fdata-sections -shared \
	-Iaosp/include \
	-Ibuild \
	aosp/src/lhdcv5BT_enc.c \
	aosp/target/release/liblhdcv5.a \
	-Wl,-soname,liblhdcv5.so \
	-Wl,--gc-sections -Wl,--version-script=/home/nanami114/workspace/lhdc/liblhdcv5/lhdcv5.map -Wl,-z,defs \
	 \
	-lm -lpthread -ldl \
	-o build/liblhdcv5.so
aosp/src/lhdcv5BT_enc.c: In function ‘lhdcv5BT_set_min_bitrate’:
aosp/src/lhdcv5BT_enc.c:540:24: warning: comparison of unsigned expression in ‘< 0’ is always false [-Wtype-limits]
  540 |   if ((min_bitrate_inx < LHDC_QUALITY_LOW0) || (min_bitrate_inx > LHDC_QUALITY_LOW)) {
      |                        ^
aosp/src/lhdcv5BT_enc.c: In function ‘lhdcv5BT_init_encoder’:
aosp/src/lhdcv5BT_enc.c:640:20: warning: comparison of unsigned expression in ‘< 0’ is always false [-Wtype-limits]
  640 |   if ((bitrate_inx < LHDC_QUALITY_LOW0) || (bitrate_inx > LHDC_QUALITY_AUTO)) {
      |                    ^
aosp/src/lhdcv5BT_enc.c:620:12: warning: unused variable ‘abr_table_size’ [-Wunused-variable]
  620 |   uint32_t abr_table_size = 0;
      |            ^~~~~~~~~~~~~~
sed -e "s|@PKGVER@|0.1.0|g" \
	-e "s|@PREFIX@|/usr/local|g" \
	-e "s|@LIBDIR@|/usr/local/lib/x86_64-linux-gnu|g" \
	-e "s|@INCLUDEDIR@|/usr/local/include|g" \
	lhdcv5.pc.in > build/lhdcv5.pc
make: Leaving directory '/home/nanami114/workspace/lhdc/liblhdcv5'

After the build finishes, check the shared library dependencies and exported symbols. ldd confirms liblhdcv5.so only depends on basic runtime libraries (libm, libgcc_s, libc) with no unexpected external dependencies; nm -D --defined-only confirms that the full set of lhdcv5BT_* symbols required by PipeWire’s a2dp-codec-lhdc.c (such as lhdcv5BT_init_encoder, lhdcv5BT_encode, lhdcv5BT_set_bitrate, etc.) are properly exported:

ldd ./liblhdcv5/build/liblhdcv5.so && nm -D --defined-only ./liblhdcv5/build/liblhdcv5.so

Full output

	linux-vdso.so.1 (0x00007f8d2df54000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f8d2dca4000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f8d2dc77000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8d2da83000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f8d2df56000)
0000000000020370 T lhdcv5BT_adjust_bitrate
0000000000020b30 T lhdcv5BT_encode
000000000001fb60 T lhdcv5BT_free_handle
000000000001fd10 T lhdcv5BT_get_bitrate
0000000000020a60 T lhdcv5BT_get_block_Size
000000000001fbe0 T lhdcv5BT_get_handle
0000000000020800 T lhdcv5BT_init_encoder
000000000001fe10 T lhdcv5BT_set_bitrate
0000000000020040 T lhdcv5BT_set_max_bitrate
00000000000201f0 T lhdcv5BT_set_min_bitrate
0000000000021d10 T lhdcv5_enc_ffi_encode
0000000000021ed0 T lhdcv5_enc_ffi_free_handle
0000000000021f90 T lhdcv5_enc_ffi_get_bitrate_index
0000000000022050 T lhdcv5_enc_ffi_get_block_size
00000000000221b0 T lhdcv5_enc_ffi_get_handle
0000000000022370 T lhdcv5_enc_ffi_get_last_bitrate
00000000000223c0 T lhdcv5_enc_ffi_get_quality_mode
0000000000022410 T lhdcv5_enc_ffi_init
0000000000022420 T lhdcv5_enc_ffi_init_encoder
00000000000224a0 T lhdcv5_enc_ffi_set_bitrate_index
0000000000022510 T lhdcv5_enc_ffi_set_max_bitrate
0000000000022580 T lhdcv5_enc_ffi_set_min_bitrate

2.2 Installing the Encoder and Refreshing the Dynamic Linker Cache

Install the build artifacts to /usr/local and refresh the dynamic linker cache:

sudo make -C ./liblhdcv5 install PREFIX=/usr/local LIBDIR=/usr/local/lib/x86_64-linux-gnu && sudo ldconfig

Full output

make: Entering directory '/home/nanami114/workspace/lhdc/liblhdcv5'
error: rustup could not choose a version of rustc to run, because one wasn't specified explicitly, and no default is configured.
help: run 'rustup default stable' to download the latest stable release of Rust and set it as your default toolchain.
sed -e "s|@PKGVER@|0.1.0|g" \
	-e "s|@PREFIX@|/usr/local|g" \
	-e "s|@LIBDIR@|/usr/local/lib/x86_64-linux-gnu|g" \
	-e "s|@INCLUDEDIR@|/usr/local/include|g" \
	lhdcv5.pc.in > build/lhdcv5.pc
install -Dm755 build/liblhdcv5.so "/usr/local/lib/x86_64-linux-gnu/liblhdcv5.so"
install -Dm644 aosp/include/lhdcv5BT.h "/usr/local/include/lhdcv5/lhdcv5BT.h"
install -Dm644 aosp/include/lhdcv5_api.h "/usr/local/include/lhdcv5/lhdcv5_api.h"
install -Dm644 build/lhdcv5.pc "/usr/local/lib/x86_64-linux-gnu/pkgconfig/lhdcv5.pc"
make: Leaving directory '/home/nanami114/workspace/lhdc/liblhdcv5'

Verify the liblhdcv5 installation using pkg-config and ldconfig:

pkg-config --modversion lhdcv5 && pkg-config --cflags --libs lhdcv5 && /usr/sbin/ldconfig -p | grep lhdcv5

Full output

0.1.0
-I/usr/local/include/lhdcv5 -L/usr/local/lib/x86_64-linux-gnu -llhdcv5 -lm
	liblhdcv5.so (libc6,x86-64) => /usr/local/lib/x86_64-linux-gnu/liblhdcv5.so

2.3 Installing Core Bluetooth Codec Development Packages

The codec development packages include libbluetooth-dev (BlueZ headers), libsbc-dev (mandatory base SBC codec—PipeWire’s codec-loader.c refuses to start without SBC), libldacbt-enc-dev (LDAC), libfreeaptx-dev (aptX / aptX HD), libopus-dev (Opus), liblc3-dev (LE Audio LC3 and HFP super-wideband speech), and libfdk-aac-dev from Debian’s non-free repo (to also enable high-quality AAC Bluetooth audio, which Debian leaves disabled by default). Install them all with apt:

sudo apt-get install -y libbluetooth-dev libsbc-dev libldacbt-enc-dev libfreeaptx-dev libopus-dev liblc3-dev libfdk-aac-dev

In addition, pipewire/spa/meson.build checks for ldacBT-abr (LDAC adaptive bitrate control) when -Dbluez5-codec-ldac=enabled is set, so install libldacbt-abr-dev as well. Also install libspandsp-dev so libspa-codec-bluez5-hfp-msbc.so can perform mSBC packet loss concealment (PLC) during HFP calls, avoiding call quality degradation:

sudo apt-get install -y libldacbt-abr-dev libspandsp-dev

2.4 Preparing the Official Upstream PipeWire Repository

First, do a shallow clone of the repository:

git clone --depth=1 https://gitlab.freedesktop.org/pipewire/pipewire.git

Verify the upstream commit and LHDCv5 build targets to make sure meson_options.txt and spa/plugins/bluez5/meson.build already include the native bluez5-codec-lhdc option and the spa-codec-bluez5-lhdc build target:

git -C ./pipewire log -n 1 && grep -n "lhdc" ./pipewire/meson_options.txt ./pipewire/spa/plugins/bluez5/meson.build

Full output

commit b3afa63ba086926a9626971f56d6205da864dcd1 (grafted, HEAD -> master, origin/master, origin/HEAD)
Author: Wim Taymans <wtaymans@redhat.com>
Date:   Sat Dec 5 14:45:10 2026 +0100

    filter: fix compilation
/home/nanami114/workspace/lhdc/pipewire/meson_options.txt:140:option('bluez5-codec-lhdc',
/home/nanami114/workspace/lhdc/pipewire/spa/plugins/bluez5/meson.build:173:if lhdc_dep.found()
/home/nanami114/workspace/lhdc/pipewire/spa/plugins/bluez5/meson.build:174:  bluez_codec_lhdc = shared_library('spa-codec-bluez5-lhdc',
/home/nanami114/workspace/lhdc/pipewire/spa/plugins/bluez5/meson.build:175:    [ 'a2dp-codec-lhdc.c', 'media-codecs.c' ],
/home/nanami114/workspace/lhdc/pipewire/spa/plugins/bluez5/meson.build:178:    dependencies : [ spa_dep, lhdc_dep ],

2.5 Configuring Meson to Build Only Required BlueZ5 Features

rm -rf ./pipewire/build && meson setup ./pipewire/build ./pipewire --prefix=/usr/local --libdir=lib/x86_64-linux-gnu --buildtype=release --wrap-mode=nodownload --auto-features=disabled -Dexamples=disabled -Dtests=disabled -Dman=disabled -Ddocs=disabled -Dsession-managers=[] -Dpipewire-alsa=disabled -Dpipewire-jack=disabled -Dsystemd-system-service=disabled -Dsystemd-user-service=disabled -Dflatpak=disabled -Dudev=disabled -Dalsa=disabled -Djack=disabled -Dbluez5=enabled -Dbluez5-codec-aac=enabled -Dbluez5-codec-aptx=enabled -Dbluez5-codec-g722=enabled -Dbluez5-codec-lc3=enabled -Dbluez5-codec-lc3plus=disabled -Dbluez5-codec-ldac=enabled -Dbluez5-codec-ldac-dec=disabled -Dbluez5-codec-lhdc=enabled -Dbluez5-codec-opus=enabled -Ddbus=enabled -Dlibusb=enabled -Dopus=enabled -Dselinux=disabled
  • --auto-features=disabled plus disabling alsa, jack, udev, docs, tests, and examples: avoids pulling in unrelated system dependencies and keeps the build fast and clean
  • Explicitly enabling -Dbluez5=enabled, -Dbluez5-codec-lhdc=enabled, aac/aptx/g722/lc3/ldac/opus, dbus, and libusb: ensures all required codecs and USB Bluetooth hardware quirks are built
  • --buildtype=release: enables -O3 optimization to reduce CPU usage during real-time Bluetooth audio encoding
  • --wrap-mode=nodownload: prevents Meson from downloading subprojects online, ensuring all dependencies come from the system and the newly installed liblhdcv5
  • rm -rf build: cleans up any leftover build directory from earlier failed attempts (e.g., missing ldacBT-abr) for a fresh configuration

2.6 Checking BlueZ5 Backend Status in config.h

grep -i BLUEZ /home/nanami114/workspace/lhdc/pipewire/build/config.h

Full output

#define HAVE_BLUEZ_5_BACKEND_BLUEZ_TELEPHONY
#define HAVE_BLUEZ_5_BACKEND_HFP_NATIVE
#define HAVE_BLUEZ_5_BACKEND_HSPHFPD
#define HAVE_BLUEZ_5_BACKEND_HSP_NATIVE
#define HAVE_BLUEZ_5_BACKEND_NATIVE
#undef HAVE_BLUEZ_5_BACKEND_NATIVE_MM
#define HAVE_BLUEZ_5_BACKEND_OFONO
#define HAVE_BLUEZ_5_HCI

2.7 Building All 15 BlueZ5 SPA Plugins Directly

By passing only the 15 .so targets under spa/plugins/bluez5/ to ninja, you skip compiling unrelated PipeWire daemons and tools. All 15 must be built (especially the 4 hfp-* plugins) because, as upstream codec-loader.c shows, PipeWire 1.7.0 split HFP codecs out of the main library into separate .so files and the loader enforces has_sbc && has_cvsd—missing even libspa-codec-bluez5-hfp-cvsd.so causes the entire BlueZ5 plugin to fail initialization. CCACHE_DISABLE=1 is added because ~/.cache/ccache is read-only in a sandbox environment, allowing the build to finish cleanly.

CCACHE_DISABLE=1 ninja -C ./pipewire/build spa/plugins/bluez5/libspa-bluez5.so spa/plugins/bluez5/libspa-codec-bluez5-sbc.so spa/plugins/bluez5/libspa-codec-bluez5-faststream.so spa/plugins/bluez5/libspa-codec-bluez5-hfp-cvsd.so spa/plugins/bluez5/libspa-codec-bluez5-hfp-msbc.so spa/plugins/bluez5/libspa-codec-bluez5-aac.so spa/plugins/bluez5/libspa-codec-bluez5-aptx.so spa/plugins/bluez5/libspa-codec-bluez5-ldac.so spa/plugins/bluez5/libspa-codec-bluez5-lhdc.so spa/plugins/bluez5/libspa-codec-bluez5-opus.so spa/plugins/bluez5/libspa-codec-bluez5-opus-g.so spa/plugins/bluez5/libspa-codec-bluez5-lc3.so spa/plugins/bluez5/libspa-codec-bluez5-hfp-lc3-swb.so spa/plugins/bluez5/libspa-codec-bluez5-hfp-lc3-a127.so spa/plugins/bluez5/libspa-codec-bluez5-g722.so

2.8 Verifying Dynamic Linking and Symbol Resolution with ldd -r

ldd -r ./pipewire/build/spa/plugins/bluez5/libspa-codec-bluez5-lhdc.so && ldd -r ./pipewire/build/spa/plugins/bluez5/libspa-bluez5.so

Full output

	linux-vdso.so.1 (0x00007f57d8e7b000)
	liblhdcv5.so => /usr/local/lib/x86_64-linux-gnu/liblhdcv5.so (0x00007f57d8ce5000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f57d8abc000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f57d89cc000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f57d899f000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f57d8e7d000)
	linux-vdso.so.1 (0x00007fad5ba7f000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fad5b81e000)
	libdbus-1.so.3 => /lib/x86_64-linux-gnu/libdbus-1.so.3 (0x00007fad5b7c7000)
	libbluetooth.so.3 => /lib/x86_64-linux-gnu/libbluetooth.so.3 (0x00007fad5b797000)
	libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fad5b63e000)
	libgio-2.0.so.0 => /lib/x86_64-linux-gnu/libgio-2.0.so.0 (0x00007fad5b444000)
	libgobject-2.0.so.0 => /lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007fad5b3e1000)
	libusb-1.0.so.0 => /lib/x86_64-linux-gnu/libusb-1.0.so.0 (0x00007fad5b3c1000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fad5b1cd000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fad5ba81000)
	libsystemd.so.0 => /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007fad5b0b7000)
	libatomic.so.1 => /lib/x86_64-linux-gnu/libatomic.so.1 (0x00007fad5b0ab000)
	libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007fad5affc000)
	libgmodule-2.0.so.0 => /lib/x86_64-linux-gnu/libgmodule-2.0.so.0 (0x00007fad5aff5000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fad5afd5000)
	libmount.so.1 => /lib/x86_64-linux-gnu/libmount.so.1 (0x00007fad5af59000)
	libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007fad5af25000)
	libffi.so.8 => /lib/x86_64-linux-gnu/libffi.so.8 (0x00007fad5af16000)
	libudev.so.1 => /lib/x86_64-linux-gnu/libudev.so.1 (0x00007fad5aed1000)
	libcap.so.2 => /lib/x86_64-linux-gnu/libcap.so.2 (0x00007fad5aec5000)
	libblkid.so.1 => /lib/x86_64-linux-gnu/libblkid.so.1 (0x00007fad5ae64000)

2.9 Installing the BlueZ5 SPA Plugin Overlay to a Separate Directory

Q. Why do it this way? A. Installing into /usr/local/lib/x86_64-linux-gnu/spa-0.2-lhdc/bluez5/ instead of overwriting /usr/lib/x86_64-linux-gnu/spa-0.2/bluez5/ avoids file conflicts with the libspa-0.2-bluetooth apt package (so future apt upgrade runs won’t wipe out your LHDCv5 plugins) and lets you roll back to the stock plugins instantly by removing the environment variable override.

sudo install -d -m 755 /usr/local/lib/x86_64-linux-gnu/spa-0.2-lhdc/bluez5 && sudo install -m 755 ./pipewire/build/spa/plugins/bluez5/libspa-bluez5.so ./pipewire/build/spa/plugins/bluez5/libspa-codec-bluez5-*.so /usr/local/lib/x86_64-linux-gnu/spa-0.2-lhdc/bluez5/

2.10 Installing the bluez-hardware.conf Data File

Inspecting build/config.h revealed that because Meson was configured with --prefix=/usr/local, the SPADATADIR constant compiled into libspa-bluez5.so is /usr/local/share/spa-0.2 (rather than /usr/share/spa-0.2). Without copying upstream bluez-hardware.conf (which holds hardware quirk rules for Bluetooth adapters and headphones) into /usr/local/share/spa-0.2/bluez5/, the plugin cannot load those compatibility rules at runtime.

sudo install -Dm644 ./pipewire/spa/plugins/bluez5/bluez-hardware.conf /usr/local/share/spa-0.2/bluez5/bluez-hardware.conf

At this point, the PipeWire backend with LHDCv5 support is compiled and installed on your system.

3. Configuring systemd User Drop-ins and Pre-Restart Verification

3.1 Creating systemd User Drop-in Configs

You need to configure both wireplumber.service.d and pipewire.service.d, since both map api.bluez5.* = bluez5/libspa-bluez5. Although device enumeration and A2DP endpoints are mainly handled by wireplumber, setting the same SPA_PLUGIN_DIR on pipewire.service ensures both load the exact same set of BlueZ5 SPA plugins and avoids version mismatches. Create the following two files:

  • ~/.config/systemd/user/wireplumber.service.d/50-lhdc.conf
  • ~/.config/systemd/user/pipewire.service.d/50-lhdc.conf

Fill in the following:

[Service]
Environment=SPA_PLUGIN_DIR=/usr/local/lib/x86_64-linux-gnu/spa-0.2-lhdc:/usr/lib/x86_64-linux-gnu/spa-0.2

3.2 Verifying the Installed LHDCv5 and BlueZ5 Plugins

spa-inspect /usr/local/lib/x86_64-linux-gnu/spa-0.2-lhdc/bluez5/libspa-codec-bluez5-lhdc.so && spa-inspect /usr/local/lib/x86_64-linux-gnu/spa-0.2-lhdc/bluez5/libspa-bluez5.so

Full output

factory version:		1
factory name:		'api.codec.bluez5.media.lhdc'
factory info:
  flags:00000000 n_items:1
    factory.description = "Bluetooth codec plugin"
factory interfaces:
 > interface: 'Spa:Pointer:Interface:Bluez5:Codec:Media:Private'
factory instance:
 > interface: 'Spa:Pointer:Interface:Bluez5:Codec:Media:Private'
skipping unknown interface
factory version:		1
factory name:		'api.bluez5.enum.dbus'
factory info:
  none
factory interfaces:
 > interface: 'Spa:Pointer:Interface:Device'
[E] spa.bluez5 [bluez5-dbus.c:7902 impl_init()] a dbus is needed
can't make factory instance: -22
factory version:		1
factory name:		'api.bluez5.device'
factory info:
  flags:00000000 n_items:3
    factory.author = "Wim Taymans <wim.taymans@gmail.com>"
    factory.description = "A bluetooth device"
    factory.usage = "api.bluez5.device=<device>"
factory interfaces:
 > interface: 'Spa:Pointer:Interface:Device'
can't make factory instance: -116
factory version:		1
factory name:		'api.bluez5.media.sink'
factory info:
  flags:00000000 n_items:3
    factory.author = "Wim Taymans <wim.taymans@gmail.com>"
    factory.description = "Play audio with the media"
    factory.usage = "api.bluez5.transport=<transport>"
factory interfaces:
 > interface: 'Spa:Pointer:Interface:Node'
[E] spa.bluez5.sink.media [media-sink.c:3099 impl_init()] a data system is needed
can't make factory instance: -22
factory version:		1
factory name:		'api.bluez5.media.source'
factory info:
  flags:00000000 n_items:3
    factory.author = "Collabora Ltd. <contact@collabora.com>"
    factory.description = "Capture bluetooth audio with media"
    factory.usage = "api.bluez5.transport=<transport>"
factory interfaces:
 > interface: 'Spa:Pointer:Interface:Node'
[E] spa.bluez5.source.media [media-source.c:2196 impl_init()] a data system is needed
can't make factory instance: -22
factory version:		1
factory name:		'api.bluez5.sco.sink'
factory info:
  flags:00000000 n_items:3
    factory.author = "Wim Taymans <wim.taymans@gmail.com>"
    factory.description = "Play audio with the media"
    factory.usage = "api.bluez5.transport=<transport>"
factory interfaces:
 > interface: 'Spa:Pointer:Interface:Node'
[E] spa.bluez5.sink.media [media-sink.c:3099 impl_init()] a data system is needed
can't make factory instance: -22
factory version:		1
factory name:		'api.bluez5.sco.source'
factory info:
  flags:00000000 n_items:3
    factory.author = "Collabora Ltd. <contact@collabora.com>"
    factory.description = "Capture bluetooth audio with media"
    factory.usage = "api.bluez5.transport=<transport>"
factory interfaces:
 > interface: 'Spa:Pointer:Interface:Node'
[E] spa.bluez5.source.media [media-source.c:2196 impl_init()] a data system is needed
can't make factory instance: -22
factory version:		1
factory name:		'api.bluez5.a2dp.sink'
factory info:
 flags:00000000 n_items:3
    factory.author = "Wim Taymans <wim.taymans@gmail.com>"
    factory.description = "Play audio with the media"
    factory.usage = "api.bluez5.transport=<transport>"
factory interfaces:
 > interface: 'Spa:Pointer:Interface:Node'
[E] spa.bluez5.sink.media [media-sink.c:3099 impl_init()] a data system is needed
can't make factory instance: -22
factory version:		1
factory name:		'api.bluez5.a2dp.source'
factory info:
  flags:00000000 n_items:3
    factory.author = "Collabora Ltd. <contact@collabora.com>"
    factory.description = "Capture bluetooth audio with media"
    factory.usage = "api.bluez5.transport=<transport>"
factory interfaces:
 > interface: 'Spa:Pointer:Interface:Node'
[E] spa.bluez5.source.media [media-source.c:2196 impl_init()] a data system is needed
can't make factory instance: -22
factory version:		1
factory name:		'api.bluez5.midi.enum'
factory info:
  flags:00000000 n_items:2
    factory.author = "Pauli Virtanen <pav@iki.fi>"
    factory.description = "Bluez5 MIDI connection"
factory interfaces:
 > interface: 'Spa:Pointer:Interface:Device'
[E] spa.bluez5.midi [midi-enum.c:806 impl_init()] Glib mainloop is not usable: api.glib.mainloop not set
can't make factory instance: -22
factory version:		1
factory name:		'api.bluez5.midi.node'
factory info:
  flags:00000000 n_items:2
    factory.author = "Pauli Virtanen <pav@iki.fi>"
    factory.description = "Bluez5 MIDI connection"
factory interfaces:
 > interface: 'Spa:Pointer:Interface:Node'
[E] spa.bluez5.midi.node [midi-node.c:1942 impl_init()] Glib mainloop is not usable: api.glib.mainloop not set
can't make factory instance: -22

As you can see, both the LHDCv5 and BlueZ5 plugins are properly installed.

Note: Before going further, check your PipeWire backend version. Anything older than 1.6 will fail to load. Update your PipeWire runtime to 1.6 or newer:

sudo apt-get install -y -t trixie-backports pipewire pipewire-bin pipewire-pulse libpipewire-0.3-0t64 libspa-0.2-modules libspa-0.2-bluetooth gstreamer1.0-pipewire

Q. Why? A. PipeWire 1.6 added the locked method (spa_loop_locked()) to spa_loop_methods and bumped SPA_VERSION_LOOP_CONTROL from 1 to 2. Upstream media-sink.c calls spa_loop_locked() repeatedly when starting or stopping Bluetooth transports, whereas older libspa-support.so builds lack that function pointer, returning -ENOTSUP and triggering a crash. This also explains why you cannot drop 1.7.0’s libspa-support.so into the overlay: the 1.6+ loop enter/leave/iterate locking semantics are incompatible with older libpipewire versions and will deadlock if mixed. Upgrading the PipeWire runtime to >= 1.6 is the only proper fix.

4. Restarting and Testing

4.1 Restarting User-Level PipeWire Services

systemctl --user daemon-reload && systemctl --user restart pipewire pipewire-pulse wireplumber

4.2 Checking the Running wireplumber Process Memory Maps

grep -E 'bluez5|lhdcv5' /proc/1170567/maps | awk '{print $6}' | sort -u

Full output

/usr/local/lib/x86_64-linux-gnu/liblhdcv5.so
/usr/local/lib/x86_64-linux-gnu/spa-0.2-lhdc/bluez5/libspa-bluez5.so
/usr/local/lib/x86_64-linux-gnu/spa-0.2-lhdc/bluez5/libspa-codec-bluez5-aac.so
/usr/local/lib/x86_64-linux-gnu/spa-0.2-lhdc/bluez5/libspa-codec-bluez5-aptx.so
/usr/local/lib/x86_64-linux-gnu/spa-0.2-lhdc/bluez5/libspa-codec-bluez5-faststream.so
/usr/local/lib/x86_64-linux-gnu/spa-0.2-lhdc/bluez5/libspa-codec-bluez5-g722.so
/usr/local/lib/x86_64-linux-gnu/spa-0.2-lhdc/bluez5/libspa-codec-bluez5-hfp-cvsd.so
/usr/local/lib/x86_64-linux-gnu/spa-0.2-lhdc/bluez5/libspa-codec-bluez5-hfp-lc3-a127.so
/usr/local/lib/x86_64-linux-gnu/spa-0.2-lhdc/bluez5/libspa-codec-bluez5-hfp-lc3-swb.so
/usr/local/lib/x86_64-linux-gnu/spa-0.2-lhdc/bluez5/libspa-codec-bluez5-hfp-msbc.so
/usr/local/lib/x86_64-linux-gnu/spa-0.2-lhdc/bluez5/libspa-codec-bluez5-lc3.so
/usr/local/lib/x86_64-linux-gnu/spa-0.2-lhdc/bluez5/libspa-codec-bluez5-ldac.so
/usr/local/lib/x86_64-linux-gnu/spa-0.2-lhdc/bluez5/libspa-codec-bluez5-lhdc.so
/usr/local/lib/x86_64-linux-gnu/spa-0.2-lhdc/bluez5/libspa-codec-bluez5-opus-g.so
/usr/local/lib/x86_64-linux-gnu/spa-0.2-lhdc/bluez5/libspa-codec-bluez5-opus.so
/usr/local/lib/x86_64-linux-gnu/spa-0.2-lhdc/bluez5/libspa-codec-bluez5-sbc.so

Here you can clearly see that the 15 BlueZ5 SPA plugins from the overlay have replaced the old system plugins in memory, and /usr/local/lib/x86_64-linux-gnu/liblhdcv5.so is mapped alongside libspa-codec-bluez5-lhdc.so.

4.3 Final Verification

Reconnect your Bluetooth earbuds and open the system audio settings:

Audio Settings
Audio Settings
SBC, SBC-XQ, AAC, and LHDC v5 all appear in the codec list, and audio plays normally after switching. Check the audio device details using pw-cli:

       id: 44  
       permissions: rwxm-  
       type: PipeWire:Interface:Node/3  
*       input ports: 2/129  
*       output ports: 2/0  
*       state: "suspended"  
*       properties:  
*               api.bluez5.address = "***"  
*               api.bluez5.codec = "lhdc_v5"  
*               api.bluez5.profile = "a2dp-sink"  
*               api.bluez5.transport = "18"  
*               bluez5.loopback = "false"  
*               card.profile.device = "1"  
*               device.id = "100"  
*               device.routes = "1"  
*               factory.name = "api.bluez5.a2dp.sink"  
*               node.description = "OPPO Enco X3"  
*               node.name = "bluez_output.***.1"  
*               node.pause-on-idle = "false"  
*               priority.driver = "1010"  
*               priority.session = "1010"  
*               spa.object.id = "1"  
*               factory.id = "12"  
*               clock.quantum-limit = "8192"  
*               device.api = "bluez5"  
*               media.class = "Audio/Sink"  
*               media.name = "OPPO Enco X3"  
*               node.driver = "true"  
*               port.group = "stream.0"  
*               node.loop.name = "data-loop.0"  
*               library.name = "audioconvert/libspa-audioconvert"  
*               object.id = "44"  
*               object.serial = "1548"  
*               client.id = "62"  
*       params: (9)  
*         3 (Spa:Enum:ParamId:EnumFormat) r-  
*         1 (Spa:Enum:ParamId:PropInfo) r-  
*         2 (Spa:Enum:ParamId:Props) rw  
*         4 (Spa:Enum:ParamId:Format) -w  
*         10 (Spa:Enum:ParamId:EnumPortConfig) r-  
*         11 (Spa:Enum:ParamId:PortConfig) rw  
*         15 (Spa:Enum:ParamId:Latency) rw  
*         16 (Spa:Enum:ParamId:ProcessLatency) rw  
*         17 (Spa:Enum:ParamId:Tag) rw

As shown above, the Bluetooth audio codec has switched to lhdc_v5. Check the audio stream parameters with pw-top:

S24LE 2 48000 bluez_output.***.1

You can see that a 2CH, 48000Hz audio profile is active. That wraps up this guide on compiling additional Bluetooth audio codecs for PipeWire.


Afterword

I’m not a professional, so please point out any mistakes or omissions! If you found this article helpful, please share it with someone who needs it. Thanks for reading!

If you enjoyed this, leave a comment~

Random Posts

Loading...