]> git.vomp.tv Git - vompclient.git/blob - vdr.h
VConnect, VDRServer, VDR::findServers to std::strings
[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   std::string ip;
67   std::string name;
68   USHORT port;
69   ULONG version;
70
71   VDRServer(const std::string tip, const std::string tname, USHORT tport, ULONG tversion)
72   : ip(tip), name(tname), port(tport), version(tversion) {}
73 };
74
75 struct RecTimerSorter     // : public binary_function<double, double, bool>
76 {
77   bool operator() (const RecTimer* a, const RecTimer* b)
78   {
79     return a->startTime < b->startTime;
80   }
81 };
82
83 struct ServerSorter
84 {
85   bool operator() (const VDRServer& a, const VDRServer& b)
86   {
87     return a.name < b.name;
88   }
89 };
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 RecMan;
117
118 class VDR : public Thread_TYPE,
119 public EventDispatcher,
120 #ifdef VOMP_MEDIAPLAYER
121 public MediaProvider,
122 #endif
123 public ExternLogger
124 {
125
126   public:
127     const static ULONG VIDEO = 1;
128     const static ULONG RADIO = 2;
129   
130     const static ULONG CHANNEL_REQUEST_RESPONSE = 1;
131     const static ULONG CHANNEL_STREAM = 2;
132     const static ULONG CHANNEL_KEEPALIVE = 3;
133     const static ULONG CHANNEL_NETLOG = 4;
134     const static ULONG CHANNEL_TVMEDIA = 5;
135   
136     VDR();
137     ~VDR();
138     static VDR* getInstance();
139
140     int init();
141     int shutdown();
142
143     void findServers(std::vector<VDRServer>& servers);
144     void cancelFindingServer();
145     void setServerIP(const char*);
146     void setServerPort(USHORT);
147     void setReceiveWindow(size_t size);
148     int connect();
149     void disconnect();
150     bool isConnected() { return connected; }
151     ULONG getChannelNumberWidth() { return channelNumberWidth; }
152
153     void setVDRShutdown(bool doShutdown) { doVDRShutdown = doShutdown; }
154     void shutdownVDR();
155
156     // protocol functions
157     // for the following, if result == false then the connection has died
158     //  doLogin
159     //  getRecordingList
160     //  getChannelsList
161     //  getChannelSchedule
162     //  getRecTimersList
163     // isConnected can be called after the following to determine if still ok
164     //  deleteRecording
165     //  streamRecording
166     //  positionFromFrameNumber
167     //  streamChannel
168     //  getBlock
169     //  stopStreaming
170     //  configLoad
171     //  configSave
172     //  setEventTimer
173
174     int           doLogin(unsigned int* v_server_min, unsigned int* v_server_max, unsigned int* v_client,  ASLPrefList& list, int &subtitles);
175     bool          getRecordingsList(RecMan* recman);
176     RecInfo*      getRecInfo(char* fileName);
177     int           deleteRecording(char* fileName);
178     int           deleteRecResume(char* fileName);
179     char*         moveRecording(char* fileName, char* newPath);
180     ULLONG        streamRecording(char* fileName, ULONG* lengthFrames, bool* IsPesRecording);
181     ULLONG        positionFromFrameNumber(ULONG frameNumber);
182     ULONG         frameNumberFromPosition(ULLONG position);
183     bool          getNextIFrame(ULONG frameNumber, ULONG direction, ULLONG* rfilePosition, ULONG* rframeNumber, ULONG* rframeLength);
184                   // Direction: 0=backwards, 1=forwards
185     MarkList*     getMarks(char* fileName);
186     int           deleteTimer(RecTimer* delTimer);
187     ChannelList*  getChannelsList(ULONG type);
188     int           streamChannel(ULONG number, StreamReceiver*);
189     int           streamChannel(ULONG number);
190     void          getChannelPids(Channel* channel);
191     UCHAR*        getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived);
192                   //get image blocks separate - we can do this in parallel
193     int           stopStreaming();
194     EventList*    getChannelSchedule(ULONG number);
195     EventList*    getChannelSchedule(ULONG number, time_t start, ULONG duration);
196     int           configSave(const char* section, const char* key, const char* value);
197     char*         configLoad(const char* section, const char* key);
198     ULONG         setEventTimer(char* timerString);
199     RecTimerList* getRecTimersList();
200     bool          LogExtern(const char* buffer);
201     
202     bool setCharset(int charset); // 1 latin 2 UTF-8
203 #ifdef VOMP_MEDIAPLAYER
204     /**
205       * the MediaProvider functions
206       *
207       */
208     virtual MediaList* getRootList();
209     virtual MediaList* getMediaList(const MediaURI * parent);
210     virtual int        openMedium(ULONG channel,const MediaURI *uri,ULLONG * size, ULONG xsize,ULONG ysize);
211     virtual int getMediaBlock(ULONG channel, unsigned long long offset, unsigned long len, unsigned long * outlen,
212         unsigned char ** buffer);
213     virtual int getMediaInfo(ULONG channel, struct MediaInfo * result);
214     virtual int closeMediaChannel(ULONG channel);
215 #endif
216
217     //TV Scraper support
218     void getScraperEventType(char * fileName, int & movieID, int & seriesID, int & episodeID);
219     void getScraperEventType(UINT eventid, UINT channelid, int & movieID, int & seriesID, int & episodeID, int & epgImage);
220     MovieInfo *getScraperMovieInfo(int movieID);
221     SeriesInfo *getScraperSeriesInfo(int seriesID, int episodeID);
222     ULONG loadTVMedia(TVMediaInfo& tvmedia);
223     ULONG loadTVMediaRecThumb(TVMediaInfo& tvmedia);
224     ULONG loadTVMediaEventThumb(TVMediaInfo& tvmedia);
225     ULONG loadChannelLogo(TVMediaInfo& tvmedia);
226     void invalidateTVMedia(ULONG loadindex);
227
228
229     I18n::lang_code_list getLanguageList();
230     int           getLanguageContent(const std::string code, I18n::trans_table&);
231
232     // end protocol functions
233
234
235     // obselete
236     ULLONG     rescanRecording(ULONG* lengthFrames);                    // FIXME obselete
237
238
239
240   private:
241     static VDR* instance;
242
243     VDR_ResponsePacket* RequestResponse(VDR_RequestPacket* request);
244     UCHAR* getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived, ULONG cmd);
245     
246     void connectionDied();
247     bool sendKA(ULONG timeStamp);
248     
249     Log* logger;
250     int initted{};
251     int findingServer{};
252     TCP* tcp{};
253     char serverIP[40];
254     USHORT serverPort;
255     bool connected{};
256     ULONG maxChannelNumber{};
257     bool doVDRShutdown{};
258     ULONG channelNumberWidth{1};
259     VDR_PacketReceiver* TEMP_SINGLE_VDR_PR;
260
261 #ifdef VOMP_MEDIAPLAYER
262     ULONG providerId;
263     ULONG subRange;
264     SerializeBuffer * doRequestResponse(SerializeBuffer *in,int cmd);
265 #endif
266   protected:
267   
268     // Thread
269     void threadMethod();
270
271     // EventDispatcher
272     virtual bool ed_cb_find(EDReceiver* edr, void* userTag);
273 };
274
275 #endif
276
277 /*
278
279 index.vdr file format for video:
280
281 For every video frame:
282 {
283   File offset    4 bytes
284   Picture type   1 byte
285   File number    1 byte
286   Zero           2 bytes
287 }
288
289 Picture types:
290
291 #define NO_PICTURE 0
292 #define I_FRAME    1
293 #define P_FRAME    2
294 #define B_FRAME    3
295
296
297
298 Packet formats
299
300 Packet format for an RR channel request:
301
302 4 bytes = channel ID = 1 (request/response channel)
303 4 bytes = request ID (from serialNumber)
304 4 bytes = opcode
305 4 bytes = length of the rest of the packet
306 ? bytes = rest of packet. depends on packet
307
308
309 Packet format for an RR channel response:
310
311 4 bytes = channel ID = 1 (request/response channel)
312 4 bytes = request ID (from serialNumber)
313 4 bytes = length of the rest of the packet
314 ? bytes = rest of packet. depends on packet
315
316
317 Packet format for a stream packet:
318
319 4 bytes = channel ID = 2 (stream channel)
320 4 bytes = stream ID (from requestID)
321 4 bytes = length of the stream data (rest of packet)
322 ? bytes = stream data
323
324 */
325