View previous topic :: View next topic |
Author |
Message |
mazes80 n00b
Joined: 24 Feb 2011 Posts: 13 Location: toulouse - france
|
Posted: Thu Jul 07, 2022 9:35 pm Post subject: System wide pipewire with openrc |
|
|
Required packages
Code: | emerge -C media-sound/jack-audio-connection-kit
USE="extra jack-sdk pipewire-alsa" emerge media-video/pipewire # extra is not mandatory
emerge acct-group/pipewire acct-user/pipewire |
New files
/etc/init.d/pipewire
Code: | #!/sbin/openrc-run
# Copyright 2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
PIPEWIRE_RUNTIME_DIR="/tmp/pipewire"
name="pipewire daemon"
description="Share sound and videos"
command=/usr/bin/pipewire
command_args="${pipewire_args}"
command_background=yes
command_user="pipewire:pipewire"
pidfile="${PIPEWIRE_RUNTIME_DIR}/pipewire.pid"
depend() {
use alsasound pulseaudio
}
start_pre() {
# The next 5 lines feels like it should be replaced by:
# checkpath -d -m 2775 -o "${command_user}" "${PIPEWIRE_RUNTIME_DIR}"
# Optionally replace -d with -D to clean out the directory (possible security thoughts)
if [[ ! -e ${PIPEWIRE_RUNTIME_DIR} ]]; then
mkdir ${PIPEWIRE_RUNTIME_DIR}
fi
chmod -R g+ws ${PIPEWIRE_RUNTIME_DIR}
chown -R pipewire:pipewire ${PIPEWIRE_RUNTIME_DIR}
export PIPEWIRE_RUNTIME_DIR
}
start_post() {
einfo "Wait for the pipewire socket to be ready"
sleep 3
find ${PIPEWIRE_RUNTIME_DIR} -type s -exec chmod g+w '{}' ';'
einfo "Socket file: $(find ${PIPEWIRE_RUNTIME_DIR} -type s)"
} |
Thanks grknight for the review
/etc/X11/xinit/xinitrc.d/99-pipewire
Code: | #!/bin/bash
if test -z "${XDG_RUNTIME_DIR}"; then
export XDG_RUNTIME_DIR="$(mktemp -d /tmp/$(id -u)-runtime-dir.XXX)"
else
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR}"
fi
export PIPEWIRE_RUNTIME_DIR="/tmp/pipewire" |
Tweaked files
Code: | mkdir /etc/pipewire
cp /usr/share/pipewire/pipewire.conf /etc/pipewire/
sed -i '/path.*pipewire-media-session/{s/#//;s/pipewire-media-session/wireplumber/}' |
Disable D-Bus
Code: | sed -i '/with-logind/s/true/false/' /etc/wireplumber/bluetooth.lua.d/50-bluez-config.lua
sed -i '/alsa.reserve/s/true/false/' /etc/wireplumber/main.lua.d/50-alsa-config.lua
sed -i '/enable-flatpak-portal/s/true/false/' /etc/wireplumber/main.lua.d/50-default-access-config.lua |
System settings
Start pipewire at boot
Code: | rc-update add pipewire default |
Add all user who can use sound to pipewire group
Code: | usermod -a -G pipewire user1
usermod -a -G pipewire user2
usermod -a -G pipewire mpd |
Extra step
You may also need to add to your .bashrc
Code: | export PIPEWIRE_RUNTIME_DIR="/tmp/pipewire" |
Restart your graphical sessions (wayland not covered here)
MPD
Set output as this in /etc/mpd.conf
Code: | audio_output {
type "pipewire"
name "pipewire-0"
} |
/etc/conf.d/mpd
Code: | export PIPEWIRE_RUNTIME_DIR="/tmp/pipewire" |
Last edited by mazes80 on Mon Sep 04, 2023 10:19 am; edited 2 times in total |
|
Back to top |
|
|
grknight Retired Dev
Joined: 20 Feb 2015 Posts: 1968
|
Posted: Fri Jul 08, 2022 12:46 pm Post subject: Re: System wide pipewire with openrc |
|
|
I don't know if it is right or not, but this file should be modernized a bit:
/etc/init.d/pipewire
Code: | #!/sbin/openrc-run
# Copyright 2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
PIPEWIRE_RUNTIME_DIR="/tmp/pipewire"
name="pipewire daemon"
description="Share sound and videos"
command=/usr/bin/pipewire
command_args="${pipewire_args}"
command_background=yes
command_user="pipewire:pipewire"
pidfile="${PIPEWIRE_RUNTIME_DIR}/pipewire.pid"
depend() {
use alsasound pulseaudio
}
start_pre() {
# The next 5 lines feels like it should be replaced by:
# checkpath -d -m 2775 -o "${command_user}" "${PIPEWIRE_RUNTIME_DIR}"
# Optionally replace -d with -D to clean out the directory (possible security thoughts)
if [[ ! -e ${PIPEWIRE_RUNTIME_DIR} ]]; then
mkdir ${PIPEWIRE_RUNTIME_DIR}
fi
chmod -R g+ws ${PIPEWIRE_RUNTIME_DIR}
chown -R pipewire:pipewire ${PIPEWIRE_RUNTIME_DIR}
export PIPEWIRE_RUNTIME_DIR
}
start_post() {
einfo "Wait for the pipewire socket to be ready"
sleep 3
find ${PIPEWIRE_RUNTIME_DIR} -type s -exec chmod g+w '{}' ';'
einfo "Socket file: $(find ${PIPEWIRE_RUNTIME_DIR} -type s)"
}
|
|
|
Back to top |
|
|
acidrums4 Tux's lil' helper
Joined: 05 Feb 2009 Posts: 147 Location: Al otro lado del monitor
|
Posted: Thu Nov 17, 2022 2:31 pm Post subject: Re: System wide pipewire with openrc |
|
|
mazes80 wrote: |
Add all user who can use sound to pipewire group
Code: | usermod -a -G user1
usermod -a -G user2
usermod -a -G mpd |
|
Not sure if it's worth noting that when issuing these commands, the pipewire group should precede the usernames, something like
Code: | usermod -a -G pipewire mpd |
That will add mpd user to the pipewire group.
However, this was the only thing that let me use mpd as its own user with pipewire. Thank you so much! |
|
Back to top |
|
|
L29Ah n00b
Joined: 18 Oct 2010 Posts: 12
|
Posted: Sat Aug 26, 2023 3:15 pm Post subject: |
|
|
Any plans on adding this to the media-video/pipewire ebuild (perhaps behind an USE flag)? |
|
Back to top |
|
|
Ralphred l33t
Joined: 31 Dec 2013 Posts: 671
|
Posted: Sat Aug 26, 2023 5:29 pm Post subject: Re: System wide pipewire with openrc |
|
|
mazes80 wrote: | Known issues: qjackctl will refuse to run for multiple users at the same time as the socket name seems hardcoded |
qjackctl does that with a system wide jackd too, I wouldn't consider it an exclusive pipewire issue. Are you exporting JACK_PROMISCUOUS_SERVER? |
|
Back to top |
|
|
mazes80 n00b
Joined: 24 Feb 2011 Posts: 13 Location: toulouse - france
|
Posted: Mon Sep 04, 2023 10:26 am Post subject: Re: System wide pipewire with openrc |
|
|
Ralphred wrote: | mazes80 wrote: | Known issues: qjackctl will refuse to run for multiple users at the same time as the socket name seems hardcoded |
qjackctl does that with a system wide jackd too, I wouldn't consider it an exclusive pipewire issue. Are you exporting JACK_PROMISCUOUS_SERVER? |
qjackctl and qpwgraph created one socket named: /tmp/software@hostname, if you tried to launch it in another session an error was thrown as socket already existed.
I submitted one PR that changed the socket name to /tmp/user:software@hostname, so every user can launch 1 instance of those softwares. |
|
Back to top |
|
|
mwhitlock Tux's lil' helper
Joined: 07 Aug 2006 Posts: 89 Location: New Hampshire, USA
|
Posted: Mon Dec 30, 2024 12:51 am Post subject: |
|
|
I didn't need media-sound/jack-audio-connection-kit. It was sufficient to install media-video/pipewire, media-video/wireplumber, and acct-user/pipewire.
I cleaned up the init scripts to remove some extraneous cruft, to move the runtime dir beneath /run, and to allow the user:group to be overridden…
/etc/init.d/pipewire
Code: | #!/sbin/openrc-run
: ${PIPEWIRE_RUNTIME_DIR:=/run/pipewire}
export PIPEWIRE_RUNTIME_DIR
name="PipeWire daemon"
description="Facilitates sharing of multimedia content between devices and applications"
command="/usr/bin/pipewire"
command_background="true"
command_user="${PIPEWIRE_USER:-pipewire}:${PIPEWIRE_GROUP:-pipewire}"
directory="${PIPEWIRE_RUNTIME_DIR}"
pidfile="${PIPEWIRE_RUNTIME_DIR}/${RC_SVCNAME}.pid"
umask="0002"
start_pre() {
checkpath -d -m0750 -o "${command_user}" -- "${PIPEWIRE_RUNTIME_DIR}"
} |
/etc/init.d/wireplumber
Code: | #!/sbin/openrc-run
: ${PIPEWIRE_RUNTIME_DIR:=/run/pipewire}
export PIPEWIRE_RUNTIME_DIR
: ${XDG_STATE_HOME:=${PIPEWIRE_RUNTIME_DIR}/state}
export XDG_STATE_HOME
name="WirePlumber session manager"
description="Session and policy manager for PipeWire"
command="/usr/bin/wireplumber"
command_background="true"
command_user="${PIPEWIRE_USER:-pipewire}:${PIPEWIRE_GROUP:-pipewire}"
directory="${PIPEWIRE_RUNTIME_DIR}"
pidfile="${PIPEWIRE_RUNTIME_DIR}/${RC_SVCNAME}.pid"
depend() {
need pipewire
use dev-settle
after alsasound modules
} |
You probably won't need this, but on my Raspberry Pi 1, I also needed to increase the default clock quantum to avoid sporadic audio glitches:
/etc/pipewire/pipewire.conf.d/local.conf
Code: | context.properties = {
default.clock.quantum = 2048
} |
Note: I did not need to set PIPEWIRE_RUNTIME_DIR in my user profile, as MPV's pipewire audio output module apparently finds the system-wide PipeWire socket just fine without being told explicitly where to look for it. Presumably the same would be true for any client using the PipeWire client library, but YMMV. |
|
Back to top |
|
|
L29Ah n00b
Joined: 18 Oct 2010 Posts: 12
|
Posted: Mon Dec 30, 2024 12:54 am Post subject: |
|
|
mwhitlock wrote: | Note: I did not need to set PIPEWIRE_RUNTIME_DIR in my user profile, as MPV's pipewire audio output module apparently finds the system-wide PipeWire socket just fine without being told explicitly where to look for it. Presumably the same would be true for any client using the PipeWire client library, but YMMV. |
Thanks for your work. Do i get it right you didn't need any adjustments for the default configuration of PipeWire itself?
Do ALSA and PulseAudio frontends of PipeWire work for the users in your setup? |
|
Back to top |
|
|
mwhitlock Tux's lil' helper
Joined: 07 Aug 2006 Posts: 89 Location: New Hampshire, USA
|
Posted: Mon Dec 30, 2024 1:36 am Post subject: |
|
|
L29Ah wrote: | Do i get it right you didn't need any adjustments for the default configuration of PipeWire itself? |
The only thing I changed about PipeWire's configuration was to increase the default clock quantum. Everything else is just as Portage installed it. I did add the pipewire and wireplumber services to my default runlevel, and I added my user to the pipewire group.
L29Ah wrote: | Do ALSA and PulseAudio frontends of PipeWire work for the users in your setup? |
I don't know. I am running this on a headless Raspberry Pi in my home theater rack, which is why I couldn't use PipeWire in the usual way — I don't start any desktop session, and there is no D-Bus (system or session) and no elogind. I can say that it works great for running MPV from the command line in SSH, just had to set ao=pipewire.
Code: | [ao] Trying audio driver 'pipewire'
[ao/pipewire] requested format: 44100 Hz, stereo channels, s16p
[ao/pipewire] Headers version: 1.2.6
[ao/pipewire] Library version: 1.2.6
[ao/pipewire] Core user: pipewire
[ao/pipewire] Core host: hifipi
[ao/pipewire] Core version: 1.2.6
[ao/pipewire] Core name: pipewire-0
[ao/pipewire] using soft-buffer of 132300 samples.
AO: [pipewire] 44100Hz stereo 2ch s16p
[cplayer] AO: Description: PipeWire audio output |
The only real reason I'm trying out PipeWire at all is that my stupid AV preprocessor fades in the audio after even the briefest moment of digital silence in the HDMI audio stream, and that causes the beginning of every music track to fade in and even causes some drop-outs in the middle of some tracks that contain digital silence. There's supposed to be a way to make PipeWire constantly output an inaudible noise to trick such stupid receivers into staying locked on the PCM clock. I haven't gotten that far yet, though. |
|
Back to top |
|
|
|