]> git.vomp.tv Git - vompserver.git/commitdiff
Updates for media player after protocol change
authorChris Tallon <chris@vomp.tv>
Sun, 18 Nov 2007 18:08:13 +0000 (18:08 +0000)
committerChris Tallon <chris@vomp.tv>
Sun, 18 Nov 2007 18:08:13 +0000 (18:08 +0000)
bootpd.c
bootpd.h
media.c
media.h
mvpclient.c
mvpclient.h
mvpserver.c
tftpclient.h
tftpd.h
vompserver.c

index 39cc6a4d0398276f7a2c36218157d87b5a2db997..704b43912695a9f84bb9764d9597c69e60c60ce6 100644 (file)
--- a/bootpd.c
+++ b/bootpd.c
@@ -99,7 +99,11 @@ void Bootpd::processRequest(UCHAR* data, int length)
 
   // Open a config file for the given MAC
 
+#ifndef VOMPSTANDALONE
   const char* configDir = cPlugin::ConfigDirectory();
+#else
+  const char* configDir = ".";
+#endif
 //  char* configDir = "/opt/dvb/vdr-config-1.3/plugins";
   if (!configDir)
   {
index 91d2992030a84181938228bc76cde7c750334c73..2cad4a68033d4887c04062339687744daf8a7f83 100644 (file)
--- a/bootpd.h
+++ b/bootpd.h
@@ -24,7 +24,9 @@
 #include <stdio.h>
 #include <signal.h>
 #include <ctype.h>
+#ifndef VOMPSTANDALONE
 #include <vdr/plugin.h>
+#endif
 
 #include "defines.h"
 #include "log.h"
diff --git a/media.c b/media.c
index 89a75e25ddb0b72197543d79c5b46004c9cb30a0..996413dfab75ce468f7663aad1113611b0b4e2d6 100644 (file)
--- a/media.c
+++ b/media.c
 */
 
 #include "media.h"
-//#include "tools.h"
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <dirent.h>
+#include <iostream>
+
 
 
 
@@ -67,6 +69,19 @@ static struct mtype{
 //#define NUMTYPES (sizeof(mediatypes)/sizeof(mtype))
 #define NUMTYPES 6
 
+//helper from vdr tools.c
+bool endswith(const char *s, const char *p)
+{
+  const char *se = s + strlen(s) - 1;
+  const char *pe = p + strlen(p) - 1;
+  while (pe >= p) {
+        if (*pe-- != *se-- || (se < s && pe >= p))
+           return false;
+        }
+  return true;
+}
+
+
 MediaList * MediaList::readList(Config * cfg,const char * dirname, int type) {
   MediaList *rt=NULL;
   if (dirname == NULL) {
@@ -79,7 +94,7 @@ MediaList * MediaList::readList(Config * cfg,const char * dirname, int type) {
       if (dn != NULL) {
         if (rt == NULL) rt=new MediaList();
         Media *m=new Media(MEDIA_TYPE_DIR,dn,0);
-        rt->Add(m);
+        rt->push_back(m);
         Log::getInstance()->log("Media",Log::DEBUG,"added base dir %s",dn);
        }
      }
@@ -89,9 +104,14 @@ MediaList * MediaList::readList(Config * cfg,const char * dirname, int type) {
   if (dirname == NULL) dirname="/";
   rt=new MediaList();
   //open the directory and read out the entries
-  cReadDir d(dirname);
+  DIR *d=opendir(dirname);
   struct dirent *e;
-  while ((e=d.Next()) != NULL) {
+  union { // according to "The GNU C Library Reference Manual"
+    struct dirent d;
+    char b[offsetof(struct dirent, d_name) + NAME_MAX + 1];
+    } u;
+
+  while (d != NULL && (readdir_r(d,&u.d,&e) == 0) && e != NULL) {
     {
     const char * fname=e->d_name;
     if ( fname == NULL) continue;
@@ -117,16 +137,21 @@ MediaList * MediaList::readList(Config * cfg,const char * dirname, int type) {
     //only consider entries we accept by type here
     if (mtype & type) {
      Media * m =new Media(mtype,fname,(int)(st.st_mtime));
-     rt->Add(m);
+     rt->push_back(m);
      Log::getInstance()->log("Media",Log::DEBUG,"added entry %s, type=%d",fname,mtype);
      }
     }
   }
-  //test
-  //Media *m=new Media(MEDIA_TYPE_DIR,"testMedia1",0);
-  //rt->Add(m);
+  if (d != NULL) closedir(d);
   return rt;
   }
 
+MediaList::~MediaList() {
+  MediaList::iterator it=this->begin();
+  while (it < this->end()) {
+    delete *it;
+    it++;
+  }
+}
 
 
diff --git a/media.h b/media.h
index c8642d38fe7f0e0b2dbae804b826c1485eacdb4b..d9409e684c06a885041a8d8c79b7adfa96fb06cc 100644 (file)
--- a/media.h
+++ b/media.h
@@ -27,9 +27,9 @@
 #include <endian.h>
 
 #include <unistd.h> // sleep
+#include <vector>
 
-#include <vdr/tools.h>
-
+using namespace std;
 //#include "defines.h"
 //#include "tcp.h"
 //#include "mvpreceiver.h"
@@ -47,7 +47,7 @@
 
 #define MEDIA_TYPE_ALL (1+2+4+8)
 
-class Media : public cListObject
+class Media 
 {
   public:
     /**
@@ -68,9 +68,10 @@ class Media : public cListObject
 
 };
 
-class MediaList : public cList<Media> {
+class MediaList : public vector<Media*> {
   public:
     static MediaList *readList(Config *cfg,const char * dirname,int type=MEDIA_TYPE_ALL);
+    ~MediaList();
   };
 
 #endif
index fcdae49e01112c3fd9f3b9c7dbf2f825c01b843d..01ead43ae5a2ba12bf4d835840dc5b7658ceb5c7 100644 (file)
@@ -30,10 +30,12 @@ int MVPClient::nr_clients = 0;
 MVPClient::MVPClient(Config* cfgBase, char* tconfigDirExtra, int tsocket)
  : tcp(tsocket)
 {
+#ifndef VOMPSTANDALONE
   lp = NULL;
   rp = NULL;
-  imageFile = 0;
   recordingManager = NULL;
+#endif
+  imageFile = 0;
   log = Log::getInstance();
   loggedIn = false;
   configDirExtra = tconfigDirExtra;
@@ -44,6 +46,7 @@ MVPClient::MVPClient(Config* cfgBase, char* tconfigDirExtra, int tsocket)
 MVPClient::~MVPClient()
 {
   log->log("Client", Log::DEBUG, "MVP client destructor");
+#ifndef VOMPSTANDALONE
   if (lp)
   {
     delete lp;
@@ -58,7 +61,7 @@ MVPClient::~MVPClient()
     rp = NULL;
     recordingManager = NULL;
   }
-
+#endif
   if (loggedIn) cleanConfig();
   decClients();
 }
@@ -88,6 +91,7 @@ ULLONG MVPClient::htonll(ULLONG a)
   #endif
 }
 
+#ifndef VOMPSTANDALONE
 cChannel* MVPClient::channelFromNumber(ULONG channelNumber)
 {
   cChannel* channel = NULL;
@@ -126,6 +130,7 @@ void MVPClient::writeResumeData()
                           (char*)rp->getCurrentRecording()->FileName(),
                           rp->frameNumberFromPosition(rp->getLastPosition()) );
 }
+#endif
 
 void MVPClient::sendULONG(ULONG ul)
 {
@@ -244,6 +249,7 @@ void MVPClient::run2()
       case 1:
         result = processLogin(data, extraDataLength);
         break;
+#ifndef VOMPSTANDALONE
       case 2:
         result = processGetRecordingsList(data, extraDataLength);
         break;
@@ -268,12 +274,14 @@ void MVPClient::run2()
       case 10:
         result = processGetChannelSchedule(data, extraDataLength);
         break;
+#endif
       case 11:
         result = processConfigSave(data, extraDataLength);
         break;
       case 12:
         result = processConfigLoad(data, extraDataLength);
         break;
+#ifndef VOMPSTANDALONE
       case 13:
         result = processReScanRecording(data, extraDataLength);         // FIXME obselete
         break;
@@ -307,6 +315,7 @@ void MVPClient::run2()
       case 23:
         result = processDeleteTimer(data, extraDataLength);
         break;
+#endif
       case 30:
         result = processGetMediaList(data, extraDataLength);
         break;
@@ -329,7 +338,11 @@ int MVPClient::processLogin(UCHAR* buffer, int length)
 
   // Open the config
 
+#ifndef VOMPSTANDALONE
   const char* configDir = cPlugin::ConfigDirectory(configDirExtra);
+#else
+  const char* configDir = ".";
+#endif
   if (!configDir)
   {
     log->log("Client", Log::DEBUG, "No config dir!");
@@ -358,6 +371,7 @@ int MVPClient::processLogin(UCHAR* buffer, int length)
   return 1;
 }
 
+#ifndef VOMPSTANDALONE
 int MVPClient::processGetRecordingsList(UCHAR* data, int length)
 {
   UCHAR* sendBuffer = new UCHAR[50000]; // hope this is enough
@@ -1162,6 +1176,8 @@ int MVPClient::processGetChannelSchedule(UCHAR* data, int length)
   return 1;
 }
 
+#endif //VOMPSTANDALONE
+
 int MVPClient::processConfigSave(UCHAR* buffer, int length)
 {
   char* section = (char*)buffer;
@@ -1243,6 +1259,7 @@ void MVPClient::cleanConfig()
 {
   log->log("Client", Log::DEBUG, "Clean config");
 
+#ifndef VOMPSTANDALONE
   cRecordings Recordings;
   Recordings.Load();
 
@@ -1270,6 +1287,7 @@ void MVPClient::cleanConfig()
   }
 
   delete[] resumes;
+#endif
 }
 
 
@@ -1583,6 +1601,7 @@ recording is a bool, 0 for not currently recording, 1 for currently recording
 pending is a bool, 0 for would not be trying to record this right now, 1 for would/is trying to record this right now
 */
 
+#ifndef VOMPSTANDALONE
 
 int MVPClient::processGetTimers(UCHAR* buffer, int length)
 {
@@ -1699,6 +1718,8 @@ int MVPClient::processSetTimer(UCHAR* buffer, int length)
   return 1;
 }
 
+#endif //VOMPSTANDALONE
+
 void MVPClient::incClients()
 {
   pthread_mutex_lock(&threadClientMutex);
@@ -1722,6 +1743,8 @@ int MVPClient::getNrClients()
   return nrClients;
 }
 
+#ifndef VOMPSTANDALONE
+
 int MVPClient::processGetRecInfo(UCHAR* data, int length)
 {
   // data is a pointer to the fileName string
@@ -1992,6 +2015,8 @@ int MVPClient::processGetMarks(UCHAR* data, int length)
   return 1;
 }
 
+#endif //VOMPSTANDALONE
+
 
 /**
   * media List Request:
@@ -2039,10 +2064,10 @@ int MVPClient::processGetMediaList(UCHAR* data, int length)
   *(ULONG*)&sendBuffer[count] = htonl(0);
   count += 4;
   //numentries
-  *(ULONG*)&sendBuffer[count] = htonl(ml->Count());
+  *(ULONG*)&sendBuffer[count] = htonl(ml->size());
   count += 4;
-  for (int nm=0;nm<ml->Count() && count < (MLISTBUF-1000);nm++) {
-      Media *m=ml->Get(nm);
+  for (MediaList::iterator nm=ml->begin();nm<ml->end() && count < (MLISTBUF-1000);nm++) {
+      Media *m=*nm;
       log->log("Client", Log::DEBUG, "found media entry %s, type=%d",m->getFilename(),m->getType());
       *(ULONG*)&sendBuffer[count] = htonl(m->getType());
       count += 4;
@@ -2075,8 +2100,6 @@ int MVPClient::processGetMediaList(UCHAR* data, int length)
 
 /**
   * get image Request:
-  * 4 length
-  * 4 VDR_GETIMAGE
   * 4 flags (currently unused)
   * 4 x size
   * 4 y size
@@ -2099,9 +2122,9 @@ int MVPClient::processGetPicture(UCHAR* data, int length)
     imageFile=NULL;
   }
   char * filename=NULL;
-  if (length > 4) {
+  if (length > 12) {
     //we have a dirname provided
-    filename=(char *)&data[4];
+    filename=(char *)&data[12];
     log->log("Client", Log::DEBUG, "getPicture  %s", filename);
   }
   else {
@@ -2177,6 +2200,8 @@ int MVPClient::processGetImageBlock(UCHAR* data, int length)
   return 1;
 }
 
+#ifndef VOMPSTANDALONE
+
 int MVPClient::processDeleteTimer(UCHAR* buffer, int length)
 {
   log->log("Client", Log::DEBUG, "Delete timer called");
@@ -2230,3 +2255,4 @@ int MVPClient::processDeleteTimer(UCHAR* buffer, int length)
   }  
 }
 
+#endif
index 33cc926b751306571bcce5baf85d28c29c98463b..6f8acc9e86d2f6709e1577f9a77354fa3f8f2b58 100644 (file)
 
 #include <unistd.h> // sleep
 
+#ifndef VOMPSTANDALONE
 #include <vdr/recording.h>
 #include <vdr/channels.h>
 #include <vdr/videodir.h>
 #include <vdr/plugin.h>
 #include <vdr/timers.h>
 #include <vdr/menu.h>
+#include "recplayer.h"
+#include "mvpreceiver.h"
+#endif
 
 #include "defines.h"
 #include "tcp.h"
-#include "mvpreceiver.h"
-#include "recplayer.h"
 #include "config.h"
 #include "media.h"
 
@@ -60,17 +62,19 @@ class MVPClient
     TCP tcp;
     Config config;
     Config* baseConfig;
-    MVPReceiver* lp;
     bool loggedIn;
     char* configDirExtra;
     FILE* imageFile;
 
-
+#ifndef VOMPSTANDALONE
+    MVPReceiver* lp;
     cRecordings* recordingManager;
     RecPlayer* rp;
+#endif
     Log* log;
 
     int processLogin(UCHAR* buffer, int length);
+#ifndef VOMPSTANDALONE 
     int processGetRecordingsList(UCHAR* data, int length);
     int processDeleteRecording(UCHAR* data, int length);
     int processMoveRecording(UCHAR* data, int length);
@@ -80,8 +84,6 @@ class MVPClient
     int processStopStreaming(UCHAR* data, int length);
     int processStartStreamingRecording(UCHAR* data, int length);
     int processGetChannelSchedule(UCHAR* data, int length);
-    int processConfigSave(UCHAR* data, int length);
-    int processConfigLoad(UCHAR* data, int length);
     int processGetTimers(UCHAR* data, int length);
     int processSetTimer(UCHAR* data, int length);
     int processPositionFromFrameNumber(UCHAR* data, int length);
@@ -90,18 +92,22 @@ class MVPClient
     int processGetRecInfo(UCHAR* data, int length);
     int processGetMarks(UCHAR* data, int length);
     int processGetChannelPids(UCHAR* data, int length);
-    int processGetMediaList(UCHAR* data, int length);
-    int processGetPicture(UCHAR* data, int length);
-    int processGetImageBlock(UCHAR* data, int length);
     int processDeleteTimer(UCHAR* buffer, int length);
 
     int processReScanRecording(UCHAR* data, int length);           // FIXME obselete
+#endif
+    int processConfigSave(UCHAR* data, int length);
+    int processConfigLoad(UCHAR* data, int length);
+    int processGetMediaList(UCHAR* data, int length);
+    int processGetPicture(UCHAR* data, int length);
+    int processGetImageBlock(UCHAR* data, int length);
 
     void incClients();
     void decClients();
-
+#ifndef VOMPSTANDALONE
     cChannel* channelFromNumber(ULONG channelNumber);
     void writeResumeData();
+#endif
     void cleanConfig();
     void sendULONG(ULONG ul);
 
index aed8f4ed75db884ea85be3862305f12c551b5744..85bc8da9eb28767e62c9fa6290f43ceec13c1a86 100644 (file)
@@ -19,6 +19,9 @@
 */
 
 #include "mvpserver.h"
+#ifdef VOMPSTANDALONE
+#include <iostream>
+#endif
 
 extern pthread_mutex_t threadClientMutex;
 
@@ -58,7 +61,12 @@ int MVPServer::run(char* tconfigDirExtra)
   configDirExtra = tconfigDirExtra;
 
   // Start config
+#ifndef VOMPSTANDALONE
   const char* configDir = cPlugin::ConfigDirectory(configDirExtra);
+#else
+  const char* configDir = ".";
+#define dsyslog(x) std::cout << x << std::endl;
+#endif
   if (!configDir)
   {
     dsyslog("VOMP: Could not get config dir from VDR");
index 5a80c2c8d881185b4510f1231b569c38c1ac2ddd..b4eea8beada9ba09cf390d268df10bba898f1890 100644 (file)
@@ -24,7 +24,9 @@
 #include <stdio.h>
 #include <signal.h>
 #include <ctype.h>
+#ifndef VOMPSTANDALONE
 #include <vdr/plugin.h>
+#endif
 
 #include "defines.h"
 #include "log.h"
diff --git a/tftpd.h b/tftpd.h
index 50f2edea7aadc5249eb0000aa8d2c0c832eca5b9..45da7ca2c2f0a8af2a127b488e885523fc6a4784 100644 (file)
--- a/tftpd.h
+++ b/tftpd.h
@@ -24,7 +24,9 @@
 #include <stdio.h>
 #include <signal.h>
 #include <ctype.h>
+#ifndef VOMPSTANDALONE
 #include <vdr/plugin.h>
+#endif
 
 #include "defines.h"
 #include "log.h"
index 7b0f3d16f5769d0a5a330dda9f5e8cdd417617cc..624f2798eed2dad6d40cdeb8fa4b29ce20b737fd 100644 (file)
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
+#ifndef VOMPSTANDALONE
 #include <vdr/plugin.h>
+#endif
+#include <iostream>
 #include <getopt.h>
 
 #include "mvpserver.h"
@@ -27,6 +30,7 @@
 static const char *VERSION        = "0.2.7";
 static const char *DESCRIPTION    = "VDR on MVP plugin by Chris Tallon";
 
+#ifndef VOMPSTANDALONE
 class cPluginVompserver : public cPlugin
 {
 public:
@@ -123,3 +127,21 @@ cString cPluginVompserver::Active(void)
 
 VDRPLUGINCREATOR(cPluginVompserver); // Don't touch this!
 
+#else //VOMPSTANDALONE
+
+int main(int argc, char **argv) {
+  char *cdir=".";
+    if (argc > 1) {
+      cdir=argv[1];
+    }
+  std::cout << "Vompserver starting Version " << VERSION << " " << DESCRIPTION << std::endl;
+  MVPServer server;
+  if ( server.run(cdir) != 1) {
+       std::cerr << "unable to start vompserver" << std::endl;
+       return 1;
+    }
+  while (1) sleep(1);
+  return 0;
+}
+
+#endif //VOMPSTANDALONE