2 Copyright 2004-2005 Chris Tallon
\r
4 This file is part of VOMP.
\r
6 VOMP is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 VOMP is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with VOMP; if not, write to the Free Software
\r
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
22 // FIXME - This and the protocol are overly complicated now. Sorry.
\r
23 // I'll clean it up in a couple of releases time...
\r
32 #include <algorithm>
\r
34 #include "threadsystem.h"
\r
36 #include "defines.h"
\r
37 #include "rectimer.h"
\r
39 #include "mediaprovider.h"
\r
40 #include "eventdispatcher.h"
\r
49 class VDR_RequestPacket;
\r
50 class VDR_ResponsePacket;
\r
51 class SerializeBuffer;
\r
53 using namespace std;
\r
55 typedef vector<Event*> EventList;
\r
56 typedef vector<Channel*> ChannelList;
\r
57 typedef vector<RecTimer*> RecTimerList;
\r
65 struct RecTimerSorter // : public binary_function<double, double, bool>
\r
67 bool operator() (const RecTimer* a, const RecTimer* b)
\r
69 return a->startTime < b->startTime;
\r
75 bool operator() (const VDRServer& a, const VDRServer& b)
\r
77 if (strcmp(b.name, a.name) > 0) return true;
\r
84 class StreamReceiver
\r
87 virtual void streamReceive(ULONG, void*, ULONG)=0;
\r
90 class VDR_PacketReceiver : public EDReceiver // implementation in vdr.cc
\r
93 virtual bool call(void* userTag);
\r
97 // ULONG requestTime;
\r
98 ULONG receiverChannel;
\r
100 // If receiverChannel == 1:
\r
101 ULONG requestSerialNumber; // set by RequestResponse, used in ed_cb_find
\r
102 VDR_ResponsePacket* save_vresp; // set by ed_cb_call, used in RequestResponse
\r
104 // If receiverChannel == 2:
\r
106 StreamReceiver* streamReceiver;
\r
109 class VDR : public Thread_TYPE, public EventDispatcher, public MediaProvider, public ExternLogger
\r
113 const static ULONG VIDEO = 1;
\r
114 const static ULONG RADIO = 2;
\r
116 const static ULONG CHANNEL_REQUEST_RESPONSE = 1;
\r
117 const static ULONG CHANNEL_STREAM = 2;
\r
118 const static ULONG CHANNEL_KEEPALIVE = 3;
\r
119 const static ULONG CHANNEL_NETLOG = 4;
\r
123 static VDR* getInstance();
\r
125 int init(int port);
\r
128 void findServers(vector<VDRServer>& servers);
\r
129 void cancelFindingServer();
\r
130 void setServerIP(char*);
\r
131 void setReceiveWindow(size_t size);
\r
134 bool isConnected() { return connected; }
\r
135 ULONG getChannelNumberWidth() { return channelNumberWidth; }
\r
137 // protocol functions
\r
138 // for the following, if result == false then the connection has died
\r
140 // getRecordingList
\r
142 // getChannelSchedule
\r
143 // getRecTimersList
\r
144 // isConnected can be called after the following to determine if still ok
\r
147 // positionFromFrameNumber
\r
155 int doLogin(unsigned int* v_server,unsigned int* v_client);
\r
156 bool getRecordingsList(RecMan* recman);
\r
157 RecInfo* getRecInfo(char* fileName);
\r
158 int deleteRecording(char* fileName);
\r
159 char* moveRecording(char* fileName, char* newPath);
\r
160 ULLONG streamRecording(char* fileName, ULONG* lengthFrames, bool* IsPesRecording);
\r
161 ULLONG positionFromFrameNumber(ULONG frameNumber);
\r
162 ULONG frameNumberFromPosition(ULLONG position);
\r
163 bool getNextIFrame(ULONG frameNumber, ULONG direction, ULLONG* rfilePosition, ULONG* rframeNumber, ULONG* rframeLength);
\r
164 // Direction: 0=backwards, 1=forwards
\r
165 MarkList* getMarks(char* fileName);
\r
166 int deleteTimer(RecTimer* delTimer);
\r
167 ChannelList* getChannelsList(ULONG type);
\r
168 int streamChannel(ULONG number, StreamReceiver*);
\r
169 int streamChannel(ULONG number);
\r
170 void getChannelPids(Channel* channel);
\r
171 UCHAR* getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived);
\r
172 //get image blocks separate - we can do this in parallel
\r
173 int stopStreaming();
\r
174 EventList* getChannelSchedule(ULONG number);
\r
175 EventList* getChannelSchedule(ULONG number, time_t start, ULONG duration);
\r
176 int configSave(const char* section, const char* key, const char* value);
\r
177 char* configLoad(const char* section, const char* key);
\r
178 ULONG setEventTimer(char* timerString);
\r
179 RecTimerList* getRecTimersList();
\r
180 bool LogExtern(const char* buffer);
\r
182 bool setCharset(int charset); // 1 latin 2 UTF-8
\r
185 * the MediaProvider functions
\r
188 virtual MediaList* getRootList();
\r
189 virtual MediaList* getMediaList(const MediaURI * parent);
\r
190 virtual int openMedium(ULONG channel,const MediaURI *uri,ULLONG * size, ULONG xsize,ULONG ysize);
\r
191 virtual int getMediaBlock(ULONG channel, unsigned long long offset, unsigned long len, unsigned long * outlen,
\r
192 unsigned char ** buffer);
\r
193 virtual int getMediaInfo(ULONG channel, struct MediaInfo * result);
\r
194 virtual int closeMediaChannel(ULONG channel);
\r
197 I18n::lang_code_list getLanguageList();
\r
198 int getLanguageContent(const string code, I18n::trans_table&);
\r
200 // end protocol functions
\r
204 ULLONG rescanRecording(ULONG* lengthFrames); // FIXME obselete
\r
209 static VDR* instance;
\r
211 VDR_ResponsePacket* RequestResponse(VDR_RequestPacket* request);
\r
212 UCHAR* getBlock(ULLONG position, UINT maxAmount, UINT* amountReceived, ULONG cmd);
\r
214 void connectionDied();
\r
215 bool sendKA(ULONG timeStamp);
\r
224 ULONG maxChannelNumber;
\r
225 ULONG channelNumberWidth;
\r
226 VDR_PacketReceiver* TEMP_SINGLE_VDR_PR;
\r
231 SerializeBuffer * doRequestResponse(SerializeBuffer *in,int cmd);
\r
235 void threadMethod();
\r
236 void threadPostStopCleanup() {};
\r
239 virtual bool ed_cb_find(EDReceiver* edr, void* userTag);
\r
246 index.vdr file format for video:
\r
248 For every video frame:
\r
250 File offset 4 bytes
\r
251 Picture type 1 byte
\r
258 #define NO_PICTURE 0
\r
267 Packet format for an RR channel request:
\r
269 4 bytes = channel ID = 1 (request/response channel)
\r
270 4 bytes = request ID (from serialNumber)
\r
272 4 bytes = length of the rest of the packet
\r
273 ? bytes = rest of packet. depends on packet
\r
276 Packet format for an RR channel response:
\r
278 4 bytes = channel ID = 1 (request/response channel)
\r
279 4 bytes = request ID (from serialNumber)
\r
280 4 bytes = length of the rest of the packet
\r
281 ? bytes = rest of packet. depends on packet
\r
284 Packet format for a stream packet:
\r
286 4 bytes = channel ID = 2 (stream channel)
\r
287 4 bytes = stream ID (from requestID)
\r
288 4 bytes = length of the stream data (rest of packet)
\r
289 ? bytes = stream data
\r