2 Copyright 2004-2019 Chris Tallon
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP. If not, see <https://www.gnu.org/licenses/>.
29 #include "vdrrequestpacket.h"
30 #include "vdrresponsepacket.h"
32 #ifdef VOMP_MEDIAPLAYER
34 #include "mediaprovider.h"
35 #include "mediaproviderids.h"
37 #include "vdrcommand.h"
40 #include "movieinfo.h"
41 #include "seriesinfo.h"
42 #include "osdvector.h"
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->log("doRequestResponse",Log::DEBUG,"got response %p",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()->log("VDR", Log::ERR, "decodeResponse unable to deserialize for command %lu",expected);
104 if (c->command != expected) {
105 Log::getInstance()->log("VDR", Log::ERR, "decodeResponse unexpected response received 0x%lx, expected 0x%lx",c->command,expected);
108 Log::getInstance()->log("VDR", Log::DEBUG, "decodeResponse successfully decoded command 0x%lx",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 = Log::getInstance();
148 if (!initted) return 0;
154 void VDR::setServerIP(const char* newIP)
156 strcpy(serverIP, newIP);
159 void VDR::setServerPort(USHORT newPort)
161 serverPort = newPort;
166 maxChannelNumber = 0;
167 channelNumberWidth = 1;
171 if (tcp->connectTo(serverIP, serverPort))
183 void VDR::disconnect()
189 logger->log("VDR", Log::DEBUG, "Disconnect");
192 void VDR::setReceiveWindow(size_t size)
194 if (connected && size) tcp->setReceiveWindow(size);
197 ///////////////////////////////////////////////////////
199 void VDR::threadMethod()
201 logger->log("VDR", Log::DEBUG, "VDR RUN");
203 threadSetKillable(); // FIXME - change this to deal with the EDRs
208 ULONG userDataLength;
214 VDR_ResponsePacket* vresp;
217 ULONG lastKAsent = 0;
218 ULONG lastKArecv = time(NULL);
223 timeNow = time(NULL);
225 readSuccess = tcp->readData(&channelID, sizeof(ULONG)); // 2s timeout atm
229 //logger->log("VDR", Log::DEBUG, "Net read timeout");
230 if (!tcp->isConnected()) { connectionDied(); return; } // return to stop this thread
235 if (!lastKAsent) // have not sent a KA
237 if (lastKArecv < (timeNow - 5))
239 //logger->log("VDR", Log::DEBUG, "Sending KA packet");
240 if (!sendKA(timeNow))
242 logger->log("VDR", Log::DEBUG, "Could not send KA, calling connectionDied");
246 lastKAsent = timeNow;
251 if (lastKAsent <= (timeNow - 10))
253 logger->log("VDR", Log::DEBUG, "lastKA over 10s ago, calling connectionDied");
259 if (!readSuccess) continue; // no data was read but the connection is ok.
263 channelID = ntohl(channelID);
265 if (channelID == CHANNEL_REQUEST_RESPONSE)
267 if (!tcp->readData(&requestID, sizeof(ULONG))) break;
268 requestID = ntohl(requestID);
269 if (!tcp->readData(&userDataLength, sizeof(ULONG))) break;
270 userDataLength = ntohl(userDataLength);
271 if (userDataLength > 5000000) break; // how big can these packets get?
273 if (userDataLength > 0)
275 userData = malloc(userDataLength);
276 if (!userData) break;
277 if (!tcp->readData(userData, userDataLength)) break;
280 vresp = new VDR_ResponsePacket();
281 vresp->setResponse(requestID, reinterpret_cast<UCHAR*>(userData), userDataLength);
282 // logger->log("VDR", Log::DEBUG, "Rxd a response packet, requestID=%lu, len=%lu", requestID, userDataLength);
284 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
286 // If edFindAndCall returns true, edr was called and vresp was handed off.
287 // else, delete vresp here.
291 else if (channelID == CHANNEL_STREAM || channelID == CHANNEL_TVMEDIA)
293 if (!tcp->readData(&streamID, sizeof(ULONG))) break;
294 streamID = ntohl(streamID);
296 if (!tcp->readData(&flag, sizeof(ULONG))) break;
299 if (!tcp->readData(&userDataLength, sizeof(ULONG))) break;
300 userDataLength = ntohl(userDataLength);
302 if (userDataLength > 0)
304 userData = malloc(userDataLength);
305 if (!userData) break;
306 if (!tcp->readData(userData, userDataLength)) break;
309 vresp = new VDR_ResponsePacket();
310 vresp->setStream(streamID, flag, reinterpret_cast<UCHAR*>(userData), userDataLength, channelID);
311 //logger->log("VDR", Log::DEBUG, "Rxd a stream packet, streamID=%lu, flag=%lu, len=%lu", streamID, flag, userDataLength);
313 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
315 // If edFindAndCall returns true, edr was called and vresp was handed off.
316 // else, delete vresp here.
320 else if (channelID == CHANNEL_KEEPALIVE)
323 if (!tcp->readData(&KAreply, sizeof(ULONG))) break;
324 KAreply = ntohl(KAreply);
325 if (KAreply == lastKAsent) // successful KA response
328 lastKArecv = KAreply;
329 //logger->log("VDR", Log::DEBUG, "Rxd correct KA reply");
334 logger->log("VDR", Log::ERR, "Rxd a response packet on channel %lu !!", channelID);
340 // Who deletes vresp?
341 // If RR, the individual protocol functions must delete vresp.
342 // If stream, the data and length is taken out in ed_cb_call and vresp is deleted there.
348 void VDR::connectionDied()
350 // Called from within threadMethod to do cleanup if it decides the connection has died
352 connected = false; // though actually it could still be connected until someone calls vdr->disconnect
354 // Need to wake up any waiting channel 1 request-response threads
355 // Normally this is done by a packet coming in with channelid and requestid
356 // Instead, go through the list and for each channel 1 edr, make an empty vresp
357 // An empty vresp will have userData == NULL, which means vresp->noResponse() == true
359 // If it's a stream receiver, generate a stream packet with flag == connection_lost
362 VDR_PacketReceiver* vdrpr;
363 VDR_ResponsePacket* vresp;
364 while(receivers.size())
366 vdrpr = dynamic_cast<VDR_PacketReceiver*>(*(receivers.begin()));
367 if (vdrpr->receiverChannel == CHANNEL_REQUEST_RESPONSE)
369 vresp = new VDR_ResponsePacket();
370 vresp->setResponse(vdrpr->requestSerialNumber, NULL, 0);
371 logger->log("VDR", Log::DEBUG, "Timeouts: created blank response packet for request serial %lu", vdrpr->requestSerialNumber);
373 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
375 // If edFindAndCall returns true, edr was called and vresp was handed off.
376 // else, delete vresp here.
377 logger->log("VDR", Log::ERR, "Timeouts: no waiting thread found for request serial %lu !!!", vdrpr->requestSerialNumber);
382 else if (vdrpr->receiverChannel == CHANNEL_STREAM || vdrpr->receiverChannel == CHANNEL_TVMEDIA)
384 vresp = new VDR_ResponsePacket();
385 vresp->setStream(vdrpr->streamID, 2 /* connection-lost flag */ , NULL, 0, vdrpr->receiverChannel);
386 logger->log("VDR", Log::DEBUG, "Timeouts: created blank response packet for streamid %lu", vdrpr->streamID);
388 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
390 // If edFindAndCall returns true, edr was called and vresp was handed off.
391 // else, delete vresp here.
392 logger->log("VDR", Log::ERR, "Timeouts: no waiting stream receiver found for streamid %lu !!!", vdrpr->streamID);
397 for(EDRL::iterator i = receivers.begin(); i != receivers.end(); i++)
398 if (dynamic_cast<VDR_PacketReceiver*>(*i) == vdrpr) { receivers.erase(i); break; }
402 // Ok, all event receviers should be dealt with. just in case there weren't any, inform command
403 logger->log("VDR", Log::DEBUG, "edUnlock at end of connectionDied");
405 Command::getInstance()->connectionLost();
408 bool VDR::ed_cb_find(EDReceiver* edr, void* userTag)
410 // edr is a VDR_PacketReceiver object made in VDR::RequestResponse
411 // userTag is a VDR_ResponsePacket made in threadMethod
413 VDR_PacketReceiver* vdrpr = dynamic_cast<VDR_PacketReceiver*>(edr);
414 VDR_ResponsePacket* vresp = reinterpret_cast<VDR_ResponsePacket*>(userTag);
416 // Is vresp for vdrpr ?
418 ULONG packetChannel = vresp->getChannelID();
419 //logger->log("VDR", Log::DEBUG, "TVMedia debug %d %d %x", vdrpr->receiverChannel,packetChannel,vdrpr);
420 if (vdrpr->receiverChannel != packetChannel) return false;
422 if (packetChannel == CHANNEL_REQUEST_RESPONSE)
424 if (vdrpr->requestSerialNumber == vresp->getRequestID()) return true;
426 else if (packetChannel == CHANNEL_STREAM)
428 if (vdrpr->streamID == vresp->getStreamID()) return true;
430 else if (packetChannel == CHANNEL_TVMEDIA)
432 if (vdrpr->streamID == vresp->getStreamID()) return true;
438 VDR_ResponsePacket* VDR::RequestResponse(VDR_RequestPacket* vrp)
440 //logger->log("VDR", Log::DEBUG, "RR %lu", vrp->getOpcode());
444 logger->log("VDR", Log::DEBUG, "RR when !connected");
445 VDR_ResponsePacket* vresp = new VDR_ResponsePacket();
446 return vresp; // "no-response" return
449 // ED make new VDR and register
450 // make a VDR_PacketReceiver
451 // - init with serial number of request packet
453 VDR_PacketReceiver vdrpr;
454 // vdrpr.requestTime = time(NULL);
455 vdrpr.receiverChannel = VDR::CHANNEL_REQUEST_RESPONSE;
456 vdrpr.requestSerialNumber = vrp->getSerial();
463 if (static_cast<ULONG>(tcp->sendData(vrp->getPtr(), vrp->getLen())) != vrp->getLen())
466 edUnregister(&vdrpr);
467 VDR_ResponsePacket* vresp = new VDR_ResponsePacket();
468 return vresp; // "no-response" return
471 // Sleep and block this thread. The sleep unlocks the mutex
472 // logger->log("VDR", Log::DEBUG, "RR sleep - opcode %lu", vrp->getOpcode());
473 edSleepThisReceiver(&vdrpr);
474 // logger->log("VDR", Log::DEBUG, "RR unsleep");
476 // Woken because a response packet has arrived, mutex will be locked
477 // logger->log("VDR", Log::DEBUG, "Packet delivered to me, requestID: %lu", vdrpr.save_vresp->getRequestID());
480 return vdrpr.save_vresp;
483 bool VDR::sendKA(ULONG timeStamp)
488 ULONG ul=CHANNEL_KEEPALIVE;
489 buffer[pos++]=(ul>>24)&0xff;
490 buffer[pos++]=(ul>>16)&0xff;
491 buffer[pos++]=(ul>>8)&0xff;
492 buffer[pos++]=ul &0xff;
494 buffer[pos++]=(ul>>24)&0xff;
495 buffer[pos++]=(ul>>16)&0xff;
496 buffer[pos++]=(ul>>8)&0xff;
497 buffer[pos++]=ul &0xff;
498 if (static_cast<ULONG>(tcp->sendData(buffer, 8)) != 8) return false;
502 /////////////////////////////////////////////////////////////////////////////
504 // Here VDR takes a break for the VDR_PacketReceiver helper class
506 void VDR_PacketReceiver::call(void* userTag, bool& r_deregisterEDR, bool& r_wakeThread, bool& r_deleteEDR)
508 if (receiverChannel == VDR::CHANNEL_REQUEST_RESPONSE)
510 // It's a RR. Save vresp and, signal the waiting thread and return.
511 // VDR::RequestResponse will be blocking waiting for this to happen.
512 // That function has a pointer to this object and can read save_vresp.
513 save_vresp = reinterpret_cast<VDR_ResponsePacket*>(userTag);
515 r_deregisterEDR = true;
519 else if (receiverChannel == VDR::CHANNEL_STREAM)
521 // It's a stream packet. Pass off the stream data to streamReceiver,
522 // delete the vresp. Keep this PacketReceiver for the next stream packet.
523 VDR_ResponsePacket* vresp = reinterpret_cast<VDR_ResponsePacket*>(userTag);
524 streamReceiver->streamReceive(vresp->getFlag(), vresp->getUserData(), vresp->getUserDataLength());
527 r_deregisterEDR = false;
528 r_wakeThread = false;
531 else if (receiverChannel == VDR::CHANNEL_TVMEDIA)
534 // Pass off the vresp object to OSDVector
535 // This used to return true which would signal the cond (wake the thread)
536 // but am going to try setting this to false because I don't know that there is a thread to signal
537 // delete the EDR. It's made once per media requested and wasn't owned/deleted by anything before
539 VDR_ResponsePacket* vresp = reinterpret_cast<VDR_ResponsePacket*>(userTag);
540 Log::getInstance()->log("VDR", Log::DEBUG, "TVMedia Pictures arrived VDR %x", vresp->getStreamID());
541 OsdVector *osd=dynamic_cast<OsdVector*>(Osd::getInstance());
542 if (osd) osd->getPictReader()->receivePicture(vresp);
543 // else delete vresp; //nonsense // only rpi does CHANNEL_TVMEDIA, rpi has osdvector. therefore, can't get here.
545 r_deregisterEDR = true;
546 r_wakeThread = false;
549 else abort(); // unknown receiverChannel, should not happen
552 /////////////////////////////////////////////////////////////////////////////
554 int VDR::doLogin(unsigned int* v_server_min, unsigned int* v_server_max, unsigned int* v_client,
555 ASLPrefList& list, int &subtitles)
557 VDR_RequestPacket vrp;
558 if (!vrp.init(VDR_LOGIN, true, 6)) return 0;
561 tcp->getMAC(mactemp);
562 if (!vrp.copyin(mactemp, 6)) return 0;
564 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
565 if (vresp->noResponse()) { delete vresp; return 0; }
567 ULONG vdrTime = vresp->extractULONG();
568 logger->log("VDR", Log::DEBUG, "vdrtime = %lu", vdrTime);
569 long vdrTimeOffset = vresp->extractLONG();
570 logger->log("VDR", Log::DEBUG, "offset = %i", vdrTimeOffset);
572 unsigned int version_min=vresp->extractULONG();
574 *v_server_min=version_min;
575 unsigned int version_max=vresp->extractULONG();
576 *v_server_max=version_max;
577 *v_client=VOMP_PROTOCOL_VERSION;
579 if (0x00000302 <= version_max) {
580 unsigned int numlangcodes = vresp->extractULONG();
581 subtitles = vresp->extractULONG();
583 for (unsigned int i=0; i<numlangcodes; i++) {
585 newpref.audiopref = vresp->extractLONG();
586 newpref.subtitlepref = vresp->extractLONG();
587 newpref.langcode = vresp->extractStdString();
588 //logger->log("VDR", Log::DEBUG, "Langpref %s %d %d", newpref.langcode.c_str(), newpref.audiopref, newpref.subtitlepref);
589 list.push_back(newpref);
596 if ((version_min > VOMP_PROTOCOL_VERSION)
597 || (version_max < VOMP_PROTOCOL_VERSION) ) {
603 // Set the time and zone on the MVP only
605 #if !defined(WIN32) && !defined(__ANDROID__)
606 struct timespec currentTime;
607 currentTime.tv_sec = vdrTime;
608 currentTime.tv_nsec = 0;
610 int b = clock_settime(CLOCK_REALTIME, ¤tTime);
612 logger->log("VDR", Log::DEBUG, "set clock = %u", b);
614 // now make a TZ variable and set it
618 if (vdrTimeOffset > 0) sign = '-';
621 vdrTimeOffset = abs(vdrTimeOffset);
623 hours = (int)vdrTimeOffset / 3600;
624 minutes = vdrTimeOffset % 3600;
626 logger->log("VDR", Log::DEBUG, "%c %i %i", sign, hours, minutes);
628 minutes = (int)minutes / 60;
630 logger->log("VDR", Log::DEBUG, "%c %i %i", sign, hours, minutes);
633 sprintf(newTZ, "MVP%c%i:%i", sign, hours, minutes);
634 setenv("TZ", newTZ, 1);
636 logger->log("VDR", Log::DEBUG, "Timezone data: %s", newTZ);
639 setCharset(Osd::getInstance()->charSet());
644 bool VDR::LogExtern(const char* logString)
646 if (!connected) return false;
647 int stringLength = strlen(logString);
648 int packetLength = stringLength + 8;
649 char *buffer=new char[packetLength + 1];
651 ULONG ul=CHANNEL_NETLOG;
652 buffer[pos++]=(ul>>24)&0xff;
653 buffer[pos++]=(ul>>16)&0xff;
654 buffer[pos++]=(ul>>8)&0xff;
655 buffer[pos++]=ul &0xff;
657 buffer[pos++]=(ul>>24)&0xff;
658 buffer[pos++]=(ul>>16)&0xff;
659 buffer[pos++]=(ul>>8)&0xff;
660 buffer[pos++]=ul &0xff;
662 strcpy(&buffer[8], logString);
664 if (tcp->sendData(buffer, packetLength) != packetLength)
666 connected = false; // stop the rest of the connection
674 bool VDR::setCharset(int charset)
676 VDR_RequestPacket vrp;
677 if (!vrp.init(VDR_SETCHARSET, true, sizeof(ULONG))) return false;
678 if (!vrp.addULONG(charset)) return false;
680 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
681 if (vresp->noResponse()) { delete vresp; return false; }
683 ULONG success = vresp->extractULONG();
686 if (!success) return false;
691 bool VDR::getRecordingsList(RecMan* recman)
693 VDR_RequestPacket vrp;
694 if (!vrp.init(VDR_GETRECORDINGLIST, true, 0)) return false;
696 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
697 if (vresp->noResponse()) { delete vresp; return false; }
699 ULONG totalSpace = vresp->extractULONG();
700 ULONG freeSpace = vresp->extractULONG();
701 ULONG percent = vresp->extractULONG();
703 recman->setStats(totalSpace, freeSpace, percent);
710 while (!vresp->end())
712 start = vresp->extractULONG();
713 isNew = vresp->extractUCHAR();
714 name = vresp->extractString();
715 fileName = vresp->extractString();
716 recman->addEntry(isNew, start, name, fileName);
725 int VDR::deleteRecording(char* fileName)
727 VDR_RequestPacket vrp;
728 if (!vrp.init(VDR_DELETERECORDING, true, strlen(fileName) + 1)) return 0;
729 if (!vrp.addString(fileName)) return 0;
731 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
732 if (vresp->noResponse()) { delete vresp; return 0; }
734 int toReturn = static_cast<int>(vresp->extractULONG());
740 int VDR::deleteRecResume(char* fileName)
742 VDR_RequestPacket vrp;
743 if (!vrp.init(VDR_DELETERECRESUME, true, strlen(fileName) + 1)) return 0;
744 if (!vrp.addString(fileName)) return 0;
746 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
747 if (vresp->noResponse()) { delete vresp; return 0; }
749 int toReturn = static_cast<int>(vresp->extractULONG());
755 char* VDR::moveRecording(char* fileName, char* newPath)
757 VDR_RequestPacket vrp;
758 if (!vrp.init(VDR_MOVERECORDING, true, strlen(fileName) + 1 + strlen(newPath) + 1)) return NULL;
759 if (!vrp.addString(fileName)) return NULL;
760 if (!vrp.addString(newPath)) return NULL;
762 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
763 if (vresp->noResponse()) { delete vresp; return NULL; }
765 char* toReturn = NULL;
766 int success = static_cast<int>(vresp->extractULONG());
769 toReturn = vresp->extractString();
777 ChannelList* VDR::getChannelsList(ULONG type)
779 VDR_RequestPacket vrp;
780 if (!vrp.init(VDR_GETCHANNELLIST, true, 0)) return NULL;
782 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
783 if (vresp->noResponse()) { delete vresp; return NULL; }
785 ChannelList* chanList = new ChannelList();
787 bool h264support=Video::getInstance()->supportsh264();
788 bool mpeg2support=Video::getInstance()->supportsmpeg2();
790 while (!vresp->end())
792 Channel* chan = new Channel();
793 chan->number = vresp->extractULONG();
794 chan->type = vresp->extractULONG();
795 chan->name = vresp->extractString();
796 chan->vstreamtype = static_cast<UCHAR>(vresp->extractULONG());
798 if (chan->type == type && ((chan->vstreamtype==0x1b && h264support)|| (chan->vstreamtype!=0x1b &&mpeg2support)) )
800 chanList->push_back(chan);
801 logger->log("VDR", Log::DEBUG, "Have added a channel to list. %lu %lu %s", chan->number, chan->type, chan->name);
802 if (chan->number > maxChannelNumber) maxChannelNumber = chan->number;
812 if (maxChannelNumber > 99999)
813 channelNumberWidth = 6;
814 else if (maxChannelNumber > 9999)
815 channelNumberWidth = 5;
816 else if (maxChannelNumber > 999)
817 channelNumberWidth = 4;
818 else if (maxChannelNumber > 99)
819 channelNumberWidth = 3;
820 else if (maxChannelNumber > 9)
821 channelNumberWidth = 2;
823 channelNumberWidth = 1;
828 int VDR::streamChannel(ULONG number, StreamReceiver* tstreamReceiver)
830 VDR_RequestPacket vrp;
831 if (!vrp.init(VDR_STREAMCHANNEL, true, sizeof(ULONG))) return 0;
832 if (!vrp.addULONG(number)) return 0;
835 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
836 vdrpr->receiverChannel = VDR::CHANNEL_STREAM;
837 vdrpr->streamID = vrp.getSerial();
838 vdrpr->streamReceiver = tstreamReceiver;
840 TEMP_SINGLE_VDR_PR = vdrpr;
842 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
843 if (vresp->noResponse())
851 int toReturn = static_cast<int>(vresp->extractULONG());
852 logger->log("VDR", Log::DEBUG, "VDR said %lu to start streaming request", toReturn);
858 int VDR::stopStreaming()
860 VDR_RequestPacket vrp;
861 if (!vrp.init(VDR_STOPSTREAMING, true, 0)) return 0;
863 if (TEMP_SINGLE_VDR_PR) // this block only needs to be done if it was a live stream
864 // TEMP_SINGLE_VDR_PR will not be set unless we are streaming a channel
866 edUnregister(TEMP_SINGLE_VDR_PR);
867 delete TEMP_SINGLE_VDR_PR;
868 TEMP_SINGLE_VDR_PR = NULL;
871 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
872 if (vresp->noResponse()) { delete vresp; return 0; }
874 int toReturn = static_cast<int>(vresp->extractULONG());
880 UCHAR* VDR::getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived)
882 VDR_RequestPacket vrp;
883 if (!vrp.init(VDR_GETBLOCK, true, sizeof(ULLONG) + sizeof(ULONG))) return NULL;
884 if (!vrp.addULLONG(position)) return NULL;
885 if (!vrp.addULONG(maxAmount)) return NULL;
887 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
888 if (vresp->noResponse()) { delete vresp; return NULL; }
890 if (vresp->serverError())
892 logger->log("VDR", Log::DEBUG, "Detected getblock 0");
898 // Special handling for getblock
899 UCHAR* toReturn = vresp->getUserData();
900 *amountReceived = vresp->getUserDataLength();
907 ULLONG VDR::streamRecording(char* fileName, ULONG* totalFrames, bool* IsPesRecording)
909 VDR_RequestPacket vrp;
910 if (!vrp.init(VDR_STREAMRECORDING, true, strlen(fileName) + 1)) return 0;
911 if (!vrp.addString(fileName)) return 0;
913 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
914 if (vresp->noResponse()) { delete vresp; return 0; }
916 ULLONG lengthBytes = vresp->extractULLONG();
917 ULONG lengthFrames = vresp->extractULONG();
918 UCHAR isPesRecording = vresp->extractUCHAR();
921 *totalFrames = lengthFrames;
922 *IsPesRecording = (isPesRecording);//convert Uchar to bool
924 logger->log("VDR", Log::DEBUG, "VDR said length is: %llu %lu, IsPesRecording %x", lengthBytes, lengthFrames, *IsPesRecording);
929 ULLONG VDR::positionFromFrameNumber(ULONG frameNumber)
931 VDR_RequestPacket vrp;
932 if (!vrp.init(VDR_POSFROMFRAME, true, sizeof(ULONG))) return 0;
933 if (!vrp.addULONG(frameNumber)) return 0;
935 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
936 if (vresp->noResponse()) { delete vresp; return 0; }
938 ULLONG position = vresp->extractULLONG();
941 logger->log("VDR", Log::DEBUG, "VDR said new position is: %llu", position);
946 ULONG VDR::frameNumberFromPosition(ULLONG position)
948 VDR_RequestPacket vrp;
949 if (!vrp.init(VDR_FRAMEFROMPOS, true, sizeof(ULLONG))) return 0;
950 if (!vrp.addULLONG(position)) return 0;
952 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
953 if (vresp->noResponse()) { delete vresp; return 0; }
955 ULONG framenumber = vresp->extractULONG();
958 logger->log("VDR", Log::DEBUG, "VDR said new framenumber is: %u", framenumber);
963 bool VDR::getNextIFrame(ULONG frameNumber, ULONG direction, ULLONG* rfilePosition, ULONG* rframeNumber, ULONG* rframeLength)
965 VDR_RequestPacket vrp;
966 if (!vrp.init(VDR_GETNEXTIFRAME, true, sizeof(ULONG)*2)) return false;
967 if (!vrp.addULONG(frameNumber)) return false;
968 if (!vrp.addULONG(direction)) return false;
970 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
971 if (vresp->noResponse()) { delete vresp; return false; }
973 if (vresp->serverError())
975 logger->log("VDR", Log::DEBUG, "Detected getNextIFrame error");
980 *rfilePosition = vresp->extractULLONG();
981 *rframeNumber = vresp->extractULONG();
982 *rframeLength = vresp->extractULONG();
986 logger->log("VDR", Log::DEBUG, "VDR GNIF said %llu %lu %lu", *rfilePosition, *rframeNumber, *rframeLength);
991 EventList* VDR::getChannelSchedule(ULONG number)
995 return getChannelSchedule(number, now, 24 * 60 * 60);
998 EventList* VDR::getChannelSchedule(ULONG number, time_t start, ULONG duration)
1000 // retrieve event list (vector of events) from vdr within filter window. duration is in seconds
1002 VDR_RequestPacket vrp;
1003 if (!vrp.init(VDR_GETCHANNELSCHEDULE, true, sizeof(ULONG)*3)) return NULL;
1004 if (!vrp.addULONG(number)) return NULL;
1005 if (!vrp.addULONG(start)) return NULL;
1006 if (!vrp.addULONG(duration)) return NULL;
1008 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1009 if (vresp->noResponse()) { delete vresp; return NULL; }
1011 // received a ulong(0) - schedules error in the plugin
1012 if (vresp->serverError())
1018 EventList* eventList = new EventList();
1020 while (!vresp->end())
1022 Event* event = new Event();
1023 event->id = vresp->extractULONG();
1024 event->time = vresp->extractULONG();
1025 event->duration = vresp->extractULONG();
1026 event->title = vresp->extractString();
1027 event->subtitle = vresp->extractString();
1028 event->description = vresp->extractString();
1029 eventList->push_back(event);
1034 logger->log("VDR", Log::DEBUG, "Success got to end of getChannelSchedule");
1038 int VDR::configSave(const char* section, const char* key, const char* value)
1040 VDR_RequestPacket vrp;
1041 if (!vrp.init(VDR_CONFIGSAVE, false, 0)) return 0;
1042 if (!vrp.addString(section)) return 0;
1043 if (!vrp.addString(key)) return 0;
1044 if (!vrp.addString(value)) return 0;
1046 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1047 if (vresp->noResponse()) { delete vresp; return 0; }
1049 int toReturn = static_cast<int>(vresp->extractULONG());
1055 char* VDR::configLoad(const char* section, const char* key)
1057 VDR_RequestPacket vrp;
1058 if (!vrp.init(VDR_CONFIGLOAD, false, 0)) return NULL;
1059 if (!vrp.addString(section)) return NULL;
1060 if (!vrp.addString(key)) return NULL;
1062 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1063 if (vresp->noResponse()) { delete vresp; return NULL; }
1065 char* toReturn = vresp->extractString();
1071 RecTimerList* VDR::getRecTimersList()
1073 VDR_RequestPacket vrp;
1074 if (!vrp.init(VDR_GETTIMERS, true, 0)) return NULL;
1076 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1077 if (vresp->noResponse()) { delete vresp; return NULL; }
1079 RecTimerList* recTimerList = new RecTimerList();
1081 ULONG numTimers = vresp->extractULONG();
1084 RecTimer* newRecTimer;
1087 while (!vresp->end())
1089 newRecTimer = new RecTimer();
1090 newRecTimer->active = vresp->extractULONG();
1091 newRecTimer->recording = vresp->extractULONG();
1092 newRecTimer->pending = vresp->extractULONG();
1093 newRecTimer->priority = vresp->extractULONG();
1094 newRecTimer->lifeTime = vresp->extractULONG();
1095 newRecTimer->channelNumber = vresp->extractULONG();
1096 newRecTimer->startTime = vresp->extractULONG();
1097 newRecTimer->stopTime = vresp->extractULONG();
1098 newRecTimer->day = vresp->extractULONG();
1099 newRecTimer->weekDays = vresp->extractULONG();
1101 tempString = vresp->extractString();
1102 newRecTimer->setFile(tempString);
1103 delete[] tempString;
1105 recTimerList->push_back(newRecTimer);
1106 logger->log("VDR", Log::DEBUG, "TL: %lu %lu %lu %lu %lu %lu %lu %lu %s",
1107 newRecTimer->active, newRecTimer->recording, newRecTimer->pending, newRecTimer->priority, newRecTimer->lifeTime,
1108 newRecTimer->channelNumber, newRecTimer->startTime, newRecTimer->stopTime, newRecTimer->getFile());
1114 sort(recTimerList->begin(), recTimerList->end(), RecTimerSorter());
1116 return recTimerList;
1119 ULONG VDR::setEventTimer(char* timerString)
1121 VDR_RequestPacket vrp;
1122 if (!vrp.init(VDR_SETTIMER, true, strlen(timerString) + 1)) return 0;
1123 if (!vrp.addString(timerString)) return 0;
1125 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1126 if (vresp->noResponse()) { delete vresp; return 0; }
1128 ULONG toReturn = vresp->extractULONG();
1134 RecInfo* VDR::getRecInfo(char* fileName)
1136 VDR_RequestPacket vrp;
1137 if (!vrp.init(VDR_GETRECINFO2, true, strlen(fileName) + 1)) return NULL;
1138 if (!vrp.addString(fileName)) return NULL;
1139 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1141 if (vresp->noResponse()) { delete vresp; return NULL; }
1143 if (vresp->serverError())
1145 logger->log("VDR", Log::DEBUG, "Could not get rec info");
1150 RecInfo* recInfo = new RecInfo();
1152 recInfo->timerStart = vresp->extractULONG();
1153 recInfo->timerEnd = vresp->extractULONG();
1154 recInfo->resumePoint = vresp->extractULONG();
1155 recInfo->summary = vresp->extractString();
1157 ULONG numComponents = vresp->extractULONG();
1160 recInfo->setNumComponents(numComponents);
1161 for (ULONG i = 0; i < numComponents; i++)
1163 recInfo->streams[i] = vresp->extractUCHAR();
1164 recInfo->types[i] = vresp->extractUCHAR();
1165 recInfo->languages[i] = vresp->extractString();
1166 recInfo->descriptions[i] = vresp->extractString();
1169 recInfo->fps=vresp->extractdouble();
1170 recInfo->title=vresp->extractString();
1173 recInfo->channelName = vresp->extractString();
1174 recInfo->duration = vresp->extractULONG();
1175 recInfo->fileSize = vresp->extractULONG();
1176 recInfo->priority = vresp->extractULONG();
1177 recInfo->lifetime = vresp->extractULONG();
1186 ULLONG VDR::rescanRecording(ULONG* totalFrames)
1188 VDR_RequestPacket vrp;
1189 if (!vrp.init(VDR_RESCANRECORDING, true, 0)) return 0;
1191 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1192 if (vresp->noResponse()) { delete vresp; return 0; }
1194 ULLONG lengthBytes = vresp->extractULLONG();
1195 ULONG lengthFrames = vresp->extractULONG();
1198 logger->log("VDR", Log::DEBUG, "VDR said length is: %llu %lu", lengthBytes, lengthFrames);
1200 *totalFrames = lengthFrames;
1204 MarkList* VDR::getMarks(char* fileName)
1206 VDR_RequestPacket vrp;
1207 if (!vrp.init(VDR_GETMARKS, true, strlen(fileName) + 1)) return NULL;
1208 if (!vrp.addString(fileName)) return NULL;
1210 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1211 if (vresp->noResponse()) { delete vresp; return NULL; }
1213 if (vresp->serverError())
1219 MarkList* markList = new MarkList();
1221 while (!vresp->end())
1223 Mark* mark = new Mark();
1224 mark->pos = vresp->extractULONG();
1226 markList->push_back(mark);
1227 logger->log("VDR", Log::DEBUG, "Have added a mark to list. %lu", mark->pos);
1235 void VDR::getChannelPids(Channel* channel)
1237 VDR_RequestPacket vrp;
1238 if (!vrp.init(VDR_GETCHANNELPIDS, true, sizeof(ULONG))) return ;
1239 if (!vrp.addULONG(channel->number)) return ;
1241 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1242 if (vresp->noResponse()) { delete vresp; return ; }
1244 // Format of response
1252 channel->vpid = vresp->extractULONG();
1253 channel->vstreamtype = static_cast<UCHAR>(vresp->extractULONG());
1254 channel->numAPids = vresp->extractULONG();
1256 for (ULONG i = 0; i < channel->numAPids; i++)
1259 newapid.pid = vresp->extractULONG();
1260 char * name=vresp->extractString();
1261 strncpy(newapid.desc,name,9);
1263 channel->apids.push_back(newapid);
1266 channel->numDPids = vresp->extractULONG();
1268 for (ULONG i = 0; i < channel->numDPids; i++)
1271 newdpid.pid = vresp->extractULONG();
1272 char * name=vresp->extractString();
1273 strncpy(newdpid.desc,name,9);
1275 channel->dpids.push_back(newdpid);
1278 channel->numSPids = vresp->extractULONG();
1280 for (ULONG i = 0; i < channel->numSPids; i++)
1283 newspid.pid = vresp->extractULONG();
1284 char * name=vresp->extractString();
1285 strncpy(newspid.desc,name,9);
1287 channel->spids.push_back(newspid);
1289 channel->tpid = vresp->extractULONG();
1291 for (ULONG i = 0; i < channel->numAPids; i++)
1293 channel->apids[i].type = vresp->extractULONG();
1295 for (ULONG i = 0; i < channel->numDPids; i++)
1297 channel->dpids[i].type = vresp->extractULONG();
1299 for (ULONG i = 0; i < channel->numSPids; i++)
1301 channel->spids[i].type = vresp->extractULONG();
1302 channel->spids[i].data1 = vresp->extractULONG();
1303 channel->spids[i].data2 = vresp->extractULONG();
1311 #ifdef VOMP_MEDIAPLAYER
1312 MediaList * VDR::getRootList() {
1313 return getMediaList(NULL);
1316 * media List Request:
1318 * Media List response:
1321 MediaList* VDR::getMediaList(const MediaURI * root)
1323 logger->log("VDR", Log::DEBUG, "getMediaList %s,d=%s, prov=%d", (root?root->getName():"NULL"),
1324 ((root && root->hasDisplayName())?root->getDisplayName():"NULL"),
1325 (root?root->getProvider():providerId));
1326 MediaURI remoteURI(root);
1327 VDR_GetMediaListRequest request(&remoteURI);
1328 SerializeBuffer *vrp=prepareRequest(&request);
1330 logger->log("VDR", Log::ERR, "getMediaList unable to create command");
1334 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1336 Command::getInstance()->connectionLost();
1340 MediaList *rt=new MediaList(NULL);
1342 VDR_GetMediaListResponse resp(&rtflags,rt);
1343 if (decodeResponse(vresp,&resp) != 0) {
1350 * get image Request:
1352 * get media response:
1356 int VDR::openMedium(ULONG channel,const MediaURI *uri, ULLONG * size, ULONG x, ULONG y)
1358 MediaURI remoteURI(uri);
1359 VDR_OpenMediumRequest request(&channel,&remoteURI,&x,&y);
1361 SerializeBuffer *vrp=prepareRequest(&request);
1363 logger->log("VDR", Log::ERR, "openMedium unable to create command");
1366 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1368 Command::getInstance()->connectionLost();
1372 VDR_OpenMediumResponse response(&flags,size);
1373 if (decodeResponse(vresp,&response) != 0) {
1376 logger->log("VDR", Log::DEBUG, "openMedia len=%llu", *size);
1381 * getMediaBlock - no separate response class - simple data block
1385 int VDR::getMediaBlock(ULONG channel, ULLONG position, ULONG maxAmount, ULONG* amountReceived, unsigned char **buffer)
1388 VDR_GetMediaBlockRequest request(&channel,&position,&maxAmount);
1389 SerializeBuffer *vrp=prepareRequest(&request);
1391 logger->log("VDR", Log::ERR, "getMediaBlock unable to create command");
1394 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1396 Command::getInstance()->connectionLost();
1400 // Special handling for getblock
1401 *amountReceived = (ULONG)(vresp->getEnd()-vresp->getStart());
1402 *buffer = vresp->steelBuffer();
1415 int VDR::getMediaInfo(ULONG channel, MediaInfo * result) {
1416 if (! result) return -1;
1417 VDR_GetMediaInfoRequest request(&channel);
1418 SerializeBuffer *vrp=prepareRequest(&request);
1420 logger->log("VDR", Log::ERR, "getMediaInfo unable to create command");
1423 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1425 Command::getInstance()->connectionLost();
1430 VDR_GetMediaInfoResponse response(&flags,result);
1431 if (decodeResponse(vresp,&response) != 0) {
1444 int VDR::closeMediaChannel(ULONG channel) {
1445 VDR_CloseMediaChannelRequest request(&channel);
1446 SerializeBuffer *vrp=prepareRequest(&request);
1448 logger->log("VDR", Log::ERR, "closeMediaChannel unable to create command");
1451 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1453 Command::getInstance()->connectionLost();
1457 VDR_CloseMediaChannelResponse response(&flags);
1458 if (decodeResponse(vresp,&response) != 0) return -1;
1459 return (flags != 0)?-1:0;
1465 int VDR::deleteTimer(RecTimer* delTimer)
1467 logger->log("VDR", Log::DEBUG, "Delete timer called");
1469 VDR_RequestPacket vrp;
1470 if (!vrp.init(VDR_DELETETIMER, false, 0)) return 0;
1471 if (!vrp.addULONG(delTimer->channelNumber)) return 0;
1472 if (!vrp.addULONG(delTimer->weekDays)) return 0;
1473 if (!vrp.addULONG(delTimer->day)) return 0;
1474 if (!vrp.addULONG(delTimer->startTime)) return 0;
1475 if (!vrp.addULONG(delTimer->stopTime)) return 0;
1477 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1478 if (vresp->noResponse()) { delete vresp; return 0; }
1480 int toReturn = static_cast<int>(vresp->extractULONG());
1486 I18n::lang_code_list VDR::getLanguageList()
1488 I18n::lang_code_list CodeList;
1489 CodeList["en"] = "English"; // Default entry
1490 VDR_RequestPacket vrp;
1491 if (!vrp.init(VDR_GETLANGUAGELIST, false, 0)) return CodeList;
1492 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1493 if (vresp->noResponse() || vresp->end())
1499 while (!vresp->end())
1501 char* c_code = vresp->extractString();
1502 char* c_name = vresp->extractString();
1503 std::string code = c_code;
1504 std::string name = c_name;
1505 CodeList[code] = name;
1513 int VDR::getLanguageContent(const std::string code, I18n::trans_table& texts)
1515 VDR_RequestPacket vrp;
1516 if (!vrp.init(VDR_GETLANGUAGECONTENT, false, 0)) return 0;
1517 if (!vrp.addString(code.c_str())) return 0;
1518 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1519 if (vresp->noResponse()) { delete vresp; return 0; }
1521 while (!vresp->end())
1523 char* c_key = vresp->extractString();
1524 char* c_text = vresp->extractString();
1525 std::string key = c_key;
1526 std::string text = c_text;
1535 void VDR::shutdownVDR()
1538 logger->log("VDR", Log::DEBUG, "Shutting down vdr");
1540 logger->log("VDR", Log::DEBUG, "Shutting down vomp only");
1542 if(!doVDRShutdown || !connected)
1545 VDR_RequestPacket vrp;
1546 logger->log("VDR", Log::DEBUG, "Sending shutdown");
1547 if (!vrp.init(VDR_SHUTDOWN, false, 0)) return;
1548 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1551 logger->log("VDR", Log::DEBUG, "VDR shutdown");
1554 void VDR::getScraperEventType(char * fileName, int & movieID,
1555 int & seriesID, int & episodeID)
1560 VDR_RequestPacket vrp;
1561 if (!vrp.init(VDR_GETRECSCRAPEREVENTTYPE, true, strlen(fileName) + 1)) return;
1562 if (!vrp.addString(fileName)) return ;
1563 Log::getInstance()->log("Recording", Log::DEBUG, "Before Response ");
1564 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1565 Log::getInstance()->log("Recording", Log::DEBUG, "After Response ");
1566 if (vresp->noResponse()) { delete vresp; return ; }
1567 int type = vresp->extractUCHAR();
1568 if (type == 0) //serie
1570 seriesID = vresp->extractLONG();
1571 episodeID = vresp->extractLONG();
1572 } else if (type == 1) //movie
1574 movieID = vresp->extractLONG();
1580 void VDR::getScraperEventType(UINT channelid, UINT eventid, int & movieID,
1581 int & seriesID, int & episodeID, int & epgImage )
1587 VDR_RequestPacket vrp;
1588 if (!vrp.init(VDR_GETEVENTSCRAPEREVENTTYPE, false, 0)) return;
1589 if (!vrp.addULONG(channelid)) return ;
1590 if (!vrp.addULONG(eventid)) return ;
1591 Log::getInstance()->log("Recording", Log::DEBUG, "Before Response ");
1592 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1593 Log::getInstance()->log("Recording", Log::DEBUG, "After Response ");
1594 if (vresp->noResponse()) { delete vresp; return ; }
1595 int type = vresp->extractUCHAR();
1596 if (type == 0) //serie
1598 seriesID = vresp->extractLONG();
1599 episodeID = vresp->extractLONG();
1600 } else if (type == 1) //movie
1602 movieID = vresp->extractLONG();
1604 epgImage = vresp->extractLONG();
1609 MovieInfo *VDR::getScraperMovieInfo(int movieID)
1611 VDR_RequestPacket vrp;
1612 if (!vrp.init(VDR_GETSCRAPERMOVIEINFO, false, 0)) return NULL;
1613 if (!vrp.addULONG(movieID)) return NULL;
1614 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1615 if (vresp->noResponse()) { delete vresp; return NULL; }
1616 MovieInfo * movieinf= new MovieInfo();
1618 movieinf->id=movieID;
1619 movieinf->title = vresp->extractStdString();
1620 movieinf->originalTitle = vresp->extractStdString();
1621 movieinf->tagline = vresp->extractStdString();
1622 movieinf->overview = vresp->extractStdString();
1623 movieinf->adult = vresp->extractUCHAR();
1624 movieinf->collectionName = vresp->extractStdString();
1626 movieinf->budget = vresp->extractLONG();
1627 movieinf->revenue = vresp->extractLONG();
1628 movieinf->genres = vresp->extractStdString();
1629 movieinf->homepage = vresp->extractStdString();
1630 movieinf->releaseDate = vresp->extractStdString();
1631 movieinf->runtime = vresp->extractLONG();
1632 movieinf->popularity = vresp->extractdouble();
1633 movieinf->voteAverage = vresp->extractdouble();
1634 movieinf->poster.width = vresp->extractULONG();
1635 movieinf->poster.height = vresp->extractULONG();
1636 movieinf->poster.info.setMovieInfo(movieinf);
1637 movieinf->poster.info.setElement(0,0);
1638 movieinf->fanart.width = vresp->extractULONG();
1639 movieinf->fanart.height = vresp->extractULONG();
1640 movieinf->fanart.info.setMovieInfo(movieinf);
1641 movieinf->fanart.info.setElement(1,0);
1642 movieinf->collectionPoster.width = vresp->extractULONG();
1643 movieinf->collectionPoster.height = vresp->extractULONG();
1644 movieinf->collectionPoster.info.setMovieInfo(movieinf);
1645 movieinf->collectionPoster.info.setElement(2,0);
1646 movieinf->collectionFanart.width = vresp->extractULONG();
1647 movieinf->collectionFanart.height = vresp->extractULONG();
1648 movieinf->collectionFanart.info.setMovieInfo(movieinf);
1649 movieinf->collectionFanart.info.setElement(3,0);
1650 ULONG num_actors = vresp->extractULONG();
1651 movieinf->actors.clear();
1652 movieinf->actors.reserve(num_actors);
1653 for (ULONG acty=0; acty < num_actors; acty++) {
1655 new_act.name = vresp->extractStdString();
1656 new_act.role = vresp->extractStdString();
1657 new_act.thumb.width = vresp->extractULONG();
1658 new_act.thumb.height = vresp->extractULONG();
1659 new_act.thumb.info.setMovieInfo(movieinf);
1660 new_act.thumb.info.setElement(4,acty);
1661 movieinf->actors.push_back(new_act);
1670 SeriesInfo *VDR::getScraperSeriesInfo(int seriesID, int episodeID)
1672 VDR_RequestPacket vrp;
1673 if (!vrp.init(VDR_GETSCRAPERSERIESINFO, false, 0)) return NULL;
1674 if (!vrp.addULONG(seriesID)) return NULL;
1675 if (!vrp.addULONG(episodeID)) return NULL;
1677 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1678 if (vresp->noResponse()) { delete vresp; return 0; }
1679 SeriesInfo * seriesinf= new SeriesInfo();
1681 seriesinf->id=seriesID;
1684 seriesinf->name = vresp->extractStdString();
1685 seriesinf->overview = vresp->extractStdString();
1686 seriesinf->firstAired = vresp->extractStdString();
1687 seriesinf->network = vresp->extractStdString();
1688 seriesinf->genre = vresp->extractStdString();
1689 seriesinf->rating = vresp->extractdouble();
1690 seriesinf->status = vresp->extractStdString();
1693 seriesinf->episode.episodeid=episodeID;
1694 seriesinf->episode.number = vresp->extractLONG();
1695 seriesinf->episode.season = vresp->extractLONG();
1696 seriesinf->episode.name = vresp->extractStdString();
1697 seriesinf->episode.firstAired = vresp->extractStdString();
1698 seriesinf->episode.guestStars = vresp->extractStdString();
1699 seriesinf->episode.overview = vresp->extractStdString();
1700 seriesinf->episode.rating = vresp->extractdouble();
1701 seriesinf->episode.image.width = vresp->extractULONG();
1702 seriesinf->episode.image.height = vresp->extractULONG();
1703 seriesinf->episode.image.info.setSeriesInfo(seriesinf);
1704 seriesinf->episode.image.info.setElement(0,0);
1707 ULONG num_actors = vresp->extractULONG();
1708 seriesinf->actors.clear();
1709 seriesinf->actors.reserve(num_actors);
1710 for (ULONG acty=0; acty < num_actors; acty++) {
1712 new_act.name = vresp->extractStdString();
1713 new_act.role = vresp->extractStdString();
1714 new_act.thumb.width = vresp->extractULONG();
1715 new_act.thumb.height = vresp->extractULONG();
1716 new_act.thumb.info.setSeriesInfo(seriesinf);
1717 new_act.thumb.info.setElement(1,acty);
1718 seriesinf->actors.push_back(new_act);
1720 ULONG num_posters = vresp->extractULONG();
1721 for (ULONG medias = 0; medias < num_posters; medias++ ) {
1723 media.info.setSeriesInfo(seriesinf);
1724 media.info.setElement(2,medias);
1725 media.width = vresp->extractULONG();
1726 media.height = vresp->extractULONG();
1727 seriesinf->posters.push_back(media);
1730 ULONG num_banners = vresp->extractULONG();
1731 for (ULONG medias = 0; medias < num_banners; medias++ ) {
1733 media.info.setSeriesInfo(seriesinf);
1734 media.info.setElement(3,medias);
1735 media.width = vresp->extractULONG();
1736 media.height = vresp->extractULONG();
1737 seriesinf->banners.push_back(media);
1739 ULONG num_fanarts = vresp->extractULONG();
1740 for (ULONG medias = 0; medias < num_fanarts; medias++ ) {
1742 media.info.setSeriesInfo(seriesinf);
1743 media.info.setElement(4,medias);
1744 media.width = vresp->extractULONG();
1745 media.height = vresp->extractULONG();
1746 seriesinf->fanart.push_back(media);
1748 seriesinf->seasonposter.width = vresp->extractULONG();
1749 seriesinf->seasonposter.height = vresp->extractULONG();
1750 seriesinf->seasonposter.info.setSeriesInfo(seriesinf);
1751 seriesinf->seasonposter.info.setElement(5,0);
1758 ULONG VDR::loadTVMedia(TVMediaInfo& tvmedia)
1760 VDR_RequestPacket vrp;
1762 if (!vrp.init(VDR_LOADTVMEDIA, false, 0)) return ULONG_MAX;
1763 if (!vrp.addULONG(tvmedia.type)) return ULONG_MAX;
1764 if (!vrp.addULONG(tvmedia.primary_id)) return ULONG_MAX;
1765 if (!vrp.addULONG(tvmedia.secondary_id)) return ULONG_MAX;
1766 if (!vrp.addULONG(tvmedia.type_pict)) return ULONG_MAX;
1767 if (!vrp.addULONG(tvmedia.container)) return ULONG_MAX;
1768 if (!vrp.addULONG(tvmedia.container_member)) return ULONG_MAX;
1769 /* Log::getInstance()->log("VDR", Log::DEBUG, "TVMedia with ID %d %d; %d %d %d %d;%d",
1770 tvmedia.primary_id,tvmedia.secondary_id,tvmedia.type,tvmedia.type_pict,
1771 tvmedia.container,tvmedia.container_member,vrp.getSerial());*/
1774 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
1775 vdrpr->receiverChannel = VDR::CHANNEL_TVMEDIA;
1776 vdrpr->streamID = vrp.getSerial();
1777 vdrpr->streamReceiver = NULL;
1781 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1782 //if (vresp->noResponse()) { delete vresp; return ULONG_MAX; }
1785 return vrp.getSerial();
1788 ULONG VDR::loadTVMediaRecThumb(TVMediaInfo & media)
1791 VDR_RequestPacket vrp;
1793 if (!vrp.init(VDR_LOADTVMEDIARECTHUMB, false, 0)) return ULONG_MAX;
1794 if (!vrp.addString(media.primary_name.c_str())) return ULONG_MAX;
1796 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
1797 vdrpr->receiverChannel = VDR::CHANNEL_TVMEDIA;
1798 vdrpr->streamID = vrp.getSerial();
1799 vdrpr->streamReceiver = NULL;
1803 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1804 //if (vresp->noResponse()) { delete vresp; return ULONG_MAX; }
1807 return vrp.getSerial();
1810 ULONG VDR::loadTVMediaEventThumb(TVMediaInfo & media)
1813 VDR_RequestPacket vrp;
1815 if (!vrp.init(VDR_LOADTVMEDIAEVENTTHUMB, false, 0)) return ULONG_MAX;
1816 if (!vrp.addULONG(media.primary_id)) return ULONG_MAX;
1817 if (!vrp.addULONG(media.secondary_id)) return ULONG_MAX;
1819 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
1820 vdrpr->receiverChannel = VDR::CHANNEL_TVMEDIA;
1821 vdrpr->streamID = vrp.getSerial();
1822 vdrpr->streamReceiver = NULL;
1826 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1827 //if (vresp->noResponse()) { delete vresp; return ULONG_MAX; }
1830 return vrp.getSerial();
1833 ULONG VDR::loadChannelLogo(TVMediaInfo & media)
1836 VDR_RequestPacket vrp;
1838 if (!vrp.init(VDR_LOADCHANNELLOGO, false, 0)) return ULONG_MAX;
1839 if (!vrp.addULONG(media.primary_id)) return ULONG_MAX;
1841 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
1842 vdrpr->receiverChannel = VDR::CHANNEL_TVMEDIA;
1843 vdrpr->streamID = vrp.getSerial();
1844 vdrpr->streamReceiver = NULL;
1848 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1849 //if (vresp->noResponse()) { delete vresp; return ULONG_MAX; }
1852 // Log::getInstance()->log("VDR", Log::DEBUG, "TVMedia Channel Logo %d %x",
1853 // media.primary_id,vrp.getSerial());
1855 return vrp.getSerial();