]> git.vomp.tv Git - vompclient.git/blob - vdr.h
Fix for possible crash when removing bar
[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     void         getChannelPids(Channel* channel);
130
131     UCHAR*     getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived);
132     int        stopStreaming();
133     EventList* getChannelSchedule(ULONG number);
134     EventList* getChannelSchedule(ULONG number, time_t start, ULONG duration);
135     int        configSave(char* section, char* key, const char* value);
136     char*      configLoad(char* section, char* key);
137     ULONG      setEventTimer(char* timerString);
138
139     RecTimerList* getRecTimersList();
140
141     // end
142
143     const static ULONG VIDEO = 1;
144     const static ULONG RADIO = 2;
145
146
147
148
149     // obselete
150     ULLONG     rescanRecording(ULONG* lengthFrames);                    // FIXME obselete
151
152
153
154   private:
155     static VDR* instance;
156     Log* logger;
157     int initted;
158     int findingServer;
159     TCP* tcp;
160     int port;
161     char serverIP[16];
162     bool connected;
163 #ifndef WIN32
164     pthread_mutex_t mutex;
165 #else
166     HANDLE mutex;
167 #endif
168
169     UCHAR* packet;
170     ULONG packetLength;
171     ULONG packetPos;
172
173     const static ULONG VDR_LOGIN               = 1;
174     const static ULONG VDR_GETRECORDINGLIST    = 2;
175     const static ULONG VDR_DELETERECORDING     = 3;
176     const static ULONG VDR_GETCHANNELLIST      = 5;
177     const static ULONG VDR_STREAMCHANNEL       = 6;
178     const static ULONG VDR_GETBLOCK            = 7;
179     const static ULONG VDR_STOPSTREAMING       = 8;
180     const static ULONG VDR_STREAMRECORDING     = 9;
181     const static ULONG VDR_GETCHANNELSCHEDULE  = 10;
182     const static ULONG VDR_CONFIGSAVE          = 11;
183     const static ULONG VDR_CONFIGLOAD          = 12;
184     const static ULONG VDR_RESCANRECORDING     = 13;  // FIXME obselete
185     const static ULONG VDR_GETTIMERS           = 14;
186     const static ULONG VDR_SETTIMER            = 15;
187     const static ULONG VDR_POSFROMFRAME        = 16;
188     const static ULONG VDR_FRAMEFROMPOS        = 17;
189     const static ULONG VDR_MOVERECORDING       = 18;
190     const static ULONG VDR_GETNEXTIFRAME       = 19;
191     const static ULONG VDR_GETRECINFO          = 20;
192     const static ULONG VDR_GETMARKS            = 21;
193     const static ULONG VDR_GETCHANNELPIDS      = 22;
194
195     int  getPacket();
196     void freePacket();
197     int  serverError();
198     char*  extractString();
199     UCHAR  extractUCHAR();
200     ULONG  extractULONG();
201     ULLONG extractULLONG();
202     long   extractLONG();
203 };
204
205 #endif
206
207 /*
208
209 index.vdr file format for video:
210
211 For every video frame:
212 {
213   File offset    4 bytes
214   Picture type   1 byte
215   File number    1 byte
216   Zero           2 bytes
217 }
218
219 Picture types:
220
221 #define NO_PICTURE 0
222 #define I_FRAME    1
223 #define P_FRAME    2
224 #define B_FRAME    3
225
226 */