[vdr] MP3/MPlayer plugin 0.9.11 (development)

Stefan Huelswitt s.huelswitt at gmx.de
Wed Feb 23 21:44:49 CET 2005


On 20 Feb 2005 "C.Y.M" <syphir at syphir.sytes.net> wrote:

> Here is an example of the error in the syslog:
> 
> Feb 20 10:28:06 sid vdr[7544]: mp3: player thread started (pid=7544)
> Feb 20 10:28:08 sid vdr[4248]: error reading '/dev/input/event2'
> Feb 20 10:28:11 sid vdr[7545]: ERROR: thread 81926 won't end (waited 3 seconds) 
> - canceling it...
> Feb 20 10:28:22 sid vdr[7544]: mp3: player thread ended (pid=7544)
> 
> How to reproduce:
> 
> Put an image file in a directory with a matching mp3 file.  This error occurs 
> the first time the image is converted to a mpg file.  Once the cache file 
> exists, the error does not happen any more.
> 
> I would also like to add that everything *appears* to work correctly from a 
> users standpoint.  The only problem is the error in the syslog (but VDR does not 
> actually shutdown).

Does this patch solves the problem?

Regards.

-- 
Stefan Huelswitt
s.huelswitt at gmx.de  | http://www.muempf.de/
-------------- next part --------------
diff -urN -x '*.o' -x .dependencies mp3-0.9.11/data-mp3.c mp3-unstable/data-mp3.c
--- mp3-0.9.11/data-mp3.c	2005-02-19 12:11:41.000000000 +0100
+++ mp3-unstable/data-mp3.c	2005-02-22 18:18:58.000000000 +0100
@@ -45,7 +39,65 @@
 const char *imagecache = "/var/cache/images/mp3";
 const char *imageconv  = "image_convert.sh";
 
-// --- cSong -------------------------------------------------------------
+// --- cImageConvert -----------------------------------------------------------
+
+class cImageConvert : private cThread {
+private:
+  char *image;
+  enum eStatus { stNone, stRun, stFin };
+  eStatus status;
+protected:
+  virtual void Action(void);
+public:
+  cImageConvert(void);
+  ~cImageConvert();
+  bool Convert(const char *Image);
+  bool Status(void);
+  };
+
+cImageConvert::cImageConvert(void)
+{
+  image=0; status=stNone;
+}
+
+cImageConvert::~cImageConvert()
+{
+  if(status==stRun) Cancel(10);
+  free(image);
+}
+
+bool cImageConvert::Convert(const char *Image)
+{
+  if(status==stNone) {
+    image=strdup(Image);
+    status=stRun;
+    Start();
+    return true;
+    }
+  return false;
+}
+
+bool cImageConvert::Status(void)
+{
+  if(status==stRun && !Active()) status=stFin;
+  return status==stFin;
+}
+
+void cImageConvert::Action(void)
+{
+  nice(3);
+  char *m, *cmd, *qp, *qm;
+  asprintf(&m,"%s%s.mpg",imagecache,image);
+  di(printf("image: convert started %s -> %s\n",image,m))
+  asprintf(&cmd,"%s \"%s\" \"%s\"",imageconv,qp=Quote(image),qm=Quote(m));
+  int r=system(cmd);
+  if(r!=0) di(printf("image: convert returned with code %d. Failed?\n",r))
+  free(cmd); free(qp); free(qm); free(m);
+  di(printf("image: convert finished\n"))
+  status=stFin;
+}
+
+// --- cSong -------------------------------------------------------------------
 
 cSong::cSong(cFileObj *Obj)
 {
@@ -67,10 +119,7 @@
 
 cSong::~cSong()
 {
-  if(queuePid>0) {
-    kill(queuePid,SIGTERM);
-    waitpid(queuePid,0,0);
-    }
+  delete conv;
   delete decoder;
   obj->Source()->Unblock();
   delete obj;
@@ -79,15 +128,23 @@
 
 void cSong::Init(void)
 {
-  decoder=0; user=0; image=0; queuePid=0;
+  decoder=0; user=0; image=0; conv=0; queueStat=0;
   fromDOS=decoderFailed=false;
   obj->Source()->Block();
 }
 
+#if VDRVERSNUM >= 10315
 int cSong::Compare(const cListObject &ListObject) const
+#else
+bool cSong::operator<(const cListObject &ListObject)
+#endif
 {
   cSong *song=(cSong *)&ListObject;
+#if VDRVERSNUM >= 10315
   return strcasecmp(obj->Path(),song->obj->Path());
+#else
+  return strcasecmp(obj->Path(),song->obj->Path())<0;
+#endif
 }
 
 cSongInfo *cSong::Info(bool get)
@@ -229,12 +286,13 @@
 bool cSong::Image(unsigned char * &mem, int &len)
 {
   mem=0;
-  if(queuePid>0) {
-    if(!waitpid(queuePid,0,WNOHANG)) {
+  if(queueStat>0) {
+    if(!conv->Status()) {
       di(printf("image: still queued\n"))
       return false;
       }
-    queuePid=-1;
+    queueStat=-1;
+    delete conv; conv=0;
     }
 
   int res=0;
@@ -244,31 +302,19 @@
     asprintf(&m,"%s%s.mpg",imagecache,image);
     if(access(m,R_OK)) {
       di(printf("image: not cached\n"))
-      if(queuePid<0) {
+      if(queueStat<0) {
         di(printf("image: obviously convert failed...\n"))
         }
       else {
-        int pid=fork();
-        if(pid==0) { // child
-          nice(3);
-          di(printf("image: convert started %s -> %s\n",image,m))
-          char *m, *cmd, *qp, *qm;
-          asprintf(&m,"%s%s.mpg",imagecache,image);
-          asprintf(&cmd,"%s \"%s\" \"%s\"",imageconv,qp=Quote(image),qm=Quote(m));
-          int r=system(cmd);
-          if(r!=0) di(printf("image: convert returned with code %d. Failed?\n",r))
-          free(cmd); free(qp); free(qm); free(m);
-          di(printf("image: convert finished\n"))
-          exit(0);
-          }
-        else if(pid>0) { 
+        if(!conv) conv=new cImageConvert;
+        if(conv && conv->Convert(image)) {
           di(printf("image: convert queued\n"))
-          queuePid=pid;
+          queueStat=1;
           res=-1;
           }
         else {
           di(printf("image: queueing failed\n"))
-          queuePid=-1;
+          queueStat=-1;
           }
         }
       }
@@ -349,10 +395,18 @@
     }
 }
 
+#if VDRVERSNUM >= 10315
 int cPlayList::Compare(const cListObject &ListObject) const
+#else
+bool cPlayList::operator<(const cListObject &ListObject)
+#endif
 {
   cPlayList *list=(cPlayList *)&ListObject;
+#if VDRVERSNUM >= 10315
   return strcasecmp(obj->Name(),list->obj->Name());
+#else
+  return strcasecmp(obj->Name(),list->obj->Name())<0;
+#endif
 }
 
 bool cPlayList::Load(void)
diff -urN -x '*.o' -x .dependencies mp3-0.9.11/data-mp3.h mp3-unstable/data-mp3.h
--- mp3-0.9.11/data-mp3.h	2005-02-11 18:00:07.000000000 +0100
+++ mp3-unstable/data-mp3.h	2005-02-22 18:12:09.000000000 +0100
@@ -30,6 +30,7 @@
 
 class cDecoder;
 class cSongInfo;
+class cImageConvert;
 
 extern const char *imagecache, *imageconv;
 
@@ -45,7 +46,8 @@
   cMutex decLock;
   //
   const char *image;
-  int queuePid;
+  cImageConvert *conv;
+  int queueStat;
   //
   void Init(void);
   char *Convert2Unix(const char *name) const;
@@ -56,7 +58,11 @@
   cSong(cFileSource *Source, const char *Subdir, const char *Name);
   cSong(cSong *Song);
   ~cSong();
+#if VDRVERSNUM >= 10315
   virtual int Compare(const cListObject &ListObject) const;
+#else
+  virtual bool operator<(const cListObject &ListObject);
+#endif
   bool Parse(char *s, const char *reldir) const;
   bool Save(FILE *f, const char *reldir) const;
   void Convert(void);
@@ -86,7 +92,11 @@
   ~cPlayList();
   virtual bool Load(void);
   virtual bool Save(void);
+#if VDRVERSNUM >= 10315
   virtual int Compare(const cListObject &ListObject) const;
+#else
+  virtual bool operator<(const cListObject &ListObject);
+#endif
   //
   bool Rename(const char *newName);
   bool Delete(void);


More information about the vdr mailing list