Pulseaudio

From miki
Revision as of 10:46, 25 April 2022 by Mip (talk | contribs) (→‎Commands)
Jump to navigation Jump to search

This page contains dedicated information about Pulseaudio. See Linux audio page for more general information (might also include some general info on Pulseaudio).

References

Commands

pactl
pactl list                 # View devices (including bluetooth headsets...)
pactl load-module module-native-protocol-tcp listen=192.168.1.10 # Use the local IP address
pactl load-module module-zeroconf-publish

Pulseaudio with systemd

On recent Ubuntu / Debian version, Pulseaudio is started by systemd.

  • Unit file is at /etc/systemd/user/default.target.wants/pulseaudio.service.
This file starts pulseaudio in non-daemon mode.
  • To get pulseaudio log, do something like journalctl | grep pulseaudio.
  • To restart pulseaudio, simply kill it. For instance:
pulseaudio -k
 ✐  Configuring pulseaudio to log in a file does not work very well. Better use systemd journal.

How-To

PulseAudio across network with Avahi / auto-discovery

This configuration is very useful to send sound to another network device (for instance, if you have one headset but multiple computers) [1].

First install pulseaudio-module-zeroconf on both server and client:

sudo apt install pulseaudio-module-zeroconf

In the server computer (the one that will play the sound), add to ~/.pulse/default.pa:

.include /etc/pulse/default.pa

load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1
load-module module-zeroconf-publish

In the client computer (the one that will send the sound), add to ~/.pulse/default.pa:

.include /etc/pulse/default.pa

load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1
load-module module-zeroconf-discover

On the server, we must open the TCP port 4713 in the firewall.

By default, Pulseaudio is configured to use cookie authentication, except for the address excluded by auth-ip-acl (this can be sequence of address, see online documentation). The easiest is to copy the cookie from the server to the client:

cd ~/.config/pulse
scp server:.pulse/cookie .

Finally, restart pulseaudio on both computers:

pulseaudio -k
Fix [puseaudio] module-tunnel.c
Failed to authenticate
  • Make sure that there is no other cookie file in user home.
  • In particular, there are two separate directories: ~/.pulse and ~/.config/pulse. The cookie is taken from 2nd directory, whereas the configuration is read from the first folder.
  • The easiest is to symlink the 2nd folder to first one:
rm -rf ~/.config/pulse
ln -sf ../.pulse ~/.config/pulse
pulseaudio -k

PulseAudio in multi-user (relay)

The solution is to have all users have their own PulseAudio server, but all of these relay to one server (typically the one of current active user, see [2]).

For each potential active user, edit file ~/.pulse/default.pa:

.include /etc/pulse/default.pa

load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1

For all users that needs to relay to active user, edit file ~/.pulse/client.conf:

default-server = 127.0.0.1

Active user might also need to run:

xhost +

PulseAudio in multi-user (system mode)

Main article: [3] (see also [4])

CAUTION — PulseAudio developers seriously recommend against this (see [5])

The solution here is to run pulseaudio as a system-wide daemon. For this:

  • Enable system start. For 12.04, edit /etc/default/pulseaudio:
PULSEAUDIO_SYSTEM_START=1

For 12.10, edit /etc/init/pulseaudio.conf:

start on runlevel [2345]
  • Edit /etc/pulse/daemon.conf — See man pulse-daemon.conf for more information.
daemonize = yes
local-server-type = system
  • Edit /etc/pulse/client.conf (this is actually not really necessary
autospawn = no

We also need to add users to the pulse-access group.

sudo usermod -a -G pulse-access <username>

Troubleshooting

Get verbose log

  • Edit /etc/systemd/user/default.target.wants/pulseaudio.service:
-ExecStart=/usr/bin/pulseaudio --daemonize=no
+ExecStart=/usr/bin/pulseaudio --daemonize=no -v

Get the log with

sudo journalctl -b | grep pulse

Clean up config

Cleaning up the user config may solve issues (like not working speaker):

  • remove all files in .pulse and .config/pulse, except possibly client.conf, cookie and default.pa.

General

Troubleshooting PulseAudio:

paplay /usr/share/sounds/alsa/Front_Center.wav           # Try to play using PulseAudio

Choppy sound in flash video

Reference askubuntu.

  • Simply kill and restart pulseaudio:
pulseaudio -k
pusseaudio -D       # To restart it - not needed if pulse runs in daemon mode

Understanding / Troubleshooting PulseAudio

  • Only active user has access to /dev/snd/* devices. Access is granted by ConsoleKit when user logs in [6]. Access control can be seen with
getfacl /dev/snd/*
  • To restart PulseAudio [7]
pulseaudio --check && echo running       # Check if any pulseaudio is running
pulseaudio -k                            # ... if so, kill it
pulseaudio -D                            # and start it again (optional is auto-spawn is enabled)