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
24 VDR* VDR::instance = NULL;
27 #define MUTEX_LOCK(mutex) pthread_mutex_lock(mutex)
28 #define MUTEX_UNLOCK(mutex) pthread_mutex_unlock(mutex)
30 #define MUTEX_LOCK(mutex) WaitForSingleObject(*(mutex), INFINITE )
31 #define MUTEX_UNLOCK(mutex) ReleaseMutex(*(mutex))
43 pthread_mutex_init(&mutex, NULL);
45 mutex=CreateMutex(NULL,FALSE,NULL);
59 if (initted) shutdown();
62 VDR* VDR::getInstance()
67 int VDR::init(int tport)
69 if (initted) return 0;
72 logger = Log::getInstance();
78 if (!initted) return 0;
84 void VDR::findServers(vector<VDRServer>& servers)
86 Wol* wol = Wol::getInstance();
88 char* message = "VOMP";
90 DatagramSocket ds(port);
91 int haveAtLeastOne = 0;
94 bool firstloop = true;
101 logger->log("VDR", Log::NOTICE, "Broadcasting for server");
102 ds.send("255.255.255.255", 3024, message, strlen(message));
103 if(!firstloop) wol->doWakeUp();
105 retval = ds.waitforMessage(waitType);
107 if (retval == 2) // we got a reply
109 if (!strcmp(ds.getData(), "VOMP")) // echo.....
116 newServer.ip = new char[16];
117 strcpy(newServer.ip, ds.getFromIPA());
119 if (ds.getDataLength() == 0)
121 newServer.name = new char[1];
122 newServer.name[0] = '\0';
126 newServer.name = new char[strlen(ds.getData())+1];
127 strcpy(newServer.name, ds.getData());
130 servers.push_back(newServer);
137 if (haveAtLeastOne) break;
142 sort(servers.begin(), servers.end(), ServerSorter());
145 void VDR::cancelFindingServer()
150 void VDR::setServerIP(char* newIP)
152 strcpy(serverIP, newIP);
159 if (tcp->connectTo(serverIP, 3024))
170 void VDR::disconnect()
175 Log::getInstance()->log("VDR", Log::DEBUG, "Disconnect");
178 void VDR::setReceiveWindow(size_t size)
180 if (connected) tcp->setReceiveWindow(size);
183 ///////////////////////////////////////////////////////
187 packet = (UCHAR*)tcp->receivePacket();
193 packetLength = tcp->getDataLength();
197 void VDR::freePacket()
199 // Must be called if getPacket return 1, except in getBlock
206 int VDR::serverError()
208 if ((packetPos == 0) && (packetLength == 4) && !ntohl(*(ULONG*)packet)) return 1;
212 char* VDR::extractString()
214 if (serverError()) return NULL;
216 int length = strlen((char*)&packet[packetPos]);
217 if ((packetPos + length) > packetLength) return NULL;
218 char* str = new char[length + 1];
219 strcpy(str, (char*)&packet[packetPos]);
220 packetPos += length + 1;
224 UCHAR VDR::extractUCHAR()
226 if ((packetPos + sizeof(UCHAR)) > packetLength) return 0;
227 UCHAR uc = packet[packetPos];
228 packetPos += sizeof(UCHAR);
232 ULONG VDR::extractULONG()
234 if ((packetPos + sizeof(ULONG)) > packetLength) return 0;
235 ULONG ul = ntohl(*(ULONG*)&packet[packetPos]);
236 packetPos += sizeof(ULONG);
240 ULLONG VDR::extractULLONG()
242 if ((packetPos + sizeof(ULLONG)) > packetLength) return 0;
243 ULLONG ull = ntohll(*(ULLONG*)&packet[packetPos]);
244 packetPos += sizeof(ULLONG);
248 long VDR::extractLONG()
250 if ((packetPos + sizeof(long)) > packetLength) return 0;
251 long l = ntohl(*(long*)&packet[packetPos]);
252 packetPos += sizeof(long);
256 /////////////////////////////////////////////////////////////////////////////
262 *(unsigned long*)&buffer[0] = htonl(10);
263 *(unsigned long*)&buffer[4] = htonl(VDR_LOGIN);
265 tcp->getMAC((char*)&buffer[8]);
271 MUTEX_UNLOCK(&mutex);
275 int a = tcp->sendPacket(buffer, 14);
279 MUTEX_UNLOCK(&mutex);
287 MUTEX_UNLOCK(&mutex);
291 ULONG vdrTime = extractULONG();
292 logger->log("VDR", Log::DEBUG, "vdrtime = %lu", vdrTime);
293 long vdrTimeOffset = extractLONG();
294 logger->log("VDR", Log::DEBUG, "offset = %i", vdrTimeOffset);
297 MUTEX_UNLOCK(&mutex);
299 // Set the time and zone on the MVP
302 struct timespec currentTime;
303 currentTime.tv_sec = vdrTime;
304 currentTime.tv_nsec = 0;
305 int b = clock_settime(CLOCK_REALTIME, ¤tTime);
307 logger->log("VDR", Log::DEBUG, "set clock = %u", b);
309 // now make a TZ variable and set it
313 if (vdrTimeOffset > 0) sign = '-';
316 vdrTimeOffset = abs(vdrTimeOffset);
318 hours = (int)vdrTimeOffset / 3600;
319 minutes = vdrTimeOffset % 3600;
321 logger->log("VDR", Log::DEBUG, "%c %i %i", sign, hours, minutes);
323 minutes = (int)minutes / 60;
325 logger->log("VDR", Log::DEBUG, "%c %i %i", sign, hours, minutes);
328 sprintf(newTZ, "MVP%c%i:%i", sign, hours, minutes);
329 setenv("TZ", newTZ, 1);
331 logger->log("VDR", Log::DEBUG, "Timezone data: %s", newTZ);
337 bool VDR::getRecordingsList(RecMan* recman)
341 *(unsigned long*)&buffer[0] = htonl(4);
342 *(unsigned long*)&buffer[4] = htonl(VDR_GETRECORDINGLIST);
347 MUTEX_UNLOCK(&mutex);
351 int a = tcp->sendPacket(buffer, 8);
355 MUTEX_UNLOCK(&mutex);
363 MUTEX_UNLOCK(&mutex);
367 ULONG totalSpace = extractULONG();
368 ULONG freeSpace = extractULONG();
369 ULONG percent = extractULONG();
370 recman->setStats(totalSpace, freeSpace, percent);
376 while (packetPos < packetLength)
378 start = extractULONG();
379 name = extractString();
380 fileName = extractString();
382 recman->addEntry(start, name, fileName);
389 MUTEX_UNLOCK(&mutex);
394 int VDR::deleteRecording(char* fileName)
396 unsigned long totalLength = 8 + strlen(fileName) + 1;
397 UCHAR* buffer = new UCHAR[totalLength];
399 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
400 *(unsigned long*)&buffer[4] = htonl(VDR_DELETERECORDING);
401 strcpy((char*)&buffer[8], fileName);
404 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
406 unsigned int a = tcp->sendPacket(buffer, totalLength);
409 if (a != totalLength)
412 MUTEX_UNLOCK(&mutex);
418 MUTEX_UNLOCK(&mutex);
422 int toReturn = (int)extractULONG();
424 MUTEX_UNLOCK(&mutex);
429 char* VDR::moveRecording(char* fileName, char* newPath)
431 unsigned long totalLength = 8 + strlen(fileName) + 1 + strlen(newPath) + 1;
432 UCHAR* buffer = new UCHAR[totalLength];
434 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
435 *(unsigned long*)&buffer[4] = htonl(VDR_MOVERECORDING);
436 strcpy((char*)&buffer[8], fileName);
437 strcpy((char*)&buffer[8 + strlen(fileName) + 1], newPath);
440 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
442 unsigned int a = tcp->sendPacket(buffer, totalLength);
445 if (a != totalLength)
448 MUTEX_UNLOCK(&mutex);
454 MUTEX_UNLOCK(&mutex);
458 char* toReturn = NULL;
459 int success = (int)extractULONG();
462 toReturn = extractString();
466 MUTEX_UNLOCK(&mutex);
471 ChannelList* VDR::getChannelsList(ULONG type)
475 *(unsigned long*)&buffer[0] = htonl(4);
476 *(unsigned long*)&buffer[4] = htonl(VDR_GETCHANNELLIST);
479 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
481 int a = tcp->sendPacket(buffer, 8);
485 MUTEX_UNLOCK(&mutex);
493 MUTEX_UNLOCK(&mutex);
497 ChannelList* chanList = new ChannelList();
499 while (packetPos < packetLength)
501 Channel* chan = new Channel();
502 chan->number = extractULONG();
503 chan->type = extractULONG();
504 chan->name = extractString();
506 if (chan->type == type)
508 chanList->push_back(chan);
509 Log::getInstance()->log("VDR", Log::DEBUG, "Have added a channel to list. %lu %lu %s", chan->number, chan->type, chan->name);
518 MUTEX_UNLOCK(&mutex);
523 int VDR::streamChannel(ULONG number)
527 *(unsigned long*)&buffer[0] = htonl(8);
528 *(unsigned long*)&buffer[4] = htonl(VDR_STREAMCHANNEL);
529 *(unsigned long*)&buffer[8] = htonl(number);
532 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
534 int a = tcp->sendPacket(buffer, 12);
539 MUTEX_UNLOCK(&mutex);
545 MUTEX_UNLOCK(&mutex);
549 int toReturn = (int)extractULONG();
551 MUTEX_UNLOCK(&mutex);
556 int VDR::stopStreaming()
560 *(unsigned long*)&buffer[0] = htonl(4);
561 *(unsigned long*)&buffer[4] = htonl(VDR_STOPSTREAMING);
564 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
566 int a = tcp->sendPacket(buffer, 8);
571 MUTEX_UNLOCK(&mutex);
577 MUTEX_UNLOCK(&mutex);
581 int toReturn = (int)extractULONG();
583 MUTEX_UNLOCK(&mutex);
588 UCHAR* VDR::getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived)
592 *(unsigned long*)&buffer[0] = htonl(16);
593 *(unsigned long*)&buffer[4] = htonl(VDR_GETBLOCK);
594 *(ULLONG*)&buffer[8] = htonll(position);
595 *(unsigned long*)&buffer[16] = htonl(maxAmount);
598 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
600 int a = tcp->sendPacket(buffer, 20);
604 MUTEX_UNLOCK(&mutex);
610 MUTEX_UNLOCK(&mutex);
616 Log::getInstance()->log("VDR", Log::DEBUG, "Detected getblock 0");
618 MUTEX_UNLOCK(&mutex);
622 UCHAR* toReturn = packet;
623 *amountReceived = packetLength;
624 // Manually clean up instead of running freePacket to keep the block
628 MUTEX_UNLOCK(&mutex);
634 ULLONG VDR::streamRecording(char* fileName, ULONG* totalFrames)
636 unsigned long totalLength = 8 + strlen(fileName) + 1;
637 UCHAR* buffer = new UCHAR[totalLength];
639 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
640 *(unsigned long*)&buffer[4] = htonl(VDR_STREAMRECORDING);
641 strcpy((char*)&buffer[8], fileName);
644 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
646 unsigned int a = tcp->sendPacket(buffer, totalLength);
649 if (a != totalLength)
652 MUTEX_UNLOCK(&mutex);
658 MUTEX_UNLOCK(&mutex);
662 ULLONG lengthBytes = extractULLONG();
663 ULONG lengthFrames = extractULONG();
665 MUTEX_UNLOCK(&mutex);
667 Log::getInstance()->log("VDR", Log::DEBUG, "VDR said length is: %llu %lu", lengthBytes, lengthFrames);
669 *totalFrames = lengthFrames;
673 ULLONG VDR::positionFromFrameNumber(ULONG frameNumber)
675 unsigned long totalLength = 12;
676 UCHAR* buffer = new UCHAR[totalLength];
678 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
679 *(unsigned long*)&buffer[4] = htonl(VDR_POSFROMFRAME);
680 *(unsigned long*)&buffer[8] = htonl(frameNumber);
683 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
685 unsigned int a = tcp->sendPacket(buffer, totalLength);
688 if (a != totalLength)
691 MUTEX_UNLOCK(&mutex);
697 MUTEX_UNLOCK(&mutex);
701 ULLONG position = extractULLONG();
703 MUTEX_UNLOCK(&mutex);
705 Log::getInstance()->log("VDR", Log::DEBUG, "VDR said new position is: %llu", position);
710 ULONG VDR::frameNumberFromPosition(ULLONG position)
712 unsigned long totalLength = 16;
713 UCHAR* buffer = new UCHAR[totalLength];
715 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
716 *(unsigned long*)&buffer[4] = htonl(VDR_FRAMEFROMPOS);
717 *(ULLONG*)&buffer[8] = htonll(position);
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 ULONG framenumber = extractULONG();
740 MUTEX_UNLOCK(&mutex);
742 Log::getInstance()->log("VDR", Log::DEBUG, "VDR said new framenumber is: %u", framenumber);
747 bool VDR::getNextIFrame(ULONG frameNumber, ULONG direction, ULLONG* rfilePosition, ULONG* rframeNumber, ULONG* rframeLength)
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_GETNEXTIFRAME);
754 *(unsigned long*)&buffer[8] = htonl(frameNumber);
755 *(unsigned long*)&buffer[12] = htonl(direction);
758 if (!connected) { MUTEX_UNLOCK(&mutex); return false; }
760 unsigned int a = tcp->sendPacket(buffer, totalLength);
763 if (a != totalLength)
766 MUTEX_UNLOCK(&mutex);
772 MUTEX_UNLOCK(&mutex);
778 Log::getInstance()->log("VDR", Log::DEBUG, "Detected getNextIFrame error");
780 MUTEX_UNLOCK(&mutex);
784 *rfilePosition = extractULLONG();
785 *rframeNumber = extractULONG();
786 *rframeLength = extractULONG();
789 MUTEX_UNLOCK(&mutex);
791 // Log::getInstance()->log("VDR", Log::DEBUG, "VDR GNIF said %llu %lu %lu", *rfilePosition, *rframeNumber, *rframeLength);
796 EventList* VDR::getChannelSchedule(ULONG number)
800 return getChannelSchedule(number, now, 24 * 60 * 60);
803 EventList* VDR::getChannelSchedule(ULONG number, time_t start, ULONG duration)
805 // retrieve event list (vector of events) from vdr within filter window. duration is in seconds
808 *(unsigned long*)&buffer[0] = htonl(16);
809 *(unsigned long*)&buffer[4] = htonl(VDR_GETCHANNELSCHEDULE);
810 *(unsigned long*)&buffer[8] = htonl(number);
811 *(unsigned long*)&buffer[12] = htonl(start);
812 *(unsigned long*)&buffer[16] = htonl(duration);
815 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
817 int a = tcp->sendPacket(buffer, 20);
822 MUTEX_UNLOCK(&mutex);
828 MUTEX_UNLOCK(&mutex);
832 // received a ulong(0) - schedules error in the plugin
836 MUTEX_UNLOCK(&mutex);
840 EventList* eventList = new EventList();
842 while (packetPos < packetLength)
844 Event* event = new Event();
845 event->id = extractULONG();
846 event->time = extractULONG();
847 event->duration = extractULONG();
848 event->title = extractString();
849 event->subtitle = extractString();
850 event->description = extractString();
851 eventList->push_back(event);
855 MUTEX_UNLOCK(&mutex);
857 Log::getInstance()->log("VDR", Log::DEBUG, "Success got to end of getChannelSchedule");
861 int VDR::configSave(char* section, char* key, const char* value)
863 ULONG totalLength = 8 + strlen(section) + strlen(key) + strlen(value) + 3; // 8 for headers, 3 for nulls
864 UCHAR* buffer = new UCHAR[totalLength];
866 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
867 *(unsigned long*)&buffer[4] = htonl(VDR_CONFIGSAVE);
870 strcpy((char*)&buffer[position], section);
871 position += strlen(section) + 1;
872 strcpy((char*)&buffer[position], key);
873 position += strlen(key) + 1;
874 strcpy((char*)&buffer[position], value);
877 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
879 unsigned int a = tcp->sendPacket(buffer, totalLength);
882 if (a != totalLength)
885 MUTEX_UNLOCK(&mutex);
891 MUTEX_UNLOCK(&mutex);
895 int toReturn = (int)extractULONG();
897 MUTEX_UNLOCK(&mutex);
902 char* VDR::configLoad(char* section, char* key)
904 ULONG totalLength = 8 + strlen(section) + strlen(key) + 2; // 8 for headers, 2 for nulls
905 UCHAR* buffer = new UCHAR[totalLength];
907 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
908 *(unsigned long*)&buffer[4] = htonl(VDR_CONFIGLOAD);
911 strcpy((char*)&buffer[position], section);
912 position += strlen(section) + 1;
913 strcpy((char*)&buffer[position], key);
916 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
918 unsigned int a = tcp->sendPacket(buffer, totalLength);
921 if (a != totalLength)
924 MUTEX_UNLOCK(&mutex);
930 MUTEX_UNLOCK(&mutex);
933 char* toReturn = extractString();
935 MUTEX_UNLOCK(&mutex);
940 RecTimerList* VDR::getRecTimersList()
944 *(unsigned long*)&buffer[0] = htonl(4);
945 *(unsigned long*)&buffer[4] = htonl(VDR_GETTIMERS);
948 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
950 int a = tcp->sendPacket(buffer, 8);
954 MUTEX_UNLOCK(&mutex);
962 MUTEX_UNLOCK(&mutex);
966 RecTimerList* recTimerList = new RecTimerList();
968 ULONG numTimers = extractULONG();
971 RecTimer* newRecTimer;
974 while (packetPos < packetLength)
976 newRecTimer = new RecTimer();
977 newRecTimer->active = extractULONG();
978 newRecTimer->recording = extractULONG();
979 newRecTimer->pending = extractULONG();
980 newRecTimer->priority = extractULONG();
981 newRecTimer->lifeTime = extractULONG();
982 newRecTimer->channelNumber = extractULONG();
983 newRecTimer->startTime = extractULONG();
984 newRecTimer->stopTime = extractULONG();
986 tempString = extractString();
987 newRecTimer->setFile(tempString);
990 recTimerList->push_back(newRecTimer);
991 Log::getInstance()->log("VDR", Log::DEBUG, "TL: %lu %lu %lu %lu %lu %lu %lu %lu %s",
992 newRecTimer->active, newRecTimer->recording, newRecTimer->pending, newRecTimer->priority, newRecTimer->lifeTime,
993 newRecTimer->channelNumber, newRecTimer->startTime, newRecTimer->stopTime, newRecTimer->getFile());
998 MUTEX_UNLOCK(&mutex);
1000 sort(recTimerList->begin(), recTimerList->end(), RecTimerSorter());
1002 return recTimerList;
1005 ULONG VDR::setEventTimer(char* timerString)
1007 unsigned long totalLength = 8 + strlen(timerString) + 1;
1008 UCHAR* buffer = new UCHAR[totalLength];
1010 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
1011 *(unsigned long*)&buffer[4] = htonl(VDR_SETTIMER);
1012 strcpy((char*)&buffer[8], timerString);
1015 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
1017 unsigned int a = tcp->sendPacket(buffer, totalLength);
1020 if (a != totalLength)
1023 MUTEX_UNLOCK(&mutex);
1029 MUTEX_UNLOCK(&mutex);
1033 ULONG toReturn = extractULONG();
1035 MUTEX_UNLOCK(&mutex);
1040 RecInfo* VDR::getRecInfo(char* fileName)
1042 unsigned long totalLength = 8 + strlen(fileName) + 1;
1043 UCHAR* buffer = new UCHAR[totalLength];
1045 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
1046 *(unsigned long*)&buffer[4] = htonl(VDR_GETRECINFO);
1047 strcpy((char*)&buffer[8], fileName);
1050 if (!connected) { MUTEX_UNLOCK(&mutex); return NULL; }
1052 unsigned int a = tcp->sendPacket(buffer, totalLength);
1055 if (a != totalLength)
1058 MUTEX_UNLOCK(&mutex);
1064 MUTEX_UNLOCK(&mutex);
1070 Log::getInstance()->log("VDR", Log::DEBUG, "Could not get rec info");
1072 MUTEX_UNLOCK(&mutex);
1076 TCP::dump(packet, packetLength);
1078 RecInfo* recInfo = new RecInfo();
1080 recInfo->timerStart = extractULONG();
1081 recInfo->timerEnd = extractULONG();
1082 recInfo->resumePoint = extractULONG();
1083 recInfo->summary = extractString();
1085 ULONG numComponents = extractULONG();
1088 recInfo->setNumComponents(numComponents);
1089 for (ULONG i = 0; i < numComponents; i++)
1091 recInfo->streams[i] = extractUCHAR();
1092 recInfo->types[i] = extractUCHAR();
1093 recInfo->languages[i] = extractString();
1094 recInfo->descriptions[i] = extractString();
1101 MUTEX_UNLOCK(&mutex);
1106 ULLONG VDR::rescanRecording(ULONG* totalFrames)
1108 unsigned long totalLength = 8;
1109 UCHAR* buffer = new UCHAR[totalLength];
1111 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
1112 *(unsigned long*)&buffer[4] = htonl(VDR_RESCANRECORDING);
1115 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
1117 unsigned int a = tcp->sendPacket(buffer, totalLength);
1120 if (a != totalLength)
1123 MUTEX_UNLOCK(&mutex);
1129 MUTEX_UNLOCK(&mutex);
1133 ULLONG lengthBytes = extractULLONG();
1134 ULONG lengthFrames = extractULONG();
1136 MUTEX_UNLOCK(&mutex);
1138 Log::getInstance()->log("VDR", Log::DEBUG, "VDR said length is: %llu %lu", lengthBytes, lengthFrames);
1140 *totalFrames = lengthFrames;
1144 MarkList* VDR::getMarks(char* fileName)
1146 unsigned long totalLength = 8 + strlen(fileName) + 1;
1147 UCHAR* buffer = new UCHAR[totalLength];
1149 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
1150 *(unsigned long*)&buffer[4] = htonl(VDR_GETMARKS);
1151 strcpy((char*)&buffer[8], fileName);
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);
1174 MUTEX_UNLOCK(&mutex);
1178 MarkList* markList = new MarkList();
1180 while (packetPos < packetLength)
1182 Mark* mark = new Mark();
1183 mark->pos = extractULONG();
1185 markList->push_back(mark);
1186 Log::getInstance()->log("VDR", Log::DEBUG, "Have added a mark to list. %lu", mark->pos);
1190 MUTEX_UNLOCK(&mutex);
1195 void VDR::getChannelPids(Channel* channel)
1199 *(unsigned long*)&buffer[0] = htonl(8);
1200 *(unsigned long*)&buffer[4] = htonl(VDR_GETCHANNELPIDS);
1201 *(unsigned long*)&buffer[8] = htonl(channel->number);
1204 if (!connected) { MUTEX_UNLOCK(&mutex); return ; }
1206 int a = tcp->sendPacket(buffer, 12);
1211 MUTEX_UNLOCK(&mutex);
1217 MUTEX_UNLOCK(&mutex);
1221 // Format of response
1229 channel->vpid = extractULONG();
1230 channel->numAPids = extractULONG();
1232 for (ULONG i = 0; i < channel->numAPids; i++)
1235 newapid.pid = extractULONG();
1236 newapid.name = extractString();
1237 channel->apids.push_back(newapid);
1241 MUTEX_UNLOCK(&mutex);