Skip to content

Instantly share code, notes, and snippets.

@ford-prefect
Last active March 14, 2024 07:54
Show Gist options
  • Save ford-prefect/924cb946631d82c8195b464a7be21d53 to your computer and use it in GitHub Desktop.
Save ford-prefect/924cb946631d82c8195b464a7be21d53 to your computer and use it in GitHub Desktop.
Hacking on PulseAudio

Let's take the example of needing to build webrtc-audio-processing with some changes, and then PA against that

Building webrtc-audio-processing

This follows standard the autotools procedure for a prefixed installation:

  • Checkout the code, cd in
  • ./autogen.sh --prefix=${HOME}/prefix/webrtc-audio-processing
  • make && make install

There is now a standard install in ~/prefix/webrtc-audio-processing and we can use pkg-config to pick up that path for headers and libs using $PKG_CONFIG_PATH in the environment. This trick works with any library that provides pkg-config files.

Building pulseaudio

If you don't already have it, you might want the required dependencies from your distro using sudo apt-get build-dep pulseaudio on Debian or sudo dnf builddep pulseaudio on Fedora.

We'll also run the build in a separate directory this time, so it's easy to wipe it out and create a fresh build without having to muck around with the checked out code.

  • Checkout the code, cd in
  • `NOCONFIGURE=1 ./bootstrap.sh
  • mkdir build && cd build
  • ../configure --prefix=$HOME/prefix/pulseaudio --localstatedir=/var --with-udev-rules-dir='${prefix}/lib/udev/rules.d' --with-systemduserunitdir='${prefix}/lib/systemd/user' --sysconfdir=/etc PKG_CONFIG_PATH=$HOME/local/webrtc-audio-processing/lib/pkgconfig
  • make
  • ./src/pulseaudio -vvv

That's it!

  • The --localstatedir=/var makes it so existing applications will continue to look in /var/... for the PA socket
  • The udev and systemd rules dir overrides make sure we don't write to system directories
  • Using --sysconfdir=/etc allows us to just pick up the system config without doing a make install. If you plan to do a prefixed install, skip this flag so you don't overwrite system config.

Misc. tips

  • pactl info tells you a bunch of things about the running instance
  • PULSE_SERVER in the environment lets you configure what PA instance your app should talk to
    • Pro-tip: this can also be a PA instance on the network with module-native-protocol-tcp loaded (you might want to set auth-anonymous=true in modargs if you don't want to worry about pesky security concerns)
    • Pro-tip 2: this means you can also run pavucontrol on your desktop against PA on your device
  • pactl list sinks short (also works for other objects) gives you a quick way to look up devices without getting lost in the full pactl list output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment