{"id":1956,"date":"2014-11-30T06:52:34","date_gmt":"2014-11-30T04:52:34","guid":{"rendered":"http:\/\/possiblelossofprecision.net\/?p=1956"},"modified":"2021-05-15T11:46:37","modified_gmt":"2021-05-15T09:46:37","slug":"running-pulseaudio-as-system-service","status":"publish","type":"post","link":"https:\/\/possiblelossofprecision.net\/?p=1956","title":{"rendered":"Running PulseAudio as system service"},"content":{"rendered":"<p>Running PulseAudio in system mode is usually <a href=\"http:\/\/www.freedesktop.org\/wiki\/Software\/PulseAudio\/Documentation\/User\/WhatIsWrongWithSystemWide\/\">a bad idea<\/a>. There are use cases however, where PulseAudio&#8217;s system mode is a great tool, e.g. for building a PulseAudio streaming target to stream audio from multiple clients to speakers.<\/p>\n<p>First, install PulseAudio, <a href=\"http:\/\/en.wikipedia.org\/wiki\/Avahi_%28software%29\">avahi<\/a> (a free implementation of <a href=\"http:\/\/en.wikipedia.org\/wiki\/Zero-configuration_networking\">zeroconf<\/a>) to publish the service throughout the network and the corresponding PulseAudio module:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# yum install pulseaudio pulseaudio-module-zeroconf avahi\r\n<\/pre>\n<p>Since the use cases of PulseAudio in system mode are limited, distributions usually do not ship a systemd unit for it. <\/p>\n<pre class=\"brush: plain; title: \/etc\/systemd\/system\/pulseaudio.service; notranslate\" title=\"\/etc\/systemd\/system\/pulseaudio.service\">\r\n&#x5B;Unit]\r\nDescription=PulseAudio Daemon\r\n\r\n&#x5B;Install]\r\nWantedBy=multi-user.target\r\n\r\n&#x5B;Service]\r\nType=simple\r\nPrivateTmp=true\r\nExecStart=\/usr\/bin\/pulseaudio --system --realtime --disallow-exit --no-cpu-limit \r\n<\/pre>\n<p>For a list of available options, have a loot at the <a href=\"http:\/\/linux.die.net\/man\/5\/pulse-daemon.conf\">pulse-daemon manpage<\/a>.<\/p>\n<p>In Fedora, sound devices (<code>\/dev\/snd\/*<\/code>) are usually owned by <code>root:audio<\/code> and since the <code>pulse<\/code> user who will run PulseAudio daemon later is not part of the <code>audio<\/code> group per default, it cannot access sound devices. Adding the <code>pulse<\/code> user to the <code>audio<\/code> group is simple though<\/p>\n<pre class=\"brush: plain; highlight: [12]; title: ; notranslate\" title=\"\">\r\n# ls -lah \/dev\/snd\/\r\ntotal 0\r\ndrwxr-xr-x  3 root root      180 Nov 18 09:45 .\r\ndrwxr-xr-x 19 root root     3.2K Nov 18 09:45 ..\r\ndrwxr-xr-x  2 root root       60 Nov 18 09:45 by-path\r\ncrw-rw----  1 root audio 116,  2 Nov 18 09:45 controlC0\r\ncrw-rw----  1 root audio 116,  4 Nov 18 11:33 pcmC0D0c\r\ncrw-rw----  1 root audio 116,  3 Nov 18 11:29 pcmC0D0p\r\ncrw-rw----  1 root audio 116,  5 Nov 18 09:45 pcmC0D1c\r\ncrw-rw----  1 root audio 116,  1 Nov 18 09:45 seq\r\ncrw-rw----  1 root audio 116, 33 Nov 18 09:45 timer\r\n# usermod -a -G audio pulse\r\n<\/pre>\n<p>To make PulseAudio available over the network, you have to add a bit of configuration to <code>\/etc\/pulse\/system.pa<\/code><\/p>\n<pre class=\"brush: plain; highlight: [5,6]; title: \/etc\/pulse\/system.pa; notranslate\" title=\"\/etc\/pulse\/system.pa\">\r\n&#x5B;...]\r\n### Enable positioned event sounds\r\nload-module module-position-event-sounds\r\n\r\nload-module module-native-protocol-tcp auth-anonymous=1\r\nload-module module-zeroconf-publish\r\n<\/pre>\n<p>For a list of available module options, consult the <a href=\"http:\/\/www.freedesktop.org\/wiki\/Software\/PulseAudio\/Documentation\/User\/Modules\/\">PulseAudio module dokumentation<\/a>, especially <a href=\"http:\/\/www.freedesktop.org\/wiki\/Software\/PulseAudio\/Documentation\/User\/Modules\/#index22h3\">module-native-protocol-tcp<\/a>.<br \/>\n<code>auth-anonymous<\/code> in particular might be a questionable idea in larger environments. An IP based access control list (<code>auth-ip-acl<\/code>) or a cookie containing some random data that serves as a shared secret between server and clients (<code>auth-cookie<\/code>) could be a more feasible approach.<\/p>\n<p>Next, enable and start the PulseAudio server as well as the avahi daemon<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# systemctl enable pulseaudio.service \r\nln -s '\/etc\/systemd\/system\/pulseaudio.service' '\/etc\/systemd\/system\/multi-user.target.wants\/pulseaudio.service'\r\n# systemctl start pulseaudio.service\r\n# systemctl start avahi-daemon.service\r\n<\/pre>\n<p>You should be able to see a new service being published through avahi on the client:<\/p>\n<pre class=\"brush: plain; highlight: [1]; title: ; notranslate\" title=\"\">\r\n&#x5B;user@PulseClient ~]$ avahi-browse -a\r\n+ enp0s25 IPv4 PulseAudio &#x5B;46:46:46:46:46:46]                 Workstation          local\r\n+ enp0s25 IPv4 pulse@PulseAudio                               PulseAudio Sound Server local\r\n+ enp0s25 IPv4 pulse@PulseAudio: Built-in Audio Analog Stereo PulseAudio Sound Sink local\r\n+ enp0s25 IPv4 pulse@PulseAudio: Built-in Audio Analog Stereo PulseAudio Sound Source local\r\n<\/pre>\n<p>You could then go ahead and use <code>paprefs<\/code> on your client to make remote PulseAudio sound devices available locally:<\/p>\n<div id=\"attachment_1970\" style=\"width: 560px\" class=\"wp-caption aligncenter\"><a data-rokbox data-rokbox-caption=\"Use paprefs to make remote sound devices available locally.\" href=\"wordpress\/wp-content\/uploads\/2014\/11\/paprefs.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1970\" src=\"wordpress\/wp-content\/uploads\/2014\/11\/paprefs-550x286.png\" alt=\"Use paprefs to make remote sound devices available locally.\" width=\"550\" height=\"286\" class=\"size-medium wp-image-1970\" srcset=\"https:\/\/possiblelossofprecision.net\/wordpress\/wp-content\/uploads\/2014\/11\/paprefs-550x286.png 550w, https:\/\/possiblelossofprecision.net\/wordpress\/wp-content\/uploads\/2014\/11\/paprefs.png 647w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/a><p id=\"caption-attachment-1970\" class=\"wp-caption-text\">Use <code>paprefs<\/code> to make remote sound devices available locally.<\/p><\/div>\n<p>Finally, you might want to enable additional audio channels or change the channel mapping on the server:<\/p>\n<pre class=\"brush: plain; highlight: [6]; title: \/etc\/pulse\/daemon.conf; notranslate\" title=\"\/etc\/pulse\/daemon.conf\">\r\n&#x5B;...]\r\n; default-sample-format = s16le\r\n; default-sample-rate = 44100\r\n; alternate-sample-rate = 48000\r\n; default-sample-channels = 2\r\ndefault-sample-channels = 4\r\n; default-channel-map = front-left,front-right\r\n<\/pre>\n<p>Don&#8217;t forget to restart the PulseAudio server afterwards!<\/p>\n<p>Resources:<br \/>\n<a href=\"https:\/\/elehack.net\/writings\/computing\/audio-server\">https:\/\/elehack.net\/writings\/computing\/audio-server<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Running PulseAudio in system mode is usually a bad idea. There are use cases however, where PulseAudio&#8217;s system mode is a great tool, e.g. for building a PulseAudio streaming target to stream audio from multiple clients to speakers. First, install PulseAudio, avahi (a free implementation of zeroconf) to publish the service throughout the network and the corresponding PulseAudio module: #&#8230; <a href=\"https:\/\/possiblelossofprecision.net\/?p=1956\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[7,30],"class_list":["post-1956","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-fedora","tag-pulseaudio"],"_links":{"self":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/1956","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1956"}],"version-history":[{"count":23,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/1956\/revisions"}],"predecessor-version":[{"id":2100,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=\/wp\/v2\/posts\/1956\/revisions\/2100"}],"wp:attachment":[{"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1956"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1956"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/possiblelossofprecision.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1956"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}