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