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:

  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

  • If you just wish to share audio and video files then something like mediatomb with be much more simple (although rygel also shares files).
  • There is meant to be a simpler way to link rygel and pulseaudio where everything works out of the box and rygel appears as a separate audio out but it’s currently broken with the supplied pulseaudio/rygel combination in ubuntu.

Acknowledgements

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

Thanks.

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

  1. Jens says:

    wavpackenc != wav. Wavpack is a lossless compressed audio codec, while WAV is raw PCM samples in RIFF container.

    Also I’m curious why you think that using MediaTomb is easier for file sharing than Rygel :)

  2. Cefn Hoile says:

    I think the reason you needed to add ‘.monitor’ to the end is that you were running the wrong pulseaudio command in the first place. If you run

    pacmd list-sources

    then you get the properly named source device. It’s just a helpful coincidence that the source is named the same as the sink, plus ‘.monitor’.

  3. Paul B says:

    Thank you! Ubuntu 12.04 user here with a Sony MX-CT700NI hifi. At first my hifi couldn’t connect with my music files after I followed the steps above. I had success by changing the boolean values of export pictures and videos to False from True when editing rygel.conf, i.e. only a value of True on exporting music. Now it all works perfectly. Thanks again!

  4. griasi says:

    Anyone succeeded in streaming to an onkyo tx-nr414 (or maybe another onkyo receiver)? Would be grateful for help because so far I couldn’t get it on…

Leave a Reply