]> git.vomp.tv Git - vompclient.git/blob - vdr.h
New player, ffwd/fbwd, iframe navigation stuff
[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 "recman.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
73 class VDR
74 {
75
76   public:
77     VDR();
78     ~VDR();
79     static VDR* getInstance();
80
81     int init(int port);
82     int shutdown();
83
84     void findServers(vector<VDRServer>& servers);
85     void cancelFindingServer();
86     void setServerIP(char*);
87     int connect();
88     void disconnect();
89     bool isConnected() { return connected; }
90     ULONG getResumePoint(char* fileName);  // uses configLoad
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     //  getRecordingSummary
103     //  deleteRecording
104     //  streamRecording
105     //  rescanRecording
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     char*      getRecordingSummary(char* fileName);
118     int        deleteRecording(char* fileName);
119     char*      moveRecording(char* fileName, char* newPath);
120     ULLONG     streamRecording(char* fileName, ULONG* lengthFrames);
121     ULLONG     rescanRecording(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
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   private:
146     static VDR* instance;
147     Log* logger;
148     int initted;
149     int findingServer;
150     TCP* tcp;
151     int port;
152     char serverIP[16];
153     bool connected;
154 #ifndef WIN32
155     pthread_mutex_t mutex;
156 #else
157     HANDLE mutex;
158 #endif
159
160     UCHAR* packet;
161     ULONG packetLength;
162     ULONG packetPos;
163
164     const static ULONG VDR_LOGIN               = 1;
165     const static ULONG VDR_GETRECORDINGLIST    = 2;
166     const static ULONG VDR_DELETERECORDING     = 3;
167     const static ULONG VDR_GETSUMMARY          = 4;
168     const static ULONG VDR_GETCHANNELLIST      = 5;
169     const static ULONG VDR_STREAMCHANNEL       = 6;
170     const static ULONG VDR_GETBLOCK            = 7;
171     const static ULONG VDR_STOPSTREAMING       = 8;
172     const static ULONG VDR_STREAMRECORDING     = 9;
173     const static ULONG VDR_GETCHANNELSCHEDULE  = 10;
174     const static ULONG VDR_CONFIGSAVE          = 11;
175     const static ULONG VDR_CONFIGLOAD          = 12;
176     const static ULONG VDR_RESCANRECORDING     = 13;
177     const static ULONG VDR_GETTIMERS           = 14;
178     const static ULONG VDR_SETTIMER            = 15;
179     const static ULONG VDR_POSFROMFRAME        = 16;
180     const static ULONG VDR_FRAMEFROMPOS        = 17;
181     const static ULONG VDR_MOVERECORDING       = 18;
182     const static ULONG VDR_GETNEXTIFRAME       = 19;
183
184     int  getPacket();
185     void freePacket();
186     int  serverError();
187     char*  extractString();
188     ULONG  extractULONG();
189     ULLONG extractULLONG();
190     long   extractLONG();
191 };
192
193 #endif
194