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