]> git.vomp.tv Git - vompclient.git/blob - vdr.h
Screenshot support for vector based osd on raspberry pi
[vompclient.git] / vdr.h
1 /*
2     Copyright 2004-2005 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 "tvmedia.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
60
61 using namespace std;
62
63 typedef vector<Event*> EventList;
64 typedef vector<Channel*> ChannelList;
65 typedef vector<RecTimer*> RecTimerList;
66
67 struct VDRServer
68 {
69   char* ip;
70   char* name;
71   USHORT port;
72   ULONG version;
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     if (strcmp(b.name, a.name) > 0) return true;
88     return false;
89   }
90 };
91
92 class RecMan;
93
94 class StreamReceiver
95 {
96   public:
97     virtual void streamReceive(ULONG, void*, ULONG)=0;
98 };
99
100 class VDR_PacketReceiver : public EDReceiver // implementation in vdr.cc
101 {
102   public:
103     virtual bool call(void* userTag, bool & deleteme);
104
105   friend class VDR;
106   protected:
107 //    ULONG requestTime;
108     ULONG receiverChannel;
109     
110     // If receiverChannel == 1:
111     ULONG requestSerialNumber;      // set by RequestResponse, used in ed_cb_find
112     VDR_ResponsePacket* save_vresp; // set by ed_cb_call, used in RequestResponse
113         
114     // If receiverChannel == 2:
115     ULONG streamID;
116     StreamReceiver* streamReceiver;
117 };
118
119 class VDR : public Thread_TYPE,
120 public EventDispatcher,
121 #ifdef VOMP_MEDIAPLAYER
122 public MediaProvider,
123 #endif
124 public ExternLogger
125 {
126
127   public:
128     const static ULONG VIDEO = 1;
129     const static ULONG RADIO = 2;
130   
131     const static ULONG CHANNEL_REQUEST_RESPONSE = 1;
132     const static ULONG CHANNEL_STREAM = 2;
133     const static ULONG CHANNEL_KEEPALIVE = 3;
134     const static ULONG CHANNEL_NETLOG = 4;
135     const static ULONG CHANNEL_TVMEDIA = 5;
136   
137     VDR();
138     ~VDR();
139     static VDR* getInstance();
140
141     int init(int port);
142     int shutdown();
143
144     void findServers(vector<VDRServer>& servers);
145     void cancelFindingServer();
146     void setServerIP(char*);
147     void setServerPort(USHORT);
148     void setReceiveWindow(size_t size);
149     int connect();
150     void disconnect();
151     bool isConnected() { return connected; }
152     ULONG getChannelNumberWidth() { return channelNumberWidth; }
153
154     void setVDRShutdown(bool doShutdown) { doVDRShutdown = doShutdown; }
155     void shutdownVDR();
156
157     // protocol functions
158     // for the following, if result == false then the connection has died
159     //  doLogin
160     //  getRecordingList
161     //  getChannelsList
162     //  getChannelSchedule
163     //  getRecTimersList
164     // isConnected can be called after the following to determine if still ok
165     //  deleteRecording
166     //  streamRecording
167     //  positionFromFrameNumber
168     //  streamChannel
169     //  getBlock
170     //  stopStreaming
171     //  configLoad
172     //  configSave
173     //  setEventTimer
174
175     int           doLogin(unsigned int* v_server_min, unsigned int* v_server_max, unsigned int* v_client);
176     bool          getRecordingsList(RecMan* recman);
177     RecInfo*      getRecInfo(char* fileName);
178     int           deleteRecording(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);
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 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     int port;
254     char serverIP[16];
255     USHORT serverPort;
256     bool connected;
257     ULONG maxChannelNumber;
258     bool doVDRShutdown;
259     ULONG channelNumberWidth;
260     VDR_PacketReceiver* TEMP_SINGLE_VDR_PR;
261
262 #ifdef VOMP_MEDIAPLAYER
263     ULONG providerId;
264     ULONG subRange;
265     SerializeBuffer * doRequestResponse(SerializeBuffer *in,int cmd);
266 #endif
267   protected:
268   
269     // Thread
270     void threadMethod();
271     void threadPostStopCleanup() {};
272
273     // EventDispatcher
274     virtual bool ed_cb_find(EDReceiver* edr, void* userTag);
275 };
276
277 #endif
278
279 /*
280
281 index.vdr file format for video:
282
283 For every video frame:
284 {
285   File offset    4 bytes
286   Picture type   1 byte
287   File number    1 byte
288   Zero           2 bytes
289 }
290
291 Picture types:
292
293 #define NO_PICTURE 0
294 #define I_FRAME    1
295 #define P_FRAME    2
296 #define B_FRAME    3
297
298
299
300 Packet formats
301
302 Packet format for an RR channel request:
303
304 4 bytes = channel ID = 1 (request/response channel)
305 4 bytes = request ID (from serialNumber)
306 4 bytes = opcode
307 4 bytes = length of the rest of the packet
308 ? bytes = rest of packet. depends on packet
309
310
311 Packet format for an RR channel response:
312
313 4 bytes = channel ID = 1 (request/response channel)
314 4 bytes = request ID (from serialNumber)
315 4 bytes = length of the rest of the packet
316 ? bytes = rest of packet. depends on packet
317
318
319 Packet format for a stream packet:
320
321 4 bytes = channel ID = 2 (stream channel)
322 4 bytes = stream ID (from requestID)
323 4 bytes = length of the stream data (rest of packet)
324 ? bytes = stream data
325
326 */
327