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