From 6c736b6b0352d52c295d9adcd669148c32e426ef Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 18 Nov 2007 18:08:13 +0000 Subject: [PATCH] Updates for media player after protocol change --- bootpd.c | 4 ++++ bootpd.h | 2 ++ media.c | 41 +++++++++++++++++++++++++++++++++-------- media.h | 9 +++++---- mvpclient.c | 44 +++++++++++++++++++++++++++++++++++--------- mvpclient.h | 26 ++++++++++++++++---------- mvpserver.c | 8 ++++++++ tftpclient.h | 2 ++ tftpd.h | 2 ++ vompserver.c | 22 ++++++++++++++++++++++ 10 files changed, 129 insertions(+), 31 deletions(-) diff --git a/bootpd.c b/bootpd.c index 39cc6a4..704b439 100644 --- 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) { diff --git a/bootpd.h b/bootpd.h index 91d2992..2cad4a6 100644 --- a/bootpd.h +++ b/bootpd.h @@ -24,7 +24,9 @@ #include #include #include +#ifndef VOMPSTANDALONE #include +#endif #include "defines.h" #include "log.h" diff --git a/media.c b/media.c index 89a75e2..996413d 100644 --- a/media.c +++ b/media.c @@ -19,9 +19,11 @@ */ #include "media.h" -//#include "tools.h" #include #include +#include +#include + @@ -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 c8642d3..d9409e6 100644 --- a/media.h +++ b/media.h @@ -27,9 +27,9 @@ #include #include // sleep +#include -#include - +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 { +class MediaList : public vector { public: static MediaList *readList(Config *cfg,const char * dirname,int type=MEDIA_TYPE_ALL); + ~MediaList(); }; #endif diff --git a/mvpclient.c b/mvpclient.c index fcdae49..01ead43 100644 --- a/mvpclient.c +++ b/mvpclient.c @@ -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;nmCount() && count < (MLISTBUF-1000);nm++) { - Media *m=ml->Get(nm); + for (MediaList::iterator nm=ml->begin();nmend() && 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 diff --git a/mvpclient.h b/mvpclient.h index 33cc926..6f8acc9 100644 --- a/mvpclient.h +++ b/mvpclient.h @@ -28,17 +28,19 @@ #include // sleep +#ifndef VOMPSTANDALONE #include #include #include #include #include #include +#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); diff --git a/mvpserver.c b/mvpserver.c index aed8f4e..85bc8da 100644 --- a/mvpserver.c +++ b/mvpserver.c @@ -19,6 +19,9 @@ */ #include "mvpserver.h" +#ifdef VOMPSTANDALONE +#include +#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"); diff --git a/tftpclient.h b/tftpclient.h index 5a80c2c..b4eea8b 100644 --- a/tftpclient.h +++ b/tftpclient.h @@ -24,7 +24,9 @@ #include #include #include +#ifndef VOMPSTANDALONE #include +#endif #include "defines.h" #include "log.h" diff --git a/tftpd.h b/tftpd.h index 50f2ede..45da7ca 100644 --- a/tftpd.h +++ b/tftpd.h @@ -24,7 +24,9 @@ #include #include #include +#ifndef VOMPSTANDALONE #include +#endif #include "defines.h" #include "log.h" diff --git a/vompserver.c b/vompserver.c index 7b0f3d1..624f279 100644 --- a/vompserver.c +++ b/vompserver.c @@ -18,7 +18,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#ifndef VOMPSTANDALONE #include +#endif +#include #include #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 -- 2.39.5