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/>.
30 #include "vdrrequestpacket.h"
31 #include "vdrresponsepacket.h"
34 #ifdef VOMP_MEDIAPLAYER
36 #include "mediaprovider.h"
37 #include "mediaproviderids.h"
39 #include "vdrcommand.h"
42 #include "movieinfo.h"
43 #include "seriesinfo.h"
44 #include "osdvector.h"
48 #define VOMP_PROTOCOL_VERSION 0x00000500
50 VDR* VDR::instance = NULL;
51 #ifdef VOMP_MEDIAPLAYER
53 //will create a request package from a command variable and fill this
54 //caller has to destroy buffer
55 static SerializeBuffer * prepareRequest(VDR_Command *cmd) {
56 SerializeBuffer *buf=new SerializeBuffer(512,false,true);
57 if (cmd->serialize(buf) != 0) {
64 //handle request/response
65 //TODO avoid copy of buffer (needs extension of requestpacket)
66 //TODO avoid command 2x (needs some more restructuring)
67 SerializeBuffer * VDR::doRequestResponse(SerializeBuffer *rq,int cmd) {
68 VDR_RequestPacket *rt=new VDR_RequestPacket;
73 if (! rt->init(cmd,true,rq->getCurrent()-rq->getStart())) {
78 if (! rt->copyin(rq->getStart(),(ULONG)(rq->getCurrent()-rq->getStart()))) {
84 VDR_ResponsePacket *rp=RequestResponse(rt);
85 logger->log("doRequestResponse",Log::DEBUG,"got response %p",rp);
90 SerializeBuffer *buf=new SerializeBuffer(rp->getUserData(),rp->getUserDataLength(),true,true,false);
97 //deserialize a received response
100 static int decodeResponse(SerializeBuffer *rp,VDR_Command *c) {
101 ULONG expected=c->command;
102 if (c->deserialize(rp) != 0) {
104 Log::getInstance()->log("VDR", Log::ERR, "decodeResponse unable to deserialize for command %lu",expected);
108 if (c->command != expected) {
109 Log::getInstance()->log("VDR", Log::ERR, "decodeResponse unexpected response received 0x%lx, expected 0x%lx",c->command,expected);
112 Log::getInstance()->log("VDR", Log::DEBUG, "decodeResponse successfully decoded command 0x%lx",expected);
120 if (instance) return;
123 TEMP_SINGLE_VDR_PR = NULL; // FIXME what is this
124 #ifdef VOMP_MEDIAPLAYER
125 providerId=MPROVIDERID_VDR;
126 subRange=MPROVIDERRANGE_VDR;
127 MediaPlayerRegister::getInstance()->registerMediaProvider(this,MPROVIDERID_VDR,MPROVIDERRANGE_VDR);
134 if (initted) shutdown();
137 VDR* VDR::getInstance()
144 if (initted) return 0;
146 logger = Log::getInstance();
152 if (!initted) return 0;
158 void VDR::findServers(std::vector<VDRServer>& servers)
160 Wol* wol = Wol::getInstance();
163 memset(message, 0, 15);
164 strcpy(message, "VDP-0001");
165 /*tcp->getMAC(&message[9]); put mac here when TCP modified to do this*/
168 // FIXME Horrible hack. Rewrite all this.
169 // Change away from relying on the dsock select to do the timing
170 // Do timing here and let UDP4 / UDP6 objects/threads just wait
176 DatagramSocket ds(0);
177 int haveAtLeastOne = 0;
180 bool firstloop = true;
187 logger->log("VDR", Log::NOTICE, "Broadcasting for server");
188 ds.send("255.255.255.255", 51051U, message, 15);
189 ds.send("255.255.255.255", 51052U, message, 15);
190 ds.send("255.255.255.255", 51053U, message, 15);
191 ds.send("255.255.255.255", 51054U, message, 15);
192 ds.send("255.255.255.255", 51055U, message, 15);
193 if(!firstloop) wol->doWakeUp();
195 retval = ds.waitforMessage(waitType);
197 if (retval == 2) // we got a reply
201 const char* vdpreply = static_cast<const char*>(ds.getData());
202 if ((ds.getDataLength() >= 24) && !strncmp(vdpreply, "VDP-0002", 8))
204 // FIXME upgrade this to look for a return IP in the reply packet
206 USHORT newServerPort;
207 memcpy(&newServerPort, &vdpreply[26], 2);
209 ULONG newServerVersion;
210 memcpy(&newServerVersion, &vdpreply[28], 4);
213 // FIXME - packet length > 24 not checked, end NULL not checked!!
214 // FIXME mutex protection ?? Nope this is a separate vector currently
215 servers.emplace_back(ds.getFromIPA(), &vdpreply[32], ntohs(newServerPort), ntohl(newServerVersion));
220 if (haveAtLeastOne) break;
222 if (vdp6.numFound()) break;
229 logger->log("VDR", Log::NOTICE, "END loop");
233 std::vector<VDRServer>* servers6 = vdp6.getServers();
235 // Add IPv6 found servers to servers vector, if not in servers already
237 for(auto i6 = servers6->begin(); i6 != servers6->end(); i6++)
241 for(auto i4 = servers.begin(); i4 != servers.end(); i4++)
242 if (i4->name == i6->name) { found = true; break; }
244 if (found) continue; // Don't add
246 servers.push_back(std::move(*i6)); // VDP6 is stopped, the vector owner only goes out of scope after this method
251 sort(servers.begin(), servers.end(), ServerSorter());
254 void VDR::cancelFindingServer()
259 void VDR::setServerIP(const char* newIP)
261 strcpy(serverIP, newIP);
264 void VDR::setServerPort(USHORT newPort)
266 serverPort = newPort;
271 maxChannelNumber = 0;
272 channelNumberWidth = 1;
276 if (tcp->connectTo(serverIP, serverPort))
288 void VDR::disconnect()
294 logger->log("VDR", Log::DEBUG, "Disconnect");
297 void VDR::setReceiveWindow(size_t size)
299 if (connected && size) tcp->setReceiveWindow(size);
302 ///////////////////////////////////////////////////////
304 void VDR::threadMethod()
306 logger->log("VDR", Log::DEBUG, "VDR RUN");
308 threadSetKillable(); // FIXME - change this to deal with the EDRs
313 ULONG userDataLength;
319 VDR_ResponsePacket* vresp;
322 ULONG lastKAsent = 0;
323 ULONG lastKArecv = time(NULL);
328 timeNow = time(NULL);
330 readSuccess = tcp->readData(&channelID, sizeof(ULONG)); // 2s timeout atm
334 //logger->log("VDR", Log::DEBUG, "Net read timeout");
335 if (!tcp->isConnected()) { connectionDied(); return; } // return to stop this thread
340 if (!lastKAsent) // have not sent a KA
342 if (lastKArecv < (timeNow - 5))
344 //logger->log("VDR", Log::DEBUG, "Sending KA packet");
345 if (!sendKA(timeNow))
347 logger->log("VDR", Log::DEBUG, "Could not send KA, calling connectionDied");
351 lastKAsent = timeNow;
356 if (lastKAsent <= (timeNow - 10))
358 logger->log("VDR", Log::DEBUG, "lastKA over 10s ago, calling connectionDied");
364 if (!readSuccess) continue; // no data was read but the connection is ok.
368 channelID = ntohl(channelID);
370 if (channelID == CHANNEL_REQUEST_RESPONSE)
372 if (!tcp->readData(&requestID, sizeof(ULONG))) break;
373 requestID = ntohl(requestID);
374 if (!tcp->readData(&userDataLength, sizeof(ULONG))) break;
375 userDataLength = ntohl(userDataLength);
376 if (userDataLength > 5000000) break; // how big can these packets get?
378 if (userDataLength > 0)
380 userData = malloc(userDataLength);
381 if (!userData) break;
382 if (!tcp->readData(userData, userDataLength)) break;
385 vresp = new VDR_ResponsePacket();
386 vresp->setResponse(requestID, reinterpret_cast<UCHAR*>(userData), userDataLength);
387 // logger->log("VDR", Log::DEBUG, "Rxd a response packet, requestID=%lu, len=%lu", requestID, userDataLength);
389 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
391 // If edFindAndCall returns true, edr was called and vresp was handed off.
392 // else, delete vresp here.
396 else if (channelID == CHANNEL_STREAM || channelID == CHANNEL_TVMEDIA)
398 if (!tcp->readData(&streamID, sizeof(ULONG))) break;
399 streamID = ntohl(streamID);
401 if (!tcp->readData(&flag, sizeof(ULONG))) break;
404 if (!tcp->readData(&userDataLength, sizeof(ULONG))) break;
405 userDataLength = ntohl(userDataLength);
407 if (userDataLength > 0)
409 userData = malloc(userDataLength);
410 if (!userData) break;
411 if (!tcp->readData(userData, userDataLength)) break;
414 vresp = new VDR_ResponsePacket();
415 vresp->setStream(streamID, flag, reinterpret_cast<UCHAR*>(userData), userDataLength, channelID);
416 //logger->log("VDR", Log::DEBUG, "Rxd a stream packet, streamID=%lu, flag=%lu, len=%lu", streamID, flag, userDataLength);
418 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
420 // If edFindAndCall returns true, edr was called and vresp was handed off.
421 // else, delete vresp here.
425 else if (channelID == CHANNEL_KEEPALIVE)
428 if (!tcp->readData(&KAreply, sizeof(ULONG))) break;
429 KAreply = ntohl(KAreply);
430 if (KAreply == lastKAsent) // successful KA response
433 lastKArecv = KAreply;
434 //logger->log("VDR", Log::DEBUG, "Rxd correct KA reply");
439 logger->log("VDR", Log::ERR, "Rxd a response packet on channel %lu !!", channelID);
445 // Who deletes vresp?
446 // If RR, the individual protocol functions must delete vresp.
447 // If stream, the data and length is taken out in ed_cb_call and vresp is deleted there.
453 void VDR::connectionDied()
455 // Called from within threadMethod to do cleanup if it decides the connection has died
457 connected = false; // though actually it could still be connected until someone calls vdr->disconnect
459 // Need to wake up any waiting channel 1 request-response threads
460 // Normally this is done by a packet coming in with channelid and requestid
461 // Instead, go through the list and for each channel 1 edr, make an empty vresp
462 // An empty vresp will have userData == NULL, which means vresp->noResponse() == true
464 // If it's a stream receiver, generate a stream packet with flag == connection_lost
467 VDR_PacketReceiver* vdrpr;
468 VDR_ResponsePacket* vresp;
469 while(receivers.size())
471 vdrpr = dynamic_cast<VDR_PacketReceiver*>(*(receivers.begin()));
472 if (vdrpr->receiverChannel == CHANNEL_REQUEST_RESPONSE)
474 vresp = new VDR_ResponsePacket();
475 vresp->setResponse(vdrpr->requestSerialNumber, NULL, 0);
476 logger->log("VDR", Log::DEBUG, "Timeouts: created blank response packet for request serial %lu", vdrpr->requestSerialNumber);
478 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
480 // If edFindAndCall returns true, edr was called and vresp was handed off.
481 // else, delete vresp here.
482 logger->log("VDR", Log::ERR, "Timeouts: no waiting thread found for request serial %lu !!!", vdrpr->requestSerialNumber);
487 else if (vdrpr->receiverChannel == CHANNEL_STREAM || vdrpr->receiverChannel == CHANNEL_TVMEDIA)
489 vresp = new VDR_ResponsePacket();
490 vresp->setStream(vdrpr->streamID, 2 /* connection-lost flag */ , NULL, 0, vdrpr->receiverChannel);
491 logger->log("VDR", Log::DEBUG, "Timeouts: created blank response packet for streamid %lu", vdrpr->streamID);
493 if (!edFindAndCall(vresp)) // makes ED lock, find receiver for vresp (using ed_cb_find() ) and then call (using ed_cb_call() )
495 // If edFindAndCall returns true, edr was called and vresp was handed off.
496 // else, delete vresp here.
497 logger->log("VDR", Log::ERR, "Timeouts: no waiting stream receiver found for streamid %lu !!!", vdrpr->streamID);
502 for(EDRL::iterator i = receivers.begin(); i != receivers.end(); i++)
503 if (dynamic_cast<VDR_PacketReceiver*>(*i) == vdrpr) { receivers.erase(i); break; }
507 // Ok, all event receviers should be dealt with. just in case there weren't any, inform command
508 logger->log("VDR", Log::DEBUG, "edUnlock at end of connectionDied");
510 Command::getInstance()->connectionLost();
513 bool VDR::ed_cb_find(EDReceiver* edr, void* userTag)
515 // edr is a VDR_PacketReceiver object made in VDR::RequestResponse
516 // userTag is a VDR_ResponsePacket made in threadMethod
518 VDR_PacketReceiver* vdrpr = dynamic_cast<VDR_PacketReceiver*>(edr);
519 VDR_ResponsePacket* vresp = reinterpret_cast<VDR_ResponsePacket*>(userTag);
521 // Is vresp for vdrpr ?
523 ULONG packetChannel = vresp->getChannelID();
524 //logger->log("VDR", Log::DEBUG, "TVMedia debug %d %d %x", vdrpr->receiverChannel,packetChannel,vdrpr);
525 if (vdrpr->receiverChannel != packetChannel) return false;
527 if (packetChannel == CHANNEL_REQUEST_RESPONSE)
529 if (vdrpr->requestSerialNumber == vresp->getRequestID()) return true;
531 else if (packetChannel == CHANNEL_STREAM)
533 if (vdrpr->streamID == vresp->getStreamID()) return true;
535 else if (packetChannel == CHANNEL_TVMEDIA)
537 if (vdrpr->streamID == vresp->getStreamID()) return true;
543 VDR_ResponsePacket* VDR::RequestResponse(VDR_RequestPacket* vrp)
545 //logger->log("VDR", Log::DEBUG, "RR %lu", vrp->getOpcode());
549 logger->log("VDR", Log::DEBUG, "RR when !connected");
550 VDR_ResponsePacket* vresp = new VDR_ResponsePacket();
551 return vresp; // "no-response" return
554 // ED make new VDR and register
555 // make a VDR_PacketReceiver
556 // - init with serial number of request packet
558 VDR_PacketReceiver vdrpr;
559 // vdrpr.requestTime = time(NULL);
560 vdrpr.receiverChannel = VDR::CHANNEL_REQUEST_RESPONSE;
561 vdrpr.requestSerialNumber = vrp->getSerial();
568 if (static_cast<ULONG>(tcp->sendData(vrp->getPtr(), vrp->getLen())) != vrp->getLen())
571 edUnregister(&vdrpr);
572 VDR_ResponsePacket* vresp = new VDR_ResponsePacket();
573 return vresp; // "no-response" return
576 // Sleep and block this thread. The sleep unlocks the mutex
577 // logger->log("VDR", Log::DEBUG, "RR sleep - opcode %lu", vrp->getOpcode());
578 edSleepThisReceiver(&vdrpr);
579 // logger->log("VDR", Log::DEBUG, "RR unsleep");
581 // Woken because a response packet has arrived, mutex will be locked
582 // logger->log("VDR", Log::DEBUG, "Packet delivered to me, requestID: %lu", vdrpr.save_vresp->getRequestID());
585 return vdrpr.save_vresp;
588 bool VDR::sendKA(ULONG timeStamp)
593 ULONG ul=CHANNEL_KEEPALIVE;
594 buffer[pos++]=(ul>>24)&0xff;
595 buffer[pos++]=(ul>>16)&0xff;
596 buffer[pos++]=(ul>>8)&0xff;
597 buffer[pos++]=ul &0xff;
599 buffer[pos++]=(ul>>24)&0xff;
600 buffer[pos++]=(ul>>16)&0xff;
601 buffer[pos++]=(ul>>8)&0xff;
602 buffer[pos++]=ul &0xff;
603 if (static_cast<ULONG>(tcp->sendData(buffer, 8)) != 8) return false;
607 /////////////////////////////////////////////////////////////////////////////
609 // Here VDR takes a break for the VDR_PacketReceiver helper class
611 void VDR_PacketReceiver::call(void* userTag, bool& r_deregisterEDR, bool& r_wakeThread, bool& r_deleteEDR)
613 if (receiverChannel == VDR::CHANNEL_REQUEST_RESPONSE)
615 // It's a RR. Save vresp and, signal the waiting thread and return.
616 // VDR::RequestResponse will be blocking waiting for this to happen.
617 // That function has a pointer to this object and can read save_vresp.
618 save_vresp = reinterpret_cast<VDR_ResponsePacket*>(userTag);
620 r_deregisterEDR = true;
624 else if (receiverChannel == VDR::CHANNEL_STREAM)
626 // It's a stream packet. Pass off the stream data to streamReceiver,
627 // delete the vresp. Keep this PacketReceiver for the next stream packet.
628 VDR_ResponsePacket* vresp = reinterpret_cast<VDR_ResponsePacket*>(userTag);
629 streamReceiver->streamReceive(vresp->getFlag(), vresp->getUserData(), vresp->getUserDataLength());
632 r_deregisterEDR = false;
633 r_wakeThread = false;
636 else if (receiverChannel == VDR::CHANNEL_TVMEDIA)
639 // Pass off the vresp object to OSDVector
640 // This used to return true which would signal the cond (wake the thread)
641 // but am going to try setting this to false because I don't know that there is a thread to signal
642 // delete the EDR. It's made once per media requested and wasn't owned/deleted by anything before
644 VDR_ResponsePacket* vresp = reinterpret_cast<VDR_ResponsePacket*>(userTag);
645 Log::getInstance()->log("VDR", Log::DEBUG, "TVMedia Pictures arrived VDR %x", vresp->getStreamID());
646 OsdVector *osd=dynamic_cast<OsdVector*>(Osd::getInstance());
647 if (osd) osd->getPictReader()->receivePicture(vresp);
648 // else delete vresp; //nonsense // only rpi does CHANNEL_TVMEDIA, rpi has osdvector. therefore, can't get here.
650 r_deregisterEDR = true;
651 r_wakeThread = false;
654 else abort(); // unknown receiverChannel, should not happen
657 /////////////////////////////////////////////////////////////////////////////
659 int VDR::doLogin(unsigned int* v_server_min, unsigned int* v_server_max, unsigned int* v_client,
660 ASLPrefList& list, int &subtitles)
662 VDR_RequestPacket vrp;
663 if (!vrp.init(VDR_LOGIN, true, 6)) return 0;
666 tcp->getMAC(mactemp);
667 if (!vrp.copyin(mactemp, 6)) return 0;
669 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
670 if (vresp->noResponse()) { delete vresp; return 0; }
672 ULONG vdrTime = vresp->extractULONG();
673 logger->log("VDR", Log::DEBUG, "vdrtime = %lu", vdrTime);
674 long vdrTimeOffset = vresp->extractLONG();
675 logger->log("VDR", Log::DEBUG, "offset = %i", vdrTimeOffset);
677 unsigned int version_min=vresp->extractULONG();
679 *v_server_min=version_min;
680 unsigned int version_max=vresp->extractULONG();
681 *v_server_max=version_max;
682 *v_client=VOMP_PROTOCOL_VERSION;
684 if (0x00000302 <= version_max) {
685 unsigned int numlangcodes = vresp->extractULONG();
686 subtitles = vresp->extractULONG();
688 for (unsigned int i=0; i<numlangcodes; i++) {
690 newpref.audiopref = vresp->extractLONG();
691 newpref.subtitlepref = vresp->extractLONG();
692 newpref.langcode = vresp->extractStdString();
693 //logger->log("VDR", Log::DEBUG, "Langpref %s %d %d", newpref.langcode.c_str(), newpref.audiopref, newpref.subtitlepref);
694 list.push_back(newpref);
701 if ((version_min > VOMP_PROTOCOL_VERSION)
702 || (version_max < VOMP_PROTOCOL_VERSION) ) {
708 // Set the time and zone on the MVP only
710 #if !defined(WIN32) && !defined(__ANDROID__)
711 struct timespec currentTime;
712 currentTime.tv_sec = vdrTime;
713 currentTime.tv_nsec = 0;
715 int b = clock_settime(CLOCK_REALTIME, ¤tTime);
717 logger->log("VDR", Log::DEBUG, "set clock = %u", b);
719 // now make a TZ variable and set it
723 if (vdrTimeOffset > 0) sign = '-';
726 vdrTimeOffset = abs(vdrTimeOffset);
728 hours = (int)vdrTimeOffset / 3600;
729 minutes = vdrTimeOffset % 3600;
731 logger->log("VDR", Log::DEBUG, "%c %i %i", sign, hours, minutes);
733 minutes = (int)minutes / 60;
735 logger->log("VDR", Log::DEBUG, "%c %i %i", sign, hours, minutes);
738 sprintf(newTZ, "MVP%c%i:%i", sign, hours, minutes);
739 setenv("TZ", newTZ, 1);
741 logger->log("VDR", Log::DEBUG, "Timezone data: %s", newTZ);
744 setCharset(Osd::getInstance()->charSet());
749 bool VDR::LogExtern(const char* logString)
751 if (!connected) return false;
752 int stringLength = strlen(logString);
753 int packetLength = stringLength + 8;
754 char *buffer=new char[packetLength + 1];
756 ULONG ul=CHANNEL_NETLOG;
757 buffer[pos++]=(ul>>24)&0xff;
758 buffer[pos++]=(ul>>16)&0xff;
759 buffer[pos++]=(ul>>8)&0xff;
760 buffer[pos++]=ul &0xff;
762 buffer[pos++]=(ul>>24)&0xff;
763 buffer[pos++]=(ul>>16)&0xff;
764 buffer[pos++]=(ul>>8)&0xff;
765 buffer[pos++]=ul &0xff;
767 strcpy(&buffer[8], logString);
769 if (tcp->sendData(buffer, packetLength) != packetLength)
771 connected = false; // stop the rest of the connection
779 bool VDR::setCharset(int charset)
781 VDR_RequestPacket vrp;
782 if (!vrp.init(VDR_SETCHARSET, true, sizeof(ULONG))) return false;
783 if (!vrp.addULONG(charset)) return false;
785 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
786 if (vresp->noResponse()) { delete vresp; return false; }
788 ULONG success = vresp->extractULONG();
791 if (!success) return false;
796 bool VDR::getRecordingsList(RecMan* recman)
798 VDR_RequestPacket vrp;
799 if (!vrp.init(VDR_GETRECORDINGLIST, true, 0)) return false;
801 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
802 if (vresp->noResponse()) { delete vresp; return false; }
804 ULONG totalSpace = vresp->extractULONG();
805 ULONG freeSpace = vresp->extractULONG();
806 ULONG percent = vresp->extractULONG();
808 recman->setStats(totalSpace, freeSpace, percent);
815 while (!vresp->end())
817 start = vresp->extractULONG();
818 isNew = vresp->extractUCHAR();
819 name = vresp->extractString();
820 fileName = vresp->extractString();
821 recman->addEntry(isNew, start, name, fileName);
830 int VDR::deleteRecording(char* fileName)
832 VDR_RequestPacket vrp;
833 if (!vrp.init(VDR_DELETERECORDING, true, strlen(fileName) + 1)) return 0;
834 if (!vrp.addString(fileName)) return 0;
836 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
837 if (vresp->noResponse()) { delete vresp; return 0; }
839 int toReturn = static_cast<int>(vresp->extractULONG());
845 int VDR::deleteRecResume(char* fileName)
847 VDR_RequestPacket vrp;
848 if (!vrp.init(VDR_DELETERECRESUME, true, strlen(fileName) + 1)) return 0;
849 if (!vrp.addString(fileName)) return 0;
851 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
852 if (vresp->noResponse()) { delete vresp; return 0; }
854 int toReturn = static_cast<int>(vresp->extractULONG());
860 char* VDR::moveRecording(char* fileName, char* newPath)
862 VDR_RequestPacket vrp;
863 if (!vrp.init(VDR_MOVERECORDING, true, strlen(fileName) + 1 + strlen(newPath) + 1)) return NULL;
864 if (!vrp.addString(fileName)) return NULL;
865 if (!vrp.addString(newPath)) return NULL;
867 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
868 if (vresp->noResponse()) { delete vresp; return NULL; }
870 char* toReturn = NULL;
871 int success = static_cast<int>(vresp->extractULONG());
874 toReturn = vresp->extractString();
882 ChannelList* VDR::getChannelsList(ULONG type)
884 VDR_RequestPacket vrp;
885 if (!vrp.init(VDR_GETCHANNELLIST, true, 0)) return NULL;
887 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
888 if (vresp->noResponse()) { delete vresp; return NULL; }
890 ChannelList* chanList = new ChannelList();
892 bool h264support=Video::getInstance()->supportsh264();
893 bool mpeg2support=Video::getInstance()->supportsmpeg2();
895 while (!vresp->end())
897 Channel* chan = new Channel();
898 chan->number = vresp->extractULONG();
899 chan->type = vresp->extractULONG();
900 chan->name = vresp->extractString();
901 chan->vstreamtype = static_cast<UCHAR>(vresp->extractULONG());
903 if (chan->type == type && ((chan->vstreamtype==0x1b && h264support)|| (chan->vstreamtype!=0x1b &&mpeg2support)) )
905 chanList->push_back(chan);
906 logger->log("VDR", Log::DEBUG, "Have added a channel to list. %lu %lu %s", chan->number, chan->type, chan->name);
907 if (chan->number > maxChannelNumber) maxChannelNumber = chan->number;
917 if (maxChannelNumber > 99999)
918 channelNumberWidth = 6;
919 else if (maxChannelNumber > 9999)
920 channelNumberWidth = 5;
921 else if (maxChannelNumber > 999)
922 channelNumberWidth = 4;
923 else if (maxChannelNumber > 99)
924 channelNumberWidth = 3;
925 else if (maxChannelNumber > 9)
926 channelNumberWidth = 2;
928 channelNumberWidth = 1;
933 int VDR::streamChannel(ULONG number, StreamReceiver* tstreamReceiver)
935 VDR_RequestPacket vrp;
936 if (!vrp.init(VDR_STREAMCHANNEL, true, sizeof(ULONG))) return 0;
937 if (!vrp.addULONG(number)) return 0;
940 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
941 vdrpr->receiverChannel = VDR::CHANNEL_STREAM;
942 vdrpr->streamID = vrp.getSerial();
943 vdrpr->streamReceiver = tstreamReceiver;
945 TEMP_SINGLE_VDR_PR = vdrpr;
947 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
948 if (vresp->noResponse())
956 int toReturn = static_cast<int>(vresp->extractULONG());
957 logger->log("VDR", Log::DEBUG, "VDR said %lu to start streaming request", toReturn);
963 int VDR::stopStreaming()
965 VDR_RequestPacket vrp;
966 if (!vrp.init(VDR_STOPSTREAMING, true, 0)) return 0;
968 if (TEMP_SINGLE_VDR_PR) // this block only needs to be done if it was a live stream
969 // TEMP_SINGLE_VDR_PR will not be set unless we are streaming a channel
971 edUnregister(TEMP_SINGLE_VDR_PR);
972 delete TEMP_SINGLE_VDR_PR;
973 TEMP_SINGLE_VDR_PR = NULL;
976 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
977 if (vresp->noResponse()) { delete vresp; return 0; }
979 int toReturn = static_cast<int>(vresp->extractULONG());
985 UCHAR* VDR::getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived)
987 VDR_RequestPacket vrp;
988 if (!vrp.init(VDR_GETBLOCK, true, sizeof(ULLONG) + sizeof(ULONG))) return NULL;
989 if (!vrp.addULLONG(position)) return NULL;
990 if (!vrp.addULONG(maxAmount)) return NULL;
992 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
993 if (vresp->noResponse()) { delete vresp; return NULL; }
995 if (vresp->serverError())
997 logger->log("VDR", Log::DEBUG, "Detected getblock 0");
1003 // Special handling for getblock
1004 UCHAR* toReturn = vresp->getUserData();
1005 *amountReceived = vresp->getUserDataLength();
1012 ULLONG VDR::streamRecording(char* fileName, ULONG* totalFrames, bool* IsPesRecording)
1014 VDR_RequestPacket vrp;
1015 if (!vrp.init(VDR_STREAMRECORDING, true, strlen(fileName) + 1)) return 0;
1016 if (!vrp.addString(fileName)) return 0;
1018 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1019 if (vresp->noResponse()) { delete vresp; return 0; }
1021 ULLONG lengthBytes = vresp->extractULLONG();
1022 ULONG lengthFrames = vresp->extractULONG();
1023 UCHAR isPesRecording = vresp->extractUCHAR();
1026 *totalFrames = lengthFrames;
1027 *IsPesRecording = (isPesRecording);//convert Uchar to bool
1029 logger->log("VDR", Log::DEBUG, "VDR said length is: %llu %lu, IsPesRecording %x", lengthBytes, lengthFrames, *IsPesRecording);
1034 ULLONG VDR::positionFromFrameNumber(ULONG frameNumber)
1036 VDR_RequestPacket vrp;
1037 if (!vrp.init(VDR_POSFROMFRAME, true, sizeof(ULONG))) return 0;
1038 if (!vrp.addULONG(frameNumber)) return 0;
1040 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1041 if (vresp->noResponse()) { delete vresp; return 0; }
1043 ULLONG position = vresp->extractULLONG();
1046 logger->log("VDR", Log::DEBUG, "VDR said new position is: %llu", position);
1051 ULONG VDR::frameNumberFromPosition(ULLONG position)
1053 VDR_RequestPacket vrp;
1054 if (!vrp.init(VDR_FRAMEFROMPOS, true, sizeof(ULLONG))) return 0;
1055 if (!vrp.addULLONG(position)) return 0;
1057 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1058 if (vresp->noResponse()) { delete vresp; return 0; }
1060 ULONG framenumber = vresp->extractULONG();
1063 logger->log("VDR", Log::DEBUG, "VDR said new framenumber is: %u", framenumber);
1068 bool VDR::getNextIFrame(ULONG frameNumber, ULONG direction, ULLONG* rfilePosition, ULONG* rframeNumber, ULONG* rframeLength)
1070 VDR_RequestPacket vrp;
1071 if (!vrp.init(VDR_GETNEXTIFRAME, true, sizeof(ULONG)*2)) return false;
1072 if (!vrp.addULONG(frameNumber)) return false;
1073 if (!vrp.addULONG(direction)) return false;
1075 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1076 if (vresp->noResponse()) { delete vresp; return false; }
1078 if (vresp->serverError())
1080 logger->log("VDR", Log::DEBUG, "Detected getNextIFrame error");
1085 *rfilePosition = vresp->extractULLONG();
1086 *rframeNumber = vresp->extractULONG();
1087 *rframeLength = vresp->extractULONG();
1091 logger->log("VDR", Log::DEBUG, "VDR GNIF said %llu %lu %lu", *rfilePosition, *rframeNumber, *rframeLength);
1096 EventList* VDR::getChannelSchedule(ULONG number)
1100 return getChannelSchedule(number, now, 24 * 60 * 60);
1103 EventList* VDR::getChannelSchedule(ULONG number, time_t start, ULONG duration)
1105 // retrieve event list (vector of events) from vdr within filter window. duration is in seconds
1107 VDR_RequestPacket vrp;
1108 if (!vrp.init(VDR_GETCHANNELSCHEDULE, true, sizeof(ULONG)*3)) return NULL;
1109 if (!vrp.addULONG(number)) return NULL;
1110 if (!vrp.addULONG(start)) return NULL;
1111 if (!vrp.addULONG(duration)) return NULL;
1113 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1114 if (vresp->noResponse()) { delete vresp; return NULL; }
1116 // received a ulong(0) - schedules error in the plugin
1117 if (vresp->serverError())
1123 EventList* eventList = new EventList();
1125 while (!vresp->end())
1127 Event* event = new Event();
1128 event->id = vresp->extractULONG();
1129 event->time = vresp->extractULONG();
1130 event->duration = vresp->extractULONG();
1131 event->title = vresp->extractString();
1132 event->subtitle = vresp->extractString();
1133 event->description = vresp->extractString();
1134 eventList->push_back(event);
1139 logger->log("VDR", Log::DEBUG, "Success got to end of getChannelSchedule");
1143 int VDR::configSave(const char* section, const char* key, const char* value)
1145 VDR_RequestPacket vrp;
1146 if (!vrp.init(VDR_CONFIGSAVE, false, 0)) return 0;
1147 if (!vrp.addString(section)) return 0;
1148 if (!vrp.addString(key)) return 0;
1149 if (!vrp.addString(value)) return 0;
1151 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1152 if (vresp->noResponse()) { delete vresp; return 0; }
1154 int toReturn = static_cast<int>(vresp->extractULONG());
1160 char* VDR::configLoad(const char* section, const char* key)
1162 VDR_RequestPacket vrp;
1163 if (!vrp.init(VDR_CONFIGLOAD, false, 0)) return NULL;
1164 if (!vrp.addString(section)) return NULL;
1165 if (!vrp.addString(key)) return NULL;
1167 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1168 if (vresp->noResponse()) { delete vresp; return NULL; }
1170 char* toReturn = vresp->extractString();
1176 RecTimerList* VDR::getRecTimersList()
1178 VDR_RequestPacket vrp;
1179 if (!vrp.init(VDR_GETTIMERS, true, 0)) return NULL;
1181 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1182 if (vresp->noResponse()) { delete vresp; return NULL; }
1184 RecTimerList* recTimerList = new RecTimerList();
1186 ULONG numTimers = vresp->extractULONG();
1189 RecTimer* newRecTimer;
1192 while (!vresp->end())
1194 newRecTimer = new RecTimer();
1195 newRecTimer->active = vresp->extractULONG();
1196 newRecTimer->recording = vresp->extractULONG();
1197 newRecTimer->pending = vresp->extractULONG();
1198 newRecTimer->priority = vresp->extractULONG();
1199 newRecTimer->lifeTime = vresp->extractULONG();
1200 newRecTimer->channelNumber = vresp->extractULONG();
1201 newRecTimer->startTime = vresp->extractULONG();
1202 newRecTimer->stopTime = vresp->extractULONG();
1203 newRecTimer->day = vresp->extractULONG();
1204 newRecTimer->weekDays = vresp->extractULONG();
1206 tempString = vresp->extractString();
1207 newRecTimer->setFile(tempString);
1208 delete[] tempString;
1210 recTimerList->push_back(newRecTimer);
1211 logger->log("VDR", Log::DEBUG, "TL: %lu %lu %lu %lu %lu %lu %lu %lu %s",
1212 newRecTimer->active, newRecTimer->recording, newRecTimer->pending, newRecTimer->priority, newRecTimer->lifeTime,
1213 newRecTimer->channelNumber, newRecTimer->startTime, newRecTimer->stopTime, newRecTimer->getFile());
1219 sort(recTimerList->begin(), recTimerList->end(), RecTimerSorter());
1221 return recTimerList;
1224 ULONG VDR::setEventTimer(char* timerString)
1226 VDR_RequestPacket vrp;
1227 if (!vrp.init(VDR_SETTIMER, true, strlen(timerString) + 1)) return 0;
1228 if (!vrp.addString(timerString)) return 0;
1230 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1231 if (vresp->noResponse()) { delete vresp; return 0; }
1233 ULONG toReturn = vresp->extractULONG();
1239 RecInfo* VDR::getRecInfo(char* fileName)
1241 VDR_RequestPacket vrp;
1242 if (!vrp.init(VDR_GETRECINFO2, true, strlen(fileName) + 1)) return NULL;
1243 if (!vrp.addString(fileName)) return NULL;
1244 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1246 if (vresp->noResponse()) { delete vresp; return NULL; }
1248 if (vresp->serverError())
1250 logger->log("VDR", Log::DEBUG, "Could not get rec info");
1255 RecInfo* recInfo = new RecInfo();
1257 recInfo->timerStart = vresp->extractULONG();
1258 recInfo->timerEnd = vresp->extractULONG();
1259 recInfo->resumePoint = vresp->extractULONG();
1260 recInfo->summary = vresp->extractString();
1262 ULONG numComponents = vresp->extractULONG();
1265 recInfo->setNumComponents(numComponents);
1266 for (ULONG i = 0; i < numComponents; i++)
1268 recInfo->streams[i] = vresp->extractUCHAR();
1269 recInfo->types[i] = vresp->extractUCHAR();
1270 recInfo->languages[i] = vresp->extractString();
1271 recInfo->descriptions[i] = vresp->extractString();
1274 recInfo->fps=vresp->extractdouble();
1275 recInfo->title=vresp->extractString();
1278 recInfo->channelName = vresp->extractString();
1279 recInfo->duration = vresp->extractULONG();
1280 recInfo->fileSize = vresp->extractULONG();
1281 recInfo->priority = vresp->extractULONG();
1282 recInfo->lifetime = vresp->extractULONG();
1291 ULLONG VDR::rescanRecording(ULONG* totalFrames)
1293 VDR_RequestPacket vrp;
1294 if (!vrp.init(VDR_RESCANRECORDING, true, 0)) return 0;
1296 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1297 if (vresp->noResponse()) { delete vresp; return 0; }
1299 ULLONG lengthBytes = vresp->extractULLONG();
1300 ULONG lengthFrames = vresp->extractULONG();
1303 logger->log("VDR", Log::DEBUG, "VDR said length is: %llu %lu", lengthBytes, lengthFrames);
1305 *totalFrames = lengthFrames;
1309 MarkList* VDR::getMarks(char* fileName)
1311 VDR_RequestPacket vrp;
1312 if (!vrp.init(VDR_GETMARKS, true, strlen(fileName) + 1)) return NULL;
1313 if (!vrp.addString(fileName)) return NULL;
1315 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1316 if (vresp->noResponse()) { delete vresp; return NULL; }
1318 if (vresp->serverError())
1324 MarkList* markList = new MarkList();
1326 while (!vresp->end())
1328 Mark* mark = new Mark();
1329 mark->pos = vresp->extractULONG();
1331 markList->push_back(mark);
1332 logger->log("VDR", Log::DEBUG, "Have added a mark to list. %lu", mark->pos);
1340 void VDR::getChannelPids(Channel* channel)
1342 VDR_RequestPacket vrp;
1343 if (!vrp.init(VDR_GETCHANNELPIDS, true, sizeof(ULONG))) return ;
1344 if (!vrp.addULONG(channel->number)) return ;
1346 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1347 if (vresp->noResponse()) { delete vresp; return ; }
1349 // Format of response
1357 channel->vpid = vresp->extractULONG();
1358 channel->vstreamtype = static_cast<UCHAR>(vresp->extractULONG());
1359 channel->numAPids = vresp->extractULONG();
1361 for (ULONG i = 0; i < channel->numAPids; i++)
1364 newapid.pid = vresp->extractULONG();
1365 char * name=vresp->extractString();
1366 strncpy(newapid.desc,name,9);
1368 channel->apids.push_back(newapid);
1371 channel->numDPids = vresp->extractULONG();
1373 for (ULONG i = 0; i < channel->numDPids; i++)
1376 newdpid.pid = vresp->extractULONG();
1377 char * name=vresp->extractString();
1378 strncpy(newdpid.desc,name,9);
1380 channel->dpids.push_back(newdpid);
1383 channel->numSPids = vresp->extractULONG();
1385 for (ULONG i = 0; i < channel->numSPids; i++)
1388 newspid.pid = vresp->extractULONG();
1389 char * name=vresp->extractString();
1390 strncpy(newspid.desc,name,9);
1392 channel->spids.push_back(newspid);
1394 channel->tpid = vresp->extractULONG();
1396 for (ULONG i = 0; i < channel->numAPids; i++)
1398 channel->apids[i].type = vresp->extractULONG();
1400 for (ULONG i = 0; i < channel->numDPids; i++)
1402 channel->dpids[i].type = vresp->extractULONG();
1404 for (ULONG i = 0; i < channel->numSPids; i++)
1406 channel->spids[i].type = vresp->extractULONG();
1407 channel->spids[i].data1 = vresp->extractULONG();
1408 channel->spids[i].data2 = vresp->extractULONG();
1416 #ifdef VOMP_MEDIAPLAYER
1417 MediaList * VDR::getRootList() {
1418 return getMediaList(NULL);
1421 * media List Request:
1423 * Media List response:
1426 MediaList* VDR::getMediaList(const MediaURI * root)
1428 logger->log("VDR", Log::DEBUG, "getMediaList %s,d=%s, prov=%d", (root?root->getName():"NULL"),
1429 ((root && root->hasDisplayName())?root->getDisplayName():"NULL"),
1430 (root?root->getProvider():providerId));
1431 MediaURI remoteURI(root);
1432 VDR_GetMediaListRequest request(&remoteURI);
1433 SerializeBuffer *vrp=prepareRequest(&request);
1435 logger->log("VDR", Log::ERR, "getMediaList unable to create command");
1439 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1441 Command::getInstance()->connectionLost();
1445 MediaList *rt=new MediaList(NULL);
1447 VDR_GetMediaListResponse resp(&rtflags,rt);
1448 if (decodeResponse(vresp,&resp) != 0) {
1455 * get image Request:
1457 * get media response:
1461 int VDR::openMedium(ULONG channel,const MediaURI *uri, ULLONG * size, ULONG x, ULONG y)
1463 MediaURI remoteURI(uri);
1464 VDR_OpenMediumRequest request(&channel,&remoteURI,&x,&y);
1466 SerializeBuffer *vrp=prepareRequest(&request);
1468 logger->log("VDR", Log::ERR, "openMedium unable to create command");
1471 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1473 Command::getInstance()->connectionLost();
1477 VDR_OpenMediumResponse response(&flags,size);
1478 if (decodeResponse(vresp,&response) != 0) {
1481 logger->log("VDR", Log::DEBUG, "openMedia len=%llu", *size);
1486 * getMediaBlock - no separate response class - simple data block
1490 int VDR::getMediaBlock(ULONG channel, ULLONG position, ULONG maxAmount, ULONG* amountReceived, unsigned char **buffer)
1493 VDR_GetMediaBlockRequest request(&channel,&position,&maxAmount);
1494 SerializeBuffer *vrp=prepareRequest(&request);
1496 logger->log("VDR", Log::ERR, "getMediaBlock unable to create command");
1499 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1501 Command::getInstance()->connectionLost();
1505 // Special handling for getblock
1506 *amountReceived = (ULONG)(vresp->getEnd()-vresp->getStart());
1507 *buffer = vresp->steelBuffer();
1520 int VDR::getMediaInfo(ULONG channel, MediaInfo * result) {
1521 if (! result) return -1;
1522 VDR_GetMediaInfoRequest request(&channel);
1523 SerializeBuffer *vrp=prepareRequest(&request);
1525 logger->log("VDR", Log::ERR, "getMediaInfo unable to create command");
1528 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1530 Command::getInstance()->connectionLost();
1535 VDR_GetMediaInfoResponse response(&flags,result);
1536 if (decodeResponse(vresp,&response) != 0) {
1549 int VDR::closeMediaChannel(ULONG channel) {
1550 VDR_CloseMediaChannelRequest request(&channel);
1551 SerializeBuffer *vrp=prepareRequest(&request);
1553 logger->log("VDR", Log::ERR, "closeMediaChannel unable to create command");
1556 SerializeBuffer* vresp = doRequestResponse(vrp,request.command);
1558 Command::getInstance()->connectionLost();
1562 VDR_CloseMediaChannelResponse response(&flags);
1563 if (decodeResponse(vresp,&response) != 0) return -1;
1564 return (flags != 0)?-1:0;
1570 int VDR::deleteTimer(RecTimer* delTimer)
1572 logger->log("VDR", Log::DEBUG, "Delete timer called");
1574 VDR_RequestPacket vrp;
1575 if (!vrp.init(VDR_DELETETIMER, false, 0)) return 0;
1576 if (!vrp.addULONG(delTimer->channelNumber)) return 0;
1577 if (!vrp.addULONG(delTimer->weekDays)) return 0;
1578 if (!vrp.addULONG(delTimer->day)) return 0;
1579 if (!vrp.addULONG(delTimer->startTime)) return 0;
1580 if (!vrp.addULONG(delTimer->stopTime)) return 0;
1582 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1583 if (vresp->noResponse()) { delete vresp; return 0; }
1585 int toReturn = static_cast<int>(vresp->extractULONG());
1591 I18n::lang_code_list VDR::getLanguageList()
1593 I18n::lang_code_list CodeList;
1594 CodeList["en"] = "English"; // Default entry
1595 VDR_RequestPacket vrp;
1596 if (!vrp.init(VDR_GETLANGUAGELIST, false, 0)) return CodeList;
1597 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1598 if (vresp->noResponse() || vresp->end())
1604 while (!vresp->end())
1606 char* c_code = vresp->extractString();
1607 char* c_name = vresp->extractString();
1608 std::string code = c_code;
1609 std::string name = c_name;
1610 CodeList[code] = name;
1618 int VDR::getLanguageContent(const std::string code, I18n::trans_table& texts)
1620 VDR_RequestPacket vrp;
1621 if (!vrp.init(VDR_GETLANGUAGECONTENT, false, 0)) return 0;
1622 if (!vrp.addString(code.c_str())) return 0;
1623 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1624 if (vresp->noResponse()) { delete vresp; return 0; }
1626 while (!vresp->end())
1628 char* c_key = vresp->extractString();
1629 char* c_text = vresp->extractString();
1630 std::string key = c_key;
1631 std::string text = c_text;
1640 void VDR::shutdownVDR()
1643 logger->log("VDR", Log::DEBUG, "Shutting down vdr");
1645 logger->log("VDR", Log::DEBUG, "Shutting down vomp only");
1647 if(!doVDRShutdown || !connected)
1650 VDR_RequestPacket vrp;
1651 logger->log("VDR", Log::DEBUG, "Sending shutdown");
1652 if (!vrp.init(VDR_SHUTDOWN, false, 0)) return;
1653 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1656 logger->log("VDR", Log::DEBUG, "VDR shutdown");
1659 void VDR::getScraperEventType(char * fileName, int & movieID,
1660 int & seriesID, int & episodeID)
1665 VDR_RequestPacket vrp;
1666 if (!vrp.init(VDR_GETRECSCRAPEREVENTTYPE, true, strlen(fileName) + 1)) return;
1667 if (!vrp.addString(fileName)) return ;
1668 Log::getInstance()->log("Recording", Log::DEBUG, "Before Response ");
1669 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1670 Log::getInstance()->log("Recording", Log::DEBUG, "After Response ");
1671 if (vresp->noResponse()) { delete vresp; return ; }
1672 int type = vresp->extractUCHAR();
1673 if (type == 0) //serie
1675 seriesID = vresp->extractLONG();
1676 episodeID = vresp->extractLONG();
1677 } else if (type == 1) //movie
1679 movieID = vresp->extractLONG();
1685 void VDR::getScraperEventType(UINT channelid, UINT eventid, int & movieID,
1686 int & seriesID, int & episodeID, int & epgImage )
1692 VDR_RequestPacket vrp;
1693 if (!vrp.init(VDR_GETEVENTSCRAPEREVENTTYPE, false, 0)) return;
1694 if (!vrp.addULONG(channelid)) return ;
1695 if (!vrp.addULONG(eventid)) return ;
1696 Log::getInstance()->log("Recording", Log::DEBUG, "Before Response ");
1697 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1698 Log::getInstance()->log("Recording", Log::DEBUG, "After Response ");
1699 if (vresp->noResponse()) { delete vresp; return ; }
1700 int type = vresp->extractUCHAR();
1701 if (type == 0) //serie
1703 seriesID = vresp->extractLONG();
1704 episodeID = vresp->extractLONG();
1705 } else if (type == 1) //movie
1707 movieID = vresp->extractLONG();
1709 epgImage = vresp->extractLONG();
1714 MovieInfo *VDR::getScraperMovieInfo(int movieID)
1716 VDR_RequestPacket vrp;
1717 if (!vrp.init(VDR_GETSCRAPERMOVIEINFO, false, 0)) return NULL;
1718 if (!vrp.addULONG(movieID)) return NULL;
1719 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1720 if (vresp->noResponse()) { delete vresp; return NULL; }
1721 MovieInfo * movieinf= new MovieInfo();
1723 movieinf->id=movieID;
1724 movieinf->title = vresp->extractStdString();
1725 movieinf->originalTitle = vresp->extractStdString();
1726 movieinf->tagline = vresp->extractStdString();
1727 movieinf->overview = vresp->extractStdString();
1728 movieinf->adult = vresp->extractUCHAR();
1729 movieinf->collectionName = vresp->extractStdString();
1731 movieinf->budget = vresp->extractLONG();
1732 movieinf->revenue = vresp->extractLONG();
1733 movieinf->genres = vresp->extractStdString();
1734 movieinf->homepage = vresp->extractStdString();
1735 movieinf->releaseDate = vresp->extractStdString();
1736 movieinf->runtime = vresp->extractLONG();
1737 movieinf->popularity = vresp->extractdouble();
1738 movieinf->voteAverage = vresp->extractdouble();
1739 movieinf->poster.width = vresp->extractULONG();
1740 movieinf->poster.height = vresp->extractULONG();
1741 movieinf->poster.info.setMovieInfo(movieinf);
1742 movieinf->poster.info.setElement(0,0);
1743 movieinf->fanart.width = vresp->extractULONG();
1744 movieinf->fanart.height = vresp->extractULONG();
1745 movieinf->fanart.info.setMovieInfo(movieinf);
1746 movieinf->fanart.info.setElement(1,0);
1747 movieinf->collectionPoster.width = vresp->extractULONG();
1748 movieinf->collectionPoster.height = vresp->extractULONG();
1749 movieinf->collectionPoster.info.setMovieInfo(movieinf);
1750 movieinf->collectionPoster.info.setElement(2,0);
1751 movieinf->collectionFanart.width = vresp->extractULONG();
1752 movieinf->collectionFanart.height = vresp->extractULONG();
1753 movieinf->collectionFanart.info.setMovieInfo(movieinf);
1754 movieinf->collectionFanart.info.setElement(3,0);
1755 ULONG num_actors = vresp->extractULONG();
1756 movieinf->actors.clear();
1757 movieinf->actors.reserve(num_actors);
1758 for (ULONG acty=0; acty < num_actors; acty++) {
1760 new_act.name = vresp->extractStdString();
1761 new_act.role = vresp->extractStdString();
1762 new_act.thumb.width = vresp->extractULONG();
1763 new_act.thumb.height = vresp->extractULONG();
1764 new_act.thumb.info.setMovieInfo(movieinf);
1765 new_act.thumb.info.setElement(4,acty);
1766 movieinf->actors.push_back(new_act);
1775 SeriesInfo *VDR::getScraperSeriesInfo(int seriesID, int episodeID)
1777 VDR_RequestPacket vrp;
1778 if (!vrp.init(VDR_GETSCRAPERSERIESINFO, false, 0)) return NULL;
1779 if (!vrp.addULONG(seriesID)) return NULL;
1780 if (!vrp.addULONG(episodeID)) return NULL;
1782 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1783 if (vresp->noResponse()) { delete vresp; return 0; }
1784 SeriesInfo * seriesinf= new SeriesInfo();
1786 seriesinf->id=seriesID;
1789 seriesinf->name = vresp->extractStdString();
1790 seriesinf->overview = vresp->extractStdString();
1791 seriesinf->firstAired = vresp->extractStdString();
1792 seriesinf->network = vresp->extractStdString();
1793 seriesinf->genre = vresp->extractStdString();
1794 seriesinf->rating = vresp->extractdouble();
1795 seriesinf->status = vresp->extractStdString();
1798 seriesinf->episode.episodeid=episodeID;
1799 seriesinf->episode.number = vresp->extractLONG();
1800 seriesinf->episode.season = vresp->extractLONG();
1801 seriesinf->episode.name = vresp->extractStdString();
1802 seriesinf->episode.firstAired = vresp->extractStdString();
1803 seriesinf->episode.guestStars = vresp->extractStdString();
1804 seriesinf->episode.overview = vresp->extractStdString();
1805 seriesinf->episode.rating = vresp->extractdouble();
1806 seriesinf->episode.image.width = vresp->extractULONG();
1807 seriesinf->episode.image.height = vresp->extractULONG();
1808 seriesinf->episode.image.info.setSeriesInfo(seriesinf);
1809 seriesinf->episode.image.info.setElement(0,0);
1812 ULONG num_actors = vresp->extractULONG();
1813 seriesinf->actors.clear();
1814 seriesinf->actors.reserve(num_actors);
1815 for (ULONG acty=0; acty < num_actors; acty++) {
1817 new_act.name = vresp->extractStdString();
1818 new_act.role = vresp->extractStdString();
1819 new_act.thumb.width = vresp->extractULONG();
1820 new_act.thumb.height = vresp->extractULONG();
1821 new_act.thumb.info.setSeriesInfo(seriesinf);
1822 new_act.thumb.info.setElement(1,acty);
1823 seriesinf->actors.push_back(new_act);
1825 ULONG num_posters = vresp->extractULONG();
1826 for (ULONG medias = 0; medias < num_posters; medias++ ) {
1828 media.info.setSeriesInfo(seriesinf);
1829 media.info.setElement(2,medias);
1830 media.width = vresp->extractULONG();
1831 media.height = vresp->extractULONG();
1832 seriesinf->posters.push_back(media);
1835 ULONG num_banners = vresp->extractULONG();
1836 for (ULONG medias = 0; medias < num_banners; medias++ ) {
1838 media.info.setSeriesInfo(seriesinf);
1839 media.info.setElement(3,medias);
1840 media.width = vresp->extractULONG();
1841 media.height = vresp->extractULONG();
1842 seriesinf->banners.push_back(media);
1844 ULONG num_fanarts = vresp->extractULONG();
1845 for (ULONG medias = 0; medias < num_fanarts; medias++ ) {
1847 media.info.setSeriesInfo(seriesinf);
1848 media.info.setElement(4,medias);
1849 media.width = vresp->extractULONG();
1850 media.height = vresp->extractULONG();
1851 seriesinf->fanart.push_back(media);
1853 seriesinf->seasonposter.width = vresp->extractULONG();
1854 seriesinf->seasonposter.height = vresp->extractULONG();
1855 seriesinf->seasonposter.info.setSeriesInfo(seriesinf);
1856 seriesinf->seasonposter.info.setElement(5,0);
1863 ULONG VDR::loadTVMedia(TVMediaInfo& tvmedia)
1865 VDR_RequestPacket vrp;
1867 if (!vrp.init(VDR_LOADTVMEDIA, false, 0)) return ULONG_MAX;
1868 if (!vrp.addULONG(tvmedia.type)) return ULONG_MAX;
1869 if (!vrp.addULONG(tvmedia.primary_id)) return ULONG_MAX;
1870 if (!vrp.addULONG(tvmedia.secondary_id)) return ULONG_MAX;
1871 if (!vrp.addULONG(tvmedia.type_pict)) return ULONG_MAX;
1872 if (!vrp.addULONG(tvmedia.container)) return ULONG_MAX;
1873 if (!vrp.addULONG(tvmedia.container_member)) return ULONG_MAX;
1874 /* Log::getInstance()->log("VDR", Log::DEBUG, "TVMedia with ID %d %d; %d %d %d %d;%d",
1875 tvmedia.primary_id,tvmedia.secondary_id,tvmedia.type,tvmedia.type_pict,
1876 tvmedia.container,tvmedia.container_member,vrp.getSerial());*/
1879 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
1880 vdrpr->receiverChannel = VDR::CHANNEL_TVMEDIA;
1881 vdrpr->streamID = vrp.getSerial();
1882 vdrpr->streamReceiver = NULL;
1886 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1887 //if (vresp->noResponse()) { delete vresp; return ULONG_MAX; }
1890 return vrp.getSerial();
1893 ULONG VDR::loadTVMediaRecThumb(TVMediaInfo & media)
1896 VDR_RequestPacket vrp;
1898 if (!vrp.init(VDR_LOADTVMEDIARECTHUMB, false, 0)) return ULONG_MAX;
1899 if (!vrp.addString(media.primary_name.c_str())) return ULONG_MAX;
1901 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
1902 vdrpr->receiverChannel = VDR::CHANNEL_TVMEDIA;
1903 vdrpr->streamID = vrp.getSerial();
1904 vdrpr->streamReceiver = NULL;
1908 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1909 //if (vresp->noResponse()) { delete vresp; return ULONG_MAX; }
1912 return vrp.getSerial();
1915 ULONG VDR::loadTVMediaEventThumb(TVMediaInfo & media)
1918 VDR_RequestPacket vrp;
1920 if (!vrp.init(VDR_LOADTVMEDIAEVENTTHUMB, false, 0)) return ULONG_MAX;
1921 if (!vrp.addULONG(media.primary_id)) return ULONG_MAX;
1922 if (!vrp.addULONG(media.secondary_id)) return ULONG_MAX;
1924 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
1925 vdrpr->receiverChannel = VDR::CHANNEL_TVMEDIA;
1926 vdrpr->streamID = vrp.getSerial();
1927 vdrpr->streamReceiver = NULL;
1931 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1932 //if (vresp->noResponse()) { delete vresp; return ULONG_MAX; }
1935 return vrp.getSerial();
1938 ULONG VDR::loadChannelLogo(TVMediaInfo & media)
1941 VDR_RequestPacket vrp;
1943 if (!vrp.init(VDR_LOADCHANNELLOGO, false, 0)) return ULONG_MAX;
1944 if (!vrp.addULONG(media.primary_id)) return ULONG_MAX;
1946 VDR_PacketReceiver* vdrpr = new VDR_PacketReceiver();
1947 vdrpr->receiverChannel = VDR::CHANNEL_TVMEDIA;
1948 vdrpr->streamID = vrp.getSerial();
1949 vdrpr->streamReceiver = NULL;
1953 VDR_ResponsePacket* vresp = RequestResponse(&vrp);
1954 //if (vresp->noResponse()) { delete vresp; return ULONG_MAX; }
1957 // Log::getInstance()->log("VDR", Log::DEBUG, "TVMedia Channel Logo %d %x",
1958 // media.primary_id,vrp.getSerial());
1960 return vrp.getSerial();