Today i played with my cubietruck and wanted to make network audio server. I just open laptop, connect to WiFi, choose remote sound device in gnome-control-center and listen music.
First of all I’d want to say many thanks to Jonas Wielicki for help with debugging problems and providing his ansible playbook with the same task, Stefan Majewsky who inspired Jonas about configuration management and to Felipe Sateler for tip with permissions.
Server configuration
I have installed minimal Fedora so it means that I don’t have avahi, pulseaudio and other tools in system. Let’s install them:
# dnf install pulseaudio pulseaudio-module-zeroconf avahi
Nothing needs to be set up in avahi, so just start and enable daemon:
# systemctl start avahi-daemon # systemctl enable avahi-daemon
module-native-protocol-tcp will use 4317/tcp port to handle connections, need to open port.
# firewall-cmd --add-port=4317/tcp # firewall-cmd --add-port=4317/tcp --permanent
Unfortunately, firewalld currently doesn’t xml with service defined to just use --add-service=pulseaudio
, but I already sent PATCH.
Time to configure PulseAudio. Add following lines to end of the /etc/pulse/default.pa
load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1;192.168.254.0/24 auth-anonymous=1 load-module module-zeroconf-publish
Since 6.0 PA socket-activated so we need to write systemd unit. Also running PA from root is not good, so we will use systemd user-session.
/etc/systemd/user/pulseaudio.service
[Unit] After=sound.target network.target avahi-daemon.service Requires=sound.target Wants=avahi-daemon.service Description=PulseAudio Sound System [Service] Type=dbus BusName=org.pulseaudio.Server BusName=org.PulseAudio1 ExecStart=/usr/bin/pulseaudio -vv ExecStop=/usr/bin/pulseaudio --kill Restart=always [Install] WantedBy=default.target
Now we need to create user and add it to audio
group.
# useradd -m -G audio media -s /bin/bash
All is ready. Login as media
user and start and enable pulseaudio.service
, but don’t try this. It will not work due to SELinux policy issues.
Create pulseaudio_user.tt
with following content:
module pulseaudio_user 1.0; require { type proc_net_t; type avahi_t; type pulseaudio_t; class dbus send_msg; class file read; } #============= avahi_t ============== allow avahi_t pulseaudio_t:dbus send_msg; #============= pulseaudio_t ============== allow pulseaudio_t avahi_t:dbus send_msg; allow pulseaudio_t proc_net_t:file read;
Then compile and install it (requires policycoreutils-python
package):
# checkmodule -M -m -o pulseaudio_user.mod pulseaudio_user.te # semodule_package -o pulseaudio_user.pp -m pulseaudio_user.mod # semodule -i pulseaudio_user.pp
Now we really can login as media
user and enable PulseAudio:
$ systemctl --user enable pulseaudio.service
We also need to enable lingering for this user to start systemd user-session in boot time, not when user logins.
# loginctl enable-linger media
If you are getting Failed to get D-Bus connection: Connection refused
:
$ export XDG_RUNTIME_DIR=/run/user/$(id -u)
Client configuration
On client you also need to have pulseaudio-module-zeroconf
package. Simply add following line to the end of /etc/pulse/default.pa
:
load-module module-zeroconf-discover
Restart pulseaudio and gnome-control-center, pavucontrol will find our server.
In case if you don’t want to use avahi, you can specify server manually for sink, something like:
$ pactl load-module module-tunnel-sink "server=192.168.254.20 sink=alsa_output.platform-1c22c00.codec.analog-stereo sink_name=cubietruck"
PulseAudio & Avahi & systemd –> Ready for Desktop
Comments are closed.
Is it working well for you? Last time I tried it, it was quite choppy. There were interruptions every few minutes.
It needs good bandwidth (IIRC I read on official site 1.4Mbps). But anyway it works well. I’m listening music, watching videos and it works pretty well.
I just checked — it takes ~ 192 kbps of my internet channel.
1.Create pulseaudio_user.tt with following content: = Create pulseaudio_user.te with following content:
2.# loginctl enable-lingering media = # loginctl enable-linger media