2 Copyright 2004-2020 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...
40 #ifdef VOMP_MEDIAPLAYER
41 #include "mediaprovider.h"
43 #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;
65 // Subclass vector to add custom delete behaviour for the contents
66 class ChannelList : public std::vector<Channel*>
71 for (Channel* p : *this) delete p;
75 struct RecTimerSorter // : public binary_function<double, double, bool>
77 bool operator() (const RecTimer* a, const RecTimer* b)
79 return a->startTime < b->startTime;
86 virtual void streamReceive(ULONG, void*, ULONG)=0;
89 class VDR_PacketReceiver : public EDReceiver // implementation in vdr.cc
92 virtual void call(void* userTag, bool& r_deregisterEDR, bool& r_wakeThread, bool& r_deleteEDR);
97 ULONG receiverChannel;
99 // If receiverChannel == 1:
100 ULONG requestSerialNumber; // set by RequestResponse, used in ed_cb_find
101 VDR_ResponsePacket* save_vresp; // set by ed_cb_call, used in RequestResponse
103 // If receiverChannel == 2:
105 StreamReceiver* streamReceiver;
110 class VDR : public EventDispatcher,
111 #ifdef VOMP_MEDIAPLAYER
112 public MediaProvider,
118 const static ULONG VIDEO = 1;
119 const static ULONG RADIO = 2;
121 const static ULONG CHANNEL_REQUEST_RESPONSE = 1;
122 const static ULONG CHANNEL_STREAM = 2;
123 const static ULONG CHANNEL_KEEPALIVE = 3;
124 const static ULONG CHANNEL_NETLOG = 4;
125 const static ULONG CHANNEL_TVMEDIA = 5;
129 static VDR* getInstance();
135 void findServers(std::vector<VDRServer>& servers);
136 void cancelFindingServer();
139 void setServerIP(const char*);
140 void setServerPort(USHORT);
141 void setReceiveWindow(size_t size);
144 void abortConnect(); // If there is one, force a running connect call to abort
145 bool isConnected() { return connected; }
146 int getChannelNumberWidth() { return channelNumberWidth; }
148 void setVDRShutdown(bool doShutdown) { doVDRShutdown = doShutdown; }
151 // protocol functions
152 // for the following, if result == false then the connection has died
156 // getChannelSchedule
158 // isConnected can be called after the following to determine if still ok
161 // positionFromFrameNumber
169 bool doLogin(unsigned int* v_server_min, unsigned int* v_server_max, unsigned int* v_client, ASLPrefList& list, int &subtitles);
170 bool getRecordingsList(RecMan* recman);
171 RecInfo* getRecInfo(char* fileName);
172 int deleteRecording(char* fileName);
173 int deleteRecResume(char* fileName);
174 char* moveRecording(char* fileName, char* newPath);
175 ULLONG streamRecording(char* fileName, ULONG* lengthFrames, bool* IsPesRecording);
176 ULLONG positionFromFrameNumber(ULONG frameNumber);
177 ULONG frameNumberFromPosition(ULLONG position);
178 bool getNextIFrame(ULONG frameNumber, ULONG direction, ULLONG* rfilePosition, ULONG* rframeNumber, ULONG* rframeLength);
179 // Direction: 0=backwards, 1=forwards
180 MarkList* getMarks(char* fileName);
181 int deleteTimer(RecTimer* delTimer);
182 std::shared_ptr<ChannelList> getChannelsList(ULONG type);
183 int streamChannel(ULONG number, StreamReceiver*);
184 int streamChannel(ULONG number);
185 void getChannelPids(Channel* channel);
186 UCHAR* getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived);
187 //get image blocks separate - we can do this in parallel
189 EventList* getChannelSchedule(ULONG number);
190 EventList* getChannelSchedule(ULONG number, time_t start, ULONG duration);
191 int configSave(const char* section, const char* key, const char* value);
192 char* configLoad(const char* section, const char* key);
193 ULONG setEventTimer(char* timerString);
194 RecTimerList* getRecTimersList();
195 bool LogExtern(const char* buffer);
197 bool setCharset(int charset); // 1 latin 2 UTF-8
198 #ifdef VOMP_MEDIAPLAYER
200 * the MediaProvider functions
203 virtual MediaList* getRootList();
204 virtual MediaList* getMediaList(const MediaURI * parent);
205 virtual int openMedium(ULONG channel,const MediaURI *uri,ULLONG * size, ULONG xsize,ULONG ysize);
206 virtual int getMediaBlock(ULONG channel, unsigned long long offset, unsigned long len, unsigned long * outlen,
207 unsigned char ** buffer);
208 virtual int getMediaInfo(ULONG channel, struct MediaInfo * result);
209 virtual int closeMediaChannel(ULONG channel);
213 void getScraperEventType(char * fileName, int & movieID, int & seriesID, int & episodeID);
214 void getScraperEventType(UINT eventid, UINT channelid, int & movieID, int & seriesID, int & episodeID, int & epgImage);
215 MovieInfo *getScraperMovieInfo(int movieID);
216 SeriesInfo *getScraperSeriesInfo(int seriesID, int episodeID);
217 ULONG loadTVMedia(TVMediaInfo& tvmedia);
218 ULONG loadTVMediaRecThumb(TVMediaInfo& tvmedia);
219 ULONG loadTVMediaEventThumb(TVMediaInfo& tvmedia);
220 ULONG loadChannelLogo(TVMediaInfo& tvmedia);
221 void invalidateTVMedia(ULONG loadindex);
224 I18n::lang_code_list getLanguageList();
225 int getLanguageContent(const std::string code, I18n::trans_table&);
227 // end protocol functions
231 ULLONG rescanRecording(ULONG* lengthFrames); // FIXME obselete
236 static VDR* instance;
238 VDR_ResponsePacket* RequestResponse(VDR_RequestPacket* request);
239 UCHAR* getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived, ULONG cmd);
241 void connectionDied();
242 bool sendKA(ULONG timeStamp);
250 ULONG maxChannelNumber{};
251 bool doVDRShutdown{};
252 int channelNumberWidth{1};
253 VDR_PacketReceiver* TEMP_SINGLE_VDR_PR;
255 std::mutex connectStateMutex; // FIXME improve this
257 bool disconnecting{};
258 bool babortConnect{};
261 std::mutex threadStartProtect;
262 std::thread vdrThread;
263 bool threadReqStop{};
265 #ifdef VOMP_MEDIAPLAYER
268 SerializeBuffer * doRequestResponse(SerializeBuffer *in,int cmd);
276 virtual bool ed_cb_find(EDReceiver* edr, void* userTag);
283 index.vdr file format for video:
285 For every video frame:
304 Packet format for an RR channel request:
306 4 bytes = channel ID = 1 (request/response channel)
307 4 bytes = request ID (from serialNumber)
309 4 bytes = length of the rest of the packet
310 ? bytes = rest of packet. depends on packet
313 Packet format for an RR channel response:
315 4 bytes = channel ID = 1 (request/response channel)
316 4 bytes = request ID (from serialNumber)
317 4 bytes = length of the rest of the packet
318 ? bytes = rest of packet. depends on packet
321 Packet format for a stream packet:
323 4 bytes = channel ID = 2 (stream channel)
324 4 bytes = stream ID (from requestID)
325 4 bytes = length of the stream data (rest of packet)
326 ? bytes = stream data