]> git.vomp.tv Git - vompclient.git/blob - vdr.h
Windows and endian updates
[vompclient.git] / vdr.h
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
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.
10
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.
15
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.
19 */
20
21 #ifndef VDR_H
22 #define VDR_H
23
24 #include <stdio.h>
25 #include <time.h>
26 #include <vector>
27 #include <algorithm>
28
29 #ifdef WIN32
30 #include "threadwin.h"
31 #else
32 #include "threadp.h"
33 #endif
34 #include "defines.h"
35 #include "rectimer.h"
36 #include "mark.h"
37 #include "media.h"
38 #include "eventdispatcher.h"
39 #include "i18n.h"
40
41 class TCP;
42 class Log;
43 class RecInfo;
44 class Event;
45 class Channel;
46 class VDR_RequestPacket;
47 class VDR_ResponsePacket;
48
49 using namespace std;
50
51 typedef vector<Event*> EventList;
52 typedef vector<Channel*> ChannelList;
53 typedef vector<RecTimer*> RecTimerList;
54
55 struct VDRServer
56 {
57   char* ip;
58   char* name;
59 };
60
61 struct RecTimerSorter     // : public binary_function<double, double, bool>
62 {
63   bool operator() (const RecTimer* a, const RecTimer* b)
64   {
65     return a->startTime < b->startTime;
66   }
67 };
68
69 struct ServerSorter
70 {
71   bool operator() (const VDRServer& a, const VDRServer& b)
72   {
73     if (strcmp(b.name, a.name) > 0) return true;
74     return false;
75   }
76 };
77
78 class RecMan;
79
80 class StreamReceiver
81 {
82   public:
83     virtual void streamReceive(void*, ULONG)=0;
84 };
85
86 class VDR_PacketReceiver : public EDReceiver // implementation in vdr.cc
87 {
88   public:
89     virtual bool call(void* userTag);
90
91   friend class VDR;
92   protected:
93 //    ULONG requestTime;
94     ULONG receiverChannel;
95     
96     // If receiverChannel == 1:
97     ULONG requestSerialNumber;      // set by RequestResponse, used in ed_cb_find
98     VDR_ResponsePacket* save_vresp; // set by ed_cb_call, used in RequestResponse
99         
100     // If receiverChannel == 2:
101     ULONG streamID;
102     StreamReceiver* streamReceiver;
103 };
104
105 class VDR : public Thread_TYPE, public EventDispatcher
106 {
107
108   public:
109     const static ULONG VIDEO = 1;
110     const static ULONG RADIO = 2;
111   
112     const static ULONG CHANNEL_REQUEST_RESPONSE = 1;
113     const static ULONG CHANNEL_STREAM = 2;
114   
115     VDR();
116     ~VDR();
117     static VDR* getInstance();
118
119     int init(int port);
120     int shutdown();
121
122     void findServers(vector<VDRServer>& servers);
123     void cancelFindingServer();
124     void setServerIP(char*);
125     void setReceiveWindow(size_t size);
126     int connect();
127     void disconnect();
128     bool isConnected() { return connected; }
129     ULONG getChannelNumberWidth() { return channelNumberWidth; }
130
131     // protocol functions
132     // for the following, if result == false then the connection has died
133     //  doLogin
134     //  getRecordingList
135     //  getChannelsList
136     //  getChannelSchedule
137     //  getRecTimersList
138     // isConnected can be called after the following to determine if still ok
139     //  deleteRecording
140     //  streamRecording
141     //  positionFromFrameNumber
142     //  streamChannel
143     //  getBlock
144     //  stopStreaming
145     //  configLoad
146     //  configSave
147     //  setEventTimer
148
149     int           doLogin();
150     bool          getRecordingsList(RecMan* recman);
151     RecInfo*      getRecInfo(char* fileName);
152     int           deleteRecording(char* fileName);
153     char*         moveRecording(char* fileName, char* newPath);
154     ULLONG        streamRecording(char* fileName, ULONG* lengthFrames);
155     ULLONG        positionFromFrameNumber(ULONG frameNumber);
156     ULONG         frameNumberFromPosition(ULLONG position);
157     bool          getNextIFrame(ULONG frameNumber, ULONG direction, ULLONG* rfilePosition, ULONG* rframeNumber, ULONG* rframeLength);
158                   // Direction: 0=backwards, 1=forwards
159     MarkList*     getMarks(char* fileName);
160     int           deleteTimer(RecTimer* delTimer);
161     ChannelList*  getChannelsList(ULONG type);
162     int           streamChannel(ULONG number, StreamReceiver*);
163     int           streamChannel(ULONG number);
164     void          getChannelPids(Channel* channel);
165     UCHAR*        getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived);
166                   //get image blocks separate - we can do this in parallel
167     UCHAR*        getImageBlock(ULONG position, UINT maxAmount, UINT* amountReceived);
168     int           stopStreaming();
169     EventList*    getChannelSchedule(ULONG number);
170     EventList*    getChannelSchedule(ULONG number, time_t start, ULONG duration);
171     int           configSave(const char* section, const char* key, const char* value);
172     char*         configLoad(const char* section, const char* key);
173     ULONG         setEventTimer(char* timerString);
174     RecTimerList* getRecTimersList();
175     /**
176       * ge a list of media entries
177       * if parent==NULL this is the configured base list
178       */
179     MediaList*    getMediaList(const char* parent=NULL,int mediaType=MEDIA_TYPE_ALL);
180     /**
181       * start loading a JPEG image
182       * return size, 0 if not found
183       */
184     ULONG         loadImage(const char * filename, ULONG xsize=0,ULONG ysize=0);
185
186     I18n::lang_code_list getLanguageList();
187     int           getLanguageContent(const string code, I18n::trans_table&);
188
189     // end protocol functions
190
191
192     // obselete
193     ULLONG     rescanRecording(ULONG* lengthFrames);                    // FIXME obselete
194
195
196
197   private:
198     static VDR* instance;
199
200     VDR_ResponsePacket* RequestResponse(VDR_RequestPacket* request);
201     UCHAR* getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived, ULONG cmd);
202     
203     Log* logger;
204     int initted;
205     int findingServer;
206     TCP* tcp;
207     int port;
208     char serverIP[16];
209     bool connected;
210     ULONG maxChannelNumber;
211     ULONG channelNumberWidth;
212
213     const static ULONG VDR_LOGIN               = 1;
214     const static ULONG VDR_GETRECORDINGLIST    = 2;
215     const static ULONG VDR_DELETERECORDING     = 3;
216     const static ULONG VDR_GETCHANNELLIST      = 5;
217     const static ULONG VDR_STREAMCHANNEL       = 6;
218     const static ULONG VDR_GETBLOCK            = 7;
219     const static ULONG VDR_STOPSTREAMING       = 8;
220     const static ULONG VDR_STREAMRECORDING     = 9;
221     const static ULONG VDR_GETCHANNELSCHEDULE  = 10;
222     const static ULONG VDR_CONFIGSAVE          = 11;
223     const static ULONG VDR_CONFIGLOAD          = 12;
224     const static ULONG VDR_RESCANRECORDING     = 13;  // FIXME obselete
225     const static ULONG VDR_GETTIMERS           = 14;
226     const static ULONG VDR_SETTIMER            = 15;
227     const static ULONG VDR_POSFROMFRAME        = 16;
228     const static ULONG VDR_FRAMEFROMPOS        = 17;
229     const static ULONG VDR_MOVERECORDING       = 18;
230     const static ULONG VDR_GETNEXTIFRAME       = 19;
231     const static ULONG VDR_GETRECINFO          = 20;
232     const static ULONG VDR_GETMARKS            = 21;
233     const static ULONG VDR_GETCHANNELPIDS      = 22;
234     const static ULONG VDR_DELETETIMER         = 23;
235     const static ULONG VDR_GETMEDIALIST        = 30;
236     const static ULONG VDR_GETIMAGE            = 31;
237     const static ULONG VDR_GETIMAGEBLOCK       = 32;
238     const static ULONG VDR_GETLANGUAGELIST     = 33;
239     const static ULONG VDR_GETLANGUAGECONTENT  = 34;
240
241   protected:
242   
243     // Thread
244     void threadMethod();
245     void threadPostStopCleanup() {};
246
247     // EventDispatcher
248     virtual bool ed_cb_find(EDReceiver* edr, void* userTag);
249 };
250
251 #endif
252
253 /*
254
255 index.vdr file format for video:
256
257 For every video frame:
258 {
259   File offset    4 bytes
260   Picture type   1 byte
261   File number    1 byte
262   Zero           2 bytes
263 }
264
265 Picture types:
266
267 #define NO_PICTURE 0
268 #define I_FRAME    1
269 #define P_FRAME    2
270 #define B_FRAME    3
271
272
273
274 Packet formats
275
276 Packet format for an RR channel request:
277
278 4 bytes = channel ID = 1 (request/response channel)
279 4 bytes = request ID (from serialNumber)
280 4 bytes = opcode
281 4 bytes = length of the rest of the packet
282 ? bytes = rest of packet. depends on packet
283
284
285 Packet format for an RR channel response:
286
287 4 bytes = channel ID = 1 (request/response channel)
288 4 bytes = request ID (from serialNumber)
289 4 bytes = length of the rest of the packet
290 ? bytes = rest of packet. depends on packet
291
292
293 Packet format for a stream packet:
294
295 4 bytes = channel ID = 2 (stream channel)
296 4 bytes = stream ID (from requestID)
297 4 bytes = length of the stream data (rest of packet)
298 ? bytes = stream data
299
300 */
301