PipeWire: Difference between revisions

From Alpine Linux
(fix)
Line 7: Line 7:
=== Audio Group ===
=== Audio Group ===


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.
When elogind is not available, the user has to be added to the <code>audio</code> group. The user must re-log-in in for this to take effect.


<pre>
<pre>
Line 18: Line 18:


<pre>
<pre>
# apk add dbus dbus-openrc dbus-x11
# apk add dbus dbus-openrc
# rc-service dbus start
# rc-service dbus start
# rc-update add dbus default
# rc-update add dbus default
</pre>
</pre>


Then use <code>dbus-launch</code> whenever you start an X or Wayland session. For example:
Then use <code>dbus-run-session</code> whenever you start an X or Wayland session. For example:
<pre>
<pre>
$ dbus-launch --exit-with-session sway
$ dbus-run-session -- sway
</pre>
</pre>


Line 45: Line 45:


{{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.}}
{{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>
# mkdir /etc/pipewire
# cp /usr/share/pipewire/pipewire.conf /etc/pipewire/
</pre>
Replace pipewire-media-session with wireplumber:
<pre>
# sed -i 's|#*{ path = "/usr/bin/pipewire-media-session.*|{ path = "wireplumber"  args = "" }|' /etc/pipewire/pipewire.conf
</pre>
Enable the <code>snd_seq</code> kernel module for ALSA support.
<pre>
# modprobe snd_seq
# echo snd_seq >> /etc/modules
</pre>


=== Realtime scheduling ===
=== Realtime scheduling ===
Line 92: Line 72:
</pre>
</pre>


ALSA support works out of the box if you have the pipewire-alsa package
ALSA support works out of the box if you have the pipewire-alsa package. You may need the <code>snd_seq</code> kernel module.


=== PulseAudio ===
=== PulseAudio ===


PipeWire can run a [https://www.freedesktop.org/wiki/Software/PulseAudio/ PulseAudio] daemon which should allow all existing PulseAudio applications to be used with the PipeWire backend.
PipeWire can run a [https://www.freedesktop.org/wiki/Software/PulseAudio/ PulseAudio] daemon which should allow all existing PulseAudio applications to be used with the PipeWire backend. You need to have <code>pipewire-pulse</code> installed.
 
<pre>
# apk add pipewire-pulse
# sed -i 's|#*{ path = "/usr/bin/pipewire" args = "-c pipewire-pulse.conf" }|{ path = "/usr/bin/pipewire" args = "-c pipewire-pulse.conf" }|' /etc/pipewire/pipewire.conf
</pre>
 


=== JACK ===
=== JACK ===


If you will be using PipeWire for [https://jackaudio.org/ JACK] applications install the required package and make system wide links to the PipeWire replacement JACK libraries (I have not had success using <code>pw-jack</code>). You will not need to start a JACK server.
If you will be using PipeWire for [https://jackaudio.org/ JACK] applications install the required package (pipewire-jack). Things should work with just that.
 
<pre>
# 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
</pre>
 
{{Note|These symlinks might be overwritten during updates.}}


=== Video ===
=== Video ===
Line 148: Line 113:
</pre>
</pre>


 
TODO: for pipewire the config is somewhere else


== Screen sharing on Wayland ==
== Screen sharing on Wayland ==
Line 170: Line 135:
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!
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!


wireplumber:
<pre>
<pre>
# apk add pipewire-tools
$ wpctl status
$ pw-cat -p --list-targets
</pre>
</pre>
{{Note| pw-cat doesn't have --list-targets option anymore.
The version of pipewire used in Alpine 3.16 and later has the --list-targets option removed. You should now use '''pw-cli list-objects''' or '''wpctl status''' (if you use wireplumber).}}


Test sound is working using an audio file in a format supported by [http://www.mega-nerd.com/libsndfile/ libsndfile] (e.g. flac, opus, ogg, wav).
Test sound is working using an audio file in a format supported by [http://www.mega-nerd.com/libsndfile/ libsndfile] (e.g. flac, opus, ogg, wav).


<pre>
<pre>
# apk add pipewire-tools
$ pw-cat -p test.flac
$ pw-cat -p test.flac
</pre>
</pre>
Line 202: Line 165:
You should hear a sustained beep.
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 <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>/usr/libexec/pipewire-launcher</code> command to <code>~/.xinitrc</code> or your window manager's config file.


== Troubleshooting ==
== Troubleshooting ==


=== `pw-cat -p --list-targets` shows no targets ===
=== `wpctl status` shows no targets ===


First, check whether ALSA knows about your sound card:
First, check whether ALSA knows about your sound card:

Revision as of 15:04, 23 July 2022

This material is work-in-progress ...

The instructions below have not been thoroughly tested and may break things.
(Last edited by Psykose on 23 Jul 2022.)

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 re-log-in 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
# rc-service dbus start
# rc-update add dbus default

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

$ dbus-run-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.

Realtime scheduling

For realtime scheduling, it is recommended to use rtkit,

# apk add rtkit

and then add your user to the `rtkit` group.

Alternatively, ensure your user has the right ulimit permissions. You generally need (limits.conf format):

@audio - memlock 256
@audio - nice -11
@audio - rtprio 88

This allows a member of the audio group to have the right permissions for PipeWire to use realtime scheduling without rtkit.

ALSA

# apk add pipewire-alsa

ALSA support works out of the box if you have the pipewire-alsa package. You may need the snd_seq kernel module.

PulseAudio

PipeWire can run a PulseAudio daemon which should allow all existing PulseAudio applications to be used with the PipeWire backend. You need to have pipewire-pulse installed.

JACK

If you will be using PipeWire for JACK applications install the required package (pipewire-jack). Things should work with just that.

Video

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

Bluetooth audio

  • Enable PulseAudio support as described above
  • Install bluetooth service packages: bluez bluez-openrc pipewire-spa-bluez
  • Optional: install GUI manager for bluetooth blueman
  • Enable and start bluetooth service: rc-update add bluetooth; rc-service bluetooth start
  • Restart PipeWire
  • Use commandline program bluetoothctl or GUI program blueman-manager to scan and pair bluetooth audio devices.
  • Use pavucontrol to adjust volume and manually select high definition bluetooth codecs.

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

TODO: for pipewire the config is somewhere else

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, see Sway for details

Usage

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

$ pipewire
Note: PipeWire doesn't auto-start a session manager anymore. In 3.14 and earlier, the PipeWire default config was edited in packaging to auto-start pipewire-media-session as the default session manager. Since we now have wireplumber available as an alternative session manager, this has been changed in favor of a launch wrapper for pipewire at /usr/libexec/pipewire-launcher. When executed, this will launch pipewire, pipewire-media-session or wireplumber, and pipewire-pulse, depending on what modules are available. If you were launching /usr/bin/pipewire and the session manager manually before, please use the new launcher wrapper instead. WirePlumber can now also be used as a proper alternative for pipewire-media-session.

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!

wireplumber:

$ wpctl status

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

# apk add pipewire-tools
$ 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 /usr/libexec/pipewire-launcher command to ~/.xinitrc or your window manager's config file.

Troubleshooting

`wpctl status` 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

Quick Configuration

You might want to use pavucontrol to have a simple GUI app for controlling sound, outputs, etc, in which case:

# apk add pavucontrol

See Also