WirePlumber
WirePlumber 是一款強大的PipeWire 會話和策略管理器。其採用模塊化設計,使用 Lua 插件進行管理,具有高度可配置性及可擴展性。
安裝 wireplumber包。任何衝突的 PipeWire 回話管理器會被卸載。
WirePlumber 使用 systemd 用戶單元管理 PipeWire 服務。
WirePlumber 的配置使用 PipeWire 的 JSON 對象如 context 和 alsa_monitor,通過修改這些對象來控制其行為。配置文件位於 ~/.config/wireplumber/(用戶配置)、/etc/wireplumber/(全局配置)以及 /usr/share/wireplumber/(默認配置)。
WirePlumber 啟動時首先會讀取主配置文件。這是一個類 JSON 文件,用於設定 PipeWire 上下文環境(context)、SPA 插件、模塊以及組件。
默認配置文件位於 /usr/share/wireplumber/wireplumber.conf,其是一個單實例配置文件,集成其他配置到一個進程中。請參閱文檔 ALSA 對象、"access" 對象和藍牙對象。
The recommended way to configure WirePlumber is to add an SPA-JSON file to the appropriate wireplumber.conf.d/ directory within /etc/wireplumber/ or ~/.config/wireplumber/.
User configuration files have a higher priority than system files. Configuration files with the same name but in a lower priority location will be ignored. Within each configuration directory, the individual files are opened in alphanumerical order. See the documentation for details.
In the configuration, you need to specify matches rules with a property from an object of the interface you want to configure.
Use the command wpctl status to show all objects managed by WirePlumber. Find the ID assigned to the target interface. Then use command wpctl inspect ID to get a needed property.
For example, if your target interface is HD Audio Controller Analog Stereo, consider the following output:
$ wpctl status
PipeWire 'pipewire-0' [0.3.56, user@hostname, cookie:1163266174] Audio ├─ Devices: │ 42. HD Audio Controller [alsa] │ 105. USB PnP Audio Device [alsa] │ ├─ Sinks: │ * 48. HD Audio Controller Analog Stereo [vol: 0.50] │ ├─ ... │ ├─ Sources: │ * 101. USB PnP Audio Device Mono [vol: 0.74] │ └─ ...
the interface ID is 48.
Then use the inspect command to view the object's detail and list all properties in that object:
$ wpctl inspect 48
id 48, type PipeWire:Interface:Node
...
device.api = "alsa"
device.class = "sound"
* device.id = "42"
device.profile.description = "Analog Stereo"
device.profile.name = "analog-stereo"
...
* factory.id = "18"
factory.mode = "merge"
factory.name = "api.alsa.pcm.sink"
...
* media.class = "Audio/Sink"
* node.description = "HD Audio Controller Analog Stereo"
* node.name = "alsa_output.pci-0000_08_00.4.analog-stereo"
* node.nick = "ALC1220 Analog"
...
* object.path = "alsa:pcm:1:front:1:playback"
* object.serial = "49"
...
Choose the device.name or node.name property to use with the matches rules in the configuration.
Avoid using device.id; it is dynamic and changes often.
Multiple properties in matches rules are possible; see the alsa_monitor.rules section in the documentation for the WirePlumber ALSA configuration.
- You can determine the
Endpointclass of this object from themedia.classproperty. - For ALSA,
nodeobjects are Sinks or Sources /deviceobjects correspond to the card. - Since v0.4.9, ALSA nodes use the PCM name to populate
node.nick, which is useful at least on HDA cards using UCM, where all outputs (analog, HDMI, etc.) are exposed asNodeon a single profile.
- The command
pw-topshows the PipeWireDeviceandNodecurrently in use. - Similar inspection command from PipeWire is
pw-cli info ID.
To change a device or node property, such as its description or nick, you must create an SPA-JSON file and add it into /etc/wireplumber/ or ~/.config/wireplumber/ under the proper path and name.
For instance, to change the description of an ALSA node, you would create a file such as:
/etc/wireplumber/wireplumber.conf.d/device-rename.conf (or ~/.config/wireplumber/wireplumber.conf.d/device-rename.conf)
monitor.alsa.rules = [
{
matches = [
{
node.name = "alsa_output.pci-0000_00_1f.3.output_analog-stereo"
}
]
actions = {
update-props = {
node.description = "Laptop"
}
}
}
]
If instead you wish to change something on a Bluetooth node or device, you could create a file such as:
/etc/wireplumber/wireplumber.conf.d/bluez-rename.conf (or ~/.config/wireplumber/wireplumber.conf.d/bluez-rename.conf)
monitor.bluez.rules = [
{
matches = [
{
node.name = "bluez_output.02_11_45_A0_B3_27.a2dp-sink"
}
]
actions = {
update-props = {
node.nick = "Headphones"
}
}
}
]
The properties that you can change as well as the matching rules to select devices or nodes are documented at ALSA configuration and Bluetooth configuration.
Since WirePlumber v0.4.7, users could now disable any devices or nodes by property device.disabled or node.disabled:
/etc/wireplumber/wireplumber.conf.d/alsa-disable.conf (or ~/.config/wireplumber/wireplumber.conf.d/alsa-disable.conf)
monitor.alsa.rules = [
{
matches = [
{
device.name = "alsa_card.pci-0000_08_00.4"
}
]
actions = {
update-props = {
device.disabled = true
}
}
}
]
For the name of alsa_card.* in your system, see #Obtain interface name for rules matching.
To change which sink or source is automatically selected, you need to set its priority.driver and priority.session values:
/etc/wireplumber/wireplumber.conf.d/set-priorities.conf
monitor.alsa.rules = [
{
matches = [
{
node.name = "alsa_output.usb-Generic_USB_Audio-00.HiFi__Speaker__sink"
}
]
actions = {
update-props = {
priority.driver = 100
priority.session = 100
}
}
}
]
This example sets the priority of the speaker output sink of the on-board audio on the Asus B650E-F motherboard to 100, lowered from the original value of 1000. Consequently, the other output sinks, such as the S/PDIF output of the onboard audio device or the plugged in headphones, will be selected by default due to their higher priorities, instead of the analog speaker output.
See PipeWire#Simultaneous output to multiple sinks on the same sound card.
You may wish to output sound to onboard and external devices simultaneously - even when the external devices are not always plugged in. To accomplish this we create a virtual node that will always be present, regardless of what hardware is plugged in. We then link the transient hardware (in this example USB headphones) to the virtual node whenever they are plugged in.
First, create a script to run during login; this is usually easiest to do via your window manager's Startup function.
/usr/local/sbin/create-virtual-sink.sh
#!/bin/bash
# Create a new sink called Simultaneous Output
pw-cli create-node adapter '{ factory.name=support.null-audio-sink node.name="Simultaneous Output" node.description="Simultaneous Output" media.class=Audio/Sink object.linger=true audio.position=[FL FR] }'
# Connect the normal permanent sound card output to the new sink
pw-link "Simultaneous Output:monitor_FL" alsa_output.pci-0000_05_04.0.analog-stereo:playback_FL
pw-link "Simultaneous Output:monitor_FR" alsa_output.pci-0000_05_04.0.analog-stereo:playback_FR
# Switch the default output to the new virtual sink
wpctl set-default `wpctl status | grep "\. Simultaneous Output" | egrep '^ │( )*[0-9]*' -o | cut -c6-55 | egrep -o '[0-9]*'`
In the above example, initially the only output device is our 'normal' on-board soundcard (alsa_output.pci-0000_05_04.0.analog-stereo). You can find the designator for your card by running wpctl status and wpctl inspect.
Run the following script when your USB headphones are inserted in order to link them to the virtual sink:
link-virtual-sink-headphones.sh
#!/bin/bash # link the virtual sync to your headphones should run when detected by UDEV # wait a second for the drivers to load sleep 1s # link the headphones to your virtual sink sudo -u user1 env XDG_RUNTIME_DIR=/run/user/1000 pw-link "Simultaneous Output:monitor_FL" alsa_output.usb-Kingston_HyperX_Cloud_Flight_S_000000000001-00.analog-stereo:playback_FL sudo -u user1 env XDG_RUNTIME_DIR=/run/user/1000 pw-link "Simultaneous Output:monitor_FR" alsa_output.usb-Kingston_HyperX_Cloud_Flight_S_000000000001-00.analog-stereo:playback_FR # finish and return the code for success exit 0
Ideally you would run this script automatically when your headphones are inserted. The instructions on the udev page describe how you would create a custom rule for that. (Although note that you cannot run this script directly - because udev will not load drivers until after any specified script has run. So you will have to have an intermediate script with some nohup trickery or something like that). You will also need to modify the above script so that the XDG_RUNTIME_DIR matches your user id number and user1 will need to be replaced with your username.
You can add any arbitrary number of devices to this virtual sink in the same manner.
If you are having trouble keeping track what devices are connected where, the qpwgraph包 tool is excellent for getting a visual representation of which devices are connected to each other.
If the settings of WirePlumber are corrupted it is possible to delete all user settings:
$ systemctl --user stop wireplumber.service $ rm -r ~/.local/state/wireplumber # deletes settings $ systemctl --user start wireplumber.service
See Keyboard shortcuts#Xorg to bind the following commands to your volume keys: XF86AudioRaiseVolume, XF86AudioLowerVolume, XF86AudioMute and XF86AudioMicMute.
To raise the volume, with a limit of 150%:
$ wpctl set-volume -l 1.5 @DEFAULT_AUDIO_SINK@ 5%+
To lower the volume:
$ wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-
To mute/unmute the volume:
$ wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
To mute/unmute the microphone:
$ wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle
wpctl status to list all available sinks, and use sink or source numbers in place of @DEFAULT_AUDIO_SINK@ or _SOURCE@.To get the volume level and mute status of the default sink:
$ wpctl get-volume @DEFAULT_AUDIO_SINK@
Volume: 0.45
See PipeWire#Automatic profile selection.
Since 0.4.8 the requirement to support.logind has to be disabled for the bluez seat-monitoring.
~/.config/wireplumber/wireplumber.conf.d/disable-logind.conf
wireplumber.profiles = {
main = {
monitor.bluez.seat-monitoring = disabled
}
}
If you do not want PipeWire/Wireplumber to take over control of your audio devices because you are opting for a different audio solution (e.g. PulseAudio/JACK/ALSA) but still want it to be available for screen sharing/video purposes you can make use of the wireplumber@.service template unit to enable a different set of default profiles. Wireplumber ships with a profile configuration that enables only the video parts and disables audio integration (including Bluetooth audio) by enabling the video-only template user unit.
Disable wireplumber.service user unit and enable wireplumber@video-only.service user unit.
Some applications (e.g. launchers) play sound too briefly to adjust their volume using GUI mixers. WirePlumber stores per-application and per-node volume and mute states in a text file at $HOME/.local/state/wireplumber/stream-properties. This file can be edited manually to change these settings. Ensure WirePlumber is not running while editing, or it may overwrite the changes.
Since WirePlumber only exists to manage PipeWire sessions, WirePlumber-related fixes may be found in PipeWire#Troubleshooting.
- Documentation — Official documentation
- WirePlumber, the PipeWire session manager — Blog post by George Kiagiadakis (Collabora) from May 2020, detailing how WirePlumber works