2 Copyright 2004-2005 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, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 VDR* VDR::instance = NULL;
35 #define MUTEX_LOCK(mutex) pthread_mutex_lock(mutex)
36 #define MUTEX_UNLOCK(mutex) pthread_mutex_unlock(mutex)
38 #define MUTEX_LOCK(mutex) WaitForSingleObject(*(mutex), INFINITE )
39 #define MUTEX_UNLOCK(mutex) ReleaseMutex(*(mutex))
51 pthread_mutex_init(&mutex, NULL);
53 mutex=CreateMutex(NULL,FALSE,NULL);
60 channelNumberWidth = 1;
69 if (initted) shutdown();
72 VDR* VDR::getInstance()
77 int VDR::init(int tport)
79 if (initted) return 0;
82 logger = Log::getInstance();
88 if (!initted) return 0;
94 void VDR::findServers(vector<VDRServer>& servers)
96 Wol* wol = Wol::getInstance();
98 char* message = "VOMP";
100 DatagramSocket ds(port);
101 int haveAtLeastOne = 0;
104 bool firstloop = true;
111 logger->log("VDR", Log::NOTICE, "Broadcasting for server");
112 ds.send("255.255.255.255", 3024, message, strlen(message));
113 if(!firstloop) wol->doWakeUp();
115 retval = ds.waitforMessage(waitType);
117 if (retval == 2) // we got a reply
119 if (!strcmp(ds.getData(), "VOMP")) // echo.....
126 newServer.ip = new char[16];
127 strcpy(newServer.ip, ds.getFromIPA());
129 if (ds.getDataLength() == 0)
131 newServer.name = new char[1];
132 newServer.name[0] = '\0';
136 newServer.name = new char[strlen(ds.getData())+1];
137 strcpy(newServer.name, ds.getData());
140 servers.push_back(newServer);
147 if (haveAtLeastOne) break;
152 sort(servers.begin(), servers.end(), ServerSorter());
155 void VDR::cancelFindingServer()
160 void VDR::setServerIP(char* newIP)
162 strcpy(serverIP, newIP);
167 maxChannelNumber = 0;
168 channelNumberWidth = 1;
172 if (tcp->connectTo(serverIP, 3024))
183 void VDR::disconnect()
188 Log::getInstance()->log("VDR", Log::DEBUG, "Disconnect");
191 void VDR::setReceiveWindow(size_t size)
193 if (connected) tcp->setReceiveWindow(size);
196 ///////////////////////////////////////////////////////
200 packet = (UCHAR*)tcp->receivePacket();
206 packetLength = tcp->getDataLength();
210 void VDR::freePacket()
212 // Must be called if getPacket return 1, except in getBlock
219 int VDR::serverError()
221 if ((packetPos == 0) && (packetLength == 4) && !ntohl(*(ULONG*)packet)) return 1;
225 char* VDR::extractString()
227 if (serverError()) return NULL;
229 int length = strlen((char*)&packet[packetPos]);
230 if ((packetPos + length) > packetLength) return NULL;
231 char* str = new char[length + 1];
232 strcpy(str, (char*)&packet[packetPos]);
233 packetPos += length + 1;
237 UCHAR VDR::extractUCHAR()
239 if ((packetPos + sizeof(UCHAR)) > packetLength) return 0;
240 UCHAR uc = packet[packetPos];
241 packetPos += sizeof(UCHAR);
245 ULONG VDR::extractULONG()
247 if ((packetPos + sizeof(ULONG)) > packetLength) return 0;
248 ULONG ul = ntohl(*(ULONG*)&packet[packetPos]);
249 packetPos += sizeof(ULONG);
253 ULLONG VDR::extractULLONG()
255 if ((packetPos + sizeof(ULLONG)) > packetLength) return 0;
256 ULLONG ull = ntohll(*(ULLONG*)&packet[packetPos]);
257 packetPos += sizeof(ULLONG);
261 long VDR::extractLONG()
263 if ((packetPos + sizeof(long)) > packetLength) return 0;
264 long l = ntohl(*(long*)&packet[packetPos]);
265 packetPos += sizeof(long);
269 /////////////////////////////////////////////////////////////////////////////
275 *(unsigned long*)&buffer[0] = htonl(10);
276 *(unsigned long*)&buffer[4] = htonl(VDR_LOGIN);
278 tcp->getMAC((char*)&buffer[8]);
284 MUTEX_UNLOCK(&mutex);
288 int a = tcp->sendPacket(buffer, 14);
292 MUTEX_UNLOCK(&mutex);
300 MUTEX_UNLOCK(&mutex);
304 ULONG vdrTime = extractULONG();
305 logger->log("VDR", Log::DEBUG, "vdrtime = %lu", vdrTime);
306 long vdrTimeOffset = extractLONG();
307 logger->log("VDR", Log::DEBUG, "offset = %i", vdrTimeOffset);
310 MUTEX_UNLOCK(&mutex);
312 // Set the time and zone on the MVP
315 struct timespec currentTime;
316 currentTime.tv_sec = vdrTime;
317 currentTime.tv_nsec = 0;
318 int b = clock_settime(CLOCK_REALTIME, ¤tTime);
320 logger->log("VDR", Log::DEBUG, "set clock = %u", b);
322 // now make a TZ variable and set it
326 if (vdrTimeOffset > 0) sign = '-';
329 vdrTimeOffset = abs(vdrTimeOffset);
331 hours = (int)vdrTimeOffset / 3600;
332 minutes = vdrTimeOffset % 3600;
334 logger->log("VDR", Log::DEBUG, "%c %i %i", sign, hours, minutes);
336 minutes = (int)minutes / 60;
338 logger->log("VDR", Log::DEBUG, "%c %i %i", sign, hours, minutes);
341 sprintf(newTZ, "MVP%c%i:%i", sign, hours, minutes);
342 setenv("TZ", newTZ, 1);
344 logger->log("VDR", Log::DEBUG, "Timezone data: %s", newTZ);
350 bool VDR::getRecordingsList(RecMan* recman)
354 *(unsigned long*)&buffer[0] = htonl(4);
355 *(unsigned long*)&buffer[4] = htonl(VDR_GETRECORDINGLIST);
360 MUTEX_UNLOCK(&mutex);
364 int a = tcp->sendPacket(buffer, 8);
368 MUTEX_UNLOCK(&mutex);
376 MUTEX_UNLOCK(&mutex);
380 ULONG totalSpace = extractULONG();
381 ULONG freeSpace = extractULONG();
382 ULONG percent = extractULONG();
383 recman->setStats(totalSpace, freeSpace, percent);
389 while (packetPos < packetLength)
391 start = extractULONG();
392 name = extractString();
393 fileName = extractString();
395 recman->addEntry(start, name, fileName);
402 MUTEX_UNLOCK(&mutex);
407 int VDR::deleteRecording(char* fileName)
409 unsigned long totalLength = 8 + strlen(fileName) + 1;
410 UCHAR* buffer = new UCHAR[totalLength];
412 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
413 *(unsigned long*)&buffer[4] = htonl(VDR_DELETERECORDING);
414 strcpy((char*)&buffer[8], fileName);
417 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
419 unsigned int a = tcp->sendPacket(buffer, totalLength);
422 if (a != totalLength)
425 MUTEX_UNLOCK(&mutex);
431 MUTEX_UNLOCK(&mutex);
435 int toReturn = (int)extractULONG();
437 MUTEX_UNLOCK(&mutex);
442 char* VDR::moveRecording(char* fileName, char* newPath)
444 unsigned long totalLength = 8 + strlen(fileName) + 1 + strlen(newPath) + 1;
445 UCHAR* buffer = new UCHAR[totalLength];
447 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
448 *(unsigned long*)&buffer[4] = htonl(VDR_MOVERECORDING);
449 strcpy((char*)&buffer[8], fileName);
450 strcpy((char*)&buffer[8 + strlen(fileName) + 1], newPath);
453 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
455 unsigned int a = tcp->sendPacket(buffer, totalLength);
458 if (a != totalLength)
461 MUTEX_UNLOCK(&mutex);
467 MUTEX_UNLOCK(&mutex);
471 char* toReturn = NULL;
472 int success = (int)extractULONG();
475 toReturn = extractString();
479 MUTEX_UNLOCK(&mutex);
484 ChannelList* VDR::getChannelsList(ULONG type)
488 *(unsigned long*)&buffer[0] = htonl(4);
489 *(unsigned long*)&buffer[4] = htonl(VDR_GETCHANNELLIST);
492 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
494 int a = tcp->sendPacket(buffer, 8);
498 MUTEX_UNLOCK(&mutex);
506 MUTEX_UNLOCK(&mutex);
510 ChannelList* chanList = new ChannelList();
512 while (packetPos < packetLength)
514 Channel* chan = new Channel();
515 chan->number = extractULONG();
516 chan->type = extractULONG();
517 chan->name = extractString();
519 if (chan->type == type)
521 chanList->push_back(chan);
522 Log::getInstance()->log("VDR", Log::DEBUG, "Have added a channel to list. %lu %lu %s", chan->number, chan->type, chan->name);
523 if (chan->number > maxChannelNumber) maxChannelNumber = chan->number;
532 MUTEX_UNLOCK(&mutex);
534 if (maxChannelNumber > 99999)
535 channelNumberWidth = 6;
536 else if (maxChannelNumber > 9999)
537 channelNumberWidth = 5;
538 else if (maxChannelNumber > 999)
539 channelNumberWidth = 4;
540 else if (maxChannelNumber > 99)
541 channelNumberWidth = 3;
542 else if (maxChannelNumber > 9)
543 channelNumberWidth = 2;
545 channelNumberWidth = 1;
550 int VDR::streamChannel(ULONG number)
554 *(unsigned long*)&buffer[0] = htonl(8);
555 *(unsigned long*)&buffer[4] = htonl(VDR_STREAMCHANNEL);
556 *(unsigned long*)&buffer[8] = htonl(number);
559 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
561 int a = tcp->sendPacket(buffer, 12);
566 MUTEX_UNLOCK(&mutex);
572 MUTEX_UNLOCK(&mutex);
576 int toReturn = (int)extractULONG();
578 MUTEX_UNLOCK(&mutex);
583 int VDR::stopStreaming()
587 *(unsigned long*)&buffer[0] = htonl(4);
588 *(unsigned long*)&buffer[4] = htonl(VDR_STOPSTREAMING);
591 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
593 int a = tcp->sendPacket(buffer, 8);
598 MUTEX_UNLOCK(&mutex);
604 MUTEX_UNLOCK(&mutex);
608 int toReturn = (int)extractULONG();
610 MUTEX_UNLOCK(&mutex);
615 UCHAR* VDR::getImageBlock(ULONG position, UINT maxAmount, UINT* amountReceived)
617 return getBlock(position, maxAmount, amountReceived, VDR_GETIMAGEBLOCK);
620 UCHAR* VDR::getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived)
622 return getBlock(position, maxAmount, amountReceived, VDR_GETBLOCK);
625 UCHAR* VDR::getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived, ULONG cmd)
629 *(unsigned long*)&buffer[0] = htonl(16);
630 *(unsigned long*)&buffer[4] = htonl(cmd);
631 *(ULLONG*)&buffer[8] = htonll(position);
632 *(unsigned long*)&buffer[16] = htonl(maxAmount);
635 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
637 int a = tcp->sendPacket(buffer, 20);
641 MUTEX_UNLOCK(&mutex);
647 MUTEX_UNLOCK(&mutex);
653 Log::getInstance()->log("VDR", Log::DEBUG, "Detected getblock 0");
655 MUTEX_UNLOCK(&mutex);
659 UCHAR* toReturn = packet;
660 *amountReceived = packetLength;
661 // Manually clean up instead of running freePacket to keep the block
665 MUTEX_UNLOCK(&mutex);
671 ULLONG VDR::streamRecording(char* fileName, ULONG* totalFrames)
673 unsigned long totalLength = 8 + strlen(fileName) + 1;
674 UCHAR* buffer = new UCHAR[totalLength];
676 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
677 *(unsigned long*)&buffer[4] = htonl(VDR_STREAMRECORDING);
678 strcpy((char*)&buffer[8], fileName);
681 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
683 unsigned int a = tcp->sendPacket(buffer, totalLength);
686 if (a != totalLength)
689 MUTEX_UNLOCK(&mutex);
695 MUTEX_UNLOCK(&mutex);
699 ULLONG lengthBytes = extractULLONG();
700 ULONG lengthFrames = extractULONG();
702 MUTEX_UNLOCK(&mutex);
704 Log::getInstance()->log("VDR", Log::DEBUG, "VDR said length is: %llu %lu", lengthBytes, lengthFrames);
706 *totalFrames = lengthFrames;
710 ULLONG VDR::positionFromFrameNumber(ULONG frameNumber)
712 unsigned long totalLength = 12;
713 UCHAR* buffer = new UCHAR[totalLength];
715 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
716 *(unsigned long*)&buffer[4] = htonl(VDR_POSFROMFRAME);
717 *(unsigned long*)&buffer[8] = htonl(frameNumber);
720 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
722 unsigned int a = tcp->sendPacket(buffer, totalLength);
725 if (a != totalLength)
728 MUTEX_UNLOCK(&mutex);
734 MUTEX_UNLOCK(&mutex);
738 ULLONG position = extractULLONG();
740 MUTEX_UNLOCK(&mutex);
742 Log::getInstance()->log("VDR", Log::DEBUG, "VDR said new position is: %llu", position);
747 ULONG VDR::frameNumberFromPosition(ULLONG position)
749 unsigned long totalLength = 16;
750 UCHAR* buffer = new UCHAR[totalLength];
752 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
753 *(unsigned long*)&buffer[4] = htonl(VDR_FRAMEFROMPOS);
754 *(ULLONG*)&buffer[8] = htonll(position);
757 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
759 unsigned int a = tcp->sendPacket(buffer, totalLength);
762 if (a != totalLength)
765 MUTEX_UNLOCK(&mutex);
771 MUTEX_UNLOCK(&mutex);
775 ULONG framenumber = extractULONG();
777 MUTEX_UNLOCK(&mutex);
779 Log::getInstance()->log("VDR", Log::DEBUG, "VDR said new framenumber is: %u", framenumber);
784 bool VDR::getNextIFrame(ULONG frameNumber, ULONG direction, ULLONG* rfilePosition, ULONG* rframeNumber, ULONG* rframeLength)
786 unsigned long totalLength = 16;
787 UCHAR* buffer = new UCHAR[totalLength];
789 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
790 *(unsigned long*)&buffer[4] = htonl(VDR_GETNEXTIFRAME);
791 *(unsigned long*)&buffer[8] = htonl(frameNumber);
792 *(unsigned long*)&buffer[12] = htonl(direction);
795 if (!connected) { MUTEX_UNLOCK(&mutex); return false; }
797 unsigned int a = tcp->sendPacket(buffer, totalLength);
800 if (a != totalLength)
803 MUTEX_UNLOCK(&mutex);
809 MUTEX_UNLOCK(&mutex);
815 Log::getInstance()->log("VDR", Log::DEBUG, "Detected getNextIFrame error");
817 MUTEX_UNLOCK(&mutex);
821 *rfilePosition = extractULLONG();
822 *rframeNumber = extractULONG();
823 *rframeLength = extractULONG();
826 MUTEX_UNLOCK(&mutex);
828 // Log::getInstance()->log("VDR", Log::DEBUG, "VDR GNIF said %llu %lu %lu", *rfilePosition, *rframeNumber, *rframeLength);
833 EventList* VDR::getChannelSchedule(ULONG number)
837 return getChannelSchedule(number, now, 24 * 60 * 60);
840 EventList* VDR::getChannelSchedule(ULONG number, time_t start, ULONG duration)
842 // retrieve event list (vector of events) from vdr within filter window. duration is in seconds
845 *(unsigned long*)&buffer[0] = htonl(16);
846 *(unsigned long*)&buffer[4] = htonl(VDR_GETCHANNELSCHEDULE);
847 *(unsigned long*)&buffer[8] = htonl(number);
848 *(unsigned long*)&buffer[12] = htonl(start);
849 *(unsigned long*)&buffer[16] = htonl(duration);
852 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
854 int a = tcp->sendPacket(buffer, 20);
859 MUTEX_UNLOCK(&mutex);
865 MUTEX_UNLOCK(&mutex);
869 // received a ulong(0) - schedules error in the plugin
873 MUTEX_UNLOCK(&mutex);
877 EventList* eventList = new EventList();
879 while (packetPos < packetLength)
881 Event* event = new Event();
882 event->id = extractULONG();
883 event->time = extractULONG();
884 event->duration = extractULONG();
885 event->title = extractString();
886 event->subtitle = extractString();
887 event->description = extractString();
888 eventList->push_back(event);
892 MUTEX_UNLOCK(&mutex);
894 Log::getInstance()->log("VDR", Log::DEBUG, "Success got to end of getChannelSchedule");
898 int VDR::configSave(const char* section, const char* key, const char* value)
900 ULONG totalLength = 8 + strlen(section) + strlen(key) + strlen(value) + 3; // 8 for headers, 3 for nulls
901 UCHAR* buffer = new UCHAR[totalLength];
903 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
904 *(unsigned long*)&buffer[4] = htonl(VDR_CONFIGSAVE);
907 strcpy((char*)&buffer[position], section);
908 position += strlen(section) + 1;
909 strcpy((char*)&buffer[position], key);
910 position += strlen(key) + 1;
911 strcpy((char*)&buffer[position], value);
914 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
916 unsigned int a = tcp->sendPacket(buffer, totalLength);
919 if (a != totalLength)
922 MUTEX_UNLOCK(&mutex);
928 MUTEX_UNLOCK(&mutex);
932 int toReturn = (int)extractULONG();
934 MUTEX_UNLOCK(&mutex);
939 char* VDR::configLoad(const char* section, const char* key)
941 ULONG totalLength = 8 + strlen(section) + strlen(key) + 2; // 8 for headers, 2 for nulls
942 UCHAR* buffer = new UCHAR[totalLength];
944 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
945 *(unsigned long*)&buffer[4] = htonl(VDR_CONFIGLOAD);
948 strcpy((char*)&buffer[position], section);
949 position += strlen(section) + 1;
950 strcpy((char*)&buffer[position], key);
953 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
955 unsigned int a = tcp->sendPacket(buffer, totalLength);
958 if (a != totalLength)
961 MUTEX_UNLOCK(&mutex);
967 MUTEX_UNLOCK(&mutex);
970 char* toReturn = extractString();
972 MUTEX_UNLOCK(&mutex);
977 RecTimerList* VDR::getRecTimersList()
981 *(unsigned long*)&buffer[0] = htonl(4);
982 *(unsigned long*)&buffer[4] = htonl(VDR_GETTIMERS);
985 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
987 int a = tcp->sendPacket(buffer, 8);
991 MUTEX_UNLOCK(&mutex);
999 MUTEX_UNLOCK(&mutex);
1003 RecTimerList* recTimerList = new RecTimerList();
1005 ULONG numTimers = extractULONG();
1008 RecTimer* newRecTimer;
1011 while (packetPos < packetLength)
1013 newRecTimer = new RecTimer();
1014 newRecTimer->active = extractULONG();
1015 newRecTimer->recording = extractULONG();
1016 newRecTimer->pending = extractULONG();
1017 newRecTimer->priority = extractULONG();
1018 newRecTimer->lifeTime = extractULONG();
1019 newRecTimer->channelNumber = extractULONG();
1020 newRecTimer->startTime = extractULONG();
1021 newRecTimer->stopTime = extractULONG();
1022 newRecTimer->day = extractULONG();
1023 newRecTimer->weekDays = extractULONG();
1025 tempString = extractString();
1026 newRecTimer->setFile(tempString);
1027 delete[] tempString;
1029 recTimerList->push_back(newRecTimer);
1030 Log::getInstance()->log("VDR", Log::DEBUG, "TL: %lu %lu %lu %lu %lu %lu %lu %lu %s",
1031 newRecTimer->active, newRecTimer->recording, newRecTimer->pending, newRecTimer->priority, newRecTimer->lifeTime,
1032 newRecTimer->channelNumber, newRecTimer->startTime, newRecTimer->stopTime, newRecTimer->getFile());
1037 MUTEX_UNLOCK(&mutex);
1039 sort(recTimerList->begin(), recTimerList->end(), RecTimerSorter());
1041 return recTimerList;
1044 ULONG VDR::setEventTimer(char* timerString)
1046 unsigned long totalLength = 8 + strlen(timerString) + 1;
1047 UCHAR* buffer = new UCHAR[totalLength];
1049 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
1050 *(unsigned long*)&buffer[4] = htonl(VDR_SETTIMER);
1051 strcpy((char*)&buffer[8], timerString);
1054 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
1056 unsigned int a = tcp->sendPacket(buffer, totalLength);
1059 if (a != totalLength)
1062 MUTEX_UNLOCK(&mutex);
1068 MUTEX_UNLOCK(&mutex);
1072 ULONG toReturn = extractULONG();
1074 MUTEX_UNLOCK(&mutex);
1079 RecInfo* VDR::getRecInfo(char* fileName)
1081 unsigned long totalLength = 8 + strlen(fileName) + 1;
1082 UCHAR* buffer = new UCHAR[totalLength];
1084 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
1085 *(unsigned long*)&buffer[4] = htonl(VDR_GETRECINFO);
1086 strcpy((char*)&buffer[8], fileName);
1089 if (!connected) { MUTEX_UNLOCK(&mutex); return NULL; }
1091 unsigned int a = tcp->sendPacket(buffer, totalLength);
1094 if (a != totalLength)
1097 MUTEX_UNLOCK(&mutex);
1103 MUTEX_UNLOCK(&mutex);
1109 Log::getInstance()->log("VDR", Log::DEBUG, "Could not get rec info");
1111 MUTEX_UNLOCK(&mutex);
1115 TCP::dump(packet, packetLength);
1117 RecInfo* recInfo = new RecInfo();
1119 recInfo->timerStart = extractULONG();
1120 recInfo->timerEnd = extractULONG();
1121 recInfo->resumePoint = extractULONG();
1122 recInfo->summary = extractString();
1124 ULONG numComponents = extractULONG();
1127 recInfo->setNumComponents(numComponents);
1128 for (ULONG i = 0; i < numComponents; i++)
1130 recInfo->streams[i] = extractUCHAR();
1131 recInfo->types[i] = extractUCHAR();
1132 recInfo->languages[i] = extractString();
1133 recInfo->descriptions[i] = extractString();
1140 MUTEX_UNLOCK(&mutex);
1145 ULLONG VDR::rescanRecording(ULONG* totalFrames)
1147 unsigned long totalLength = 8;
1148 UCHAR* buffer = new UCHAR[totalLength];
1150 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
1151 *(unsigned long*)&buffer[4] = htonl(VDR_RESCANRECORDING);
1154 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
1156 unsigned int a = tcp->sendPacket(buffer, totalLength);
1159 if (a != totalLength)
1162 MUTEX_UNLOCK(&mutex);
1168 MUTEX_UNLOCK(&mutex);
1172 ULLONG lengthBytes = extractULLONG();
1173 ULONG lengthFrames = extractULONG();
1175 MUTEX_UNLOCK(&mutex);
1177 Log::getInstance()->log("VDR", Log::DEBUG, "VDR said length is: %llu %lu", lengthBytes, lengthFrames);
1179 *totalFrames = lengthFrames;
1183 MarkList* VDR::getMarks(char* fileName)
1185 unsigned long totalLength = 8 + strlen(fileName) + 1;
1186 UCHAR* buffer = new UCHAR[totalLength];
1188 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
1189 *(unsigned long*)&buffer[4] = htonl(VDR_GETMARKS);
1190 strcpy((char*)&buffer[8], fileName);
1193 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
1195 unsigned int a = tcp->sendPacket(buffer, totalLength);
1198 if (a != totalLength)
1201 MUTEX_UNLOCK(&mutex);
1207 MUTEX_UNLOCK(&mutex);
1213 MUTEX_UNLOCK(&mutex);
1217 MarkList* markList = new MarkList();
1219 while (packetPos < packetLength)
1221 Mark* mark = new Mark();
1222 mark->pos = extractULONG();
1224 markList->push_back(mark);
1225 Log::getInstance()->log("VDR", Log::DEBUG, "Have added a mark to list. %lu", mark->pos);
1229 MUTEX_UNLOCK(&mutex);
1234 void VDR::getChannelPids(Channel* channel)
1238 *(unsigned long*)&buffer[0] = htonl(8);
1239 *(unsigned long*)&buffer[4] = htonl(VDR_GETCHANNELPIDS);
1240 *(unsigned long*)&buffer[8] = htonl(channel->number);
1243 if (!connected) { MUTEX_UNLOCK(&mutex); return ; }
1245 int a = tcp->sendPacket(buffer, 12);
1250 MUTEX_UNLOCK(&mutex);
1256 MUTEX_UNLOCK(&mutex);
1260 // Format of response
1268 channel->vpid = extractULONG();
1269 channel->numAPids = extractULONG();
1271 for (ULONG i = 0; i < channel->numAPids; i++)
1274 newapid.pid = extractULONG();
1275 newapid.name = extractString();
1276 channel->apids.push_back(newapid);
1280 MUTEX_UNLOCK(&mutex);
1286 * media List Request:
1288 * 4 VDR_GETMEDIALIST
1289 * 4 flags (currently unused)
1292 * Media List response:
1300 * 4 strlen (incl. 0 Byte)
1304 MediaList* VDR::getMediaList(const char* parent,int mediaType)
1306 Log::getInstance()->log("VDR", Log::DEBUG, "getMediaList %s,type=%d",
1307 (parent?parent:"NULL"), mediaType);
1308 unsigned long totalLength = 12;
1309 if (parent) totalLength+=strlen(parent) + 1;
1310 UCHAR* buffer = new UCHAR[totalLength];
1312 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
1313 *(unsigned long*)&buffer[4] = htonl(VDR_GETMEDIALIST);
1315 for (int i=8;i<12;i++) buffer[i]=0;
1318 strcpy((char*)&buffer[12], parent);
1319 buffer[totalLength-1]=0;
1322 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
1324 unsigned int a = tcp->sendPacket(buffer, totalLength);
1327 if (a != totalLength)
1330 MUTEX_UNLOCK(&mutex);
1336 MUTEX_UNLOCK(&mutex);
1342 MUTEX_UNLOCK(&mutex);
1345 if (packetLength < 12) {
1346 Log::getInstance()->log("VDR", Log::ERR, "receiveMediaList packet too short, expected 12, got %d", packetLength);
1348 MUTEX_UNLOCK(&mutex);
1351 MediaList* mediaList = new MediaList();
1353 code=extractULONG();
1354 ULONG numEntries=extractULONG();
1355 Log::getInstance()->log("VDR", Log::DEBUG, "receiveMediaList with %d entries",numEntries);
1356 while (packetPos < packetLength && numEntries >0)
1358 Media* m = new Media();
1359 ULONG mtype = extractULONG();
1360 ULONG mtime=extractULONG();
1362 flags=extractULONG();
1363 ULONG stsize=extractULONG();
1364 char * name=extractString();
1365 if (! name || stsize != (strlen(name)+1)) {
1366 Log::getInstance()->log("VDR", Log::ERR, "receiveMediaList invalid packet entry, read size %d, strlen %d", stsize, strlen(name)+1);
1370 MUTEX_UNLOCK(&mutex);
1373 //ignore . and .. entries
1374 if (strcmp(name,".") == 0 || strcmp(name,"..")==0) {
1378 m->setFileName(name);
1380 m->setMediaType(mtype);
1381 mediaList->push_back(m);
1382 Log::getInstance()->log("VDR", Log::DEBUG, "Have added a media to list. %s, type=%d, time=%d", name,mtype,mtime);
1387 MUTEX_UNLOCK(&mutex);
1392 * get image Request:
1395 * 4 flags (currently unused)
1400 * get image response:
1405 ULONG VDR::loadImage(const char* fileName, ULONG x, ULONG y)
1407 unsigned long totalLength = 20 + strlen(fileName) + 1;
1408 UCHAR* buffer = new UCHAR[totalLength];
1410 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
1411 *(unsigned long*)&buffer[4] = htonl(VDR_GETIMAGE);
1412 *(unsigned long*)&buffer[8] = htonl(0);
1413 *(unsigned long*)&buffer[8] = htonl(x);
1414 *(unsigned long*)&buffer[8] = htonl(y);
1415 strcpy((char*)&buffer[12], fileName);
1418 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
1420 unsigned int a = tcp->sendPacket(buffer, totalLength);
1423 if (a != totalLength)
1426 MUTEX_UNLOCK(&mutex);
1432 MUTEX_UNLOCK(&mutex);
1437 ULONG lengthBytes = extractULONG();
1439 MUTEX_UNLOCK(&mutex);
1441 Log::getInstance()->log("VDR", Log::DEBUG, "getImage %s: %lu", fileName,lengthBytes);
1446 int VDR::deleteTimer(RecTimer* delTimer)
1448 Log::getInstance()->log("VDR", Log::DEBUG, "Delete timer called");
1450 unsigned long totalLength = 28;
1451 UCHAR* buffer = new UCHAR[totalLength];
1453 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
1454 *(unsigned long*)&buffer[4] = htonl(VDR_DELETETIMER);
1455 *(unsigned long*)&buffer[8] = htonl(delTimer->channelNumber);
1456 *(unsigned long*)&buffer[12] = htonl(delTimer->weekDays);
1457 *(unsigned long*)&buffer[16] = htonl(delTimer->day);
1458 *(unsigned long*)&buffer[20] = htonl(delTimer->startTime);
1459 *(unsigned long*)&buffer[24] = htonl(delTimer->stopTime);
1463 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
1465 unsigned int a = tcp->sendPacket(buffer, totalLength);
1468 if (a != totalLength)
1471 MUTEX_UNLOCK(&mutex);
1477 MUTEX_UNLOCK(&mutex);
1481 int toReturn = (int)extractULONG();
1483 MUTEX_UNLOCK(&mutex);