remove generated file "config.h":
[enigma2.git] / lib / dvb / idvb.h
1 #ifndef __dvb_idvb_h
2 #define __dvb_idvb_h
3
4 #if HAVE_DVB_API_VERSION < 3
5 #include <ost/frontend.h>
6 #define FRONTENDPARAMETERS FrontendParameters
7 #else
8 #include <linux/dvb/frontend.h>
9 #define FRONTENDPARAMETERS struct dvb_frontend_parameters
10 #endif
11 #include <lib/dvb/frontendparms.h>
12 #include <lib/base/object.h>
13 #include <lib/base/ebase.h>
14 #include <lib/service/service.h>
15 #include <libsig_comp.h>
16 #include <connection.h>
17
18 struct eBouquet
19 {
20         std::string m_bouquet_name;
21         std::string m_filename;  // without path.. just name
22         typedef std::list<eServiceReference> list;
23         list m_services;
24 // the following four methods are implemented in db.cpp
25         RESULT flushChanges();
26         RESULT addService(const eServiceReference &);
27         RESULT removeService(const eServiceReference &);
28         RESULT moveService(const eServiceReference &, unsigned int);
29 };
30
31                 /* these structures have by intention no operator int() defined.
32                    the reason of these structures is to avoid mixing for example
33                    a onid and a tsid (as there's no general order for them).
34                    
35                    defining an operator int() would implicitely convert values
36                    between them over the constructor with the int argument.
37                    
38                    'explicit' doesn't here - eTransportStreamID(eOriginalNetworkID(n)) 
39                    would still work. */
40
41 struct eTransportStreamID
42 {
43 private:
44         int v;
45 public:
46         int get() const { return v; }
47         eTransportStreamID(int i): v(i) { }
48         eTransportStreamID(): v(-1) { }
49         bool operator == (const eTransportStreamID &c) const { return v == c.v; }
50         bool operator != (const eTransportStreamID &c) const { return v != c.v; }
51         bool operator < (const eTransportStreamID &c) const { return v < c.v; }
52         bool operator > (const eTransportStreamID &c) const { return v > c.v; }
53 };
54
55 struct eServiceID
56 {
57 private:
58         int v;
59 public:
60         int get() const { return v; }
61         eServiceID(int i): v(i) { }
62         eServiceID(): v(-1) { }
63         bool operator == (const eServiceID &c) const { return v == c.v; }
64         bool operator != (const eServiceID &c) const { return v != c.v; }
65         bool operator < (const eServiceID &c) const { return v < c.v; }
66         bool operator > (const eServiceID &c) const { return v > c.v; }
67 };
68
69 struct eOriginalNetworkID
70 {
71 private:
72         int v;
73 public:
74         int get() const { return v; }
75         eOriginalNetworkID(int i): v(i) { }
76         eOriginalNetworkID(): v(-1) { }
77         bool operator == (const eOriginalNetworkID &c) const { return v == c.v; }
78         bool operator != (const eOriginalNetworkID &c) const { return v != c.v; }
79         bool operator < (const eOriginalNetworkID &c) const { return v < c.v; }
80         bool operator > (const eOriginalNetworkID &c) const { return v > c.v; }
81 };
82
83 struct eDVBNamespace
84 {
85 private:
86         int v;
87 public:
88         int get() const { return v; }
89         eDVBNamespace(int i): v(i) { }
90         eDVBNamespace(): v(-1) { }
91         bool operator == (const eDVBNamespace &c) const { return v == c.v; }
92         bool operator != (const eDVBNamespace &c) const { return v != c.v; }
93         bool operator < (const eDVBNamespace &c) const { return v < c.v; }
94         bool operator > (const eDVBNamespace &c) const { return v > c.v; }
95 };
96
97 struct eDVBChannelID
98 {
99         eDVBNamespace dvbnamespace;
100         eTransportStreamID transport_stream_id;
101         eOriginalNetworkID original_network_id;
102         
103         bool operator==(const eDVBChannelID &c) const
104         {
105                 return dvbnamespace == c.dvbnamespace &&
106                         transport_stream_id == c.transport_stream_id &&
107                         original_network_id == c.original_network_id;
108         }
109         
110         bool operator<(const eDVBChannelID &c) const
111         {
112                 if (dvbnamespace < c.dvbnamespace)
113                         return 1;
114                 else if (dvbnamespace == c.dvbnamespace)
115                 {
116                         if (original_network_id < c.original_network_id)
117                                 return 1;
118                         else if (original_network_id == c.original_network_id)
119                                 if (transport_stream_id < c.transport_stream_id)
120                                         return 1;
121                 }
122                 return 0;
123         }
124         eDVBChannelID(eDVBNamespace dvbnamespace, eTransportStreamID tsid, eOriginalNetworkID onid): 
125                         dvbnamespace(dvbnamespace), transport_stream_id(tsid), original_network_id(onid)
126         {
127         }
128         eDVBChannelID():
129                         dvbnamespace(-1), transport_stream_id(-1), original_network_id(-1)
130         {
131         }
132         operator bool() const
133         {
134                 return (dvbnamespace != -1) && (transport_stream_id != -1) && (original_network_id != -1);
135         }
136 };
137
138 struct eServiceReferenceDVB: public eServiceReference
139 {
140         int getServiceType() const { return data[0]; }
141         void setServiceType(int service_type) { data[0]=service_type; }
142
143         eServiceID getServiceID() const { return eServiceID(data[1]); }
144         void setServiceID(eServiceID service_id) { data[1]=service_id.get(); }
145
146         eTransportStreamID getTransportStreamID() const { return eTransportStreamID(data[2]); }
147         void setTransportStreamID(eTransportStreamID transport_stream_id) { data[2]=transport_stream_id.get(); }
148
149         eOriginalNetworkID getOriginalNetworkID() const { return eOriginalNetworkID(data[3]); }
150         void setOriginalNetworkID(eOriginalNetworkID original_network_id) { data[3]=original_network_id.get(); }
151
152         eDVBNamespace getDVBNamespace() const { return eDVBNamespace(data[4]); }
153         void setDVBNamespace(eDVBNamespace dvbnamespace) { data[4]=dvbnamespace.get(); }
154
155         eServiceID getParentServiceID() const { return eServiceID(data[5]); }
156         void setParentServiceID( eServiceID sid ) { data[5]=sid.get(); }
157
158         eTransportStreamID getParentTransportStreamID() const { return eTransportStreamID(data[6]); }
159         void setParentTransportStreamID( eTransportStreamID tsid ) { data[6]=tsid.get(); }
160
161         eServiceReferenceDVB(eDVBNamespace dvbnamespace, eTransportStreamID transport_stream_id, eOriginalNetworkID original_network_id, eServiceID service_id, int service_type)
162                 :eServiceReference(eServiceReference::idDVB, 0)
163         {
164                 setTransportStreamID(transport_stream_id);
165                 setOriginalNetworkID(original_network_id);
166                 setDVBNamespace(dvbnamespace);
167                 setServiceID(service_id);
168                 setServiceType(service_type);
169         }
170         
171         void set(const eDVBChannelID &chid)
172         {
173                 setDVBNamespace(chid.dvbnamespace);
174                 setOriginalNetworkID(chid.original_network_id);
175                 setTransportStreamID(chid.transport_stream_id);
176         }
177         
178         void getChannelID(eDVBChannelID &chid) const
179         {
180                 chid = eDVBChannelID(getDVBNamespace(), getTransportStreamID(), getOriginalNetworkID());
181         }
182
183         eServiceReferenceDVB()
184                 :eServiceReference(eServiceReference::idDVB, 0)
185         {
186         }
187
188         eServiceReferenceDVB(const std::string &string)
189                 :eServiceReference(string)
190         {
191         }
192 };
193
194
195 ////////////////// TODO: we need an interface here, but what exactly?
196
197 #include <set>
198 // btw, still implemented in db.cpp. FIX THIS, TOO.
199
200 class eDVBChannelQuery;
201
202 class eDVBService: public iStaticServiceInformation
203 {
204         DECLARE_REF(eDVBService);
205 public:
206         enum cacheID
207         {
208                 cVPID, cAPID, cTPID, cPCRPID, cAC3PID, cacheMax
209         };
210
211         int getCachePID(cacheID);
212         void setCachePID(cacheID, int);
213         bool cacheEmpty() { return m_cache.empty(); }
214
215         eDVBService();
216                 /* m_service_name_sort is uppercase, with special chars removed, to increase sort performance. */
217         std::string m_service_name, m_service_name_sort;
218         std::string m_provider_name;
219         
220         void genSortName();
221         
222         int m_flags;
223         std::set<int> m_ca;
224         std::map<int,int> m_cache;
225         virtual ~eDVBService();
226         
227         eDVBService &operator=(const eDVBService &);
228         
229         // iStaticServiceInformation
230         RESULT getName(const eServiceReference &ref, std::string &name);
231         RESULT getEvent(const eServiceReference &ref, ePtr<eServiceEvent> &ptr, time_t start_time);
232         bool isPlayable(const eServiceReference &ref, const eServiceReference &ignore);
233
234                 /* for filtering: */
235         int checkFilter(const eServiceReferenceDVB &ref, const eDVBChannelQuery &query);
236 };
237
238 //////////////////
239
240 class iDVBChannel;
241 class iDVBDemux;
242 class iDVBFrontendParameters;
243
244 class iDVBChannelListQuery: public iObject
245 {
246 public:
247         virtual RESULT getNextResult(eServiceReferenceDVB &ref)=0;
248         virtual int compareLessEqual(const eServiceReferenceDVB &a, const eServiceReferenceDVB &b)=0;
249 };
250
251 class eDVBChannelQuery: public iObject
252 {
253         DECLARE_REF(eDVBChannelQuery);
254 public:
255         enum
256         {
257                 tName,
258                 tProvider,
259                 tType,
260                 tBouquet,
261                 tSatellitePosition,
262                 tChannelID,
263                 tAND,
264                 tOR
265         };
266         
267         int m_type;
268         int m_inverse;
269         
270         std::string m_string;
271         int m_int;
272         eDVBChannelID m_channelid;
273         
274                 /* sort is only valid in root, and must be from the enum above. */
275         int m_sort;
276         std::string m_bouquet_name;
277         
278         static RESULT compile(ePtr<eDVBChannelQuery> &res, std::string query);
279         
280         ePtr<eDVBChannelQuery> m_p1, m_p2;
281 };
282
283 class iDVBChannelList: public iObject
284 {
285 public:
286         virtual RESULT addChannelToList(const eDVBChannelID &id, iDVBFrontendParameters *feparm)=0;
287         virtual RESULT removeChannel(const eDVBChannelID &id)=0;
288         
289         virtual RESULT getChannelFrontendData(const eDVBChannelID &id, ePtr<iDVBFrontendParameters> &parm)=0;
290         
291         virtual RESULT addService(const eServiceReferenceDVB &service, eDVBService *service)=0;
292         virtual RESULT getService(const eServiceReferenceDVB &reference, ePtr<eDVBService> &service)=0;
293         virtual RESULT flush()=0;
294
295         virtual RESULT getBouquet(const eServiceReference &ref,  eBouquet* &bouquet)=0;
296
297         virtual RESULT startQuery(ePtr<iDVBChannelListQuery> &query, eDVBChannelQuery *query, const eServiceReference &source)=0;
298 };
299
300 class iDVBFrontendParameters: public iObject
301 {
302 public:
303         virtual RESULT getSystem(int &type) const = 0;
304         virtual RESULT getDVBS(eDVBFrontendParametersSatellite &p) const = 0;
305         virtual RESULT getDVBC(eDVBFrontendParametersCable &p) const = 0;
306         virtual RESULT getDVBT(eDVBFrontendParametersTerrestrial &p) const = 0;
307         
308         virtual RESULT calculateDifference(const iDVBFrontendParameters *parm, int &diff) const = 0;
309         virtual RESULT getHash(unsigned long &hash) const = 0;
310 };
311
312 #define MAX_DISEQC_LENGTH  16
313
314 class eDVBDiseqcCommand
315 {
316 public:
317         int len;
318         __u8 data[MAX_DISEQC_LENGTH];
319 #if HAVE_DVB_API_VERSION < 3
320         int tone;
321         int voltage;
322 #endif
323 };
324
325 class iDVBSatelliteEquipmentControl;
326 class eSecCommandList;
327
328 class iDVBFrontend: public iObject
329 {
330 public:
331         enum {
332                 feSatellite, feCable, feTerrestrial
333         };
334         virtual RESULT getFrontendType(int &type)=0;
335         virtual RESULT tune(const iDVBFrontendParameters &where)=0;
336         virtual RESULT connectStateChange(const Slot1<void,iDVBFrontend*> &stateChange, ePtr<eConnection> &connection)=0;
337         enum {
338                 stateIdle = 0,
339                 stateTuning = 1,
340                 stateFailed = 2,
341                 stateLock = 3,
342                 stateLostLock = 4,
343         };
344         virtual RESULT getState(int &state)=0;
345         enum {
346                 toneOff, toneOn
347         };
348         virtual RESULT setTone(int tone)=0;
349         enum {
350                 voltageOff, voltage13, voltage18, voltage13_5, voltage18_5
351         };
352         virtual RESULT setVoltage(int voltage)=0;
353         virtual RESULT sendDiseqc(const eDVBDiseqcCommand &diseqc)=0;
354         virtual RESULT sendToneburst(int burst)=0;
355         virtual RESULT setSEC(iDVBSatelliteEquipmentControl *sec)=0;
356         virtual RESULT setSecSequence(const eSecCommandList &list)=0;
357
358         enum {
359                 bitErrorRate, signalPower, signalQuality
360         };
361         virtual int readFrontendData(int type)=0;
362
363         virtual RESULT getData(int num, int &data)=0;
364         virtual RESULT setData(int num, int val)=0;
365         
366                 /* 0 means: not compatible. other values are a priority. */
367         virtual int isCompatibleWith(ePtr<iDVBFrontendParameters> &feparm)=0;
368 };
369
370 class iDVBSatelliteEquipmentControl: public iObject
371 {
372 public:
373         virtual RESULT prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, eDVBFrontendParametersSatellite &sat, int frontend_id)=0;
374         virtual int canTune(const eDVBFrontendParametersSatellite &feparm, iDVBFrontend *fe, int frontend_id)=0;
375         virtual void setRotorMoving(bool)=0;
376 };
377
378 struct eDVBCIRouting
379 {
380         int enabled;
381 };
382
383 class iDVBChannel: public iObject
384 {
385 public:
386         enum
387         {
388                 state_idle,        /* not yet tuned */
389                 state_tuning,      /* currently tuning (first time) */
390                 state_failed,      /* tuning failed. */
391                 state_unavailable, /* currently unavailable, will be back without further interaction */
392                 state_ok,          /* ok */
393                 state_release      /* channel is being shut down. */
394         };
395         
396         enum 
397         {
398                 evtEOF, evtFailed
399         };
400         virtual RESULT connectStateChange(const Slot1<void,iDVBChannel*> &stateChange, ePtr<eConnection> &connection)=0;
401         virtual RESULT connectEvent(const Slot2<void,iDVBChannel*,int> &eventChange, ePtr<eConnection> &connection)=0;
402         virtual RESULT getState(int &state)=0;
403         
404                 /* demux capabilities */
405         enum
406         {
407                 capDecode = 1,
408                 /* capCI = 2 */
409         };
410         virtual RESULT setCIRouting(const eDVBCIRouting &routing)=0;
411         virtual RESULT getDemux(ePtr<iDVBDemux> &demux, int cap=0)=0;
412         
413                 /* direct frontend access for raw channels and/or status inquiries. */
414         virtual RESULT getFrontend(ePtr<iDVBFrontend> &frontend)=0;
415         
416                 /* use count handling */
417         virtual void AddUse() = 0;
418         virtual void ReleaseUse() = 0;
419 };
420
421         /* signed, so we can express deltas. */
422 typedef long long pts_t;
423
424 class iDVBPVRChannel: public iDVBChannel
425 {
426 public:
427         enum
428         {
429                 state_eof = state_release + 1  /* end-of-file reached. */
430         };
431         
432                 /* FIXME: there are some very ugly buffer-end and ... related problems */
433                 /* so this is VERY UGLY. */
434         virtual RESULT playFile(const char *file) = 0;
435         
436         virtual RESULT getLength(pts_t &pts) = 0;
437         
438                 /* we explicitely ask for the decoding demux here because a channel
439                    can be shared between multiple decoders.
440                    Of couse skipping doesn't make much sense 
441                    then, but getCurrentPosition does. */
442         virtual RESULT getCurrentPosition(iDVBDemux *decoding_demux, pts_t &pos, int mode) = 0;
443         virtual RESULT seekTo(iDVBDemux *decoding_demux, int relative, pts_t &pts) = 0;
444         virtual RESULT seekToPosition(iDVBDemux *decoding_demux, const off_t &pts) = 0;
445 };
446
447 class iDVBSectionReader;
448 class iDVBTSRecorder;
449 class iTSMPEGDecoder;
450
451 class iDVBDemux: public iObject
452 {
453 public:
454         virtual RESULT createSectionReader(eMainloop *context, ePtr<iDVBSectionReader> &reader)=0;
455         virtual RESULT createTSRecorder(ePtr<iDVBTSRecorder> &recorder)=0;
456         virtual RESULT getMPEGDecoder(ePtr<iTSMPEGDecoder> &reader)=0;
457         virtual RESULT getSTC(pts_t &pts, int num=0)=0;
458         virtual RESULT getCADemuxID(uint8_t &id)=0;
459         virtual RESULT flush()=0;
460 };
461
462 class iTSMPEGDecoder: public iObject
463 {
464 public:
465         enum { pidDisabled = -1 };
466                 /** Set Displayed Video PID */
467         virtual RESULT setVideoPID(int vpid)=0;
468
469         enum { af_MPEG, af_AC3, af_DTS };
470                 /** Set Displayed Audio PID and type */
471         virtual RESULT setAudioPID(int apid, int type)=0;
472
473                 /** Set Displayed Videotext PID */
474         virtual RESULT setTextPID(int vpid)=0;
475
476                 /** Set Sync mode to PCR */
477         virtual RESULT setSyncPCR(int pcrpid)=0;
478         enum { sm_Audio, sm_Video };
479                 /** Set Sync mode to either audio or video master */
480         virtual RESULT setSyncMaster(int who)=0;
481
482                 /** Apply settings */
483         virtual RESULT start()=0;
484         
485                 /** Freeze frame. Either continue decoding (without display) or halt. */
486         virtual RESULT freeze(int cont)=0;
487                 /** Continue after freeze. */
488         virtual RESULT unfreeze()=0;
489         
490                 /** fast forward by skipping frames. 0 is disabled, 2 is twice-the-speed, ... */
491         virtual RESULT setFastForward(int skip=0)=0;
492         
493                 // stop on .. Picture
494         enum { spm_I, spm_Ref, spm_Any };
495                 /** Stop on specific decoded picture. For I-Frame display. */
496         virtual RESULT setSinglePictureMode(int when)=0;
497         
498         enum { pkm_B, pkm_PB };
499                 /** Fast forward by skipping either B or P/B pictures */
500         virtual RESULT setPictureSkipMode(int what)=0;
501         
502                 /** Slow Motion by repeating pictures */
503         virtual RESULT setSlowMotion(int repeat)=0;
504         
505         enum { zoom_Normal, zoom_PanScan, zoom_Letterbox, zoom_Fullscreen };
506                 /** Set Zoom. mode *must* be fitting. */
507         virtual RESULT setZoom(int what)=0;
508         
509         virtual RESULT setTrickmode(int what) = 0;
510 };
511
512 #endif