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