Redirect Linux sound to DLNA receivers using PulseAudio

Slashdot it! Delicious Share on Facebook Tweet! Digg!
fotum, 123RF.com

fotum, 123RF.com

Sonic Redirection

Using PulseAudio DLNA, you can redirect your computer's sound to a stereo system or TV via the network. Even Google's Chromecast dongle supports the latest version of the program.

PulseAudio constantly has to fend off harsh criticism – sometimes justifiably, but often wrongly because it is definitely possible to do some interesting things with the flexible sound server. You can, for example, adjust the volume of individual applications or redirect the sound to another computer that has speakers connected to its audio output.

This is where DLNA comes into play. The protocol lets you stream multimedia data via the network. Streaming is really easy thanks to PulseAudio DLNA [1] if you have a DLNA-enabled AV receiver or another device with the necessary support, such as a home cinema PC or a Raspberry Pi with Kodi. The latest version of the DLNA server used with PulseAudio also supports Google's Chromecast dongle and (at least in theory) Sonos loudspeakers.

PulseAudio and DLNA

The developer of the program, Massimo Mund, provides a Ubuntu PPA for systems as of 14.04 LTS ("Trusty Tahr") for installing the latest version of PulseAudio DLNA [2]. Listing 1 shows the commands for integrating PPAs and installing the program. There are also packages for openSUSE and Fedora [3]; Arch Linux users will find the program in the AUR [4]. You at least need to install version 0.4.0 to help PulseAudio DLNA make friends with Google's Chromecast (Figure 1). The information in this article is related to PulseAudio-DLNA 0.4.4 from early August 2015.

Figure 1: PulseAudio DLNA supports DLNA-enabled receivers such as modern TVs and AV receivers and also Google's Chromecast dongle.

Listing 1

Installing PulseAudio DLNA

$ sudo apt-add-repository ppa:qos/
  pulseaudio-dlna
$ sudo apt-get update
$ sudo apt-get install pulseaudio-dlna
  pavucontrol

After installing PulseAudio DLNA, start it from a terminal and call up the pavucontrol volume control installed with PulseAudio from the last line of Listing 1. A range of information will now appear in the terminal; the lines with Added the device <Device> are of particular interest (Listing 2). You can see from these lines which DLNA devices PulseAudio-DLNA finds on the network. In our lab, it worked without any problems with an LG TV, with a Raspberry Pi with Kodi in the form of OpenELEC, and with the Volumio [5] audio server distribution and Chromecast.

Listing 2

Setup Information

$ pulseaudio-dlna
08-01 13:23:36 pulseaudio_dlna.application
  INFO Using localhost: 192.168.178.49:8080
08-01 13:23:36 pulseaudio_dlna.application
  INFO Loaded encoders:
08-01 13:23:36 pulseaudio_dlna.application INFO
[...]
08-01 13:23:38 pulseaudio_dlna.pulseaudio
  INFO Added the device "42LS560S-ZC (DLNA)".
08-01 13:23:38 pulseaudio_dlna.plugins.chromecast.renderer
  INFO The Chromecast seems not to be an original Chromecast!
  Model name: "FireTV" Skipping device ...
08-01 13:23:38 pulseaudio_dlna.plugins.chromecast.renderer
  INFO The Chromecast seems not to be an original
  Chromecast! Model name: "FireTV" Skipping device ...
08-01 13:23:38 pulseaudio_dlna.pulseaudio
  INFO Added the device "Livingroom (Chromecast)".
08-01 13:23:43 pulseaudio_dlna.listener
  INFO Discovery complete.
[...]

PulseAudio DLNA also recognizes the Amazon Fire TV but ignores it, saying The Chromecast seems not to be an original Chromecast! . The program version 0.3.5 also recognized the Sonos loudspeakers – but they remained silent when we fed sound to them. PulseAudio DLNA 0.4.4 no longer lists the active Sonos devices on the network, even if the description still lists Sonos speakers as compatible devices (see the "Sonos Speakers" box).

Sonos Loudspeakers

Although Sonos claims on its website that it is not compatible with DLNA streams [8], Sonos loudspeakers unofficially work as DLNA receivers. Version 0.4.5 of PulseAudio DLNA, which had not yet been released when this article was written, finds Sonos speakers on the network [9] and offers them as audio sinks in PulseAudio. However, in this case, the system only supports streams to individual loudspeakers of the multi-room audio system, not to groups of several Sonos devices.

Stream the audio data in WAV format so that the sound arrives without interference from the Sonos loudspeakers. To do this, start PulseAudio DLNA with the --encoder wav option. If the sound from the Sonos speakers is still not satisfactory, then set the volume for that stream to 100 percent in the PulseAudio volume control and jiggle the volume control a bit. After taking a few moments to adjust, the sound streamed from the computer will come clearly and cleanly from the Sonos speakers.

If PulseAudio DLNA fails to launch because other applications are already listening on port 1900, switch off SSDP (Simple Service Discovery Protocol) using the --disable-ssdp-listener option (Listing 3). With Gnome, for example, Gnome photos automatically searches for DLNA servers with images on the network using dLeyna [6].

Listing 3

Switch off SSDP

$ pulseaudio-dlna
[...]
08-10 14:04:39 pulseaudio_dlna.application  ERROR  The SSDP
  listener could not bind to the port 1900/UDP. Perhaps this
  is already in use? Application terminates. You can disable
  this feature with the "--disable-ssdp-listener" flag.
$ sudo netstat -tunlp | grep 1900
udp        0      0 239.255.255.250:1900    0.0.0.0:*
    6358/dleyna-rendere
udp        0      0 192.168.111.192:1900    0.0.0.0:*
    6358/dleyna-rendere
udp        0      0 239.255.255.250:1900    0.0.0.0:*
    6358/dleyna-rendere
udp        0      0 127.0.0.1:1900          0.0.0.0:*
    6358/dleyna-rendere
$ pulseaudio-dlna --disable-ssdp-listener

Occasionally, however, PulseAudio itself also occupies the port for sending and receiving multicast/RTP (Real-time Transport Protocol); see Figure 2. You can check this if necessary in the PulseAudio settings (installable via paprefs in most distributions).

Figure 2: If PulseAudio is being used as a receiver or transmitter for multicast/RTP, the sound server occupies port 1900 requested by PulseAudio DLNA.

Forwarding Sound

For a first test, open any application that plays sound and switch to PulseAudio volume control. Select the corresponding program in the Playback tab and, from the drop-down menu, choose the device to which you want PulseAudio DLNA to forward the sound (Figure 3). The sound will come from the corresponding device a few seconds later – you do not need to leave the terminal window open with PulseAudio DLNA.

Figure 3: You can forward the sound from the desired application to the discovered DLNA devices using the PulseAudio volume control with PulseAudio DLNA running.

If you turn off the selected audio device, PulseAudio DLNA automatically switches back to internal audio. The sound server remembers the combination of program and target. As long as you don't stop PulseAudio DLNA, it will automatically play the sound from the selected application through the DLNA device, even if you restart the device in the meantime.

To check the process, take a look at the terminal by calling up PulseAudio DLNA. Here the program reports the stream and provides further information about the errors for you to report to the developer (Listing 4).

Listing 4

Report from PulseAudio DLNA

[...]
08-01 13:24:12 pulseaudio_dlna.streamserver
  INFO Requested streaming URL was: /livingroom_chromecast.wav (HTTP/1.1)
08-01 13:24:12 pulseaudio_dlna.streamserver
  INFO Got request from Chromecast.fritz.box - GET /livingroom_chromecast.wav HTTP/1.1,200,-
08-01 13:24:12 pulseaudio_dlna.streamserver
  INFO Client 192.168.178.54 registered to stream /livingroom_chromecast.wav.
08-01 13:24:12 pulseaudio_dlna.streamserver
  INFO Processes of /livingroom_chromecast.wav initialized ...
sox WARN wav: Length in output .wav header will be wrong since can't seek to fix it
08-01 13:24:13 pulseaudio_dlna.pulseaudio
  INFO The device "Wohnzimmer (Chromecast)" is playing.

Buy this article as PDF

Express-Checkout as PDF

Pages: 3

Price $0.99
(incl. VAT)

Buy Ubuntu User

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia