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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 // FIXME - This and the protocol are overly complicated now. Sorry.
23 // I'll clean it up in a couple of releases time...
35 #include "threadwin.h"
43 #include "eventdispatcher.h"
51 class VDR_RequestPacket;
52 class VDR_ResponsePacket;
56 typedef vector<Event*> EventList;
57 typedef vector<Channel*> ChannelList;
58 typedef vector<RecTimer*> RecTimerList;
66 struct RecTimerSorter // : public binary_function<double, double, bool>
68 bool operator() (const RecTimer* a, const RecTimer* b)
70 return a->startTime < b->startTime;
76 bool operator() (const VDRServer& a, const VDRServer& b)
78 if (strcmp(b.name, a.name) > 0) return true;
88 virtual void streamReceive(ULONG, void*, ULONG)=0;
91 class VDR_PacketReceiver : public EDReceiver // implementation in vdr.cc
94 virtual bool call(void* userTag);
99 ULONG receiverChannel;
101 // If receiverChannel == 1:
102 ULONG requestSerialNumber; // set by RequestResponse, used in ed_cb_find
103 VDR_ResponsePacket* save_vresp; // set by ed_cb_call, used in RequestResponse
105 // If receiverChannel == 2:
107 StreamReceiver* streamReceiver;
110 class VDR : public Thread_TYPE, public EventDispatcher
114 const static ULONG VIDEO = 1;
115 const static ULONG RADIO = 2;
117 const static ULONG CHANNEL_REQUEST_RESPONSE = 1;
118 const static ULONG CHANNEL_STREAM = 2;
119 const static ULONG CHANNEL_KEEPALIVE = 3;
123 static VDR* getInstance();
128 void findServers(vector<VDRServer>& servers);
129 void cancelFindingServer();
130 void setServerIP(char*);
131 void setReceiveWindow(size_t size);
134 bool isConnected() { return connected; }
135 ULONG getChannelNumberWidth() { return channelNumberWidth; }
137 // protocol functions
138 // for the following, if result == false then the connection has died
142 // getChannelSchedule
144 // isConnected can be called after the following to determine if still ok
147 // positionFromFrameNumber
156 bool getRecordingsList(RecMan* recman);
157 RecInfo* getRecInfo(char* fileName);
158 int deleteRecording(char* fileName);
159 char* moveRecording(char* fileName, char* newPath);
160 ULLONG streamRecording(char* fileName, ULONG* lengthFrames);
161 ULLONG positionFromFrameNumber(ULONG frameNumber);
162 ULONG frameNumberFromPosition(ULLONG position);
163 bool getNextIFrame(ULONG frameNumber, ULONG direction, ULLONG* rfilePosition, ULONG* rframeNumber, ULONG* rframeLength);
164 // Direction: 0=backwards, 1=forwards
165 MarkList* getMarks(char* fileName);
166 int deleteTimer(RecTimer* delTimer);
167 ChannelList* getChannelsList(ULONG type);
168 int streamChannel(ULONG number, StreamReceiver*);
169 int streamChannel(ULONG number);
170 void getChannelPids(Channel* channel);
171 UCHAR* getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived);
172 //get image blocks separate - we can do this in parallel
173 UCHAR* getImageBlock(ULONG position, UINT maxAmount, UINT* amountReceived);
175 EventList* getChannelSchedule(ULONG number);
176 EventList* getChannelSchedule(ULONG number, time_t start, ULONG duration);
177 int configSave(const char* section, const char* key, const char* value);
178 char* configLoad(const char* section, const char* key);
179 ULONG setEventTimer(char* timerString);
180 RecTimerList* getRecTimersList();
182 * ge a list of media entries
183 * if parent==NULL this is the configured base list
185 MediaList* getMediaList(const char* parent=NULL,int mediaType=MEDIA_TYPE_ALL);
187 * start loading a JPEG image
188 * return size, 0 if not found
190 ULONG loadImage(const char * filename, ULONG xsize=0,ULONG ysize=0);
192 I18n::lang_code_list getLanguageList();
193 int getLanguageContent(const string code, I18n::trans_table&);
195 // end protocol functions
199 ULLONG rescanRecording(ULONG* lengthFrames); // FIXME obselete
204 static VDR* instance;
206 VDR_ResponsePacket* RequestResponse(VDR_RequestPacket* request);
207 UCHAR* getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived, ULONG cmd);
209 void connectionDied();
210 bool sendKA(ULONG timeStamp);
219 ULONG maxChannelNumber;
220 ULONG channelNumberWidth;
222 VDR_PacketReceiver* TEMP_SINGLE_VDR_PR;
224 const static ULONG VDR_LOGIN = 1;
225 const static ULONG VDR_GETRECORDINGLIST = 2;
226 const static ULONG VDR_DELETERECORDING = 3;
227 const static ULONG VDR_GETCHANNELLIST = 5;
228 const static ULONG VDR_STREAMCHANNEL = 6;
229 const static ULONG VDR_GETBLOCK = 7;
230 const static ULONG VDR_STOPSTREAMING = 8;
231 const static ULONG VDR_STREAMRECORDING = 9;
232 const static ULONG VDR_GETCHANNELSCHEDULE = 10;
233 const static ULONG VDR_CONFIGSAVE = 11;
234 const static ULONG VDR_CONFIGLOAD = 12;
235 const static ULONG VDR_RESCANRECORDING = 13; // FIXME obselete
236 const static ULONG VDR_GETTIMERS = 14;
237 const static ULONG VDR_SETTIMER = 15;
238 const static ULONG VDR_POSFROMFRAME = 16;
239 const static ULONG VDR_FRAMEFROMPOS = 17;
240 const static ULONG VDR_MOVERECORDING = 18;
241 const static ULONG VDR_GETNEXTIFRAME = 19;
242 const static ULONG VDR_GETRECINFO = 20;
243 const static ULONG VDR_GETMARKS = 21;
244 const static ULONG VDR_GETCHANNELPIDS = 22;
245 const static ULONG VDR_DELETETIMER = 23;
246 const static ULONG VDR_GETMEDIALIST = 30;
247 const static ULONG VDR_GETIMAGE = 31;
248 const static ULONG VDR_GETIMAGEBLOCK = 32;
249 const static ULONG VDR_GETLANGUAGELIST = 33;
250 const static ULONG VDR_GETLANGUAGECONTENT = 34;
256 void threadPostStopCleanup() {};
259 virtual bool ed_cb_find(EDReceiver* edr, void* userTag);
266 index.vdr file format for video:
268 For every video frame:
287 Packet format for an RR channel request:
289 4 bytes = channel ID = 1 (request/response channel)
290 4 bytes = request ID (from serialNumber)
292 4 bytes = length of the rest of the packet
293 ? bytes = rest of packet. depends on packet
296 Packet format for an RR channel response:
298 4 bytes = channel ID = 1 (request/response channel)
299 4 bytes = request ID (from serialNumber)
300 4 bytes = length of the rest of the packet
301 ? bytes = rest of packet. depends on packet
304 Packet format for a stream packet:
306 4 bytes = channel ID = 2 (stream channel)
307 4 bytes = stream ID (from requestID)
308 4 bytes = length of the stream data (rest of packet)
309 ? bytes = stream data