Streaming audio from Ubuntu Linux to a DLNA player (Blu Ray or PS3) using Rygel

This project started out of researching how to play sound from spotify or rhythmbox from my laptop running ubuntu 11.10 through my hifi. Initially I set out to see if an airport express would work using raop and pulseaudio but it seems that support for the new 802.11 version is flakey so I didn't wish to invest £80 in a device that might not work. During my research I found that DLNA supported streaming, DLNA is a protocol commonly used for sharing media files with devices such as networked dvd players, internet tvs and consoles like the ps3 so I explored further.

DLNA is supported in Ubuntu (and other modern linux distros) by Rygel, part of the Gnome project. Rygel provides a DLNA server which also has the capability to capture a pulseaudio sink (an input or output stream) and stream it to a DLNA enabled device.

Below are the steps I took to enable me to stream audio from my computer to my Sony BDP-S370, they should be applicable to any similar device: <!--more-->

  1. Install required packages:

    sudo apt-get install rygel rygel-gst-launch wavpack
    

  2. Find the name of the pulseaudio sink which you wish to capture: To list the choices, use:
    pacmd list-sinks
    

    Then make a note of the name attribute (minus surrounding brackets), in my case it was:

    alsa_output.usb-C-Media_INC._USB_Sound_Device-00-Device.analog-stereo
    

    I found that adding .monitor to this was required for the next stage, this can be achieved in one command:

    pactl list | egrep -A2 '^(\*\*\* )?Source #' | grep 'Name: .*\.monitor$' | awk '{print $NF}' | tail -n1
    

  3. Edit /etc/rygel.conf: Replace (or comment out)

    [GstLaunch]
    enabled=true
    launch-items=audiotestsrc;videotestsrc;videotestoverlay
    audiotestsrc-title=Audiotestsrc
    audiotestsrc-mime=audio/x-wav
    audiotestsrc-launch=audiotestsrc ! wavenc
    videotestsrc-title=Videotestsrc
    videotestsrc-mime=video/mpeg
    videotestsrc-launch=videotestsrc ! ffenc_mpeg2video ! mpegtsmux
    videotestoverlay-title=Videotestsrc with timeoverlay 2
    videotestoverlay-mime=video/mpeg
    videotestoverlay-launch=videotestsrc ! timeoverlay ! ffenc_mpeg2video ! mpegtsmux
    

    with

    [GstLaunch]
    enabled=true
    launch-items=mypulseaudiosink
    mypulseaudiosink-title=Audio on @HOSTNAME@
    mypulseaudiosink-mime=audio/x-wav
    mypulseaudiosink-launch=pulsesrc device=alsa_output.usb-C-Media_INC._USB_Sound_Device-00-Device.analog-stereo.monitor ! wavpackenc
    

    replacing the device on the last line with the output from the previous stage.

  4. Start Rygel (type rygel in the terminal)
  5. Connect your player to the DLNA device which should have appeared (probably as GstLaunch) and you should hear any audio played on your computer through your DLNA device.
  6. If you wish (I don't) add rygel to run at startup.
This worked perfectly for my desktop but for my laptop I had to fiddle with which hardware output of the soundcard was being used under the standard gnome sound settings, changing the profile for the selected device to an option with no output (ie input only or disabled).

Alternatives

Acknowledgements

I figured all this out with the help of these guys: Thanks.