]> git.vomp.tv Git - vompclient.git/blob - vdr.h
Compile fix for MVP re: location change of hmsf
[vompclient.git] / vdr.h
1 /*
2     Copyright 2004-2019 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21
22 // FIXME - This and the protocol are overly complicated now. Sorry.
23 //         I'll clean it up in a couple of releases time...
24
25
26 #ifndef VDR_H
27 #define VDR_H
28
29 #include <stdio.h>
30 #include <time.h>
31 #include <vector>
32 #include <algorithm>
33
34 #include "threadsystem.h"
35
36 #include "defines.h"
37 #include "rectimer.h"
38 #include "mark.h"
39 #ifdef VOMP_MEDIAPLAYER
40 #include "mediaprovider.h"
41 #endif
42 #include "eventdispatcher.h"
43 #include "i18n.h"
44 #include "log.h"
45 #include "command.h"
46
47 class TCP;
48 class Log;
49 class RecInfo;
50 class Event;
51 class Channel;
52 class VDR_RequestPacket;
53 class VDR_ResponsePacket;
54 #ifdef VOMP_MEDIAPLAYER
55 class SerializeBuffer;
56 #endif
57 class MovieInfo;
58 class SeriesInfo;
59 class TVMediaInfo;
60
61
62 using namespace std;
63
64 typedef vector<Event*> EventList;
65 typedef vector<Channel*> ChannelList;
66 typedef vector<RecTimer*> RecTimerList;
67
68 struct VDRServer
69 {
70   char* ip;
71   char* name;
72   USHORT port;
73   ULONG version;
74 };
75
76 struct RecTimerSorter     // : public binary_function<double, double, bool>
77 {
78   bool operator() (const RecTimer* a, const RecTimer* b)
79   {
80     return a->startTime < b->startTime;
81   }
82 };
83
84 struct ServerSorter
85 {
86   bool operator() (const VDRServer& a, const VDRServer& b)
87   {
88     if (strcmp(b.name, a.name) > 0) return true;
89     return false;
90   }
91 };
92
93 class RecMan;
94
95 class StreamReceiver
96 {
97   public:
98     virtual void streamReceive(ULONG, void*, ULONG)=0;
99 };
100
101 class VDR_PacketReceiver : public EDReceiver // implementation in vdr.cc
102 {
103   public:
104     virtual void call(void* userTag, bool& r_deregisterEDR, bool& r_wakeThread, bool& r_deleteEDR);
105
106   friend class VDR;
107   protected:
108 //    ULONG requestTime;
109     ULONG receiverChannel;
110     
111     // If receiverChannel == 1:
112     ULONG requestSerialNumber;      // set by RequestResponse, used in ed_cb_find
113     VDR_ResponsePacket* save_vresp; // set by ed_cb_call, used in RequestResponse
114         
115     // If receiverChannel == 2:
116     ULONG streamID;
117     StreamReceiver* streamReceiver;
118 };
119
120 class VDR : public Thread_TYPE,
121 public EventDispatcher,
122 #ifdef VOMP_MEDIAPLAYER
123 public MediaProvider,
124 #endif
125 public ExternLogger
126 {
127
128   public:
129     const static ULONG VIDEO = 1;
130     const static ULONG RADIO = 2;
131   
132     const static ULONG CHANNEL_REQUEST_RESPONSE = 1;
133     const static ULONG CHANNEL_STREAM = 2;
134     const static ULONG CHANNEL_KEEPALIVE = 3;
135     const static ULONG CHANNEL_NETLOG = 4;
136     const static ULONG CHANNEL_TVMEDIA = 5;
137   
138     VDR();
139     ~VDR();
140     static VDR* getInstance();
141
142     int init(int port);
143     int shutdown();
144
145     void findServers(vector<VDRServer>& servers);
146     void cancelFindingServer();
147     void setServerIP(char*);
148     void setServerPort(USHORT);
149     void setReceiveWindow(size_t size);
150     int connect();
151     void disconnect();
152     bool isConnected() { return connected; }
153     ULONG getChannelNumberWidth() { return channelNumberWidth; }
154
155     void setVDRShutdown(bool doShutdown) { doVDRShutdown = doShutdown; }
156     void shutdownVDR();
157
158     // protocol functions
159     // for the following, if result == false then the connection has died
160     //  doLogin
161     //  getRecordingList
162     //  getChannelsList
163     //  getChannelSchedule
164     //  getRecTimersList
165     // isConnected can be called after the following to determine if still ok
166     //  deleteRecording
167     //  streamRecording
168     //  positionFromFrameNumber
169     //  streamChannel
170     //  getBlock
171     //  stopStreaming
172     //  configLoad
173     //  configSave
174     //  setEventTimer
175
176     int           doLogin(unsigned int* v_server_min, unsigned int* v_server_max, unsigned int* v_client,  ASLPrefList& list, int &subtitles);
177     bool          getRecordingsList(RecMan* recman);
178     RecInfo*      getRecInfo(char* fileName);
179     int           deleteRecording(char* fileName);
180     int           deleteRecResume(char* fileName);
181     char*         moveRecording(char* fileName, char* newPath);
182     ULLONG        streamRecording(char* fileName, ULONG* lengthFrames, bool* IsPesRecording);
183     ULLONG        positionFromFrameNumber(ULONG frameNumber);
184     ULONG         frameNumberFromPosition(ULLONG position);
185     bool          getNextIFrame(ULONG frameNumber, ULONG direction, ULLONG* rfilePosition, ULONG* rframeNumber, ULONG* rframeLength);
186                   // Direction: 0=backwards, 1=forwards
187     MarkList*     getMarks(char* fileName);
188     int           deleteTimer(RecTimer* delTimer);
189     ChannelList*  getChannelsList(ULONG type);
190     int           streamChannel(ULONG number, StreamReceiver*);
191     int           streamChannel(ULONG number);
192     void          getChannelPids(Channel* channel);
193     UCHAR*        getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived);
194                   //get image blocks separate - we can do this in parallel
195     int           stopStreaming();
196     EventList*    getChannelSchedule(ULONG number);
197     EventList*    getChannelSchedule(ULONG number, time_t start, ULONG duration);
198     int           configSave(const char* section, const char* key, const char* value);
199     char*         configLoad(const char* section, const char* key);
200     ULONG         setEventTimer(char* timerString);
201     RecTimerList* getRecTimersList();
202     bool          LogExtern(const char* buffer);
203     
204     bool setCharset(int charset); // 1 latin 2 UTF-8
205 #ifdef VOMP_MEDIAPLAYER
206     /**
207       * the MediaProvider functions
208       *
209       */
210     virtual MediaList* getRootList();
211     virtual MediaList* getMediaList(const MediaURI * parent);
212     virtual int        openMedium(ULONG channel,const MediaURI *uri,ULLONG * size, ULONG xsize,ULONG ysize);
213     virtual int getMediaBlock(ULONG channel, unsigned long long offset, unsigned long len, unsigned long * outlen,
214         unsigned char ** buffer);
215     virtual int getMediaInfo(ULONG channel, struct MediaInfo * result);
216     virtual int closeMediaChannel(ULONG channel);
217 #endif
218
219     //TV Scraper support
220     void getScraperEventType(char * fileName, int & movieID, int & seriesID, int & episodeID);
221     void getScraperEventType(UINT eventid, UINT channelid, int & movieID, int & seriesID, int & episodeID, int & epgImage);
222     MovieInfo *getScraperMovieInfo(int movieID);
223     SeriesInfo *getScraperSeriesInfo(int seriesID, int episodeID);
224     ULONG loadTVMedia(TVMediaInfo& tvmedia);
225     ULONG loadTVMediaRecThumb(TVMediaInfo& tvmedia);
226     ULONG loadTVMediaEventThumb(TVMediaInfo& tvmedia);
227     ULONG loadChannelLogo(TVMediaInfo& tvmedia);
228     void invalidateTVMedia(ULONG loadindex);
229
230
231     I18n::lang_code_list getLanguageList();
232     int           getLanguageContent(const string code, I18n::trans_table&);
233
234     // end protocol functions
235
236
237     // obselete
238     ULLONG     rescanRecording(ULONG* lengthFrames);                    // FIXME obselete
239
240
241
242   private:
243     static VDR* instance;
244
245     VDR_ResponsePacket* RequestResponse(VDR_RequestPacket* request);
246     UCHAR* getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived, ULONG cmd);
247     
248     void connectionDied();
249     bool sendKA(ULONG timeStamp);
250     
251     Log* logger;
252     int initted;
253     int findingServer;
254     TCP* tcp;
255     int port;
256     char serverIP[16];
257     USHORT serverPort;
258     bool connected;
259     ULONG maxChannelNumber;
260     bool doVDRShutdown;
261     ULONG channelNumberWidth;
262     VDR_PacketReceiver* TEMP_SINGLE_VDR_PR;
263
264 #ifdef VOMP_MEDIAPLAYER
265     ULONG providerId;
266     ULONG subRange;
267     SerializeBuffer * doRequestResponse(SerializeBuffer *in,int cmd);
268 #endif
269   protected:
270   
271     // Thread
272     void threadMethod();
273     void threadPostStopCleanup() {};
274
275     // EventDispatcher
276     virtual bool ed_cb_find(EDReceiver* edr, void* userTag);
277 };
278
279 #endif
280
281 /*
282
283 index.vdr file format for video:
284
285 For every video frame:
286 {
287   File offset    4 bytes
288   Picture type   1 byte
289   File number    1 byte
290   Zero           2 bytes
291 }
292
293 Picture types:
294
295 #define NO_PICTURE 0
296 #define I_FRAME    1
297 #define P_FRAME    2
298 #define B_FRAME    3
299
300
301
302 Packet formats
303
304 Packet format for an RR channel request:
305
306 4 bytes = channel ID = 1 (request/response channel)
307 4 bytes = request ID (from serialNumber)
308 4 bytes = opcode
309 4 bytes = length of the rest of the packet
310 ? bytes = rest of packet. depends on packet
311
312
313 Packet format for an RR channel response:
314
315 4 bytes = channel ID = 1 (request/response channel)
316 4 bytes = request ID (from serialNumber)
317 4 bytes = length of the rest of the packet
318 ? bytes = rest of packet. depends on packet
319
320
321 Packet format for a stream packet:
322
323 4 bytes = channel ID = 2 (stream channel)
324 4 bytes = stream ID (from requestID)
325 4 bytes = length of the stream data (rest of packet)
326 ? bytes = stream data
327
328 */
329