]> git.vomp.tv Git - vompclient.git/blob - vdr.h
WOL 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 #include "wol.h"
44
45 using namespace std;
46
47 typedef vector<Event*> EventList;
48 typedef vector<Channel*> ChannelList;
49 typedef vector<RecTimer*> RecTimerList;
50 typedef vector<Mark*> MarkList;
51
52 struct VDRServer
53 {
54   char* ip;
55   char* name;
56 };
57
58 struct RecTimerSorter     // : public binary_function<double, double, bool>
59 {
60   bool operator() (const RecTimer* a, const RecTimer* b)
61   {
62     return a->startTime < b->startTime;
63   }
64 };
65
66 struct ServerSorter
67 {
68   bool operator() (const VDRServer& a, const VDRServer& b)
69   {
70     if (strcmp(b.name, a.name) > 0) return true;
71     return false;
72   }
73 };
74
75 class RecMan;
76
77 class VDR
78 {
79
80   public:
81     VDR();
82     ~VDR();
83     static VDR* getInstance();
84
85     int init(int port);
86     int shutdown();
87
88     void findServers(vector<VDRServer>& servers);
89     void cancelFindingServer();
90     void setServerIP(char*);
91     int connect();
92     void disconnect();
93     bool isConnected() { return connected; }
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
128     ChannelList* getChannelsList(ULONG type);
129     int          streamChannel(ULONG number);
130     void         getChannelPids(Channel* channel);
131
132     UCHAR*     getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived);
133     int        stopStreaming();
134     EventList* getChannelSchedule(ULONG number);
135     EventList* getChannelSchedule(ULONG number, time_t start, ULONG duration);
136     int        configSave(char* section, char* key, const char* value);
137     char*      configLoad(char* section, char* key);
138     ULONG      setEventTimer(char* timerString);
139
140     RecTimerList* getRecTimersList();
141
142     // end
143
144     const static ULONG VIDEO = 1;
145     const static ULONG RADIO = 2;
146
147
148
149
150     // obselete
151     ULLONG     rescanRecording(ULONG* lengthFrames);                    // FIXME obselete
152
153
154
155   private:
156     static VDR* instance;
157     Log* logger;
158     int initted;
159     int findingServer;
160     TCP* tcp;
161     int port;
162     char serverIP[16];
163     bool connected;
164 #ifndef WIN32
165     pthread_mutex_t mutex;
166 #else
167     HANDLE mutex;
168 #endif
169
170     UCHAR* packet;
171     ULONG packetLength;
172     ULONG packetPos;
173
174     const static ULONG VDR_LOGIN               = 1;
175     const static ULONG VDR_GETRECORDINGLIST    = 2;
176     const static ULONG VDR_DELETERECORDING     = 3;
177     const static ULONG VDR_GETCHANNELLIST      = 5;
178     const static ULONG VDR_STREAMCHANNEL       = 6;
179     const static ULONG VDR_GETBLOCK            = 7;
180     const static ULONG VDR_STOPSTREAMING       = 8;
181     const static ULONG VDR_STREAMRECORDING     = 9;
182     const static ULONG VDR_GETCHANNELSCHEDULE  = 10;
183     const static ULONG VDR_CONFIGSAVE          = 11;
184     const static ULONG VDR_CONFIGLOAD          = 12;
185     const static ULONG VDR_RESCANRECORDING     = 13;  // FIXME obselete
186     const static ULONG VDR_GETTIMERS           = 14;
187     const static ULONG VDR_SETTIMER            = 15;
188     const static ULONG VDR_POSFROMFRAME        = 16;
189     const static ULONG VDR_FRAMEFROMPOS        = 17;
190     const static ULONG VDR_MOVERECORDING       = 18;
191     const static ULONG VDR_GETNEXTIFRAME       = 19;
192     const static ULONG VDR_GETRECINFO          = 20;
193     const static ULONG VDR_GETMARKS            = 21;
194     const static ULONG VDR_GETCHANNELPIDS      = 22;
195
196     int  getPacket();
197     void freePacket();
198     int  serverError();
199     char*  extractString();
200     UCHAR  extractUCHAR();
201     ULONG  extractULONG();
202     ULLONG extractULLONG();
203     long   extractLONG();
204 };
205
206 #endif
207
208 /*
209
210 index.vdr file format for video:
211
212 For every video frame:
213 {
214   File offset    4 bytes
215   Picture type   1 byte
216   File number    1 byte
217   Zero           2 bytes
218 }
219
220 Picture types:
221
222 #define NO_PICTURE 0
223 #define I_FRAME    1
224 #define P_FRAME    2
225 #define B_FRAME    3
226
227 */