Skip to content

Instantly share code, notes, and snippets.

@the-spyke
Last active April 23, 2024 20:48
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'
@fir3-1ce
Copy link

After some time using this, I'm wondering what is the difference between pipewire-pulse and Pipewire in general? Am I missing some functionality over if I were using a distro that ships with Pipewire by default? My pactl info says I'm using this:

Server Name: PulseAudio (on PipeWire 0.3.48)

Why is Pulse even involved at all anymore? Hope this makes sense, I'm still learning about Linux audio and the Linux ecosystem in general

@the-spyke
Copy link
Author

the-spyke commented Sep 16, 2023

@fir3-1ce With pipewire-pulse your PulseAudio server is disabled and Pipewire takes its place. So, pactl thinks it connects to PA, but it's PW in disguise.

@Dephrilibrium
Copy link

Dephrilibrium commented Sep 16, 2023

Heyho,

had exactly that problem with my setup and this solution worked for me.

  • Ubuntu Server 22.04
  • with kde-plasma-desktop on top
  • trying to connect a UE Megaboom 3 via bluetooth

Thanks a lot.

Kind regards,
Deph

@aglasgall
Copy link

I have built and uploaded packages for Ubuntu 23.10 "mantic", which entered beta today, to the PPA.

@basert
Copy link

basert commented Oct 1, 2023

You are the MVP @aglasgall! Thanks for your awesome work! You have a link to buy you a coffee, pizza or beer?

@aglasgall
Copy link

@basert I suppose I can dig up a venmo or something if you really insist, but I really don't want to incur an obligation here. I build these packages when I have time; I cannot promise I will be able to do so indefinitely!

That being said, the source packages with my changes are available from the PPA, so if I ever do drift away from this, you just need to find someone who knows how to do Debian packaging.

@aglasgall
Copy link

I missed something in the packages I initially uploaded to the PPA for 23.10, and they lacked AAC support as a result. I've uploaded new ones that do have AAC support; if you have the PPA enabled, you'll get them the next time you do a package update.

@unoexperto
Copy link

Hi folks,

I'm on Ubuntu 23.04. I'm unable to install pipewire-audio. I get following errors. Any idea how to fix it ?

The following packages have unmet dependencies.
 libspa-0.2-bluetooth : Depends: libspa-0.2-modules (= 0.3.65-4~glasgall1) but 0.3.66-8~ubuntu22.04 is to be installed
 pipewire-alsa : Depends: pipewire (= 0.3.65-4~glasgall1) but 0.3.66-8~ubuntu22.04 is to be installed
                 Depends: libpipewire-0.3-0 (= 0.3.65-4~glasgall1) but 0.3.66-8~ubuntu22.04 is to be installed
E: Unable to correct problems, you have held broken packages.

@the-spyke
Copy link
Author

@unoexperto Ubuntu 23.04 and later has PipeWire out of the box. Looks like you are using the PPA from @aglasgall to get AAC support, but there are some conflicts as apt tries to install ubuntu22.04 version for some reason. You can try to remove related PPAs and use canonical packages using the ppa-purge utility. Or try to resolve conflicts yourself.

@joihn
Copy link

joihn commented Nov 26, 2023

Hello everyone,
Thanks for this tutorial,
It didn't work correctly for me.

goal

connect to my headset via bluetooth + AAC

env

ubuntu 22.04.

steps I did

add @aglasgall ppa

sudo add-apt-repository ppa:aglasgall/pipewire-extra-bt-codecs
sudo apt update

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 ?)

10-samplerate.conf                  deleted
50-arcam-av-ctl.conf                deleted  
50-oss.conf                              deleted
50-pulseaudio.conf                  deleted
60-vdownmix.conf                    deleted
99-pipewire-default.conf           deleted      
99-pulse.conf deleted               kept
10-speexrate.conf                   deleted
50-jack.conf                             deleted
50-pipewire.conf                      kept
60-upmix.conf                          deleted
98-usb-stream.conf                  deleted
99-pulseaudio-default.conf.example deleted

I rebooted. I think I succesfully installed pipewire

$LANG=C pactl info | grep '^Server Name'
Server Name: PulseAudio (on PipeWire 0.3.48)

Issue

After applying the steps, I can connect to the headset, however, I only have a low quality, mono sound, option available.
Untitled

@the-spyke
Copy link
Author

@joihn Unfortunately, I haven't tried AAC myself. But, please check if you have several output devices and one of them may have a High Fidelity Playback configuration. A mono is usually for a "handsfree" mode when you are also use the microphone. I don't think Linux supports full quality sound in this mode (with stereo SBC, AAC, or other codec). Only in the A2DP mode.

@joihn
Copy link

joihn commented Nov 27, 2023

I can confirm this is the only mode I have access to. No AD2P mode unfortunately.
I noticed I still have some pulse package installed, is it normal ?

$apt list --installed | grep pulse

gstreamer1.0-pulseaudio/jammy-updates,jammy-security,now 1.20.3-0ubuntu1.1 amd64 [installed,automatic]
libcanberra-pulse/jammy-updates,now 0.30-10ubuntu1.22.04.1 amd64 [installed,automatic]
libkf5pulseaudioqt3/jammy,now 1.3-2 amd64 [installed,automatic]
libpulse-mainloop-glib0/jammy-updates,now 1:15.99.1+dfsg1-1ubuntu2.1 amd64 [installed,automatic]
libpulse0/jammy-updates,now 1:15.99.1+dfsg1-1ubuntu2.1 amd64 [installed,automatic]
libpulsedsp/jammy-updates,now 1:15.99.1+dfsg1-1ubuntu2.1 amd64 [installed,automatic]
pipewire-pulse/jammy,now 0.3.48-2~glasgall2 amd64 [installed,automatic]
pulseaudio-utils/jammy-updates,now 1:15.99.1+dfsg1-1ubuntu2.1 amd64 [installed,automatic]
pulseaudio/jammy-updates,now 1:15.99.1+dfsg1-1ubuntu2.1 amd64 [installed,automatic]

@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.

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