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, see <https://www.gnu.org/licenses/>.
21 // FIXME - This and the protocol are overly complicated now. Sorry.
22 // I'll clean it up in a couple of releases time...
33 #include "threadsystem.h"
38 #ifdef VOMP_MEDIAPLAYER
39 #include "mediaprovider.h"
41 #include "eventdispatcher.h"
51 class VDR_RequestPacket;
52 class VDR_ResponsePacket;
53 #ifdef VOMP_MEDIAPLAYER
54 class SerializeBuffer;
60 typedef std::vector<Event*> EventList;
61 typedef std::vector<Channel*> ChannelList;
62 typedef std::vector<RecTimer*> RecTimerList;
72 struct RecTimerSorter // : public binary_function<double, double, bool>
74 bool operator() (const RecTimer* a, const RecTimer* b)
76 return a->startTime < b->startTime;
82 bool operator() (const VDRServer& a, const VDRServer& b)
84 if (strcmp(b.name, a.name) > 0) return true;
94 virtual void streamReceive(ULONG, void*, ULONG)=0;
97 class VDR_PacketReceiver : public EDReceiver // implementation in vdr.cc
100 virtual void call(void* userTag, bool& r_deregisterEDR, bool& r_wakeThread, bool& r_deleteEDR);
104 // ULONG requestTime;
105 ULONG receiverChannel;
107 // If receiverChannel == 1:
108 ULONG requestSerialNumber; // set by RequestResponse, used in ed_cb_find
109 VDR_ResponsePacket* save_vresp; // set by ed_cb_call, used in RequestResponse
111 // If receiverChannel == 2:
113 StreamReceiver* streamReceiver;
116 class VDR : public Thread_TYPE,
117 public EventDispatcher,
118 #ifdef VOMP_MEDIAPLAYER
119 public MediaProvider,
125 const static ULONG VIDEO = 1;
126 const static ULONG RADIO = 2;
128 const static ULONG CHANNEL_REQUEST_RESPONSE = 1;
129 const static ULONG CHANNEL_STREAM = 2;
130 const static ULONG CHANNEL_KEEPALIVE = 3;
131 const static ULONG CHANNEL_NETLOG = 4;
132 const static ULONG CHANNEL_TVMEDIA = 5;
136 static VDR* getInstance();
141 void findServers(std::vector<VDRServer>& servers);
142 void cancelFindingServer();
143 void setServerIP(char*);
144 void setServerPort(USHORT);
145 void setReceiveWindow(size_t size);
148 bool isConnected() { return connected; }
149 ULONG getChannelNumberWidth() { return channelNumberWidth; }
151 void setVDRShutdown(bool doShutdown) { doVDRShutdown = doShutdown; }
154 // protocol functions
155 // for the following, if result == false then the connection has died
159 // getChannelSchedule
161 // isConnected can be called after the following to determine if still ok
164 // positionFromFrameNumber
172 int doLogin(unsigned int* v_server_min, unsigned int* v_server_max, unsigned int* v_client, ASLPrefList& list, int &subtitles);
173 bool getRecordingsList(RecMan* recman);
174 RecInfo* getRecInfo(char* fileName);
175 int deleteRecording(char* fileName);
176 int deleteRecResume(char* fileName);
177 char* moveRecording(char* fileName, char* newPath);
178 ULLONG streamRecording(char* fileName, ULONG* lengthFrames, bool* IsPesRecording);
179 ULLONG positionFromFrameNumber(ULONG frameNumber);
180 ULONG frameNumberFromPosition(ULLONG position);
181 bool getNextIFrame(ULONG frameNumber, ULONG direction, ULLONG* rfilePosition, ULONG* rframeNumber, ULONG* rframeLength);
182 // Direction: 0=backwards, 1=forwards
183 MarkList* getMarks(char* fileName);
184 int deleteTimer(RecTimer* delTimer);
185 ChannelList* getChannelsList(ULONG type);
186 int streamChannel(ULONG number, StreamReceiver*);
187 int streamChannel(ULONG number);
188 void getChannelPids(Channel* channel);
189 UCHAR* getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived);
190 //get image blocks separate - we can do this in parallel
192 EventList* getChannelSchedule(ULONG number);
193 EventList* getChannelSchedule(ULONG number, time_t start, ULONG duration);
194 int configSave(const char* section, const char* key, const char* value);
195 char* configLoad(const char* section, const char* key);
196 ULONG setEventTimer(char* timerString);
197 RecTimerList* getRecTimersList();
198 bool LogExtern(const char* buffer);
200 bool setCharset(int charset); // 1 latin 2 UTF-8
201 #ifdef VOMP_MEDIAPLAYER
203 * the MediaProvider functions
206 virtual MediaList* getRootList();
207 virtual MediaList* getMediaList(const MediaURI * parent);
208 virtual int openMedium(ULONG channel,const MediaURI *uri,ULLONG * size, ULONG xsize,ULONG ysize);
209 virtual int getMediaBlock(ULONG channel, unsigned long long offset, unsigned long len, unsigned long * outlen,
210 unsigned char ** buffer);
211 virtual int getMediaInfo(ULONG channel, struct MediaInfo * result);
212 virtual int closeMediaChannel(ULONG channel);
216 void getScraperEventType(char * fileName, int & movieID, int & seriesID, int & episodeID);
217 void getScraperEventType(UINT eventid, UINT channelid, int & movieID, int & seriesID, int & episodeID, int & epgImage);
218 MovieInfo *getScraperMovieInfo(int movieID);
219 SeriesInfo *getScraperSeriesInfo(int seriesID, int episodeID);
220 ULONG loadTVMedia(TVMediaInfo& tvmedia);
221 ULONG loadTVMediaRecThumb(TVMediaInfo& tvmedia);
222 ULONG loadTVMediaEventThumb(TVMediaInfo& tvmedia);
223 ULONG loadChannelLogo(TVMediaInfo& tvmedia);
224 void invalidateTVMedia(ULONG loadindex);
227 I18n::lang_code_list getLanguageList();
228 int getLanguageContent(const std::string code, I18n::trans_table&);
230 // end protocol functions
234 ULLONG rescanRecording(ULONG* lengthFrames); // FIXME obselete
239 static VDR* instance;
241 VDR_ResponsePacket* RequestResponse(VDR_RequestPacket* request);
242 UCHAR* getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived, ULONG cmd);
244 void connectionDied();
245 bool sendKA(ULONG timeStamp);
254 ULONG maxChannelNumber{};
255 bool doVDRShutdown{};
256 ULONG channelNumberWidth{1};
257 VDR_PacketReceiver* TEMP_SINGLE_VDR_PR;
259 #ifdef VOMP_MEDIAPLAYER
262 SerializeBuffer * doRequestResponse(SerializeBuffer *in,int cmd);
270 virtual bool ed_cb_find(EDReceiver* edr, void* userTag);
277 index.vdr file format for video:
279 For every video frame:
298 Packet format for an RR channel request:
300 4 bytes = channel ID = 1 (request/response channel)
301 4 bytes = request ID (from serialNumber)
303 4 bytes = length of the rest of the packet
304 ? bytes = rest of packet. depends on packet
307 Packet format for an RR channel response:
309 4 bytes = channel ID = 1 (request/response channel)
310 4 bytes = request ID (from serialNumber)
311 4 bytes = length of the rest of the packet
312 ? bytes = rest of packet. depends on packet
315 Packet format for a stream packet:
317 4 bytes = channel ID = 2 (stream channel)
318 4 bytes = stream ID (from requestID)
319 4 bytes = length of the stream data (rest of packet)
320 ? bytes = stream data