Showing posts with label upnp. Show all posts
Showing posts with label upnp. Show all posts

2008/06/08

UPnP client under Ubuntu: djmount

While there are quite a few UPnP servers for Linux out there (MediaTomb, Rhythmbox Coherence Plugin,...), I couldn't find any serious UPnP client (or UPnP-renderer in UPnP-speak) for Linux. I did find some promising libraries like the C++ Platinum UPnP library (used in XBMC) or the Java UPnpLib., but as far as I know no Linux MediaPlayer (like Rhythmbox or Amarok) uses those. There is also a UPnP 'controller', Cidero written in Java, but it has no playback capabilities. Cidero is very useful for debugging your UPnP setup, however.

The only relevant linux UPnP-client is djmount, also used in GeexBox. It is quite primitive: the UPnP devices are mounted as a filesystem. There are no debian packages available for djmount; you have to build it from the sources. The best copy/paste scenario for installing djmount on ubuntu is http://linuxowns.wordpress.com/2008/06/05/accessing-upnp-server-from-ubuntu/.

Unfortunately the last step '6', ie. autorunning djmount at logon doesn't work -- at least under Ubuntu 8.04. If you have a wlan, djmount fails when no network is up. As a comment by 'anonymous' points out, the Ubuntu NetworkManager fires the /etc/NetworkManager/dispatcher.d/01ifupdown script that runs (with run-parts) all scripts in /etc/network/if-up.d under root.

The following steps do work for autostarting djmount under ubuntu:
cd /etc/network/if-up.d
gksudo gedit ./djmount
contents of script:
#!/bin/sh

# Not for loopback!
[ "$IFACE" != "lo" ] || exit 0

modprobe fuse
fusermount -u /media/upnp
djmount -o allow_other /media/upnp

sudo chmod 755 ./djmount
sudo chown root ./djmount
sudo chgrp root ./djmount
Djmount is now (re)mounted whenever the network is up. As stated previously, djmount is a very rudimentary solution because Rhythmbox for example will parse and analyse all mp3s again. Maybe the linux mediaplayers will integrate some of the existing UPnP Libraries in the future. This would be a welcome addition. I'm still hesitating between using djmount or using regular samba-mounts on my laptop.

update 7/7/2008 : This fixed version runs djmount after the network is connected. No need for setuid or "sleep 30" anymore. (*)

(*) to remove the old version of the scripts this post in its first form suggested, you must:
  • remove the upnp action from the System/Preferences/Sessions
  • sudo rm -f /usr/local/bin/djmount.sh
  • sudo chmod u-s /usr/local/bin/djmount
  • sudo chmod g-s /usr/local/bin/djmount

2008/06/05

Running Mediatomb on CH3WNAS natively!

I managed to get MediaTomb running on the Grab'n'Go CH3WNAS without gentoo! There is no need to follow the gentoo steps in http://forum.dsmg600.info/t916-Installing-mediatomb.html since the MediaTomb project itself provides binaries for the PPC cpu with no dependencies. MediaTomb provides you a better uPnP Server than the original upnp in the firmware.

Since uPnP has no authentication, make sure you run the CH3WNAS behind a NAT router!

Those are the steps to setup MediaTomb on the CH3WNAS:
  • Download the mediatomb build for the ppc-platform:
    http://downloads.sourceforge.net/mediatomb/mediatomb-static-0.11.0-r1-linux-uclibc-ppce300c2.tar.gz
    (or, to get the latest version, surf to http://mediatomb.cc/pages/download#static and then click on the latest mediatomb-static*-ppc*tar.gz file)

  • unzip the tar.gz and ftp (e.g. with gftp) the full mediatomb-directory to the CH3WNAS under HD_a2 (= /mnt/HD_a2/ on the device)

  • telnet to the device (scroll down in my previous post for fun_plug'in and enabling telnet)

  • make executable:
    chmod 775 /mnt/HD_a2/mediatomb/usr/bin/mediatomb

  • chmod mediatomb.sh for easier ftp(*):
    chmod 777 /mnt/HD_a2/mediatomb/mediatomb.sh

  • edit (e.g. with ftp mediatomb.sh to start mediatomb as daemon +fix LAUNCHDIR bug):
    #!/bin/sh

    # if you want to launch this script from a different directory (for example
    # from an another init script or similar, set the LAUNCHDIR variable below
    # to the absolute path of the mediatomb.sh script

    #LAUNCHDIR=`pwd`
    LAUNCHDIR=/mnt/HD_a2/mediatomb

    rm -f $LAUNCHDIR/mediatomb.log

    export MEDIATOMB_DATADIR="$LAUNCHDIR/usr/share/mediatomb"
    export MEDIATOMB_MAGIC_FILE="$LAUNCHDIR/usr/share/file/magic"
    $LAUNCHDIR/usr/bin/mediatomb -m $LAUNCHDIR -f config -d -l $LAUNCHDIR/mediatomb.log

    !! Remark: Make sure the script is Unix-encoded (single \n for line-breaks), otherwise you'll get a "-ash /mnt/hd_a2/mediatomb/mediatomb.sh" error. try this command to translate the linebreaks:
    /mnt/HD_a2/busybox dos2unix /mnt/HD_a2/mediatomb/mediatomb.sh > /mnt/HD_a2/mediatomb/mediatomb.sh.new
    mv /mnt/HD_a2/mediatomb/mediatomb.sh.new /mnt/HD_a2/mediatomb/mediatomb.sh
  • a first run will create the config.xml:
    /mnt/HD_a2/mediatomb/mediatomb.sh
    then run kill `pidof mediatomb` to stop the daemon

  • for easier editing of the config.xml (*):
    chmod 666 /mnt/HD_a2/mediatomb/config/config.xml

  • now modify (ftp) the newly created /mnt/HD_a2/mediatomb/config/config.xml in order to add a fixed ipadres or interface and optional port.

    <server>
    ...
    <name>Michael's MediaTomb</name>
    <udn>...</udn>
    <ip>192.168.1.30</ip>
    <port>50505</port>
    <!-- or define port <interface>br0</interface> -->
    <home>/mnt/HD_a2/mediatomb/config</home>
    ...
    <protocolInfo extend="yes"/>
    ...
    <!-- add extra mappings for jpeg / mpeg -->
    <map from="JPG" to="image/jpeg"/>
    <map from="jpg" to="image/jpeg"/>
    <map from="mpg" to="video/mpeg"/>
    <map from="m4a" to="audio/mpeg"/>
    ...
    The config.xml is well-documented at http://mediatomb.cc/pages/documentation#id2536421. Check out the docs in order to support for example PS3 connections.
  • for auto-startup, you can add the following lines your fun_plug:
    ...
    #kill legacy upnp
    kill -9 `pidof upnp`

    #start mediatomb
    /mnt/HD_a2/mediatomb/mediatomb.sh

    As you can see, I still run firefly, because I couldn't get a uPnP client working in Ubuntu (Rhythmbox).

  • after startup, connect to MediaTomb for configuring the directories to watch: (e.g.) http://192.168.1.30:50505/
I'm not 100% sure that my config is OK, because I couldn't get Rhythmbox (+python-coherence) connecting to MediaTomb. I can see the uPnP broadcast messages from MediaTomb in WireShark and the Cidero java client can connect to MediaTomb and show a tree of media files. Cidero has no playback capabilities, so it's still possible I'll have to tweak the config a bit.

update 9/7/2008: fixed the config for serving jpeg (see comments below) / using correct 'magic' files. If you used a previous version of this post, delete the bogus config.xml and mediatomb.db* files and follow the steps starting with fixing mediatomb.sh.

(*) Close this small security hole: revert to the original protection with a chmod 440 or 550 afterwards. Of course, with telnet and upnp enabled, you'd better keep the CH3WNAS behind a NAT router.