]> git.vomp.tv Git - vompclient.git/blob - vdr.h
German 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #ifndef VDR_H
22 #define VDR_H
23
24 #include <stdio.h>
25 #include <time.h>
26 #ifndef WIN32
27   #include <pthread.h>
28 #else
29   //Find threading replacements
30 #endif
31 #include <vector>
32 #include <algorithm>
33
34 #include "defines.h"
35 #include "rectimer.h"
36 #include "mark.h"
37 #include "media.h"
38
39 class TCP;
40 class Log;
41 class RecInfo;
42 class Event;
43 class Channel;
44
45 using namespace std;
46
47 typedef vector<Event*> EventList;
48 typedef vector<Channel*> ChannelList;
49 typedef vector<RecTimer*> RecTimerList;
50
51 struct VDRServer
52 {
53   char* ip;
54   char* name;
55 };
56
57 struct RecTimerSorter     // : public binary_function<double, double, bool>
58 {
59   bool operator() (const RecTimer* a, const RecTimer* b)
60   {
61     return a->startTime < b->startTime;
62   }
63 };
64
65 struct ServerSorter
66 {
67   bool operator() (const VDRServer& a, const VDRServer& b)
68   {
69     if (strcmp(b.name, a.name) > 0) return true;
70     return false;
71   }
72 };
73
74 class RecMan;
75
76 class VDR
77 {
78
79   public:
80     VDR();
81     ~VDR();
82     static VDR* getInstance();
83
84     int init(int port);
85     int shutdown();
86
87     void findServers(vector<VDRServer>& servers);
88     void cancelFindingServer();
89     void setServerIP(char*);
90     int connect();
91     void disconnect();
92     bool isConnected() { return connected; }
93     ULONG getChannelNumberWidth() { return channelNumberWidth; }
94
95     void setReceiveWindow(size_t size);
96
97     // protocol functions
98     // for the following, if result == false then the connection has died
99     //  doLogin
100     //  getRecordingList
101     //  getChannelsList
102     //  getChannelSchedule
103     //  getRecTimersList
104     // isConnected can be called after the following to determine if still ok
105     //  deleteRecording
106     //  streamRecording
107     //  positionFromFrameNumber
108     //  streamChannel
109     //  getBlock
110     //  stopStreaming
111     //  configLoad
112     //  configSave
113     //  setEventTimer
114
115     int doLogin();
116
117     bool       getRecordingsList(RecMan* recman);
118     RecInfo*   getRecInfo(char* fileName);
119     int        deleteRecording(char* fileName);
120     char*      moveRecording(char* fileName, char* newPath);
121     ULLONG     streamRecording(char* fileName, ULONG* lengthFrames);
122     ULLONG     positionFromFrameNumber(ULONG frameNumber);
123     ULONG      frameNumberFromPosition(ULLONG position);
124     bool       getNextIFrame(ULONG frameNumber, ULONG direction, ULLONG* rfilePosition, ULONG* rframeNumber, ULONG* rframeLength);
125                // Direction: 0=backwards, 1=forwards
126     MarkList*  getMarks(char* fileName);
127     int        deleteTimer(RecTimer* delTimer);
128
129     ChannelList* getChannelsList(ULONG type);
130     int          streamChannel(ULONG number);
131     void         getChannelPids(Channel* channel);
132
133     UCHAR*     getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived);
134     //get image blocks separate - we can do this in parallel
135     UCHAR*     getImageBlock(ULONG position, UINT maxAmount, UINT* amountReceived);
136     int        stopStreaming();
137     EventList* getChannelSchedule(ULONG number);
138     EventList* getChannelSchedule(ULONG number, time_t start, ULONG duration);
139     int        configSave(const char* section, const char* key, const char* value);
140     char*      configLoad(const char* section, const char* key);
141     ULONG      setEventTimer(char* timerString);
142
143     RecTimerList* getRecTimersList();
144     /**
145       * ge a list of media entries
146       * if parent==NULL this is the configured base list
147       */
148     MediaList* getMediaList(const char* parent=NULL,int mediaType=MEDIA_TYPE_ALL);
149     /**
150       * start loading a JPEG image
151       * return size, 0 if not found
152       */
153     ULONG loadImage(const char * filename, ULONG xsize=0,ULONG ysize=0);
154
155     // end
156
157     const static ULONG VIDEO = 1;
158     const static ULONG RADIO = 2;
159
160
161
162
163     // obselete
164     ULLONG     rescanRecording(ULONG* lengthFrames);                    // FIXME obselete
165
166
167
168   private:
169     UCHAR*     getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived, ULONG cmd);
170     static VDR* instance;
171     Log* logger;
172     int initted;
173     int findingServer;
174     TCP* tcp;
175     int port;
176     char serverIP[16];
177     bool connected;
178
179     ULONG maxChannelNumber;
180     ULONG channelNumberWidth;
181
182 #ifndef WIN32
183     pthread_mutex_t mutex;
184 #else
185     HANDLE mutex;
186 #endif
187
188     UCHAR* packet;
189     ULONG packetLength;
190     ULONG packetPos;
191
192     const static ULONG VDR_LOGIN               = 1;
193     const static ULONG VDR_GETRECORDINGLIST    = 2;
194     const static ULONG VDR_DELETERECORDING     = 3;
195     const static ULONG VDR_GETCHANNELLIST      = 5;
196     const static ULONG VDR_STREAMCHANNEL       = 6;
197     const static ULONG VDR_GETBLOCK            = 7;
198     const static ULONG VDR_STOPSTREAMING       = 8;
199     const static ULONG VDR_STREAMRECORDING     = 9;
200     const static ULONG VDR_GETCHANNELSCHEDULE  = 10;
201     const static ULONG VDR_CONFIGSAVE          = 11;
202     const static ULONG VDR_CONFIGLOAD          = 12;
203     const static ULONG VDR_RESCANRECORDING     = 13;  // FIXME obselete
204     const static ULONG VDR_GETTIMERS           = 14;
205     const static ULONG VDR_SETTIMER            = 15;
206     const static ULONG VDR_POSFROMFRAME        = 16;
207     const static ULONG VDR_FRAMEFROMPOS        = 17;
208     const static ULONG VDR_MOVERECORDING       = 18;
209     const static ULONG VDR_GETNEXTIFRAME       = 19;
210     const static ULONG VDR_GETRECINFO          = 20;
211     const static ULONG VDR_GETMARKS            = 21;
212     const static ULONG VDR_GETCHANNELPIDS      = 22;
213     const static ULONG VDR_DELETETIMER         = 23;
214     const static ULONG VDR_GETMEDIALIST        = 30;
215     const static ULONG VDR_GETIMAGE            = 31;
216     const static ULONG VDR_GETIMAGEBLOCK       = 32;
217     int  getPacket();
218     void freePacket();
219     int  serverError();
220     char*  extractString();
221     UCHAR  extractUCHAR();
222     ULONG  extractULONG();
223     ULLONG extractULLONG();
224     long   extractLONG();
225 };
226
227 #endif
228
229 /*
230
231 index.vdr file format for video:
232
233 For every video frame:
234 {
235   File offset    4 bytes
236   Picture type   1 byte
237   File number    1 byte
238   Zero           2 bytes
239 }
240
241 Picture types:
242
243 #define NO_PICTURE 0
244 #define I_FRAME    1
245 #define P_FRAME    2
246 #define B_FRAME    3
247
248 */