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...
34 #include "threadsystem.h"
39 #include "mediaprovider.h"
40 #include "eventdispatcher.h"
49 class VDR_RequestPacket;
50 class VDR_ResponsePacket;
51 class SerializeBuffer;
55 typedef vector<Event*> EventList;
56 typedef vector<Channel*> ChannelList;
57 typedef vector<RecTimer*> RecTimerList;
67 struct RecTimerSorter // : public binary_function<double, double, bool>
69 bool operator() (const RecTimer* a, const RecTimer* b)
71 return a->startTime < b->startTime;
77 bool operator() (const VDRServer& a, const VDRServer& b)
79 if (strcmp(b.name, a.name) > 0) return true;
89 virtual void streamReceive(ULONG, void*, ULONG)=0;
92 class VDR_PacketReceiver : public EDReceiver // implementation in vdr.cc
95 virtual bool call(void* userTag);
100 ULONG receiverChannel;
102 // If receiverChannel == 1:
103 ULONG requestSerialNumber; // set by RequestResponse, used in ed_cb_find
104 VDR_ResponsePacket* save_vresp; // set by ed_cb_call, used in RequestResponse
106 // If receiverChannel == 2:
108 StreamReceiver* streamReceiver;
111 class VDR : public Thread_TYPE, public EventDispatcher, public MediaProvider, public ExternLogger
115 const static ULONG VIDEO = 1;
116 const static ULONG RADIO = 2;
118 const static ULONG CHANNEL_REQUEST_RESPONSE = 1;
119 const static ULONG CHANNEL_STREAM = 2;
120 const static ULONG CHANNEL_KEEPALIVE = 3;
121 const static ULONG CHANNEL_NETLOG = 4;
125 static VDR* getInstance();
130 void findServers(vector<VDRServer>& servers);
131 void cancelFindingServer();
132 void setServerIP(char*);
133 void setServerPort(USHORT);
134 void setReceiveWindow(size_t size);
137 bool isConnected() { return connected; }
138 ULONG getChannelNumberWidth() { return channelNumberWidth; }
140 // protocol functions
141 // for the following, if result == false then the connection has died
145 // getChannelSchedule
147 // isConnected can be called after the following to determine if still ok
150 // positionFromFrameNumber
158 int doLogin(unsigned int* v_server,unsigned int* v_client);
159 bool getRecordingsList(RecMan* recman);
160 RecInfo* getRecInfo(char* fileName);
161 int deleteRecording(char* fileName);
162 char* moveRecording(char* fileName, char* newPath);
163 ULLONG streamRecording(char* fileName, ULONG* lengthFrames, bool* IsPesRecording);
164 ULLONG positionFromFrameNumber(ULONG frameNumber);
165 ULONG frameNumberFromPosition(ULLONG position);
166 bool getNextIFrame(ULONG frameNumber, ULONG direction, ULLONG* rfilePosition, ULONG* rframeNumber, ULONG* rframeLength);
167 // Direction: 0=backwards, 1=forwards
168 MarkList* getMarks(char* fileName);
169 int deleteTimer(RecTimer* delTimer);
170 ChannelList* getChannelsList(ULONG type);
171 int streamChannel(ULONG number, StreamReceiver*);
172 int streamChannel(ULONG number);
173 void getChannelPids(Channel* channel);
174 UCHAR* getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived);
175 //get image blocks separate - we can do this in parallel
177 EventList* getChannelSchedule(ULONG number);
178 EventList* getChannelSchedule(ULONG number, time_t start, ULONG duration);
179 int configSave(const char* section, const char* key, const char* value);
180 char* configLoad(const char* section, const char* key);
181 ULONG setEventTimer(char* timerString);
182 RecTimerList* getRecTimersList();
183 bool LogExtern(const char* buffer);
185 bool setCharset(int charset); // 1 latin 2 UTF-8
188 * the MediaProvider functions
191 virtual MediaList* getRootList();
192 virtual MediaList* getMediaList(const MediaURI * parent);
193 virtual int openMedium(ULONG channel,const MediaURI *uri,ULLONG * size, ULONG xsize,ULONG ysize);
194 virtual int getMediaBlock(ULONG channel, unsigned long long offset, unsigned long len, unsigned long * outlen,
195 unsigned char ** buffer);
196 virtual int getMediaInfo(ULONG channel, struct MediaInfo * result);
197 virtual int closeMediaChannel(ULONG channel);
200 I18n::lang_code_list getLanguageList();
201 int getLanguageContent(const string code, I18n::trans_table&);
203 // end protocol functions
207 ULLONG rescanRecording(ULONG* lengthFrames); // FIXME obselete
212 static VDR* instance;
214 VDR_ResponsePacket* RequestResponse(VDR_RequestPacket* request);
215 UCHAR* getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived, ULONG cmd);
217 void connectionDied();
218 bool sendKA(ULONG timeStamp);
228 ULONG maxChannelNumber;
229 ULONG channelNumberWidth;
230 VDR_PacketReceiver* TEMP_SINGLE_VDR_PR;
235 SerializeBuffer * doRequestResponse(SerializeBuffer *in,int cmd);
240 void threadPostStopCleanup() {};
243 virtual bool ed_cb_find(EDReceiver* edr, void* userTag);
250 index.vdr file format for video:
252 For every video frame:
271 Packet format for an RR channel request:
273 4 bytes = channel ID = 1 (request/response channel)
274 4 bytes = request ID (from serialNumber)
276 4 bytes = length of the rest of the packet
277 ? bytes = rest of packet. depends on packet
280 Packet format for an RR channel response:
282 4 bytes = channel ID = 1 (request/response channel)
283 4 bytes = request ID (from serialNumber)
284 4 bytes = length of the rest of the packet
285 ? bytes = rest of packet. depends on packet
288 Packet format for a stream packet:
290 4 bytes = channel ID = 2 (stream channel)
291 4 bytes = stream ID (from requestID)
292 4 bytes = length of the stream data (rest of packet)
293 ? bytes = stream data