PipeWire: Difference between revisions

From Alpine Linux
(I found out I needed the with-alsa file to get pipewire to play)
(Encourage the use of wireplumber as the session manager (pipewire-media-session will be deprecated at some point))
(13 intermediate revisions by 7 users not shown)
Line 7: Line 7:
=== Audio Group ===
=== Audio Group ===


Add your normal user to the <code>audio</code> group. The user must log in for this to take effect.
When elogind is not available, the user has to be added to the <code>audio</code> group. The user must log in for this to take effect.


<pre>
<pre>
# addgroup audio <user>
# addgroup <user> audio
</pre>
</pre>


Line 30: Line 30:
=== XDG_RUNTIME_DIR ===
=== XDG_RUNTIME_DIR ===


If you are not using a Desktop Manager, ensure that your <code>XDG_RUNTIME_DIR</code> is set to a user-writable location. By default for pulseaudio this is <code>/run/user/1000/</code> or <code>/tmp</code>. If this is not set, pipewire will create a directory in your home folder instead, called <code>~/pulse</code>, and on attempting to run Pavucontrol or pactl, you will get the following error:
If you are not using a Desktop Manager, ensure that your <code>XDG_RUNTIME_DIR</code> is set to a user-writable location. By default for pulseaudio this is {{Path|/run/user/1000/}} or {{Path|/tmp}}. If this is not set, pipewire will create a directory in your home folder instead, called <code>~/pulse</code>, and on attempting to run Pavucontrol or pactl, you will get the following error:


<pre>
<pre>
Line 41: Line 41:


<pre>
<pre>
# apk add pipewire
# apk add pipewire wireplumber
</pre>
</pre>


Uncomment the following line in <code>/etc/pipewire/pipewire.conf</code>:
{{Note|Using [https://gitlab.freedesktop.org/pipewire/wireplumber WirePlumber] rather than the pipewire-media-session (which comes with pipewire) is [https://gitlab.freedesktop.org/pipewire/media-session/-/blob/master/README.md recommended] but not required.}}
 
Create a custom configuration file in {{Path|/etc/pipewire/pipewire.conf}}:


<pre>
<pre>
{ path = "/usr/bin/pipewire-media-session"  args = "" }
# mkdir /etc/pipewire
# cp /usr/share/pipewire/pipewire.conf /etc/pipewire/
</pre>
 
Add the following line to the <code>context.exec</code> section at the bottom of {{Path|/etc/pipewire/pipewire.conf}}:
 
<pre>
{ path = "wireplumber"  args = "" }
</pre>
</pre>


Line 59: Line 68:
=== ALSA ===
=== ALSA ===


If you used neither Jack or PulseAudio nor intend to.
If you use neither Jack nor PulseAudio and you don't intend to.


<pre>
<pre>
Line 73: Line 82:
</pre>
</pre>


To enable the PulseAudio daemon edit <code>/etc/pipewire/pipewire.conf</code> and uncomment the following line:
Uncomment the following line in {{Path|/etc/pipewire/pipewire.conf}}:


<pre>
<pre>
{ path = "/usr/bin/pipewire" args = "-c pipewire-pulse.conf" }
{ path = "/usr/bin/pipewire" args = "-c pipewire-pulse.conf" }
</pre>
</pre>
It should be automatically enabled.


=== JACK ===
=== JACK ===
Line 95: Line 106:


Video should work out-of-the-box with v4l2 devices (e.g. a lot of webcams) and [https://gstreamer.freedesktop.org/ GStreamer] applications.
Video should work out-of-the-box with v4l2 devices (e.g. a lot of webcams) and [https://gstreamer.freedesktop.org/ GStreamer] applications.
=== Bluetooth headset ===
Requires <code>pipewire-spa-bluez</code> package in addition to <code>pipewire-pulseaudio</code> daemon to be installed.
=== Automatic bluetooth profile selection ===
To automatically switch between HSP/HFP and A2DP profiles when an input stream is detected, set the bluez5.autoswitch-profile property to true:
<pre>
/etc/pipewire/media-session.d/bluez-monitor.conf
...
rules = [
    {
        ...
        actions = {
            update-props = {
                ...
                bluez5.autoswitch-profile = true
...
</pre>


=== Screen sharing on Wayland ===
=== Screen sharing on Wayland ===


You will need the right [https://github.com/flatpak/xdg-desktop-portal xdg-desktop-portal] backend for your desktop environment. Screen sharing is known to work on GNOME with <code>xdg-desktop-portal-gtk</code> and on KDE Plasma with <code>xdg-desktop-portal-kde</code> and Firefox.
You will need the right [https://github.com/flatpak/xdg-desktop-portal xdg-desktop-portal] backend for your desktop environment. Screen sharing is known to work on:
* GNOME with <code>xdg-desktop-portal-gtk</code>
* KDE Plasma with <code>xdg-desktop-portal-kde</code> and Firefox
* Sway with <code>xdg-desktop-portal-wlr</code> and Firefox


== Usage ==
== Usage ==
Line 111: Line 148:


<pre>
<pre>
# apk add pipewire-tools
$ pw-cat -p --list-targets
$ pw-cat -p --list-targets
</pre>
</pre>
Line 120: Line 158:
</pre>
</pre>


If you have a microphone test recording audio is working.
If you have a microphone test audio recording is working.


<pre>
<pre>
Line 139: Line 177:


If you are happy everything is working, make PipeWire start automatically when your X or Wayland session starts. For example, you could add the <code>pipewire</code> command to <code>~/.xinitrc</code> or your window manager's config file.
If you are happy everything is working, make PipeWire start automatically when your X or Wayland session starts. For example, you could add the <code>pipewire</code> command to <code>~/.xinitrc</code> or your window manager's config file.
== Troubleshooting ==
=== `pw-cat -p --list-targets` shows no targets ===
First, check whether ALSA knows about your sound card:
<pre>
aplay -l
</pre>
If sound devices are found, the issue is with your pipewire configuration.  Consider double-checking the instructions above.
Otherwise, your sound card may not be supported in the version of the Linux Kernel you're running.  You should search online for fixes relating to your current kernel version and the codec of your sound card.  You can find each of these with:
<pre>
uname -r
cat /proc/asound/card0/codec* | grep Codec
</pre>


== See Also ==
== See Also ==

Revision as of 18:06, 19 November 2021

This material is work-in-progress ...

The instructions below have not been thoroughly tested and may break things.
(Last edited by Govynnus on 19 Nov 2021.)

PipeWire is a multimedia processing engine that aims to improve audio and video handling on Linux.

Prerequisites

Audio Group

When elogind is not available, the user has to be added to the audio group. The user must log in for this to take effect.

# addgroup <user> audio

D-Bus

PipeWire requires a running D-Bus session. If you use a full desktop environment this will probably be started automatically, but with minimal window managers it must be done manually.

# apk add dbus dbus-openrc dbus-x11
# rc-service dbus start
# rc-update add dbus default

Then use dbus-launch whenever you start an X or Wayland session. For example:

$ dbus-launch --exit-with-session sway

XDG_RUNTIME_DIR

If you are not using a Desktop Manager, ensure that your XDG_RUNTIME_DIR is set to a user-writable location. By default for pulseaudio this is /run/user/1000/ or /tmp. If this is not set, pipewire will create a directory in your home folder instead, called ~/pulse, and on attempting to run Pavucontrol or pactl, you will get the following error:

$ pactl list
Connection failure: Connection refused
pa_context_connect() failed: Connection refused

Installation and configuration

# apk add pipewire wireplumber
Note: Using WirePlumber rather than the pipewire-media-session (which comes with pipewire) is recommended but not required.

Create a custom configuration file in /etc/pipewire/pipewire.conf:

# mkdir /etc/pipewire
# cp /usr/share/pipewire/pipewire.conf /etc/pipewire/

Add the following line to the context.exec section at the bottom of /etc/pipewire/pipewire.conf:

{ path = "wireplumber"  args = "" }

Enable the snd_seq kernel module for ALSA support.

# modprobe snd_seq
# echo snd_seq >> /etc/modules

ALSA

If you use neither Jack nor PulseAudio and you don't intend to.

# touch /etc/pipewire/media-session.d/with-alsa

PulseAudio

PipeWire can run a PulseAudio daemon which should allow all existing PulseAudio applications to be used with the PipeWire backend.

# apk add pipewire-pulse

Uncomment the following line in /etc/pipewire/pipewire.conf:

{ path = "/usr/bin/pipewire" args = "-c pipewire-pulse.conf" }

It should be automatically enabled.

JACK

If you will be using PipeWire for JACK applications install the required package and make system wide links to the PipeWire replacement JACK libraries (I have not had success using pw-jack). You will not need to start a JACK server.

# apk add pipewire-jack
# ln -sf /usr/lib/pipewire-0.3/jack/libjackserver.so.0 /usr/lib/libjackserver.so.0
# ln -sf /usr/lib/pipewire-0.3/jack/libjacknet.so.0 /usr/lib/libjacknet.so.0
# ln -sf /usr/lib/pipewire-0.3/jack/libjack.so.0 /usr/lib/libjack.so.0
Note: These symlinks might be overwritten during updates.

Video

Video should work out-of-the-box with v4l2 devices (e.g. a lot of webcams) and GStreamer applications.

Bluetooth headset

Requires pipewire-spa-bluez package in addition to pipewire-pulseaudio daemon to be installed.

Automatic bluetooth profile selection

To automatically switch between HSP/HFP and A2DP profiles when an input stream is detected, set the bluez5.autoswitch-profile property to true:

/etc/pipewire/media-session.d/bluez-monitor.conf

...
rules = [
    {
        ...
        actions = {
            update-props = {
                ...
                bluez5.autoswitch-profile = true
...


Screen sharing on Wayland

You will need the right xdg-desktop-portal backend for your desktop environment. Screen sharing is known to work on:

  • GNOME with xdg-desktop-portal-gtk
  • KDE Plasma with xdg-desktop-portal-kde and Firefox
  • Sway with xdg-desktop-portal-wlr and Firefox

Usage

Start the PipeWire media server. You'll probably get quite a few errors but just ignore them for now.

$ pipewire

In a different terminal window check the default output device. I don't yet know how this default can be changed for all applications, so you'd better hope it's right!

# apk add pipewire-tools
$ pw-cat -p --list-targets

Test sound is working using an audio file in a format supported by libsndfile (e.g. flac, opus, ogg, wav).

$ pw-cat -p test.flac

If you have a microphone test audio recording is working.

$ pw-cat -r --list-targets
$ pw-cat -r recording.flac
(Speak for a while then stop it with Ctrl+c)
$ pw-cat -p recording.flac

Test PulseAudio clients using a media player (most use PulseAudio) and if you use JACK test that too:

# apk add jack-example-clients
$ jack_simple_client

You should hear a sustained beep.

If you are happy everything is working, make PipeWire start automatically when your X or Wayland session starts. For example, you could add the pipewire command to ~/.xinitrc or your window manager's config file.

Troubleshooting

`pw-cat -p --list-targets` shows no targets

First, check whether ALSA knows about your sound card:

aplay -l

If sound devices are found, the issue is with your pipewire configuration. Consider double-checking the instructions above.

Otherwise, your sound card may not be supported in the version of the Linux Kernel you're running. You should search online for fixes relating to your current kernel version and the codec of your sound card. You can find each of these with:

uname -r
cat /proc/asound/card0/codec* | grep Codec


See Also