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