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