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 <vdr/remote.h>
31 #include "recplayer.h"
32 #include "mvpreceiver.h"
33 #include "services/scraper2vdr.h"
36 #include "vompclientrrproc.h"
37 #include "vompclient.h"
40 #include "mediaplayer.h"
41 #include "servermediafile.h"
43 #include "vdrcommand.h"
44 #include "picturereader.h"
48 ULONG VompClientRRProc::VOMP_PROTOCOL_VERSION_MIN = 0x00000301;
49 ULONG VompClientRRProc::VOMP_PROTOCOL_VERSION_MAX = 0x00000302;
51 // cc is release protocol version, increase with every release, that changes protocol
52 // dd is development protocol version, set to zero at every release,
53 // increase for every protocol change in git
54 // bb not equal zero should indicate a non loggytronic protocol
55 // aa is reserved for future use
56 // VOMP_PROTOCOL_VERSION_MIN is the protocol version minimal supported by the server
57 // VOMP_PROTOCOL_VERSION_MAX is the protocol version maximal supported by the server
58 // This allows to run older clients from a new server
59 // Increase the minimal protocol version everytime you break compatibility for a certain
62 ULONG VompClientRRProc::getProtocolVersionMin()
64 return VOMP_PROTOCOL_VERSION_MIN;
67 ULONG VompClientRRProc::getProtocolVersionMax()
69 return VOMP_PROTOCOL_VERSION_MAX;
72 VompClientRRProc::VompClientRRProc(VompClient& x)
75 log = Log::getInstance();
80 VompClientRRProc::~VompClientRRProc()
85 bool VompClientRRProc::init()
87 int a = threadStart();
92 bool VompClientRRProc::recvRequest(RequestPacket* newRequest)
96 Now we have a queue system is used,
97 since on rare occasion the client fire two request at once
98 e.g. heavily channel switching
99 then processing only a single request would cause a deadlock in the client
103 log->log("RRProc", Log::DEBUG, "recvReq");
105 req_queue.push(newRequest);
106 threadSignalNoLock();
107 log->log("RRProc", Log::DEBUG, "recvReq set req and signalled");
113 void VompClientRRProc::threadMethod()
116 log->log("RRProc", Log::DEBUG, "threadMethod startup");
118 if (req_queue.size() != 0)
121 - log->log("RRProc", Log::ERR, "threadMethod err 1");
125 That was how the code used to be.
127 TODO: Work out why this happens.
130 log->log("RRProc", Log::ERR, "threadMethod startup with already queued packets");
131 while (req_queue.size())
133 //log->log("RRProc", Log::DEBUG, "thread while");
134 req = req_queue.front();
137 threadUnlock(); // allow recvRequest to be queuing packets while we are working on this one
139 if (!processPacket())
141 log->log("RRProc", Log::ERR, "processPacket exited with fail");
147 log->log("RRProc", Log::ERR, "threadMethod startup with already queued packets done.");
153 log->log("RRProc", Log::DEBUG, "threadMethod waiting");
154 threadWaitForSignal(); // unlocks, waits, relocks
155 if (req_queue.size() == 0)
157 log->log("RRProc", Log::INFO, "threadMethod err 2 or quit");
162 // signalled with something in queue
164 log->log("RRProc", Log::DEBUG, "thread woken with req, queue size: %i", req_queue.size());
166 while (req_queue.size())
168 //log->log("RRProc", Log::DEBUG, "thread while");
169 req = req_queue.front();
172 threadUnlock(); // allow recvRequest to be queuing packets while we are working on this one
174 if (!processPacket())
176 log->log("RRProc", Log::ERR, "processPacket exited with fail");
183 // locked and run out of packets to process
187 bool VompClientRRProc::processPacket()
189 resp = new ResponsePacket();
190 if (!resp->init(req->requestID))
192 log->log("RRProc", Log::ERR, "response packet init fail");
195 if (req->data) free(req->data);
207 result = processLogin();
209 #ifndef VOMPSTANDALONE
211 result = processGetRecordingsList();
214 result = processDeleteRecording();
217 result = processGetChannelsList();
220 result = processStartStreamingChannel();
223 result = processGetBlock();
226 result = processStopStreaming();
229 result = processStartStreamingRecording();
232 result = processGetChannelSchedule();
236 result = processConfigSave();
239 result = processConfigLoad();
241 #ifndef VOMPSTANDALONE
243 result = processReScanRecording(); // FIXME obselete
246 result = processGetTimers();
249 result = processSetTimer();
252 result = processPositionFromFrameNumber();
255 result = processFrameNumberFromPosition();
258 result = processMoveRecording();
261 result = processGetIFrame();
264 result = processGetRecInfo();
267 result = processGetMarks();
270 result = processGetChannelPids();
273 result = processDeleteTimer();
276 result = processVDRShutdown();
278 case VDR_GETRECSCRAPEREVENTTYPE:
279 result = processGetRecScraperEventType();
281 case VDR_GETSCRAPERMOVIEINFO:
282 result = processGetScraperMovieInfo();
284 case VDR_GETSCRAPERSERIESINFO:
285 result = processGetScraperSeriesInfo();
287 case VDR_LOADTVMEDIA:
288 result = processLoadTvMedia();
290 case VDR_LOADTVMEDIARECTHUMB:
291 result = processLoadTvMediaRecThumb();
293 case VDR_GETEVENTSCRAPEREVENTTYPE:
294 result = processGetEventScraperEventType();
296 case VDR_LOADTVMEDIAEVENTTHUMB:
297 result = processLoadTvMediaEventThumb();
301 case VDR_GETMEDIALIST:
302 result = processGetMediaList();
305 result = processOpenMedia();
307 case VDR_GETMEDIABLOCK:
308 result = processGetMediaBlock();
311 result = processGetLanguageList();
314 result = processGetLanguageContent();
316 case VDR_GETMEDIAINFO:
317 result = processGetMediaInfo();
319 case VDR_CLOSECHANNEL:
320 result = processCloseMediaChannel();
323 result = processSetCharset();
330 if (req->data) free(req->data);
334 if (result) return true;
338 int VompClientRRProc::processLogin()
340 if (req->dataLength != 6) return 0;
344 char configFileName[PATH_MAX];
345 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]);
346 x.config.init(configFileName);
348 // Send the login reply
350 time_t timeNow = time(NULL);
351 struct tm* timeStruct = localtime(&timeNow);
352 int timeOffset = timeStruct->tm_gmtoff;
354 resp->addULONG(timeNow);
355 resp->addLONG(timeOffset);
356 resp->addULONG(VOMP_PROTOCOL_VERSION_MIN);
357 resp->addULONG(VOMP_PROTOCOL_VERSION_MAX);
359 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
360 log->log("RRProc", Log::DEBUG, "written login reply len %lu", resp->getLen());
363 x.netLog(); // safe to run here since the client won't start net logging for a while yet
368 int VompClientRRProc::processSetCharset()
370 int charset = ntohl(*(ULONG*)req->data);
371 if (charset>0 && charset<3)
373 log->log("RRProc", Log::DEBUG, "Set charset to %d", charset);
374 x.setCharset(charset);
379 log->log("RRProc", Log::DEBUG, "Invalid charset %d", charset);
383 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
387 int VompClientRRProc::processConfigSave()
389 char* section = (char*)req->data;
393 for (UINT k = 0; k < req->dataLength; k++)
395 if (req->data[k] == '\0')
399 key = (char*)&req->data[k+1];
403 value = (char*)&req->data[k+1];
409 // if the last string (value) doesnt have null terminator, give up
410 if (req->data[req->dataLength - 1] != '\0') return 0;
412 log->log("RRProc", Log::DEBUG, "Config save: %s %s %s", section, key, value);
413 if (x.config.setValueString(section, key, value))
423 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
428 int VompClientRRProc::processConfigLoad()
430 char* section = (char*)req->data;
433 for (UINT k = 0; k < req->dataLength; k++)
435 if (req->data[k] == '\0')
437 key = (char*)&req->data[k+1];
442 char* value = x.config.getValueString(section, key);
446 resp->addString(value);//client coding, do not touch
447 log->log("RRProc", Log::DEBUG, "Written config load packet");
453 log->log("RRProc", Log::DEBUG, "Written config load failed packet");
457 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
463 //helper for sending from a serialize buffer
464 //insert the used len into the first 4 Bytes of the buffer
465 void VompClientRRProc::sendPacket(SerializeBuffer *b) {
466 resp->copyin(b->getStart(),b->getCurrent()-b->getStart());
468 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
472 * media List Request:
473 * Media List response:
476 #define MLISTBUF 500000
477 int VompClientRRProc::processGetMediaList()
479 SerializeBuffer buffer(req->data,req->dataLength);
480 MediaURI uri(0,NULL,NULL);
481 VDR_GetMediaListRequest request(&uri);
482 if (request.deserialize(&buffer) != 0) {
483 log->log("Client", Log::ERR, "getMediaList unable to deserialize");
486 const char *dirname=uri.getName();
487 log->log("Client", Log::DEBUG, "getMediaList for %s", dirname);
490 if (dirname == NULL) {
491 ml=x.media->getRootList();
493 ml=x.media->getMediaList(&uri);
496 log->log("Client", Log::ERR, "getMediaList returned NULL");
499 SerializeBuffer rbuf(MLISTBUF,false,true);
500 ULONG flags=0; //TODO: real error handling by setting flags
501 VDR_GetMediaListResponse response(&flags,ml);
502 if (response.serialize(&rbuf) != 0) {
503 log->log("Client", Log::ERR, "getMediaList returned NULL");
507 log->log("Client", Log::DEBUG, "getMediaList size %u", ml->size());
512 log->log("Client", Log::DEBUG, "Written Media list");
517 * openMedia response:
519 int VompClientRRProc::processOpenMedia()
521 SerializeBuffer buffer(req->data,req->dataLength);
522 MediaURI uri(0,NULL,NULL);
526 VDR_OpenMediumRequest request(&channel,&uri,&xs,&ys);
527 if (request.deserialize(&buffer) != 0) {
528 log->log("Client", Log::ERR, "openMediaRequest unable to deserialize");
531 const char *name=uri.getName();
532 log->log("Client", Log::DEBUG, "openMediaRequest for %s", name);
534 int rt=x.media->openMedium(channel,&uri,&size,xs,ys);
539 log->log("Client", Log::ERR, "openMediaRequest unable to open");
541 VDR_OpenMediumResponse response(&flags,&size);
542 SerializeBuffer rbuf(response.getSerializedLen()+4,false,true);
543 if (response.serialize(&rbuf) != 0) {
544 log->log("Client", Log::ERR, "openMediaRequest cannot serialize");
547 log->log("Client", Log::DEBUG, "openMediaRequest size %llu", size);
554 * packet - no serialized response!
556 int VompClientRRProc::processGetMediaBlock()
558 SerializeBuffer buffer(req->data,req->dataLength);
562 VDR_GetMediaBlockRequest request(&channel,&position,&amount);
563 if (request.deserialize(&buffer) != 0) {
564 log->log("Client", Log::ERR, "getMediaBlock unable to deserialize");
567 log->log("Client", Log::DEBUG, "getMediaBlock pos = %llu length = %lu,chan=%lu", position, amount,channel);
569 UCHAR sendBuffer[amount ];
570 ULONG amountReceived = 0;
571 UCHAR *rbuf=sendBuffer;
572 int rt=x.media->getMediaBlock(channel,position,amount,&amountReceived,&rbuf);
573 if (!amountReceived || rt != 0)
575 log->log("Client", Log::DEBUG, "written 4(0) as getblock got 0");
579 if (rbuf != sendBuffer) {
580 //the provider did not use the optimized handling with using my buffer
581 resp->copyin(rbuf,amountReceived);
584 // the provider did not allocate a new buffer
585 resp->copyin(sendBuffer,amountReceived);
589 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
590 log->log("Client", Log::DEBUG, "written ok %lu", amountReceived);
597 int VompClientRRProc::processGetMediaInfo()
599 SerializeBuffer buffer(req->data,req->dataLength);
601 VDR_GetMediaInfoRequest request(&channel);
602 if (request.deserialize(&buffer) != 0) {
603 log->log("Client", Log::ERR, "getMediaInfo unable to deserialize");
606 log->log("Client", Log::DEBUG, "getMediaInfo chan=%lu", channel);
609 int rt=x.media->getMediaInfo(channel,&mi);
612 log->log("Client", Log::ERR, "getMediaInfo unable to get");
614 VDR_GetMediaInfoResponse response(&flags,&mi);
615 SerializeBuffer rbuf(response.getSerializedLen()+4,false,true);
616 if (response.serialize(&rbuf) != 0) {
617 log->log("Client", Log::ERR, "getMediaInfo cannot serialize");
629 int VompClientRRProc::processCloseMediaChannel()
631 SerializeBuffer buffer(req->data,req->dataLength);
633 VDR_CloseMediaChannelRequest request(&channel);
634 if (request.deserialize(&buffer) != 0) {
635 log->log("Client", Log::ERR, "closeMediaChannel unable to deserialize");
639 log->log("Client", Log::DEBUG, "closeMediaChannel chan=%lu", channel);
640 int rt=x.media->closeMediaChannel(channel);
643 log->log("Client", Log::ERR, "closeMediaChannel unable to get");
645 VDR_CloseMediaChannelResponse response(&flags);
646 SerializeBuffer rbuf(response.getSerializedLen()+4,false,true);
647 if (response.serialize(&rbuf) != 0) {
648 log->log("Client", Log::ERR, "closeMediaChannel cannot serialize");
657 int VompClientRRProc::processGetLanguageList()
659 x.i18n.findLanguages();
660 const I18n::lang_code_list& languages = x.i18n.getLanguageList();
662 I18n::lang_code_list::const_iterator iter;
663 for (iter = languages.begin(); iter != languages.end(); ++iter)
665 resp->addString(iter->first.c_str()); // Source code is acsii
666 resp->addString(x.charconvutf8->Convert(iter->second.c_str())); //translate string can be any utf-8 character
669 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
673 int VompClientRRProc::processGetLanguageContent()
675 if (req->dataLength <= 0) return 0;
676 std::string code, result;
677 code.assign((char*)req->data, req->dataLength - 1);
678 x.i18n.findLanguages();
679 I18n::trans_table texts = x.i18n.getLanguageContent(code);
680 I18n::trans_table::const_iterator iter;
681 for (iter = texts.begin(); iter != texts.end(); ++iter)
683 resp->addString(iter->first.c_str());// source code is acsii since it is english
684 resp->addString(x.charconvutf8->Convert(iter->second.c_str())); // translate text can be any unicode string, it is stored as UTF-8
687 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
691 #ifndef VOMPSTANDALONE
693 int VompClientRRProc::processGetRecordingsList()
696 #if APIVERSNUM > 20101
697 int Percent = cVideoDirectory::VideoDiskSpace(&FreeMB);
699 int Percent = VideoDiskSpace(&FreeMB);
701 int Total = (FreeMB / (100 - Percent)) * 100;
703 resp->addULONG(Total);
704 resp->addULONG(FreeMB);
705 resp->addULONG(Percent);
707 cRecordings Recordings;
710 for (cRecording *recording = Recordings.First(); recording; recording = Recordings.Next(recording))
712 #if VDRVERSNUM < 10721
713 resp->addULONG(recording->start);
715 resp->addULONG(recording->Start());
717 resp->addUCHAR(recording->IsNew() ? 1 : 0);
718 resp->addString(x.charconvsys->Convert(recording->Name())); //coding of recording name is system dependent
719 resp->addString(recording->FileName());//file name are not visible by user do not touch
723 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
725 log->log("RRProc", Log::DEBUG, "Written recordings list");
730 int VompClientRRProc::processDeleteRecording()
732 // data is a pointer to the fileName string
734 cRecordings Recordings;
735 Recordings.Load(); // probably have to do this
737 cRecording* recording = Recordings.GetByName((char*)req->data);
739 log->log("RRProc", Log::DEBUG, "recording pointer %p", recording);
743 log->log("RRProc", Log::DEBUG, "deleting recording: %s", recording->Name());
745 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
748 if (recording->Delete())
750 // Copy svdrp's way of doing this, see if it works
751 #if VDRVERSNUM > 10300
752 ::Recordings.DelByName(recording->FileName());
772 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
777 int VompClientRRProc::processMoveRecording()
779 log->log("RRProc", Log::DEBUG, "Process move recording");
780 char* fileName = (char*)req->data;
781 char* newPath = NULL;
783 for (UINT k = 0; k < req->dataLength; k++)
785 if (req->data[k] == '\0')
787 newPath = (char*)&req->data[k+1];
791 if (!newPath) return 0;
793 cRecordings Recordings;
794 Recordings.Load(); // probably have to do this
796 cRecording* recording = Recordings.GetByName((char*)fileName);
798 log->log("RRProc", Log::DEBUG, "recording pointer %p", recording);
802 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
805 log->log("RRProc", Log::DEBUG, "moving recording: %s", recording->Name());
806 log->log("RRProc", Log::DEBUG, "moving recording: %s", recording->FileName());
807 log->log("RRProc", Log::DEBUG, "to: %s", newPath);
809 const char* t = recording->FileName();
811 char* dateDirName = NULL; int k;
812 char* titleDirName = NULL; int j;
814 // Find the datedirname
815 for(k = strlen(t) - 1; k >= 0; k--)
819 log->log("RRProc", Log::DEBUG, "l1: %i", strlen(&t[k+1]) + 1);
820 dateDirName = new char[strlen(&t[k+1]) + 1];
821 strcpy(dateDirName, &t[k+1]);
826 // Find the titledirname
828 for(j = k-1; j >= 0; j--)
832 log->log("RRProc", Log::DEBUG, "l2: %i", (k - j - 1) + 1);
833 titleDirName = new char[(k - j - 1) + 1];
834 memcpy(titleDirName, &t[j+1], k - j - 1);
835 titleDirName[k - j - 1] = '\0';
840 log->log("RRProc", Log::DEBUG, "datedirname: %s", dateDirName);
841 log->log("RRProc", Log::DEBUG, "titledirname: %s", titleDirName);
842 #if APIVERSNUM > 20101
843 log->log("RRProc", Log::DEBUG, "viddir: %s", cVideoDirectory::Name());
845 log->log("RRProc", Log::DEBUG, "viddir: %s", VideoDirectory);
848 char* newPathConv = new char[strlen(newPath)+1];
849 strcpy(newPathConv, newPath);
850 ExchangeChars(newPathConv, true);
851 log->log("RRProc", Log::DEBUG, "EC: %s", newPathConv);
853 #if APIVERSNUM > 20101
854 char* newContainer = new char[strlen(cVideoDirectory::Name()) + strlen(newPathConv) + strlen(titleDirName) + 1];
855 log->log("RRProc", Log::DEBUG, "l10: %i", strlen(cVideoDirectory::Name()) + strlen(newPathConv) + strlen(titleDirName) + 1);
856 sprintf(newContainer, "%s%s%s", cVideoDirectory::Name(), newPathConv, titleDirName);
858 char* newContainer = new char[strlen(VideoDirectory) + strlen(newPathConv) + strlen(titleDirName) + 1];
859 log->log("RRProc", Log::DEBUG, "l10: %i", strlen(VideoDirectory) + strlen(newPathConv) + strlen(titleDirName) + 1);
860 sprintf(newContainer, "%s%s%s", VideoDirectory, newPathConv, titleDirName);
862 delete[] newPathConv;
864 log->log("RRProc", Log::DEBUG, "%s", newContainer);
867 int statret = stat(newContainer, &dstat);
868 if ((statret == -1) && (errno == ENOENT)) // Dir does not exist
870 log->log("RRProc", Log::DEBUG, "new dir does not exist");
871 int mkdirret = mkdir(newContainer, 0755);
874 delete[] dateDirName;
875 delete[] titleDirName;
876 delete[] newContainer;
880 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
884 else if ((statret == 0) && (! (dstat.st_mode && S_IFDIR))) // Something exists but it's not a dir
886 delete[] dateDirName;
887 delete[] titleDirName;
888 delete[] newContainer;
892 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
896 // Ok, the directory container has been made, or it pre-existed.
898 char* newDir = new char[strlen(newContainer) + 1 + strlen(dateDirName) + 1];
899 sprintf(newDir, "%s/%s", newContainer, dateDirName);
901 log->log("RRProc", Log::DEBUG, "doing rename '%s' '%s'", t, newDir);
902 int renameret = rename(t, newDir);
905 // Success. Test for remove old dir containter
906 char* oldTitleDir = new char[k+1];
907 memcpy(oldTitleDir, t, k);
908 oldTitleDir[k] = '\0';
909 log->log("RRProc", Log::DEBUG, "len: %i, cp: %i, strlen: %i, oldtitledir: %s", k+1, k, strlen(oldTitleDir), oldTitleDir);
910 rmdir(oldTitleDir); // can't do anything about a fail result at this point.
911 delete[] oldTitleDir;
916 #if VDRVERSNUM > 10311
918 ::Recordings.Update();
920 // Success. Send a different packet from just a ulong
921 resp->addULONG(1); // success
922 resp->addString(newDir); //system depent do not convert
930 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
932 delete[] dateDirName;
933 delete[] titleDirName;
934 delete[] newContainer;
941 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
948 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
954 int VompClientRRProc::processGetChannelsList()
958 char* chanConfig = x.config.getValueString("General", "Channels");
960 if (chanConfig) allChans = strcasecmp(chanConfig, "FTA only");
962 for (cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel))
964 #if VDRVERSNUM < 10300
965 if (!channel->GroupSep() && (!channel->Ca() || allChans))
967 if (!channel->GroupSep() && (!channel->Ca(0) || allChans))
970 log->log("RRProc", Log::DEBUG, "name: '%s'", channel->Name());
972 if (channel->Vpid()) type = 1;
973 #if VDRVERSNUM < 10300
976 else if (channel->Apid(0)) type = 2;
980 resp->addULONG(channel->Number());
981 resp->addULONG(type);
982 resp->addString(x.charconvsys->Convert(channel->Name()));
983 #if VDRVERSNUM < 10703
986 resp->addULONG(channel->Vtype());
992 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
994 log->log("RRProc", Log::DEBUG, "Written channels list");
999 int VompClientRRProc::processGetChannelPids()
1001 ULONG channelNumber = ntohl(*(ULONG*)req->data);
1003 cChannel* channel = x.channelFromNumber(channelNumber);
1008 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1017 #if VDRVERSNUM < 10300
1019 log->log("RRProc", Log::DEBUG, "Apid1: %i", channel->Apid1());
1020 log->log("RRProc", Log::DEBUG, "Apid2: %i", channel->Apid2());
1022 if (channel->Apid2())
1024 else if (channel->Apid1())
1031 for (const int *Apid = channel->Apids(); *Apid; Apid++)
1035 for (const int *Dpid = channel->Dpids(); *Dpid; Dpid++)
1039 for (const int *Spid = channel->Spids(); *Spid; Spid++)
1046 // Format of response
1065 resp->addULONG(channel->Vpid());
1066 #if VDRVERSNUM < 10703
1069 resp->addULONG(channel->Vtype());
1071 resp->addULONG(numApids);
1073 #if VDRVERSNUM < 10300
1076 resp->addULONG(channel->Apid1());
1077 resp->addString("");
1081 resp->addULONG(channel->Apid2());
1082 resp->addString("");
1087 for (ULONG i = 0; i < numApids; i++)
1089 resp->addULONG(channel->Apid(i));
1090 resp->addString(x.charconvsys->Convert(channel->Alang(i)));
1092 resp->addULONG(numDpids);
1093 for (ULONG i = 0; i < numDpids; i++)
1095 resp->addULONG(channel->Dpid(i));
1096 resp->addString(x.charconvsys->Convert(channel->Dlang(i)));
1098 resp->addULONG(numSpids);
1099 for (ULONG i = 0; i < numSpids; i++)
1101 resp->addULONG(channel->Spid(i));
1102 resp->addString(x.charconvsys->Convert(channel->Slang(i)));
1105 resp->addULONG(channel->Tpid());
1106 // Format of extended response, for compatibility with older client at the end
1118 #if VDRVERSNUM < 10300
1128 for (ULONG i = 0; i < numApids; i++)
1130 #if VDRVERSNUM < 10715
1133 resp->addULONG(channel->Atype(i));
1136 for (ULONG i = 0; i < numDpids; i++)
1138 #if VDRVERSNUM < 10715
1139 resp->addULONG(0x6A /*AC3*/);
1141 resp->addULONG(channel->Dtype(i));
1144 for (ULONG i = 0; i < numSpids; i++)
1146 #if VDRVERSNUM < 10715
1151 resp->addULONG(channel->SubtitlingType(i));
1152 resp->addULONG(channel->CompositionPageId(i));
1153 resp->addULONG(channel->AncillaryPageId(i));
1160 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1162 log->log("RRProc", Log::DEBUG, "Written channels pids");
1167 int VompClientRRProc::processStartStreamingChannel()
1171 log->log("RRProc", Log::ERR, "Client called start streaming twice");
1175 log->log("RRProc", Log::DEBUG, "req->dataLength = %i", req->dataLength);
1176 ULONG channelNumber = ntohl(*(ULONG*)req->data);
1178 cChannel* channel = x.channelFromNumber(channelNumber);
1183 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1187 // get the priority we should use
1189 int priority = x.config.getValueLong("General", "Live priority", &fail);
1192 log->log("RRProc", Log::DEBUG, "Config: Live TV priority: %i", priority);
1196 log->log("RRProc", Log::DEBUG, "Config: Live TV priority config fail");
1200 // a bit of sanity..
1201 #if VDRVERSNUM < 10725
1202 if (priority < 0) priority = 0;
1204 if (priority < -99) priority = -99;
1206 if (priority > 99) priority = 99;
1208 log->log("RRProc", Log::DEBUG, "Using live TV priority %i", priority);
1209 x.lp = MVPReceiver::create(channel, priority);
1215 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1219 if (!x.lp->init(&x.tcp, req->requestID))
1225 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1231 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1235 int VompClientRRProc::processStopStreaming()
1237 log->log("RRProc", Log::DEBUG, "STOP STREAMING RECEIVED");
1240 x.lp->detachMVPReceiver();
1244 else if (x.recplayer)
1246 x.writeResumeData();
1249 delete x.recordingManager;
1251 x.recordingManager = NULL;
1256 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1260 int VompClientRRProc::processGetBlock()
1264 log->log("RRProc", Log::ERR, "Get block called during live streaming");
1270 log->log("RRProc", Log::ERR, "Get block called when no recording open");
1274 UCHAR* data = req->data;
1276 ULLONG position = x.ntohll(*(ULLONG*)data);
1277 data += sizeof(ULLONG);
1278 ULONG amount = ntohl(*(ULONG*)data);
1280 log->log("RRProc", Log::DEBUG, "getblock pos = %llu length = %lu", position, amount);
1282 UCHAR sendBuffer[amount];
1283 ULONG amountReceived = x.recplayer->getBlock(&sendBuffer[0], position, amount);
1285 if (!amountReceived)
1288 log->log("RRProc", Log::DEBUG, "written 4(0) as getblock got 0");
1292 resp->copyin(sendBuffer, amountReceived);
1293 log->log("RRProc", Log::DEBUG, "written %lu", amountReceived);
1297 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1298 log->log("RRProc", Log::DEBUG, "Finished getblock, have sent %lu", resp->getLen());
1302 int VompClientRRProc::processStartStreamingRecording()
1304 // data is a pointer to the fileName string
1306 x.recordingManager = new cRecordings;
1307 x.recordingManager->Load();
1309 cRecording* recording = x.recordingManager->GetByName((char*)req->data);
1311 log->log("RRProc", Log::DEBUG, "recording pointer %p", recording);
1315 x.recplayer = new RecPlayer(recording);
1317 resp->addULLONG(x.recplayer->getLengthBytes());
1318 resp->addULONG(x.recplayer->getLengthFrames());
1320 #if VDRVERSNUM < 10703
1321 resp->addUCHAR(true);//added for TS
1323 resp->addUCHAR(recording->IsPesRecording());//added for TS
1327 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1329 log->log("RRProc", Log::DEBUG, "written totalLength");
1333 delete x.recordingManager;
1334 x.recordingManager = NULL;
1339 int VompClientRRProc::processPositionFromFrameNumber()
1343 ULONG frameNumber = ntohl(*(ULONG*)req->data);
1347 log->log("RRProc", Log::DEBUG, "Rescan recording called when no recording being played!");
1351 retval = x.recplayer->positionFromFrameNumber(frameNumber);
1354 resp->addULLONG(retval);
1356 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1358 log->log("RRProc", Log::DEBUG, "Wrote posFromFrameNum reply to client");
1362 int VompClientRRProc::processFrameNumberFromPosition()
1366 ULLONG position = x.ntohll(*(ULLONG*)req->data);
1370 log->log("RRProc", Log::DEBUG, "Rescan recording called when no recording being played!");
1374 retval = x.recplayer->frameNumberFromPosition(position);
1377 resp->addULONG(retval);
1379 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1381 log->log("RRProc", Log::DEBUG, "Wrote frameNumFromPos reply to client");
1385 int VompClientRRProc::processGetIFrame()
1387 bool success = false;
1389 ULONG* data = (ULONG*)req->data;
1391 ULONG frameNumber = ntohl(*data);
1393 ULONG direction = ntohl(*data);
1395 ULLONG rfilePosition = 0;
1396 ULONG rframeNumber = 0;
1397 ULONG rframeLength = 0;
1401 log->log("RRProc", Log::DEBUG, "GetIFrame recording called when no recording being played!");
1405 success = x.recplayer->getNextIFrame(frameNumber, direction, &rfilePosition, &rframeNumber, &rframeLength);
1408 // returns file position, frame number, length
1412 resp->addULLONG(rfilePosition);
1413 resp->addULONG(rframeNumber);
1414 resp->addULONG(rframeLength);
1422 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1424 log->log("RRProc", Log::DEBUG, "Wrote GNIF reply to client %llu %lu %lu", rfilePosition, rframeNumber, rframeLength);
1428 int VompClientRRProc::processGetChannelSchedule()
1430 ULONG* data = (ULONG*)req->data;
1432 ULONG channelNumber = ntohl(*data);
1434 ULONG startTime = ntohl(*data);
1436 ULONG duration = ntohl(*data);
1438 log->log("RRProc", Log::DEBUG, "get schedule called for channel %lu", channelNumber);
1440 cChannel* channel = x.channelFromNumber(channelNumber);
1445 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1447 log->log("RRProc", Log::DEBUG, "written 0 because channel = NULL");
1451 log->log("RRProc", Log::DEBUG, "Got channel");
1453 #if VDRVERSNUM < 10300
1454 cMutexLock MutexLock;
1455 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
1457 cSchedulesLock MutexLock;
1458 const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
1464 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1466 log->log("RRProc", Log::DEBUG, "written 0 because Schedule!s! = NULL");
1470 log->log("RRProc", Log::DEBUG, "Got schedule!s! object");
1472 const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
1477 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1479 log->log("RRProc", Log::DEBUG, "written 0 because Schedule = NULL");
1483 log->log("RRProc", Log::DEBUG, "Got schedule object");
1485 const char* empty = "";
1486 bool atLeastOneEvent = false;
1489 ULONG thisEventTime;
1490 ULONG thisEventDuration;
1491 const char* thisEventTitle;
1492 const char* thisEventSubTitle;
1493 const char* thisEventDescription;
1495 #if VDRVERSNUM < 10300
1497 const cEventInfo *event;
1498 for (int eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
1500 event = Schedule->GetEventNumber(eventNumber);
1502 thisEventID = event->GetEventID();
1503 thisEventTime = event->GetTime();
1504 thisEventDuration = event->GetDuration();
1505 thisEventTitle = event->GetTitle();
1506 thisEventSubTitle = event->GetSubtitle();
1507 thisEventDescription = event->GetExtendedDescription();
1511 for (const cEvent* event = Schedule->Events()->First(); event; event = Schedule->Events()->Next(event))
1513 thisEventID = event->EventID();
1514 thisEventTime = event->StartTime();
1515 thisEventDuration = event->Duration();
1516 thisEventTitle = event->Title();
1517 thisEventSubTitle = NULL;
1518 thisEventDescription = event->Description();
1522 //in the past filter
1523 if ((thisEventTime + thisEventDuration) < (ULONG)time(NULL)) continue;
1526 if ((thisEventTime + thisEventDuration) <= startTime) continue;
1529 if (thisEventTime >= (startTime + duration)) continue;
1531 if (!thisEventTitle) thisEventTitle = empty;
1532 if (!thisEventSubTitle) thisEventSubTitle = empty;
1533 if (!thisEventDescription) thisEventDescription = empty;
1535 resp->addULONG(thisEventID);
1536 resp->addULONG(thisEventTime);
1537 resp->addULONG(thisEventDuration);
1539 resp->addString(x.charconvsys->Convert(thisEventTitle));
1540 resp->addString(x.charconvsys->Convert(thisEventSubTitle));
1541 resp->addString(x.charconvsys->Convert(thisEventDescription));
1543 atLeastOneEvent = true;
1546 log->log("RRProc", Log::DEBUG, "Got all event data");
1548 if (!atLeastOneEvent)
1551 log->log("RRProc", Log::DEBUG, "Written 0 because no data");
1555 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1557 log->log("RRProc", Log::DEBUG, "written schedules packet");
1562 int VompClientRRProc::processGetTimers()
1565 int numTimers = Timers.Count();
1567 resp->addULONG(numTimers);
1569 for (int i = 0; i < numTimers; i++)
1571 timer = Timers.Get(i);
1573 #if VDRVERSNUM < 10300
1574 resp->addULONG(timer->Active());
1576 resp->addULONG(timer->HasFlags(tfActive));
1578 resp->addULONG(timer->Recording());
1579 resp->addULONG(timer->Pending());
1580 resp->addULONG(timer->Priority());
1581 resp->addULONG(timer->Lifetime());
1582 resp->addULONG(timer->Channel()->Number());
1583 resp->addULONG(timer->StartTime());
1584 resp->addULONG(timer->StopTime());
1585 resp->addULONG(timer->Day());
1586 resp->addULONG(timer->WeekDays());
1587 resp->addString(timer->File()); //Filename is system specific and not visible by user
1591 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1593 log->log("RRProc", Log::DEBUG, "Written timers list");
1598 int VompClientRRProc::processSetTimer()
1600 char* timerString = new char[strlen((char*)req->data) + 1];
1601 strcpy(timerString, (char*)req->data);
1603 #if VDRVERSNUM < 10300
1605 // If this is VDR 1.2 the date part of the timer string must be reduced
1606 // to just DD rather than YYYY-MM-DD
1608 int s = 0; // source
1609 int d = 0; // destination
1611 while(c != 2) // copy up to date section, including the second ':'
1613 timerString[d] = req->data[s];
1614 if (req->data[s] == ':') c++;
1618 // now it has copied up to the date section
1620 while(c != 2) // waste YYYY-MM-
1622 if (req->data[s] == '-') c++;
1625 // now source is at the DD
1626 memcpy(&timerString[d], &req->data[s], req->dataLength - s);
1627 d += req->dataLength - s;
1628 timerString[d] = '\0';
1630 log->log("RRProc", Log::DEBUG, "Timer string after 1.2 conversion:");
1633 log->log("RRProc", Log::DEBUG, "%s", timerString);
1635 cTimer *timer = new cTimer;
1636 if (timer->Parse((char*)timerString))
1638 cTimer *t = Timers.GetTimer(timer);
1642 #if VDRVERSNUM < 10300
1645 Timers.SetModified();
1649 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1650 return 1; // FIXME - cTimer* timer is leaked here!
1656 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1663 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1669 int VompClientRRProc::processDeleteTimer()
1671 log->log("RRProc", Log::DEBUG, "Delete timer called");
1676 INT delChannel = ntohl(*(ULONG*)&req->data[position]); position += 4;
1677 INT delWeekdays = ntohl(*(ULONG*)&req->data[position]); position += 4;
1678 INT delDay = ntohl(*(ULONG*)&req->data[position]); position += 4;
1679 INT delStart = ntohl(*(ULONG*)&req->data[position]); position += 4;
1680 INT delStop = ntohl(*(ULONG*)&req->data[position]); position += 4;
1683 for (ti = Timers.First(); ti; ti = Timers.Next(ti))
1685 if ( (ti->Channel()->Number() == delChannel)
1686 && ((ti->WeekDays() && (ti->WeekDays() == delWeekdays)) || (!ti->WeekDays() && (ti->Day() == delDay)))
1687 && (ti->StartTime() == delStart)
1688 && (ti->StopTime() == delStop) )
1696 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1700 if (!Timers.BeingEdited())
1702 if (!ti->Recording())
1705 Timers.SetModified();
1708 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1713 log->log("RRProc", Log::ERR, "Unable to delete timer - timer is running");
1716 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1722 log->log("RRProc", Log::ERR, "Unable to delete timer - timers being edited at VDR");
1725 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1730 int VompClientRRProc::processGetRecInfo()
1732 // data is a pointer to the fileName string
1734 cRecordings Recordings;
1735 Recordings.Load(); // probably have to do this
1737 cRecording *recording = Recordings.GetByName((char*)req->data);
1739 time_t timerStart = 0;
1740 time_t timerStop = 0;
1741 char* summary = NULL;
1742 char* shorttext = NULL;
1743 char* description = NULL;
1745 bool newsummary=false;
1746 ULONG resumePoint = 0;
1750 log->log("RRProc", Log::ERR, "GetRecInfo found no recording");
1753 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1758 4 bytes: start time for timer
1759 4 bytes: end time for timer
1760 4 bytes: resume point
1762 4 bytes: num components
1769 8 bytes: frames per second
1772 // Get current timer
1774 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
1777 timerStart = rc->Timer()->StartTime();
1778 timerStop = rc->Timer()->StopTime();
1779 log->log("RRProc", Log::DEBUG, "GRI: RC: %lu %lu", timerStart, timerStop);
1782 resp->addULONG(timerStart);
1783 resp->addULONG(timerStop);
1787 /* char* value = x.config.getValueString("ResumeData", (char*)req->data);
1790 resumePoint = strtoul(value, NULL, 10);
1794 char* ResumeIdC = x.config.getValueString("General", "ResumeId");
1797 ResumeId = atoi(ResumeIdC);
1801 ResumeId = 0; //default if not defined in vomp-MAC.conf
1803 while (ResumeIDLock)
1804 cCondWait::SleepMs(100);
1805 ResumeIDLock = true;
1806 int OldSetupResumeID = Setup.ResumeID;
1807 Setup.ResumeID = ResumeId; //UGLY: quickly change resumeid
1808 #if VDRVERSNUM < 10703
1809 cResumeFile ResumeFile(recording->FileName()); //get corresponding resume file
1811 cResumeFile ResumeFile(recording->FileName(), recording->IsPesRecording()); //get corresponding resume file
1813 Setup.ResumeID = OldSetupResumeID; //and restore it back
1814 ResumeIDLock = false;
1816 int resume = ResumeFile.Read();
1817 //isyslog("VOMPDEBUG: resumePoint = %i, resume = %i, ResumeId = %i",resumePoint, resume, ResumeId);
1819 resumePoint = ResumeFile.Read();
1821 log->log("RRProc", Log::DEBUG, "GRI: RP: %lu", resumePoint);
1823 resp->addULONG(resumePoint);
1827 #if VDRVERSNUM < 10300
1828 summary = (char*)recording->Summary();
1830 const cRecordingInfo *Info = recording->Info();
1831 shorttext = (char*)Info->ShortText();
1832 description = (char*) (char*)Info->Description();
1833 if (isempty(shorttext)) summary=description;
1834 else if (isempty(description)) summary=shorttext;
1836 int length=strlen(description)+strlen(shorttext)+4;
1837 summary=new char[length];
1838 snprintf(summary,length,"%s\n\n%s",shorttext,description);
1842 if (isempty(summary)) summary = (char*)Info->Description();
1844 log->log("RRProc", Log::DEBUG, "GRI: S: %s", summary);
1847 resp->addString(x.charconvsys->Convert(summary));
1848 if (newsummary) delete [] summary;
1852 resp->addString("");
1857 #if VDRVERSNUM < 10300
1859 // Send 0 for numchannels - this signals the client this info is not available
1863 const cComponents* components = Info->Components();
1865 log->log("RRProc", Log::DEBUG, "GRI: D1: %p", components);
1873 resp->addULONG(components->NumComponents());
1875 tComponent* component;
1876 for (int i = 0; i < components->NumComponents(); i++)
1878 component = components->Component(i);
1880 log->log("RRProc", Log::DEBUG, "GRI: C: %i %u %u %s %s", i, component->stream, component->type, component->language, component->description);
1882 resp->addUCHAR(component->stream);
1883 resp->addUCHAR(component->type);
1885 if (component->language)
1887 resp->addString(x.charconvsys->Convert(component->language));
1891 resp->addString("");
1893 if (component->description)
1895 resp->addString(x.charconvsys->Convert(component->description));
1899 resp->addString("");
1905 double framespersec;
1906 #if VDRVERSNUM < 10703
1907 framespersec = FRAMESPERSEC;
1909 framespersec = Info->FramesPerSecond();
1911 resp->adddouble(framespersec);
1912 title = (char*)Info->Title();
1915 resp->addString(x.charconvsys->Convert(title));
1919 resp->addString(x.charconvsys->Convert(recording->Name()));
1925 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1927 log->log("RRProc", Log::DEBUG, "Written getrecinfo");
1937 int VompClientRRProc::processReScanRecording()
1941 log->log("RRProc", Log::DEBUG, "Rescan recording called when no recording being played!");
1945 x.recplayer->scan();
1947 resp->addULLONG(x.recplayer->getLengthBytes());
1948 resp->addULONG(x.recplayer->getLengthFrames());
1950 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1951 log->log("RRProc", Log::DEBUG, "Rescan recording, wrote new length to client");
1955 // FIXME without client calling rescan, getblock wont work even tho more data is avail
1957 int VompClientRRProc::processGetMarks()
1959 // data is a pointer to the fileName string
1962 cRecordings Recordings;
1963 Recordings.Load(); // probably have to do this
1965 cRecording *recording = Recordings.GetByName((char*)req->data);
1967 log->log("RRProc", Log::DEBUG, "recording pointer %p", recording);
1971 #if VDRVERSNUM < 10703
1972 Marks.Load(recording->FileName());
1974 Marks.Load(recording->FileName(), recording->FramesPerSecond(), recording->IsPesRecording());
1978 for (const cMark *m = Marks.First(); m; m = Marks.Next(m))
1980 #if VDRVERSNUM < 10721
1981 ULLONG mposition = m->position;
1983 ULLONG mposition = m->Position();
1985 log->log("RRProc", Log::DEBUG, "found Mark %i", mposition);
1987 resp->addULONG(mposition);
1992 log->log("RRProc", Log::DEBUG, "no marks found, sending 0-mark");
1998 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
2000 log->log("RRProc", Log::DEBUG, "Written Marks list");
2005 int VompClientRRProc::processVDRShutdown()
2007 log->log("RRProc", Log::DEBUG, "Trying to shutdown VDR");
2008 VompClient::decClients(); // Temporarily make this client disappear
2009 cRemote::Put(kPower);
2010 VompClient::incClients();
2012 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
2016 int VompClientRRProc::processGetRecScraperEventType()
2018 Recordings.Load(); // probably have to do this
2020 cRecording *recording = Recordings.GetByName((char*)req->data);
2021 ScraperGetEventType call;
2024 if (recording && x.scraper)
2026 call.recording = recording;
2027 x.scraper->Service("GetEventType",&call);
2029 resp->addUCHAR(call.type);
2030 if (call.type == tMovie)
2032 resp->addLONG(call.movieId);
2033 } else if (call.type == tSeries){
2034 resp->addLONG(call.seriesId);
2035 resp->addLONG(call.episodeId);
2038 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
2043 int VompClientRRProc::processGetEventScraperEventType()
2045 ScraperGetEventType call;
2047 ULONG channelid = ntohl(*(ULONG*)req->data);
2048 ULONG eventid = ntohl(*(ULONG*)(req->data+4));
2049 const cEvent *event = NULL;
2051 cChannel* channel = x.channelFromNumber(channelid);
2053 #if VDRVERSNUM < 10300
2054 cMutexLock MutexLock;
2055 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
2057 cSchedulesLock MutexLock;
2058 const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
2060 const cSchedule * Schedule;
2061 if (Schedules && channel)
2063 const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
2065 event = Schedule->GetEvent(eventid);
2069 if (event && x.scraper)
2072 x.scraper->Service("GetEventType",&call);
2074 resp->addUCHAR(call.type);
2075 if (call.type == tMovie)
2077 resp->addLONG(call.movieId);
2078 } else if (call.type == tSeries){
2079 resp->addLONG(call.seriesId);
2080 resp->addLONG(call.episodeId);
2083 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
2088 #define ADDSTRING_TO_PAKET(y) if ((y)!=0) resp->addString(x.charconvutf8->Convert(y)); else resp->addString("");
2090 int VompClientRRProc::processGetScraperMovieInfo()
2094 movie.movieId = ntohl(*(ULONG*)req->data);
2096 log->log("RRProc", Log::DEBUG, "No Scraper, get SeriesInfo");
2097 return 0; //stupid, I have no scraper why are you still asking
2099 x.scraper->Service("GetMovie",&movie);
2102 ADDSTRING_TO_PAKET(movie.title.c_str());
2103 ADDSTRING_TO_PAKET(movie.originalTitle.c_str());
2104 ADDSTRING_TO_PAKET(movie.tagline.c_str());
2105 ADDSTRING_TO_PAKET(movie.overview.c_str());
2106 resp->addUCHAR(movie.adult);
2107 ADDSTRING_TO_PAKET(movie.collectionName.c_str());
2109 resp->addLONG(movie.budget);
2110 resp->addLONG(movie.revenue);
2111 ADDSTRING_TO_PAKET(movie.genres.c_str());
2112 ADDSTRING_TO_PAKET(movie.homepage.c_str());
2113 ADDSTRING_TO_PAKET(movie.releaseDate.c_str());
2114 resp->addLONG(movie.runtime);
2115 resp->adddouble(movie.popularity);
2116 resp->adddouble(movie.voteAverage);
2117 resp->addULONG(movie.poster.width);
2118 resp->addULONG(movie.poster.height);
2119 resp->addULONG(movie.fanart.width);
2120 resp->addULONG(movie.fanart.height);
2121 resp->addULONG(movie.collectionPoster.width);
2122 resp->addULONG(movie.collectionPoster.height);
2123 resp->addULONG(movie.collectionFanart.width);
2124 resp->addULONG(movie.collectionFanart.height);
2125 resp->addULONG(movie.actors.size());
2126 for (ULONG acty=0; acty < movie.actors.size(); acty++) {
2127 ADDSTRING_TO_PAKET(movie.actors[acty].name.c_str());
2128 ADDSTRING_TO_PAKET(movie.actors[acty].role.c_str());
2129 resp->addULONG(movie.actors[acty].actorThumb.width);
2130 resp->addULONG(movie.actors[acty].actorThumb.height);
2134 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
2141 int VompClientRRProc::processGetScraperSeriesInfo()
2144 series.seriesId = ntohl(*(ULONG*)req->data);
2145 series.episodeId = ntohl(*(ULONG*)(req->data+4));
2147 log->log("RRProc", Log::DEBUG, "No Scraper, get SeriesInfo");
2148 return 0; //stupid, I have no scraper why are you still asking
2150 x.scraper->Service("GetSeries",&series);
2152 ADDSTRING_TO_PAKET(series.name.c_str());
2153 ADDSTRING_TO_PAKET(series.overview.c_str());
2154 ADDSTRING_TO_PAKET(series.firstAired.c_str());
2155 ADDSTRING_TO_PAKET(series.network.c_str());
2156 ADDSTRING_TO_PAKET(series.genre.c_str());
2157 resp->adddouble(series.rating);
2158 ADDSTRING_TO_PAKET(series.status.c_str());
2160 resp->addLONG(series.episode.number);
2161 resp->addLONG(series.episode.season);
2162 ADDSTRING_TO_PAKET(series.episode.name.c_str());
2163 ADDSTRING_TO_PAKET(series.episode.firstAired.c_str());
2164 ADDSTRING_TO_PAKET(series.episode.guestStars.c_str());
2165 ADDSTRING_TO_PAKET(series.episode.overview.c_str());
2166 resp->adddouble(series.episode.rating);
2167 resp->addULONG(series.episode.episodeImage.width);
2168 resp->addULONG(series.episode.episodeImage.height);
2170 ULONG num_actors = series.actors.size();
2171 resp->addULONG(num_actors);
2172 for (ULONG acty=0; acty < num_actors; acty++) {
2173 ADDSTRING_TO_PAKET(series.actors[acty].name.c_str());
2174 ADDSTRING_TO_PAKET(series.actors[acty].role.c_str());
2175 resp->addULONG(series.actors[acty].actorThumb.width);
2176 resp->addULONG(series.actors[acty].actorThumb.height);
2178 ULONG num_posters = series.posters.size();
2179 resp->addULONG(num_posters);
2180 for (ULONG medias = 0; medias < num_posters; medias++ ) {
2181 cTvMedia media=series.posters[medias];
2182 resp->addULONG(media.width);
2183 resp->addULONG(media.height);
2186 ULONG num_banners = series.banners.size();
2187 resp->addULONG(num_banners);
2188 for (ULONG medias = 0; medias < num_banners; medias++ ) {
2189 cTvMedia media=series.banners[medias];
2190 resp->addULONG(media.width);
2191 resp->addULONG(media.height);
2193 ULONG num_fanarts = series.fanarts.size();
2194 resp->addULONG(num_fanarts);
2195 for (ULONG medias = 0; medias < num_fanarts; medias++ ) {
2196 cTvMedia media=series.fanarts[medias];
2197 resp->addULONG(media.width);
2198 resp->addULONG(media.height);
2200 resp->addULONG(series.seasonPoster.width);
2201 resp->addULONG(series.seasonPoster.height);
2205 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
2210 int VompClientRRProc::processLoadTvMedia()
2212 TVMediaRequest tvreq;
2213 tvreq.streamID = req->requestID;
2214 tvreq.type = ntohl(*(ULONG*)req->data);
2215 tvreq.primary_id = ntohl(*(ULONG*)(req->data+4));
2216 tvreq.secondary_id = ntohl(*(ULONG*)(req->data+8));
2217 tvreq.type_pict = ntohl(*(ULONG*)(req->data+12));
2218 tvreq.container = ntohl(*(ULONG*)(req->data+16));
2219 tvreq.container_member = ntohl(*(ULONG*)(req->data+20));
2220 log->log("RRProc", Log::DEBUG, "TVMedia request %d",req->requestID);
2221 x.pict->addTVMediaRequest(tvreq);
2226 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
2231 int VompClientRRProc::processLoadTvMediaRecThumb()
2233 TVMediaRequest tvreq;
2234 tvreq.streamID = req->requestID;
2235 tvreq.type = 3; // unknown but primary_name is set
2236 tvreq.primary_id = 0;
2237 tvreq.primary_name = std::string((const char*) req->data);
2238 tvreq.secondary_id = 0;
2239 tvreq.type_pict = 1;
2240 tvreq.container = 0;
2241 tvreq.container_member = 0;
2242 log->log("RRProc", Log::DEBUG, "TVMedia request %d %s",req->requestID,req->data);
2243 x.pict->addTVMediaRequest(tvreq);
2248 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
2253 int VompClientRRProc::processLoadTvMediaEventThumb()
2255 TVMediaRequest tvreq;
2256 tvreq.streamID = req->requestID;
2257 tvreq.type = 4; // unknown but primary_id is set
2258 UINT channelid = ntohl(*(ULONG*)req->data);
2259 tvreq.primary_id = ntohl(*(ULONG*)(req->data+4));
2260 tvreq.secondary_id = 0;
2261 cChannel* channel = x.channelFromNumber(channelid);
2263 if (channel) tvreq.primary_name = std::string((const char*)channel->GetChannelID().ToString());
2264 tvreq.type_pict = 1;
2265 tvreq.container = 0;
2266 tvreq.container_member = 0;
2267 log->log("RRProc", Log::DEBUG, "TVMedia request %d %s",req->requestID,req->data);
2268 x.pict->addTVMediaRequest(tvreq);
2273 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
2282 #endif // !VOMPSTANDALONE