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 static const char* TAG = "VDR";
47 #define VOMP_PROTOCOL_VERSION 0x00000500
49 VDR* VDR::instance = NULL;
50 #ifdef VOMP_MEDIAPLAYER
52 //will create a request package from a command variable and fill this
53 //caller has to destroy buffer
54 static SerializeBuffer * prepareRequest(VDR_Command *cmd) {
55 SerializeBuffer *buf=new SerializeBuffer(512,false,true);
56 if (cmd->serialize(buf) != 0) {
63 //handle request/response
64 //TODO avoid copy of buffer (needs extension of requestpacket)
65 //TODO avoid command 2x (needs some more restructuring)
66 SerializeBuffer * VDR::doRequestResponse(SerializeBuffer *rq,int cmd) {
67 VDR_RequestPacket *rt=new VDR_RequestPacket;
72 if (! rt->init(cmd,true,rq->getCurrent()-rq->getStart())) {
77 if (! rt->copyin(rq->getStart(),(ULONG)(rq->getCurrent()-rq->getStart()))) {
83 VDR_ResponsePacket *rp=RequestResponse(rt);
84 logger->debug(TAG, "Got response {}", (void*)rp);
89 SerializeBuffer *buf=new SerializeBuffer(rp->getUserData(),rp->getUserDataLength(),true,true,false);
94 //deserialize a received response
97 static int decodeResponse(SerializeBuffer *rp,VDR_Command *c) {
98 ULONG expected=c->command;
99 if (c->deserialize(rp) != 0) {
101 Log::getInstance()->error(TAG, "decodeResponse unable to deserialize for command {}", expected);
105 if (c->command != expected) {
106 Log::getInstance()->error(TAG, "decodeResponse unexpected response received {:#x}, expected {:#x}", c->command, expected);
109 Log::getInstance()->error(TAG, "decodeResponse successfully decoded command {:#x}", expected);
117 if (instance) return;
120 TEMP_SINGLE_VDR_PR = NULL; // FIXME what is this
121 #ifdef VOMP_MEDIAPLAYER
122 providerId=MPROVIDERID_VDR;
123 subRange=MPROVIDERRANGE_VDR;
124 MediaPlayerRegister::getInstance()->registerMediaProvider(this,MPROVIDERID_VDR,MPROVIDERRANGE_VDR);
131 if (initted) shutdown();
134 VDR* VDR::getInstance()
141 if (initted) return 0;
143 logger = LogNT::getInstance();
150 if (!initted) return 0;
156 void VDR::setServerIP(const char* newIP)
158 strcpy(serverIP, newIP);
161 void VDR::setServerPort(USHORT newPort)
163 serverPort = newPort;
169 maxChannelNumber = 0;
170 channelNumberWidth = 1;
172 connectStateMutex.lock();
173 if (connecting || connected) return true;
175 connectStateMutex.unlock(); // now I have connecting
177 bool connectResult = tcp.connect(serverIP, serverPort);
179 connectStateMutex.lock(); // connected = false, connecting = true, babortConnect = ?
184 if (connectResult) tcp.shutdown();
185 babortConnect = false;
186 connectStateMutex.unlock();
194 threadStartProtect.lock();
195 vdrThread = std::thread( [this]
197 threadStartProtect.lock();
198 threadStartProtect.unlock();
201 threadStartProtect.unlock();
203 connectStateMutex.unlock();
208 connectStateMutex.unlock();
213 void VDR::abortConnect() // If there is one, force a running connect call to abort
215 connectStateMutex.lock();
219 babortConnect = true;
223 connectStateMutex.unlock();
226 void VDR::disconnect()
228 std::lock_guard<std::mutex> lg(connectStateMutex);
230 if (!connected) return;
232 if (vdrThread.joinable())
234 threadReqStop = true;
237 threadReqStop = false;
242 disconnecting = false;
244 logger->debug(TAG, "Disconnect");
247 void VDR::setReceiveWindow(size_t size)
249 //if (connected && size) tcpold->setReceiveWindow(size);
252 ///////////////////////////////////////////////////////
254 void VDR::threadMethod()
256 logger->debug(TAG, "VDR RUN");
261 ULONG userDataLength;
267 VDR_ResponsePacket* vresp;
270 ULONG lastKAsent = 0;
271 ULONG lastKArecv = time(NULL);
276 readSuccess = tcp.read(&channelID, sizeof(ULONG));
277 if (threadReqStop) return;
278 timeNow = time(NULL);
282 //logger->debug(TAG, "Net read timeout");
283 if (!tcp.status()) { connectionDied(); return; } // return to stop this thread
286 if (!lastKAsent) // have not sent a KA
288 if (lastKArecv < (timeNow - 5))
290 //logger->debug(TAG, "Sending KA packet");
291 if (!sendKA(timeNow))
293 logger->debug(TAG, "Could not send KA, calling connectionDied");
297 lastKAsent = timeNow;
299 if (threadReqStop) return;
304 if (lastKAsent <= (timeNow - 10))
306 logger->debug(TAG, "lastKA over 10s ago, calling connectionDied");
312 if (!readSuccess) continue; // no data was read but the connection is ok.
316 channelID = ntohl(channelID);
318 if (channelID == CHANNEL_REQUEST_RESPONSE)
320 if (!tcp.read(&requestID, sizeof(ULONG))) break;
321 if (threadReqStop) return;
322 requestID = ntohl(requestID);
323 if (!tcp.read(&userDataLength, sizeof(ULONG))) break;
324 if (threadReqStop) return;
325 userDataLength = ntohl(userDataLength);
326 if (userDataLength > 5000000) break; // how big can these packets get?
328 if (userDataLength > 0)
330 userData = malloc(userDataLength);
331 if (!userData) break;
332 if (!tcp.read(userData, userDataLength))
345 vresp = new VDR_ResponsePacket();
346 vresp->setResponse(requestID, reinterpret_cast<UCHAR*>(userData), userDataLength);
347 // vresp now owns userData unless something calls vresp->getUserData()
348 // logger->debug(TAG, "Rxd a response packet, requestID={}, len={}", requestID, userDataLength);
350 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
352 // If edFindAndCall returns true, edr was called and vresp was handed off.
353 // else, delete vresp here.
356 if (threadReqStop) return;
358 else if (channelID == CHANNEL_STREAM || channelID == CHANNEL_TVMEDIA)
360 if (!tcp.read(&streamID, sizeof(ULONG))) break;
361 if (threadReqStop) return;
362 streamID = ntohl(streamID);
364 if (!tcp.read(&flag, sizeof(ULONG))) break;
365 if (threadReqStop) return;
368 if (!tcp.read(&userDataLength, sizeof(ULONG))) break;
369 if (threadReqStop) return;
370 userDataLength = ntohl(userDataLength);
372 if (userDataLength > 0)
374 userData = malloc(userDataLength);
375 if (!userData) break;
376 if (!tcp.read(userData, userDataLength))
389 vresp = new VDR_ResponsePacket();
390 vresp->setStream(streamID, flag, reinterpret_cast<UCHAR*>(userData), userDataLength, channelID);
391 //logger->debug(TAG, "Rxd a stream packet, streamID={}, flag={}, len={}", streamID, flag, userDataLength);
393 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
395 // If edFindAndCall returns true, edr was called and vresp was handed off.
396 // else, delete vresp here.
400 if (threadReqStop) return;
402 else if (channelID == CHANNEL_KEEPALIVE)
405 if (!tcp.read(&KAreply, sizeof(ULONG))) break;
406 if (threadReqStop) return;
407 KAreply = ntohl(KAreply);
408 if (KAreply == lastKAsent) // successful KA response
411 lastKArecv = KAreply;
412 //logger->debug(TAG, "Rxd correct KA reply");
417 logger->error(TAG, "Rxd a response packet on channel {} !!", channelID);
421 // Who deletes vresp?
422 // If RR, the individual protocol functions must delete vresp.
423 // If stream, the data and length is taken out in ed_cb_call and vresp is deleted there.
429 void VDR::connectionDied()
431 // Called from within threadMethod to do cleanup if it decides the connection has died
433 disconnecting = true;
435 // Need to wake up any waiting channel 1 request-response threads
436 // Normally this is done by a packet coming in with channelid and requestid
437 // Instead, go through the list and for each channel 1 edr, make an empty vresp
438 // An empty vresp will have userData == NULL, which means vresp->noResponse() == true
440 // If it's a stream receiver, generate a stream packet with flag == connection_lost
443 VDR_PacketReceiver* vdrpr;
444 VDR_ResponsePacket* vresp;
445 while(receivers.size())
447 vdrpr = dynamic_cast<VDR_PacketReceiver*>(*(receivers.begin()));
448 if (vdrpr->receiverChannel == CHANNEL_REQUEST_RESPONSE)
450 vresp = new VDR_ResponsePacket();
451 vresp->setResponse(vdrpr->requestSerialNumber, NULL, 0);
452 logger->debug(TAG, "Timeouts: created blank response packet for request serial {}", vdrpr->requestSerialNumber);
454 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
456 // If edFindAndCall returns true, edr was called and vresp was handed off.
457 // else, delete vresp here.
458 logger->error(TAG, "Timeouts: no waiting thread found for request serial {} !!!", vdrpr->requestSerialNumber);
463 else if (vdrpr->receiverChannel == CHANNEL_STREAM || vdrpr->receiverChannel == CHANNEL_TVMEDIA)
465 vresp = new VDR_ResponsePacket();
466 vresp->setStream(vdrpr->streamID, 2 /* connection-lost flag */ , NULL, 0, vdrpr->receiverChannel);
467 logger->debug(TAG, "Timeouts: created blank response packet for streamid {}", vdrpr->streamID);
469 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
471 // If edFindAndCall returns true, edr was called and vresp was handed off.
472 // else, delete vresp here.
473 logger->error(TAG, "Timeouts: no waiting stream receiver found for streamid {} !!!", vdrpr->streamID);
478 for(EDRL::iterator i = receivers.begin(); i != receivers.end(); i++)
479 if (dynamic_cast<VDR_PacketReceiver*>(*i) == vdrpr) { receivers.erase(i); break; }
483 // Ok, all event receviers should be dealt with. just in case there weren't any, inform control
484 logger->debug(TAG, "edUnlock at end of connectionDied");
486 Control::getInstance()->connectionLost();
489 bool VDR::ed_cb_find(EDReceiver* edr, void* userTag)
491 // edr is a VDR_PacketReceiver object made in VDR::RequestResponse
492 // userTag is a VDR_ResponsePacket made in threadMethod
494 VDR_PacketReceiver* vdrpr = dynamic_cast<VDR_PacketReceiver*>(edr);
495 VDR_ResponsePacket* vresp = reinterpret_cast<VDR_ResponsePacket*>(userTag);
497 // Is vresp for vdrpr ?
499 ULONG packetChannel = vresp->getChannelID();
500 //logger->debug(TAG, "TVMedia debug {} {} {:#x}", vdrpr->receiverChannel,packetChannel,vdrpr);
501 if (vdrpr->receiverChannel != packetChannel) return false;
503 if (packetChannel == CHANNEL_REQUEST_RESPONSE)
505 if (vdrpr->requestSerialNumber == vresp->getRequestID()) return true;
507 else if (packetChannel == CHANNEL_STREAM)
509 if (vdrpr->streamID == vresp->getStreamID()) return true;
511 else if (packetChannel == CHANNEL_TVMEDIA)
513 if (vdrpr->streamID == vresp->getStreamID()) return true;
519 VDR_ResponsePacket* VDR::RequestResponse(VDR_RequestPacket* vrp)
521 //logger->debug(TAG, "RR {}", vrp->getOpcode());
523 if (!connected || disconnecting)
525 logger->debug(TAG, "RR when !connected || disconnecting");
526 VDR_ResponsePacket* vresp = new VDR_ResponsePacket();
527 return vresp; // "no-response" return
530 // ED make new VDR and register
531 // make a VDR_PacketReceiver
532 // - init with serial number of request packet
534 VDR_PacketReceiver vdrpr;
535 // vdrpr.requestTime = time(NULL);
536 vdrpr.receiverChannel = VDR::CHANNEL_REQUEST_RESPONSE;
537 vdrpr.requestSerialNumber = vrp->getSerial();
544 if (!tcp.write(vrp->getPtr(), vrp->getLen()))
547 edUnregister(&vdrpr);
548 VDR_ResponsePacket* vresp = new VDR_ResponsePacket();
549 return vresp; // "no-response" return
552 // Sleep and block this thread. The sleep unlocks the mutex
553 // logger->debug(TAG, "RR sleep - opcode {}", vrp->getOpcode());
554 edSleepThisReceiver(&vdrpr);
555 // logger->debug(TAG, "RR unsleep");
557 // Woken because a response packet has arrived, mutex will be locked
558 // logger->debug(TAG, "Packet delivered to me, requestID: {}", vdrpr.save_vresp->getRequestID());
561 return vdrpr.save_vresp;
564 bool VDR::sendKA(ULONG timeStamp)
569 ULONG ul=CHANNEL_KEEPALIVE;
570 buffer[pos++]=(ul>>24)&0xff;
571 buffer[pos++]=(ul>>16)&0xff;
572 buffer[pos++]=(ul>>8)&0xff;
573 buffer[pos++]=ul &0xff;
575 buffer[pos++]=(ul>>24)&0xff;
576 buffer[pos++]=(ul>>16)&0xff;
577 buffer[pos++]=(ul>>8)&0xff;
578 buffer[pos++]=ul &0xff;
579 return tcp.write(buffer, 8);
582 /////////////////////////////////////////////////////////////////////////////
584 // Here VDR takes a break for the VDR_PacketReceiver helper class
586 void VDR_PacketReceiver::call(void* userTag, bool& r_deregisterEDR, bool& r_wakeThread, bool& r_deleteEDR)
588 if (receiverChannel == VDR::CHANNEL_REQUEST_RESPONSE)
590 // It's a RR. Save vresp and, signal the waiting thread and return.
591 // VDR::RequestResponse will be blocking waiting for this to happen.
592 // That function has a pointer to this object and can read save_vresp.
593 save_vresp = reinterpret_cast<VDR_ResponsePacket*>(userTag);
595 r_deregisterEDR = true;
599 else if (receiverChannel == VDR::CHANNEL_STREAM)
601 // It's a stream packet. Pass off the stream data to streamReceiver,
602 // delete the vresp. Keep this PacketReceiver for the next stream packet.
603 VDR_ResponsePacket* vresp = reinterpret_cast<VDR_ResponsePacket*>(userTag);
604 streamReceiver->streamReceive(vresp->getFlag(), vresp->getUserData(), vresp->getUserDataLength());
607 r_deregisterEDR = false;
608 r_wakeThread = false;
611 else if (receiverChannel == VDR::CHANNEL_TVMEDIA)
614 // Pass off the vresp object to OSDVector
615 // This used to return true which would signal the cond (wake the thread)
616 // but am going to try setting this to false because I don't know that there is a thread to signal
617 // delete the EDR. It's made once per media requested and wasn't owned/deleted by anything before
619 VDR_ResponsePacket* vresp = reinterpret_cast<VDR_ResponsePacket*>(userTag);
620 LogNT::getInstance()->debug(TAG, "TVMedia Pictures arrived VDR %x", vresp->getStreamID());
621 OsdVector *osd=dynamic_cast<OsdVector*>(Osd::getInstance());
622 if (osd) osd->getPictReader()->receivePicture(vresp);
623 // else delete vresp; //nonsense // only rpi does CHANNEL_TVMEDIA, rpi has osdvector. therefore, can't get here.
625 r_deregisterEDR = true;
626 r_wakeThread = false;
629 else abort(); // unknown receiverChannel, should not happen
632 /////////////////////////////////////////////////////////////////////////////
634 bool VDR::doLogin(unsigned int* v_server_min, unsigned int* v_server_max, unsigned int* v_client,
635 ASLPrefList& list, int &subtitles)
637 VDR_RequestPacket vrp;
638 if (!vrp.init(VDR_LOGIN, true, 6)) return false;
640 MACAddress myMAC = tcp.getMAC();
641 if (!vrp.copyin(reinterpret_cast<UCHAR*>(&myMAC), 6)) return false;
643 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
644 if (vresp->noResponse()) { delete vresp; return false; }
646 ULONG vdrTime = vresp->extractULONG();
647 logger->debug(TAG, "vdrtime = {}", vdrTime);
648 long vdrTimeOffset = vresp->extractLONG();
649 logger->debug(TAG, "offset = {}", vdrTimeOffset);
651 unsigned int version_min=vresp->extractULONG();
653 *v_server_min=version_min;
654 unsigned int version_max=vresp->extractULONG();
655 *v_server_max=version_max;
656 *v_client=VOMP_PROTOCOL_VERSION;
658 if (0x00000302 <= version_max) {
659 unsigned int numlangcodes = vresp->extractULONG();
660 subtitles = vresp->extractULONG();
662 for (unsigned int i=0; i<numlangcodes; i++) {
664 newpref.audiopref = vresp->extractLONG();
665 newpref.subtitlepref = vresp->extractLONG();
666 newpref.langcode = vresp->extractStdString();
667 //logger->debug(TAG, "Langpref {} {} {} {}", subtitles, newpref.langcode, newpref.audiopref, newpref.subtitlepref);
668 list.push_back(newpref);
675 if ((version_min > VOMP_PROTOCOL_VERSION)
676 || (version_max < VOMP_PROTOCOL_VERSION) ) {
682 // Set the time and zone on the MVP only
684 #if !defined(WIN32) && !defined(__ANDROID__)
685 struct timespec currentTime;
686 currentTime.tv_sec = vdrTime;
687 currentTime.tv_nsec = 0;
689 int b = clock_settime(CLOCK_REALTIME, ¤tTime);
691 logger->debug(TAG, "set clock = {}", b);
693 // now make a TZ variable and set it
697 if (vdrTimeOffset > 0) sign = '-';
700 vdrTimeOffset = abs(vdrTimeOffset);
702 hours = (int)vdrTimeOffset / 3600;
703 minutes = vdrTimeOffset % 3600;
705 logger->debug(TAG, "{} {} {}", sign, hours, minutes);
707 minutes = (int)minutes / 60;
709 logger->debug(TAG, "{} {} {}", sign, hours, minutes);
712 sprintf(newTZ, "MVP%c%i:%i", sign, hours, minutes);
713 setenv("TZ", newTZ, 1);
715 logger->debug(TAG, "Timezone data: {}", newTZ);
718 setCharset(Osd::getInstance()->charSet());
723 bool VDR::LogExtern(const char* logString)
725 if (!connected || disconnecting) return false;
726 int stringLength = strlen(logString);
727 int packetLength = stringLength + 8;
728 char *buffer=new char[packetLength + 1];
730 ULONG ul=CHANNEL_NETLOG;
731 buffer[pos++]=(ul>>24)&0xff;
732 buffer[pos++]=(ul>>16)&0xff;
733 buffer[pos++]=(ul>>8)&0xff;
734 buffer[pos++]=ul &0xff;
736 buffer[pos++]=(ul>>24)&0xff;
737 buffer[pos++]=(ul>>16)&0xff;
738 buffer[pos++]=(ul>>8)&0xff;
739 buffer[pos++]=ul &0xff;
741 strcpy(&buffer[8], logString);
743 if (!tcp.write(buffer, packetLength))
746 disconnecting = true; // stop the rest of the connection
747 Control::getInstance()->connectionLost();
754 bool VDR::setCharset(int charset)
756 VDR_RequestPacket vrp;
757 if (!vrp.init(VDR_SETCHARSET, true, sizeof(ULONG))) return false;
758 if (!vrp.addULONG(charset)) return false;
760 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
761 if (vresp->noResponse()) { delete vresp; return false; }
763 ULONG success = vresp->extractULONG();
766 if (!success) return false;
771 bool VDR::getRecordingsList(RecMan* recman)
773 VDR_RequestPacket vrp;
774 if (!vrp.init(VDR_GETRECORDINGLIST, true, 0)) return false;
776 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
777 if (vresp->noResponse()) { delete vresp; return false; }
779 ULONG totalSpace = vresp->extractULONG();
780 ULONG freeSpace = vresp->extractULONG();
781 ULONG percent = vresp->extractULONG();
783 recman->setStats(totalSpace, freeSpace, percent);
790 while (!vresp->end())
792 start = vresp->extractULONG();
793 isNew = vresp->extractUCHAR();
794 name = vresp->extractString();
795 fileName = vresp->extractString();
796 recman->addEntry(isNew, start, name, fileName);
805 int VDR::deleteRecording(char* fileName)
807 VDR_RequestPacket vrp;
808 if (!vrp.init(VDR_DELETERECORDING, true, strlen(fileName) + 1)) return 0;
809 if (!vrp.addString(fileName)) return 0;
811 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
812 if (vresp->noResponse()) { delete vresp; return 0; }
814 int toReturn = static_cast<int>(vresp->extractULONG());
820 int VDR::deleteRecResume(char* fileName)
822 VDR_RequestPacket vrp;
823 if (!vrp.init(VDR_DELETERECRESUME, true, strlen(fileName) + 1)) return 0;
824 if (!vrp.addString(fileName)) return 0;
826 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
827 if (vresp->noResponse()) { delete vresp; return 0; }
829 int toReturn = static_cast<int>(vresp->extractULONG());
835 char* VDR::moveRecording(char* fileName, char* newPath)
837 VDR_RequestPacket vrp;
838 if (!vrp.init(VDR_MOVERECORDING, true, strlen(fileName) + 1 + strlen(newPath) + 1)) return NULL;
839 if (!vrp.addString(fileName)) return NULL;
840 if (!vrp.addString(newPath)) return NULL;
842 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
843 if (vresp->noResponse()) { delete vresp; return NULL; }
845 char* toReturn = NULL;
846 int success = static_cast<int>(vresp->extractULONG());
849 toReturn = vresp->extractString();
857 ChannelList* VDR::getChannelsList(ULONG type)
859 VDR_RequestPacket vrp;
860 if (!vrp.init(VDR_GETCHANNELLIST, true, 0)) return NULL;
862 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
863 if (vresp->noResponse()) { delete vresp; return NULL; }
865 ChannelList* chanList = new ChannelList();
867 bool h264support=Video::getInstance()->supportsh264();
868 bool mpeg2support=Video::getInstance()->supportsmpeg2();
870 while (!vresp->end())
872 Channel* chan = new Channel();
873 chan->number = vresp->extractULONG();
874 chan->type = vresp->extractULONG();
875 chan->name = vresp->extractString();
876 chan->vstreamtype = static_cast<UCHAR>(vresp->extractULONG());
878 if (chan->type == type && ((chan->vstreamtype==0x1b && h264support)|| (chan->vstreamtype!=0x1b &&mpeg2support)) )
880 chanList->push_back(chan);
881 logger->debug(TAG, "Have added a channel to list. {} {} {}", chan->number, chan->type, chan->name);
882 if (chan->number > maxChannelNumber) maxChannelNumber = chan->number;
892 if (maxChannelNumber > 99999)
893 channelNumberWidth = 6;
894 else if (maxChannelNumber > 9999)
895 channelNumberWidth = 5;
896 else if (maxChannelNumber > 999)
897 channelNumberWidth = 4;
898 else if (maxChannelNumber > 99)
899 channelNumberWidth = 3;
900 else if (maxChannelNumber > 9)
901 channelNumberWidth = 2;
903 channelNumberWidth = 1;
908 int VDR::streamChannel(ULONG number, StreamReceiver* tstreamReceiver)
910 VDR_RequestPacket vrp;
911 if (!vrp.init(VDR_STREAMCHANNEL, true, sizeof(ULONG))) return 0;
912 if (!vrp.addULONG(number)) return 0;
915 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
916 vdrpr->receiverChannel = VDR::CHANNEL_STREAM;
917 vdrpr->streamID = vrp.getSerial();
918 vdrpr->streamReceiver = tstreamReceiver;
920 TEMP_SINGLE_VDR_PR = vdrpr;
922 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
923 if (vresp->noResponse())
931 int toReturn = static_cast<int>(vresp->extractULONG());
932 logger->debug(TAG, "VDR said {} to start streaming request", toReturn);
938 int VDR::stopStreaming()
940 VDR_RequestPacket vrp;
941 if (!vrp.init(VDR_STOPSTREAMING, true, 0)) return 0;
943 if (TEMP_SINGLE_VDR_PR) // this block only needs to be done if it was a live stream
944 // TEMP_SINGLE_VDR_PR will not be set unless we are streaming a channel
946 edUnregister(TEMP_SINGLE_VDR_PR);
947 delete TEMP_SINGLE_VDR_PR;
948 TEMP_SINGLE_VDR_PR = NULL;
951 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
952 if (vresp->noResponse()) { delete vresp; return 0; }
954 int toReturn = static_cast<int>(vresp->extractULONG());
960 UCHAR* VDR::getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived)
962 VDR_RequestPacket vrp;
963 if (!vrp.init(VDR_GETBLOCK, true, sizeof(ULLONG) + sizeof(ULONG))) return NULL;
964 if (!vrp.addULLONG(position)) return NULL;
965 if (!vrp.addULONG(maxAmount)) return NULL;
967 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
968 if (vresp->noResponse()) { delete vresp; return NULL; }
970 if (vresp->serverError())
972 logger->debug(TAG, "Detected getblock 0");
978 // Special handling for getblock
979 UCHAR* toReturn = vresp->getUserData();
980 *amountReceived = vresp->getUserDataLength();
987 ULLONG VDR::streamRecording(char* fileName, ULONG* totalFrames, bool* IsPesRecording)
989 VDR_RequestPacket vrp;
990 if (!vrp.init(VDR_STREAMRECORDING, true, strlen(fileName) + 1)) return 0;
991 if (!vrp.addString(fileName)) return 0;
993 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
994 if (vresp->noResponse()) { delete vresp; return 0; }
996 ULLONG lengthBytes = vresp->extractULLONG();
997 ULONG lengthFrames = vresp->extractULONG();
998 UCHAR isPesRecording = vresp->extractUCHAR();
1001 *totalFrames = lengthFrames;
1002 *IsPesRecording = (isPesRecording);//convert Uchar to bool
1004 logger->debug(TAG, "VDR said length is: {} {}, IsPesRecording {:#x}", lengthBytes, lengthFrames, *IsPesRecording);
1009 ULLONG VDR::positionFromFrameNumber(ULONG frameNumber)
1011 VDR_RequestPacket vrp;
1012 if (!vrp.init(VDR_POSFROMFRAME, true, sizeof(ULONG))) return 0;
1013 if (!vrp.addULONG(frameNumber)) return 0;
1015 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1016 if (vresp->noResponse()) { delete vresp; return 0; }
1018 ULLONG position = vresp->extractULLONG();
1021 logger->debug(TAG, "VDR said new position is: {}", position);
1026 ULONG VDR::frameNumberFromPosition(ULLONG position)
1028 VDR_RequestPacket vrp;
1029 if (!vrp.init(VDR_FRAMEFROMPOS, true, sizeof(ULLONG))) return 0;
1030 if (!vrp.addULLONG(position)) return 0;
1032 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1033 if (vresp->noResponse()) { delete vresp; return 0; }
1035 ULONG framenumber = vresp->extractULONG();
1038 logger->debug(TAG, "VDR said new framenumber is: {}", framenumber);
1043 bool VDR::getNextIFrame(ULONG frameNumber, ULONG direction, ULLONG* rfilePosition, ULONG* rframeNumber, ULONG* rframeLength)
1045 VDR_RequestPacket vrp;
1046 if (!vrp.init(VDR_GETNEXTIFRAME, true, sizeof(ULONG)*2)) return false;
1047 if (!vrp.addULONG(frameNumber)) return false;
1048 if (!vrp.addULONG(direction)) return false;
1050 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1051 if (vresp->noResponse()) { delete vresp; return false; }
1053 if (vresp->serverError())
1055 logger->debug(TAG, "Detected getNextIFrame error");
1060 *rfilePosition = vresp->extractULLONG();
1061 *rframeNumber = vresp->extractULONG();
1062 *rframeLength = vresp->extractULONG();
1066 logger->debug(TAG, "VDR GNIF said {} {} {}", *rfilePosition, *rframeNumber, *rframeLength);
1071 EventList* VDR::getChannelSchedule(ULONG number)
1075 return getChannelSchedule(number, now, 24 * 60 * 60);
1078 EventList* VDR::getChannelSchedule(ULONG number, time_t start, ULONG duration)
1080 // retrieve event list (vector of events) from vdr within filter window. duration is in seconds
1082 VDR_RequestPacket vrp;
1083 if (!vrp.init(VDR_GETCHANNELSCHEDULE, true, sizeof(ULONG)*3)) return NULL;
1084 if (!vrp.addULONG(number)) return NULL;
1085 if (!vrp.addULONG(start)) return NULL;
1086 if (!vrp.addULONG(duration)) return NULL;
1088 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1089 if (vresp->noResponse()) { delete vresp; return NULL; }
1091 // received a ulong(0) - schedules error in the plugin
1092 if (vresp->serverError())
1098 EventList* eventList = new EventList();
1100 while (!vresp->end())
1102 Event* event = new Event();
1103 event->id = vresp->extractULONG();
1104 event->time = vresp->extractULONG();
1105 event->duration = vresp->extractULONG();
1106 event->title = vresp->extractString();
1107 event->subtitle = vresp->extractString();
1108 event->description = vresp->extractString();
1109 eventList->push_back(event);
1114 logger->debug(TAG, "Success got to end of getChannelSchedule");
1118 int VDR::configSave(const char* section, const char* key, const char* value)
1120 VDR_RequestPacket vrp;
1121 if (!vrp.init(VDR_CONFIGSAVE, false, 0)) return 0;
1122 if (!vrp.addString(section)) return 0;
1123 if (!vrp.addString(key)) return 0;
1124 if (!vrp.addString(value)) return 0;
1126 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1127 if (vresp->noResponse()) { delete vresp; return 0; }
1129 int toReturn = static_cast<int>(vresp->extractULONG());
1135 char* VDR::configLoad(const char* section, const char* key)
1137 VDR_RequestPacket vrp;
1138 if (!vrp.init(VDR_CONFIGLOAD, false, 0)) return NULL;
1139 if (!vrp.addString(section)) return NULL;
1140 if (!vrp.addString(key)) return NULL;
1142 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1143 if (vresp->noResponse()) { delete vresp; return NULL; }
1145 char* toReturn = vresp->extractString();
1151 RecTimerList* VDR::getRecTimersList()
1153 VDR_RequestPacket vrp;
1154 if (!vrp.init(VDR_GETTIMERS, true, 0)) return NULL;
1156 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1157 if (vresp->noResponse()) { delete vresp; return NULL; }
1159 RecTimerList* recTimerList = new RecTimerList();
1161 ULONG numTimers = vresp->extractULONG();
1164 RecTimer* newRecTimer;
1167 while (!vresp->end())
1169 newRecTimer = new RecTimer();
1170 newRecTimer->active = vresp->extractULONG();
1171 newRecTimer->recording = vresp->extractULONG();
1172 newRecTimer->pending = vresp->extractULONG();
1173 newRecTimer->priority = vresp->extractULONG();
1174 newRecTimer->lifeTime = vresp->extractULONG();
1175 newRecTimer->channelNumber = vresp->extractULONG();
1176 newRecTimer->startTime = vresp->extractULONG();
1177 newRecTimer->stopTime = vresp->extractULONG();
1178 newRecTimer->day = vresp->extractULONG();
1179 newRecTimer->weekDays = vresp->extractULONG();
1181 tempString = vresp->extractString();
1182 newRecTimer->setFile(tempString);
1183 delete[] tempString;
1185 recTimerList->push_back(newRecTimer);
1186 logger->debug(TAG, "TL: {} {} {} {} {} {} {} {} {}",
1187 newRecTimer->active, newRecTimer->recording, newRecTimer->pending, newRecTimer->priority, newRecTimer->lifeTime,
1188 newRecTimer->channelNumber, newRecTimer->startTime, newRecTimer->stopTime, newRecTimer->getFile());
1194 sort(recTimerList->begin(), recTimerList->end(), RecTimerSorter());
1196 return recTimerList;
1199 ULONG VDR::setEventTimer(char* timerString)
1201 VDR_RequestPacket vrp;
1202 if (!vrp.init(VDR_SETTIMER, true, strlen(timerString) + 1)) return 0;
1203 if (!vrp.addString(timerString)) return 0;
1205 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1206 if (vresp->noResponse()) { delete vresp; return 0; }
1208 ULONG toReturn = vresp->extractULONG();
1214 RecInfo* VDR::getRecInfo(char* fileName)
1216 VDR_RequestPacket vrp;
1217 if (!vrp.init(VDR_GETRECINFO2, true, strlen(fileName) + 1)) return NULL;
1218 if (!vrp.addString(fileName)) return NULL;
1219 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1221 if (vresp->noResponse()) { delete vresp; return NULL; }
1223 if (vresp->serverError())
1225 logger->debug(TAG, "Could not get rec info");
1230 RecInfo* recInfo = new RecInfo();
1232 recInfo->timerStart = vresp->extractULONG();
1233 recInfo->timerEnd = vresp->extractULONG();
1234 recInfo->resumePoint = vresp->extractULONG();
1235 recInfo->summary = vresp->extractString();
1237 ULONG numComponents = vresp->extractULONG();
1240 recInfo->setNumComponents(numComponents);
1241 for (ULONG i = 0; i < numComponents; i++)
1243 recInfo->streams[i] = vresp->extractUCHAR();
1244 recInfo->types[i] = vresp->extractUCHAR();
1245 recInfo->languages[i] = vresp->extractString();
1246 recInfo->descriptions[i] = vresp->extractString();
1249 recInfo->fps=vresp->extractdouble();
1250 recInfo->title=vresp->extractString();
1253 recInfo->channelName = vresp->extractString();
1254 recInfo->duration = vresp->extractULONG();
1255 recInfo->fileSize = vresp->extractULONG();
1256 recInfo->priority = vresp->extractULONG();
1257 recInfo->lifetime = vresp->extractULONG();
1266 ULLONG VDR::rescanRecording(ULONG* totalFrames)
1268 VDR_RequestPacket vrp;
1269 if (!vrp.init(VDR_RESCANRECORDING, true, 0)) return 0;
1271 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1272 if (vresp->noResponse()) { delete vresp; return 0; }
1274 ULLONG lengthBytes = vresp->extractULLONG();
1275 ULONG lengthFrames = vresp->extractULONG();
1278 logger->debug(TAG, "VDR said length is: {} {}", lengthBytes, lengthFrames);
1280 *totalFrames = lengthFrames;
1284 MarkList* VDR::getMarks(char* fileName)
1286 VDR_RequestPacket vrp;
1287 if (!vrp.init(VDR_GETMARKS, true, strlen(fileName) + 1)) return NULL;
1288 if (!vrp.addString(fileName)) return NULL;
1290 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1291 if (vresp->noResponse()) { delete vresp; return NULL; }
1293 if (vresp->serverError())
1299 MarkList* markList = new MarkList();
1301 while (!vresp->end())
1303 Mark* mark = new Mark();
1304 mark->pos = vresp->extractULONG();
1306 markList->push_back(mark);
1307 logger->debug(TAG, "Have added a mark to list. {}", mark->pos);
1315 void VDR::getChannelPids(Channel* channel)
1317 VDR_RequestPacket vrp;
1318 if (!vrp.init(VDR_GETCHANNELPIDS, true, sizeof(ULONG))) return ;
1319 if (!vrp.addULONG(channel->number)) return ;
1321 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1322 if (vresp->noResponse()) { delete vresp; return ; }
1324 // Format of response
1332 channel->vpid = vresp->extractULONG();
1333 channel->vstreamtype = static_cast<UCHAR>(vresp->extractULONG());
1334 channel->numAPids = vresp->extractULONG();
1336 for (ULONG i = 0; i < channel->numAPids; i++)
1339 newapid.pid = vresp->extractULONG();
1340 char * name=vresp->extractString();
1341 strncpy(newapid.desc,name,9);
1343 channel->apids.push_back(newapid);
1346 channel->numDPids = vresp->extractULONG();
1348 for (ULONG i = 0; i < channel->numDPids; i++)
1351 newdpid.pid = vresp->extractULONG();
1352 char * name=vresp->extractString();
1353 strncpy(newdpid.desc,name,9);
1355 channel->dpids.push_back(newdpid);
1358 channel->numSPids = vresp->extractULONG();
1360 for (ULONG i = 0; i < channel->numSPids; i++)
1363 newspid.pid = vresp->extractULONG();
1364 char * name=vresp->extractString();
1365 strncpy(newspid.desc,name,9);
1367 channel->spids.push_back(newspid);
1369 channel->tpid = vresp->extractULONG();
1371 for (ULONG i = 0; i < channel->numAPids; i++)
1373 channel->apids[i].type = vresp->extractULONG();
1375 for (ULONG i = 0; i < channel->numDPids; i++)
1377 channel->dpids[i].type = vresp->extractULONG();
1379 for (ULONG i = 0; i < channel->numSPids; i++)
1381 channel->spids[i].type = vresp->extractULONG();
1382 channel->spids[i].data1 = vresp->extractULONG();
1383 channel->spids[i].data2 = vresp->extractULONG();
1391 #ifdef VOMP_MEDIAPLAYER
1392 MediaList * VDR::getRootList() {
1393 return getMediaList(NULL);
1396 * media List Request:
1398 * Media List response:
1401 MediaList* VDR::getMediaList(const MediaURI * root)
1403 logger->debug(TAG, "getMediaList {},d={}, prov={}", (root?root->getName():"NULL"),
1404 ((root && root->hasDisplayName())?root->getDisplayName():"NULL"),
1405 (root?root->getProvider():providerId));
1406 MediaURI remoteURI(root);
1407 VDR_GetMediaListRequest request(&remoteURI);
1408 SerializeBuffer *vrp=prepareRequest(&request);
1410 logger->log("VDR", Log::ERR, "getMediaList unable to create command");
1414 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1416 Control::getInstance()->connectionLost();
1420 MediaList *rt=new MediaList(NULL);
1422 VDR_GetMediaListResponse resp(&rtflags,rt);
1423 if (decodeResponse(vresp,&resp) != 0) {
1430 * get image Request:
1432 * get media response:
1436 int VDR::openMedium(ULONG channel,const MediaURI *uri, ULLONG * size, ULONG x, ULONG y)
1438 MediaURI remoteURI(uri);
1439 VDR_OpenMediumRequest request(&channel,&remoteURI,&x,&y);
1441 SerializeBuffer *vrp=prepareRequest(&request);
1443 logger->log("VDR", Log::ERR, "openMedium unable to create command");
1446 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1448 Control::getInstance()->connectionLost();
1452 VDR_OpenMediumResponse response(&flags,size);
1453 if (decodeResponse(vresp,&response) != 0) {
1456 logger->debug(TAG, "openMedia len={}", *size);
1461 * getMediaBlock - no separate response class - simple data block
1465 int VDR::getMediaBlock(ULONG channel, ULLONG position, ULONG maxAmount, ULONG* amountReceived, unsigned char **buffer)
1468 VDR_GetMediaBlockRequest request(&channel,&position,&maxAmount);
1469 SerializeBuffer *vrp=prepareRequest(&request);
1471 logger->log("VDR", Log::ERR, "getMediaBlock unable to create command");
1474 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1476 Control::getInstance()->connectionLost();
1480 // Special handling for getblock
1481 *amountReceived = (ULONG)(vresp->getEnd()-vresp->getStart());
1482 *buffer = vresp->steelBuffer();
1495 int VDR::getMediaInfo(ULONG channel, MediaInfo * result) {
1496 if (! result) return -1;
1497 VDR_GetMediaInfoRequest request(&channel);
1498 SerializeBuffer *vrp=prepareRequest(&request);
1500 logger->log("VDR", Log::ERR, "getMediaInfo unable to create command");
1503 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1505 Control::getInstance()->connectionLost();
1510 VDR_GetMediaInfoResponse response(&flags,result);
1511 if (decodeResponse(vresp,&response) != 0) {
1524 int VDR::closeMediaChannel(ULONG channel) {
1525 VDR_CloseMediaChannelRequest request(&channel);
1526 SerializeBuffer *vrp=prepareRequest(&request);
1528 logger->log("VDR", Log::ERR, "closeMediaChannel unable to create command");
1531 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1533 Control::getInstance()->connectionLost();
1537 VDR_CloseMediaChannelResponse response(&flags);
1538 if (decodeResponse(vresp,&response) != 0) return -1;
1539 return (flags != 0)?-1:0;
1545 int VDR::deleteTimer(RecTimer* delTimer)
1547 logger->debug(TAG, "Delete timer called");
1549 VDR_RequestPacket vrp;
1550 if (!vrp.init(VDR_DELETETIMER, false, 0)) return 0;
1551 if (!vrp.addULONG(delTimer->channelNumber)) return 0;
1552 if (!vrp.addULONG(delTimer->weekDays)) return 0;
1553 if (!vrp.addULONG(delTimer->day)) return 0;
1554 if (!vrp.addULONG(delTimer->startTime)) return 0;
1555 if (!vrp.addULONG(delTimer->stopTime)) return 0;
1557 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1558 if (vresp->noResponse()) { delete vresp; return 0; }
1560 int toReturn = static_cast<int>(vresp->extractULONG());
1566 I18n::lang_code_list VDR::getLanguageList()
1568 I18n::lang_code_list CodeList;
1569 CodeList["en"] = "English"; // Default entry
1570 VDR_RequestPacket vrp;
1571 if (!vrp.init(VDR_GETLANGUAGELIST, false, 0)) return CodeList;
1572 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1573 if (vresp->noResponse() || vresp->end())
1579 while (!vresp->end())
1581 char* c_code = vresp->extractString();
1582 char* c_name = vresp->extractString();
1583 std::string code = c_code;
1584 std::string name = c_name;
1585 CodeList[code] = name;
1593 int VDR::getLanguageContent(const std::string code, I18n::trans_table& texts)
1595 VDR_RequestPacket vrp;
1596 if (!vrp.init(VDR_GETLANGUAGECONTENT, false, 0)) return 0;
1597 if (!vrp.addString(code.c_str())) return 0;
1598 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1599 if (vresp->noResponse()) { delete vresp; return 0; }
1601 while (!vresp->end())
1603 char* c_key = vresp->extractString();
1604 char* c_text = vresp->extractString();
1605 std::string key = c_key;
1606 std::string text = c_text;
1615 void VDR::shutdownVDR()
1618 logger->debug(TAG, "Shutting down vdr");
1620 logger->debug(TAG, "Shutting down vomp only");
1622 if(!doVDRShutdown || !connected || disconnecting)
1625 VDR_RequestPacket vrp;
1626 logger->debug(TAG, "Sending shutdown");
1627 if (!vrp.init(VDR_SHUTDOWN, false, 0)) return;
1628 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1631 logger->debug(TAG, "VDR shutdown");
1634 void VDR::getScraperEventType(char * fileName, int & movieID,
1635 int & seriesID, int & episodeID)
1640 VDR_RequestPacket vrp;
1641 if (!vrp.init(VDR_GETRECSCRAPEREVENTTYPE, true, strlen(fileName) + 1)) return;
1642 if (!vrp.addString(fileName)) return ;
1643 logger->debug(TAG, "Before response");
1644 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1645 logger->debug(TAG, "After response");
1646 if (vresp->noResponse()) { delete vresp; return ; }
1647 int type = vresp->extractUCHAR();
1648 if (type == 0) //serie
1650 seriesID = vresp->extractLONG();
1651 episodeID = vresp->extractLONG();
1652 } else if (type == 1) //movie
1654 movieID = vresp->extractLONG();
1660 void VDR::getScraperEventType(UINT channelid, UINT eventid, int & movieID,
1661 int & seriesID, int & episodeID, int & epgImage )
1667 VDR_RequestPacket vrp;
1668 if (!vrp.init(VDR_GETEVENTSCRAPEREVENTTYPE, false, 0)) return;
1669 if (!vrp.addULONG(channelid)) return ;
1670 if (!vrp.addULONG(eventid)) return ;
1671 logger->debug(TAG, "Before response");
1672 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1673 logger->debug(TAG, "After response");
1674 if (vresp->noResponse()) { delete vresp; return ; }
1675 int type = vresp->extractUCHAR();
1676 if (type == 0) //serie
1678 seriesID = vresp->extractLONG();
1679 episodeID = vresp->extractLONG();
1680 } else if (type == 1) //movie
1682 movieID = vresp->extractLONG();
1684 epgImage = vresp->extractLONG();
1689 MovieInfo *VDR::getScraperMovieInfo(int movieID)
1691 VDR_RequestPacket vrp;
1692 if (!vrp.init(VDR_GETSCRAPERMOVIEINFO, false, 0)) return NULL;
1693 if (!vrp.addULONG(movieID)) return NULL;
1694 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1695 if (vresp->noResponse()) { delete vresp; return NULL; }
1696 MovieInfo * movieinf= new MovieInfo();
1698 movieinf->id=movieID;
1699 movieinf->title = vresp->extractStdString();
1700 movieinf->originalTitle = vresp->extractStdString();
1701 movieinf->tagline = vresp->extractStdString();
1702 movieinf->overview = vresp->extractStdString();
1703 movieinf->adult = vresp->extractUCHAR();
1704 movieinf->collectionName = vresp->extractStdString();
1706 movieinf->budget = vresp->extractLONG();
1707 movieinf->revenue = vresp->extractLONG();
1708 movieinf->genres = vresp->extractStdString();
1709 movieinf->homepage = vresp->extractStdString();
1710 movieinf->releaseDate = vresp->extractStdString();
1711 movieinf->runtime = vresp->extractLONG();
1712 movieinf->popularity = vresp->extractdouble();
1713 movieinf->voteAverage = vresp->extractdouble();
1714 movieinf->poster.width = vresp->extractULONG();
1715 movieinf->poster.height = vresp->extractULONG();
1716 movieinf->poster.info.setMovieInfo(movieinf);
1717 movieinf->poster.info.setElement(0,0);
1718 movieinf->fanart.width = vresp->extractULONG();
1719 movieinf->fanart.height = vresp->extractULONG();
1720 movieinf->fanart.info.setMovieInfo(movieinf);
1721 movieinf->fanart.info.setElement(1,0);
1722 movieinf->collectionPoster.width = vresp->extractULONG();
1723 movieinf->collectionPoster.height = vresp->extractULONG();
1724 movieinf->collectionPoster.info.setMovieInfo(movieinf);
1725 movieinf->collectionPoster.info.setElement(2,0);
1726 movieinf->collectionFanart.width = vresp->extractULONG();
1727 movieinf->collectionFanart.height = vresp->extractULONG();
1728 movieinf->collectionFanart.info.setMovieInfo(movieinf);
1729 movieinf->collectionFanart.info.setElement(3,0);
1730 ULONG num_actors = vresp->extractULONG();
1731 movieinf->actors.clear();
1732 movieinf->actors.reserve(num_actors);
1733 for (ULONG acty=0; acty < num_actors; acty++) {
1735 new_act.name = vresp->extractStdString();
1736 new_act.role = vresp->extractStdString();
1737 new_act.thumb.width = vresp->extractULONG();
1738 new_act.thumb.height = vresp->extractULONG();
1739 new_act.thumb.info.setMovieInfo(movieinf);
1740 new_act.thumb.info.setElement(4,acty);
1741 movieinf->actors.push_back(new_act);
1750 SeriesInfo *VDR::getScraperSeriesInfo(int seriesID, int episodeID)
1752 VDR_RequestPacket vrp;
1753 if (!vrp.init(VDR_GETSCRAPERSERIESINFO, false, 0)) return NULL;
1754 if (!vrp.addULONG(seriesID)) return NULL;
1755 if (!vrp.addULONG(episodeID)) return NULL;
1757 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1758 if (vresp->noResponse()) { delete vresp; return 0; }
1759 SeriesInfo * seriesinf= new SeriesInfo();
1761 seriesinf->id=seriesID;
1764 seriesinf->name = vresp->extractStdString();
1765 seriesinf->overview = vresp->extractStdString();
1766 seriesinf->firstAired = vresp->extractStdString();
1767 seriesinf->network = vresp->extractStdString();
1768 seriesinf->genre = vresp->extractStdString();
1769 seriesinf->rating = vresp->extractdouble();
1770 seriesinf->status = vresp->extractStdString();
1773 seriesinf->episode.episodeid=episodeID;
1774 seriesinf->episode.number = vresp->extractLONG();
1775 seriesinf->episode.season = vresp->extractLONG();
1776 seriesinf->episode.name = vresp->extractStdString();
1777 seriesinf->episode.firstAired = vresp->extractStdString();
1778 seriesinf->episode.guestStars = vresp->extractStdString();
1779 seriesinf->episode.overview = vresp->extractStdString();
1780 seriesinf->episode.rating = vresp->extractdouble();
1781 seriesinf->episode.image.width = vresp->extractULONG();
1782 seriesinf->episode.image.height = vresp->extractULONG();
1783 seriesinf->episode.image.info.setSeriesInfo(seriesinf);
1784 seriesinf->episode.image.info.setElement(0,0);
1787 ULONG num_actors = vresp->extractULONG();
1788 seriesinf->actors.clear();
1789 seriesinf->actors.reserve(num_actors);
1790 for (ULONG acty=0; acty < num_actors; acty++) {
1792 new_act.name = vresp->extractStdString();
1793 new_act.role = vresp->extractStdString();
1794 new_act.thumb.width = vresp->extractULONG();
1795 new_act.thumb.height = vresp->extractULONG();
1796 new_act.thumb.info.setSeriesInfo(seriesinf);
1797 new_act.thumb.info.setElement(1,acty);
1798 seriesinf->actors.push_back(new_act);
1800 ULONG num_posters = vresp->extractULONG();
1801 for (ULONG medias = 0; medias < num_posters; medias++ ) {
1803 media.info.setSeriesInfo(seriesinf);
1804 media.info.setElement(2,medias);
1805 media.width = vresp->extractULONG();
1806 media.height = vresp->extractULONG();
1807 seriesinf->posters.push_back(media);
1810 ULONG num_banners = vresp->extractULONG();
1811 for (ULONG medias = 0; medias < num_banners; medias++ ) {
1813 media.info.setSeriesInfo(seriesinf);
1814 media.info.setElement(3,medias);
1815 media.width = vresp->extractULONG();
1816 media.height = vresp->extractULONG();
1817 seriesinf->banners.push_back(media);
1819 ULONG num_fanarts = vresp->extractULONG();
1820 for (ULONG medias = 0; medias < num_fanarts; medias++ ) {
1822 media.info.setSeriesInfo(seriesinf);
1823 media.info.setElement(4,medias);
1824 media.width = vresp->extractULONG();
1825 media.height = vresp->extractULONG();
1826 seriesinf->fanart.push_back(media);
1828 seriesinf->seasonposter.width = vresp->extractULONG();
1829 seriesinf->seasonposter.height = vresp->extractULONG();
1830 seriesinf->seasonposter.info.setSeriesInfo(seriesinf);
1831 seriesinf->seasonposter.info.setElement(5,0);
1838 ULONG VDR::loadTVMedia(TVMediaInfo& tvmedia)
1840 VDR_RequestPacket vrp;
1842 if (!vrp.init(VDR_LOADTVMEDIA, false, 0)) return ULONG_MAX;
1843 if (!vrp.addULONG(tvmedia.type)) return ULONG_MAX;
1844 if (!vrp.addULONG(tvmedia.primary_id)) return ULONG_MAX;
1845 if (!vrp.addULONG(tvmedia.secondary_id)) return ULONG_MAX;
1846 if (!vrp.addULONG(tvmedia.type_pict)) return ULONG_MAX;
1847 if (!vrp.addULONG(tvmedia.container)) return ULONG_MAX;
1848 if (!vrp.addULONG(tvmedia.container_member)) return ULONG_MAX;
1849 /* logger->debug(TAG, "TVMedia with ID {} {}; {} {} {} {};{}",
1850 tvmedia.primary_id,tvmedia.secondary_id,tvmedia.type,tvmedia.type_pict,
1851 tvmedia.container,tvmedia.container_member,vrp.getSerial());*/
1854 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
1855 vdrpr->receiverChannel = VDR::CHANNEL_TVMEDIA;
1856 vdrpr->streamID = vrp.getSerial();
1857 vdrpr->streamReceiver = NULL;
1861 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1862 //if (vresp->noResponse()) { delete vresp; return ULONG_MAX; }
1865 return vrp.getSerial();
1868 ULONG VDR::loadTVMediaRecThumb(TVMediaInfo & media)
1871 VDR_RequestPacket vrp;
1873 if (!vrp.init(VDR_LOADTVMEDIARECTHUMB, false, 0)) return ULONG_MAX;
1874 if (!vrp.addString(media.primary_name.c_str())) return ULONG_MAX;
1876 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
1877 vdrpr->receiverChannel = VDR::CHANNEL_TVMEDIA;
1878 vdrpr->streamID = vrp.getSerial();
1879 vdrpr->streamReceiver = NULL;
1883 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1884 //if (vresp->noResponse()) { delete vresp; return ULONG_MAX; }
1887 return vrp.getSerial();
1890 ULONG VDR::loadTVMediaEventThumb(TVMediaInfo & media)
1893 VDR_RequestPacket vrp;
1895 if (!vrp.init(VDR_LOADTVMEDIAEVENTTHUMB, false, 0)) return ULONG_MAX;
1896 if (!vrp.addULONG(media.primary_id)) return ULONG_MAX;
1897 if (!vrp.addULONG(media.secondary_id)) return ULONG_MAX;
1899 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
1900 vdrpr->receiverChannel = VDR::CHANNEL_TVMEDIA;
1901 vdrpr->streamID = vrp.getSerial();
1902 vdrpr->streamReceiver = NULL;
1906 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1907 //if (vresp->noResponse()) { delete vresp; return ULONG_MAX; }
1910 return vrp.getSerial();
1913 ULONG VDR::loadChannelLogo(TVMediaInfo & media)
1916 VDR_RequestPacket vrp;
1918 if (!vrp.init(VDR_LOADCHANNELLOGO, false, 0)) return ULONG_MAX;
1919 if (!vrp.addULONG(media.primary_id)) return ULONG_MAX;
1921 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
1922 vdrpr->receiverChannel = VDR::CHANNEL_TVMEDIA;
1923 vdrpr->streamID = vrp.getSerial();
1924 vdrpr->streamReceiver = NULL;
1928 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1929 //if (vresp->noResponse()) { delete vresp; return ULONG_MAX; }
1932 // logger->debug(TAG, "TVMedia Channel Logo {} {:#x}",
1933 // media.primary_id,vrp.getSerial());
1935 return vrp.getSerial();