]> git.vomp.tv Git - vompclient.git/blob - vdr.h
Preparations for dynamic mode switching
[vompclient.git] / vdr.h
1 /*\r
2     Copyright 2004-2005 Chris Tallon\r
3 \r
4     This file is part of VOMP.\r
5 \r
6     VOMP is free software; you can redistribute it and/or modify\r
7     it under the terms of the GNU General Public License as published by\r
8     the Free Software Foundation; either version 2 of the License, or\r
9     (at your option) any later version.\r
10 \r
11     VOMP is distributed in the hope that it will be useful,\r
12     but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14     GNU General Public License for more details.\r
15 \r
16     You should have received a copy of the GNU General Public License\r
17     along with VOMP; if not, write to the Free Software\r
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.\r
19 */\r
20 \r
21 \r
22 // FIXME - This and the protocol are overly complicated now. Sorry.\r
23 //         I'll clean it up in a couple of releases time...\r
24 \r
25 \r
26 #ifndef VDR_H\r
27 #define VDR_H\r
28 \r
29 #include <stdio.h>\r
30 #include <time.h>\r
31 #include <vector>\r
32 #include <algorithm>\r
33 \r
34 #include "threadsystem.h"\r
35 \r
36 #include "defines.h"\r
37 #include "rectimer.h"\r
38 #include "mark.h"\r
39 #include "mediaprovider.h"\r
40 #include "eventdispatcher.h"\r
41 #include "i18n.h"\r
42 #include "log.h"\r
43 \r
44 class TCP;\r
45 class Log;\r
46 class RecInfo;\r
47 class Event;\r
48 class Channel;\r
49 class VDR_RequestPacket;\r
50 class VDR_ResponsePacket;\r
51 class SerializeBuffer;\r
52 \r
53 using namespace std;\r
54 \r
55 typedef vector<Event*> EventList;\r
56 typedef vector<Channel*> ChannelList;\r
57 typedef vector<RecTimer*> RecTimerList;\r
58 \r
59 struct VDRServer\r
60 {\r
61   char* ip;\r
62   char* name;\r
63 };\r
64 \r
65 struct RecTimerSorter     // : public binary_function<double, double, bool>\r
66 {\r
67   bool operator() (const RecTimer* a, const RecTimer* b)\r
68   {\r
69     return a->startTime < b->startTime;\r
70   }\r
71 };\r
72 \r
73 struct ServerSorter\r
74 {\r
75   bool operator() (const VDRServer& a, const VDRServer& b)\r
76   {\r
77     if (strcmp(b.name, a.name) > 0) return true;\r
78     return false;\r
79   }\r
80 };\r
81 \r
82 class RecMan;\r
83 \r
84 class StreamReceiver\r
85 {\r
86   public:\r
87     virtual void streamReceive(ULONG, void*, ULONG)=0;\r
88 };\r
89 \r
90 class VDR_PacketReceiver : public EDReceiver // implementation in vdr.cc\r
91 {\r
92   public:\r
93     virtual bool call(void* userTag);\r
94 \r
95   friend class VDR;\r
96   protected:\r
97 //    ULONG requestTime;\r
98     ULONG receiverChannel;\r
99     \r
100     // If receiverChannel == 1:\r
101     ULONG requestSerialNumber;      // set by RequestResponse, used in ed_cb_find\r
102     VDR_ResponsePacket* save_vresp; // set by ed_cb_call, used in RequestResponse\r
103         \r
104     // If receiverChannel == 2:\r
105     ULONG streamID;\r
106     StreamReceiver* streamReceiver;\r
107 };\r
108 \r
109 class VDR : public Thread_TYPE, public EventDispatcher, public MediaProvider, public ExternLogger\r
110 {\r
111 \r
112   public:\r
113     const static ULONG VIDEO = 1;\r
114     const static ULONG RADIO = 2;\r
115   \r
116     const static ULONG CHANNEL_REQUEST_RESPONSE = 1;\r
117     const static ULONG CHANNEL_STREAM = 2;\r
118     const static ULONG CHANNEL_KEEPALIVE = 3;\r
119     const static ULONG CHANNEL_NETLOG = 4;\r
120   \r
121     VDR();\r
122     ~VDR();\r
123     static VDR* getInstance();\r
124 \r
125     int init(int port);\r
126     int shutdown();\r
127 \r
128     void findServers(vector<VDRServer>& servers);\r
129     void cancelFindingServer();\r
130     void setServerIP(char*);\r
131     void setReceiveWindow(size_t size);\r
132     int connect();\r
133     void disconnect();\r
134     bool isConnected() { return connected; }\r
135     ULONG getChannelNumberWidth() { return channelNumberWidth; }\r
136 \r
137     // protocol functions\r
138     // for the following, if result == false then the connection has died\r
139     //  doLogin\r
140     //  getRecordingList\r
141     //  getChannelsList\r
142     //  getChannelSchedule\r
143     //  getRecTimersList\r
144     // isConnected can be called after the following to determine if still ok\r
145     //  deleteRecording\r
146     //  streamRecording\r
147     //  positionFromFrameNumber\r
148     //  streamChannel\r
149     //  getBlock\r
150     //  stopStreaming\r
151     //  configLoad\r
152     //  configSave\r
153     //  setEventTimer\r
154 \r
155     int           doLogin(unsigned int* v_server,unsigned int* v_client);\r
156     bool          getRecordingsList(RecMan* recman);\r
157     RecInfo*      getRecInfo(char* fileName);\r
158     int           deleteRecording(char* fileName);\r
159     char*         moveRecording(char* fileName, char* newPath);\r
160     ULLONG        streamRecording(char* fileName, ULONG* lengthFrames, bool* IsPesRecording);\r
161     ULLONG        positionFromFrameNumber(ULONG frameNumber);\r
162     ULONG         frameNumberFromPosition(ULLONG position);\r
163     bool          getNextIFrame(ULONG frameNumber, ULONG direction, ULLONG* rfilePosition, ULONG* rframeNumber, ULONG* rframeLength);\r
164                   // Direction: 0=backwards, 1=forwards\r
165     MarkList*     getMarks(char* fileName);\r
166     int           deleteTimer(RecTimer* delTimer);\r
167     ChannelList*  getChannelsList(ULONG type);\r
168     int           streamChannel(ULONG number, StreamReceiver*);\r
169     int           streamChannel(ULONG number);\r
170     void          getChannelPids(Channel* channel);\r
171     UCHAR*        getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived);\r
172                   //get image blocks separate - we can do this in parallel\r
173     int           stopStreaming();\r
174     EventList*    getChannelSchedule(ULONG number);\r
175     EventList*    getChannelSchedule(ULONG number, time_t start, ULONG duration);\r
176     int           configSave(const char* section, const char* key, const char* value);\r
177     char*         configLoad(const char* section, const char* key);\r
178     ULONG         setEventTimer(char* timerString);\r
179     RecTimerList* getRecTimersList();\r
180     bool          LogExtern(const char* buffer);\r
181     \r
182     bool setCharset(int charset); // 1 latin 2 UTF-8\r
183 \r
184     /**\r
185       * the MediaProvider functions\r
186       *\r
187       */\r
188     virtual MediaList* getRootList();\r
189     virtual MediaList* getMediaList(const MediaURI * parent);\r
190     virtual int        openMedium(ULONG channel,const MediaURI *uri,ULLONG * size, ULONG xsize,ULONG ysize);\r
191     virtual int getMediaBlock(ULONG channel, unsigned long long offset, unsigned long len, unsigned long * outlen,\r
192         unsigned char ** buffer);\r
193     virtual int getMediaInfo(ULONG channel, struct MediaInfo * result);\r
194     virtual int closeMediaChannel(ULONG channel);\r
195 \r
196 \r
197     I18n::lang_code_list getLanguageList();\r
198     int           getLanguageContent(const string code, I18n::trans_table&);\r
199 \r
200     // end protocol functions\r
201 \r
202 \r
203     // obselete\r
204     ULLONG     rescanRecording(ULONG* lengthFrames);                    // FIXME obselete\r
205 \r
206 \r
207 \r
208   private:\r
209     static VDR* instance;\r
210 \r
211     VDR_ResponsePacket* RequestResponse(VDR_RequestPacket* request);\r
212     UCHAR* getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived, ULONG cmd);\r
213     \r
214     void connectionDied();\r
215     bool sendKA(ULONG timeStamp);\r
216     \r
217     Log* logger;\r
218     int initted;\r
219     int findingServer;\r
220     TCP* tcp;\r
221     int port;\r
222     char serverIP[16];\r
223     bool connected;\r
224     ULONG maxChannelNumber;\r
225     ULONG channelNumberWidth;\r
226     VDR_PacketReceiver* TEMP_SINGLE_VDR_PR;\r
227 \r
228 \r
229     ULONG providerId;\r
230     ULONG subRange;\r
231     SerializeBuffer * doRequestResponse(SerializeBuffer *in,int cmd);\r
232   protected:\r
233   \r
234     // Thread\r
235     void threadMethod();\r
236     void threadPostStopCleanup() {};\r
237 \r
238     // EventDispatcher\r
239     virtual bool ed_cb_find(EDReceiver* edr, void* userTag);\r
240 };\r
241 \r
242 #endif\r
243 \r
244 /*\r
245 \r
246 index.vdr file format for video:\r
247 \r
248 For every video frame:\r
249 {\r
250   File offset    4 bytes\r
251   Picture type   1 byte\r
252   File number    1 byte\r
253   Zero           2 bytes\r
254 }\r
255 \r
256 Picture types:\r
257 \r
258 #define NO_PICTURE 0\r
259 #define I_FRAME    1\r
260 #define P_FRAME    2\r
261 #define B_FRAME    3\r
262 \r
263 \r
264 \r
265 Packet formats\r
266 \r
267 Packet format for an RR channel request:\r
268 \r
269 4 bytes = channel ID = 1 (request/response channel)\r
270 4 bytes = request ID (from serialNumber)\r
271 4 bytes = opcode\r
272 4 bytes = length of the rest of the packet\r
273 ? bytes = rest of packet. depends on packet\r
274 \r
275 \r
276 Packet format for an RR channel response:\r
277 \r
278 4 bytes = channel ID = 1 (request/response channel)\r
279 4 bytes = request ID (from serialNumber)\r
280 4 bytes = length of the rest of the packet\r
281 ? bytes = rest of packet. depends on packet\r
282 \r
283 \r
284 Packet format for a stream packet:\r
285 \r
286 4 bytes = channel ID = 2 (stream channel)\r
287 4 bytes = stream ID (from requestID)\r
288 4 bytes = length of the stream data (rest of packet)\r
289 ? bytes = stream data\r
290 \r
291 */\r
292 \r