2 Copyright 2008 Chris Tallon
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #ifndef VOMPSTANDALONE
24 #include <vdr/recording.h>
25 #include <vdr/channels.h>
26 #include <vdr/videodir.h>
27 #include <vdr/plugin.h>
28 #include <vdr/timers.h>
30 #include "recplayer.h"
31 #include "mvpreceiver.h"
34 #include "vompclientrrproc.h"
35 #include "vompclient.h"
40 VompClientRRProc::VompClientRRProc(VompClient& x)
43 log = Log::getInstance();
48 VompClientRRProc::~VompClientRRProc()
53 bool VompClientRRProc::init()
58 bool VompClientRRProc::recvRequest(RequestPacket* newRequest)
62 Now we have a queue system is used,
63 since on rare occasion the client fire two request at once
64 e.g. heavily channel switching
65 then processing only a single request would cause a deadlock in the client
70 req_queue.push(newRequest);
72 log->log("RRProc", Log::DEBUG, "recvReq set req and signalled");
78 void VompClientRRProc::threadMethod()
81 log->log("RRProc", Log::DEBUG, "threadMethod startup");
83 if (req_queue.size() != 0)
85 log->log("RRProc", Log::ERR, "threadMethod err 1");
92 log->log("RRProc", Log::DEBUG, "threadMethod waiting");
93 threadWaitForSignal(); // unlocks, waits, relocks
94 if (req_queue.size() == 0)
96 log->log("RRProc", Log::INFO, "threadMethod err 2 or quit");
101 // signalled with something in queue
103 log->log("RRProc", Log::DEBUG, "thread woken with req, queue size: %i", req_queue.size());
105 while (req_queue.size())
107 log->log("RRProc", Log::DEBUG, "thread while");
108 req = req_queue.front();
111 threadUnlock(); // allow recvRequest to be queuing packets while we are working on this one
113 if (!processPacket())
115 log->log("RRProc", Log::ERR, "processPacket exited with fail");
122 // locked and run out of packets to process
126 bool VompClientRRProc::processPacket()
128 resp = new ResponsePacket();
129 if (!resp->init(req->requestID))
131 log->log("RRProc", Log::ERR, "response packet init fail");
134 if (req->data) free(req->data);
146 result = processLogin();
148 #ifndef VOMPSTANDALONE
150 result = processGetRecordingsList();
153 result = processDeleteRecording();
156 result = processGetChannelsList();
159 result = processStartStreamingChannel();
162 result = processGetBlock();
165 result = processStopStreaming();
168 result = processStartStreamingRecording();
172 result = processGetChannelSchedule();
175 result = processConfigSave();
178 result = processConfigLoad();
180 #ifndef VOMPSTANDALONE
182 result = processReScanRecording(); // FIXME obselete
185 result = processGetTimers();
188 result = processSetTimer();
191 result = processPositionFromFrameNumber();
194 result = processFrameNumberFromPosition();
197 result = processMoveRecording();
200 result = processGetIFrame();
203 result = processGetRecInfo();
206 result = processGetMarks();
209 result = processGetChannelPids();
212 result = processDeleteTimer();
216 result = processGetMediaList();
219 result = processGetPicture();
222 result = processGetImageBlock();
225 result = processGetLanguageList();
228 result = processGetLanguageContent();
235 if (req->data) free(req->data);
239 if (result) return true;
243 int VompClientRRProc::processLogin()
245 if (req->dataLength != 6) return 0;
249 char configFileName[PATH_MAX];
250 snprintf(configFileName, PATH_MAX, "%s/vomp-%02X-%02X-%02X-%02X-%02X-%02X.conf", x.configDir, req->data[0], req->data[1], req->data[2], req->data[3], req->data[4], req->data[5]);
251 x.config.init(configFileName);
253 // Send the login reply
255 time_t timeNow = time(NULL);
256 struct tm* timeStruct = localtime(&timeNow);
257 int timeOffset = timeStruct->tm_gmtoff;
259 resp->addULONG(timeNow);
260 resp->addLONG(timeOffset);
262 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
263 log->log("RRProc", Log::DEBUG, "written login reply len %lu", resp->getLen());
269 int VompClientRRProc::processConfigSave()
271 char* section = (char*)req->data;
275 for (UINT k = 0; k < req->dataLength; k++)
277 if (req->data[k] == '\0')
281 key = (char*)&req->data[k+1];
285 value = (char*)&req->data[k+1];
291 // if the last string (value) doesnt have null terminator, give up
292 if (req->data[req->dataLength - 1] != '\0') return 0;
294 log->log("RRProc", Log::DEBUG, "Config save: %s %s %s", section, key, value);
295 if (x.config.setValueString(section, key, value))
305 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
310 int VompClientRRProc::processConfigLoad()
312 char* section = (char*)req->data;
315 for (UINT k = 0; k < req->dataLength; k++)
317 if (req->data[k] == '\0')
319 key = (char*)&req->data[k+1];
324 char* value = x.config.getValueString(section, key);
328 resp->addString(value);
329 log->log("RRProc", Log::DEBUG, "Written config load packet");
335 log->log("RRProc", Log::DEBUG, "Written config load failed packet");
339 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
345 * media List Request:
348 * 4 flags (currently unused)
351 * Media List response:
359 * 4 strlen (incl. 0 Byte)
364 int VompClientRRProc::processGetMediaList()
366 if (req->dataLength < 4) {
367 log->log("RRProc", Log::ERR, "getMediaList packet too short %d", req->dataLength);
371 if (req->dataLength > 4) {
372 //we have a dirname provided
373 dirname=(char *)&req->data[4];
374 log->log("RRProc", Log::DEBUG, "getMediaList for %s", dirname);
377 MediaList * ml=MediaList::readList(x.baseConfig, dirname);
379 log->log("RRProc", Log::ERR, "getMediaList returned NULL");
383 //response code (not yet set)
387 resp->addULONG(ml->size());
389 for (MediaList::iterator nm=ml->begin(); nm<ml->end(); nm++)
392 log->log("RRProc", Log::DEBUG, "found media entry %s, type=%d",m->getFilename(),m->getType());
393 resp->addULONG(m->getType());
395 resp->addULONG(m->getTime());
398 int len=strlen(m->getFilename());
400 resp->addULONG(len+1);
401 resp->addString(m->getFilename());
406 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
408 log->log("RRProc", Log::DEBUG, "Written Media list");
414 * 4 flags (currently unused)
419 * get image response:
425 int VompClientRRProc::processGetPicture()
427 if (req->dataLength < 12) {
428 log->log("RRProc", Log::ERR, "getPicture packet too short %d", req->dataLength);
435 char * filename=NULL;
436 if (req->dataLength > 12) {
437 //we have a dirname provided
438 filename=(char *)&req->data[12];
439 log->log("RRProc", Log::DEBUG, "getPicture %s", filename);
442 log->log("RRProc", Log::ERR, "getPicture empty filename");
445 x.imageFile=fopen(filename,"r");
446 if (!x.imageFile) log->log("RRProc", Log::ERR, "getPicture unable to open %s",filename);
451 if ( fstat(fileno(x.imageFile),&st) == 0) size=st.st_size;
453 //response code (not yet set)
456 resp->addULONG(size);
458 log->log("RRProc", Log::DEBUG, "getPicture size %u", size);
461 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
463 log->log("RRProc", Log::DEBUG, "Written getPicture");
469 int VompClientRRProc::processGetImageBlock()
473 log->log("RRProc", Log::DEBUG, "Get image block called when no image active");
477 UCHAR* data = req->data;
479 ULLONG position = x.ntohll(*(ULLONG*)data);
480 data += sizeof(ULLONG);
481 ULONG amount = ntohl(*(ULONG*)data);
483 log->log("RRProc", Log::DEBUG, "getImageblock pos = %llu length = %lu", position, amount);
485 UCHAR sendBuffer[amount];
486 ULONG amountReceived = 0; // compiler moan.
487 ULLONG cpos=ftell(x.imageFile);
488 if (position != cpos) {
489 fseek(x.imageFile,position-cpos,SEEK_CUR);
491 if (position != (ULLONG)ftell(x.imageFile)) {
492 log->log("RRProc", Log::DEBUG, "getImageblock pos = %llu not available", position);
495 amountReceived=fread(&sendBuffer[0],1,amount,x.imageFile);
501 log->log("RRProc", Log::DEBUG, "written 4(0) as getblock got 0");
505 resp->copyin(sendBuffer, amount);
506 log->log("RRProc", Log::DEBUG, "written %lu", amountReceived);
510 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
516 int VompClientRRProc::processGetLanguageList()
518 x.i18n.findLanguages();
519 const I18n::lang_code_list& languages = x.i18n.getLanguageList();
521 I18n::lang_code_list::const_iterator iter;
522 for (iter = languages.begin(); iter != languages.end(); ++iter)
524 resp->addString(iter->first.c_str());
525 resp->addString(iter->second.c_str());
528 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
532 int VompClientRRProc::processGetLanguageContent()
534 if (req->dataLength <= 0) return 0;
535 std::string code, result;
536 code.assign((char*)req->data, req->dataLength - 1);
537 x.i18n.findLanguages();
538 I18n::trans_table texts = x.i18n.getLanguageContent(code);
539 I18n::trans_table::const_iterator iter;
540 for (iter = texts.begin(); iter != texts.end(); ++iter)
542 resp->addString(iter->first.c_str());
543 resp->addString(iter->second.c_str());
546 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
550 #ifndef VOMPSTANDALONE
552 int VompClientRRProc::processGetRecordingsList()
555 int Percent = VideoDiskSpace(&FreeMB);
556 int Total = (FreeMB / (100 - Percent)) * 100;
558 resp->addULONG(Total);
559 resp->addULONG(FreeMB);
560 resp->addULONG(Percent);
562 cRecordings Recordings;
565 for (cRecording *recording = Recordings.First(); recording; recording = Recordings.Next(recording))
567 resp->addULONG(recording->start);
568 resp->addString(recording->Name());
569 resp->addString(recording->FileName());
573 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
575 log->log("RRProc", Log::DEBUG, "Written recordings list");
580 int VompClientRRProc::processDeleteRecording()
582 // data is a pointer to the fileName string
584 cRecordings Recordings;
585 Recordings.Load(); // probably have to do this
587 cRecording* recording = Recordings.GetByName((char*)req->data);
589 log->log("RRProc", Log::DEBUG, "recording pointer %p", recording);
593 log->log("RRProc", Log::DEBUG, "deleting recording: %s", recording->Name());
595 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
598 if (recording->Delete())
600 // Copy svdrp's way of doing this, see if it works
601 #if VDRVERSNUM > 10300
602 ::Recordings.DelByName(recording->FileName());
622 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
627 int VompClientRRProc::processMoveRecording()
629 log->log("RRProc", Log::DEBUG, "Process move recording");
630 char* fileName = (char*)req->data;
631 char* newPath = NULL;
633 for (UINT k = 0; k < req->dataLength; k++)
635 if (req->data[k] == '\0')
637 newPath = (char*)&req->data[k+1];
641 if (!newPath) return 0;
643 cRecordings Recordings;
644 Recordings.Load(); // probably have to do this
646 cRecording* recording = Recordings.GetByName((char*)fileName);
648 log->log("RRProc", Log::DEBUG, "recording pointer %p", recording);
652 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
655 log->log("RRProc", Log::DEBUG, "moving recording: %s", recording->Name());
656 log->log("RRProc", Log::DEBUG, "moving recording: %s", recording->FileName());
657 log->log("RRProc", Log::DEBUG, "to: %s", newPath);
659 const char* t = recording->FileName();
661 char* dateDirName = NULL; int k;
662 char* titleDirName = NULL; int j;
664 // Find the datedirname
665 for(k = strlen(t) - 1; k >= 0; k--)
669 log->log("RRProc", Log::DEBUG, "l1: %i", strlen(&t[k+1]) + 1);
670 dateDirName = new char[strlen(&t[k+1]) + 1];
671 strcpy(dateDirName, &t[k+1]);
676 // Find the titledirname
678 for(j = k-1; j >= 0; j--)
682 log->log("RRProc", Log::DEBUG, "l2: %i", (k - j - 1) + 1);
683 titleDirName = new char[(k - j - 1) + 1];
684 memcpy(titleDirName, &t[j+1], k - j - 1);
685 titleDirName[k - j - 1] = '\0';
690 log->log("RRProc", Log::DEBUG, "datedirname: %s", dateDirName);
691 log->log("RRProc", Log::DEBUG, "titledirname: %s", titleDirName);
692 log->log("RRProc", Log::DEBUG, "viddir: %s", VideoDirectory);
694 char* newPathConv = new char[strlen(newPath)+1];
695 strcpy(newPathConv, newPath);
696 ExchangeChars(newPathConv, true);
697 log->log("RRProc", Log::DEBUG, "EC: %s", newPathConv);
699 char* newContainer = new char[strlen(VideoDirectory) + strlen(newPathConv) + strlen(titleDirName) + 1];
700 log->log("RRProc", Log::DEBUG, "l10: %i", strlen(VideoDirectory) + strlen(newPathConv) + strlen(titleDirName) + 1);
701 sprintf(newContainer, "%s%s%s", VideoDirectory, newPathConv, titleDirName);
702 delete[] newPathConv;
704 log->log("RRProc", Log::DEBUG, "%s", newContainer);
707 int statret = stat(newContainer, &dstat);
708 if ((statret == -1) && (errno == ENOENT)) // Dir does not exist
710 log->log("RRProc", Log::DEBUG, "new dir does not exist");
711 int mkdirret = mkdir(newContainer, 0755);
714 delete[] dateDirName;
715 delete[] titleDirName;
716 delete[] newContainer;
720 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
724 else if ((statret == 0) && (! (dstat.st_mode && S_IFDIR))) // Something exists but it's not a dir
726 delete[] dateDirName;
727 delete[] titleDirName;
728 delete[] newContainer;
732 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
736 // Ok, the directory container has been made, or it pre-existed.
738 char* newDir = new char[strlen(newContainer) + 1 + strlen(dateDirName) + 1];
739 sprintf(newDir, "%s/%s", newContainer, dateDirName);
741 log->log("RRProc", Log::DEBUG, "doing rename '%s' '%s'", t, newDir);
742 int renameret = rename(t, newDir);
745 // Success. Test for remove old dir containter
746 char* oldTitleDir = new char[k+1];
747 memcpy(oldTitleDir, t, k);
748 oldTitleDir[k] = '\0';
749 log->log("RRProc", Log::DEBUG, "len: %i, cp: %i, strlen: %i, oldtitledir: %s", k+1, k, strlen(oldTitleDir), oldTitleDir);
750 rmdir(oldTitleDir); // can't do anything about a fail result at this point.
751 delete[] oldTitleDir;
756 #if VDRVERSNUM > 10311
758 ::Recordings.Update();
760 // Success. Send a different packet from just a ulong
761 resp->addULONG(1); // success
762 resp->addString(newDir);
770 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
772 delete[] dateDirName;
773 delete[] titleDirName;
774 delete[] newContainer;
781 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
788 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
794 int VompClientRRProc::processGetChannelsList()
798 char* chanConfig = x.config.getValueString("General", "Channels");
800 if (chanConfig) allChans = strcasecmp(chanConfig, "FTA only");
802 for (cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel))
804 #if VDRVERSNUM < 10300
805 if (!channel->GroupSep() && (!channel->Ca() || allChans))
807 if (!channel->GroupSep() && (!channel->Ca(0) || allChans))
810 log->log("RRProc", Log::DEBUG, "name: '%s'", channel->Name());
812 if (channel->Vpid()) type = 1;
813 #if VDRVERSNUM < 10300
816 else if (channel->Apid(0)) type = 2;
820 resp->addULONG(channel->Number());
821 resp->addULONG(type);
822 resp->addString(channel->Name());
827 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
829 log->log("RRProc", Log::DEBUG, "Written channels list");
834 int VompClientRRProc::processGetChannelPids()
836 ULONG channelNumber = ntohl(*(ULONG*)req->data);
838 cChannel* channel = x.channelFromNumber(channelNumber);
843 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
852 #if VDRVERSNUM < 10300
854 log->log("RRProc", Log::DEBUG, "Apid1: %i", channel->Apid1());
855 log->log("RRProc", Log::DEBUG, "Apid2: %i", channel->Apid2());
857 if (channel->Apid2())
859 else if (channel->Apid1())
866 for (const int *Apid = channel->Apids(); *Apid; Apid++)
870 for (const int *Dpid = channel->Dpids(); *Dpid; Dpid++)
874 for (const int *Spid = channel->Spids(); *Spid; Spid++)
881 // Format of response
900 resp->addULONG(channel->Vpid());
901 resp->addULONG(numApids);
903 #if VDRVERSNUM < 10300
906 resp->addULONG(channel->Apid1());
911 resp->addULONG(channel->Apid2());
917 for (ULONG i = 0; i < numApids; i++)
919 resp->addULONG(channel->Apid(i));
920 resp->addString(channel->Alang(i));
922 resp->addULONG(numDpids);
923 for (ULONG i = 0; i < numDpids; i++)
925 resp->addULONG(channel->Dpid(i));
926 resp->addString(channel->Dlang(i));
928 resp->addULONG(numSpids);
929 for (ULONG i = 0; i < numSpids; i++)
931 resp->addULONG(channel->Spid(i));
932 resp->addString(channel->Slang(i));
935 resp->addULONG(channel->Tpid());
939 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
941 log->log("RRProc", Log::DEBUG, "Written channels pids");
946 int VompClientRRProc::processStartStreamingChannel()
950 log->log("RRProc", Log::ERR, "Client called start streaming twice");
954 log->log("RRProc", Log::DEBUG, "req->dataLength = %i", req->dataLength);
955 ULONG channelNumber = ntohl(*(ULONG*)req->data);
957 cChannel* channel = x.channelFromNumber(channelNumber);
962 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
966 // get the priority we should use
968 int priority = x.config.getValueLong("General", "Live priority", &fail);
971 log->log("RRProc", Log::DEBUG, "Config: Live TV priority: %i", priority);
975 log->log("RRProc", Log::DEBUG, "Config: Live TV priority config fail");
980 if (priority < 0) priority = 0;
981 if (priority > 99) priority = 99;
983 log->log("RRProc", Log::DEBUG, "Using live TV priority %i", priority);
984 x.lp = MVPReceiver::create(channel, priority);
990 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
994 if (!x.lp->init(&x.tcp, req->requestID))
1000 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1006 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1010 int VompClientRRProc::processStopStreaming()
1012 log->log("RRProc", Log::DEBUG, "STOP STREAMING RECEIVED");
1018 else if (x.recplayer)
1020 x.writeResumeData();
1023 delete x.recordingManager;
1025 x.recordingManager = NULL;
1030 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1034 int VompClientRRProc::processGetBlock()
1038 log->log("RRProc", Log::ERR, "Get block called during live streaming");
1044 log->log("RRProc", Log::ERR, "Get block called when no recording open");
1048 UCHAR* data = req->data;
1050 ULLONG position = x.ntohll(*(ULLONG*)data);
1051 data += sizeof(ULLONG);
1052 ULONG amount = ntohl(*(ULONG*)data);
1054 log->log("RRProc", Log::DEBUG, "getblock pos = %llu length = %lu", position, amount);
1056 UCHAR sendBuffer[amount];
1057 ULONG amountReceived = x.recplayer->getBlock(&sendBuffer[0], position, amount);
1059 if (!amountReceived)
1062 log->log("RRProc", Log::DEBUG, "written 4(0) as getblock got 0");
1066 resp->copyin(sendBuffer, amountReceived);
1067 log->log("RRProc", Log::DEBUG, "written %lu", amountReceived);
1071 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1072 log->log("RRProc", Log::DEBUG, "Finished getblock, have sent %lu", resp->getLen());
1076 int VompClientRRProc::processStartStreamingRecording()
1078 // data is a pointer to the fileName string
1080 x.recordingManager = new cRecordings;
1081 x.recordingManager->Load();
1083 cRecording* recording = x.recordingManager->GetByName((char*)req->data);
1085 log->log("RRProc", Log::DEBUG, "recording pointer %p", recording);
1089 x.recplayer = new RecPlayer(recording);
1091 resp->addULLONG(x.recplayer->getLengthBytes());
1092 resp->addULONG(x.recplayer->getLengthFrames());
1094 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1096 log->log("RRProc", Log::DEBUG, "written totalLength");
1100 delete x.recordingManager;
1101 x.recordingManager = NULL;
1106 int VompClientRRProc::processPositionFromFrameNumber()
1110 ULONG frameNumber = ntohl(*(ULONG*)req->data);
1114 log->log("RRProc", Log::DEBUG, "Rescan recording called when no recording being played!");
1118 retval = x.recplayer->positionFromFrameNumber(frameNumber);
1121 resp->addULLONG(retval);
1123 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1125 log->log("RRProc", Log::DEBUG, "Wrote posFromFrameNum reply to client");
1129 int VompClientRRProc::processFrameNumberFromPosition()
1133 ULLONG position = x.ntohll(*(ULLONG*)req->data);
1137 log->log("RRProc", Log::DEBUG, "Rescan recording called when no recording being played!");
1141 retval = x.recplayer->frameNumberFromPosition(position);
1144 resp->addULONG(retval);
1146 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1148 log->log("RRProc", Log::DEBUG, "Wrote frameNumFromPos reply to client");
1152 int VompClientRRProc::processGetIFrame()
1154 bool success = false;
1156 ULONG* data = (ULONG*)req->data;
1158 ULONG frameNumber = ntohl(*data);
1160 ULONG direction = ntohl(*data);
1162 ULLONG rfilePosition = 0;
1163 ULONG rframeNumber = 0;
1164 ULONG rframeLength = 0;
1168 log->log("RRProc", Log::DEBUG, "GetIFrame recording called when no recording being played!");
1172 success = x.recplayer->getNextIFrame(frameNumber, direction, &rfilePosition, &rframeNumber, &rframeLength);
1175 // returns file position, frame number, length
1179 resp->addULLONG(rfilePosition);
1180 resp->addULONG(rframeNumber);
1181 resp->addULONG(rframeLength);
1189 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1191 log->log("RRProc", Log::DEBUG, "Wrote GNIF reply to client %llu %lu %lu", rfilePosition, rframeNumber, rframeLength);
1195 int VompClientRRProc::processGetChannelSchedule()
1197 ULONG* data = (ULONG*)req->data;
1199 ULONG channelNumber = ntohl(*data);
1201 ULONG startTime = ntohl(*data);
1203 ULONG duration = ntohl(*data);
1205 log->log("RRProc", Log::DEBUG, "get schedule called for channel %lu", channelNumber);
1207 cChannel* channel = x.channelFromNumber(channelNumber);
1212 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1214 log->log("RRProc", Log::DEBUG, "written 0 because channel = NULL");
1218 log->log("RRProc", Log::DEBUG, "Got channel");
1220 #if VDRVERSNUM < 10300
1221 cMutexLock MutexLock;
1222 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
1224 cSchedulesLock MutexLock;
1225 const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
1231 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1233 log->log("RRProc", Log::DEBUG, "written 0 because Schedule!s! = NULL");
1237 log->log("RRProc", Log::DEBUG, "Got schedule!s! object");
1239 const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
1244 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1246 log->log("RRProc", Log::DEBUG, "written 0 because Schedule = NULL");
1250 log->log("RRProc", Log::DEBUG, "Got schedule object");
1252 const char* empty = "";
1253 bool atLeastOneEvent = false;
1256 ULONG thisEventTime;
1257 ULONG thisEventDuration;
1258 const char* thisEventTitle;
1259 const char* thisEventSubTitle;
1260 const char* thisEventDescription;
1262 #if VDRVERSNUM < 10300
1264 const cEventInfo *event;
1265 for (int eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
1267 event = Schedule->GetEventNumber(eventNumber);
1269 thisEventID = event->GetEventID();
1270 thisEventTime = event->GetTime();
1271 thisEventDuration = event->GetDuration();
1272 thisEventTitle = event->GetTitle();
1273 thisEventSubTitle = event->GetSubtitle();
1274 thisEventDescription = event->GetExtendedDescription();
1278 for (const cEvent* event = Schedule->Events()->First(); event; event = Schedule->Events()->Next(event))
1280 thisEventID = event->EventID();
1281 thisEventTime = event->StartTime();
1282 thisEventDuration = event->Duration();
1283 thisEventTitle = event->Title();
1284 thisEventSubTitle = NULL;
1285 thisEventDescription = event->Description();
1289 //in the past filter
1290 if ((thisEventTime + thisEventDuration) < (ULONG)time(NULL)) continue;
1293 if ((thisEventTime + thisEventDuration) <= startTime) continue;
1296 if (thisEventTime >= (startTime + duration)) continue;
1298 if (!thisEventTitle) thisEventTitle = empty;
1299 if (!thisEventSubTitle) thisEventSubTitle = empty;
1300 if (!thisEventDescription) thisEventDescription = empty;
1302 resp->addULONG(thisEventID);
1303 resp->addULONG(thisEventTime);
1304 resp->addULONG(thisEventDuration);
1306 resp->addString(thisEventTitle);
1307 resp->addString(thisEventSubTitle);
1308 resp->addString(thisEventDescription);
1310 atLeastOneEvent = true;
1313 log->log("RRProc", Log::DEBUG, "Got all event data");
1315 if (!atLeastOneEvent)
1318 log->log("RRProc", Log::DEBUG, "Written 0 because no data");
1322 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1324 log->log("RRProc", Log::DEBUG, "written schedules packet");
1329 int VompClientRRProc::processGetTimers()
1332 int numTimers = Timers.Count();
1334 resp->addULONG(numTimers);
1336 for (int i = 0; i < numTimers; i++)
1338 timer = Timers.Get(i);
1340 #if VDRVERSNUM < 10300
1341 resp->addULONG(timer->Active());
1343 resp->addULONG(timer->HasFlags(tfActive));
1345 resp->addULONG(timer->Recording());
1346 resp->addULONG(timer->Pending());
1347 resp->addULONG(timer->Priority());
1348 resp->addULONG(timer->Lifetime());
1349 resp->addULONG(timer->Channel()->Number());
1350 resp->addULONG(timer->StartTime());
1351 resp->addULONG(timer->StopTime());
1352 resp->addULONG(timer->Day());
1353 resp->addULONG(timer->WeekDays());
1354 resp->addString(timer->File());
1358 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1360 log->log("RRProc", Log::DEBUG, "Written timers list");
1365 int VompClientRRProc::processSetTimer()
1367 char* timerString = new char[strlen((char*)req->data) + 1];
1368 strcpy(timerString, (char*)req->data);
1370 #if VDRVERSNUM < 10300
1372 // If this is VDR 1.2 the date part of the timer string must be reduced
1373 // to just DD rather than YYYY-MM-DD
1375 int s = 0; // source
1376 int d = 0; // destination
1378 while(c != 2) // copy up to date section, including the second ':'
1380 timerString[d] = req->data[s];
1381 if (req->data[s] == ':') c++;
1385 // now it has copied up to the date section
1387 while(c != 2) // waste YYYY-MM-
1389 if (req->data[s] == '-') c++;
1392 // now source is at the DD
1393 memcpy(&timerString[d], &req->data[s], req->dataLength - s);
1394 d += req->dataLength - s;
1395 timerString[d] = '\0';
1397 log->log("RRProc", Log::DEBUG, "Timer string after 1.2 conversion:");
1398 log->log("RRProc", Log::DEBUG, "%s", timerString);
1402 cTimer *timer = new cTimer;
1403 if (timer->Parse((char*)timerString))
1405 cTimer *t = Timers.GetTimer(timer);
1409 #if VDRVERSNUM < 10300
1412 Timers.SetModified();
1416 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1423 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1430 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1436 int VompClientRRProc::processDeleteTimer()
1438 log->log("RRProc", Log::DEBUG, "Delete timer called");
1443 INT delChannel = ntohl(*(ULONG*)&req->data[position]); position += 4;
1444 INT delWeekdays = ntohl(*(ULONG*)&req->data[position]); position += 4;
1445 INT delDay = ntohl(*(ULONG*)&req->data[position]); position += 4;
1446 INT delStart = ntohl(*(ULONG*)&req->data[position]); position += 4;
1447 INT delStop = ntohl(*(ULONG*)&req->data[position]); position += 4;
1450 for (ti = Timers.First(); ti; ti = Timers.Next(ti))
1452 if ( (ti->Channel()->Number() == delChannel)
1453 && ((ti->WeekDays() && (ti->WeekDays() == delWeekdays)) || (!ti->WeekDays() && (ti->Day() == delDay)))
1454 && (ti->StartTime() == delStart)
1455 && (ti->StopTime() == delStop) )
1463 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1467 if (!Timers.BeingEdited())
1469 if (!ti->Recording())
1472 Timers.SetModified();
1475 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1480 log->log("RRProc", Log::ERR, "Unable to delete timer - timer is running");
1483 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1489 log->log("RRProc", Log::ERR, "Unable to delete timer - timers being edited at VDR");
1492 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1497 int VompClientRRProc::processGetRecInfo()
1499 // data is a pointer to the fileName string
1501 cRecordings Recordings;
1502 Recordings.Load(); // probably have to do this
1504 cRecording *recording = Recordings.GetByName((char*)req->data);
1506 time_t timerStart = 0;
1507 time_t timerStop = 0;
1508 char* summary = NULL;
1509 ULONG resumePoint = 0;
1513 log->log("RRProc", Log::ERR, "GetRecInfo found no recording");
1516 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1521 4 bytes: start time for timer
1522 4 bytes: end time for timer
1523 4 bytes: resume point
1525 4 bytes: num components
1535 // Get current timer
1537 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
1540 timerStart = rc->Timer()->StartTime();
1541 timerStop = rc->Timer()->StopTime();
1542 log->log("RRProc", Log::DEBUG, "GRI: RC: %lu %lu", timerStart, timerStop);
1545 resp->addULONG(timerStart);
1546 resp->addULONG(timerStop);
1550 char* value = x.config.getValueString("ResumeData", (char*)req->data);
1553 resumePoint = strtoul(value, NULL, 10);
1556 log->log("RRProc", Log::DEBUG, "GRI: RP: %lu", resumePoint);
1558 resp->addULONG(resumePoint);
1563 #if VDRVERSNUM < 10300
1564 summary = (char*)recording->Summary();
1566 const cRecordingInfo *Info = recording->Info();
1567 summary = (char*)Info->ShortText();
1568 if (isempty(summary)) summary = (char*)Info->Description();
1570 log->log("RRProc", Log::DEBUG, "GRI: S: %s", summary);
1573 resp->addString(summary);
1577 resp->addString("");
1582 #if VDRVERSNUM < 10300
1584 // Send 0 for numchannels - this signals the client this info is not available
1588 const cComponents* components = Info->Components();
1590 log->log("RRProc", Log::DEBUG, "GRI: D1: %p", components);
1598 resp->addULONG(components->NumComponents());
1600 tComponent* component;
1601 for (int i = 0; i < components->NumComponents(); i++)
1603 component = components->Component(i);
1605 log->log("RRProc", Log::DEBUG, "GRI: C: %i %u %u %s %s", i, component->stream, component->type, component->language, component->description);
1607 resp->addUCHAR(component->stream);
1608 resp->addUCHAR(component->type);
1610 if (component->language)
1612 resp->addString(component->language);
1616 resp->addString("");
1618 if (component->description)
1620 resp->addString(component->description);
1624 resp->addString("");
1634 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1636 log->log("RRProc", Log::DEBUG, "Written getrecinfo");
1646 int VompClientRRProc::processReScanRecording()
1650 log->log("RRProc", Log::DEBUG, "Rescan recording called when no recording being played!");
1654 x.recplayer->scan();
1656 resp->addULLONG(x.recplayer->getLengthBytes());
1657 resp->addULONG(x.recplayer->getLengthFrames());
1659 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1660 log->log("RRProc", Log::DEBUG, "Rescan recording, wrote new length to client");
1664 // FIXME without client calling rescan, getblock wont work even tho more data is avail
1666 int VompClientRRProc::processGetMarks()
1668 // data is a pointer to the fileName string
1671 cRecordings Recordings;
1672 Recordings.Load(); // probably have to do this
1674 cRecording *recording = Recordings.GetByName((char*)req->data);
1676 log->log("RRProc", Log::DEBUG, "recording pointer %p", recording);
1680 Marks.Load(recording->FileName());
1683 for (const cMark *m = Marks.First(); m; m = Marks.Next(m))
1685 log->log("RRProc", Log::DEBUG, "found Mark %i", m->position);
1687 resp->addULONG(m->position);
1692 log->log("RRProc", Log::DEBUG, "no marks found, sending 0-mark");
1698 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1700 log->log("RRProc", Log::DEBUG, "Written Marks list");
1705 #endif // !VOMPSTANDALONE