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 //ChannelList* chanList = new ChannelList();
865 std::shared_ptr<ChannelList> chanList = std::make_shared<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();