]> git.vomp.tv Git - vompclient.git/blob - vdr.h
Demuxer::scanForVideo()
[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
43 using namespace std;
44
45 typedef vector<Event*> EventList;
46 typedef vector<Channel*> ChannelList;
47 typedef vector<RecTimer*> RecTimerList;
48
49 struct VDRServer
50 {
51   char* ip;
52   char* name;
53 };
54
55 struct RecTimerSorter     // : public binary_function<double, double, bool>
56 {
57   bool operator() (const RecTimer* a, const RecTimer* b)
58   {
59     return a->startTime < b->startTime;
60   }
61 };
62
63 struct ServerSorter
64 {
65   bool operator() (const VDRServer& a, const VDRServer& b)
66   {
67     if (strcmp(b.name, a.name) > 0) return true;
68     return false;
69   }
70 };
71
72 class RecMan;
73
74 class VDR
75 {
76
77   public:
78     VDR();
79     ~VDR();
80     static VDR* getInstance();
81
82     int init(int port);
83     int shutdown();
84
85     void findServers(vector<VDRServer>& servers);
86     void cancelFindingServer();
87     void setServerIP(char*);
88     int connect();
89     void disconnect();
90     bool isConnected() { return connected; }
91
92     void setReceiveWindow(size_t size);
93
94     // protocol functions
95     // for the following, if result == false then the connection has died
96     //  doLogin
97     //  getRecordingList
98     //  getChannelsList
99     //  getChannelSchedule
100     //  getRecTimersList
101     // isConnected can be called after the following to determine if still ok
102     //  deleteRecording
103     //  streamRecording
104     //  positionFromFrameNumber
105     //  streamChannel
106     //  getBlock
107     //  stopStreaming
108     //  configLoad
109     //  configSave
110     //  setEventTimer
111
112     int doLogin();
113
114     bool       getRecordingsList(RecMan* recman);
115     RecInfo*   getRecInfo(char* fileName);
116     int        deleteRecording(char* fileName);
117     char*      moveRecording(char* fileName, char* newPath);
118     ULLONG     streamRecording(char* fileName, ULONG* lengthFrames);
119     ULLONG     positionFromFrameNumber(ULONG frameNumber);
120     ULONG      frameNumberFromPosition(ULLONG position);
121     bool       getNextIFrame(ULONG frameNumber, ULONG direction, ULLONG* rfilePosition, ULONG* rframeNumber, ULONG* rframeLength);
122                // Direction: 0=backwards, 1=forwards
123
124     ChannelList* getChannelsList(ULONG type);
125     int          streamChannel(ULONG number);
126
127     UCHAR*     getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived);
128     int        stopStreaming();
129     EventList* getChannelSchedule(ULONG number);
130     EventList* getChannelSchedule(ULONG number, time_t start, ULONG duration);
131     int        configSave(char* section, char* key, const char* value);
132     char*      configLoad(char* section, char* key);
133     ULONG      setEventTimer(char* timerString);
134
135     RecTimerList* getRecTimersList();
136
137     // end
138
139     const static ULONG VIDEO = 1;
140     const static ULONG RADIO = 2;
141
142
143
144
145     // obselete
146     ULLONG     rescanRecording(ULONG* lengthFrames);                    // FIXME obselete
147
148
149
150   private:
151     static VDR* instance;
152     Log* logger;
153     int initted;
154     int findingServer;
155     TCP* tcp;
156     int port;
157     char serverIP[16];
158     bool connected;
159 #ifndef WIN32
160     pthread_mutex_t mutex;
161 #else
162     HANDLE mutex;
163 #endif
164
165     UCHAR* packet;
166     ULONG packetLength;
167     ULONG packetPos;
168
169     const static ULONG VDR_LOGIN               = 1;
170     const static ULONG VDR_GETRECORDINGLIST    = 2;
171     const static ULONG VDR_DELETERECORDING     = 3;
172     const static ULONG VDR_GETCHANNELLIST      = 5;
173     const static ULONG VDR_STREAMCHANNEL       = 6;
174     const static ULONG VDR_GETBLOCK            = 7;
175     const static ULONG VDR_STOPSTREAMING       = 8;
176     const static ULONG VDR_STREAMRECORDING     = 9;
177     const static ULONG VDR_GETCHANNELSCHEDULE  = 10;
178     const static ULONG VDR_CONFIGSAVE          = 11;
179     const static ULONG VDR_CONFIGLOAD          = 12;
180     const static ULONG VDR_RESCANRECORDING     = 13;  // FIXME obselete
181     const static ULONG VDR_GETTIMERS           = 14;
182     const static ULONG VDR_SETTIMER            = 15;
183     const static ULONG VDR_POSFROMFRAME        = 16;
184     const static ULONG VDR_FRAMEFROMPOS        = 17;
185     const static ULONG VDR_MOVERECORDING       = 18;
186     const static ULONG VDR_GETNEXTIFRAME       = 19;
187     const static ULONG VDR_GETRECINFO          = 20;
188
189     int  getPacket();
190     void freePacket();
191     int  serverError();
192     char*  extractString();
193     UCHAR  extractUCHAR();
194     ULONG  extractULONG();
195     ULLONG extractULLONG();
196     long   extractLONG();
197 };
198
199 #endif
200
201 /*
202
203 index.vdr file format for video:
204
205 For every video frame:
206 {
207   File offset    4 bytes
208   Picture type   1 byte
209   File number    1 byte
210   Zero           2 bytes
211 }
212
213 Picture types:
214
215 #define NO_PICTURE 0
216 #define I_FRAME    1
217 #define P_FRAME    2
218 #define B_FRAME    3
219
220 */