Skip to content

Instantly share code, notes, and snippets.

@the-spyke
Last active May 3, 2024 13:19
Show Gist options
  • Save the-spyke/2de98b22ff4f978ebf0650c90e82027e to your computer and use it in GitHub Desktop.
Save the-spyke/2de98b22ff4f978ebf0650c90e82027e to your computer and use it in GitHub Desktop.
Enable PipeWire on Ubuntu 22.04

Enable PipeWire on Ubuntu 22.04

This guide is only for original Ubuntu out-of-the-box packages. If you have added a custom PPA like pipewire-debian, you might get into conflicts.

Ubuntu 22.04 has PipeWire partially installed and enabled as it's used by browsers (WebRTC) for recoding the screeen under Wayland. We can enable remaining parts and use PipeWire for audio and Bluetooth instead of PulseAudio.

Starting from WirePlumber version 0.4.8 automatic Bluetooth profile switching (e.g. switching from A2DP to HSP/HFP when an application needs microphone access) is supported. Jammy (22.04) repos provide exactly version 0.4.8. So, we're good.

Based on Debian Wiki, but simplified for Ubuntu 22.04.

Install

Install WirePlumber as the session manager:

$ sudo apt install pipewire-media-session- wireplumber

Notice '-' at the end of 'pipewire-media-session'. This is to remove it in the same command, because 'wireplumber' will be used instead.

Start WirePlumber for your user:

$ systemctl --user --now enable wireplumber.service

Configure

ALSA

Install the ALSA plug-in:

$ sudo apt install pipewire-audio-client-libraries

And copy the config file from PipeWire docs (provided by the plug-in) into the ALSA configuration directory:

$ sudo cp /usr/share/doc/pipewire/examples/alsa.conf.d/99-pipewire-default.conf /etc/alsa/conf.d/

Check if you have other (like Pulse) configs in the /etc/alsa/conf.d/ installed by something else. You might want to remove them.

PulseAudio

Everything was done automatically by pipewire-pulse package, which should have been installed by wireplumber package as recommended. If not, install it yourself.

Bluetooth

Install the codecs and remove Bluetooth from PulseAudio, so it would be handled directly by PipeWire:

$ sudo apt install libldacbt-{abr,enc}2 libspa-0.2-bluetooth pulseaudio-module-bluetooth-

The supported codecs are SBC and LDAC.

Unfortunately, aptX and AAC are not supported because of patents and other technical reasons. aptX is available starting from 22.10 via libfreeaptx0 installed by default there (22.10 uses PipeWire by default as well). If you really need these codecs in 22.04 you may use this PPA from @aglasgall which is based on universe, but rebuilds pipewire with additional packages for aptX and AAC from multiverse. Read the discussion here.

Done

Reboot and check if it works by running:

$ LANG=C pactl info | grep '^Server Name'
@the-spyke
Copy link
Author

@joihn Yes, PulseAudio is not removed, just disabled by pipewire-pulse. Have you tried with the stock packages? A2DP should work with SBC.

@mandofrog
Copy link

Tutorial said:

Check if you have other (like Pulse) configs in the /etc/alsa/conf.d/ installed by something else. You might want to remove them.

@joihn said:

followed the whole tutorial described by @the-spyke in the first post, ----> in /etc/alsa/conf.d, I removed everything non-pipewire related (was it a good idea ?)

OK, once more for the noob in the back . . .
My /etc/alsa/conf.d has 13 files:
10-samplerate.conf
10-speexrate.conf
50-arcam-av-ctl.conf
50-jack.conf
50-oss.conf
50-pipewire.conf
50-pulseaudio.conf
60-upmix.conf
60-vdownmix.conf
98-usb-stream.conf
99-pipewire-default.conf
99-pulseaudio-default.conf.example
99-pulse.conf

99-pipewire-default.conf is the only new file. All the rest are dated January to March '22 (I got Ubuntu Studio 22.04 LTS running just a couple weeks ago and I'm still trying to make heads or tails of it all) Do I remove all the rest? or just the 3 labeled Pulse? The old 50-pipewire.conf? Would it work to rename them (i.e. 10-samplerate.conf.bak or 99-pulse.conf.bak)? Or maybe move to another directory?

Thanks for the tutorial, and thanks for the patience.

@the-spyke
Copy link
Author

@mandofrog The idea was that you might have conflicting configs because you (or some package) have created them before. For example, in your case both 99-pipewire-default.conf and 99-pulse.conf have the same priority which may lead to conflicts. My 23.10 system (which began as a fresh 22.10, so PipeWire out of the box) has only 2 files there:

$ ll /etc/alsa/conf.d
total 8
drwxr-xr-x 1 root root 80 Nov  2 18:11 ./
drwxr-xr-x 1 root root 12 Apr 21  2023 ../
lrwxrwxrwx 1 root root 44 Sep 11 12:12 50-pipewire.conf -> /usr/share/alsa/alsa.conf.d/50-pipewire.conf
lrwxrwxrwx 1 root root 52 Sep 11 12:12 99-pipewire-default.conf -> /usr/share/alsa/alsa.conf.d/99-pipewire-default.conf

I am not an expert in ALSA, but PipeWire replaces both PulseAudio and JACK. So, I would guess their configs are not needed. You may try to move all non-pipewire files to some temporary directory, reboot, and check if everything works fine. Not sure where files like 50-arcam-av-ctl.conf come from.

@joihn Maybe you have a similar issue.

@aglasgall
Copy link

I do want to be extremely clear that the only change between the packages in my PPA and the ones from ubuntu main is that additional codecs are enabled at build time. I have not modified any configuration files - you can verify this yourself by grabbing the source package from the PPA if you want.

Does the headset you are using even support A2DP or is it monaural HSP/HFP only?

If you're running Ubuntu Studio instead of plain Ubuntu, JACK may also be involved, which complicates things; I know PipeWire is supposed to supplant both pulseaudio and JACK but I don't know much about the details.

@joihn
Copy link

joihn commented Nov 28, 2023

thank you for your kind support @aglasgall @the-spyke 🙂

I am not an expert in ALSA, but PipeWire replaces both PulseAudio and JACK. So, I would guess their configs are not needed. You may try to move all non-pipewire files to some temporary directory, reboot, and check if everything works fine. Not sure where files like 50-arcam-av-ctl.conf come from.
@joihn Maybe you have a similar issue.

I too have the same files as you (and yes I did a reboot)

$ls /etc/alsa/conf.d 
50-pipewire.conf  99-pipewire-default.conf

Does the headset you are using even support A2DP or is it monaural HSP/HFP only?

I am sure the headset does support A2DP. I did previously work with AD2P under pulseaudio.

@joihn
Copy link

joihn commented Dec 1, 2023

SOLVED my issue with Ad2p not beeing present (I previously had only sBMC availble) 🔥
Now Ad2p with AAC is working well, thanks everyone :)

Did not work

forgetting the device, repairing

worked

sudo cp -r /var/lib/bluetooth /var/lib/bluetooth_BACKUP
sudo systemctl stop bluetooth
sudo rm -rf /var/lib/bluetooth/*
sudo systemctl start bluetooth
sudo reboot

then re-pair the device

@the-spyke
Copy link
Author

@joihn Congrats and thank you for sharing the solution.

For everyone on newer systems, here is a snipped to enable bluetooth headset battery reporting. Not sure about version requirements, but works on 23.10:

Bluetooth headset battery:
1. sudo micro /etc/bluetooth/main.conf
   and add Experimental=true
2. sudo micro /lib/systemd/system/bluetooth.service
   and add the --experimental exec option
3. sudo systemctl daemon-reload
4. sudo systemctl restart bluetooth

@federerfanatic
Copy link

Nice work.

@r-egorov
Copy link

Hey! Thanks for the tutorial!
I followed it and have the following codecs available!

Image

image

SBC seems to have much better sound quality than the stock codecs.

However, I am experiencing issues with the microphone from my bluetooth headset now. I am unnable to choose my headset as the Input device. When I choose something else from HSP/HFP for my headset the Internal Microphone is selected automatically as the Input device.

When I choose my bluetooth headset there, the output codec HSP/HFP is chosen automatically. And the microphone quality is really bad.
What can I do?

@the-spyke
Copy link
Author

@r-egorov SBC is the default Bluetooth codec, so the option without codec name might be the same as codec SBC. Regarding the microphone, this is a limitation of the current Bluetooth implementation. For the microphone to work you need to use a headset profile, but this profile has a very low listening audio quality and it is mono. iPhones and some other devices have more advanced A2DP implementations with back channels to overcome this. So, currently on Linux to get a great headset (like for games) you need to buy something with a USB dongle.

@joihn
Copy link

joihn commented Jan 22, 2024

after installing pipewire, unrelated cupsd service crash once a day with a related message
sudo cat /var/crash/_usr_sbin_cupsd.0.crash | grep -C 50 ' Main process exited'

Disassembly:
 => 0x7f0968c8f177 <_cups_safe_vsnprintf+1511>:	movzbl (%rcx),%eax
    0x7f0968c8f17a <_cups_safe_vsnprintf+1514>:	test   %al,%al
    0x7f0968c8f17c <_cups_safe_vsnprintf+1516>:	setne  %dl
    0x7f0968c8f17f <_cups_safe_vsnprintf+1519>:	mov    0x8(%rsp),%rsi
    0x7f0968c8f184 <_cups_safe_vsnprintf+1524>:	sub    $0x1,%rsi
    0x7f0968c8f188 <_cups_safe_vsnprintf+1528>:	cmp    %r12,%rsi
    0x7f0968c8f18b <_cups_safe_vsnprintf+1531>:	jbe    0x7f0968c8ec1e <_cups_safe_vsnprintf+142>
    0x7f0968c8f191 <_cups_safe_vsnprintf+1537>:	test   %dl,%dl
    0x7f0968c8f193 <_cups_safe_vsnprintf+1539>:	je     0x7f0968c8ec1e <_cups_safe_vsnprintf+142>
    0x7f0968c8f199 <_cups_safe_vsnprintf+1545>:	cmp    $0x27,%al
    0x7f0968c8f19b <_cups_safe_vsnprintf+1547>:	jg     0x7f0968c8f240 <_cups_safe_vsnprintf+1712>
    0x7f0968c8f1a1 <_cups_safe_vsnprintf+1553>:	nopl   0x0(%rax)
    0x7f0968c8f1a8 <_cups_safe_vsnprintf+1560>:	cmp    $0x8,%al
    0x7f0968c8f1aa <_cups_safe_vsnprintf+1562>:	jle    0x7f0968c8f1d0 <_cups_safe_vsnprintf+1600>
    0x7f0968c8f1ac <_cups_safe_vsnprintf+1564>:	lea    -0x9(%rax),%edx
    0x7f0968c8f1af <_cups_safe_vsnprintf+1567>:	cmp    $0x1e,%dl
InstallationDate: Installed on 2023-11-25 (58 days ago)
InstallationMedia: Ubuntu 22.04.3 LTS "Jammy Jellyfish" - Release amd64 (20230807.2)
JournalErrors:
 Jan 22 14:33:47 laptop pipewire-pulse[3554]: mod.protocol-pulse: server 0x55db3d1a7bf0: failed to create client: Connection refused
 Jan 22 14:33:47 laptop systemd[1]: cups.service: Main process exited, code=dumped, status=11/SEGV
 Jan 22 14:33:47 laptop systemd[1]: cups.service: Failed with result 'core-dump'.

@the-spyke
Copy link
Author

the-spyke commented Jan 22, 2024

@joihn Please open a bug on LaunchPad. I don't think we can help you here.

@joihn
Copy link

joihn commented Mar 9, 2024

Hello,
could anyone help me to revert back to normal ?

@the-spyke
Copy link
Author

@joihn All the steps, but backwards.

@joihn
Copy link

joihn commented Mar 9, 2024

I tried it last week and it broke my Ubuntu install, gnome could not boot anymore.
I had to revert back to a backup.
It might be due to the uninstall of pipewire?

@shackra
Copy link

shackra commented Apr 19, 2024

Would it be possible to connect input/output devices on a network? like barrier but for audio

there is a chance https://sonobus.net/ is the solution I'm looking for.

@K-Michallik
Copy link

I'm running Ubuntu 22.04 LTS currently with a set of Jabra 85's. Is it possible to use High Fidelity playback while using the headset microphone? Currently if I switch my input device to the headset, I lose the high quality audio (although the Sounds settings menu still displays it as active).

If not available in Ubuntu 22.04, is the functionality available in any version? I know it works fine in Windows 10/11

@the-spyke
Copy link
Author

@K-Michallik I haven't investigated this topic deeply myself yet. But as I understand the first option is to try mSBC. It should at least have better quality. And the full solution would be using a codec supporting duplex communications: FastStream, aptX Low Latency, LC3. But for this you need the headset to support it as well.

@eygraber
Copy link

I still don't have aac or aptx in the profile settings after updating to Ubuntu 24.04 from 22.04. I thought it would be natively supported because a liveusb I tried on my system did have it, but I guess not.

I followed these steps but that didn't help. Is ppa:aglasgall/pipewire-extra-bt-codecs the only way to get support for those codecs (even on 24.04)?

@aglasgall
Copy link

@eygraber , the PPA only works for distributions that I have built packages for; this is something I maintain in my spare time on a best effort basis. I had not built and uploaded packages for 24.04 because I did not have time.

I have uploaded pipewire packages for 24.04 with AAC enabled; they will be available for install sometime in the next hour.

The latest Ubuntu Pipewire packages do have AptX enabled already; if aptx doesn't show up as a codec option it is because your headset does not support it.

@eygraber
Copy link

@aglasgall thank you!

To clarify, I understood the PPA wouldn't work until you got to updating it. I hope that didn't come across as complaining that it wasn't available yet.

I think my headset supports AptX, so I have more digging to do. Might just do a fresh install after struggling with this for years.

@aglasgall
Copy link

Packages for 24.04 ("Noble Numbat") are up now.

@jojommeke
Copy link

can anyone please help me undoing this because it broke everything, i fixed it mostly, mic is now working and outpouting sound but i can't connect to my bluethooth speaker anymore pleae help me uninstall pipewire and use pulseaudio again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment