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