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;
60 typedef std::vector<Event*> EventList;
61 typedef std::vector<Channel*> ChannelList;
62 typedef std::vector<RecTimer*> RecTimerList;
64 struct RecTimerSorter // : public binary_function<double, double, bool>
66 bool operator() (const RecTimer* a, const RecTimer* b)
68 return a->startTime < b->startTime;
75 virtual void streamReceive(u4, void*, u4)=0;
78 class VDR_PacketReceiver : public EDReceiver // implementation in vdr.cc
81 virtual void call(void* userTag, bool& r_deregisterEDR, bool& r_wakeThread, bool& r_deleteEDR);
88 // If receiverChannel == 1:
89 u4 requestSerialNumber; // set by RequestResponse, used in ed_cb_find
90 VDR_ResponsePacket* save_vresp; // set by ed_cb_call, used in RequestResponse
92 // If receiverChannel == 2:
94 StreamReceiver* streamReceiver;
99 class VDR : public EventDispatcher,
100 #ifdef VOMP_MEDIAPLAYER
101 public MediaProvider,
107 const static u4 VIDEO = 1;
108 const static u4 RADIO = 2;
110 const static u4 CHANNEL_REQUEST_RESPONSE = 1;
111 const static u4 CHANNEL_STREAM = 2;
112 const static u4 CHANNEL_KEEPALIVE = 3;
113 const static u4 CHANNEL_NETLOG = 4;
114 const static u4 CHANNEL_TVMEDIA = 5;
118 static VDR* getInstance();
124 void findServers(std::vector<VDRServer>& servers);
125 void cancelFindingServer();
128 void setServerIP(const char*);
129 void setServerPort(u2);
130 void setReceiveWindow(size_t size);
133 void abortConnect(); // If there is one, force a running connect call to abort
134 bool isConnected() { return connected; }
135 int getChannelNumberWidth() { return channelNumberWidth; }
137 void setVDRShutdown(bool doShutdown) { doVDRShutdown = doShutdown; }
140 // protocol functions
141 // for the following, if result == false then the connection has died
145 // getChannelSchedule
147 // isConnected can be called after the following to determine if still ok
150 // positionFromFrameNumber
158 bool doLogin(unsigned int* v_server_min, unsigned int* v_server_max, unsigned int* v_client, ASLPrefList& list, int &subtitles);
159 bool getRecordingsList(RecMan* recman);
160 RecInfo* getRecInfo(char* fileName);
161 int deleteRecording(char* fileName);
162 int deleteRecResume(char* fileName);
163 char* moveRecording(char* fileName, char* newPath);
164 u8 streamRecording(char* fileName, u4* lengthFrames, bool* IsPesRecording);
165 u8 positionFromFrameNumber(u4 frameNumber);
166 u4 frameNumberFromPosition(u8 position);
167 bool getNextIFrame(u4 frameNumber, u4 direction, u8* rfilePosition, u4* rframeNumber, u4* rframeLength);
168 // Direction: 0=backwards, 1=forwards
169 MarkList* getMarks(char* fileName);
170 int deleteTimer(RecTimer* delTimer);
171 std::shared_ptr<ChannelList> getChannelsList(u4 type);
172 int streamChannel(u4 number, StreamReceiver*);
173 int streamChannel(u4 number);
174 void getChannelPids(Channel* channel);
175 u1* getBlock(u8 position, u4 maxAmount, u4* amountReceived);
176 //get image blocks separate - we can do this in parallel
178 EventList* getChannelSchedule(u4 number);
179 EventList* getChannelSchedule(u4 number, time_t start, u4 duration);
180 int configSave(const char* section, const char* key, const char* value);
181 char* configLoad(const char* section, const char* key);
182 u4 setEventTimer(char* timerString);
183 RecTimerList* getRecTimersList();
184 bool LogExtern(const char* buffer);
186 bool setCharset(int charset); // 1 latin 2 UTF-8
187 #ifdef VOMP_MEDIAPLAYER
189 * the MediaProvider functions
192 virtual MediaList* getRootList();
193 virtual MediaList* getMediaList(const MediaURI * parent);
194 virtual int openMedium(u4 channel,const MediaURI *uri,u8 * size, u4 xsize,u4 ysize);
195 virtual int getMediaBlock(u4 channel, unsigned long long offset, unsigned long len, unsigned long * outlen,
196 unsigned char ** buffer);
197 virtual int getMediaInfo(u4 channel, struct MediaInfo * result);
198 virtual int closeMediaChannel(u4 channel);
202 void getScraperEventType(char * fileName, int & movieID, int & seriesID, int & episodeID);
203 void getScraperEventType(u4 eventid, u4 channelid, int & movieID, int & seriesID, int & episodeID, int & epgImage);
204 MovieInfo* getScraperMovieInfo(int movieID);
205 SeriesInfo* getScraperSeriesInfo(int seriesID, int episodeID);
207 bool loadImageGeneric(ImageGeneric& image);
208 bool loadImageRecThumb(ImageRecThumb& image);
209 bool loadImageEventThumb(ImageEventThumb& image);
210 bool loadImageChannelLogo(ImageChannelLogo& image);
212 I18n::lang_code_list getLanguageList();
213 int getLanguageContent(const std::string code, I18n::trans_table&);
215 // end protocol functions
219 u8 rescanRecording(u4* lengthFrames); // FIXME obselete
224 static VDR* instance;
226 VDR_ResponsePacket* RequestResponse(VDR_RequestPacket* request);
227 u1* getBlock(u8 position, u4 maxAmount, u4* amountReceived, u4 cmd);
229 void connectionDied();
230 bool sendKA(u4 timeStamp);
238 u4 maxChannelNumber{};
239 bool doVDRShutdown{};
240 int channelNumberWidth{1};
241 VDR_PacketReceiver* TEMP_SINGLE_VDR_PR;
243 std::mutex connectStateMutex; // FIXME improve this
245 bool disconnecting{};
246 bool babortConnect{};
249 std::mutex threadStartProtect;
250 std::thread vdrThread;
251 bool threadReqStop{};
253 #ifdef VOMP_MEDIAPLAYER
256 SerializeBuffer * doRequestResponse(SerializeBuffer *in,int cmd);
264 virtual bool ed_cb_find(EDReceiver* edr, void* userTag);
271 index.vdr file format for video:
273 For every video frame:
292 Packet format for an RR channel request:
294 4 bytes = channel ID = 1 (request/response channel)
295 4 bytes = request ID (from serialNumber)
297 4 bytes = length of the rest of the packet
298 ? bytes = rest of packet. depends on packet
301 Packet format for an RR channel response:
303 4 bytes = channel ID = 1 (request/response channel)
304 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 a stream packet:
311 4 bytes = channel ID = 2 (stream channel)
312 4 bytes = stream ID (from requestID)
313 4 bytes = length of the stream data (rest of packet)
314 ? bytes = stream data