me, myself and vdr-mediad ;-) [Update]

Posted on February 9th, 2008

Update:

This patch has been integrated into vdr-mediad-0.1.0rc1. The rc has some other great new features, so go and get it here.

:-)

 
 
 
 
My new board had some disadvantages, one of them: it had internal usb-connectors, which were actually usable! ;-)
So this made me wanna have the mediad-plugin running, so that i can actually use the internal card-reader of my box. Unfortunatly it didnt quite work out of the box.

The first problem was, that it still tried to use pmount.sh even though i told it not to! :-D This was easily fixed. Now everything mounts and unmounts like it should (without pmount btw, see my mount.sh further down).

The next prob were lockups when starting the mp3-plugin. This was caused by endlessly cycling through the list of sources, since i have my vdr set to go to the first entry in lists when pushing down on the last entry.

Then i didnt wanna put a source for every possible device in for the mp3-plugin, so i changed the mediad-plugin to also look for matching parent directories in the mp3-sources.

Okay, lets just get the diff out:

diff -ur mediad-0.0.3/devicesetup.c mediad-0.0.3-patched/devicesetup.c
--- mediad-0.0.3/devicesetup.c  2007-05-22 23:05:26.000000000 +0200
+++ mediad-0.0.3-patched/devicesetup.c  2008-02-02 14:34:24.000000000 +0100
@@ -11,7 +11,7 @@
 device::device()
        : _hasVolume(false), _unLock(false), _name(NULL), _mountPoint(NULL), _curDevice(NULL), _curUDI(NULL), _curMediaType(unknown), _redirectedVideoDir(false), _mountPath(NULL), _mounted(false)
 {
-       if(device::_st_instances == 0)
+       if((! device::st_mountScript) && (device::_st_instances == 0))
                device::st_mountScript = strdup("pmount.sh");
        device::_st_instances++;
 }
@@ -19,7 +19,7 @@
 device::device(const char* name, const char* deviceName, char* mountPoint, bool unLock)
        : _hasVolume(false), _unLock(unLock), _name(NULL), _mountPoint(NULL), _curDevice(NULL), _curUDI(NULL), _curMediaType(unknown), _redirectedVideoDir(false), _mountPath(NULL), _mounted(false)
 {
-       if(device::_st_instances == 0)
+       if((! device::st_mountScript) && (device::_st_instances == 0))
                device::st_mountScript = strdup("pmount.sh");
        device::_st_instances++;

@@ -36,7 +36,7 @@

 device::device(const device& dev)
 {
-       if(device::_st_instances == 0)
+       if((! device::st_mountScript) && (device::_st_instances == 0))
                device::st_mountScript = strdup("pmount.sh");
        device::_st_instances++;
        if(dev._name)
diff -ur mediad-0.0.3/hal.c mediad-0.0.3-patched/hal.c
--- mediad-0.0.3/hal.c  2007-05-29 21:08:48.000000000 +0200
+++ mediad-0.0.3-patched/hal.c  2008-02-04 23:00:55.000000000 +0100
@@ -33,15 +33,16 @@

 void hal::Stop()
 {
-       if(loop) {
-               while(g_main_loop_is_running(loop))
-                       g_main_loop_quit( loop );
-       }
        g_main_context_wakeup(g_main_loop_get_context(loop));
        if( _halContext ) {
                libhal_ctx_shutdown( _halContext, 0 );
                libhal_ctx_free( _halContext );
        }
+       if(loop) {
+               while(g_main_loop_is_running(loop))
+                       g_main_loop_quit( loop );
+       }
+       g_main_loop_unref( loop );
        Cancel(5);
 }

diff -ur mediad-0.0.3/plugins.c mediad-0.0.3-patched/plugins.c
--- mediad-0.0.3/plugins.c      2007-05-23 00:52:07.000000000 +0200
+++ mediad-0.0.3-patched/plugins.c      2008-02-04 22:34:35.000000000 +0100
@@ -382,25 +382,56 @@
                osd->ProcessKey(kGreen);

                const char *last = NULL;
-               while (last != _st_status->Current()) {
-                       if (strcmp(_st_status->Current() + strlen(_st_status->Current())
-                                       - strlen(_st_curDirectory), _st_curDirectory) == 0) {
-
-                               osd->ProcessKey(kRed);    // Select it
-                               osd->ProcessKey(kYellow); // Change to browse mode again
-
-                               osd->ProcessKey(kYellow); // Instant Playback
-                               break;
+               const char *first = NULL;
+               bool found = false;
+               while (last != _st_status->Current() && first != _st_status->Current()) {
+                        DPRINT("dir: %s (%s)\n", _st_status->Current(), last ? last : "NULL");
+                        char *_st_curSubDir = strdup(_st_curDirectory);
+                        char *_st_curSubDirLast = _st_curSubDir + strlen(_st_curSubDir) - 1;
+                        while (_st_curSubDirLast >= _st_curSubDir) {
+                                DPRINT("trying: %s (%s)\n", _st_curSubDir, _st_curDirectory);
+                                if ((strcmp(_st_status->Current() + strlen(_st_status->Current())
+                                                - strlen(_st_curSubDir), _st_curSubDir) == 0)
+                                                && ((* (_st_status->Current() + strlen(_st_status->Current())
+                                                - strlen(_st_curSubDir) - 1)) != ' ')) {
+                                        DPRINT("play it!!\n");
+
+                                        osd->ProcessKey(kRed);    // Select it
+                                        osd->ProcessKey(kYellow); // Change to browse mode again
+
+                                        osd->ProcessKey(kYellow); // Instant Playback
+
+                                        found = true;
+                                        break;
+                                }
+                                do {
+                                        (* _st_curSubDirLast) = 0;
+                                        _st_curSubDirLast--;
+                                        if ((_st_curSubDirLast >= _st_curSubDir) && (* _st_curSubDirLast) == '/') {
+                                                if (_st_curSubDirLast > _st_curSubDir) {
+                                                        (* _st_curSubDirLast) = 0;
+                                                        _st_curSubDirLast--;
+                                                }
+                                                break;
+                                        }
+                                } while (_st_curSubDirLast > _st_curSubDir);
                        }
+                       free(_st_curSubDir);
+                       if (found) {
+                                break;
+                        }

                        last = _st_status->Current();
+                        if (first == NULL) {
+                            first = _st_status->Current();
+                        }
                        osd->ProcessKey(kDown);
                }

                /*delete osd;
                osd = NULL;
                */
-               if (last == _st_status->Current())
+               if (! found)
                        Skins.Message(mtError, tr("Drive not present in mp3sources.conf!"));
        }
        return osd;

And also my mount.sh

#!/bin/bash
# This script is based on the mp3 plugin's mount.sh script
#
# This script is called from VDR to mount/unmount/eject
# devices detected with the mediad plugin
#
# argument 1: wanted action, one of mount,unmount,eject,status
# argument 2: mountpoint to act on
#
# mount,unmount,eject must return 0 if succeeded, 1 if failed
# status must return 0 if device is mounted, 1 if not
#

action="$1"
#device="$2"
path="$2"

if [ -z "$path" ]; then
        exit 1
fi

case "$action" in
mount)
  target=/media/vdr/`echo $path | sed "s/^\/dev\///"`
  if [ ! -d "$target" ]; then
        mkdir "$target"
  fi

  eject -t "$path"        # close the tray
  sudo mount -r "$path" "$target" || exit 1            # mount it
  ;;
unmount)
  sudo umount "$path" || exit 1           # unmount it
  ;;
eject)
  eject "$path" || exit 1            # eject disk
  ;;
status)
  cat /proc/mounts | grep -q "$path" # check if mounted
  if [ $? -ne 0 ]; then              # not mounted ...
    exit 1
  fi
esac

exit 0

AddThis button



About Me

Photo of myself Aike J Sommer
web [at] aikesommer [dot] name
Feed: RSS Syndicate content
Company: AS Media