]> git.vomp.tv Git - vompclient.git/blob - vdr.h
Cut marks support
[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 "log.h"
36 #include "dsock.h"
37 #include "tcp.h"
38 #include "channel.h"
39 #include "event.h"
40 #include "rectimer.h"
41 #include "recinfo.h"
42 #include "mark.h"
43
44 using namespace std;
45
46 typedef vector<Event*> EventList;
47 typedef vector<Channel*> ChannelList;
48 typedef vector<RecTimer*> RecTimerList;
49 typedef vector<Mark*> MarkList;
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
94     void setReceiveWindow(size_t size);
95
96     // protocol functions
97     // for the following, if result == false then the connection has died
98     //  doLogin
99     //  getRecordingList
100     //  getChannelsList
101     //  getChannelSchedule
102     //  getRecTimersList
103     // isConnected can be called after the following to determine if still ok
104     //  deleteRecording
105     //  streamRecording
106     //  positionFromFrameNumber
107     //  streamChannel
108     //  getBlock
109     //  stopStreaming
110     //  configLoad
111     //  configSave
112     //  setEventTimer
113
114     int doLogin();
115
116     bool       getRecordingsList(RecMan* recman);
117     RecInfo*   getRecInfo(char* fileName);
118     int        deleteRecording(char* fileName);
119     char*      moveRecording(char* fileName, char* newPath);
120     ULLONG     streamRecording(char* fileName, ULONG* lengthFrames);
121     ULLONG     positionFromFrameNumber(ULONG frameNumber);
122     ULONG      frameNumberFromPosition(ULLONG position);
123     bool       getNextIFrame(ULONG frameNumber, ULONG direction, ULLONG* rfilePosition, ULONG* rframeNumber, ULONG* rframeLength);
124                // Direction: 0=backwards, 1=forwards
125     MarkList*  getMarks(char* fileName);
126
127     ChannelList* getChannelsList(ULONG type);
128     int          streamChannel(ULONG number);
129
130     UCHAR*     getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived);
131     int        stopStreaming();
132     EventList* getChannelSchedule(ULONG number);
133     EventList* getChannelSchedule(ULONG number, time_t start, ULONG duration);
134     int        configSave(char* section, char* key, const char* value);
135     char*      configLoad(char* section, char* key);
136     ULONG      setEventTimer(char* timerString);
137
138     RecTimerList* getRecTimersList();
139
140     // end
141
142     const static ULONG VIDEO = 1;
143     const static ULONG RADIO = 2;
144
145
146
147
148     // obselete
149     ULLONG     rescanRecording(ULONG* lengthFrames);                    // FIXME obselete
150
151
152
153   private:
154     static VDR* instance;
155     Log* logger;
156     int initted;
157     int findingServer;
158     TCP* tcp;
159     int port;
160     char serverIP[16];
161     bool connected;
162 #ifndef WIN32
163     pthread_mutex_t mutex;
164 #else
165     HANDLE mutex;
166 #endif
167
168     UCHAR* packet;
169     ULONG packetLength;
170     ULONG packetPos;
171
172     const static ULONG VDR_LOGIN               = 1;
173     const static ULONG VDR_GETRECORDINGLIST    = 2;
174     const static ULONG VDR_DELETERECORDING     = 3;
175     const static ULONG VDR_GETCHANNELLIST      = 5;
176     const static ULONG VDR_STREAMCHANNEL       = 6;
177     const static ULONG VDR_GETBLOCK            = 7;
178     const static ULONG VDR_STOPSTREAMING       = 8;
179     const static ULONG VDR_STREAMRECORDING     = 9;
180     const static ULONG VDR_GETCHANNELSCHEDULE  = 10;
181     const static ULONG VDR_CONFIGSAVE          = 11;
182     const static ULONG VDR_CONFIGLOAD          = 12;
183     const static ULONG VDR_RESCANRECORDING     = 13;  // FIXME obselete
184     const static ULONG VDR_GETTIMERS           = 14;
185     const static ULONG VDR_SETTIMER            = 15;
186     const static ULONG VDR_POSFROMFRAME        = 16;
187     const static ULONG VDR_FRAMEFROMPOS        = 17;
188     const static ULONG VDR_MOVERECORDING       = 18;
189     const static ULONG VDR_GETNEXTIFRAME       = 19;
190     const static ULONG VDR_GETRECINFO          = 20;
191     const static ULONG VDR_GETMARKS            = 21;
192
193     int  getPacket();
194     void freePacket();
195     int  serverError();
196     char*  extractString();
197     UCHAR  extractUCHAR();
198     ULONG  extractULONG();
199     ULLONG extractULLONG();
200     long   extractLONG();
201 };
202
203 #endif
204
205 /*
206
207 index.vdr file format for video:
208
209 For every video frame:
210 {
211   File offset    4 bytes
212   Picture type   1 byte
213   File number    1 byte
214   Zero           2 bytes
215 }
216
217 Picture types:
218
219 #define NO_PICTURE 0
220 #define I_FRAME    1
221 #define P_FRAME    2
222 #define B_FRAME    3
223
224 */