Raspberry Pi network audio player: pulseaudio, DLNA and bluetooth A2DP – part 2: DLNA


Raspberry Pi DLNAThis article is part 2 of 3, where I cover DLNA renderer and DLNA media server. At first I planned to do only the rendering, but now also included serving media for those who have hooked up some storage with music/videos/photos . Parts 1 and 3 focus on setting up pulseaudio over network, and a bluetooth audio A2DP accessory role for the Pi respectively. In the end you get a multi-protocol audio-playing Raspberry Pi.

Why DLNA?

The goal is simple: make Raspberry Pi play music remotely. Technically this can be already accomplished with what I described in the pulseaudio article, but that solution has several drawbacks. The DLNA way provides a different approach, with the following advantages:

  • playback from any OS/device (not just Linux/UNIX with pulseaudio sending an audio stream), eg. some Windows or smart TV
  • playback control from your phone/tablet/etc
  • independent playing device, controlling device, and media storage device (any independence of these if required)

DLNA concepts

Before I dive into configuration let me first clarify some basics on what DLNA/UPnP is all about. In short, DLNA is the functionality, and UPnP is the underlying communications mechanism used in a local network. While I’ll skip the latter, the former could be shortly described as a way multimedia is managed between independent devices. Basic use cases consist of three major DLNA roles:

  • DLNA media server – there is a device storing your files somewhere on your (W)LAN. This might be your NAS with DLNA capabilities, or a computer with appropriate software configured and running (good fit for Raspberry Pi)
  • DLNA controller – to manage the playback of your media, seek, skip, pause, and track time you need a controller. This is where you press PLAY :)
  • DLNA renderer – in the end you need to actually watch or listen to the media. This is where you have a display and/or speakers connected (also a good fit for the Pi)

Sometimes there is also DLNA player mentioned – combining controller and renderer together as one entity. Below I focus on two of these roles; controller is omitted here.

DLNA Renderer

As of today (March 2013), there are not many choices in terms of software for providing this capability. There seem to be larger projects providing this functionality (as far as I remember: XBMC possibly via Raspbmc or OpenELEC), but adhering to the traditional UNIX philosophy of small utilities for well-defined tasks, I skipped these. Some time ago GMediaRender project was being developed, which would suit audio just fine, but currently it is a bit buggy and not really usable in production. Luckily Henner Zeller decided to resurrect the code forking it to gmrender-resurrect – which works just great.

It is a project in development, which currently needs to be acquired from github directly. Let’s get build and run dependencies:

$ sudo aptitude -P install git alsa-base alsa-tools alsa-utils \
automake cvs gstreamer0.10-alsa gstreamer0.10-ffmpeg \
gstreamer0.10-fluendo-mp3 gstreamer0.10-plugins-base \
gstreamer0.10-plugins-good gstreamer0.10-pulseaudio \
gstreamer0.10-tools libglib2.0-dev libgstreamer0.10-0 \
libgstreamer0.10-dev libgstreamer-plugins-base0.10-0 libupnp-dev \
libxml2-dev

And now for the software (local $HOME installation for clarity, not elegance):

$ mkdir -p software/gmrender-resurrect && cd software/gmrender-resurrect
$ git clone https://github.com/hzeller/gmrender-resurrect
$ cd gmrender-resurrect
$ # less README
$ ./autogen.sh # Edit: added
$ ./configure --prefix=$HOME/opt/gmrender-resurrect && make install

Finally, run it:

$ $HOME/opt/gmrender-resurrect/bin/gmediarender -f "Raspberry Pi"

You should now see it starting up, registering for various mime media types, and finally saying:

Ready for rendering..

Note: If you plan to run a few of these on one local network (as I happen to do) you might seriously consider using -u command line switch to specify renderer’s UUID. For example, to derive one from Ethernet’s MAC address:

$ UUID="`cat /sys/class/net/eth0/address |sed 's/:/\n/g'| \
xargs -iqwe printf "%03d" 0xqwe`"
$ $HOME/opt/gmrender-resurrect/bin/gmediarender -f "Raspberry Pi" -u $UUID

For starting it up on boot you can either write an init script, or add these commands to /etc/rc.local – with the last one single-quoted in a su call like this:

su - pi -c '(...)' >/dev/null &

Now on to the media server. If you need just the renderer you can skip that – these can be installed independently.

DLNA Media Server

It looks like the minidlna server implementation (small programs for well-defined tasks, remember?) is in Raspbian repositories:

$ sudo aptitude -P install minidlna

The configuration is pretty straightforward in /etc/minidlna.conf – just set your media_dir as explained in the comments to the path(s) where your media is mounted. You could also change friendly_name to RaspberryPi and serial to some unique value if required. To start just use the init script provided:

$ sudo /etc/init.d/minidlna start

On its first run it will start indexing your files and building database. Give it some time to complete. And off to testing :)

Testing Raspberry Pi DLNA operation

Get your controller, and browse the network. Whether it is your TV, some Windows software, or BubbleUPnP on Android you should see your renderer and/or media server on the network. Here’s an example from BubbleUPnP:

BubbleUPnP (Android) DLNA controller displaying Raspberry Pi renderer and media server

BubbleUPnP (Android) DLNA controller displaying Raspberry Pi renderer and media server

As far as I recall, on Windows you can right-click a local file and select “Play To”, and Raspberry Pi should be there as a renderer for you to pick. Do not be discouraged if the playback fails, it might be not your fault, since Windows Media Player requires the file to be in its library, and you need to set-up WMP to allow access, etc. Personally I had mixed results with this.

Notes

You might not notice it at first, but DLNA is not only about local media. The renderer can also play media streamed from outside, eg. internet radio. If your controller allows you to play an URL, you might try pasting to it something from shoutcast.com (BubbleUPnP and XiiaLive do this together perfectly and automatically on Android).

If you get popping and clicking sound while changing songs, check if your Raspberry Pi’s audio device is kept open playing silence – my earlier article covers this issue.

Have fun!

Next

About these ads

24 Responses to “Raspberry Pi network audio player: pulseaudio, DLNA and bluetooth A2DP – part 2: DLNA”


  1. 1 Axel 31.03.2013 at 10:53

    Hi – im try to using your How To do on my Pi – but after cloning the GIT the “./configure –prefix=$HOME/opt/gmrender-resurrect && make install” dont work – if i look at the Directory – there is no “configure” within there ?
    What i making wrong ?

    • 2 Apatsch 01.04.2013 at 16:30

      Hi, if you take a look in the INSTALL.md there’s one more step before ./configure, namely ./autogen.sh – I have just updated the article to include this step.

  2. 3 pmac 09.04.2013 at 21:16

    Great article!
    Looks like this is exactly what I am searching for. But unfortunatly I am new to Linux ….
    You recommend gmrender-resurrect. Can it use the hdmi port for playing audio?
    thanks
    pmac

    • 4 Apatsch 09.04.2013 at 22:51

      I did not test it with HDMI, but I think it should just work out of the box, or require minimal configuration.

  3. 5 p 10.04.2013 at 18:39

    Gibt es das als fertiges Image?
    Würde gerne etwas dafür spenden …

    • 6 Apatsch 23.04.2013 at 23:29

      Derzeit nicht. Aber wenn ich etwas Zeit finde ich könnte eine erstellen. // Not currently. But if I find some time I could create one.

  4. 7 Peter 09.05.2013 at 19:29

    Hi, thanks for such a useful guide. I was running raspbmc as my DLNA renderer but thought it was a big piece of software to only use a small part plus it’s a little awkward to use headless.

    Anyway, I have a question / small issue – every time a new audio file starts, the volume is set back to the default level as set in the ALSA mixer.

    I could set the default to 100% and use my amplifier’s volume control but I was hoping to have it all controlled from BubbleUPNP.

    Any thoughts on how to keep the gmrender set audio level persistent across music track changes?

    • 8 Apatsch 09.05.2013 at 23:09

      Hi Peter! I have just checked my setup and I could not observe the issue you are describing with neither manual/automatic song change. I am currently running commit 0a8f9c495ebde88680c69e69e045636f04b01b8e of gmrender-resurrect on my Pi. Might be the audio device reopening. Did you try pulseaudio/pacat combination to keep the audio device open playing silence, and gmrender going through pulseaudio?

      • 9 petermgates 10.05.2013 at 01:45

        Hmm, I rolled back to my original raspbian image and went through it all again and now it seems to work properly. Thanks for your help.

  5. 10 Ivan 02.10.2013 at 12:22

    Hi, great article! I’m currently struggling to run all that on my MK802 miniPC.
    But the question is: is it possible to stream same audio on multiple devices simultaneously using DLNA and gmrender-resurrect?
    Thanks!

    • 11 Apatsch 02.10.2013 at 20:03

      I am not sure what you want to achieve… Did not explore running multipoint DLNA; I am not even sure if it has any chance to work without audio synchronization issues between the nodes. What exactly would you like to do?

      • 12 ivanjjill 03.10.2013 at 12:02

        Thanks for response!
        The plan is: to have several DLNA-renders in different rooms, playing same music, and controlled with a single control device.
        I found as well this:

        http://www.bubblesoftapps.com/bubbleupnpserver/

        might help with a single device control.
        but I’m not sure about synchronization.
        Thought you might have done something similar.
        I know that pulseaudio has such functionality but not sure about DLNA.
        Cheers!

      • 13 Apatsch 03.10.2013 at 14:24

        Hi, this is exactly what I am doing at my place, except it is not with DLNA, but pulseaudio. As far as I understand DLNA, on play command the player gets an URL of media to be played, connects, and starts. Taking this architecture into account I doubt if there is any additional way of synchronizing playback between them. Surely you can command 3 players to play one resource, but they can start with delays (sec-msec), and then go out of sync over 1h of playback anyway (quartz differences). The thing is, that pulseaudio compensates this as best as it can. It may not be always ideal, sound devices may vary on the network in terms of buffer sizes… The out of sync effect is especially audible when you are in the center and hear every device equally.

        Why are you sticking with DLNA for this?

      • 14 ivanjjill 03.10.2013 at 15:06

        It’s just that I have Synology NAS Server running DLNA, and I’d like to use it as multimedia server. From what I’m aware of there is no possibility to set it as pulseaudio server, and therefor I have to stick with DLNA. So I thought maybe gmrender-resurrect supports renders synchronization. If not, I’ll probably just stick with AirPlay from apple, as Synology runs iTunes server from box. More cash but less troubles though…

      • 15 Apatsch 04.10.2013 at 00:06

        Hmm, you might try playing on a DLNA player media from your NAS, and the player would play to local pulseaudio device, and pulseaudio would play to the network (and other pulses). You might want to try this out. But Synology NAS Server runs linux, right? You could consider doing research on installing pulseaudio on it :) If it is a player.

    • 16 Marwa 13.03.2014 at 14:51

      Is there a way to turn autompd off (remove the proilfe permanently)? For some reason gmpc changes to it automaticly sometimes (seems pretty random). Then it tries to index everything (cpu hogging) in my home folder.Autompd is defiantly a great idea, but old mpd users will not appreciate it.

  6. 17 Adam 23.12.2013 at 18:41

    How can i make the dlna client start on boot headless?

    It works if i put the command in ssh

    but i wont it to be automatically

    Sorry for Noob question.

    • 18 Apatsch 23.12.2013 at 19:00

      Well, you might want to add the command to /etc/rc.local – it’s there, in the article :)

      • 19 Adam 25.12.2013 at 10:50

        I did that, it did not work,

        Since i asked i maneged to do this.

        Thank you

      • 20 Apatsch 25.12.2013 at 12:45

        Glad to hear you got it running, what was the solution that worked for you?

  7. 21 fecub 18.01.2014 at 17:17

    Reblogged this on fecub Blog.

    • 22 Juanca 02.05.2014 at 13:08

      Hello, thanks for the great guide. I’ve a doubt about what have i to install to play music files from xbmc to one wifi speaker (Pioneer A4 XW-SMA4-K). Thanks a lot for the answer and congratulations for the blog.

  8. 23 comment-1075 23.07.2014 at 03:10

    Dzięki takim wpisom jak te pokochałem internetowe blogi


  1. 1 scott tucker Trackback on 05.07.2014 at 00:19

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Enter your email address to follow this blog and receive notifications of new posts by email.

Join 47 other followers

Marcin Gałkowski

Seasoned admin, Linux hacker, Android fan, Gentoo enthusiast. Doing digital audio on Linux when time permits. At work: IT Team Lead (+labs, +datacenters...)

Latest Tweets

BTC tip jar:

1HprotPu2zi8v8hFZBqVfcTYL7ZYVYBruo

Follow

Get every new post delivered to your Inbox.

Join 47 other followers

%d bloggers like this: