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)
87 char* message = "VOMP";
89 DatagramSocket ds(port);
90 int haveAtLeastOne = 0;
99 logger->log("VDR", Log::NOTICE, "Broadcasting for server");
100 ds.send("255.255.255.255", 3024, message, strlen(message));
102 retval = ds.waitforMessage(waitType);
104 if (retval == 2) // we got a reply
106 if (!strcmp(ds.getData(), "VOMP")) // echo.....
113 newServer.ip = new char[16];
114 strcpy(newServer.ip, ds.getFromIPA());
116 if (ds.getDataLength() == 0)
118 newServer.name = new char[1];
119 newServer.name[0] = '\0';
123 newServer.name = new char[strlen(ds.getData())+1];
124 strcpy(newServer.name, ds.getData());
127 servers.push_back(newServer);
134 if (haveAtLeastOne) break;
138 sort(servers.begin(), servers.end(), ServerSorter());
141 void VDR::cancelFindingServer()
146 void VDR::setServerIP(char* newIP)
148 strcpy(serverIP, newIP);
155 if (tcp->connectTo(serverIP, 3024))
166 void VDR::disconnect()
171 Log::getInstance()->log("VDR", Log::DEBUG, "Disconnect");
174 void VDR::setReceiveWindow(size_t size)
176 if (connected) tcp->setReceiveWindow(size);
179 ///////////////////////////////////////////////////////
183 packet = (UCHAR*)tcp->receivePacket();
189 packetLength = tcp->getDataLength();
193 void VDR::freePacket()
195 // Must be called if getPacket return 1, except in getBlock
202 int VDR::serverError()
204 if ((packetPos == 0) && (packetLength == 4) && !ntohl(*(ULONG*)packet)) return 1;
208 char* VDR::extractString()
210 if (serverError()) return NULL;
212 int length = strlen((char*)&packet[packetPos]);
213 if ((packetPos + length) > packetLength) return NULL;
214 char* str = new char[length + 1];
215 strcpy(str, (char*)&packet[packetPos]);
216 packetPos += length + 1;
220 UCHAR VDR::extractUCHAR()
222 if ((packetPos + sizeof(UCHAR)) > packetLength) return 0;
223 UCHAR uc = packet[packetPos];
224 packetPos += sizeof(UCHAR);
228 ULONG VDR::extractULONG()
230 if ((packetPos + sizeof(ULONG)) > packetLength) return 0;
231 ULONG ul = ntohl(*(ULONG*)&packet[packetPos]);
232 packetPos += sizeof(ULONG);
236 ULLONG VDR::extractULLONG()
238 if ((packetPos + sizeof(ULLONG)) > packetLength) return 0;
239 ULLONG ull = ntohll(*(ULLONG*)&packet[packetPos]);
240 packetPos += sizeof(ULLONG);
244 long VDR::extractLONG()
246 if ((packetPos + sizeof(long)) > packetLength) return 0;
247 long l = ntohl(*(long*)&packet[packetPos]);
248 packetPos += sizeof(long);
252 /////////////////////////////////////////////////////////////////////////////
258 *(unsigned long*)&buffer[0] = htonl(10);
259 *(unsigned long*)&buffer[4] = htonl(VDR_LOGIN);
261 tcp->getMAC((char*)&buffer[8]);
267 MUTEX_UNLOCK(&mutex);
271 int a = tcp->sendPacket(buffer, 14);
275 MUTEX_UNLOCK(&mutex);
283 MUTEX_UNLOCK(&mutex);
287 ULONG vdrTime = extractULONG();
288 logger->log("VDR", Log::DEBUG, "vdrtime = %lu", vdrTime);
289 long vdrTimeOffset = extractLONG();
290 logger->log("VDR", Log::DEBUG, "offset = %i", vdrTimeOffset);
293 MUTEX_UNLOCK(&mutex);
295 // Set the time and zone on the MVP
298 struct timespec currentTime;
299 currentTime.tv_sec = vdrTime;
300 currentTime.tv_nsec = 0;
301 int b = clock_settime(CLOCK_REALTIME, ¤tTime);
303 logger->log("VDR", Log::DEBUG, "set clock = %u", b);
305 // now make a TZ variable and set it
309 if (vdrTimeOffset > 0) sign = '-';
312 vdrTimeOffset = abs(vdrTimeOffset);
314 hours = (int)vdrTimeOffset / 3600;
315 minutes = vdrTimeOffset % 3600;
317 logger->log("VDR", Log::DEBUG, "%c %i %i", sign, hours, minutes);
319 minutes = (int)minutes / 60;
321 logger->log("VDR", Log::DEBUG, "%c %i %i", sign, hours, minutes);
324 sprintf(newTZ, "MVP%c%i:%i", sign, hours, minutes);
325 setenv("TZ", newTZ, 1);
327 logger->log("VDR", Log::DEBUG, "Timezone data: %s", newTZ);
333 bool VDR::getRecordingsList(RecMan* recman)
337 *(unsigned long*)&buffer[0] = htonl(4);
338 *(unsigned long*)&buffer[4] = htonl(VDR_GETRECORDINGLIST);
343 MUTEX_UNLOCK(&mutex);
347 int a = tcp->sendPacket(buffer, 8);
351 MUTEX_UNLOCK(&mutex);
359 MUTEX_UNLOCK(&mutex);
363 ULONG totalSpace = extractULONG();
364 ULONG freeSpace = extractULONG();
365 ULONG percent = extractULONG();
366 recman->setStats(totalSpace, freeSpace, percent);
372 while (packetPos < packetLength)
374 start = extractULONG();
375 name = extractString();
376 fileName = extractString();
378 recman->addEntry(start, name, fileName);
385 MUTEX_UNLOCK(&mutex);
390 int VDR::deleteRecording(char* fileName)
392 unsigned long totalLength = 8 + strlen(fileName) + 1;
393 UCHAR* buffer = new UCHAR[totalLength];
395 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
396 *(unsigned long*)&buffer[4] = htonl(VDR_DELETERECORDING);
397 strcpy((char*)&buffer[8], fileName);
400 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
402 unsigned int a = tcp->sendPacket(buffer, totalLength);
405 if (a != totalLength)
408 MUTEX_UNLOCK(&mutex);
414 MUTEX_UNLOCK(&mutex);
418 int toReturn = (int)extractULONG();
420 MUTEX_UNLOCK(&mutex);
425 char* VDR::moveRecording(char* fileName, char* newPath)
427 unsigned long totalLength = 8 + strlen(fileName) + 1 + strlen(newPath) + 1;
428 UCHAR* buffer = new UCHAR[totalLength];
430 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
431 *(unsigned long*)&buffer[4] = htonl(VDR_MOVERECORDING);
432 strcpy((char*)&buffer[8], fileName);
433 strcpy((char*)&buffer[8 + strlen(fileName) + 1], newPath);
436 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
438 unsigned int a = tcp->sendPacket(buffer, totalLength);
441 if (a != totalLength)
444 MUTEX_UNLOCK(&mutex);
450 MUTEX_UNLOCK(&mutex);
454 char* toReturn = NULL;
455 int success = (int)extractULONG();
458 toReturn = extractString();
462 MUTEX_UNLOCK(&mutex);
467 ChannelList* VDR::getChannelsList(ULONG type)
471 *(unsigned long*)&buffer[0] = htonl(4);
472 *(unsigned long*)&buffer[4] = htonl(VDR_GETCHANNELLIST);
475 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
477 int a = tcp->sendPacket(buffer, 8);
481 MUTEX_UNLOCK(&mutex);
489 MUTEX_UNLOCK(&mutex);
493 ChannelList* chanList = new ChannelList();
495 while (packetPos < packetLength)
497 Channel* chan = new Channel();
498 chan->number = extractULONG();
499 chan->type = extractULONG();
500 chan->name = extractString();
502 if (chan->type == type)
504 chanList->push_back(chan);
505 Log::getInstance()->log("VDR", Log::DEBUG, "Have added a channel to list. %lu %lu %s", chan->number, chan->type, chan->name);
514 MUTEX_UNLOCK(&mutex);
519 int VDR::streamChannel(ULONG number)
523 *(unsigned long*)&buffer[0] = htonl(8);
524 *(unsigned long*)&buffer[4] = htonl(VDR_STREAMCHANNEL);
525 *(unsigned long*)&buffer[8] = htonl(number);
528 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
530 int a = tcp->sendPacket(buffer, 12);
535 MUTEX_UNLOCK(&mutex);
541 MUTEX_UNLOCK(&mutex);
545 int toReturn = (int)extractULONG();
547 MUTEX_UNLOCK(&mutex);
552 int VDR::stopStreaming()
556 *(unsigned long*)&buffer[0] = htonl(4);
557 *(unsigned long*)&buffer[4] = htonl(VDR_STOPSTREAMING);
560 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
562 int a = tcp->sendPacket(buffer, 8);
567 MUTEX_UNLOCK(&mutex);
573 MUTEX_UNLOCK(&mutex);
577 int toReturn = (int)extractULONG();
579 MUTEX_UNLOCK(&mutex);
584 UCHAR* VDR::getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived)
588 *(unsigned long*)&buffer[0] = htonl(16);
589 *(unsigned long*)&buffer[4] = htonl(VDR_GETBLOCK);
590 *(ULLONG*)&buffer[8] = htonll(position);
591 *(unsigned long*)&buffer[16] = htonl(maxAmount);
594 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
596 int a = tcp->sendPacket(buffer, 20);
600 MUTEX_UNLOCK(&mutex);
606 MUTEX_UNLOCK(&mutex);
612 Log::getInstance()->log("VDR", Log::DEBUG, "Detected getblock 0");
614 MUTEX_UNLOCK(&mutex);
618 UCHAR* toReturn = packet;
619 *amountReceived = packetLength;
620 // Manually clean up instead of running freePacket to keep the block
624 MUTEX_UNLOCK(&mutex);
630 ULLONG VDR::streamRecording(char* fileName, ULONG* totalFrames)
632 unsigned long totalLength = 8 + strlen(fileName) + 1;
633 UCHAR* buffer = new UCHAR[totalLength];
635 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
636 *(unsigned long*)&buffer[4] = htonl(VDR_STREAMRECORDING);
637 strcpy((char*)&buffer[8], fileName);
640 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
642 unsigned int a = tcp->sendPacket(buffer, totalLength);
645 if (a != totalLength)
648 MUTEX_UNLOCK(&mutex);
654 MUTEX_UNLOCK(&mutex);
658 ULLONG lengthBytes = extractULLONG();
659 ULONG lengthFrames = extractULONG();
661 MUTEX_UNLOCK(&mutex);
663 Log::getInstance()->log("VDR", Log::DEBUG, "VDR said length is: %llu %lu", lengthBytes, lengthFrames);
665 *totalFrames = lengthFrames;
669 ULLONG VDR::positionFromFrameNumber(ULONG frameNumber)
671 unsigned long totalLength = 12;
672 UCHAR* buffer = new UCHAR[totalLength];
674 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
675 *(unsigned long*)&buffer[4] = htonl(VDR_POSFROMFRAME);
676 *(unsigned long*)&buffer[8] = htonl(frameNumber);
679 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
681 unsigned int a = tcp->sendPacket(buffer, totalLength);
684 if (a != totalLength)
687 MUTEX_UNLOCK(&mutex);
693 MUTEX_UNLOCK(&mutex);
697 ULLONG position = extractULLONG();
699 MUTEX_UNLOCK(&mutex);
701 Log::getInstance()->log("VDR", Log::DEBUG, "VDR said new position is: %llu", position);
706 ULONG VDR::frameNumberFromPosition(ULLONG position)
708 unsigned long totalLength = 16;
709 UCHAR* buffer = new UCHAR[totalLength];
711 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
712 *(unsigned long*)&buffer[4] = htonl(VDR_FRAMEFROMPOS);
713 *(ULLONG*)&buffer[8] = htonll(position);
716 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
718 unsigned int a = tcp->sendPacket(buffer, totalLength);
721 if (a != totalLength)
724 MUTEX_UNLOCK(&mutex);
730 MUTEX_UNLOCK(&mutex);
734 ULONG framenumber = extractULONG();
736 MUTEX_UNLOCK(&mutex);
738 Log::getInstance()->log("VDR", Log::DEBUG, "VDR said new framenumber is: %u", framenumber);
743 bool VDR::getNextIFrame(ULONG frameNumber, ULONG direction, ULLONG* rfilePosition, ULONG* rframeNumber, ULONG* rframeLength)
745 unsigned long totalLength = 16;
746 UCHAR* buffer = new UCHAR[totalLength];
748 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
749 *(unsigned long*)&buffer[4] = htonl(VDR_GETNEXTIFRAME);
750 *(unsigned long*)&buffer[8] = htonl(frameNumber);
751 *(unsigned long*)&buffer[12] = htonl(direction);
754 if (!connected) { MUTEX_UNLOCK(&mutex); return false; }
756 unsigned int a = tcp->sendPacket(buffer, totalLength);
759 if (a != totalLength)
762 MUTEX_UNLOCK(&mutex);
768 MUTEX_UNLOCK(&mutex);
774 Log::getInstance()->log("VDR", Log::DEBUG, "Detected getNextIFrame error");
776 MUTEX_UNLOCK(&mutex);
780 *rfilePosition = extractULLONG();
781 *rframeNumber = extractULONG();
782 *rframeLength = extractULONG();
785 MUTEX_UNLOCK(&mutex);
787 // Log::getInstance()->log("VDR", Log::DEBUG, "VDR GNIF said %llu %lu %lu", *rfilePosition, *rframeNumber, *rframeLength);
792 EventList* VDR::getChannelSchedule(ULONG number)
796 return getChannelSchedule(number, now, 24 * 60 * 60);
799 EventList* VDR::getChannelSchedule(ULONG number, time_t start, ULONG duration)
801 // retrieve event list (vector of events) from vdr within filter window. duration is in seconds
804 *(unsigned long*)&buffer[0] = htonl(16);
805 *(unsigned long*)&buffer[4] = htonl(VDR_GETCHANNELSCHEDULE);
806 *(unsigned long*)&buffer[8] = htonl(number);
807 *(unsigned long*)&buffer[12] = htonl(start);
808 *(unsigned long*)&buffer[16] = htonl(duration);
811 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
813 int a = tcp->sendPacket(buffer, 20);
818 MUTEX_UNLOCK(&mutex);
824 MUTEX_UNLOCK(&mutex);
828 // received a ulong(0) - schedules error in the plugin
832 MUTEX_UNLOCK(&mutex);
836 EventList* eventList = new EventList();
838 while (packetPos < packetLength)
840 Event* event = new Event();
841 event->id = extractULONG();
842 event->time = extractULONG();
843 event->duration = extractULONG();
844 event->title = extractString();
845 event->subtitle = extractString();
846 event->description = extractString();
847 eventList->push_back(event);
851 MUTEX_UNLOCK(&mutex);
853 Log::getInstance()->log("VDR", Log::DEBUG, "Success got to end of getChannelSchedule");
857 int VDR::configSave(char* section, char* key, const char* value)
859 ULONG totalLength = 8 + strlen(section) + strlen(key) + strlen(value) + 3; // 8 for headers, 3 for nulls
860 UCHAR* buffer = new UCHAR[totalLength];
862 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
863 *(unsigned long*)&buffer[4] = htonl(VDR_CONFIGSAVE);
866 strcpy((char*)&buffer[position], section);
867 position += strlen(section) + 1;
868 strcpy((char*)&buffer[position], key);
869 position += strlen(key) + 1;
870 strcpy((char*)&buffer[position], value);
873 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
875 unsigned int a = tcp->sendPacket(buffer, totalLength);
878 if (a != totalLength)
881 MUTEX_UNLOCK(&mutex);
887 MUTEX_UNLOCK(&mutex);
891 int toReturn = (int)extractULONG();
893 MUTEX_UNLOCK(&mutex);
898 char* VDR::configLoad(char* section, char* key)
900 ULONG totalLength = 8 + strlen(section) + strlen(key) + 2; // 8 for headers, 2 for nulls
901 UCHAR* buffer = new UCHAR[totalLength];
903 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
904 *(unsigned long*)&buffer[4] = htonl(VDR_CONFIGLOAD);
907 strcpy((char*)&buffer[position], section);
908 position += strlen(section) + 1;
909 strcpy((char*)&buffer[position], key);
912 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
914 unsigned int a = tcp->sendPacket(buffer, totalLength);
917 if (a != totalLength)
920 MUTEX_UNLOCK(&mutex);
926 MUTEX_UNLOCK(&mutex);
929 char* toReturn = extractString();
931 MUTEX_UNLOCK(&mutex);
936 RecTimerList* VDR::getRecTimersList()
940 *(unsigned long*)&buffer[0] = htonl(4);
941 *(unsigned long*)&buffer[4] = htonl(VDR_GETTIMERS);
944 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
946 int a = tcp->sendPacket(buffer, 8);
950 MUTEX_UNLOCK(&mutex);
958 MUTEX_UNLOCK(&mutex);
962 RecTimerList* recTimerList = new RecTimerList();
964 ULONG numTimers = extractULONG();
967 RecTimer* newRecTimer;
970 while (packetPos < packetLength)
972 newRecTimer = new RecTimer();
973 newRecTimer->active = extractULONG();
974 newRecTimer->recording = extractULONG();
975 newRecTimer->pending = extractULONG();
976 newRecTimer->priority = extractULONG();
977 newRecTimer->lifeTime = extractULONG();
978 newRecTimer->channelNumber = extractULONG();
979 newRecTimer->startTime = extractULONG();
980 newRecTimer->stopTime = extractULONG();
982 tempString = extractString();
983 newRecTimer->setFile(tempString);
986 recTimerList->push_back(newRecTimer);
987 Log::getInstance()->log("VDR", Log::DEBUG, "TL: %lu %lu %lu %lu %lu %lu %lu %lu %s",
988 newRecTimer->active, newRecTimer->recording, newRecTimer->pending, newRecTimer->priority, newRecTimer->lifeTime,
989 newRecTimer->channelNumber, newRecTimer->startTime, newRecTimer->stopTime, newRecTimer->getFile());
994 MUTEX_UNLOCK(&mutex);
996 sort(recTimerList->begin(), recTimerList->end(), RecTimerSorter());
1001 ULONG VDR::setEventTimer(char* timerString)
1003 unsigned long totalLength = 8 + strlen(timerString) + 1;
1004 UCHAR* buffer = new UCHAR[totalLength];
1006 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
1007 *(unsigned long*)&buffer[4] = htonl(VDR_SETTIMER);
1008 strcpy((char*)&buffer[8], timerString);
1011 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
1013 unsigned int a = tcp->sendPacket(buffer, totalLength);
1016 if (a != totalLength)
1019 MUTEX_UNLOCK(&mutex);
1025 MUTEX_UNLOCK(&mutex);
1029 ULONG toReturn = extractULONG();
1031 MUTEX_UNLOCK(&mutex);
1036 RecInfo* VDR::getRecInfo(char* fileName)
1038 unsigned long totalLength = 8 + strlen(fileName) + 1;
1039 UCHAR* buffer = new UCHAR[totalLength];
1041 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
1042 *(unsigned long*)&buffer[4] = htonl(VDR_GETRECINFO);
1043 strcpy((char*)&buffer[8], fileName);
1046 if (!connected) { MUTEX_UNLOCK(&mutex); return NULL; }
1048 unsigned int a = tcp->sendPacket(buffer, totalLength);
1051 if (a != totalLength)
1054 MUTEX_UNLOCK(&mutex);
1060 MUTEX_UNLOCK(&mutex);
1066 Log::getInstance()->log("VDR", Log::DEBUG, "Could not get rec info");
1068 MUTEX_UNLOCK(&mutex);
1072 TCP::dump(packet, packetLength);
1074 RecInfo* recInfo = new RecInfo();
1076 recInfo->timerStart = extractULONG();
1077 recInfo->timerEnd = extractULONG();
1078 recInfo->resumePoint = extractULONG();
1079 recInfo->summary = extractString();
1081 ULONG numComponents = extractULONG();
1084 recInfo->setNumComponents(numComponents);
1085 for (ULONG i = 0; i < numComponents; i++)
1087 recInfo->streams[i] = extractUCHAR();
1088 recInfo->types[i] = extractUCHAR();
1089 recInfo->languages[i] = extractString();
1090 recInfo->descriptions[i] = extractString();
1097 MUTEX_UNLOCK(&mutex);
1102 ULLONG VDR::rescanRecording(ULONG* totalFrames)
1104 unsigned long totalLength = 8;
1105 UCHAR* buffer = new UCHAR[totalLength];
1107 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
1108 *(unsigned long*)&buffer[4] = htonl(VDR_RESCANRECORDING);
1111 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
1113 unsigned int a = tcp->sendPacket(buffer, totalLength);
1116 if (a != totalLength)
1119 MUTEX_UNLOCK(&mutex);
1125 MUTEX_UNLOCK(&mutex);
1129 ULLONG lengthBytes = extractULLONG();
1130 ULONG lengthFrames = extractULONG();
1132 MUTEX_UNLOCK(&mutex);
1134 Log::getInstance()->log("VDR", Log::DEBUG, "VDR said length is: %llu %lu", lengthBytes, lengthFrames);
1136 *totalFrames = lengthFrames;
1140 MarkList* VDR::getMarks(char* fileName)
1142 unsigned long totalLength = 8 + strlen(fileName) + 1;
1143 UCHAR* buffer = new UCHAR[totalLength];
1145 *(unsigned long*)&buffer[0] = htonl(totalLength - 4);
1146 *(unsigned long*)&buffer[4] = htonl(VDR_GETMARKS);
1147 strcpy((char*)&buffer[8], fileName);
1150 if (!connected) { MUTEX_UNLOCK(&mutex); return 0; }
1152 unsigned int a = tcp->sendPacket(buffer, totalLength);
1155 if (a != totalLength)
1158 MUTEX_UNLOCK(&mutex);
1164 MUTEX_UNLOCK(&mutex);
1170 MUTEX_UNLOCK(&mutex);
1174 MarkList* markList = new MarkList();
1176 while (packetPos < packetLength)
1178 Mark* mark = new Mark();
1179 mark->pos = extractULONG();
1181 markList->push_back(mark);
1182 Log::getInstance()->log("VDR", Log::DEBUG, "Have added a mark to list. %lu", mark->pos);
1186 MUTEX_UNLOCK(&mutex);
1191 void VDR::getChannelPids(Channel* channel)
1195 *(unsigned long*)&buffer[0] = htonl(8);
1196 *(unsigned long*)&buffer[4] = htonl(VDR_GETCHANNELPIDS);
1197 *(unsigned long*)&buffer[8] = htonl(channel->number);
1200 if (!connected) { MUTEX_UNLOCK(&mutex); return ; }
1202 int a = tcp->sendPacket(buffer, 12);
1207 MUTEX_UNLOCK(&mutex);
1213 MUTEX_UNLOCK(&mutex);
1217 // Format of response
1225 channel->vpid = extractULONG();
1226 channel->numAPids = extractULONG();
1228 for (ULONG i = 0; i < channel->numAPids; i++)
1231 newapid.pid = extractULONG();
1232 newapid.name = extractString();
1233 channel->apids.push_back(newapid);
1237 MUTEX_UNLOCK(&mutex);