Dienstag, 13. November 2012

Setup a Media Renderer on a headless NAS w/ USB Soundcard

Hey everybody!

Got this NAS (GoFlex Net) for quite a long time, serving all my needs - till now!

Recently I aquired a new Android device, a very powerful one with LTE, which gave me the idea how great it would be to be able to send YouTube musicstreams from the android device over to the NAS, playing the sound on my crappy soundsystem with heavy bass :D

Before this moment, the NAS only used MPD + Alsa to talk to the attached USB soundcard.

What am I even looking for?

Converting Youtube videos on the mobile device, only pulling the audiostream from it .. sending it over to a networkshare and re-reading MPD database?
NAAAH... way too much work and very time intense.

What about pulseaudio-server on the NAS and pulseaudio-client on the android device? NAAAH... there is no pulseaudio-client on Android (well there is, with a lot hacking and ditching AudioFlinger involved afaik) - so, option dismissed!

Well... there is still uPnP, right? It's very doubtful I could run xbmc on this little 1,2GhZ ARM processor and still use the other services (samba, nfs, sabnzbd, mpd, pyload) on the NAS properly... also, there is no gpu or hardware-renderer so let's dismiss this option too.

After making some research for my options I came across a nice project called GMediaRenderer - It uses Gstreamer to catch files via uPnP and playback those locally. The problem is, the original version of it is not in a very functional state BUT somebody, hzeller "Henner Zeller", picked it up and got it to a working condition - he calls it >gmrender-resurrect< :)

At first I had to install pulseaudio and run it in system-wide mode so MPD and GmediaRenderer can both use it (normally MPD autospawns it's own pulseaudio session, we don't want that in this case). Please note that I am working as root the whole time, I know it's unsafe, but meeh.. it's just a little embedded device.

 # Install pulseaudio via package-manager  
 apt-get install pulseaudio pulseaudio-utils  
   
 nano /etc/default/pulseaudio  
 # Change PULSEAUDIO_SYSTEM_START from 0 to 1  
 # Change DISALLOW_MODULE_LOADING from 1 to 0  
 # Save the file  

Now we would like to adjust MPD to use pulseaudio instead of alsa.
 # Add mpd user to pulse-access group  
 usermod -aG pulse-access mpd  
   
 # Change mpd from alsa to pulse  
 nano /etc/mpd.conf  
   
 # Comment out all alsa references like this:  
   
 #audio_output {  
 #  type    "alsa"  
 #  name    "My ALSA Device"  
 #  device    "hw:0,0"  # optional  
 #  format    "44100:16:2"  # optional  
 #  mixer_device  "default"  # optional  
 #  mixer_control  "PCM"    # optional  
 #  mixer_index  "0"    # optional  
 #}  
   
 # Now make the pulse-section look like this  
 audio_output {  
 type    "pulse"  
 name    "MPD PulseAudio Stream"  
 }  
   
 # Save the file  

Reboot your machine and verify that MPD is still working! If everything is correct, continue with the following steps to install GMediaRenderer.
 #Install dependencies
 apt-get install alsa-base alsa-tools alsa-utils gstreamer0.10-alsa \
 gstreamer0.10-ffmpeg gstreamer0.10-fluendo-mp3 gstreamer0.10-plugins-base \
 libgstreamer-plugins-base0.10-0 libgstreamer0.10-0 libgstreamer0.10-dev \
 gstreamer0.10-plugins-good gstreamer0.10-tools libupnp-dev automake git

 #Clone the repository
 git clone git://github.com/hzeller/gmrender-resurrect.git
 cd gmrender-resurrect

 #Build the application
 ./autogen.sh
 ./configure
 make
 make install

 #You need to add our user to the "pulse-access" group
 usermod -aG pulse-access root

Now that the application *should* be built, we can run it.
 gmediarender -f "NAS MediaRenderer"
 #You don't have to care about the dbus / X11 errors

Now you should be able to push Videos from your Android device to the MediaRenderer and hear the sound playing. Personally, I am using "BubbleUPnP" on Android. If everything works, you can make it autostart on boot.
 cat > /etc/init.d/gmediarender << EOF
### BEGIN INIT INFO
# Provides: gmediarender
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start GMediaRender at boot time
# Description: Start GMediaRender at boot time.
### END INIT INFO
#! /bin/sh
# /etc/init.d/gmediarender
USER=root
HOME=/root
export USER HOME
case "$1" in
 start)
 echo "Starting GMediaRender"
 /usr/local/bin/gmediarender -d -f "NAS MediaRenderer"
 ;;
stop)
 echo "Stopping GMediaRender"
 killall gmediarender
 ;;
*)
 echo "Usage: /etc/init.d/gmediarender {start|stop}"
 exit 1
 ;;
esac
exit 0
EOF

 #Make it executable
 chmod 755 /etc/init.d/gmediarender

 #Configure the system to run it on startup:
 update-rc.d gmediarender defaults
Reboot the system and you should be good to go :)

UPDATE  1: In the init.d script I forgot to start gmediarender as DAEMON, FIXED!


Links which helped me during this process:
http://mpd.wikia.com/wiki/PulseAudio
http://chrisbaume.wordpress.com/2012/06/24/raspberry-pi-upnp-media-player/
https://github.com/hzeller/gmrender-resurrect
http://www.ubuntugeek.com/how-to-setup-mpd-with-pulseaudio-independent-on-x.html

Keine Kommentare:

Kommentar veröffentlichen