2 Copyright 2004-2020 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/>.
27 #include "vdrrequestpacket.h"
28 #include "vdrresponsepacket.h"
30 #ifdef VOMP_MEDIAPLAYER
32 #include "mediaprovider.h"
33 #include "mediaproviderids.h"
35 #include "vdrcommand.h"
38 #include "movieinfo.h"
39 #include "seriesinfo.h"
40 #include "osdvector.h"
45 #define VOMP_PROTOCOL_VERSION 0x00000500
47 VDR* VDR::instance = NULL;
48 #ifdef VOMP_MEDIAPLAYER
50 //will create a request package from a command variable and fill this
51 //caller has to destroy buffer
52 static SerializeBuffer * prepareRequest(VDR_Command *cmd) {
53 SerializeBuffer *buf=new SerializeBuffer(512,false,true);
54 if (cmd->serialize(buf) != 0) {
61 //handle request/response
62 //TODO avoid copy of buffer (needs extension of requestpacket)
63 //TODO avoid command 2x (needs some more restructuring)
64 SerializeBuffer * VDR::doRequestResponse(SerializeBuffer *rq,int cmd) {
65 VDR_RequestPacket *rt=new VDR_RequestPacket;
70 if (! rt->init(cmd,true,rq->getCurrent()-rq->getStart())) {
75 if (! rt->copyin(rq->getStart(),(ULONG)(rq->getCurrent()-rq->getStart()))) {
81 VDR_ResponsePacket *rp=RequestResponse(rt);
82 logger->log("doRequestResponse",Log::DEBUG,"got response %p",rp);
87 SerializeBuffer *buf=new SerializeBuffer(rp->getUserData(),rp->getUserDataLength(),true,true,false);
92 //deserialize a received response
95 static int decodeResponse(SerializeBuffer *rp,VDR_Command *c) {
96 ULONG expected=c->command;
97 if (c->deserialize(rp) != 0) {
99 Log::getInstance()->log("VDR", Log::ERR, "decodeResponse unable to deserialize for command %lu",expected);
103 if (c->command != expected) {
104 Log::getInstance()->log("VDR", Log::ERR, "decodeResponse unexpected response received 0x%lx, expected 0x%lx",c->command,expected);
107 Log::getInstance()->log("VDR", Log::DEBUG, "decodeResponse successfully decoded command 0x%lx",expected);
115 if (instance) return;
118 TEMP_SINGLE_VDR_PR = NULL; // FIXME what is this
119 #ifdef VOMP_MEDIAPLAYER
120 providerId=MPROVIDERID_VDR;
121 subRange=MPROVIDERRANGE_VDR;
122 MediaPlayerRegister::getInstance()->registerMediaProvider(this,MPROVIDERID_VDR,MPROVIDERRANGE_VDR);
129 if (initted) shutdown();
132 VDR* VDR::getInstance()
139 if (initted) return 0;
141 logger = Log::getInstance();
148 if (!initted) return 0;
154 void VDR::setServerIP(const char* newIP)
156 strcpy(serverIP, newIP);
159 void VDR::setServerPort(USHORT newPort)
161 serverPort = newPort;
167 maxChannelNumber = 0;
168 channelNumberWidth = 1;
170 connectStateMutex.lock();
171 if (connecting || connected) return 0;
173 connectStateMutex.unlock(); // now I have connecting
175 bool connectResult = tcp.connect(serverIP, serverPort);
177 connectStateMutex.lock(); // connected = false, connecting = true, babortConnect = ?
182 if (connectResult) tcp.shutdown();
183 babortConnect = false;
184 connectStateMutex.unlock();
192 threadStartProtect.lock();
193 vdrThread = std::thread( [this]
195 threadStartProtect.lock();
196 threadStartProtect.unlock();
199 threadStartProtect.unlock();
201 connectStateMutex.unlock();
206 connectStateMutex.unlock();
211 void VDR::abortConnect() // If there is one, force a running connect call to abort
213 connectStateMutex.lock();
217 babortConnect = true;
221 connectStateMutex.unlock();
224 void VDR::disconnect()
226 std::lock_guard<std::mutex> lg(connectStateMutex);
228 if (!connected) return;
230 if (vdrThread.joinable())
232 threadReqStop = true;
235 threadReqStop = false;
240 disconnecting = false;
242 logger->log("VDR", Log::DEBUG, "Disconnect");
245 void VDR::setReceiveWindow(size_t size)
247 //if (connected && size) tcpold->setReceiveWindow(size);
250 ///////////////////////////////////////////////////////
252 void VDR::threadMethod()
254 logger->log("VDR", Log::DEBUG, "VDR RUN");
259 ULONG userDataLength;
265 VDR_ResponsePacket* vresp;
268 ULONG lastKAsent = 0;
269 ULONG lastKArecv = time(NULL);
274 readSuccess = tcp.read(&channelID, sizeof(ULONG));
275 if (threadReqStop) return;
276 timeNow = time(NULL);
280 //logger->log("VDR", Log::DEBUG, "Net read timeout");
281 if (!tcp.status()) { connectionDied(); return; } // return to stop this thread
284 if (!lastKAsent) // have not sent a KA
286 if (lastKArecv < (timeNow - 5))
288 //logger->log("VDR", Log::DEBUG, "Sending KA packet");
289 if (!sendKA(timeNow))
291 logger->log("VDR", Log::DEBUG, "Could not send KA, calling connectionDied");
295 lastKAsent = timeNow;
297 if (threadReqStop) return;
302 if (lastKAsent <= (timeNow - 10))
304 logger->log("VDR", Log::DEBUG, "lastKA over 10s ago, calling connectionDied");
310 if (!readSuccess) continue; // no data was read but the connection is ok.
314 channelID = ntohl(channelID);
316 if (channelID == CHANNEL_REQUEST_RESPONSE)
318 if (!tcp.read(&requestID, sizeof(ULONG))) break;
319 if (threadReqStop) return;
320 requestID = ntohl(requestID);
321 if (!tcp.read(&userDataLength, sizeof(ULONG))) break;
322 if (threadReqStop) return;
323 userDataLength = ntohl(userDataLength);
324 if (userDataLength > 5000000) break; // how big can these packets get?
326 if (userDataLength > 0)
328 userData = malloc(userDataLength);
329 if (!userData) break;
330 if (!tcp.read(userData, userDataLength))
343 vresp = new VDR_ResponsePacket();
344 vresp->setResponse(requestID, reinterpret_cast<UCHAR*>(userData), userDataLength);
345 // vresp now owns userData unless something calls vresp->getUserData()
346 // logger->log("VDR", Log::DEBUG, "Rxd a response packet, requestID=%lu, len=%lu", requestID, userDataLength);
348 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
350 // If edFindAndCall returns true, edr was called and vresp was handed off.
351 // else, delete vresp here.
354 if (threadReqStop) return;
356 else if (channelID == CHANNEL_STREAM || channelID == CHANNEL_TVMEDIA)
358 if (!tcp.read(&streamID, sizeof(ULONG))) break;
359 if (threadReqStop) return;
360 streamID = ntohl(streamID);
362 if (!tcp.read(&flag, sizeof(ULONG))) break;
363 if (threadReqStop) return;
366 if (!tcp.read(&userDataLength, sizeof(ULONG))) break;
367 if (threadReqStop) return;
368 userDataLength = ntohl(userDataLength);
370 if (userDataLength > 0)
372 userData = malloc(userDataLength);
373 if (!userData) break;
374 if (!tcp.read(userData, userDataLength))
387 vresp = new VDR_ResponsePacket();
388 vresp->setStream(streamID, flag, reinterpret_cast<UCHAR*>(userData), userDataLength, channelID);
389 //logger->log("VDR", Log::DEBUG, "Rxd a stream packet, streamID=%lu, flag=%lu, len=%lu", streamID, flag, userDataLength);
391 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
393 // If edFindAndCall returns true, edr was called and vresp was handed off.
394 // else, delete vresp here.
398 if (threadReqStop) return;
400 else if (channelID == CHANNEL_KEEPALIVE)
403 if (!tcp.read(&KAreply, sizeof(ULONG))) break;
404 if (threadReqStop) return;
405 KAreply = ntohl(KAreply);
406 if (KAreply == lastKAsent) // successful KA response
409 lastKArecv = KAreply;
410 //logger->log("VDR", Log::DEBUG, "Rxd correct KA reply");
415 logger->log("VDR", Log::ERR, "Rxd a response packet on channel %lu !!", channelID);
419 // Who deletes vresp?
420 // If RR, the individual protocol functions must delete vresp.
421 // If stream, the data and length is taken out in ed_cb_call and vresp is deleted there.
427 void VDR::connectionDied()
429 // Called from within threadMethod to do cleanup if it decides the connection has died
431 disconnecting = true;
433 // Need to wake up any waiting channel 1 request-response threads
434 // Normally this is done by a packet coming in with channelid and requestid
435 // Instead, go through the list and for each channel 1 edr, make an empty vresp
436 // An empty vresp will have userData == NULL, which means vresp->noResponse() == true
438 // If it's a stream receiver, generate a stream packet with flag == connection_lost
441 VDR_PacketReceiver* vdrpr;
442 VDR_ResponsePacket* vresp;
443 while(receivers.size())
445 vdrpr = dynamic_cast<VDR_PacketReceiver*>(*(receivers.begin()));
446 if (vdrpr->receiverChannel == CHANNEL_REQUEST_RESPONSE)
448 vresp = new VDR_ResponsePacket();
449 vresp->setResponse(vdrpr->requestSerialNumber, NULL, 0);
450 logger->log("VDR", Log::DEBUG, "Timeouts: created blank response packet for request serial %lu", vdrpr->requestSerialNumber);
452 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
454 // If edFindAndCall returns true, edr was called and vresp was handed off.
455 // else, delete vresp here.
456 logger->log("VDR", Log::ERR, "Timeouts: no waiting thread found for request serial %lu !!!", vdrpr->requestSerialNumber);
461 else if (vdrpr->receiverChannel == CHANNEL_STREAM || vdrpr->receiverChannel == CHANNEL_TVMEDIA)
463 vresp = new VDR_ResponsePacket();
464 vresp->setStream(vdrpr->streamID, 2 /* connection-lost flag */ , NULL, 0, vdrpr->receiverChannel);
465 logger->log("VDR", Log::DEBUG, "Timeouts: created blank response packet for streamid %lu", vdrpr->streamID);
467 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
469 // If edFindAndCall returns true, edr was called and vresp was handed off.
470 // else, delete vresp here.
471 logger->log("VDR", Log::ERR, "Timeouts: no waiting stream receiver found for streamid %lu !!!", vdrpr->streamID);
476 for(EDRL::iterator i = receivers.begin(); i != receivers.end(); i++)
477 if (dynamic_cast<VDR_PacketReceiver*>(*i) == vdrpr) { receivers.erase(i); break; }
481 // Ok, all event receviers should be dealt with. just in case there weren't any, inform control
482 logger->log("VDR", Log::DEBUG, "edUnlock at end of connectionDied");
484 Control::getInstance()->connectionLost();
487 bool VDR::ed_cb_find(EDReceiver* edr, void* userTag)
489 // edr is a VDR_PacketReceiver object made in VDR::RequestResponse
490 // userTag is a VDR_ResponsePacket made in threadMethod
492 VDR_PacketReceiver* vdrpr = dynamic_cast<VDR_PacketReceiver*>(edr);
493 VDR_ResponsePacket* vresp = reinterpret_cast<VDR_ResponsePacket*>(userTag);
495 // Is vresp for vdrpr ?
497 ULONG packetChannel = vresp->getChannelID();
498 //logger->log("VDR", Log::DEBUG, "TVMedia debug %d %d %x", vdrpr->receiverChannel,packetChannel,vdrpr);
499 if (vdrpr->receiverChannel != packetChannel) return false;
501 if (packetChannel == CHANNEL_REQUEST_RESPONSE)
503 if (vdrpr->requestSerialNumber == vresp->getRequestID()) return true;
505 else if (packetChannel == CHANNEL_STREAM)
507 if (vdrpr->streamID == vresp->getStreamID()) return true;
509 else if (packetChannel == CHANNEL_TVMEDIA)
511 if (vdrpr->streamID == vresp->getStreamID()) return true;
517 VDR_ResponsePacket* VDR::RequestResponse(VDR_RequestPacket* vrp)
519 //logger->log("VDR", Log::DEBUG, "RR %lu", vrp->getOpcode());
521 if (!connected || disconnecting)
523 logger->log("VDR", Log::DEBUG, "RR when !connected || disconnecting");
524 VDR_ResponsePacket* vresp = new VDR_ResponsePacket();
525 return vresp; // "no-response" return
528 // ED make new VDR and register
529 // make a VDR_PacketReceiver
530 // - init with serial number of request packet
532 VDR_PacketReceiver vdrpr;
533 // vdrpr.requestTime = time(NULL);
534 vdrpr.receiverChannel = VDR::CHANNEL_REQUEST_RESPONSE;
535 vdrpr.requestSerialNumber = vrp->getSerial();
542 if (!tcp.write(vrp->getPtr(), vrp->getLen()))
545 edUnregister(&vdrpr);
546 VDR_ResponsePacket* vresp = new VDR_ResponsePacket();
547 return vresp; // "no-response" return
550 // Sleep and block this thread. The sleep unlocks the mutex
551 // logger->log("VDR", Log::DEBUG, "RR sleep - opcode %lu", vrp->getOpcode());
552 edSleepThisReceiver(&vdrpr);
553 // logger->log("VDR", Log::DEBUG, "RR unsleep");
555 // Woken because a response packet has arrived, mutex will be locked
556 // logger->log("VDR", Log::DEBUG, "Packet delivered to me, requestID: %lu", vdrpr.save_vresp->getRequestID());
559 return vdrpr.save_vresp;
562 bool VDR::sendKA(ULONG timeStamp)
567 ULONG ul=CHANNEL_KEEPALIVE;
568 buffer[pos++]=(ul>>24)&0xff;
569 buffer[pos++]=(ul>>16)&0xff;
570 buffer[pos++]=(ul>>8)&0xff;
571 buffer[pos++]=ul &0xff;
573 buffer[pos++]=(ul>>24)&0xff;
574 buffer[pos++]=(ul>>16)&0xff;
575 buffer[pos++]=(ul>>8)&0xff;
576 buffer[pos++]=ul &0xff;
577 return tcp.write(buffer, 8);
580 /////////////////////////////////////////////////////////////////////////////
582 // Here VDR takes a break for the VDR_PacketReceiver helper class
584 void VDR_PacketReceiver::call(void* userTag, bool& r_deregisterEDR, bool& r_wakeThread, bool& r_deleteEDR)
586 if (receiverChannel == VDR::CHANNEL_REQUEST_RESPONSE)
588 // It's a RR. Save vresp and, signal the waiting thread and return.
589 // VDR::RequestResponse will be blocking waiting for this to happen.
590 // That function has a pointer to this object and can read save_vresp.
591 save_vresp = reinterpret_cast<VDR_ResponsePacket*>(userTag);
593 r_deregisterEDR = true;
597 else if (receiverChannel == VDR::CHANNEL_STREAM)
599 // It's a stream packet. Pass off the stream data to streamReceiver,
600 // delete the vresp. Keep this PacketReceiver for the next stream packet.
601 VDR_ResponsePacket* vresp = reinterpret_cast<VDR_ResponsePacket*>(userTag);
602 streamReceiver->streamReceive(vresp->getFlag(), vresp->getUserData(), vresp->getUserDataLength());
605 r_deregisterEDR = false;
606 r_wakeThread = false;
609 else if (receiverChannel == VDR::CHANNEL_TVMEDIA)
612 // Pass off the vresp object to OSDVector
613 // This used to return true which would signal the cond (wake the thread)
614 // but am going to try setting this to false because I don't know that there is a thread to signal
615 // delete the EDR. It's made once per media requested and wasn't owned/deleted by anything before
617 VDR_ResponsePacket* vresp = reinterpret_cast<VDR_ResponsePacket*>(userTag);
618 Log::getInstance()->log("VDR", Log::DEBUG, "TVMedia Pictures arrived VDR %x", vresp->getStreamID());
619 OsdVector *osd=dynamic_cast<OsdVector*>(Osd::getInstance());
620 if (osd) osd->getPictReader()->receivePicture(vresp);
621 // else delete vresp; //nonsense // only rpi does CHANNEL_TVMEDIA, rpi has osdvector. therefore, can't get here.
623 r_deregisterEDR = true;
624 r_wakeThread = false;
627 else abort(); // unknown receiverChannel, should not happen
630 /////////////////////////////////////////////////////////////////////////////
632 int VDR::doLogin(unsigned int* v_server_min, unsigned int* v_server_max, unsigned int* v_client,
633 ASLPrefList& list, int &subtitles)
635 VDR_RequestPacket vrp;
636 if (!vrp.init(VDR_LOGIN, true, 6)) return 0;
638 MACAddress myMAC = tcp.getMAC();
639 if (!vrp.copyin(reinterpret_cast<UCHAR*>(&myMAC), 6)) return 0;
641 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
642 if (vresp->noResponse()) { delete vresp; return 0; }
644 ULONG vdrTime = vresp->extractULONG();
645 logger->log("VDR", Log::DEBUG, "vdrtime = %lu", vdrTime);
646 long vdrTimeOffset = vresp->extractLONG();
647 logger->log("VDR", Log::DEBUG, "offset = %i", vdrTimeOffset);
649 unsigned int version_min=vresp->extractULONG();
651 *v_server_min=version_min;
652 unsigned int version_max=vresp->extractULONG();
653 *v_server_max=version_max;
654 *v_client=VOMP_PROTOCOL_VERSION;
656 if (0x00000302 <= version_max) {
657 unsigned int numlangcodes = vresp->extractULONG();
658 subtitles = vresp->extractULONG();
660 for (unsigned int i=0; i<numlangcodes; i++) {
662 newpref.audiopref = vresp->extractLONG();
663 newpref.subtitlepref = vresp->extractLONG();
664 newpref.langcode = vresp->extractStdString();
665 //logger->log("VDR", Log::DEBUG, "Langpref %s %d %d", newpref.langcode.c_str(), newpref.audiopref, newpref.subtitlepref);
666 list.push_back(newpref);
673 if ((version_min > VOMP_PROTOCOL_VERSION)
674 || (version_max < VOMP_PROTOCOL_VERSION) ) {
680 // Set the time and zone on the MVP only
682 #if !defined(WIN32) && !defined(__ANDROID__)
683 struct timespec currentTime;
684 currentTime.tv_sec = vdrTime;
685 currentTime.tv_nsec = 0;
687 int b = clock_settime(CLOCK_REALTIME, ¤tTime);
689 logger->log("VDR", Log::DEBUG, "set clock = %u", b);
691 // now make a TZ variable and set it
695 if (vdrTimeOffset > 0) sign = '-';
698 vdrTimeOffset = abs(vdrTimeOffset);
700 hours = (int)vdrTimeOffset / 3600;
701 minutes = vdrTimeOffset % 3600;
703 logger->log("VDR", Log::DEBUG, "%c %i %i", sign, hours, minutes);
705 minutes = (int)minutes / 60;
707 logger->log("VDR", Log::DEBUG, "%c %i %i", sign, hours, minutes);
710 sprintf(newTZ, "MVP%c%i:%i", sign, hours, minutes);
711 setenv("TZ", newTZ, 1);
713 logger->log("VDR", Log::DEBUG, "Timezone data: %s", newTZ);
716 setCharset(Osd::getInstance()->charSet());
721 bool VDR::LogExtern(const char* logString)
723 if (!connected || disconnecting) return false;
724 int stringLength = strlen(logString);
725 int packetLength = stringLength + 8;
726 char *buffer=new char[packetLength + 1];
728 ULONG ul=CHANNEL_NETLOG;
729 buffer[pos++]=(ul>>24)&0xff;
730 buffer[pos++]=(ul>>16)&0xff;
731 buffer[pos++]=(ul>>8)&0xff;
732 buffer[pos++]=ul &0xff;
734 buffer[pos++]=(ul>>24)&0xff;
735 buffer[pos++]=(ul>>16)&0xff;
736 buffer[pos++]=(ul>>8)&0xff;
737 buffer[pos++]=ul &0xff;
739 strcpy(&buffer[8], logString);
741 if (!tcp.write(buffer, packetLength))
744 disconnecting = true; // stop the rest of the connection
745 Control::getInstance()->connectionLost();
752 bool VDR::setCharset(int charset)
754 VDR_RequestPacket vrp;
755 if (!vrp.init(VDR_SETCHARSET, true, sizeof(ULONG))) return false;
756 if (!vrp.addULONG(charset)) return false;
758 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
759 if (vresp->noResponse()) { delete vresp; return false; }
761 ULONG success = vresp->extractULONG();
764 if (!success) return false;
769 bool VDR::getRecordingsList(RecMan* recman)
771 VDR_RequestPacket vrp;
772 if (!vrp.init(VDR_GETRECORDINGLIST, true, 0)) return false;
774 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
775 if (vresp->noResponse()) { delete vresp; return false; }
777 ULONG totalSpace = vresp->extractULONG();
778 ULONG freeSpace = vresp->extractULONG();
779 ULONG percent = vresp->extractULONG();
781 recman->setStats(totalSpace, freeSpace, percent);
788 while (!vresp->end())
790 start = vresp->extractULONG();
791 isNew = vresp->extractUCHAR();
792 name = vresp->extractString();
793 fileName = vresp->extractString();
794 recman->addEntry(isNew, start, name, fileName);
803 int VDR::deleteRecording(char* fileName)
805 VDR_RequestPacket vrp;
806 if (!vrp.init(VDR_DELETERECORDING, true, strlen(fileName) + 1)) return 0;
807 if (!vrp.addString(fileName)) return 0;
809 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
810 if (vresp->noResponse()) { delete vresp; return 0; }
812 int toReturn = static_cast<int>(vresp->extractULONG());
818 int VDR::deleteRecResume(char* fileName)
820 VDR_RequestPacket vrp;
821 if (!vrp.init(VDR_DELETERECRESUME, true, strlen(fileName) + 1)) return 0;
822 if (!vrp.addString(fileName)) return 0;
824 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
825 if (vresp->noResponse()) { delete vresp; return 0; }
827 int toReturn = static_cast<int>(vresp->extractULONG());
833 char* VDR::moveRecording(char* fileName, char* newPath)
835 VDR_RequestPacket vrp;
836 if (!vrp.init(VDR_MOVERECORDING, true, strlen(fileName) + 1 + strlen(newPath) + 1)) return NULL;
837 if (!vrp.addString(fileName)) return NULL;
838 if (!vrp.addString(newPath)) return NULL;
840 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
841 if (vresp->noResponse()) { delete vresp; return NULL; }
843 char* toReturn = NULL;
844 int success = static_cast<int>(vresp->extractULONG());
847 toReturn = vresp->extractString();
855 ChannelList* VDR::getChannelsList(ULONG type)
857 VDR_RequestPacket vrp;
858 if (!vrp.init(VDR_GETCHANNELLIST, true, 0)) return NULL;
860 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
861 if (vresp->noResponse()) { delete vresp; return NULL; }
863 ChannelList* chanList = new ChannelList();
865 bool h264support=Video::getInstance()->supportsh264();
866 bool mpeg2support=Video::getInstance()->supportsmpeg2();
868 while (!vresp->end())
870 Channel* chan = new Channel();
871 chan->number = vresp->extractULONG();
872 chan->type = vresp->extractULONG();
873 chan->name = vresp->extractString();
874 chan->vstreamtype = static_cast<UCHAR>(vresp->extractULONG());
876 if (chan->type == type && ((chan->vstreamtype==0x1b && h264support)|| (chan->vstreamtype!=0x1b &&mpeg2support)) )
878 chanList->push_back(chan);
879 logger->log("VDR", Log::DEBUG, "Have added a channel to list. %lu %lu %s", chan->number, chan->type, chan->name);
880 if (chan->number > maxChannelNumber) maxChannelNumber = chan->number;
890 if (maxChannelNumber > 99999)
891 channelNumberWidth = 6;
892 else if (maxChannelNumber > 9999)
893 channelNumberWidth = 5;
894 else if (maxChannelNumber > 999)
895 channelNumberWidth = 4;
896 else if (maxChannelNumber > 99)
897 channelNumberWidth = 3;
898 else if (maxChannelNumber > 9)
899 channelNumberWidth = 2;
901 channelNumberWidth = 1;
906 int VDR::streamChannel(ULONG number, StreamReceiver* tstreamReceiver)
908 VDR_RequestPacket vrp;
909 if (!vrp.init(VDR_STREAMCHANNEL, true, sizeof(ULONG))) return 0;
910 if (!vrp.addULONG(number)) return 0;
913 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
914 vdrpr->receiverChannel = VDR::CHANNEL_STREAM;
915 vdrpr->streamID = vrp.getSerial();
916 vdrpr->streamReceiver = tstreamReceiver;
918 TEMP_SINGLE_VDR_PR = vdrpr;
920 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
921 if (vresp->noResponse())
929 int toReturn = static_cast<int>(vresp->extractULONG());
930 logger->log("VDR", Log::DEBUG, "VDR said %lu to start streaming request", toReturn);
936 int VDR::stopStreaming()
938 VDR_RequestPacket vrp;
939 if (!vrp.init(VDR_STOPSTREAMING, true, 0)) return 0;
941 if (TEMP_SINGLE_VDR_PR) // this block only needs to be done if it was a live stream
942 // TEMP_SINGLE_VDR_PR will not be set unless we are streaming a channel
944 edUnregister(TEMP_SINGLE_VDR_PR);
945 delete TEMP_SINGLE_VDR_PR;
946 TEMP_SINGLE_VDR_PR = NULL;
949 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
950 if (vresp->noResponse()) { delete vresp; return 0; }
952 int toReturn = static_cast<int>(vresp->extractULONG());
958 UCHAR* VDR::getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived)
960 VDR_RequestPacket vrp;
961 if (!vrp.init(VDR_GETBLOCK, true, sizeof(ULLONG) + sizeof(ULONG))) return NULL;
962 if (!vrp.addULLONG(position)) return NULL;
963 if (!vrp.addULONG(maxAmount)) return NULL;
965 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
966 if (vresp->noResponse()) { delete vresp; return NULL; }
968 if (vresp->serverError())
970 logger->log("VDR", Log::DEBUG, "Detected getblock 0");
976 // Special handling for getblock
977 UCHAR* toReturn = vresp->getUserData();
978 *amountReceived = vresp->getUserDataLength();
985 ULLONG VDR::streamRecording(char* fileName, ULONG* totalFrames, bool* IsPesRecording)
987 VDR_RequestPacket vrp;
988 if (!vrp.init(VDR_STREAMRECORDING, true, strlen(fileName) + 1)) return 0;
989 if (!vrp.addString(fileName)) return 0;
991 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
992 if (vresp->noResponse()) { delete vresp; return 0; }
994 ULLONG lengthBytes = vresp->extractULLONG();
995 ULONG lengthFrames = vresp->extractULONG();
996 UCHAR isPesRecording = vresp->extractUCHAR();
999 *totalFrames = lengthFrames;
1000 *IsPesRecording = (isPesRecording);//convert Uchar to bool
1002 logger->log("VDR", Log::DEBUG, "VDR said length is: %llu %lu, IsPesRecording %x", lengthBytes, lengthFrames, *IsPesRecording);
1007 ULLONG VDR::positionFromFrameNumber(ULONG frameNumber)
1009 VDR_RequestPacket vrp;
1010 if (!vrp.init(VDR_POSFROMFRAME, true, sizeof(ULONG))) return 0;
1011 if (!vrp.addULONG(frameNumber)) return 0;
1013 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1014 if (vresp->noResponse()) { delete vresp; return 0; }
1016 ULLONG position = vresp->extractULLONG();
1019 logger->log("VDR", Log::DEBUG, "VDR said new position is: %llu", position);
1024 ULONG VDR::frameNumberFromPosition(ULLONG position)
1026 VDR_RequestPacket vrp;
1027 if (!vrp.init(VDR_FRAMEFROMPOS, true, sizeof(ULLONG))) return 0;
1028 if (!vrp.addULLONG(position)) return 0;
1030 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1031 if (vresp->noResponse()) { delete vresp; return 0; }
1033 ULONG framenumber = vresp->extractULONG();
1036 logger->log("VDR", Log::DEBUG, "VDR said new framenumber is: %u", framenumber);
1041 bool VDR::getNextIFrame(ULONG frameNumber, ULONG direction, ULLONG* rfilePosition, ULONG* rframeNumber, ULONG* rframeLength)
1043 VDR_RequestPacket vrp;
1044 if (!vrp.init(VDR_GETNEXTIFRAME, true, sizeof(ULONG)*2)) return false;
1045 if (!vrp.addULONG(frameNumber)) return false;
1046 if (!vrp.addULONG(direction)) return false;
1048 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1049 if (vresp->noResponse()) { delete vresp; return false; }
1051 if (vresp->serverError())
1053 logger->log("VDR", Log::DEBUG, "Detected getNextIFrame error");
1058 *rfilePosition = vresp->extractULLONG();
1059 *rframeNumber = vresp->extractULONG();
1060 *rframeLength = vresp->extractULONG();
1064 logger->log("VDR", Log::DEBUG, "VDR GNIF said %llu %lu %lu", *rfilePosition, *rframeNumber, *rframeLength);
1069 EventList* VDR::getChannelSchedule(ULONG number)
1073 return getChannelSchedule(number, now, 24 * 60 * 60);
1076 EventList* VDR::getChannelSchedule(ULONG number, time_t start, ULONG duration)
1078 // retrieve event list (vector of events) from vdr within filter window. duration is in seconds
1080 VDR_RequestPacket vrp;
1081 if (!vrp.init(VDR_GETCHANNELSCHEDULE, true, sizeof(ULONG)*3)) return NULL;
1082 if (!vrp.addULONG(number)) return NULL;
1083 if (!vrp.addULONG(start)) return NULL;
1084 if (!vrp.addULONG(duration)) return NULL;
1086 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1087 if (vresp->noResponse()) { delete vresp; return NULL; }
1089 // received a ulong(0) - schedules error in the plugin
1090 if (vresp->serverError())
1096 EventList* eventList = new EventList();
1098 while (!vresp->end())
1100 Event* event = new Event();
1101 event->id = vresp->extractULONG();
1102 event->time = vresp->extractULONG();
1103 event->duration = vresp->extractULONG();
1104 event->title = vresp->extractString();
1105 event->subtitle = vresp->extractString();
1106 event->description = vresp->extractString();
1107 eventList->push_back(event);
1112 logger->log("VDR", Log::DEBUG, "Success got to end of getChannelSchedule");
1116 int VDR::configSave(const char* section, const char* key, const char* value)
1118 VDR_RequestPacket vrp;
1119 if (!vrp.init(VDR_CONFIGSAVE, false, 0)) return 0;
1120 if (!vrp.addString(section)) return 0;
1121 if (!vrp.addString(key)) return 0;
1122 if (!vrp.addString(value)) return 0;
1124 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1125 if (vresp->noResponse()) { delete vresp; return 0; }
1127 int toReturn = static_cast<int>(vresp->extractULONG());
1133 char* VDR::configLoad(const char* section, const char* key)
1135 VDR_RequestPacket vrp;
1136 if (!vrp.init(VDR_CONFIGLOAD, false, 0)) return NULL;
1137 if (!vrp.addString(section)) return NULL;
1138 if (!vrp.addString(key)) return NULL;
1140 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1141 if (vresp->noResponse()) { delete vresp; return NULL; }
1143 char* toReturn = vresp->extractString();
1149 RecTimerList* VDR::getRecTimersList()
1151 VDR_RequestPacket vrp;
1152 if (!vrp.init(VDR_GETTIMERS, true, 0)) return NULL;
1154 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1155 if (vresp->noResponse()) { delete vresp; return NULL; }
1157 RecTimerList* recTimerList = new RecTimerList();
1159 ULONG numTimers = vresp->extractULONG();
1162 RecTimer* newRecTimer;
1165 while (!vresp->end())
1167 newRecTimer = new RecTimer();
1168 newRecTimer->active = vresp->extractULONG();
1169 newRecTimer->recording = vresp->extractULONG();
1170 newRecTimer->pending = vresp->extractULONG();
1171 newRecTimer->priority = vresp->extractULONG();
1172 newRecTimer->lifeTime = vresp->extractULONG();
1173 newRecTimer->channelNumber = vresp->extractULONG();
1174 newRecTimer->startTime = vresp->extractULONG();
1175 newRecTimer->stopTime = vresp->extractULONG();
1176 newRecTimer->day = vresp->extractULONG();
1177 newRecTimer->weekDays = vresp->extractULONG();
1179 tempString = vresp->extractString();
1180 newRecTimer->setFile(tempString);
1181 delete[] tempString;
1183 recTimerList->push_back(newRecTimer);
1184 logger->log("VDR", Log::DEBUG, "TL: %lu %lu %lu %lu %lu %lu %lu %lu %s",
1185 newRecTimer->active, newRecTimer->recording, newRecTimer->pending, newRecTimer->priority, newRecTimer->lifeTime,
1186 newRecTimer->channelNumber, newRecTimer->startTime, newRecTimer->stopTime, newRecTimer->getFile());
1192 sort(recTimerList->begin(), recTimerList->end(), RecTimerSorter());
1194 return recTimerList;
1197 ULONG VDR::setEventTimer(char* timerString)
1199 VDR_RequestPacket vrp;
1200 if (!vrp.init(VDR_SETTIMER, true, strlen(timerString) + 1)) return 0;
1201 if (!vrp.addString(timerString)) return 0;
1203 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1204 if (vresp->noResponse()) { delete vresp; return 0; }
1206 ULONG toReturn = vresp->extractULONG();
1212 RecInfo* VDR::getRecInfo(char* fileName)
1214 VDR_RequestPacket vrp;
1215 if (!vrp.init(VDR_GETRECINFO2, true, strlen(fileName) + 1)) return NULL;
1216 if (!vrp.addString(fileName)) return NULL;
1217 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1219 if (vresp->noResponse()) { delete vresp; return NULL; }
1221 if (vresp->serverError())
1223 logger->log("VDR", Log::DEBUG, "Could not get rec info");
1228 RecInfo* recInfo = new RecInfo();
1230 recInfo->timerStart = vresp->extractULONG();
1231 recInfo->timerEnd = vresp->extractULONG();
1232 recInfo->resumePoint = vresp->extractULONG();
1233 recInfo->summary = vresp->extractString();
1235 ULONG numComponents = vresp->extractULONG();
1238 recInfo->setNumComponents(numComponents);
1239 for (ULONG i = 0; i < numComponents; i++)
1241 recInfo->streams[i] = vresp->extractUCHAR();
1242 recInfo->types[i] = vresp->extractUCHAR();
1243 recInfo->languages[i] = vresp->extractString();
1244 recInfo->descriptions[i] = vresp->extractString();
1247 recInfo->fps=vresp->extractdouble();
1248 recInfo->title=vresp->extractString();
1251 recInfo->channelName = vresp->extractString();
1252 recInfo->duration = vresp->extractULONG();
1253 recInfo->fileSize = vresp->extractULONG();
1254 recInfo->priority = vresp->extractULONG();
1255 recInfo->lifetime = vresp->extractULONG();
1264 ULLONG VDR::rescanRecording(ULONG* totalFrames)
1266 VDR_RequestPacket vrp;
1267 if (!vrp.init(VDR_RESCANRECORDING, true, 0)) return 0;
1269 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1270 if (vresp->noResponse()) { delete vresp; return 0; }
1272 ULLONG lengthBytes = vresp->extractULLONG();
1273 ULONG lengthFrames = vresp->extractULONG();
1276 logger->log("VDR", Log::DEBUG, "VDR said length is: %llu %lu", lengthBytes, lengthFrames);
1278 *totalFrames = lengthFrames;
1282 MarkList* VDR::getMarks(char* fileName)
1284 VDR_RequestPacket vrp;
1285 if (!vrp.init(VDR_GETMARKS, true, strlen(fileName) + 1)) return NULL;
1286 if (!vrp.addString(fileName)) return NULL;
1288 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1289 if (vresp->noResponse()) { delete vresp; return NULL; }
1291 if (vresp->serverError())
1297 MarkList* markList = new MarkList();
1299 while (!vresp->end())
1301 Mark* mark = new Mark();
1302 mark->pos = vresp->extractULONG();
1304 markList->push_back(mark);
1305 logger->log("VDR", Log::DEBUG, "Have added a mark to list. %lu", mark->pos);
1313 void VDR::getChannelPids(Channel* channel)
1315 VDR_RequestPacket vrp;
1316 if (!vrp.init(VDR_GETCHANNELPIDS, true, sizeof(ULONG))) return ;
1317 if (!vrp.addULONG(channel->number)) return ;
1319 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1320 if (vresp->noResponse()) { delete vresp; return ; }
1322 // Format of response
1330 channel->vpid = vresp->extractULONG();
1331 channel->vstreamtype = static_cast<UCHAR>(vresp->extractULONG());
1332 channel->numAPids = vresp->extractULONG();
1334 for (ULONG i = 0; i < channel->numAPids; i++)
1337 newapid.pid = vresp->extractULONG();
1338 char * name=vresp->extractString();
1339 strncpy(newapid.desc,name,9);
1341 channel->apids.push_back(newapid);
1344 channel->numDPids = vresp->extractULONG();
1346 for (ULONG i = 0; i < channel->numDPids; i++)
1349 newdpid.pid = vresp->extractULONG();
1350 char * name=vresp->extractString();
1351 strncpy(newdpid.desc,name,9);
1353 channel->dpids.push_back(newdpid);
1356 channel->numSPids = vresp->extractULONG();
1358 for (ULONG i = 0; i < channel->numSPids; i++)
1361 newspid.pid = vresp->extractULONG();
1362 char * name=vresp->extractString();
1363 strncpy(newspid.desc,name,9);
1365 channel->spids.push_back(newspid);
1367 channel->tpid = vresp->extractULONG();
1369 for (ULONG i = 0; i < channel->numAPids; i++)
1371 channel->apids[i].type = vresp->extractULONG();
1373 for (ULONG i = 0; i < channel->numDPids; i++)
1375 channel->dpids[i].type = vresp->extractULONG();
1377 for (ULONG i = 0; i < channel->numSPids; i++)
1379 channel->spids[i].type = vresp->extractULONG();
1380 channel->spids[i].data1 = vresp->extractULONG();
1381 channel->spids[i].data2 = vresp->extractULONG();
1389 #ifdef VOMP_MEDIAPLAYER
1390 MediaList * VDR::getRootList() {
1391 return getMediaList(NULL);
1394 * media List Request:
1396 * Media List response:
1399 MediaList* VDR::getMediaList(const MediaURI * root)
1401 logger->log("VDR", Log::DEBUG, "getMediaList %s,d=%s, prov=%d", (root?root->getName():"NULL"),
1402 ((root && root->hasDisplayName())?root->getDisplayName():"NULL"),
1403 (root?root->getProvider():providerId));
1404 MediaURI remoteURI(root);
1405 VDR_GetMediaListRequest request(&remoteURI);
1406 SerializeBuffer *vrp=prepareRequest(&request);
1408 logger->log("VDR", Log::ERR, "getMediaList unable to create command");
1412 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1414 Control::getInstance()->connectionLost();
1418 MediaList *rt=new MediaList(NULL);
1420 VDR_GetMediaListResponse resp(&rtflags,rt);
1421 if (decodeResponse(vresp,&resp) != 0) {
1428 * get image Request:
1430 * get media response:
1434 int VDR::openMedium(ULONG channel,const MediaURI *uri, ULLONG * size, ULONG x, ULONG y)
1436 MediaURI remoteURI(uri);
1437 VDR_OpenMediumRequest request(&channel,&remoteURI,&x,&y);
1439 SerializeBuffer *vrp=prepareRequest(&request);
1441 logger->log("VDR", Log::ERR, "openMedium unable to create command");
1444 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1446 Control::getInstance()->connectionLost();
1450 VDR_OpenMediumResponse response(&flags,size);
1451 if (decodeResponse(vresp,&response) != 0) {
1454 logger->log("VDR", Log::DEBUG, "openMedia len=%llu", *size);
1459 * getMediaBlock - no separate response class - simple data block
1463 int VDR::getMediaBlock(ULONG channel, ULLONG position, ULONG maxAmount, ULONG* amountReceived, unsigned char **buffer)
1466 VDR_GetMediaBlockRequest request(&channel,&position,&maxAmount);
1467 SerializeBuffer *vrp=prepareRequest(&request);
1469 logger->log("VDR", Log::ERR, "getMediaBlock unable to create command");
1472 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1474 Control::getInstance()->connectionLost();
1478 // Special handling for getblock
1479 *amountReceived = (ULONG)(vresp->getEnd()-vresp->getStart());
1480 *buffer = vresp->steelBuffer();
1493 int VDR::getMediaInfo(ULONG channel, MediaInfo * result) {
1494 if (! result) return -1;
1495 VDR_GetMediaInfoRequest request(&channel);
1496 SerializeBuffer *vrp=prepareRequest(&request);
1498 logger->log("VDR", Log::ERR, "getMediaInfo unable to create command");
1501 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1503 Control::getInstance()->connectionLost();
1508 VDR_GetMediaInfoResponse response(&flags,result);
1509 if (decodeResponse(vresp,&response) != 0) {
1522 int VDR::closeMediaChannel(ULONG channel) {
1523 VDR_CloseMediaChannelRequest request(&channel);
1524 SerializeBuffer *vrp=prepareRequest(&request);
1526 logger->log("VDR", Log::ERR, "closeMediaChannel unable to create command");
1529 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1531 Control::getInstance()->connectionLost();
1535 VDR_CloseMediaChannelResponse response(&flags);
1536 if (decodeResponse(vresp,&response) != 0) return -1;
1537 return (flags != 0)?-1:0;
1543 int VDR::deleteTimer(RecTimer* delTimer)
1545 logger->log("VDR", Log::DEBUG, "Delete timer called");
1547 VDR_RequestPacket vrp;
1548 if (!vrp.init(VDR_DELETETIMER, false, 0)) return 0;
1549 if (!vrp.addULONG(delTimer->channelNumber)) return 0;
1550 if (!vrp.addULONG(delTimer->weekDays)) return 0;
1551 if (!vrp.addULONG(delTimer->day)) return 0;
1552 if (!vrp.addULONG(delTimer->startTime)) return 0;
1553 if (!vrp.addULONG(delTimer->stopTime)) return 0;
1555 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1556 if (vresp->noResponse()) { delete vresp; return 0; }
1558 int toReturn = static_cast<int>(vresp->extractULONG());
1564 I18n::lang_code_list VDR::getLanguageList()
1566 I18n::lang_code_list CodeList;
1567 CodeList["en"] = "English"; // Default entry
1568 VDR_RequestPacket vrp;
1569 if (!vrp.init(VDR_GETLANGUAGELIST, false, 0)) return CodeList;
1570 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1571 if (vresp->noResponse() || vresp->end())
1577 while (!vresp->end())
1579 char* c_code = vresp->extractString();
1580 char* c_name = vresp->extractString();
1581 std::string code = c_code;
1582 std::string name = c_name;
1583 CodeList[code] = name;
1591 int VDR::getLanguageContent(const std::string code, I18n::trans_table& texts)
1593 VDR_RequestPacket vrp;
1594 if (!vrp.init(VDR_GETLANGUAGECONTENT, false, 0)) return 0;
1595 if (!vrp.addString(code.c_str())) return 0;
1596 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1597 if (vresp->noResponse()) { delete vresp; return 0; }
1599 while (!vresp->end())
1601 char* c_key = vresp->extractString();
1602 char* c_text = vresp->extractString();
1603 std::string key = c_key;
1604 std::string text = c_text;
1613 void VDR::shutdownVDR()
1616 logger->log("VDR", Log::DEBUG, "Shutting down vdr");
1618 logger->log("VDR", Log::DEBUG, "Shutting down vomp only");
1620 if(!doVDRShutdown || !connected || disconnecting)
1623 VDR_RequestPacket vrp;
1624 logger->log("VDR", Log::DEBUG, "Sending shutdown");
1625 if (!vrp.init(VDR_SHUTDOWN, false, 0)) return;
1626 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1629 logger->log("VDR", Log::DEBUG, "VDR shutdown");
1632 void VDR::getScraperEventType(char * fileName, int & movieID,
1633 int & seriesID, int & episodeID)
1638 VDR_RequestPacket vrp;
1639 if (!vrp.init(VDR_GETRECSCRAPEREVENTTYPE, true, strlen(fileName) + 1)) return;
1640 if (!vrp.addString(fileName)) return ;
1641 Log::getInstance()->log("Recording", Log::DEBUG, "Before Response ");
1642 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1643 Log::getInstance()->log("Recording", Log::DEBUG, "After Response ");
1644 if (vresp->noResponse()) { delete vresp; return ; }
1645 int type = vresp->extractUCHAR();
1646 if (type == 0) //serie
1648 seriesID = vresp->extractLONG();
1649 episodeID = vresp->extractLONG();
1650 } else if (type == 1) //movie
1652 movieID = vresp->extractLONG();
1658 void VDR::getScraperEventType(UINT channelid, UINT eventid, int & movieID,
1659 int & seriesID, int & episodeID, int & epgImage )
1665 VDR_RequestPacket vrp;
1666 if (!vrp.init(VDR_GETEVENTSCRAPEREVENTTYPE, false, 0)) return;
1667 if (!vrp.addULONG(channelid)) return ;
1668 if (!vrp.addULONG(eventid)) return ;
1669 Log::getInstance()->log("Recording", Log::DEBUG, "Before Response ");
1670 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1671 Log::getInstance()->log("Recording", Log::DEBUG, "After Response ");
1672 if (vresp->noResponse()) { delete vresp; return ; }
1673 int type = vresp->extractUCHAR();
1674 if (type == 0) //serie
1676 seriesID = vresp->extractLONG();
1677 episodeID = vresp->extractLONG();
1678 } else if (type == 1) //movie
1680 movieID = vresp->extractLONG();
1682 epgImage = vresp->extractLONG();
1687 MovieInfo *VDR::getScraperMovieInfo(int movieID)
1689 VDR_RequestPacket vrp;
1690 if (!vrp.init(VDR_GETSCRAPERMOVIEINFO, false, 0)) return NULL;
1691 if (!vrp.addULONG(movieID)) return NULL;
1692 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1693 if (vresp->noResponse()) { delete vresp; return NULL; }
1694 MovieInfo * movieinf= new MovieInfo();
1696 movieinf->id=movieID;
1697 movieinf->title = vresp->extractStdString();
1698 movieinf->originalTitle = vresp->extractStdString();
1699 movieinf->tagline = vresp->extractStdString();
1700 movieinf->overview = vresp->extractStdString();
1701 movieinf->adult = vresp->extractUCHAR();
1702 movieinf->collectionName = vresp->extractStdString();
1704 movieinf->budget = vresp->extractLONG();
1705 movieinf->revenue = vresp->extractLONG();
1706 movieinf->genres = vresp->extractStdString();
1707 movieinf->homepage = vresp->extractStdString();
1708 movieinf->releaseDate = vresp->extractStdString();
1709 movieinf->runtime = vresp->extractLONG();
1710 movieinf->popularity = vresp->extractdouble();
1711 movieinf->voteAverage = vresp->extractdouble();
1712 movieinf->poster.width = vresp->extractULONG();
1713 movieinf->poster.height = vresp->extractULONG();
1714 movieinf->poster.info.setMovieInfo(movieinf);
1715 movieinf->poster.info.setElement(0,0);
1716 movieinf->fanart.width = vresp->extractULONG();
1717 movieinf->fanart.height = vresp->extractULONG();
1718 movieinf->fanart.info.setMovieInfo(movieinf);
1719 movieinf->fanart.info.setElement(1,0);
1720 movieinf->collectionPoster.width = vresp->extractULONG();
1721 movieinf->collectionPoster.height = vresp->extractULONG();
1722 movieinf->collectionPoster.info.setMovieInfo(movieinf);
1723 movieinf->collectionPoster.info.setElement(2,0);
1724 movieinf->collectionFanart.width = vresp->extractULONG();
1725 movieinf->collectionFanart.height = vresp->extractULONG();
1726 movieinf->collectionFanart.info.setMovieInfo(movieinf);
1727 movieinf->collectionFanart.info.setElement(3,0);
1728 ULONG num_actors = vresp->extractULONG();
1729 movieinf->actors.clear();
1730 movieinf->actors.reserve(num_actors);
1731 for (ULONG acty=0; acty < num_actors; acty++) {
1733 new_act.name = vresp->extractStdString();
1734 new_act.role = vresp->extractStdString();
1735 new_act.thumb.width = vresp->extractULONG();
1736 new_act.thumb.height = vresp->extractULONG();
1737 new_act.thumb.info.setMovieInfo(movieinf);
1738 new_act.thumb.info.setElement(4,acty);
1739 movieinf->actors.push_back(new_act);
1748 SeriesInfo *VDR::getScraperSeriesInfo(int seriesID, int episodeID)
1750 VDR_RequestPacket vrp;
1751 if (!vrp.init(VDR_GETSCRAPERSERIESINFO, false, 0)) return NULL;
1752 if (!vrp.addULONG(seriesID)) return NULL;
1753 if (!vrp.addULONG(episodeID)) return NULL;
1755 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1756 if (vresp->noResponse()) { delete vresp; return 0; }
1757 SeriesInfo * seriesinf= new SeriesInfo();
1759 seriesinf->id=seriesID;
1762 seriesinf->name = vresp->extractStdString();
1763 seriesinf->overview = vresp->extractStdString();
1764 seriesinf->firstAired = vresp->extractStdString();
1765 seriesinf->network = vresp->extractStdString();
1766 seriesinf->genre = vresp->extractStdString();
1767 seriesinf->rating = vresp->extractdouble();
1768 seriesinf->status = vresp->extractStdString();
1771 seriesinf->episode.episodeid=episodeID;
1772 seriesinf->episode.number = vresp->extractLONG();
1773 seriesinf->episode.season = vresp->extractLONG();
1774 seriesinf->episode.name = vresp->extractStdString();
1775 seriesinf->episode.firstAired = vresp->extractStdString();
1776 seriesinf->episode.guestStars = vresp->extractStdString();
1777 seriesinf->episode.overview = vresp->extractStdString();
1778 seriesinf->episode.rating = vresp->extractdouble();
1779 seriesinf->episode.image.width = vresp->extractULONG();
1780 seriesinf->episode.image.height = vresp->extractULONG();
1781 seriesinf->episode.image.info.setSeriesInfo(seriesinf);
1782 seriesinf->episode.image.info.setElement(0,0);
1785 ULONG num_actors = vresp->extractULONG();
1786 seriesinf->actors.clear();
1787 seriesinf->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.setSeriesInfo(seriesinf);
1795 new_act.thumb.info.setElement(1,acty);
1796 seriesinf->actors.push_back(new_act);
1798 ULONG num_posters = vresp->extractULONG();
1799 for (ULONG medias = 0; medias < num_posters; medias++ ) {
1801 media.info.setSeriesInfo(seriesinf);
1802 media.info.setElement(2,medias);
1803 media.width = vresp->extractULONG();
1804 media.height = vresp->extractULONG();
1805 seriesinf->posters.push_back(media);
1808 ULONG num_banners = vresp->extractULONG();
1809 for (ULONG medias = 0; medias < num_banners; medias++ ) {
1811 media.info.setSeriesInfo(seriesinf);
1812 media.info.setElement(3,medias);
1813 media.width = vresp->extractULONG();
1814 media.height = vresp->extractULONG();
1815 seriesinf->banners.push_back(media);
1817 ULONG num_fanarts = vresp->extractULONG();
1818 for (ULONG medias = 0; medias < num_fanarts; medias++ ) {
1820 media.info.setSeriesInfo(seriesinf);
1821 media.info.setElement(4,medias);
1822 media.width = vresp->extractULONG();
1823 media.height = vresp->extractULONG();
1824 seriesinf->fanart.push_back(media);
1826 seriesinf->seasonposter.width = vresp->extractULONG();
1827 seriesinf->seasonposter.height = vresp->extractULONG();
1828 seriesinf->seasonposter.info.setSeriesInfo(seriesinf);
1829 seriesinf->seasonposter.info.setElement(5,0);
1836 ULONG VDR::loadTVMedia(TVMediaInfo& tvmedia)
1838 VDR_RequestPacket vrp;
1840 if (!vrp.init(VDR_LOADTVMEDIA, false, 0)) return ULONG_MAX;
1841 if (!vrp.addULONG(tvmedia.type)) return ULONG_MAX;
1842 if (!vrp.addULONG(tvmedia.primary_id)) return ULONG_MAX;
1843 if (!vrp.addULONG(tvmedia.secondary_id)) return ULONG_MAX;
1844 if (!vrp.addULONG(tvmedia.type_pict)) return ULONG_MAX;
1845 if (!vrp.addULONG(tvmedia.container)) return ULONG_MAX;
1846 if (!vrp.addULONG(tvmedia.container_member)) return ULONG_MAX;
1847 /* Log::getInstance()->log("VDR", Log::DEBUG, "TVMedia with ID %d %d; %d %d %d %d;%d",
1848 tvmedia.primary_id,tvmedia.secondary_id,tvmedia.type,tvmedia.type_pict,
1849 tvmedia.container,tvmedia.container_member,vrp.getSerial());*/
1852 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
1853 vdrpr->receiverChannel = VDR::CHANNEL_TVMEDIA;
1854 vdrpr->streamID = vrp.getSerial();
1855 vdrpr->streamReceiver = NULL;
1859 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1860 //if (vresp->noResponse()) { delete vresp; return ULONG_MAX; }
1863 return vrp.getSerial();
1866 ULONG VDR::loadTVMediaRecThumb(TVMediaInfo & media)
1869 VDR_RequestPacket vrp;
1871 if (!vrp.init(VDR_LOADTVMEDIARECTHUMB, false, 0)) return ULONG_MAX;
1872 if (!vrp.addString(media.primary_name.c_str())) return ULONG_MAX;
1874 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
1875 vdrpr->receiverChannel = VDR::CHANNEL_TVMEDIA;
1876 vdrpr->streamID = vrp.getSerial();
1877 vdrpr->streamReceiver = NULL;
1881 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1882 //if (vresp->noResponse()) { delete vresp; return ULONG_MAX; }
1885 return vrp.getSerial();
1888 ULONG VDR::loadTVMediaEventThumb(TVMediaInfo & media)
1891 VDR_RequestPacket vrp;
1893 if (!vrp.init(VDR_LOADTVMEDIAEVENTTHUMB, false, 0)) return ULONG_MAX;
1894 if (!vrp.addULONG(media.primary_id)) return ULONG_MAX;
1895 if (!vrp.addULONG(media.secondary_id)) return ULONG_MAX;
1897 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
1898 vdrpr->receiverChannel = VDR::CHANNEL_TVMEDIA;
1899 vdrpr->streamID = vrp.getSerial();
1900 vdrpr->streamReceiver = NULL;
1904 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1905 //if (vresp->noResponse()) { delete vresp; return ULONG_MAX; }
1908 return vrp.getSerial();
1911 ULONG VDR::loadChannelLogo(TVMediaInfo & media)
1914 VDR_RequestPacket vrp;
1916 if (!vrp.init(VDR_LOADCHANNELLOGO, false, 0)) return ULONG_MAX;
1917 if (!vrp.addULONG(media.primary_id)) return ULONG_MAX;
1919 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
1920 vdrpr->receiverChannel = VDR::CHANNEL_TVMEDIA;
1921 vdrpr->streamID = vrp.getSerial();
1922 vdrpr->streamReceiver = NULL;
1926 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1927 //if (vresp->noResponse()) { delete vresp; return ULONG_MAX; }
1930 // Log::getInstance()->log("VDR", Log::DEBUG, "TVMedia Channel Logo %d %x",
1931 // media.primary_id,vrp.getSerial());
1933 return vrp.getSerial();