This 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.
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)
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.
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:
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.
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.
- Raspberry Pi network audio player: pulseaudio, DLNA and bluetooth A2DP – part 1: pulseaudio (rootprompt.apatsch.net)
- Raspberry Pi overview – 3.5 Watt Linux board (rootprompt.apatsch.net)