2 Copyright 2004-2019 Chris Tallon
4 This file is part of VOMP.
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.
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.
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.
22 // FIXME - This and the protocol are overly complicated now. Sorry.
23 // I'll clean it up in a couple of releases time...
34 #include "threadsystem.h"
39 #ifdef VOMP_MEDIAPLAYER
40 #include "mediaprovider.h"
42 #include "eventdispatcher.h"
52 class VDR_RequestPacket;
53 class VDR_ResponsePacket;
54 #ifdef VOMP_MEDIAPLAYER
55 class SerializeBuffer;
61 typedef std::vector<Event*> EventList;
62 typedef std::vector<Channel*> ChannelList;
63 typedef std::vector<RecTimer*> RecTimerList;
73 struct RecTimerSorter // : public binary_function<double, double, bool>
75 bool operator() (const RecTimer* a, const RecTimer* b)
77 return a->startTime < b->startTime;
83 bool operator() (const VDRServer& a, const VDRServer& b)
85 if (strcmp(b.name, a.name) > 0) return true;
95 virtual void streamReceive(ULONG, void*, ULONG)=0;
98 class VDR_PacketReceiver : public EDReceiver // implementation in vdr.cc
101 virtual void call(void* userTag, bool& r_deregisterEDR, bool& r_wakeThread, bool& r_deleteEDR);
105 // ULONG requestTime;
106 ULONG receiverChannel;
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
112 // If receiverChannel == 2:
114 StreamReceiver* streamReceiver;
117 class VDR : public Thread_TYPE,
118 public EventDispatcher,
119 #ifdef VOMP_MEDIAPLAYER
120 public MediaProvider,
126 const static ULONG VIDEO = 1;
127 const static ULONG RADIO = 2;
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;
137 static VDR* getInstance();
142 void findServers(std::vector<VDRServer>& servers);
143 void cancelFindingServer();
144 void setServerIP(char*);
145 void setServerPort(USHORT);
146 void setReceiveWindow(size_t size);
149 bool isConnected() { return connected; }
150 ULONG getChannelNumberWidth() { return channelNumberWidth; }
152 void setVDRShutdown(bool doShutdown) { doVDRShutdown = doShutdown; }
155 // protocol functions
156 // for the following, if result == false then the connection has died
160 // getChannelSchedule
162 // isConnected can be called after the following to determine if still ok
165 // positionFromFrameNumber
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
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);
201 bool setCharset(int charset); // 1 latin 2 UTF-8
202 #ifdef VOMP_MEDIAPLAYER
204 * the MediaProvider functions
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);
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);
228 I18n::lang_code_list getLanguageList();
229 int getLanguageContent(const std::string code, I18n::trans_table&);
231 // end protocol functions
235 ULLONG rescanRecording(ULONG* lengthFrames); // FIXME obselete
240 static VDR* instance;
242 VDR_ResponsePacket* RequestResponse(VDR_RequestPacket* request);
243 UCHAR* getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived, ULONG cmd);
245 void connectionDied();
246 bool sendKA(ULONG timeStamp);
255 ULONG maxChannelNumber;
257 ULONG channelNumberWidth;
258 VDR_PacketReceiver* TEMP_SINGLE_VDR_PR;
260 #ifdef VOMP_MEDIAPLAYER
263 SerializeBuffer * doRequestResponse(SerializeBuffer *in,int cmd);
269 void threadPostStopCleanup() {};
272 virtual bool ed_cb_find(EDReceiver* edr, void* userTag);
279 index.vdr file format for video:
281 For every video frame:
300 Packet format for an RR channel request:
302 4 bytes = channel ID = 1 (request/response channel)
303 4 bytes = request ID (from serialNumber)
305 4 bytes = length of the rest of the packet
306 ? bytes = rest of packet. depends on packet
309 Packet format for an RR channel response:
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
317 Packet format for a stream packet:
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