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