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/>.
26 #include "vdrrequestpacket.h"
27 #include "vdrresponsepacket.h"
29 #ifdef VOMP_MEDIAPLAYER
31 #include "mediaprovider.h"
32 #include "mediaproviderids.h"
34 #include "vdrcommand.h"
37 #include "movieinfo.h"
38 #include "seriesinfo.h"
39 #include "osdvector.h"
44 static const char* TAG = "VDR";
46 #define VOMP_PROTOCOL_VERSION 0x00000500
48 VDR* VDR::instance = NULL;
49 #ifdef VOMP_MEDIAPLAYER
51 //will create a request package from a command variable and fill this
52 //caller has to destroy buffer
53 static SerializeBuffer * prepareRequest(VDR_Command *cmd) {
54 SerializeBuffer *buf=new SerializeBuffer(512,false,true);
55 if (cmd->serialize(buf) != 0) {
62 //handle request/response
63 //TODO avoid copy of buffer (needs extension of requestpacket)
64 //TODO avoid command 2x (needs some more restructuring)
65 SerializeBuffer * VDR::doRequestResponse(SerializeBuffer *rq,int cmd) {
66 VDR_RequestPacket *rt=new VDR_RequestPacket;
71 if (! rt->init(cmd,true,rq->getCurrent()-rq->getStart())) {
76 if (! rt->copyin(rq->getStart(),(ULONG)(rq->getCurrent()-rq->getStart()))) {
82 VDR_ResponsePacket *rp=RequestResponse(rt);
83 logger->debug(TAG, "Got response {}", (void*)rp);
88 SerializeBuffer *buf=new SerializeBuffer(rp->getUserData(),rp->getUserDataLength(),true,true,false);
93 //deserialize a received response
96 static int decodeResponse(SerializeBuffer *rp,VDR_Command *c) {
97 ULONG expected=c->command;
98 if (c->deserialize(rp) != 0) {
100 Log::getInstance()->error(TAG, "decodeResponse unable to deserialize for command {}", expected);
104 if (c->command != expected) {
105 Log::getInstance()->error(TAG, "decodeResponse unexpected response received {:#x}, expected {:#x}", c->command, expected);
108 Log::getInstance()->error(TAG, "decodeResponse successfully decoded command {:#x}", expected);
116 if (instance) return;
119 TEMP_SINGLE_VDR_PR = NULL; // FIXME what is this
120 #ifdef VOMP_MEDIAPLAYER
121 providerId=MPROVIDERID_VDR;
122 subRange=MPROVIDERRANGE_VDR;
123 MediaPlayerRegister::getInstance()->registerMediaProvider(this,MPROVIDERID_VDR,MPROVIDERRANGE_VDR);
130 if (initted) shutdown();
133 VDR* VDR::getInstance()
140 if (initted) return 0;
142 logger = LogNT::getInstance();
149 if (!initted) return 0;
155 void VDR::setServerIP(const char* newIP)
157 strcpy(serverIP, newIP);
160 void VDR::setServerPort(USHORT newPort)
162 serverPort = newPort;
168 maxChannelNumber = 0;
169 channelNumberWidth = 1;
171 connectStateMutex.lock();
172 if (connecting || connected) return true;
174 connectStateMutex.unlock(); // now I have connecting
176 bool connectResult = tcp.connect(serverIP, serverPort);
178 connectStateMutex.lock(); // connected = false, connecting = true, babortConnect = ?
183 if (connectResult) tcp.shutdown();
184 babortConnect = false;
185 connectStateMutex.unlock();
193 threadStartProtect.lock();
194 vdrThread = std::thread( [this]
196 threadStartProtect.lock();
197 threadStartProtect.unlock();
200 threadStartProtect.unlock();
202 connectStateMutex.unlock();
207 connectStateMutex.unlock();
212 void VDR::abortConnect() // If there is one, force a running connect call to abort
214 connectStateMutex.lock();
218 babortConnect = true;
222 connectStateMutex.unlock();
225 void VDR::disconnect()
227 std::lock_guard<std::mutex> lg(connectStateMutex);
229 if (!connected) return;
231 if (vdrThread.joinable())
233 threadReqStop = true;
236 threadReqStop = false;
241 disconnecting = false;
243 logger->debug(TAG, "Disconnect");
246 void VDR::setReceiveWindow(size_t size)
248 //if (connected && size) tcpold->setReceiveWindow(size);
251 ///////////////////////////////////////////////////////
253 void VDR::threadMethod()
255 logger->debug(TAG, "VDR RUN");
260 ULONG userDataLength;
266 VDR_ResponsePacket* vresp;
269 ULONG lastKAsent = 0;
270 ULONG lastKArecv = time(NULL);
275 readSuccess = tcp.read(&channelID, sizeof(ULONG));
276 if (threadReqStop) return;
277 timeNow = time(NULL);
281 //logger->debug(TAG, "Net read timeout");
282 if (!tcp.status()) { connectionDied(); return; } // return to stop this thread
285 if (!lastKAsent) // have not sent a KA
287 if (lastKArecv < (timeNow - 5))
289 //logger->debug(TAG, "Sending KA packet");
290 if (!sendKA(timeNow))
292 logger->debug(TAG, "Could not send KA, calling connectionDied");
296 lastKAsent = timeNow;
298 if (threadReqStop) return;
303 if (lastKAsent <= (timeNow - 10))
305 logger->debug(TAG, "lastKA over 10s ago, calling connectionDied");
311 if (!readSuccess) continue; // no data was read but the connection is ok.
315 channelID = ntohl(channelID);
317 if (channelID == CHANNEL_REQUEST_RESPONSE)
319 if (!tcp.read(&requestID, sizeof(ULONG))) break;
320 if (threadReqStop) return;
321 requestID = ntohl(requestID);
322 if (!tcp.read(&userDataLength, sizeof(ULONG))) break;
323 if (threadReqStop) return;
324 userDataLength = ntohl(userDataLength);
325 if (userDataLength > 5000000) break; // how big can these packets get?
327 if (userDataLength > 0)
329 userData = malloc(userDataLength);
330 if (!userData) break;
331 if (!tcp.read(userData, userDataLength))
344 vresp = new VDR_ResponsePacket();
345 vresp->setResponse(requestID, reinterpret_cast<UCHAR*>(userData), userDataLength);
346 // vresp now owns userData unless something calls vresp->getUserData()
347 // logger->debug(TAG, "Rxd a response packet, requestID={}, len={}", requestID, userDataLength);
349 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
351 // If edFindAndCall returns true, edr was called and vresp was handed off.
352 // else, delete vresp here.
355 if (threadReqStop) return;
357 else if (channelID == CHANNEL_STREAM || channelID == CHANNEL_TVMEDIA)
359 if (!tcp.read(&streamID, sizeof(ULONG))) break;
360 if (threadReqStop) return;
361 streamID = ntohl(streamID);
363 if (!tcp.read(&flag, sizeof(ULONG))) break;
364 if (threadReqStop) return;
367 if (!tcp.read(&userDataLength, sizeof(ULONG))) break;
368 if (threadReqStop) return;
369 userDataLength = ntohl(userDataLength);
371 if (userDataLength > 0)
373 userData = malloc(userDataLength);
374 if (!userData) break;
375 if (!tcp.read(userData, userDataLength))
388 vresp = new VDR_ResponsePacket();
389 vresp->setStream(streamID, flag, reinterpret_cast<UCHAR*>(userData), userDataLength, channelID);
390 //logger->debug(TAG, "Rxd a stream packet, streamID={}, flag={}, len={}", streamID, flag, userDataLength);
392 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
394 // If edFindAndCall returns true, edr was called and vresp was handed off.
395 // else, delete vresp here.
399 if (threadReqStop) return;
401 else if (channelID == CHANNEL_KEEPALIVE)
404 if (!tcp.read(&KAreply, sizeof(ULONG))) break;
405 if (threadReqStop) return;
406 KAreply = ntohl(KAreply);
407 if (KAreply == lastKAsent) // successful KA response
410 lastKArecv = KAreply;
411 //logger->debug(TAG, "Rxd correct KA reply");
416 logger->error(TAG, "Rxd a response packet on channel {} !!", channelID);
420 // Who deletes vresp?
421 // If RR, the individual protocol functions must delete vresp.
422 // If stream, the data and length is taken out in ed_cb_call and vresp is deleted there.
428 void VDR::connectionDied()
430 // Called from within threadMethod to do cleanup if it decides the connection has died
432 disconnecting = true;
434 // Need to wake up any waiting channel 1 request-response threads
435 // Normally this is done by a packet coming in with channelid and requestid
436 // Instead, go through the list and for each channel 1 edr, make an empty vresp
437 // An empty vresp will have userData == NULL, which means vresp->noResponse() == true
439 // If it's a stream receiver, generate a stream packet with flag == connection_lost
442 VDR_PacketReceiver* vdrpr;
443 VDR_ResponsePacket* vresp;
444 while(receivers.size())
446 vdrpr = dynamic_cast<VDR_PacketReceiver*>(*(receivers.begin()));
447 if (vdrpr->receiverChannel == CHANNEL_REQUEST_RESPONSE)
449 vresp = new VDR_ResponsePacket();
450 vresp->setResponse(vdrpr->requestSerialNumber, NULL, 0);
451 logger->debug(TAG, "Timeouts: created blank response packet for request serial {}", vdrpr->requestSerialNumber);
453 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
455 // If edFindAndCall returns true, edr was called and vresp was handed off.
456 // else, delete vresp here.
457 logger->error(TAG, "Timeouts: no waiting thread found for request serial {} !!!", vdrpr->requestSerialNumber);
462 else if (vdrpr->receiverChannel == CHANNEL_STREAM || vdrpr->receiverChannel == CHANNEL_TVMEDIA)
464 vresp = new VDR_ResponsePacket();
465 vresp->setStream(vdrpr->streamID, 2 /* connection-lost flag */ , NULL, 0, vdrpr->receiverChannel);
466 logger->debug(TAG, "Timeouts: created blank response packet for streamid {}", vdrpr->streamID);
468 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
470 // If edFindAndCall returns true, edr was called and vresp was handed off.
471 // else, delete vresp here.
472 logger->error(TAG, "Timeouts: no waiting stream receiver found for streamid {} !!!", vdrpr->streamID);
477 for(EDRL::iterator i = receivers.begin(); i != receivers.end(); i++)
478 if (dynamic_cast<VDR_PacketReceiver*>(*i) == vdrpr) { receivers.erase(i); break; }
482 // Ok, all event receviers should be dealt with. just in case there weren't any, inform control
483 logger->debug(TAG, "edUnlock at end of connectionDied");
485 Control::getInstance()->connectionLost();
488 bool VDR::ed_cb_find(EDReceiver* edr, void* userTag)
490 // edr is a VDR_PacketReceiver object made in VDR::RequestResponse
491 // userTag is a VDR_ResponsePacket made in threadMethod
493 VDR_PacketReceiver* vdrpr = dynamic_cast<VDR_PacketReceiver*>(edr);
494 VDR_ResponsePacket* vresp = reinterpret_cast<VDR_ResponsePacket*>(userTag);
496 // Is vresp for vdrpr ?
498 ULONG packetChannel = vresp->getChannelID();
499 //logger->debug(TAG, "TVMedia debug {} {} {:#x}", vdrpr->receiverChannel,packetChannel,vdrpr);
500 if (vdrpr->receiverChannel != packetChannel) return false;
502 if (packetChannel == CHANNEL_REQUEST_RESPONSE)
504 if (vdrpr->requestSerialNumber == vresp->getRequestID()) return true;
506 else if (packetChannel == CHANNEL_STREAM)
508 if (vdrpr->streamID == vresp->getStreamID()) return true;
510 else if (packetChannel == CHANNEL_TVMEDIA)
512 if (vdrpr->streamID == vresp->getStreamID()) return true;
518 VDR_ResponsePacket* VDR::RequestResponse(VDR_RequestPacket* vrp)
520 //logger->debug(TAG, "RR {}", vrp->getOpcode());
522 if (!connected || disconnecting)
524 logger->debug(TAG, "RR when !connected || disconnecting");
525 VDR_ResponsePacket* vresp = new VDR_ResponsePacket();
526 return vresp; // "no-response" return
529 // ED make new VDR and register
530 // make a VDR_PacketReceiver
531 // - init with serial number of request packet
533 VDR_PacketReceiver vdrpr;
534 // vdrpr.requestTime = time(NULL);
535 vdrpr.receiverChannel = VDR::CHANNEL_REQUEST_RESPONSE;
536 vdrpr.requestSerialNumber = vrp->getSerial();
543 if (!tcp.write(vrp->getPtr(), vrp->getLen()))
546 edUnregister(&vdrpr);
547 VDR_ResponsePacket* vresp = new VDR_ResponsePacket();
548 return vresp; // "no-response" return
551 // Sleep and block this thread. The sleep unlocks the mutex
552 // logger->debug(TAG, "RR sleep - opcode {}", vrp->getOpcode());
553 edSleepThisReceiver(&vdrpr);
554 // logger->debug(TAG, "RR unsleep");
556 // Woken because a response packet has arrived, mutex will be locked
557 // logger->debug(TAG, "Packet delivered to me, requestID: {}", vdrpr.save_vresp->getRequestID());
560 return vdrpr.save_vresp;
563 bool VDR::sendKA(ULONG timeStamp)
568 ULONG ul=CHANNEL_KEEPALIVE;
569 buffer[pos++]=(ul>>24)&0xff;
570 buffer[pos++]=(ul>>16)&0xff;
571 buffer[pos++]=(ul>>8)&0xff;
572 buffer[pos++]=ul &0xff;
574 buffer[pos++]=(ul>>24)&0xff;
575 buffer[pos++]=(ul>>16)&0xff;
576 buffer[pos++]=(ul>>8)&0xff;
577 buffer[pos++]=ul &0xff;
578 return tcp.write(buffer, 8);
581 /////////////////////////////////////////////////////////////////////////////
583 // Here VDR takes a break for the VDR_PacketReceiver helper class
585 void VDR_PacketReceiver::call(void* userTag, bool& r_deregisterEDR, bool& r_wakeThread, bool& r_deleteEDR)
587 if (receiverChannel == VDR::CHANNEL_REQUEST_RESPONSE)
589 // It's a RR. Save vresp and, signal the waiting thread and return.
590 // VDR::RequestResponse will be blocking waiting for this to happen.
591 // That function has a pointer to this object and can read save_vresp.
592 save_vresp = reinterpret_cast<VDR_ResponsePacket*>(userTag);
594 r_deregisterEDR = true;
598 else if (receiverChannel == VDR::CHANNEL_STREAM)
600 // It's a stream packet. Pass off the stream data to streamReceiver,
601 // delete the vresp. Keep this PacketReceiver for the next stream packet.
602 VDR_ResponsePacket* vresp = reinterpret_cast<VDR_ResponsePacket*>(userTag);
603 streamReceiver->streamReceive(vresp->getFlag(), vresp->getUserData(), vresp->getUserDataLength());
606 r_deregisterEDR = false;
607 r_wakeThread = false;
610 else if (receiverChannel == VDR::CHANNEL_TVMEDIA)
613 // Pass off the vresp object to OSDVector
614 // This used to return true which would signal the cond (wake the thread)
615 // but am going to try setting this to false because I don't know that there is a thread to signal
616 // delete the EDR. It's made once per media requested and wasn't owned/deleted by anything before
618 VDR_ResponsePacket* vresp = reinterpret_cast<VDR_ResponsePacket*>(userTag);
619 LogNT::getInstance()->debug(TAG, "TVMedia Pictures arrived VDR {:#x}", vresp->getStreamID());
620 OsdVector *osd=dynamic_cast<OsdVector*>(Osd::getInstance());
621 if (osd) osd->getPictReader()->receivePicture(vresp);
622 // else delete vresp; //nonsense // only rpi does CHANNEL_TVMEDIA, rpi has osdvector. therefore, can't get here.
624 r_deregisterEDR = true;
625 r_wakeThread = false;
628 else abort(); // unknown receiverChannel, should not happen
631 /////////////////////////////////////////////////////////////////////////////
633 bool VDR::doLogin(unsigned int* v_server_min, unsigned int* v_server_max, unsigned int* v_client,
634 ASLPrefList& list, int &subtitles)
636 VDR_RequestPacket vrp;
637 if (!vrp.init(VDR_LOGIN, true, 6)) return false;
639 MACAddress myMAC = tcp.getMAC();
640 if (!vrp.copyin(reinterpret_cast<UCHAR*>(&myMAC), 6)) return false;
642 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
643 if (vresp->noResponse()) { delete vresp; return false; }
645 ULONG vdrTime = vresp->extractULONG();
646 logger->debug(TAG, "vdrtime = {}", vdrTime);
647 long vdrTimeOffset = vresp->extractLONG();
648 logger->debug(TAG, "offset = {}", vdrTimeOffset);
650 unsigned int version_min=vresp->extractULONG();
652 *v_server_min=version_min;
653 unsigned int version_max=vresp->extractULONG();
654 *v_server_max=version_max;
655 *v_client=VOMP_PROTOCOL_VERSION;
657 if (0x00000302 <= version_max) {
658 unsigned int numlangcodes = vresp->extractULONG();
659 subtitles = vresp->extractULONG();
661 for (unsigned int i=0; i<numlangcodes; i++) {
663 newpref.audiopref = vresp->extractLONG();
664 newpref.subtitlepref = vresp->extractLONG();
665 newpref.langcode = vresp->extractStdString();
666 //logger->debug(TAG, "Langpref {} {} {} {}", subtitles, newpref.langcode, newpref.audiopref, newpref.subtitlepref);
667 list.push_back(newpref);
674 if ((version_min > VOMP_PROTOCOL_VERSION)
675 || (version_max < VOMP_PROTOCOL_VERSION) ) {
681 // Set the time and zone on the MVP only
683 #if !defined(WIN32) && !defined(__ANDROID__)
684 struct timespec currentTime;
685 currentTime.tv_sec = vdrTime;
686 currentTime.tv_nsec = 0;
688 int b = clock_settime(CLOCK_REALTIME, ¤tTime);
690 logger->debug(TAG, "set clock = {}", b);
692 // now make a TZ variable and set it
696 if (vdrTimeOffset > 0) sign = '-';
699 vdrTimeOffset = abs(vdrTimeOffset);
701 hours = (int)vdrTimeOffset / 3600;
702 minutes = vdrTimeOffset % 3600;
704 logger->debug(TAG, "{} {} {}", sign, hours, minutes);
706 minutes = (int)minutes / 60;
708 logger->debug(TAG, "{} {} {}", sign, hours, minutes);
711 sprintf(newTZ, "MVP%c%i:%i", sign, hours, minutes);
712 setenv("TZ", newTZ, 1);
714 logger->debug(TAG, "Timezone data: {}", newTZ);
717 setCharset(Osd::getInstance()->charSet());
722 bool VDR::LogExtern(const char* logString)
724 if (!connected || disconnecting) return false;
725 int stringLength = strlen(logString);
726 int packetLength = stringLength + 8;
727 char *buffer=new char[packetLength + 1];
729 ULONG ul=CHANNEL_NETLOG;
730 buffer[pos++]=(ul>>24)&0xff;
731 buffer[pos++]=(ul>>16)&0xff;
732 buffer[pos++]=(ul>>8)&0xff;
733 buffer[pos++]=ul &0xff;
735 buffer[pos++]=(ul>>24)&0xff;
736 buffer[pos++]=(ul>>16)&0xff;
737 buffer[pos++]=(ul>>8)&0xff;
738 buffer[pos++]=ul &0xff;
740 strcpy(&buffer[8], logString);
742 if (!tcp.write(buffer, packetLength))
745 disconnecting = true; // stop the rest of the connection
746 Control::getInstance()->connectionLost();
753 bool VDR::setCharset(int charset)
755 VDR_RequestPacket vrp;
756 if (!vrp.init(VDR_SETCHARSET, true, sizeof(ULONG))) return false;
757 if (!vrp.addULONG(charset)) return false;
759 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
760 if (vresp->noResponse()) { delete vresp; return false; }
762 ULONG success = vresp->extractULONG();
765 if (!success) return false;
770 bool VDR::getRecordingsList(RecMan* recman)
772 VDR_RequestPacket vrp;
773 if (!vrp.init(VDR_GETRECORDINGLIST, true, 0)) return false;
775 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
776 if (vresp->noResponse()) { delete vresp; return false; }
778 ULONG totalSpace = vresp->extractULONG();
779 ULONG freeSpace = vresp->extractULONG();
780 ULONG percent = vresp->extractULONG();
782 recman->setStats(totalSpace, freeSpace, percent);
789 while (!vresp->end())
791 start = vresp->extractULONG();
792 isNew = vresp->extractUCHAR();
793 name = vresp->extractString();
794 fileName = vresp->extractString();
795 recman->addEntry(isNew, start, name, fileName);
804 int VDR::deleteRecording(char* fileName)
806 VDR_RequestPacket vrp;
807 if (!vrp.init(VDR_DELETERECORDING, true, strlen(fileName) + 1)) return 0;
808 if (!vrp.addString(fileName)) return 0;
810 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
811 if (vresp->noResponse()) { delete vresp; return 0; }
813 int toReturn = static_cast<int>(vresp->extractULONG());
819 int VDR::deleteRecResume(char* fileName)
821 VDR_RequestPacket vrp;
822 if (!vrp.init(VDR_DELETERECRESUME, true, strlen(fileName) + 1)) return 0;
823 if (!vrp.addString(fileName)) return 0;
825 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
826 if (vresp->noResponse()) { delete vresp; return 0; }
828 int toReturn = static_cast<int>(vresp->extractULONG());
834 char* VDR::moveRecording(char* fileName, char* newPath)
836 VDR_RequestPacket vrp;
837 if (!vrp.init(VDR_MOVERECORDING, true, strlen(fileName) + 1 + strlen(newPath) + 1)) return NULL;
838 if (!vrp.addString(fileName)) return NULL;
839 if (!vrp.addString(newPath)) return NULL;
841 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
842 if (vresp->noResponse()) { delete vresp; return NULL; }
844 char* toReturn = NULL;
845 int success = static_cast<int>(vresp->extractULONG());
848 toReturn = vresp->extractString();
856 std::shared_ptr<ChannelList> VDR::getChannelsList(ULONG type)
858 VDR_RequestPacket vrp;
859 if (!vrp.init(VDR_GETCHANNELLIST, true, 0)) return NULL;
861 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
862 if (vresp->noResponse()) { delete vresp; return NULL; }
864 // shared_ptr for a ChannelList (std::vector<Channel*>) with custom deleter to delete all the Channel* objects
865 std::shared_ptr<ChannelList> chanList(new ChannelList(),
866 [] (ChannelList* cl) { for (Channel* p : *cl) delete p; });
868 bool h264support=Video::getInstance()->supportsh264();
869 bool mpeg2support=Video::getInstance()->supportsmpeg2();
871 while (!vresp->end())
873 Channel* chan = new Channel();
874 chan->number = vresp->extractULONG();
875 chan->type = vresp->extractULONG();
876 chan->name = vresp->extractString();
877 chan->vstreamtype = static_cast<UCHAR>(vresp->extractULONG());
879 if (chan->type == type && ((chan->vstreamtype==0x1b && h264support)|| (chan->vstreamtype!=0x1b &&mpeg2support)) )
881 chanList->push_back(chan);
882 logger->debug(TAG, "Have added a channel to list. {} {} {}", chan->number, chan->type, chan->name);
883 if (chan->number > maxChannelNumber) maxChannelNumber = chan->number;
893 if (maxChannelNumber > 99999)
894 channelNumberWidth = 6;
895 else if (maxChannelNumber > 9999)
896 channelNumberWidth = 5;
897 else if (maxChannelNumber > 999)
898 channelNumberWidth = 4;
899 else if (maxChannelNumber > 99)
900 channelNumberWidth = 3;
901 else if (maxChannelNumber > 9)
902 channelNumberWidth = 2;
904 channelNumberWidth = 1;
909 int VDR::streamChannel(ULONG number, StreamReceiver* tstreamReceiver)
911 VDR_RequestPacket vrp;
912 if (!vrp.init(VDR_STREAMCHANNEL, true, sizeof(ULONG))) return 0;
913 if (!vrp.addULONG(number)) return 0;
916 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
917 vdrpr->receiverChannel = VDR::CHANNEL_STREAM;
918 vdrpr->streamID = vrp.getSerial();
919 vdrpr->streamReceiver = tstreamReceiver;
921 TEMP_SINGLE_VDR_PR = vdrpr;
923 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
924 if (vresp->noResponse())
932 int toReturn = static_cast<int>(vresp->extractULONG());
933 logger->debug(TAG, "VDR said {} to start streaming request", toReturn);
939 int VDR::stopStreaming()
941 VDR_RequestPacket vrp;
942 if (!vrp.init(VDR_STOPSTREAMING, true, 0)) return 0;
944 if (TEMP_SINGLE_VDR_PR) // this block only needs to be done if it was a live stream
945 // TEMP_SINGLE_VDR_PR will not be set unless we are streaming a channel
947 edUnregister(TEMP_SINGLE_VDR_PR);
948 delete TEMP_SINGLE_VDR_PR;
949 TEMP_SINGLE_VDR_PR = NULL;
952 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
953 if (vresp->noResponse()) { delete vresp; return 0; }
955 int toReturn = static_cast<int>(vresp->extractULONG());
961 UCHAR* VDR::getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived)
963 VDR_RequestPacket vrp;
964 if (!vrp.init(VDR_GETBLOCK, true, sizeof(ULLONG) + sizeof(ULONG))) return NULL;
965 if (!vrp.addULLONG(position)) return NULL;
966 if (!vrp.addULONG(maxAmount)) return NULL;
968 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
969 if (vresp->noResponse()) { delete vresp; return NULL; }
971 if (vresp->serverError())
973 logger->debug(TAG, "Detected getblock 0");
979 // Special handling for getblock
980 UCHAR* toReturn = vresp->getUserData();
981 *amountReceived = vresp->getUserDataLength();
988 ULLONG VDR::streamRecording(char* fileName, ULONG* totalFrames, bool* IsPesRecording)
990 VDR_RequestPacket vrp;
991 if (!vrp.init(VDR_STREAMRECORDING, true, strlen(fileName) + 1)) return 0;
992 if (!vrp.addString(fileName)) return 0;
994 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
995 if (vresp->noResponse()) { delete vresp; return 0; }
997 ULLONG lengthBytes = vresp->extractULLONG();
998 ULONG lengthFrames = vresp->extractULONG();
999 UCHAR isPesRecording = vresp->extractUCHAR();
1002 *totalFrames = lengthFrames;
1003 *IsPesRecording = (isPesRecording);//convert Uchar to bool
1005 logger->debug(TAG, "VDR said length is: {} {}, IsPesRecording {:#x}", lengthBytes, lengthFrames, *IsPesRecording);
1010 ULLONG VDR::positionFromFrameNumber(ULONG frameNumber)
1012 VDR_RequestPacket vrp;
1013 if (!vrp.init(VDR_POSFROMFRAME, true, sizeof(ULONG))) return 0;
1014 if (!vrp.addULONG(frameNumber)) return 0;
1016 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1017 if (vresp->noResponse()) { delete vresp; return 0; }
1019 ULLONG position = vresp->extractULLONG();
1022 logger->debug(TAG, "VDR said new position is: {}", position);
1027 ULONG VDR::frameNumberFromPosition(ULLONG position)
1029 VDR_RequestPacket vrp;
1030 if (!vrp.init(VDR_FRAMEFROMPOS, true, sizeof(ULLONG))) return 0;
1031 if (!vrp.addULLONG(position)) return 0;
1033 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1034 if (vresp->noResponse()) { delete vresp; return 0; }
1036 ULONG framenumber = vresp->extractULONG();
1039 logger->debug(TAG, "VDR said new framenumber is: {}", framenumber);
1044 bool VDR::getNextIFrame(ULONG frameNumber, ULONG direction, ULLONG* rfilePosition, ULONG* rframeNumber, ULONG* rframeLength)
1046 VDR_RequestPacket vrp;
1047 if (!vrp.init(VDR_GETNEXTIFRAME, true, sizeof(ULONG)*2)) return false;
1048 if (!vrp.addULONG(frameNumber)) return false;
1049 if (!vrp.addULONG(direction)) return false;
1051 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1052 if (vresp->noResponse()) { delete vresp; return false; }
1054 if (vresp->serverError())
1056 logger->debug(TAG, "Detected getNextIFrame error");
1061 *rfilePosition = vresp->extractULLONG();
1062 *rframeNumber = vresp->extractULONG();
1063 *rframeLength = vresp->extractULONG();
1067 logger->debug(TAG, "VDR GNIF said {} {} {}", *rfilePosition, *rframeNumber, *rframeLength);
1072 EventList* VDR::getChannelSchedule(ULONG number)
1076 return getChannelSchedule(number, now, 24 * 60 * 60);
1079 EventList* VDR::getChannelSchedule(ULONG number, time_t start, ULONG duration)
1081 // retrieve event list (vector of events) from vdr within filter window. duration is in seconds
1083 VDR_RequestPacket vrp;
1084 if (!vrp.init(VDR_GETCHANNELSCHEDULE, true, sizeof(ULONG)*3)) return NULL;
1085 if (!vrp.addULONG(number)) return NULL;
1086 if (!vrp.addULONG(start)) return NULL;
1087 if (!vrp.addULONG(duration)) return NULL;
1089 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1090 if (vresp->noResponse()) { delete vresp; return NULL; }
1092 // received a ulong(0) - schedules error in the plugin
1093 if (vresp->serverError())
1099 EventList* eventList = new EventList();
1101 while (!vresp->end())
1103 Event* event = new Event();
1104 event->id = vresp->extractULONG();
1105 event->time = vresp->extractULONG();
1106 event->duration = vresp->extractULONG();
1107 event->title = vresp->extractString();
1108 event->subtitle = vresp->extractString();
1109 event->description = vresp->extractString();
1110 eventList->push_back(event);
1115 logger->debug(TAG, "Success got to end of getChannelSchedule");
1119 int VDR::configSave(const char* section, const char* key, const char* value)
1121 VDR_RequestPacket vrp;
1122 if (!vrp.init(VDR_CONFIGSAVE, false, 0)) return 0;
1123 if (!vrp.addString(section)) return 0;
1124 if (!vrp.addString(key)) return 0;
1125 if (!vrp.addString(value)) return 0;
1127 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1128 if (vresp->noResponse()) { delete vresp; return 0; }
1130 int toReturn = static_cast<int>(vresp->extractULONG());
1136 char* VDR::configLoad(const char* section, const char* key)
1138 VDR_RequestPacket vrp;
1139 if (!vrp.init(VDR_CONFIGLOAD, false, 0)) return NULL;
1140 if (!vrp.addString(section)) return NULL;
1141 if (!vrp.addString(key)) return NULL;
1143 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1144 if (vresp->noResponse()) { delete vresp; return NULL; }
1146 char* toReturn = vresp->extractString();
1152 RecTimerList* VDR::getRecTimersList()
1154 VDR_RequestPacket vrp;
1155 if (!vrp.init(VDR_GETTIMERS, true, 0)) return NULL;
1157 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1158 if (vresp->noResponse()) { delete vresp; return NULL; }
1160 RecTimerList* recTimerList = new RecTimerList();
1162 ULONG numTimers = vresp->extractULONG();
1165 RecTimer* newRecTimer;
1168 while (!vresp->end())
1170 newRecTimer = new RecTimer();
1171 newRecTimer->active = vresp->extractULONG();
1172 newRecTimer->recording = vresp->extractULONG();
1173 newRecTimer->pending = vresp->extractULONG();
1174 newRecTimer->priority = vresp->extractULONG();
1175 newRecTimer->lifeTime = vresp->extractULONG();
1176 newRecTimer->channelNumber = vresp->extractULONG();
1177 newRecTimer->startTime = vresp->extractULONG();
1178 newRecTimer->stopTime = vresp->extractULONG();
1179 newRecTimer->day = vresp->extractULONG();
1180 newRecTimer->weekDays = vresp->extractULONG();
1182 tempString = vresp->extractString();
1183 newRecTimer->setFile(tempString);
1184 delete[] tempString;
1186 recTimerList->push_back(newRecTimer);
1187 logger->debug(TAG, "TL: {} {} {} {} {} {} {} {} {}",
1188 newRecTimer->active, newRecTimer->recording, newRecTimer->pending, newRecTimer->priority, newRecTimer->lifeTime,
1189 newRecTimer->channelNumber, newRecTimer->startTime, newRecTimer->stopTime, newRecTimer->getFile());
1195 sort(recTimerList->begin(), recTimerList->end(), RecTimerSorter());
1197 return recTimerList;
1200 ULONG VDR::setEventTimer(char* timerString)
1202 VDR_RequestPacket vrp;
1203 if (!vrp.init(VDR_SETTIMER, true, strlen(timerString) + 1)) return 0;
1204 if (!vrp.addString(timerString)) return 0;
1206 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1207 if (vresp->noResponse()) { delete vresp; return 0; }
1209 ULONG toReturn = vresp->extractULONG();
1215 RecInfo* VDR::getRecInfo(char* fileName)
1217 VDR_RequestPacket vrp;
1218 if (!vrp.init(VDR_GETRECINFO2, true, strlen(fileName) + 1)) return NULL;
1219 if (!vrp.addString(fileName)) return NULL;
1220 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1222 if (vresp->noResponse()) { delete vresp; return NULL; }
1224 if (vresp->serverError())
1226 logger->debug(TAG, "Could not get rec info");
1231 RecInfo* recInfo = new RecInfo();
1233 recInfo->timerStart = vresp->extractULONG();
1234 recInfo->timerEnd = vresp->extractULONG();
1235 recInfo->resumePoint = vresp->extractULONG();
1236 recInfo->summary = vresp->extractString();
1238 ULONG numComponents = vresp->extractULONG();
1241 recInfo->setNumComponents(numComponents);
1242 for (ULONG i = 0; i < numComponents; i++)
1244 recInfo->streams[i] = vresp->extractUCHAR();
1245 recInfo->types[i] = vresp->extractUCHAR();
1246 recInfo->languages[i] = vresp->extractString();
1247 recInfo->descriptions[i] = vresp->extractString();
1250 recInfo->fps=vresp->extractdouble();
1251 recInfo->title=vresp->extractString();
1254 recInfo->channelName = vresp->extractString();
1255 recInfo->duration = vresp->extractULONG();
1256 recInfo->fileSize = vresp->extractULONG();
1257 recInfo->priority = vresp->extractULONG();
1258 recInfo->lifetime = vresp->extractULONG();
1267 ULLONG VDR::rescanRecording(ULONG* totalFrames)
1269 VDR_RequestPacket vrp;
1270 if (!vrp.init(VDR_RESCANRECORDING, true, 0)) return 0;
1272 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1273 if (vresp->noResponse()) { delete vresp; return 0; }
1275 ULLONG lengthBytes = vresp->extractULLONG();
1276 ULONG lengthFrames = vresp->extractULONG();
1279 logger->debug(TAG, "VDR said length is: {} {}", lengthBytes, lengthFrames);
1281 *totalFrames = lengthFrames;
1285 MarkList* VDR::getMarks(char* fileName)
1287 VDR_RequestPacket vrp;
1288 if (!vrp.init(VDR_GETMARKS, true, strlen(fileName) + 1)) return NULL;
1289 if (!vrp.addString(fileName)) return NULL;
1291 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1292 if (vresp->noResponse()) { delete vresp; return NULL; }
1294 if (vresp->serverError())
1300 MarkList* markList = new MarkList();
1302 while (!vresp->end())
1304 Mark* mark = new Mark();
1305 mark->pos = vresp->extractULONG();
1307 markList->push_back(mark);
1308 logger->debug(TAG, "Have added a mark to list. {}", mark->pos);
1316 void VDR::getChannelPids(Channel* channel)
1318 VDR_RequestPacket vrp;
1319 if (!vrp.init(VDR_GETCHANNELPIDS, true, sizeof(ULONG))) return ;
1320 if (!vrp.addULONG(channel->number)) return ;
1322 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1323 if (vresp->noResponse()) { delete vresp; return ; }
1325 // Format of response
1333 channel->vpid = vresp->extractULONG();
1334 channel->vstreamtype = static_cast<UCHAR>(vresp->extractULONG());
1335 channel->numAPids = vresp->extractULONG();
1337 for (ULONG i = 0; i < channel->numAPids; i++)
1340 newapid.pid = vresp->extractULONG();
1341 char * name=vresp->extractString();
1342 strncpy(newapid.desc,name,9);
1344 channel->apids.push_back(newapid);
1347 channel->numDPids = vresp->extractULONG();
1349 for (ULONG i = 0; i < channel->numDPids; i++)
1352 newdpid.pid = vresp->extractULONG();
1353 char * name=vresp->extractString();
1354 strncpy(newdpid.desc,name,9);
1356 channel->dpids.push_back(newdpid);
1359 channel->numSPids = vresp->extractULONG();
1361 for (ULONG i = 0; i < channel->numSPids; i++)
1364 newspid.pid = vresp->extractULONG();
1365 char * name=vresp->extractString();
1366 strncpy(newspid.desc,name,9);
1368 channel->spids.push_back(newspid);
1370 channel->tpid = vresp->extractULONG();
1372 for (ULONG i = 0; i < channel->numAPids; i++)
1374 channel->apids[i].type = vresp->extractULONG();
1376 for (ULONG i = 0; i < channel->numDPids; i++)
1378 channel->dpids[i].type = vresp->extractULONG();
1380 for (ULONG i = 0; i < channel->numSPids; i++)
1382 channel->spids[i].type = vresp->extractULONG();
1383 channel->spids[i].data1 = vresp->extractULONG();
1384 channel->spids[i].data2 = vresp->extractULONG();
1392 #ifdef VOMP_MEDIAPLAYER
1393 MediaList * VDR::getRootList() {
1394 return getMediaList(NULL);
1397 * media List Request:
1399 * Media List response:
1402 MediaList* VDR::getMediaList(const MediaURI * root)
1404 logger->debug(TAG, "getMediaList {},d={}, prov={}", (root?root->getName():"NULL"),
1405 ((root && root->hasDisplayName())?root->getDisplayName():"NULL"),
1406 (root?root->getProvider():providerId));
1407 MediaURI remoteURI(root);
1408 VDR_GetMediaListRequest request(&remoteURI);
1409 SerializeBuffer *vrp=prepareRequest(&request);
1411 logger->log("VDR", Log::ERR, "getMediaList unable to create command");
1415 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1417 Control::getInstance()->connectionLost();
1421 MediaList *rt=new MediaList(NULL);
1423 VDR_GetMediaListResponse resp(&rtflags,rt);
1424 if (decodeResponse(vresp,&resp) != 0) {
1431 * get image Request:
1433 * get media response:
1437 int VDR::openMedium(ULONG channel,const MediaURI *uri, ULLONG * size, ULONG x, ULONG y)
1439 MediaURI remoteURI(uri);
1440 VDR_OpenMediumRequest request(&channel,&remoteURI,&x,&y);
1442 SerializeBuffer *vrp=prepareRequest(&request);
1444 logger->log("VDR", Log::ERR, "openMedium unable to create command");
1447 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1449 Control::getInstance()->connectionLost();
1453 VDR_OpenMediumResponse response(&flags,size);
1454 if (decodeResponse(vresp,&response) != 0) {
1457 logger->debug(TAG, "openMedia len={}", *size);
1462 * getMediaBlock - no separate response class - simple data block
1466 int VDR::getMediaBlock(ULONG channel, ULLONG position, ULONG maxAmount, ULONG* amountReceived, unsigned char **buffer)
1469 VDR_GetMediaBlockRequest request(&channel,&position,&maxAmount);
1470 SerializeBuffer *vrp=prepareRequest(&request);
1472 logger->log("VDR", Log::ERR, "getMediaBlock unable to create command");
1475 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1477 Control::getInstance()->connectionLost();
1481 // Special handling for getblock
1482 *amountReceived = (ULONG)(vresp->getEnd()-vresp->getStart());
1483 *buffer = vresp->steelBuffer();
1496 int VDR::getMediaInfo(ULONG channel, MediaInfo * result) {
1497 if (! result) return -1;
1498 VDR_GetMediaInfoRequest request(&channel);
1499 SerializeBuffer *vrp=prepareRequest(&request);
1501 logger->log("VDR", Log::ERR, "getMediaInfo unable to create command");
1504 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1506 Control::getInstance()->connectionLost();
1511 VDR_GetMediaInfoResponse response(&flags,result);
1512 if (decodeResponse(vresp,&response) != 0) {
1525 int VDR::closeMediaChannel(ULONG channel) {
1526 VDR_CloseMediaChannelRequest request(&channel);
1527 SerializeBuffer *vrp=prepareRequest(&request);
1529 logger->log("VDR", Log::ERR, "closeMediaChannel unable to create command");
1532 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1534 Control::getInstance()->connectionLost();
1538 VDR_CloseMediaChannelResponse response(&flags);
1539 if (decodeResponse(vresp,&response) != 0) return -1;
1540 return (flags != 0)?-1:0;
1546 int VDR::deleteTimer(RecTimer* delTimer)
1548 logger->debug(TAG, "Delete timer called");
1550 VDR_RequestPacket vrp;
1551 if (!vrp.init(VDR_DELETETIMER, false, 0)) return 0;
1552 if (!vrp.addULONG(delTimer->channelNumber)) return 0;
1553 if (!vrp.addULONG(delTimer->weekDays)) return 0;
1554 if (!vrp.addULONG(delTimer->day)) return 0;
1555 if (!vrp.addULONG(delTimer->startTime)) return 0;
1556 if (!vrp.addULONG(delTimer->stopTime)) return 0;
1558 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1559 if (vresp->noResponse()) { delete vresp; return 0; }
1561 int toReturn = static_cast<int>(vresp->extractULONG());
1567 I18n::lang_code_list VDR::getLanguageList()
1569 I18n::lang_code_list CodeList;
1570 CodeList["en"] = "English"; // Default entry
1571 VDR_RequestPacket vrp;
1572 if (!vrp.init(VDR_GETLANGUAGELIST, false, 0)) return CodeList;
1573 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1574 if (vresp->noResponse() || vresp->end())
1580 while (!vresp->end())
1582 char* c_code = vresp->extractString();
1583 char* c_name = vresp->extractString();
1584 std::string code = c_code;
1585 std::string name = c_name;
1586 CodeList[code] = name;
1594 int VDR::getLanguageContent(const std::string code, I18n::trans_table& texts)
1596 VDR_RequestPacket vrp;
1597 if (!vrp.init(VDR_GETLANGUAGECONTENT, false, 0)) return 0;
1598 if (!vrp.addString(code.c_str())) return 0;
1599 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1600 if (vresp->noResponse()) { delete vresp; return 0; }
1602 while (!vresp->end())
1604 char* c_key = vresp->extractString();
1605 char* c_text = vresp->extractString();
1606 std::string key = c_key;
1607 std::string text = c_text;
1616 void VDR::shutdownVDR()
1619 logger->debug(TAG, "Shutting down vdr");
1621 logger->debug(TAG, "Shutting down vomp only");
1623 if(!doVDRShutdown || !connected || disconnecting)
1626 VDR_RequestPacket vrp;
1627 logger->debug(TAG, "Sending shutdown");
1628 if (!vrp.init(VDR_SHUTDOWN, false, 0)) return;
1629 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1632 logger->debug(TAG, "VDR shutdown");
1635 void VDR::getScraperEventType(char * fileName, int & movieID,
1636 int & seriesID, int & episodeID)
1641 VDR_RequestPacket vrp;
1642 if (!vrp.init(VDR_GETRECSCRAPEREVENTTYPE, true, strlen(fileName) + 1)) return;
1643 if (!vrp.addString(fileName)) return ;
1644 logger->debug(TAG, "Before response");
1645 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1646 logger->debug(TAG, "After response");
1647 if (vresp->noResponse()) { delete vresp; return ; }
1648 int type = vresp->extractUCHAR();
1649 if (type == 0) //serie
1651 seriesID = vresp->extractLONG();
1652 episodeID = vresp->extractLONG();
1653 } else if (type == 1) //movie
1655 movieID = vresp->extractLONG();
1661 void VDR::getScraperEventType(UINT channelid, UINT eventid, int & movieID,
1662 int & seriesID, int & episodeID, int & epgImage )
1668 VDR_RequestPacket vrp;
1669 if (!vrp.init(VDR_GETEVENTSCRAPEREVENTTYPE, false, 0)) return;
1670 if (!vrp.addULONG(channelid)) return ;
1671 if (!vrp.addULONG(eventid)) return ;
1672 logger->debug(TAG, "Before response");
1673 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1674 logger->debug(TAG, "After response");
1675 if (vresp->noResponse()) { delete vresp; return ; }
1676 int type = vresp->extractUCHAR();
1677 if (type == 0) //serie
1679 seriesID = vresp->extractLONG();
1680 episodeID = vresp->extractLONG();
1681 } else if (type == 1) //movie
1683 movieID = vresp->extractLONG();
1685 epgImage = vresp->extractLONG();
1690 MovieInfo *VDR::getScraperMovieInfo(int movieID)
1692 VDR_RequestPacket vrp;
1693 if (!vrp.init(VDR_GETSCRAPERMOVIEINFO, false, 0)) return NULL;
1694 if (!vrp.addULONG(movieID)) return NULL;
1695 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1696 if (vresp->noResponse()) { delete vresp; return NULL; }
1697 MovieInfo * movieinf= new MovieInfo();
1699 movieinf->id=movieID;
1700 movieinf->title = vresp->extractStdString();
1701 movieinf->originalTitle = vresp->extractStdString();
1702 movieinf->tagline = vresp->extractStdString();
1703 movieinf->overview = vresp->extractStdString();
1704 movieinf->adult = vresp->extractUCHAR();
1705 movieinf->collectionName = vresp->extractStdString();
1707 movieinf->budget = vresp->extractLONG();
1708 movieinf->revenue = vresp->extractLONG();
1709 movieinf->genres = vresp->extractStdString();
1710 movieinf->homepage = vresp->extractStdString();
1711 movieinf->releaseDate = vresp->extractStdString();
1712 movieinf->runtime = vresp->extractLONG();
1713 movieinf->popularity = vresp->extractdouble();
1714 movieinf->voteAverage = vresp->extractdouble();
1715 movieinf->poster.width = vresp->extractULONG();
1716 movieinf->poster.height = vresp->extractULONG();
1717 movieinf->poster.info.setMovieInfo(movieinf);
1718 movieinf->poster.info.setElement(0,0);
1719 movieinf->fanart.width = vresp->extractULONG();
1720 movieinf->fanart.height = vresp->extractULONG();
1721 movieinf->fanart.info.setMovieInfo(movieinf);
1722 movieinf->fanart.info.setElement(1,0);
1723 movieinf->collectionPoster.width = vresp->extractULONG();
1724 movieinf->collectionPoster.height = vresp->extractULONG();
1725 movieinf->collectionPoster.info.setMovieInfo(movieinf);
1726 movieinf->collectionPoster.info.setElement(2,0);
1727 movieinf->collectionFanart.width = vresp->extractULONG();
1728 movieinf->collectionFanart.height = vresp->extractULONG();
1729 movieinf->collectionFanart.info.setMovieInfo(movieinf);
1730 movieinf->collectionFanart.info.setElement(3,0);
1731 ULONG num_actors = vresp->extractULONG();
1732 movieinf->actors.clear();
1733 movieinf->actors.reserve(num_actors);
1734 for (ULONG acty=0; acty < num_actors; acty++) {
1736 new_act.name = vresp->extractStdString();
1737 new_act.role = vresp->extractStdString();
1738 new_act.thumb.width = vresp->extractULONG();
1739 new_act.thumb.height = vresp->extractULONG();
1740 new_act.thumb.info.setMovieInfo(movieinf);
1741 new_act.thumb.info.setElement(4,acty);
1742 movieinf->actors.push_back(new_act);
1751 SeriesInfo *VDR::getScraperSeriesInfo(int seriesID, int episodeID)
1753 VDR_RequestPacket vrp;
1754 if (!vrp.init(VDR_GETSCRAPERSERIESINFO, false, 0)) return NULL;
1755 if (!vrp.addULONG(seriesID)) return NULL;
1756 if (!vrp.addULONG(episodeID)) return NULL;
1758 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1759 if (vresp->noResponse()) { delete vresp; return 0; }
1760 SeriesInfo * seriesinf= new SeriesInfo();
1762 seriesinf->id=seriesID;
1765 seriesinf->name = vresp->extractStdString();
1766 seriesinf->overview = vresp->extractStdString();
1767 seriesinf->firstAired = vresp->extractStdString();
1768 seriesinf->network = vresp->extractStdString();
1769 seriesinf->genre = vresp->extractStdString();
1770 seriesinf->rating = vresp->extractdouble();
1771 seriesinf->status = vresp->extractStdString();
1774 seriesinf->episode.episodeid=episodeID;
1775 seriesinf->episode.number = vresp->extractLONG();
1776 seriesinf->episode.season = vresp->extractLONG();
1777 seriesinf->episode.name = vresp->extractStdString();
1778 seriesinf->episode.firstAired = vresp->extractStdString();
1779 seriesinf->episode.guestStars = vresp->extractStdString();
1780 seriesinf->episode.overview = vresp->extractStdString();
1781 seriesinf->episode.rating = vresp->extractdouble();
1782 seriesinf->episode.image.width = vresp->extractULONG();
1783 seriesinf->episode.image.height = vresp->extractULONG();
1784 seriesinf->episode.image.info.setSeriesInfo(seriesinf);
1785 seriesinf->episode.image.info.setElement(0,0);
1788 ULONG num_actors = vresp->extractULONG();
1789 seriesinf->actors.clear();
1790 seriesinf->actors.reserve(num_actors);
1791 for (ULONG acty=0; acty < num_actors; acty++) {
1793 new_act.name = vresp->extractStdString();
1794 new_act.role = vresp->extractStdString();
1795 new_act.thumb.width = vresp->extractULONG();
1796 new_act.thumb.height = vresp->extractULONG();
1797 new_act.thumb.info.setSeriesInfo(seriesinf);
1798 new_act.thumb.info.setElement(1,acty);
1799 seriesinf->actors.push_back(new_act);
1801 ULONG num_posters = vresp->extractULONG();
1802 for (ULONG medias = 0; medias < num_posters; medias++ ) {
1804 media.info.setSeriesInfo(seriesinf);
1805 media.info.setElement(2,medias);
1806 media.width = vresp->extractULONG();
1807 media.height = vresp->extractULONG();
1808 seriesinf->posters.push_back(media);
1811 ULONG num_banners = vresp->extractULONG();
1812 for (ULONG medias = 0; medias < num_banners; medias++ ) {
1814 media.info.setSeriesInfo(seriesinf);
1815 media.info.setElement(3,medias);
1816 media.width = vresp->extractULONG();
1817 media.height = vresp->extractULONG();
1818 seriesinf->banners.push_back(media);
1820 ULONG num_fanarts = vresp->extractULONG();
1821 for (ULONG medias = 0; medias < num_fanarts; medias++ ) {
1823 media.info.setSeriesInfo(seriesinf);
1824 media.info.setElement(4,medias);
1825 media.width = vresp->extractULONG();
1826 media.height = vresp->extractULONG();
1827 seriesinf->fanart.push_back(media);
1829 seriesinf->seasonposter.width = vresp->extractULONG();
1830 seriesinf->seasonposter.height = vresp->extractULONG();
1831 seriesinf->seasonposter.info.setSeriesInfo(seriesinf);
1832 seriesinf->seasonposter.info.setElement(5,0);
1839 ULONG VDR::loadTVMedia(TVMediaInfo& tvmedia)
1841 VDR_RequestPacket vrp;
1843 if (!vrp.init(VDR_LOADTVMEDIA, false, 0)) return ULONG_MAX;
1844 if (!vrp.addULONG(tvmedia.type)) return ULONG_MAX;
1845 if (!vrp.addULONG(tvmedia.primary_id)) return ULONG_MAX;
1846 if (!vrp.addULONG(tvmedia.secondary_id)) return ULONG_MAX;
1847 if (!vrp.addULONG(tvmedia.type_pict)) return ULONG_MAX;
1848 if (!vrp.addULONG(tvmedia.container)) return ULONG_MAX;
1849 if (!vrp.addULONG(tvmedia.container_member)) return ULONG_MAX;
1850 /* logger->debug(TAG, "TVMedia with ID {} {}; {} {} {} {};{}",
1851 tvmedia.primary_id,tvmedia.secondary_id,tvmedia.type,tvmedia.type_pict,
1852 tvmedia.container,tvmedia.container_member,vrp.getSerial());*/
1855 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
1856 vdrpr->receiverChannel = VDR::CHANNEL_TVMEDIA;
1857 vdrpr->streamID = vrp.getSerial();
1858 vdrpr->streamReceiver = NULL;
1862 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1863 //if (vresp->noResponse()) { delete vresp; return ULONG_MAX; }
1866 return vrp.getSerial();
1869 ULONG VDR::loadTVMediaRecThumb(TVMediaInfo & media)
1872 VDR_RequestPacket vrp;
1874 if (!vrp.init(VDR_LOADTVMEDIARECTHUMB, false, 0)) return ULONG_MAX;
1875 if (!vrp.addString(media.primary_name.c_str())) return ULONG_MAX;
1877 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
1878 vdrpr->receiverChannel = VDR::CHANNEL_TVMEDIA;
1879 vdrpr->streamID = vrp.getSerial();
1880 vdrpr->streamReceiver = NULL;
1884 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1885 //if (vresp->noResponse()) { delete vresp; return ULONG_MAX; }
1888 return vrp.getSerial();
1891 ULONG VDR::loadTVMediaEventThumb(TVMediaInfo & media)
1894 VDR_RequestPacket vrp;
1896 if (!vrp.init(VDR_LOADTVMEDIAEVENTTHUMB, false, 0)) return ULONG_MAX;
1897 if (!vrp.addULONG(media.primary_id)) return ULONG_MAX;
1898 if (!vrp.addULONG(media.secondary_id)) return ULONG_MAX;
1900 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
1901 vdrpr->receiverChannel = VDR::CHANNEL_TVMEDIA;
1902 vdrpr->streamID = vrp.getSerial();
1903 vdrpr->streamReceiver = NULL;
1907 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1908 //if (vresp->noResponse()) { delete vresp; return ULONG_MAX; }
1911 return vrp.getSerial();
1914 ULONG VDR::loadChannelLogo(TVMediaInfo & media)
1917 VDR_RequestPacket vrp;
1919 if (!vrp.init(VDR_LOADCHANNELLOGO, false, 0)) return ULONG_MAX;
1920 if (!vrp.addULONG(media.primary_id)) return ULONG_MAX;
1922 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
1923 vdrpr->receiverChannel = VDR::CHANNEL_TVMEDIA;
1924 vdrpr->streamID = vrp.getSerial();
1925 vdrpr->streamReceiver = NULL;
1929 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1930 //if (vresp->noResponse()) { delete vresp; return ULONG_MAX; }
1933 // logger->debug(TAG, "TVMedia Channel Logo {} {:#x}",
1934 // media.primary_id,vrp.getSerial());
1936 return vrp.getSerial();