2 Copyright 2004-2019 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, see <https://www.gnu.org/licenses/>.
30 #include "vdrrequestpacket.h"
31 #include "vdrresponsepacket.h"
34 #ifdef VOMP_MEDIAPLAYER
36 #include "mediaprovider.h"
37 #include "mediaproviderids.h"
39 #include "vdrcommand.h"
42 #include "movieinfo.h"
43 #include "seriesinfo.h"
44 #include "osdvector.h"
48 #define VOMP_PROTOCOLL_VERSION 0x00000500
50 VDR* VDR::instance = NULL;
51 #ifdef VOMP_MEDIAPLAYER
53 //will create a request package from a command variable and fill this
54 //caller has to destroy buffer
55 static SerializeBuffer * prepareRequest(VDR_Command *cmd) {
56 SerializeBuffer *buf=new SerializeBuffer(512,false,true);
57 if (cmd->serialize(buf) != 0) {
64 //handle request/response
65 //TODO avoid copy of buffer (needs extension of requestpacket)
66 //TODO avoid command 2x (needs some more restructuring)
67 SerializeBuffer * VDR::doRequestResponse(SerializeBuffer *rq,int cmd) {
68 VDR_RequestPacket *rt=new VDR_RequestPacket;
73 if (! rt->init(cmd,true,rq->getCurrent()-rq->getStart())) {
78 if (! rt->copyin(rq->getStart(),(ULONG)(rq->getCurrent()-rq->getStart()))) {
84 VDR_ResponsePacket *rp=RequestResponse(rt);
85 logger->log("doRequestResponse",Log::DEBUG,"got response %p",rp);
90 SerializeBuffer *buf=new SerializeBuffer(rp->getUserData(),rp->getUserDataLength(),true,true,false);
97 //deserialize a received response
100 static int decodeResponse(SerializeBuffer *rp,VDR_Command *c) {
101 ULONG expected=c->command;
102 if (c->deserialize(rp) != 0) {
104 Log::getInstance()->log("VDR", Log::ERR, "decodeResponse unable to deserialize for command %lu",expected);
108 if (c->command != expected) {
109 Log::getInstance()->log("VDR", Log::ERR, "decodeResponse unexpected response received 0x%lx, expected 0x%lx",c->command,expected);
112 Log::getInstance()->log("VDR", Log::DEBUG, "decodeResponse successfully decoded command 0x%lx",expected);
120 if (instance) return;
126 maxChannelNumber = 0;
127 channelNumberWidth = 1;
128 doVDRShutdown = false;
129 TEMP_SINGLE_VDR_PR = NULL;
130 #ifdef VOMP_MEDIAPLAYER
131 providerId=MPROVIDERID_VDR;
132 subRange=MPROVIDERRANGE_VDR;
133 MediaPlayerRegister::getInstance()->registerMediaProvider(this,MPROVIDERID_VDR,MPROVIDERRANGE_VDR);
140 if (initted) shutdown();
143 VDR* VDR::getInstance()
150 if (initted) return 0;
152 logger = Log::getInstance();
158 if (!initted) return 0;
164 void VDR::findServers(vector<VDRServer>& servers)
166 Wol* wol = Wol::getInstance();
169 memset(message, 0, 15);
170 strcpy(message, "VDP-0001");
171 /*tcp->getMAC(&message[9]); put mac here when TCP modified to do this*/
174 // FIXME Horrible hack. Rewrite all this.
175 // Change away from relying on the dsock select to do the timing
176 // Do timing here and let UDP4 / UDP6 objects/threads just wait
182 DatagramSocket ds(0);
183 int haveAtLeastOne = 0;
186 bool firstloop = true;
193 logger->log("VDR", Log::NOTICE, "Broadcasting for server");
194 ds.send("255.255.255.255", 51051, message, 15);
195 ds.send("255.255.255.255", 51052, message, 15);
196 ds.send("255.255.255.255", 51053, message, 15);
197 ds.send("255.255.255.255", 51054, message, 15);
198 ds.send("255.255.255.255", 51055, message, 15);
199 if(!firstloop) wol->doWakeUp();
201 retval = ds.waitforMessage(waitType);
203 if (retval == 2) // we got a reply
207 char* vdpreply = ds.getData();
208 if ((ds.getDataLength() >= 24) && !strncmp(vdpreply, "VDP-0002", 8))
211 // FIXME upgrade this to look for a return IP in the reply packet
212 newServer.ip = new char[16];
213 strcpy(newServer.ip, ds.getFromIPA());
215 USHORT newServerPort;
216 memcpy(&newServerPort, &vdpreply[26], 2);
217 newServer.port = ntohs(newServerPort);
219 ULONG newServerVersion;
220 memcpy(&newServerVersion, &vdpreply[28], 4);
221 newServer.version = ntohl(newServerVersion);
223 int newServerNameLength = ds.getDataLength() - 32;
224 newServer.name = new char[newServerNameLength];
225 strcpy(newServer.name, &vdpreply[32]);
227 servers.push_back(newServer);
233 if (haveAtLeastOne) break;
235 if (vdp6.numFound()) break;
241 { VDRServer newServer;
242 newServer.ip = new char[16];
243 strcpy(newServer.ip, "192.168.1.7");
244 newServer.name = new char[6];
245 strcpy(newServer.name,"debug");
246 servers.push_back(newServer);
248 haveAtLeastOne = 1;}/ * */
251 logger->log("VDR", Log::NOTICE, "END loop");
255 vector<VDRServer>* servers6 = vdp6.getServers();
257 // Add IPv6 found servers to servers vector, if not in servers already
258 // Free buffers from VDRServer objects if not taken. (Itching for that rewrite already).
260 for(auto i6 = servers6->begin(); i6 != servers6->end(); i6++)
264 for(auto i4 = servers.begin(); i4 != servers.end(); i4++)
266 if (!strcmp(i4->name, i6->name)) { found = true; break; }
276 servers.push_back(*i6);
282 sort(servers.begin(), servers.end(), ServerSorter());
285 void VDR::cancelFindingServer()
290 void VDR::setServerIP(char* newIP)
292 strcpy(serverIP, newIP);
295 void VDR::setServerPort(USHORT newPort)
297 serverPort = newPort;
302 maxChannelNumber = 0;
303 channelNumberWidth = 1;
307 if (tcp->connectTo(serverIP, serverPort))
319 void VDR::disconnect()
325 logger->log("VDR", Log::DEBUG, "Disconnect");
328 void VDR::setReceiveWindow(size_t size)
330 if (connected && size) tcp->setReceiveWindow(size);
333 ///////////////////////////////////////////////////////
335 void VDR::threadMethod()
337 logger->log("VDR", Log::DEBUG, "VDR RUN");
339 threadSetKillable(); // FIXME - change this to deal with the EDRs
344 ULONG userDataLength;
350 VDR_ResponsePacket* vresp;
353 ULONG lastKAsent = 0;
354 ULONG lastKArecv = time(NULL);
359 timeNow = time(NULL);
361 readSuccess = tcp->readData((UCHAR*)&channelID, sizeof(ULONG)); // 2s timeout atm
365 //logger->log("VDR", Log::DEBUG, "Net read timeout");
366 if (!tcp->isConnected()) { connectionDied(); return; } // return to stop this thread
371 if (!lastKAsent) // have not sent a KA
373 if (lastKArecv < (timeNow - 5))
375 logger->log("VDR", Log::DEBUG, "Sending KA packet");
376 if (!sendKA(timeNow))
378 logger->log("VDR", Log::DEBUG, "Could not send KA, calling connectionDied");
382 lastKAsent = timeNow;
387 if (lastKAsent <= (timeNow - 10))
389 logger->log("VDR", Log::DEBUG, "lastKA over 10s ago, calling connectionDied");
395 if (!readSuccess) continue; // no data was read but the connection is ok.
399 channelID = ntohl(channelID);
401 if (channelID == CHANNEL_REQUEST_RESPONSE)
403 if (!tcp->readData((UCHAR*)&requestID, sizeof(ULONG))) break;
404 requestID = ntohl(requestID);
405 if (!tcp->readData((UCHAR*)&userDataLength, sizeof(ULONG))) break;
406 userDataLength = ntohl(userDataLength);
407 if (userDataLength > 5000000) break; // how big can these packets get?
409 if (userDataLength > 0)
411 userData = (UCHAR*)malloc(userDataLength);
412 if (!userData) break;
413 if (!tcp->readData(userData, userDataLength)) break;
416 vresp = new VDR_ResponsePacket();
417 vresp->setResponse(requestID, userData, userDataLength);
418 logger->log("VDR", Log::DEBUG, "Rxd a response packet, requestID=%lu, len=%lu", requestID, userDataLength);
420 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
422 // If edFindAndCall returns true, edr was called and vresp was handed off.
423 // else, delete vresp here.
427 else if (channelID == CHANNEL_STREAM || channelID == CHANNEL_TVMEDIA)
429 if (!tcp->readData((UCHAR*)&streamID, sizeof(ULONG))) break;
430 streamID = ntohl(streamID);
432 if (!tcp->readData((UCHAR*)&flag, sizeof(ULONG))) break;
435 if (!tcp->readData((UCHAR*)&userDataLength, sizeof(ULONG))) break;
436 userDataLength = ntohl(userDataLength);
438 if (userDataLength > 0)
440 userData = (UCHAR*)malloc(userDataLength);
441 if (!userData) break;
442 if (!tcp->readData(userData, userDataLength)) break;
445 vresp = new VDR_ResponsePacket();
446 vresp->setStream(streamID, flag, userData, userDataLength, channelID);
447 //logger->log("VDR", Log::DEBUG, "Rxd a stream packet, streamID=%lu, flag=%lu, len=%lu", streamID, flag, userDataLength);
449 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
451 // If edFindAndCall returns true, edr was called and vresp was handed off.
452 // else, delete vresp here.
456 else if (channelID == CHANNEL_KEEPALIVE)
459 if (!tcp->readData((UCHAR*)&KAreply, sizeof(ULONG))) break;
460 KAreply = (ULONG)ntohl(KAreply);
461 if (KAreply == lastKAsent) // successful KA response
464 lastKArecv = KAreply;
465 logger->log("VDR", Log::DEBUG, "Rxd correct KA reply");
470 logger->log("VDR", Log::ERR, "Rxd a response packet on channel %lu !!", channelID);
476 // Who deletes vresp?
477 // If RR, the individual protocol functions must delete vresp.
478 // If stream, the data and length is taken out in ed_cb_call and vresp is deleted there.
484 void VDR::connectionDied()
486 // Called from within threadMethod to do cleanup if it decides the connection has died
488 connected = false; // though actually it could still be connected until someone calls vdr->disconnect
490 // Need to wake up any waiting channel 1 request-response threads
491 // Normally this is done by a packet coming in with channelid and requestid
492 // Instead, go through the list and for each channel 1 edr, make an empty vresp
493 // An empty vresp will have userData == NULL, which means vresp->noResponse() == true
495 // If it's a stream receiver, generate a stream packet with flag == connection_lost
498 VDR_PacketReceiver* vdrpr;
499 VDR_ResponsePacket* vresp;
500 while(receivers.size())
502 vdrpr = (VDR_PacketReceiver*) *(receivers.begin());
503 if (vdrpr->receiverChannel == CHANNEL_REQUEST_RESPONSE)
505 vresp = new VDR_ResponsePacket();
506 vresp->setResponse(vdrpr->requestSerialNumber, NULL, 0);
507 logger->log("VDR", Log::DEBUG, "Timeouts: created blank response packet for request serial %lu", vdrpr->requestSerialNumber);
509 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
511 // If edFindAndCall returns true, edr was called and vresp was handed off.
512 // else, delete vresp here.
513 logger->log("VDR", Log::ERR, "Timeouts: no waiting thread found for request serial %lu !!!", vdrpr->requestSerialNumber);
518 else if (vdrpr->receiverChannel == CHANNEL_STREAM || vdrpr->receiverChannel == CHANNEL_TVMEDIA)
520 vresp = new VDR_ResponsePacket();
521 vresp->setStream(vdrpr->streamID, 2 /* connection-lost flag */ , NULL, 0, vdrpr->receiverChannel);
522 logger->log("VDR", Log::DEBUG, "Timeouts: created blank response packet for streamid %lu", vdrpr->streamID);
524 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
526 // If edFindAndCall returns true, edr was called and vresp was handed off.
527 // else, delete vresp here.
528 logger->log("VDR", Log::ERR, "Timeouts: no waiting stream receiver found for streamid %lu !!!", vdrpr->streamID);
533 for(EDRL::iterator i = receivers.begin(); i != receivers.end(); i++)
534 if ((VDR_PacketReceiver*)*i == vdrpr) { receivers.erase(i); break; }
538 // Ok, all event receviers should be dealt with. just in case there weren't any, inform command
539 logger->log("VDR", Log::DEBUG, "edUnlock at end of connectionDied");
541 Command::getInstance()->connectionLost();
544 bool VDR::ed_cb_find(EDReceiver* edr, void* userTag)
546 // edr is a VDR_PacketReceiver object made in VDR::RequestResponse
547 // userTag is a VDR_ResponsePacket made in threadMethod
549 VDR_PacketReceiver* vdrpr = (VDR_PacketReceiver*)edr;
550 VDR_ResponsePacket* vresp = (VDR_ResponsePacket*)userTag;
552 // Is vresp for vdrpr ?
554 ULONG packetChannel = vresp->getChannelID();
555 //logger->log("VDR", Log::DEBUG, "TVMedia debug %d %d %x", vdrpr->receiverChannel,packetChannel,vdrpr);
556 if (vdrpr->receiverChannel != packetChannel) return false;
558 if (packetChannel == CHANNEL_REQUEST_RESPONSE)
560 if (vdrpr->requestSerialNumber == vresp->getRequestID()) return true;
562 else if (packetChannel == CHANNEL_STREAM)
564 if (vdrpr->streamID == vresp->getStreamID()) return true;
566 else if (packetChannel == CHANNEL_TVMEDIA)
568 if (vdrpr->streamID == vresp->getStreamID()) return true;
574 VDR_ResponsePacket* VDR::RequestResponse(VDR_RequestPacket* vrp)
576 //logger->log("VDR", Log::DEBUG, "RR %lu", vrp->getOpcode());
580 logger->log("VDR", Log::DEBUG, "RR when !connected");
581 VDR_ResponsePacket* vresp = new VDR_ResponsePacket();
582 return vresp; // "no-response" return
585 // ED make new VDR and register
586 // make a VDR_PacketReceiver
587 // - init with serial number of request packet
589 VDR_PacketReceiver vdrpr;
590 // vdrpr.requestTime = time(NULL);
591 vdrpr.receiverChannel = VDR::CHANNEL_REQUEST_RESPONSE;
592 vdrpr.requestSerialNumber = vrp->getSerial();
598 if ((ULONG)tcp->sendData(vrp->getPtr(), vrp->getLen()) != vrp->getLen())
601 edUnregister(&vdrpr);
602 VDR_ResponsePacket* vresp = new VDR_ResponsePacket();
603 return vresp; // "no-response" return
606 // Sleep and block this thread. The sleep unlocks the mutex
607 logger->log("VDR", Log::DEBUG, "RR sleep - opcode %lu", vrp->getOpcode());
608 edSleepThisReceiver(&vdrpr);
609 logger->log("VDR", Log::DEBUG, "RR unsleep");
611 // Woken because a response packet has arrived, mutex will be locked
612 logger->log("VDR", Log::DEBUG, "Packet delivered to me, requestID: %lu", vdrpr.save_vresp->getRequestID());
615 return vdrpr.save_vresp;
618 bool VDR::sendKA(ULONG timeStamp)
623 ULONG ul=CHANNEL_KEEPALIVE;
624 buffer[pos++]=(ul>>24)&0xff;
625 buffer[pos++]=(ul>>16)&0xff;
626 buffer[pos++]=(ul>>8)&0xff;
627 buffer[pos++]=ul &0xff;
629 buffer[pos++]=(ul>>24)&0xff;
630 buffer[pos++]=(ul>>16)&0xff;
631 buffer[pos++]=(ul>>8)&0xff;
632 buffer[pos++]=ul &0xff;
633 if ((ULONG)tcp->sendData(buffer, 8) != 8) return false;
637 /////////////////////////////////////////////////////////////////////////////
639 // Here VDR takes a break for the VDR_PacketReceiver helper class
641 void VDR_PacketReceiver::call(void* userTag, bool& r_deregisterEDR, bool& r_wakeThread, bool& r_deleteEDR)
643 if (receiverChannel == VDR::CHANNEL_REQUEST_RESPONSE)
645 // It's a RR. Save vresp and, signal the waiting thread and return.
646 // VDR::RequestResponse will be blocking waiting for this to happen.
647 // That function has a pointer to this object and can read save_vresp.
648 save_vresp = (VDR_ResponsePacket*)userTag;
650 r_deregisterEDR = true;
654 else if (receiverChannel == VDR::CHANNEL_STREAM)
656 // It's a stream packet. Pass off the stream data to streamReceiver,
657 // delete the vresp. Keep this PacketReceiver for the next stream packet.
658 VDR_ResponsePacket* vresp = (VDR_ResponsePacket*)userTag;
659 streamReceiver->streamReceive(vresp->getFlag(), vresp->getUserData(), vresp->getUserDataLength());
662 r_deregisterEDR = false;
663 r_wakeThread = false;
666 else if (receiverChannel == VDR::CHANNEL_TVMEDIA)
669 // Pass off the vresp object to OSDVector
670 // This used to return true which would signal the cond (wake the thread)
671 // but am going to try setting this to false because I don't know that there is a thread to signal
672 // delete the EDR. It's made once per media requested and wasn't owned/deleted by anything before
674 VDR_ResponsePacket* vresp = (VDR_ResponsePacket*)userTag;
675 Log::getInstance()->log("VDR", Log::DEBUG, "TVMedia Pictures arrived VDR %x", vresp->getStreamID());
676 OsdVector *osd=dynamic_cast<OsdVector*>(Osd::getInstance());
677 if (osd) osd->getPictReader()->receivePicture(vresp);
678 // else delete vresp; //nonsense // only rpi does CHANNEL_TVMEDIA, rpi has osdvector. therefore, can't get here.
680 r_deregisterEDR = true;
681 r_wakeThread = false;
684 else abort(); // unknown receiverChannel, should not happen
687 /////////////////////////////////////////////////////////////////////////////
689 int VDR::doLogin(unsigned int* v_server_min, unsigned int* v_server_max, unsigned int* v_client,
690 ASLPrefList& list, int &subtitles)
692 VDR_RequestPacket vrp;
693 if (!vrp.init(VDR_LOGIN, true, 6)) return 0;
696 tcp->getMAC((char*)mactemp);
697 if (!vrp.copyin((UCHAR*)mactemp, 6)) return 0;
699 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
700 if (vresp->noResponse()) { delete vresp; return 0; }
702 ULONG vdrTime = vresp->extractULONG();
703 logger->log("VDR", Log::DEBUG, "vdrtime = %lu", vdrTime);
704 long vdrTimeOffset = vresp->extractLONG();
705 logger->log("VDR", Log::DEBUG, "offset = %i", vdrTimeOffset);
707 unsigned int version_min=vresp->extractULONG();
709 *v_server_min=version_min;
710 unsigned int version_max=vresp->extractULONG();
711 *v_server_max=version_max;
712 *v_client=VOMP_PROTOCOLL_VERSION;
714 if (0x00000302 <= version_max) {
715 unsigned int numlangcodes = vresp->extractULONG();
716 subtitles = vresp->extractULONG();
718 for (unsigned int i=0; i<numlangcodes; i++) {
720 newpref.audiopref = vresp->extractLONG();
721 newpref.subtitlepref = vresp->extractLONG();
722 newpref.langcode = vresp->extractStdString();
723 //logger->log("VDR", Log::DEBUG, "Langpref %s %d %d", newpref.langcode.c_str(), newpref.audiopref, newpref.subtitlepref);
724 list.push_back(newpref);
731 if ((version_min > VOMP_PROTOCOLL_VERSION)
732 || (version_max < VOMP_PROTOCOLL_VERSION) ) {
738 // Set the time and zone on the MVP only
740 #if !defined(WIN32) && !defined(__ANDROID__)
741 struct timespec currentTime;
742 currentTime.tv_sec = vdrTime;
743 currentTime.tv_nsec = 0;
745 int b = clock_settime(CLOCK_REALTIME, ¤tTime);
747 logger->log("VDR", Log::DEBUG, "set clock = %u", b);
749 // now make a TZ variable and set it
753 if (vdrTimeOffset > 0) sign = '-';
756 vdrTimeOffset = abs(vdrTimeOffset);
758 hours = (int)vdrTimeOffset / 3600;
759 minutes = vdrTimeOffset % 3600;
761 logger->log("VDR", Log::DEBUG, "%c %i %i", sign, hours, minutes);
763 minutes = (int)minutes / 60;
765 logger->log("VDR", Log::DEBUG, "%c %i %i", sign, hours, minutes);
768 sprintf(newTZ, "MVP%c%i:%i", sign, hours, minutes);
769 setenv("TZ", newTZ, 1);
771 logger->log("VDR", Log::DEBUG, "Timezone data: %s", newTZ);
774 setCharset(Osd::getInstance()->charSet());
779 bool VDR::LogExtern(const char* logString)
781 if (!connected) return false;
782 int stringLength = strlen(logString);
783 int packetLength = stringLength + 8;
784 char *buffer=new char[packetLength + 1];
786 ULONG ul=CHANNEL_NETLOG;
787 buffer[pos++]=(ul>>24)&0xff;
788 buffer[pos++]=(ul>>16)&0xff;
789 buffer[pos++]=(ul>>8)&0xff;
790 buffer[pos++]=ul &0xff;
792 buffer[pos++]=(ul>>24)&0xff;
793 buffer[pos++]=(ul>>16)&0xff;
794 buffer[pos++]=(ul>>8)&0xff;
795 buffer[pos++]=ul &0xff;
797 strcpy(&buffer[8], logString);
799 if (tcp->sendData(buffer, packetLength) != packetLength)
801 connected = false; // stop the rest of the connection
809 bool VDR::setCharset(int charset)
811 VDR_RequestPacket vrp;
812 if (!vrp.init(VDR_SETCHARSET, true, sizeof(ULONG))) return false;
813 if (!vrp.addULONG(charset)) return false;
815 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
816 if (vresp->noResponse()) { delete vresp; return false; }
818 ULONG success = vresp->extractULONG();
821 if (!success) return false;
826 bool VDR::getRecordingsList(RecMan* recman)
828 VDR_RequestPacket vrp;
829 if (!vrp.init(VDR_GETRECORDINGLIST, true, 0)) return false;
831 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
832 if (vresp->noResponse()) { delete vresp; return false; }
834 ULONG totalSpace = vresp->extractULONG();
835 ULONG freeSpace = vresp->extractULONG();
836 ULONG percent = vresp->extractULONG();
838 recman->setStats(totalSpace, freeSpace, percent);
845 while (!vresp->end())
847 start = vresp->extractULONG();
848 isNew = vresp->extractUCHAR();
849 name = vresp->extractString();
850 fileName = vresp->extractString();
851 recman->addEntry(isNew, start, name, fileName);
860 int VDR::deleteRecording(char* fileName)
862 VDR_RequestPacket vrp;
863 if (!vrp.init(VDR_DELETERECORDING, true, strlen(fileName) + 1)) return 0;
864 if (!vrp.addString(fileName)) return 0;
866 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
867 if (vresp->noResponse()) { delete vresp; return 0; }
869 int toReturn = (int)vresp->extractULONG();
875 int VDR::deleteRecResume(char* fileName)
877 VDR_RequestPacket vrp;
878 if (!vrp.init(VDR_DELETERECRESUME, true, strlen(fileName) + 1)) return 0;
879 if (!vrp.addString(fileName)) return 0;
881 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
882 if (vresp->noResponse()) { delete vresp; return 0; }
884 int toReturn = (int)vresp->extractULONG();
890 char* VDR::moveRecording(char* fileName, char* newPath)
892 VDR_RequestPacket vrp;
893 if (!vrp.init(VDR_MOVERECORDING, true, strlen(fileName) + 1 + strlen(newPath) + 1)) return NULL;
894 if (!vrp.addString(fileName)) return NULL;
895 if (!vrp.addString(newPath)) return NULL;
897 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
898 if (vresp->noResponse()) { delete vresp; return NULL; }
900 char* toReturn = NULL;
901 int success = (int)vresp->extractULONG();
904 toReturn = vresp->extractString();
912 ChannelList* VDR::getChannelsList(ULONG type)
914 VDR_RequestPacket vrp;
915 if (!vrp.init(VDR_GETCHANNELLIST, true, 0)) return NULL;
917 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
918 if (vresp->noResponse()) { delete vresp; return NULL; }
920 ChannelList* chanList = new ChannelList();
922 bool h264support=Video::getInstance()->supportsh264();
923 bool mpeg2support=Video::getInstance()->supportsmpeg2();
925 while (!vresp->end())
927 Channel* chan = new Channel();
928 chan->number = vresp->extractULONG();
929 chan->type = vresp->extractULONG();
930 chan->name = vresp->extractString();
931 chan->vstreamtype = vresp->extractULONG();
933 if (chan->type == type && ((chan->vstreamtype==0x1b && h264support)|| (chan->vstreamtype!=0x1b &&mpeg2support)) )
935 chanList->push_back(chan);
936 logger->log("VDR", Log::DEBUG, "Have added a channel to list. %lu %lu %s", chan->number, chan->type, chan->name);
937 if (chan->number > maxChannelNumber) maxChannelNumber = chan->number;
947 if (maxChannelNumber > 99999)
948 channelNumberWidth = 6;
949 else if (maxChannelNumber > 9999)
950 channelNumberWidth = 5;
951 else if (maxChannelNumber > 999)
952 channelNumberWidth = 4;
953 else if (maxChannelNumber > 99)
954 channelNumberWidth = 3;
955 else if (maxChannelNumber > 9)
956 channelNumberWidth = 2;
958 channelNumberWidth = 1;
963 int VDR::streamChannel(ULONG number, StreamReceiver* tstreamReceiver)
965 VDR_RequestPacket vrp;
966 if (!vrp.init(VDR_STREAMCHANNEL, true, sizeof(ULONG))) return 0;
967 if (!vrp.addULONG(number)) return 0;
970 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
971 vdrpr->receiverChannel = VDR::CHANNEL_STREAM;
972 vdrpr->streamID = vrp.getSerial();
973 vdrpr->streamReceiver = tstreamReceiver;
975 TEMP_SINGLE_VDR_PR = vdrpr;
977 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
978 if (vresp->noResponse())
986 int toReturn = (int)vresp->extractULONG();
987 logger->log("VDR", Log::DEBUG, "VDR said %lu to start streaming request", toReturn);
993 int VDR::stopStreaming()
995 VDR_RequestPacket vrp;
996 if (!vrp.init(VDR_STOPSTREAMING, true, 0)) return 0;
998 if (TEMP_SINGLE_VDR_PR) // this block only needs to be done if it was a live stream
999 // TEMP_SINGLE_VDR_PR will not be set unless we are streaming a channel
1001 edUnregister(TEMP_SINGLE_VDR_PR);
1002 delete TEMP_SINGLE_VDR_PR;
1003 TEMP_SINGLE_VDR_PR = NULL;
1006 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1007 if (vresp->noResponse()) { delete vresp; return 0; }
1009 int toReturn = (int)vresp->extractULONG();
1015 UCHAR* VDR::getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived)
1017 VDR_RequestPacket vrp;
1018 if (!vrp.init(VDR_GETBLOCK, true, sizeof(ULLONG) + sizeof(ULONG))) return NULL;
1019 if (!vrp.addULLONG(position)) return NULL;
1020 if (!vrp.addULONG(maxAmount)) return NULL;
1022 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1023 if (vresp->noResponse()) { delete vresp; return NULL; }
1025 if (vresp->serverError())
1027 logger->log("VDR", Log::DEBUG, "Detected getblock 0");
1028 *amountReceived = 0;
1033 // Special handling for getblock
1034 UCHAR* toReturn = vresp->getUserData();
1035 *amountReceived = vresp->getUserDataLength();
1042 ULLONG VDR::streamRecording(char* fileName, ULONG* totalFrames, bool* IsPesRecording)
1044 VDR_RequestPacket vrp;
1045 if (!vrp.init(VDR_STREAMRECORDING, true, strlen(fileName) + 1)) return 0;
1046 if (!vrp.addString(fileName)) return 0;
1048 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1049 if (vresp->noResponse()) { delete vresp; return 0; }
1051 ULLONG lengthBytes = vresp->extractULLONG();
1052 ULONG lengthFrames = vresp->extractULONG();
1053 UCHAR isPesRecording = vresp->extractUCHAR();
1056 *totalFrames = lengthFrames;
1057 *IsPesRecording = (isPesRecording);//convert Uchar to bool
1059 logger->log("VDR", Log::DEBUG, "VDR said length is: %llu %lu, IsPesRecording %x", lengthBytes, lengthFrames, *IsPesRecording);
1064 ULLONG VDR::positionFromFrameNumber(ULONG frameNumber)
1066 VDR_RequestPacket vrp;
1067 if (!vrp.init(VDR_POSFROMFRAME, true, sizeof(ULONG))) return 0;
1068 if (!vrp.addULONG(frameNumber)) return 0;
1070 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1071 if (vresp->noResponse()) { delete vresp; return 0; }
1073 ULLONG position = vresp->extractULLONG();
1076 logger->log("VDR", Log::DEBUG, "VDR said new position is: %llu", position);
1081 ULONG VDR::frameNumberFromPosition(ULLONG position)
1083 VDR_RequestPacket vrp;
1084 if (!vrp.init(VDR_FRAMEFROMPOS, true, sizeof(ULLONG))) return 0;
1085 if (!vrp.addULLONG(position)) return 0;
1087 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1088 if (vresp->noResponse()) { delete vresp; return 0; }
1090 ULONG framenumber = vresp->extractULONG();
1093 logger->log("VDR", Log::DEBUG, "VDR said new framenumber is: %u", framenumber);
1098 bool VDR::getNextIFrame(ULONG frameNumber, ULONG direction, ULLONG* rfilePosition, ULONG* rframeNumber, ULONG* rframeLength)
1100 VDR_RequestPacket vrp;
1101 if (!vrp.init(VDR_GETNEXTIFRAME, true, sizeof(ULONG)*2)) return false;
1102 if (!vrp.addULONG(frameNumber)) return false;
1103 if (!vrp.addULONG(direction)) return false;
1105 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1106 if (vresp->noResponse()) { delete vresp; return false; }
1108 if (vresp->serverError())
1110 logger->log("VDR", Log::DEBUG, "Detected getNextIFrame error");
1115 *rfilePosition = vresp->extractULLONG();
1116 *rframeNumber = vresp->extractULONG();
1117 *rframeLength = vresp->extractULONG();
1121 logger->log("VDR", Log::DEBUG, "VDR GNIF said %llu %lu %lu", *rfilePosition, *rframeNumber, *rframeLength);
1126 EventList* VDR::getChannelSchedule(ULONG number)
1130 return getChannelSchedule(number, now, 24 * 60 * 60);
1133 EventList* VDR::getChannelSchedule(ULONG number, time_t start, ULONG duration)
1135 // retrieve event list (vector of events) from vdr within filter window. duration is in seconds
1137 VDR_RequestPacket vrp;
1138 if (!vrp.init(VDR_GETCHANNELSCHEDULE, true, sizeof(ULONG)*3)) return NULL;
1139 if (!vrp.addULONG(number)) return NULL;
1140 if (!vrp.addULONG(start)) return NULL;
1141 if (!vrp.addULONG(duration)) return NULL;
1143 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1144 if (vresp->noResponse()) { delete vresp; return NULL; }
1146 // received a ulong(0) - schedules error in the plugin
1147 if (vresp->serverError())
1153 EventList* eventList = new EventList();
1155 while (!vresp->end())
1157 Event* event = new Event();
1158 event->id = vresp->extractULONG();
1159 event->time = vresp->extractULONG();
1160 event->duration = vresp->extractULONG();
1161 event->title = vresp->extractString();
1162 event->subtitle = vresp->extractString();
1163 event->description = vresp->extractString();
1164 eventList->push_back(event);
1169 logger->log("VDR", Log::DEBUG, "Success got to end of getChannelSchedule");
1173 int VDR::configSave(const char* section, const char* key, const char* value)
1175 VDR_RequestPacket vrp;
1176 if (!vrp.init(VDR_CONFIGSAVE, false, 0)) return 0;
1177 if (!vrp.addString(section)) return 0;
1178 if (!vrp.addString(key)) return 0;
1179 if (!vrp.addString(value)) return 0;
1181 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1182 if (vresp->noResponse()) { delete vresp; return 0; }
1184 int toReturn = (int)vresp->extractULONG();
1190 char* VDR::configLoad(const char* section, const char* key)
1192 VDR_RequestPacket vrp;
1193 if (!vrp.init(VDR_CONFIGLOAD, false, 0)) return NULL;
1194 if (!vrp.addString(section)) return NULL;
1195 if (!vrp.addString(key)) return NULL;
1197 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1198 if (vresp->noResponse()) { delete vresp; return NULL; }
1200 char* toReturn = vresp->extractString();
1206 RecTimerList* VDR::getRecTimersList()
1208 VDR_RequestPacket vrp;
1209 if (!vrp.init(VDR_GETTIMERS, true, 0)) return NULL;
1211 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1212 if (vresp->noResponse()) { delete vresp; return NULL; }
1214 RecTimerList* recTimerList = new RecTimerList();
1216 ULONG numTimers = vresp->extractULONG();
1219 RecTimer* newRecTimer;
1222 while (!vresp->end())
1224 newRecTimer = new RecTimer();
1225 newRecTimer->active = vresp->extractULONG();
1226 newRecTimer->recording = vresp->extractULONG();
1227 newRecTimer->pending = vresp->extractULONG();
1228 newRecTimer->priority = vresp->extractULONG();
1229 newRecTimer->lifeTime = vresp->extractULONG();
1230 newRecTimer->channelNumber = vresp->extractULONG();
1231 newRecTimer->startTime = vresp->extractULONG();
1232 newRecTimer->stopTime = vresp->extractULONG();
1233 newRecTimer->day = vresp->extractULONG();
1234 newRecTimer->weekDays = vresp->extractULONG();
1236 tempString = vresp->extractString();
1237 newRecTimer->setFile(tempString);
1238 delete[] tempString;
1240 recTimerList->push_back(newRecTimer);
1241 logger->log("VDR", Log::DEBUG, "TL: %lu %lu %lu %lu %lu %lu %lu %lu %s",
1242 newRecTimer->active, newRecTimer->recording, newRecTimer->pending, newRecTimer->priority, newRecTimer->lifeTime,
1243 newRecTimer->channelNumber, newRecTimer->startTime, newRecTimer->stopTime, newRecTimer->getFile());
1249 sort(recTimerList->begin(), recTimerList->end(), RecTimerSorter());
1251 return recTimerList;
1254 ULONG VDR::setEventTimer(char* timerString)
1256 VDR_RequestPacket vrp;
1257 if (!vrp.init(VDR_SETTIMER, true, strlen(timerString) + 1)) return 0;
1258 if (!vrp.addString(timerString)) return 0;
1260 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1261 if (vresp->noResponse()) { delete vresp; return 0; }
1263 ULONG toReturn = vresp->extractULONG();
1269 RecInfo* VDR::getRecInfo(char* fileName)
1271 VDR_RequestPacket vrp;
1272 if (!vrp.init(VDR_GETRECINFO2, true, strlen(fileName) + 1)) return NULL;
1273 if (!vrp.addString(fileName)) return NULL;
1274 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1276 if (vresp->noResponse()) { delete vresp; return NULL; }
1278 if (vresp->serverError())
1280 logger->log("VDR", Log::DEBUG, "Could not get rec info");
1285 RecInfo* recInfo = new RecInfo();
1287 recInfo->timerStart = vresp->extractULONG();
1288 recInfo->timerEnd = vresp->extractULONG();
1289 recInfo->resumePoint = vresp->extractULONG();
1290 recInfo->summary = vresp->extractString();
1292 ULONG numComponents = vresp->extractULONG();
1295 recInfo->setNumComponents(numComponents);
1296 for (ULONG i = 0; i < numComponents; i++)
1298 recInfo->streams[i] = vresp->extractUCHAR();
1299 recInfo->types[i] = vresp->extractUCHAR();
1300 recInfo->languages[i] = vresp->extractString();
1301 recInfo->descriptions[i] = vresp->extractString();
1304 recInfo->fps=vresp->extractdouble();
1305 recInfo->title=vresp->extractString();
1308 recInfo->channelName = vresp->extractString();
1309 recInfo->duration = vresp->extractULONG();
1310 recInfo->fileSize = vresp->extractULONG();
1311 recInfo->priority = vresp->extractULONG();
1312 recInfo->lifetime = vresp->extractULONG();
1321 ULLONG VDR::rescanRecording(ULONG* totalFrames)
1323 VDR_RequestPacket vrp;
1324 if (!vrp.init(VDR_RESCANRECORDING, true, 0)) return 0;
1326 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1327 if (vresp->noResponse()) { delete vresp; return 0; }
1329 ULLONG lengthBytes = vresp->extractULLONG();
1330 ULONG lengthFrames = vresp->extractULONG();
1333 logger->log("VDR", Log::DEBUG, "VDR said length is: %llu %lu", lengthBytes, lengthFrames);
1335 *totalFrames = lengthFrames;
1339 MarkList* VDR::getMarks(char* fileName)
1341 VDR_RequestPacket vrp;
1342 if (!vrp.init(VDR_GETMARKS, true, strlen(fileName) + 1)) return NULL;
1343 if (!vrp.addString(fileName)) return NULL;
1345 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1346 if (vresp->noResponse()) { delete vresp; return NULL; }
1348 if (vresp->serverError())
1354 MarkList* markList = new MarkList();
1356 while (!vresp->end())
1358 Mark* mark = new Mark();
1359 mark->pos = vresp->extractULONG();
1361 markList->push_back(mark);
1362 logger->log("VDR", Log::DEBUG, "Have added a mark to list. %lu", mark->pos);
1370 void VDR::getChannelPids(Channel* channel)
1372 VDR_RequestPacket vrp;
1373 if (!vrp.init(VDR_GETCHANNELPIDS, true, sizeof(ULONG))) return ;
1374 if (!vrp.addULONG(channel->number)) return ;
1376 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1377 if (vresp->noResponse()) { delete vresp; return ; }
1379 // Format of response
1387 channel->vpid = vresp->extractULONG();
1388 channel->vstreamtype = vresp->extractULONG();
1389 channel->numAPids = vresp->extractULONG();
1391 for (ULONG i = 0; i < channel->numAPids; i++)
1394 newapid.pid = vresp->extractULONG();
1395 char * name=vresp->extractString();
1396 strncpy(newapid.desc,name,9);
1398 channel->apids.push_back(newapid);
1401 channel->numDPids = vresp->extractULONG();
1403 for (ULONG i = 0; i < channel->numDPids; i++)
1406 newdpid.pid = vresp->extractULONG();
1407 char * name=vresp->extractString();
1408 strncpy(newdpid.desc,name,9);
1410 channel->dpids.push_back(newdpid);
1413 channel->numSPids = vresp->extractULONG();
1415 for (ULONG i = 0; i < channel->numSPids; i++)
1418 newspid.pid = vresp->extractULONG();
1419 char * name=vresp->extractString();
1420 strncpy(newspid.desc,name,9);
1422 channel->spids.push_back(newspid);
1424 channel->tpid = vresp->extractULONG();
1426 for (ULONG i = 0; i < channel->numAPids; i++)
1428 channel->apids[i].type = vresp->extractULONG();
1430 for (ULONG i = 0; i < channel->numDPids; i++)
1432 channel->dpids[i].type = vresp->extractULONG();
1434 for (ULONG i = 0; i < channel->numSPids; i++)
1436 channel->spids[i].type = vresp->extractULONG();
1437 channel->spids[i].data1 = vresp->extractULONG();
1438 channel->spids[i].data2 = vresp->extractULONG();
1446 #ifdef VOMP_MEDIAPLAYER
1447 MediaList * VDR::getRootList() {
1448 return getMediaList(NULL);
1451 * media List Request:
1453 * Media List response:
1456 MediaList* VDR::getMediaList(const MediaURI * root)
1458 logger->log("VDR", Log::DEBUG, "getMediaList %s,d=%s, prov=%d", (root?root->getName():"NULL"),
1459 ((root && root->hasDisplayName())?root->getDisplayName():"NULL"),
1460 (root?root->getProvider():providerId));
1461 MediaURI remoteURI(root);
1462 VDR_GetMediaListRequest request(&remoteURI);
1463 SerializeBuffer *vrp=prepareRequest(&request);
1465 logger->log("VDR", Log::ERR, "getMediaList unable to create command");
1469 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1471 Command::getInstance()->connectionLost();
1475 MediaList *rt=new MediaList(NULL);
1477 VDR_GetMediaListResponse resp(&rtflags,rt);
1478 if (decodeResponse(vresp,&resp) != 0) {
1485 * get image Request:
1487 * get media response:
1491 int VDR::openMedium(ULONG channel,const MediaURI *uri, ULLONG * size, ULONG x, ULONG y)
1493 MediaURI remoteURI(uri);
1494 VDR_OpenMediumRequest request(&channel,&remoteURI,&x,&y);
1496 SerializeBuffer *vrp=prepareRequest(&request);
1498 logger->log("VDR", Log::ERR, "openMedium unable to create command");
1501 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1503 Command::getInstance()->connectionLost();
1507 VDR_OpenMediumResponse response(&flags,size);
1508 if (decodeResponse(vresp,&response) != 0) {
1511 logger->log("VDR", Log::DEBUG, "openMedia len=%llu", *size);
1516 * getMediaBlock - no separate response class - simple data block
1520 int VDR::getMediaBlock(ULONG channel, ULLONG position, ULONG maxAmount, ULONG* amountReceived, unsigned char **buffer)
1523 VDR_GetMediaBlockRequest request(&channel,&position,&maxAmount);
1524 SerializeBuffer *vrp=prepareRequest(&request);
1526 logger->log("VDR", Log::ERR, "getMediaBlock unable to create command");
1529 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1531 Command::getInstance()->connectionLost();
1535 // Special handling for getblock
1536 *amountReceived = (ULONG)(vresp->getEnd()-vresp->getStart());
1537 *buffer = vresp->steelBuffer();
1550 int VDR::getMediaInfo(ULONG channel, MediaInfo * result) {
1551 if (! result) return -1;
1552 VDR_GetMediaInfoRequest request(&channel);
1553 SerializeBuffer *vrp=prepareRequest(&request);
1555 logger->log("VDR", Log::ERR, "getMediaInfo unable to create command");
1558 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1560 Command::getInstance()->connectionLost();
1565 VDR_GetMediaInfoResponse response(&flags,result);
1566 if (decodeResponse(vresp,&response) != 0) {
1579 int VDR::closeMediaChannel(ULONG channel) {
1580 VDR_CloseMediaChannelRequest request(&channel);
1581 SerializeBuffer *vrp=prepareRequest(&request);
1583 logger->log("VDR", Log::ERR, "closeMediaChannel unable to create command");
1586 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1588 Command::getInstance()->connectionLost();
1592 VDR_CloseMediaChannelResponse response(&flags);
1593 if (decodeResponse(vresp,&response) != 0) return -1;
1594 return (flags != 0)?-1:0;
1600 int VDR::deleteTimer(RecTimer* delTimer)
1602 logger->log("VDR", Log::DEBUG, "Delete timer called");
1604 VDR_RequestPacket vrp;
1605 if (!vrp.init(VDR_DELETETIMER, false, 0)) return 0;
1606 if (!vrp.addULONG(delTimer->channelNumber)) return 0;
1607 if (!vrp.addULONG(delTimer->weekDays)) return 0;
1608 if (!vrp.addULONG(delTimer->day)) return 0;
1609 if (!vrp.addULONG(delTimer->startTime)) return 0;
1610 if (!vrp.addULONG(delTimer->stopTime)) return 0;
1612 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1613 if (vresp->noResponse()) { delete vresp; return 0; }
1615 int toReturn = (int)vresp->extractULONG();
1621 I18n::lang_code_list VDR::getLanguageList()
1623 I18n::lang_code_list CodeList;
1624 CodeList["en"] = "English"; // Default entry
1625 VDR_RequestPacket vrp;
1626 if (!vrp.init(VDR_GETLANGUAGELIST, false, 0)) return CodeList;
1627 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1628 if (vresp->noResponse() || vresp->end())
1634 while (!vresp->end())
1636 char* c_code = vresp->extractString();
1637 char* c_name = vresp->extractString();
1638 string code = c_code;
1639 string name = c_name;
1640 CodeList[code] = name;
1648 int VDR::getLanguageContent(const std::string code, I18n::trans_table& texts)
1650 VDR_RequestPacket vrp;
1651 if (!vrp.init(VDR_GETLANGUAGECONTENT, false, 0)) return 0;
1652 if (!vrp.addString(code.c_str())) return 0;
1653 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1654 if (vresp->noResponse()) { delete vresp; return 0; }
1656 while (!vresp->end())
1658 char* c_key = vresp->extractString();
1659 char* c_text = vresp->extractString();
1661 string text = c_text;
1670 void VDR::shutdownVDR()
1673 logger->log("VDR", Log::DEBUG, "Shutting down vdr");
1675 logger->log("VDR", Log::DEBUG, "Shutting down vomp only");
1677 if(!doVDRShutdown || !connected)
1680 VDR_RequestPacket vrp;
1681 logger->log("VDR", Log::DEBUG, "Sending shutdown");
1682 if (!vrp.init(VDR_SHUTDOWN, false, 0)) return;
1683 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1686 logger->log("VDR", Log::DEBUG, "VDR shutdown");
1689 void VDR::getScraperEventType(char * fileName, int & movieID,
1690 int & seriesID, int & episodeID)
1695 VDR_RequestPacket vrp;
1696 if (!vrp.init(VDR_GETRECSCRAPEREVENTTYPE, true, strlen(fileName) + 1)) return;
1697 if (!vrp.addString(fileName)) return ;
1698 Log::getInstance()->log("Recording", Log::DEBUG, "Before Response ");
1699 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1700 Log::getInstance()->log("Recording", Log::DEBUG, "After Response ");
1701 if (vresp->noResponse()) { delete vresp; return ; }
1702 int type = vresp->extractUCHAR();
1703 if (type == 0) //serie
1705 seriesID = vresp->extractLONG();
1706 episodeID = vresp->extractLONG();
1707 } else if (type == 1) //movie
1709 movieID = vresp->extractLONG();
1715 void VDR::getScraperEventType(UINT channelid, UINT eventid, int & movieID,
1716 int & seriesID, int & episodeID, int & epgImage )
1722 VDR_RequestPacket vrp;
1723 if (!vrp.init(VDR_GETEVENTSCRAPEREVENTTYPE, false, 0)) return;
1724 if (!vrp.addULONG(channelid)) return ;
1725 if (!vrp.addULONG(eventid)) return ;
1726 Log::getInstance()->log("Recording", Log::DEBUG, "Before Response ");
1727 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1728 Log::getInstance()->log("Recording", Log::DEBUG, "After Response ");
1729 if (vresp->noResponse()) { delete vresp; return ; }
1730 int type = vresp->extractUCHAR();
1731 if (type == 0) //serie
1733 seriesID = vresp->extractLONG();
1734 episodeID = vresp->extractLONG();
1735 } else if (type == 1) //movie
1737 movieID = vresp->extractLONG();
1739 epgImage = vresp->extractLONG();
1744 MovieInfo *VDR::getScraperMovieInfo(int movieID)
1746 VDR_RequestPacket vrp;
1747 if (!vrp.init(VDR_GETSCRAPERMOVIEINFO, false, 0)) return NULL;
1748 if (!vrp.addULONG(movieID)) return NULL;
1749 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1750 if (vresp->noResponse()) { delete vresp; return NULL; }
1751 MovieInfo * movieinf= new MovieInfo();
1753 movieinf->id=movieID;
1754 movieinf->title = vresp->extractStdString();
1755 movieinf->originalTitle = vresp->extractStdString();
1756 movieinf->tagline = vresp->extractStdString();
1757 movieinf->overview = vresp->extractStdString();
1758 movieinf->adult = vresp->extractUCHAR();
1759 movieinf->collectionName = vresp->extractStdString();
1761 movieinf->budget = vresp->extractLONG();
1762 movieinf->revenue = vresp->extractLONG();
1763 movieinf->genres = vresp->extractStdString();
1764 movieinf->homepage = vresp->extractStdString();
1765 movieinf->releaseDate = vresp->extractStdString();
1766 movieinf->runtime = vresp->extractLONG();
1767 movieinf->popularity = vresp->extractdouble();
1768 movieinf->voteAverage = vresp->extractdouble();
1769 movieinf->poster.width = vresp->extractULONG();
1770 movieinf->poster.height = vresp->extractULONG();
1771 movieinf->poster.info.setMovieInfo(movieinf);
1772 movieinf->poster.info.setElement(0,0);
1773 movieinf->fanart.width = vresp->extractULONG();
1774 movieinf->fanart.height = vresp->extractULONG();
1775 movieinf->fanart.info.setMovieInfo(movieinf);
1776 movieinf->fanart.info.setElement(1,0);
1777 movieinf->collectionPoster.width = vresp->extractULONG();
1778 movieinf->collectionPoster.height = vresp->extractULONG();
1779 movieinf->collectionPoster.info.setMovieInfo(movieinf);
1780 movieinf->collectionPoster.info.setElement(2,0);
1781 movieinf->collectionFanart.width = vresp->extractULONG();
1782 movieinf->collectionFanart.height = vresp->extractULONG();
1783 movieinf->collectionFanart.info.setMovieInfo(movieinf);
1784 movieinf->collectionFanart.info.setElement(3,0);
1785 ULONG num_actors = vresp->extractULONG();
1786 movieinf->actors.clear();
1787 movieinf->actors.reserve(num_actors);
1788 for (ULONG acty=0; acty < num_actors; acty++) {
1790 new_act.name = vresp->extractStdString();
1791 new_act.role = vresp->extractStdString();
1792 new_act.thumb.width = vresp->extractULONG();
1793 new_act.thumb.height = vresp->extractULONG();
1794 new_act.thumb.info.setMovieInfo(movieinf);
1795 new_act.thumb.info.setElement(4,acty);
1796 movieinf->actors.push_back(new_act);
1805 SeriesInfo *VDR::getScraperSeriesInfo(int seriesID, int episodeID)
1807 VDR_RequestPacket vrp;
1808 if (!vrp.init(VDR_GETSCRAPERSERIESINFO, false, 0)) return NULL;
1809 if (!vrp.addULONG(seriesID)) return NULL;
1810 if (!vrp.addULONG(episodeID)) return NULL;
1812 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1813 if (vresp->noResponse()) { delete vresp; return 0; }
1814 SeriesInfo * seriesinf= new SeriesInfo();
1816 seriesinf->id=seriesID;
1819 seriesinf->name = vresp->extractStdString();
1820 seriesinf->overview = vresp->extractStdString();
1821 seriesinf->firstAired = vresp->extractStdString();
1822 seriesinf->network = vresp->extractStdString();
1823 seriesinf->genre = vresp->extractStdString();
1824 seriesinf->rating = vresp->extractdouble();
1825 seriesinf->status = vresp->extractStdString();
1828 seriesinf->episode.episodeid=episodeID;
1829 seriesinf->episode.number = vresp->extractLONG();
1830 seriesinf->episode.season = vresp->extractLONG();
1831 seriesinf->episode.name = vresp->extractStdString();
1832 seriesinf->episode.firstAired = vresp->extractStdString();
1833 seriesinf->episode.guestStars = vresp->extractStdString();
1834 seriesinf->episode.overview = vresp->extractStdString();
1835 seriesinf->episode.rating = vresp->extractdouble();
1836 seriesinf->episode.image.width = vresp->extractULONG();
1837 seriesinf->episode.image.height = vresp->extractULONG();
1838 seriesinf->episode.image.info.setSeriesInfo(seriesinf);
1839 seriesinf->episode.image.info.setElement(0,0);
1842 ULONG num_actors = vresp->extractULONG();
1843 seriesinf->actors.clear();
1844 seriesinf->actors.reserve(num_actors);
1845 for (ULONG acty=0; acty < num_actors; acty++) {
1847 new_act.name = vresp->extractStdString();
1848 new_act.role = vresp->extractStdString();
1849 new_act.thumb.width = vresp->extractULONG();
1850 new_act.thumb.height = vresp->extractULONG();
1851 new_act.thumb.info.setSeriesInfo(seriesinf);
1852 new_act.thumb.info.setElement(1,acty);
1853 seriesinf->actors.push_back(new_act);
1855 ULONG num_posters = vresp->extractULONG();
1856 for (ULONG medias = 0; medias < num_posters; medias++ ) {
1858 media.info.setSeriesInfo(seriesinf);
1859 media.info.setElement(2,medias);
1860 media.width = vresp->extractULONG();
1861 media.height = vresp->extractULONG();
1862 seriesinf->posters.push_back(media);
1865 ULONG num_banners = vresp->extractULONG();
1866 for (ULONG medias = 0; medias < num_banners; medias++ ) {
1868 media.info.setSeriesInfo(seriesinf);
1869 media.info.setElement(3,medias);
1870 media.width = vresp->extractULONG();
1871 media.height = vresp->extractULONG();
1872 seriesinf->banners.push_back(media);
1874 ULONG num_fanarts = vresp->extractULONG();
1875 for (ULONG medias = 0; medias < num_fanarts; medias++ ) {
1877 media.info.setSeriesInfo(seriesinf);
1878 media.info.setElement(4,medias);
1879 media.width = vresp->extractULONG();
1880 media.height = vresp->extractULONG();
1881 seriesinf->fanart.push_back(media);
1883 seriesinf->seasonposter.width = vresp->extractULONG();
1884 seriesinf->seasonposter.height = vresp->extractULONG();
1885 seriesinf->seasonposter.info.setSeriesInfo(seriesinf);
1886 seriesinf->seasonposter.info.setElement(5,0);
1893 ULONG VDR::loadTVMedia(TVMediaInfo& tvmedia)
1895 VDR_RequestPacket vrp;
1897 if (!vrp.init(VDR_LOADTVMEDIA, false, 0)) return ULONG_MAX;
1898 if (!vrp.addULONG(tvmedia.type)) return ULONG_MAX;
1899 if (!vrp.addULONG(tvmedia.primary_id)) return ULONG_MAX;
1900 if (!vrp.addULONG(tvmedia.secondary_id)) return ULONG_MAX;
1901 if (!vrp.addULONG(tvmedia.type_pict)) return ULONG_MAX;
1902 if (!vrp.addULONG(tvmedia.container)) return ULONG_MAX;
1903 if (!vrp.addULONG(tvmedia.container_member)) return ULONG_MAX;
1904 /* Log::getInstance()->log("VDR", Log::DEBUG, "TVMedia with ID %d %d; %d %d %d %d;%d",
1905 tvmedia.primary_id,tvmedia.secondary_id,tvmedia.type,tvmedia.type_pict,
1906 tvmedia.container,tvmedia.container_member,vrp.getSerial());*/
1909 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
1910 vdrpr->receiverChannel = VDR::CHANNEL_TVMEDIA;
1911 vdrpr->streamID = vrp.getSerial();
1912 vdrpr->streamReceiver = NULL;
1916 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1917 //if (vresp->noResponse()) { delete vresp; return ULONG_MAX; }
1920 return vrp.getSerial();
1923 ULONG VDR::loadTVMediaRecThumb(TVMediaInfo & media)
1926 VDR_RequestPacket vrp;
1928 if (!vrp.init(VDR_LOADTVMEDIARECTHUMB, false, 0)) return ULONG_MAX;
1929 if (!vrp.addString(media.primary_name.c_str())) return ULONG_MAX;
1931 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
1932 vdrpr->receiverChannel = VDR::CHANNEL_TVMEDIA;
1933 vdrpr->streamID = vrp.getSerial();
1934 vdrpr->streamReceiver = NULL;
1938 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1939 //if (vresp->noResponse()) { delete vresp; return ULONG_MAX; }
1942 return vrp.getSerial();
1945 ULONG VDR::loadTVMediaEventThumb(TVMediaInfo & media)
1948 VDR_RequestPacket vrp;
1950 if (!vrp.init(VDR_LOADTVMEDIAEVENTTHUMB, false, 0)) return ULONG_MAX;
1951 if (!vrp.addULONG(media.primary_id)) return ULONG_MAX;
1952 if (!vrp.addULONG(media.secondary_id)) return ULONG_MAX;
1954 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
1955 vdrpr->receiverChannel = VDR::CHANNEL_TVMEDIA;
1956 vdrpr->streamID = vrp.getSerial();
1957 vdrpr->streamReceiver = NULL;
1961 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1962 //if (vresp->noResponse()) { delete vresp; return ULONG_MAX; }
1965 return vrp.getSerial();
1968 ULONG VDR::loadChannelLogo(TVMediaInfo & media)
1971 VDR_RequestPacket vrp;
1973 if (!vrp.init(VDR_LOADCHANNELLOGO, false, 0)) return ULONG_MAX;
1974 if (!vrp.addULONG(media.primary_id)) return ULONG_MAX;
1976 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
1977 vdrpr->receiverChannel = VDR::CHANNEL_TVMEDIA;
1978 vdrpr->streamID = vrp.getSerial();
1979 vdrpr->streamReceiver = NULL;
1983 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1984 //if (vresp->noResponse()) { delete vresp; return ULONG_MAX; }
1987 // Log::getInstance()->log("VDR", Log::DEBUG, "TVMedia Channel Logo %d %x",
1988 // media.primary_id,vrp.getSerial());
1990 return vrp.getSerial();