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();
299 case VDR_LOADCHANNELLOGO:
300 result = processLoadChannelLogo();
303 case VDR_GETMEDIALIST:
304 result = processGetMediaList();
307 result = processOpenMedia();
309 case VDR_GETMEDIABLOCK:
310 result = processGetMediaBlock();
313 result = processGetLanguageList();
316 result = processGetLanguageContent();
318 case VDR_GETMEDIAINFO:
319 result = processGetMediaInfo();
321 case VDR_CLOSECHANNEL:
322 result = processCloseMediaChannel();
325 result = processSetCharset();
332 if (req->data) free(req->data);
336 if (result) return true;
340 int VompClientRRProc::processLogin()
342 if (req->dataLength != 6) return 0;
346 char configFileName[PATH_MAX];
347 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]);
348 x.config.init(configFileName);
350 // Send the login reply
352 time_t timeNow = time(NULL);
353 struct tm* timeStruct = localtime(&timeNow);
354 int timeOffset = timeStruct->tm_gmtoff;
356 resp->addULONG(timeNow);
357 resp->addLONG(timeOffset);
358 resp->addULONG(VOMP_PROTOCOL_VERSION_MIN);
359 resp->addULONG(VOMP_PROTOCOL_VERSION_MAX);
361 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
362 log->log("RRProc", Log::DEBUG, "written login reply len %lu", resp->getLen());
365 x.netLog(); // safe to run here since the client won't start net logging for a while yet
370 int VompClientRRProc::processSetCharset()
372 int charset = ntohl(*(ULONG*)req->data);
373 if (charset>0 && charset<3)
375 log->log("RRProc", Log::DEBUG, "Set charset to %d", charset);
376 x.setCharset(charset);
381 log->log("RRProc", Log::DEBUG, "Invalid charset %d", charset);
385 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
389 int VompClientRRProc::processConfigSave()
391 char* section = (char*)req->data;
395 for (UINT k = 0; k < req->dataLength; k++)
397 if (req->data[k] == '\0')
401 key = (char*)&req->data[k+1];
405 value = (char*)&req->data[k+1];
411 // if the last string (value) doesnt have null terminator, give up
412 if (req->data[req->dataLength - 1] != '\0') return 0;
414 log->log("RRProc", Log::DEBUG, "Config save: %s %s %s", section, key, value);
415 if (x.config.setValueString(section, key, value))
425 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
430 int VompClientRRProc::processConfigLoad()
432 char* section = (char*)req->data;
435 for (UINT k = 0; k < req->dataLength; k++)
437 if (req->data[k] == '\0')
439 key = (char*)&req->data[k+1];
444 char* value = x.config.getValueString(section, key);
448 resp->addString(value);//client coding, do not touch
449 log->log("RRProc", Log::DEBUG, "Written config load packet");
455 log->log("RRProc", Log::DEBUG, "Written config load failed packet");
459 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
465 //helper for sending from a serialize buffer
466 //insert the used len into the first 4 Bytes of the buffer
467 void VompClientRRProc::sendPacket(SerializeBuffer *b) {
468 resp->copyin(b->getStart(),b->getCurrent()-b->getStart());
470 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
474 * media List Request:
475 * Media List response:
478 #define MLISTBUF 500000
479 int VompClientRRProc::processGetMediaList()
481 SerializeBuffer buffer(req->data,req->dataLength);
482 MediaURI uri(0,NULL,NULL);
483 VDR_GetMediaListRequest request(&uri);
484 if (request.deserialize(&buffer) != 0) {
485 log->log("Client", Log::ERR, "getMediaList unable to deserialize");
488 const char *dirname=uri.getName();
489 log->log("Client", Log::DEBUG, "getMediaList for %s", dirname);
492 if (dirname == NULL) {
493 ml=x.media->getRootList();
495 ml=x.media->getMediaList(&uri);
498 log->log("Client", Log::ERR, "getMediaList returned NULL");
501 SerializeBuffer rbuf(MLISTBUF,false,true);
502 ULONG flags=0; //TODO: real error handling by setting flags
503 VDR_GetMediaListResponse response(&flags,ml);
504 if (response.serialize(&rbuf) != 0) {
505 log->log("Client", Log::ERR, "getMediaList returned NULL");
509 log->log("Client", Log::DEBUG, "getMediaList size %u", ml->size());
514 log->log("Client", Log::DEBUG, "Written Media list");
519 * openMedia response:
521 int VompClientRRProc::processOpenMedia()
523 SerializeBuffer buffer(req->data,req->dataLength);
524 MediaURI uri(0,NULL,NULL);
528 VDR_OpenMediumRequest request(&channel,&uri,&xs,&ys);
529 if (request.deserialize(&buffer) != 0) {
530 log->log("Client", Log::ERR, "openMediaRequest unable to deserialize");
533 const char *name=uri.getName();
534 log->log("Client", Log::DEBUG, "openMediaRequest for %s", name);
536 int rt=x.media->openMedium(channel,&uri,&size,xs,ys);
541 log->log("Client", Log::ERR, "openMediaRequest unable to open");
543 VDR_OpenMediumResponse response(&flags,&size);
544 SerializeBuffer rbuf(response.getSerializedLen()+4,false,true);
545 if (response.serialize(&rbuf) != 0) {
546 log->log("Client", Log::ERR, "openMediaRequest cannot serialize");
549 log->log("Client", Log::DEBUG, "openMediaRequest size %llu", size);
556 * packet - no serialized response!
558 int VompClientRRProc::processGetMediaBlock()
560 SerializeBuffer buffer(req->data,req->dataLength);
564 VDR_GetMediaBlockRequest request(&channel,&position,&amount);
565 if (request.deserialize(&buffer) != 0) {
566 log->log("Client", Log::ERR, "getMediaBlock unable to deserialize");
569 log->log("Client", Log::DEBUG, "getMediaBlock pos = %llu length = %lu,chan=%lu", position, amount,channel);
571 UCHAR sendBuffer[amount ];
572 ULONG amountReceived = 0;
573 UCHAR *rbuf=sendBuffer;
574 int rt=x.media->getMediaBlock(channel,position,amount,&amountReceived,&rbuf);
575 if (!amountReceived || rt != 0)
577 log->log("Client", Log::DEBUG, "written 4(0) as getblock got 0");
581 if (rbuf != sendBuffer) {
582 //the provider did not use the optimized handling with using my buffer
583 resp->copyin(rbuf,amountReceived);
586 // the provider did not allocate a new buffer
587 resp->copyin(sendBuffer,amountReceived);
591 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
592 log->log("Client", Log::DEBUG, "written ok %lu", amountReceived);
599 int VompClientRRProc::processGetMediaInfo()
601 SerializeBuffer buffer(req->data,req->dataLength);
603 VDR_GetMediaInfoRequest request(&channel);
604 if (request.deserialize(&buffer) != 0) {
605 log->log("Client", Log::ERR, "getMediaInfo unable to deserialize");
608 log->log("Client", Log::DEBUG, "getMediaInfo chan=%lu", channel);
611 int rt=x.media->getMediaInfo(channel,&mi);
614 log->log("Client", Log::ERR, "getMediaInfo unable to get");
616 VDR_GetMediaInfoResponse response(&flags,&mi);
617 SerializeBuffer rbuf(response.getSerializedLen()+4,false,true);
618 if (response.serialize(&rbuf) != 0) {
619 log->log("Client", Log::ERR, "getMediaInfo cannot serialize");
631 int VompClientRRProc::processCloseMediaChannel()
633 SerializeBuffer buffer(req->data,req->dataLength);
635 VDR_CloseMediaChannelRequest request(&channel);
636 if (request.deserialize(&buffer) != 0) {
637 log->log("Client", Log::ERR, "closeMediaChannel unable to deserialize");
641 log->log("Client", Log::DEBUG, "closeMediaChannel chan=%lu", channel);
642 int rt=x.media->closeMediaChannel(channel);
645 log->log("Client", Log::ERR, "closeMediaChannel unable to get");
647 VDR_CloseMediaChannelResponse response(&flags);
648 SerializeBuffer rbuf(response.getSerializedLen()+4,false,true);
649 if (response.serialize(&rbuf) != 0) {
650 log->log("Client", Log::ERR, "closeMediaChannel cannot serialize");
659 int VompClientRRProc::processGetLanguageList()
661 x.i18n.findLanguages();
662 const I18n::lang_code_list& languages = x.i18n.getLanguageList();
664 I18n::lang_code_list::const_iterator iter;
665 for (iter = languages.begin(); iter != languages.end(); ++iter)
667 resp->addString(iter->first.c_str()); // Source code is acsii
668 resp->addString(x.charconvutf8->Convert(iter->second.c_str())); //translate string can be any utf-8 character
671 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
675 int VompClientRRProc::processGetLanguageContent()
677 if (req->dataLength <= 0) return 0;
678 std::string code, result;
679 code.assign((char*)req->data, req->dataLength - 1);
680 x.i18n.findLanguages();
681 I18n::trans_table texts = x.i18n.getLanguageContent(code);
682 I18n::trans_table::const_iterator iter;
683 for (iter = texts.begin(); iter != texts.end(); ++iter)
685 resp->addString(iter->first.c_str());// source code is acsii since it is english
686 resp->addString(x.charconvutf8->Convert(iter->second.c_str())); // translate text can be any unicode string, it is stored as UTF-8
689 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
693 #ifndef VOMPSTANDALONE
695 int VompClientRRProc::processGetRecordingsList()
698 #if APIVERSNUM > 20101
699 int Percent = cVideoDirectory::VideoDiskSpace(&FreeMB);
701 int Percent = VideoDiskSpace(&FreeMB);
703 int Total = (FreeMB / (100 - Percent)) * 100;
705 resp->addULONG(Total);
706 resp->addULONG(FreeMB);
707 resp->addULONG(Percent);
709 cRecordings Recordings;
712 for (cRecording *recording = Recordings.First(); recording; recording = Recordings.Next(recording))
714 #if VDRVERSNUM < 10721
715 resp->addULONG(recording->start);
717 resp->addULONG(recording->Start());
719 resp->addUCHAR(recording->IsNew() ? 1 : 0);
720 resp->addString(x.charconvsys->Convert(recording->Name())); //coding of recording name is system dependent
721 resp->addString(recording->FileName());//file name are not visible by user do not touch
725 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
727 log->log("RRProc", Log::DEBUG, "Written recordings list");
732 int VompClientRRProc::processDeleteRecording()
734 // data is a pointer to the fileName string
736 cRecordings Recordings;
737 Recordings.Load(); // probably have to do this
739 cRecording* recording = Recordings.GetByName((char*)req->data);
741 log->log("RRProc", Log::DEBUG, "recording pointer %p", recording);
745 log->log("RRProc", Log::DEBUG, "deleting recording: %s", recording->Name());
747 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
750 if (recording->Delete())
752 // Copy svdrp's way of doing this, see if it works
753 #if VDRVERSNUM > 10300
754 ::Recordings.DelByName(recording->FileName());
774 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
779 int VompClientRRProc::processMoveRecording()
781 log->log("RRProc", Log::DEBUG, "Process move recording");
782 char* fileName = (char*)req->data;
783 char* newPath = NULL;
785 for (UINT k = 0; k < req->dataLength; k++)
787 if (req->data[k] == '\0')
789 newPath = (char*)&req->data[k+1];
793 if (!newPath) return 0;
795 cRecordings Recordings;
796 Recordings.Load(); // probably have to do this
798 cRecording* recording = Recordings.GetByName((char*)fileName);
800 log->log("RRProc", Log::DEBUG, "recording pointer %p", recording);
804 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
807 log->log("RRProc", Log::DEBUG, "moving recording: %s", recording->Name());
808 log->log("RRProc", Log::DEBUG, "moving recording: %s", recording->FileName());
809 log->log("RRProc", Log::DEBUG, "to: %s", newPath);
811 const char* t = recording->FileName();
813 char* dateDirName = NULL; int k;
814 char* titleDirName = NULL; int j;
816 // Find the datedirname
817 for(k = strlen(t) - 1; k >= 0; k--)
821 log->log("RRProc", Log::DEBUG, "l1: %i", strlen(&t[k+1]) + 1);
822 dateDirName = new char[strlen(&t[k+1]) + 1];
823 strcpy(dateDirName, &t[k+1]);
828 // Find the titledirname
830 for(j = k-1; j >= 0; j--)
834 log->log("RRProc", Log::DEBUG, "l2: %i", (k - j - 1) + 1);
835 titleDirName = new char[(k - j - 1) + 1];
836 memcpy(titleDirName, &t[j+1], k - j - 1);
837 titleDirName[k - j - 1] = '\0';
842 log->log("RRProc", Log::DEBUG, "datedirname: %s", dateDirName);
843 log->log("RRProc", Log::DEBUG, "titledirname: %s", titleDirName);
844 #if APIVERSNUM > 20101
845 log->log("RRProc", Log::DEBUG, "viddir: %s", cVideoDirectory::Name());
847 log->log("RRProc", Log::DEBUG, "viddir: %s", VideoDirectory);
850 char* newPathConv = new char[strlen(newPath)+1];
851 strcpy(newPathConv, newPath);
852 ExchangeChars(newPathConv, true);
853 log->log("RRProc", Log::DEBUG, "EC: %s", newPathConv);
855 #if APIVERSNUM > 20101
856 char* newContainer = new char[strlen(cVideoDirectory::Name()) + strlen(newPathConv) + strlen(titleDirName) + 1];
857 log->log("RRProc", Log::DEBUG, "l10: %i", strlen(cVideoDirectory::Name()) + strlen(newPathConv) + strlen(titleDirName) + 1);
858 sprintf(newContainer, "%s%s%s", cVideoDirectory::Name(), newPathConv, titleDirName);
860 char* newContainer = new char[strlen(VideoDirectory) + strlen(newPathConv) + strlen(titleDirName) + 1];
861 log->log("RRProc", Log::DEBUG, "l10: %i", strlen(VideoDirectory) + strlen(newPathConv) + strlen(titleDirName) + 1);
862 sprintf(newContainer, "%s%s%s", VideoDirectory, newPathConv, titleDirName);
864 delete[] newPathConv;
866 log->log("RRProc", Log::DEBUG, "%s", newContainer);
869 int statret = stat(newContainer, &dstat);
870 if ((statret == -1) && (errno == ENOENT)) // Dir does not exist
872 log->log("RRProc", Log::DEBUG, "new dir does not exist");
873 int mkdirret = mkdir(newContainer, 0755);
876 delete[] dateDirName;
877 delete[] titleDirName;
878 delete[] newContainer;
882 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
886 else if ((statret == 0) && (! (dstat.st_mode && S_IFDIR))) // Something exists but it's not a dir
888 delete[] dateDirName;
889 delete[] titleDirName;
890 delete[] newContainer;
894 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
898 // Ok, the directory container has been made, or it pre-existed.
900 char* newDir = new char[strlen(newContainer) + 1 + strlen(dateDirName) + 1];
901 sprintf(newDir, "%s/%s", newContainer, dateDirName);
903 log->log("RRProc", Log::DEBUG, "doing rename '%s' '%s'", t, newDir);
904 int renameret = rename(t, newDir);
907 // Success. Test for remove old dir containter
908 char* oldTitleDir = new char[k+1];
909 memcpy(oldTitleDir, t, k);
910 oldTitleDir[k] = '\0';
911 log->log("RRProc", Log::DEBUG, "len: %i, cp: %i, strlen: %i, oldtitledir: %s", k+1, k, strlen(oldTitleDir), oldTitleDir);
912 rmdir(oldTitleDir); // can't do anything about a fail result at this point.
913 delete[] oldTitleDir;
918 #if VDRVERSNUM > 10311
920 ::Recordings.Update();
922 // Success. Send a different packet from just a ulong
923 resp->addULONG(1); // success
924 resp->addString(newDir); //system depent do not convert
932 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
934 delete[] dateDirName;
935 delete[] titleDirName;
936 delete[] newContainer;
943 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
950 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
956 int VompClientRRProc::processGetChannelsList()
960 char* chanConfig = x.config.getValueString("General", "Channels");
962 if (chanConfig) allChans = strcasecmp(chanConfig, "FTA only");
964 for (cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel))
966 #if VDRVERSNUM < 10300
967 if (!channel->GroupSep() && (!channel->Ca() || allChans))
969 if (!channel->GroupSep() && (!channel->Ca(0) || allChans))
972 log->log("RRProc", Log::DEBUG, "name: '%s'", channel->Name());
974 if (channel->Vpid()) type = 1;
975 #if VDRVERSNUM < 10300
978 else if (channel->Apid(0)) type = 2;
982 resp->addULONG(channel->Number());
983 resp->addULONG(type);
984 resp->addString(x.charconvsys->Convert(channel->Name()));
985 #if VDRVERSNUM < 10703
988 resp->addULONG(channel->Vtype());
994 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
996 log->log("RRProc", Log::DEBUG, "Written channels list");
1001 int VompClientRRProc::processGetChannelPids()
1003 ULONG channelNumber = ntohl(*(ULONG*)req->data);
1005 cChannel* channel = x.channelFromNumber(channelNumber);
1010 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1019 #if VDRVERSNUM < 10300
1021 log->log("RRProc", Log::DEBUG, "Apid1: %i", channel->Apid1());
1022 log->log("RRProc", Log::DEBUG, "Apid2: %i", channel->Apid2());
1024 if (channel->Apid2())
1026 else if (channel->Apid1())
1033 for (const int *Apid = channel->Apids(); *Apid; Apid++)
1037 for (const int *Dpid = channel->Dpids(); *Dpid; Dpid++)
1041 for (const int *Spid = channel->Spids(); *Spid; Spid++)
1048 // Format of response
1067 resp->addULONG(channel->Vpid());
1068 #if VDRVERSNUM < 10703
1071 resp->addULONG(channel->Vtype());
1073 resp->addULONG(numApids);
1075 #if VDRVERSNUM < 10300
1078 resp->addULONG(channel->Apid1());
1079 resp->addString("");
1083 resp->addULONG(channel->Apid2());
1084 resp->addString("");
1089 for (ULONG i = 0; i < numApids; i++)
1091 resp->addULONG(channel->Apid(i));
1092 resp->addString(x.charconvsys->Convert(channel->Alang(i)));
1094 resp->addULONG(numDpids);
1095 for (ULONG i = 0; i < numDpids; i++)
1097 resp->addULONG(channel->Dpid(i));
1098 resp->addString(x.charconvsys->Convert(channel->Dlang(i)));
1100 resp->addULONG(numSpids);
1101 for (ULONG i = 0; i < numSpids; i++)
1103 resp->addULONG(channel->Spid(i));
1104 resp->addString(x.charconvsys->Convert(channel->Slang(i)));
1107 resp->addULONG(channel->Tpid());
1108 // Format of extended response, for compatibility with older client at the end
1120 #if VDRVERSNUM < 10300
1130 for (ULONG i = 0; i < numApids; i++)
1132 #if VDRVERSNUM < 10715
1135 resp->addULONG(channel->Atype(i));
1138 for (ULONG i = 0; i < numDpids; i++)
1140 #if VDRVERSNUM < 10715
1141 resp->addULONG(0x6A /*AC3*/);
1143 resp->addULONG(channel->Dtype(i));
1146 for (ULONG i = 0; i < numSpids; i++)
1148 #if VDRVERSNUM < 10715
1153 resp->addULONG(channel->SubtitlingType(i));
1154 resp->addULONG(channel->CompositionPageId(i));
1155 resp->addULONG(channel->AncillaryPageId(i));
1162 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1164 log->log("RRProc", Log::DEBUG, "Written channels pids");
1169 int VompClientRRProc::processStartStreamingChannel()
1173 log->log("RRProc", Log::ERR, "Client called start streaming twice");
1177 log->log("RRProc", Log::DEBUG, "req->dataLength = %i", req->dataLength);
1178 ULONG channelNumber = ntohl(*(ULONG*)req->data);
1180 cChannel* channel = x.channelFromNumber(channelNumber);
1185 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1189 // get the priority we should use
1191 int priority = x.config.getValueLong("General", "Live priority", &fail);
1194 log->log("RRProc", Log::DEBUG, "Config: Live TV priority: %i", priority);
1198 log->log("RRProc", Log::DEBUG, "Config: Live TV priority config fail");
1202 // a bit of sanity..
1203 #if VDRVERSNUM < 10725
1204 if (priority < 0) priority = 0;
1206 if (priority < -99) priority = -99;
1208 if (priority > 99) priority = 99;
1210 log->log("RRProc", Log::DEBUG, "Using live TV priority %i", priority);
1211 x.lp = MVPReceiver::create(channel, priority);
1217 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1221 if (!x.lp->init(&x.tcp, req->requestID))
1227 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1233 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1237 int VompClientRRProc::processStopStreaming()
1239 log->log("RRProc", Log::DEBUG, "STOP STREAMING RECEIVED");
1242 x.lp->detachMVPReceiver();
1246 else if (x.recplayer)
1248 x.writeResumeData();
1251 delete x.recordingManager;
1253 x.recordingManager = NULL;
1258 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1262 int VompClientRRProc::processGetBlock()
1266 log->log("RRProc", Log::ERR, "Get block called during live streaming");
1272 log->log("RRProc", Log::ERR, "Get block called when no recording open");
1276 UCHAR* data = req->data;
1278 ULLONG position = x.ntohll(*(ULLONG*)data);
1279 data += sizeof(ULLONG);
1280 ULONG amount = ntohl(*(ULONG*)data);
1282 log->log("RRProc", Log::DEBUG, "getblock pos = %llu length = %lu", position, amount);
1284 UCHAR sendBuffer[amount];
1285 ULONG amountReceived = x.recplayer->getBlock(&sendBuffer[0], position, amount);
1287 if (!amountReceived)
1290 log->log("RRProc", Log::DEBUG, "written 4(0) as getblock got 0");
1294 resp->copyin(sendBuffer, amountReceived);
1295 log->log("RRProc", Log::DEBUG, "written %lu", amountReceived);
1299 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1300 log->log("RRProc", Log::DEBUG, "Finished getblock, have sent %lu", resp->getLen());
1304 int VompClientRRProc::processStartStreamingRecording()
1306 // data is a pointer to the fileName string
1308 x.recordingManager = new cRecordings;
1309 x.recordingManager->Load();
1311 cRecording* recording = x.recordingManager->GetByName((char*)req->data);
1313 log->log("RRProc", Log::DEBUG, "recording pointer %p", recording);
1317 x.recplayer = new RecPlayer(recording);
1319 resp->addULLONG(x.recplayer->getLengthBytes());
1320 resp->addULONG(x.recplayer->getLengthFrames());
1322 #if VDRVERSNUM < 10703
1323 resp->addUCHAR(true);//added for TS
1325 resp->addUCHAR(recording->IsPesRecording());//added for TS
1329 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1331 log->log("RRProc", Log::DEBUG, "written totalLength");
1335 delete x.recordingManager;
1336 x.recordingManager = NULL;
1341 int VompClientRRProc::processPositionFromFrameNumber()
1345 ULONG frameNumber = ntohl(*(ULONG*)req->data);
1349 log->log("RRProc", Log::DEBUG, "Rescan recording called when no recording being played!");
1353 retval = x.recplayer->positionFromFrameNumber(frameNumber);
1356 resp->addULLONG(retval);
1358 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1360 log->log("RRProc", Log::DEBUG, "Wrote posFromFrameNum reply to client");
1364 int VompClientRRProc::processFrameNumberFromPosition()
1368 ULLONG position = x.ntohll(*(ULLONG*)req->data);
1372 log->log("RRProc", Log::DEBUG, "Rescan recording called when no recording being played!");
1376 retval = x.recplayer->frameNumberFromPosition(position);
1379 resp->addULONG(retval);
1381 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1383 log->log("RRProc", Log::DEBUG, "Wrote frameNumFromPos reply to client");
1387 int VompClientRRProc::processGetIFrame()
1389 bool success = false;
1391 ULONG* data = (ULONG*)req->data;
1393 ULONG frameNumber = ntohl(*data);
1395 ULONG direction = ntohl(*data);
1397 ULLONG rfilePosition = 0;
1398 ULONG rframeNumber = 0;
1399 ULONG rframeLength = 0;
1403 log->log("RRProc", Log::DEBUG, "GetIFrame recording called when no recording being played!");
1407 success = x.recplayer->getNextIFrame(frameNumber, direction, &rfilePosition, &rframeNumber, &rframeLength);
1410 // returns file position, frame number, length
1414 resp->addULLONG(rfilePosition);
1415 resp->addULONG(rframeNumber);
1416 resp->addULONG(rframeLength);
1424 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1426 log->log("RRProc", Log::DEBUG, "Wrote GNIF reply to client %llu %lu %lu", rfilePosition, rframeNumber, rframeLength);
1430 int VompClientRRProc::processGetChannelSchedule()
1432 ULONG* data = (ULONG*)req->data;
1434 ULONG channelNumber = ntohl(*data);
1436 ULONG startTime = ntohl(*data);
1438 ULONG duration = ntohl(*data);
1440 log->log("RRProc", Log::DEBUG, "get schedule called for channel %lu", channelNumber);
1442 cChannel* channel = x.channelFromNumber(channelNumber);
1447 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1449 log->log("RRProc", Log::DEBUG, "written 0 because channel = NULL");
1453 log->log("RRProc", Log::DEBUG, "Got channel");
1455 #if VDRVERSNUM < 10300
1456 cMutexLock MutexLock;
1457 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
1459 cSchedulesLock MutexLock;
1460 const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
1466 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1468 log->log("RRProc", Log::DEBUG, "written 0 because Schedule!s! = NULL");
1472 log->log("RRProc", Log::DEBUG, "Got schedule!s! object");
1474 const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
1479 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1481 log->log("RRProc", Log::DEBUG, "written 0 because Schedule = NULL");
1485 log->log("RRProc", Log::DEBUG, "Got schedule object");
1487 const char* empty = "";
1488 bool atLeastOneEvent = false;
1491 ULONG thisEventTime;
1492 ULONG thisEventDuration;
1493 const char* thisEventTitle;
1494 const char* thisEventSubTitle;
1495 const char* thisEventDescription;
1497 #if VDRVERSNUM < 10300
1499 const cEventInfo *event;
1500 for (int eventNumber = 0; eventNumber < Schedule->NumEvents(); eventNumber++)
1502 event = Schedule->GetEventNumber(eventNumber);
1504 thisEventID = event->GetEventID();
1505 thisEventTime = event->GetTime();
1506 thisEventDuration = event->GetDuration();
1507 thisEventTitle = event->GetTitle();
1508 thisEventSubTitle = event->GetSubtitle();
1509 thisEventDescription = event->GetExtendedDescription();
1513 for (const cEvent* event = Schedule->Events()->First(); event; event = Schedule->Events()->Next(event))
1515 thisEventID = event->EventID();
1516 thisEventTime = event->StartTime();
1517 thisEventDuration = event->Duration();
1518 thisEventTitle = event->Title();
1519 thisEventSubTitle = NULL;
1520 thisEventDescription = event->Description();
1524 //in the past filter
1525 if ((thisEventTime + thisEventDuration) < (ULONG)time(NULL)) continue;
1528 if ((thisEventTime + thisEventDuration) <= startTime) continue;
1531 if (thisEventTime >= (startTime + duration)) continue;
1533 if (!thisEventTitle) thisEventTitle = empty;
1534 if (!thisEventSubTitle) thisEventSubTitle = empty;
1535 if (!thisEventDescription) thisEventDescription = empty;
1537 resp->addULONG(thisEventID);
1538 resp->addULONG(thisEventTime);
1539 resp->addULONG(thisEventDuration);
1541 resp->addString(x.charconvsys->Convert(thisEventTitle));
1542 resp->addString(x.charconvsys->Convert(thisEventSubTitle));
1543 resp->addString(x.charconvsys->Convert(thisEventDescription));
1545 atLeastOneEvent = true;
1548 log->log("RRProc", Log::DEBUG, "Got all event data");
1550 if (!atLeastOneEvent)
1553 log->log("RRProc", Log::DEBUG, "Written 0 because no data");
1557 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1559 log->log("RRProc", Log::DEBUG, "written schedules packet");
1564 int VompClientRRProc::processGetTimers()
1567 int numTimers = Timers.Count();
1569 resp->addULONG(numTimers);
1571 for (int i = 0; i < numTimers; i++)
1573 timer = Timers.Get(i);
1575 #if VDRVERSNUM < 10300
1576 resp->addULONG(timer->Active());
1578 resp->addULONG(timer->HasFlags(tfActive));
1580 resp->addULONG(timer->Recording());
1581 resp->addULONG(timer->Pending());
1582 resp->addULONG(timer->Priority());
1583 resp->addULONG(timer->Lifetime());
1584 resp->addULONG(timer->Channel()->Number());
1585 resp->addULONG(timer->StartTime());
1586 resp->addULONG(timer->StopTime());
1587 resp->addULONG(timer->Day());
1588 resp->addULONG(timer->WeekDays());
1589 resp->addString(timer->File()); //Filename is system specific and not visible by user
1593 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1595 log->log("RRProc", Log::DEBUG, "Written timers list");
1600 int VompClientRRProc::processSetTimer()
1602 char* timerString = new char[strlen((char*)req->data) + 1];
1603 strcpy(timerString, (char*)req->data);
1605 #if VDRVERSNUM < 10300
1607 // If this is VDR 1.2 the date part of the timer string must be reduced
1608 // to just DD rather than YYYY-MM-DD
1610 int s = 0; // source
1611 int d = 0; // destination
1613 while(c != 2) // copy up to date section, including the second ':'
1615 timerString[d] = req->data[s];
1616 if (req->data[s] == ':') c++;
1620 // now it has copied up to the date section
1622 while(c != 2) // waste YYYY-MM-
1624 if (req->data[s] == '-') c++;
1627 // now source is at the DD
1628 memcpy(&timerString[d], &req->data[s], req->dataLength - s);
1629 d += req->dataLength - s;
1630 timerString[d] = '\0';
1632 log->log("RRProc", Log::DEBUG, "Timer string after 1.2 conversion:");
1635 log->log("RRProc", Log::DEBUG, "%s", timerString);
1637 cTimer *timer = new cTimer;
1638 if (timer->Parse((char*)timerString))
1640 cTimer *t = Timers.GetTimer(timer);
1644 #if VDRVERSNUM < 10300
1647 Timers.SetModified();
1651 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1652 return 1; // FIXME - cTimer* timer is leaked here!
1658 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1665 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1671 int VompClientRRProc::processDeleteTimer()
1673 log->log("RRProc", Log::DEBUG, "Delete timer called");
1678 INT delChannel = ntohl(*(ULONG*)&req->data[position]); position += 4;
1679 INT delWeekdays = ntohl(*(ULONG*)&req->data[position]); position += 4;
1680 INT delDay = ntohl(*(ULONG*)&req->data[position]); position += 4;
1681 INT delStart = ntohl(*(ULONG*)&req->data[position]); position += 4;
1682 INT delStop = ntohl(*(ULONG*)&req->data[position]); position += 4;
1685 for (ti = Timers.First(); ti; ti = Timers.Next(ti))
1687 if ( (ti->Channel()->Number() == delChannel)
1688 && ((ti->WeekDays() && (ti->WeekDays() == delWeekdays)) || (!ti->WeekDays() && (ti->Day() == delDay)))
1689 && (ti->StartTime() == delStart)
1690 && (ti->StopTime() == delStop) )
1698 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1702 if (!Timers.BeingEdited())
1704 if (!ti->Recording())
1707 Timers.SetModified();
1710 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1715 log->log("RRProc", Log::ERR, "Unable to delete timer - timer is running");
1718 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1724 log->log("RRProc", Log::ERR, "Unable to delete timer - timers being edited at VDR");
1727 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1732 int VompClientRRProc::processGetRecInfo()
1734 // data is a pointer to the fileName string
1736 cRecordings Recordings;
1737 Recordings.Load(); // probably have to do this
1739 cRecording *recording = Recordings.GetByName((char*)req->data);
1741 time_t timerStart = 0;
1742 time_t timerStop = 0;
1743 char* summary = NULL;
1744 char* shorttext = NULL;
1745 char* description = NULL;
1747 bool newsummary=false;
1748 ULONG resumePoint = 0;
1752 log->log("RRProc", Log::ERR, "GetRecInfo found no recording");
1755 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1760 4 bytes: start time for timer
1761 4 bytes: end time for timer
1762 4 bytes: resume point
1764 4 bytes: num components
1771 8 bytes: frames per second
1774 // Get current timer
1776 cRecordControl *rc = cRecordControls::GetRecordControl(recording->FileName());
1779 timerStart = rc->Timer()->StartTime();
1780 timerStop = rc->Timer()->StopTime();
1781 log->log("RRProc", Log::DEBUG, "GRI: RC: %lu %lu", timerStart, timerStop);
1784 resp->addULONG(timerStart);
1785 resp->addULONG(timerStop);
1789 /* char* value = x.config.getValueString("ResumeData", (char*)req->data);
1792 resumePoint = strtoul(value, NULL, 10);
1796 char* ResumeIdC = x.config.getValueString("General", "ResumeId");
1799 ResumeId = atoi(ResumeIdC);
1803 ResumeId = 0; //default if not defined in vomp-MAC.conf
1805 while (ResumeIDLock)
1806 cCondWait::SleepMs(100);
1807 ResumeIDLock = true;
1808 int OldSetupResumeID = Setup.ResumeID;
1809 Setup.ResumeID = ResumeId; //UGLY: quickly change resumeid
1810 #if VDRVERSNUM < 10703
1811 cResumeFile ResumeFile(recording->FileName()); //get corresponding resume file
1813 cResumeFile ResumeFile(recording->FileName(), recording->IsPesRecording()); //get corresponding resume file
1815 Setup.ResumeID = OldSetupResumeID; //and restore it back
1816 ResumeIDLock = false;
1818 int resume = ResumeFile.Read();
1819 //isyslog("VOMPDEBUG: resumePoint = %i, resume = %i, ResumeId = %i",resumePoint, resume, ResumeId);
1821 resumePoint = ResumeFile.Read();
1823 log->log("RRProc", Log::DEBUG, "GRI: RP: %lu", resumePoint);
1825 resp->addULONG(resumePoint);
1829 #if VDRVERSNUM < 10300
1830 summary = (char*)recording->Summary();
1832 const cRecordingInfo *Info = recording->Info();
1833 shorttext = (char*)Info->ShortText();
1834 description = (char*) (char*)Info->Description();
1835 if (isempty(shorttext)) summary=description;
1836 else if (isempty(description)) summary=shorttext;
1838 int length=strlen(description)+strlen(shorttext)+4;
1839 summary=new char[length];
1840 snprintf(summary,length,"%s\n\n%s",shorttext,description);
1844 if (isempty(summary)) summary = (char*)Info->Description();
1846 log->log("RRProc", Log::DEBUG, "GRI: S: %s", summary);
1849 resp->addString(x.charconvsys->Convert(summary));
1850 if (newsummary) delete [] summary;
1854 resp->addString("");
1859 #if VDRVERSNUM < 10300
1861 // Send 0 for numchannels - this signals the client this info is not available
1865 const cComponents* components = Info->Components();
1867 log->log("RRProc", Log::DEBUG, "GRI: D1: %p", components);
1875 resp->addULONG(components->NumComponents());
1877 tComponent* component;
1878 for (int i = 0; i < components->NumComponents(); i++)
1880 component = components->Component(i);
1882 log->log("RRProc", Log::DEBUG, "GRI: C: %i %u %u %s %s", i, component->stream, component->type, component->language, component->description);
1884 resp->addUCHAR(component->stream);
1885 resp->addUCHAR(component->type);
1887 if (component->language)
1889 resp->addString(x.charconvsys->Convert(component->language));
1893 resp->addString("");
1895 if (component->description)
1897 resp->addString(x.charconvsys->Convert(component->description));
1901 resp->addString("");
1907 double framespersec;
1908 #if VDRVERSNUM < 10703
1909 framespersec = FRAMESPERSEC;
1911 framespersec = Info->FramesPerSecond();
1913 resp->adddouble(framespersec);
1914 title = (char*)Info->Title();
1917 resp->addString(x.charconvsys->Convert(title));
1921 resp->addString(x.charconvsys->Convert(recording->Name()));
1927 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1929 log->log("RRProc", Log::DEBUG, "Written getrecinfo");
1939 int VompClientRRProc::processReScanRecording()
1943 log->log("RRProc", Log::DEBUG, "Rescan recording called when no recording being played!");
1947 x.recplayer->scan();
1949 resp->addULLONG(x.recplayer->getLengthBytes());
1950 resp->addULONG(x.recplayer->getLengthFrames());
1952 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
1953 log->log("RRProc", Log::DEBUG, "Rescan recording, wrote new length to client");
1957 // FIXME without client calling rescan, getblock wont work even tho more data is avail
1959 int VompClientRRProc::processGetMarks()
1961 // data is a pointer to the fileName string
1964 cRecordings Recordings;
1965 Recordings.Load(); // probably have to do this
1967 cRecording *recording = Recordings.GetByName((char*)req->data);
1969 log->log("RRProc", Log::DEBUG, "recording pointer %p", recording);
1973 #if VDRVERSNUM < 10703
1974 Marks.Load(recording->FileName());
1976 Marks.Load(recording->FileName(), recording->FramesPerSecond(), recording->IsPesRecording());
1980 for (const cMark *m = Marks.First(); m; m = Marks.Next(m))
1982 #if VDRVERSNUM < 10721
1983 ULLONG mposition = m->position;
1985 ULLONG mposition = m->Position();
1987 log->log("RRProc", Log::DEBUG, "found Mark %i", mposition);
1989 resp->addULONG(mposition);
1994 log->log("RRProc", Log::DEBUG, "no marks found, sending 0-mark");
2000 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
2002 log->log("RRProc", Log::DEBUG, "Written Marks list");
2007 int VompClientRRProc::processVDRShutdown()
2009 log->log("RRProc", Log::DEBUG, "Trying to shutdown VDR");
2010 VompClient::decClients(); // Temporarily make this client disappear
2011 cRemote::Put(kPower);
2012 VompClient::incClients();
2014 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
2018 int VompClientRRProc::processGetRecScraperEventType()
2020 Recordings.Load(); // probably have to do this
2022 cRecording *recording = Recordings.GetByName((char*)req->data);
2023 ScraperGetEventType call;
2026 if (recording && x.scrapQuery())
2028 call.recording = recording;
2029 x.scraper->Service("GetEventType",&call);
2031 resp->addUCHAR(call.type);
2032 if (call.type == tMovie)
2034 resp->addLONG(call.movieId);
2035 } else if (call.type == tSeries){
2036 resp->addLONG(call.seriesId);
2037 resp->addLONG(call.episodeId);
2040 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
2045 int VompClientRRProc::processGetEventScraperEventType()
2047 ScraperGetEventType call;
2049 ULONG channelid = ntohl(*(ULONG*)req->data);
2050 ULONG eventid = ntohl(*(ULONG*)(req->data+4));
2051 const cEvent *event = NULL;
2053 cChannel* channel = x.channelFromNumber(channelid);
2055 #if VDRVERSNUM < 10300
2056 cMutexLock MutexLock;
2057 const cSchedules *Schedules = cSIProcessor::Schedules(MutexLock);
2059 cSchedulesLock MutexLock;
2060 const cSchedules *Schedules = cSchedules::Schedules(MutexLock);
2062 const cSchedule * Schedule;
2063 if (Schedules && channel)
2065 const cSchedule *Schedule = Schedules->GetSchedule(channel->GetChannelID());
2067 event = Schedule->GetEvent(eventid);
2071 if (event && x.scrapQuery())
2074 x.scraper->Service("GetEventType",&call);
2076 resp->addUCHAR(call.type);
2077 if (call.type == tMovie)
2079 resp->addLONG(call.movieId);
2080 } else if (call.type == tSeries){
2081 resp->addLONG(call.seriesId);
2082 resp->addLONG(call.episodeId);
2084 if (x.pict->epgImageExists(eventid)) {
2091 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
2096 #define ADDSTRING_TO_PAKET(y) if ((y)!=0) resp->addString(x.charconvutf8->Convert(y)); else resp->addString("");
2098 int VompClientRRProc::processGetScraperMovieInfo()
2102 movie.movieId = ntohl(*(ULONG*)req->data);
2103 if (!x.scrapQuery()) {
2104 log->log("RRProc", Log::DEBUG, "No Scraper, get SeriesInfo");
2105 return 0; //stupid, I have no scraper why are you still asking
2107 x.scraper->Service("GetMovie",&movie);
2110 ADDSTRING_TO_PAKET(movie.title.c_str());
2111 ADDSTRING_TO_PAKET(movie.originalTitle.c_str());
2112 ADDSTRING_TO_PAKET(movie.tagline.c_str());
2113 ADDSTRING_TO_PAKET(movie.overview.c_str());
2114 resp->addUCHAR(movie.adult);
2115 ADDSTRING_TO_PAKET(movie.collectionName.c_str());
2117 resp->addLONG(movie.budget);
2118 resp->addLONG(movie.revenue);
2119 ADDSTRING_TO_PAKET(movie.genres.c_str());
2120 ADDSTRING_TO_PAKET(movie.homepage.c_str());
2121 ADDSTRING_TO_PAKET(movie.releaseDate.c_str());
2122 resp->addLONG(movie.runtime);
2123 resp->adddouble(movie.popularity);
2124 resp->adddouble(movie.voteAverage);
2125 resp->addULONG(movie.poster.width);
2126 resp->addULONG(movie.poster.height);
2127 resp->addULONG(movie.fanart.width);
2128 resp->addULONG(movie.fanart.height);
2129 resp->addULONG(movie.collectionPoster.width);
2130 resp->addULONG(movie.collectionPoster.height);
2131 resp->addULONG(movie.collectionFanart.width);
2132 resp->addULONG(movie.collectionFanart.height);
2133 resp->addULONG(movie.actors.size());
2134 for (ULONG acty=0; acty < movie.actors.size(); acty++) {
2135 ADDSTRING_TO_PAKET(movie.actors[acty].name.c_str());
2136 ADDSTRING_TO_PAKET(movie.actors[acty].role.c_str());
2137 resp->addULONG(movie.actors[acty].actorThumb.width);
2138 resp->addULONG(movie.actors[acty].actorThumb.height);
2142 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
2149 int VompClientRRProc::processGetScraperSeriesInfo()
2152 series.seriesId = ntohl(*(ULONG*)req->data);
2153 series.episodeId = ntohl(*(ULONG*)(req->data+4));
2154 if (!x.scrapQuery()) {
2155 log->log("RRProc", Log::DEBUG, "No Scraper, get SeriesInfo");
2156 return 0; //stupid, I have no scraper why are you still asking
2158 x.scraper->Service("GetSeries",&series);
2160 ADDSTRING_TO_PAKET(series.name.c_str());
2161 ADDSTRING_TO_PAKET(series.overview.c_str());
2162 ADDSTRING_TO_PAKET(series.firstAired.c_str());
2163 ADDSTRING_TO_PAKET(series.network.c_str());
2164 ADDSTRING_TO_PAKET(series.genre.c_str());
2165 resp->adddouble(series.rating);
2166 ADDSTRING_TO_PAKET(series.status.c_str());
2168 resp->addLONG(series.episode.number);
2169 resp->addLONG(series.episode.season);
2170 ADDSTRING_TO_PAKET(series.episode.name.c_str());
2171 ADDSTRING_TO_PAKET(series.episode.firstAired.c_str());
2172 ADDSTRING_TO_PAKET(series.episode.guestStars.c_str());
2173 ADDSTRING_TO_PAKET(series.episode.overview.c_str());
2174 resp->adddouble(series.episode.rating);
2175 resp->addULONG(series.episode.episodeImage.width);
2176 resp->addULONG(series.episode.episodeImage.height);
2178 ULONG num_actors = series.actors.size();
2179 resp->addULONG(num_actors);
2180 for (ULONG acty=0; acty < num_actors; acty++) {
2181 ADDSTRING_TO_PAKET(series.actors[acty].name.c_str());
2182 ADDSTRING_TO_PAKET(series.actors[acty].role.c_str());
2183 resp->addULONG(series.actors[acty].actorThumb.width);
2184 resp->addULONG(series.actors[acty].actorThumb.height);
2186 ULONG num_posters = series.posters.size();
2187 resp->addULONG(num_posters);
2188 for (ULONG medias = 0; medias < num_posters; medias++ ) {
2189 cTvMedia media=series.posters[medias];
2190 resp->addULONG(media.width);
2191 resp->addULONG(media.height);
2194 ULONG num_banners = series.banners.size();
2195 resp->addULONG(num_banners);
2196 for (ULONG medias = 0; medias < num_banners; medias++ ) {
2197 cTvMedia media=series.banners[medias];
2198 resp->addULONG(media.width);
2199 resp->addULONG(media.height);
2201 ULONG num_fanarts = series.fanarts.size();
2202 resp->addULONG(num_fanarts);
2203 for (ULONG medias = 0; medias < num_fanarts; medias++ ) {
2204 cTvMedia media=series.fanarts[medias];
2205 resp->addULONG(media.width);
2206 resp->addULONG(media.height);
2208 resp->addULONG(series.seasonPoster.width);
2209 resp->addULONG(series.seasonPoster.height);
2213 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
2218 int VompClientRRProc::processLoadTvMedia()
2220 TVMediaRequest tvreq;
2221 tvreq.streamID = req->requestID;
2222 tvreq.type = ntohl(*(ULONG*)req->data);
2223 tvreq.primary_id = ntohl(*(ULONG*)(req->data+4));
2224 tvreq.secondary_id = ntohl(*(ULONG*)(req->data+8));
2225 tvreq.type_pict = ntohl(*(ULONG*)(req->data+12));
2226 tvreq.container = ntohl(*(ULONG*)(req->data+16));
2227 tvreq.container_member = ntohl(*(ULONG*)(req->data+20));
2228 log->log("RRProc", Log::DEBUG, "TVMedia request %d",req->requestID);
2229 x.pict->addTVMediaRequest(tvreq);
2234 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
2239 int VompClientRRProc::processLoadTvMediaRecThumb()
2241 TVMediaRequest tvreq;
2242 tvreq.streamID = req->requestID;
2243 tvreq.type = 3; // unknown but primary_name is set
2244 tvreq.primary_id = 0;
2245 tvreq.primary_name = std::string((const char*) req->data);
2246 tvreq.secondary_id = 0;
2247 tvreq.type_pict = 1;
2248 tvreq.container = 0;
2249 tvreq.container_member = 0;
2250 log->log("RRProc", Log::DEBUG, "TVMedia request %d %s",req->requestID,req->data);
2251 x.pict->addTVMediaRequest(tvreq);
2256 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
2261 int VompClientRRProc::processLoadTvMediaEventThumb()
2263 TVMediaRequest tvreq;
2264 tvreq.streamID = req->requestID;
2265 tvreq.type = 4; // unknown but primary_id is set
2266 UINT channelid = ntohl(*(ULONG*)req->data);
2267 tvreq.primary_id = ntohl(*(ULONG*)(req->data+4));
2268 tvreq.secondary_id = 0;
2269 cChannel* channel = x.channelFromNumber(channelid);
2271 if (channel) tvreq.primary_name = std::string((const char*)channel->GetChannelID().ToString());
2272 tvreq.type_pict = 1;
2273 tvreq.container = 0;
2274 tvreq.container_member = 0;
2275 log->log("RRProc", Log::DEBUG, "TVMedia request %d %s",req->requestID,req->data);
2276 x.pict->addTVMediaRequest(tvreq);
2281 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
2286 int VompClientRRProc::processLoadChannelLogo()
2288 TVMediaRequest tvreq;
2289 tvreq.streamID = req->requestID;
2290 tvreq.type = 5; // channel logo
2291 UINT channelid = ntohl(*(ULONG*)req->data);
2292 tvreq.primary_id = channelid;
2293 tvreq.secondary_id = 0;
2294 cChannel* channel = x.channelFromNumber(channelid);
2296 if (channel) tvreq.primary_name = std::string((const char*)channel->Name());
2297 tvreq.type_pict = 1;
2298 tvreq.container = 0;
2299 tvreq.container_member = 0;
2300 log->log("RRProc", Log::DEBUG, "TVMedia request %d %d %s",req->requestID,channelid, channel->Name());
2301 x.pict->addTVMediaRequest(tvreq);
2306 x.tcp.sendPacket(resp->getPtr(), resp->getLen());
2315 #endif // !VOMPSTANDALONE