1ee9283782f14ac9547775678dc9f93f3454cddb
[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         bool operator<(const eDVBChannelID &c) const
81         {
82                 if (dvbnamespace < c.dvbnamespace)
83                         return 1;
84                 else if (dvbnamespace == c.dvbnamespace)
85                 {
86                         if (original_network_id < c.original_network_id)
87                                 return 1;
88                         else if (original_network_id == c.original_network_id)
89                                 if (transport_stream_id < c.transport_stream_id)
90                                         return 1;
91                 }
92                 return 0;
93         }
94         eDVBChannelID(eDVBNamespace dvbnamespace, eTransportStreamID tsid, eOriginalNetworkID onid): 
95                         dvbnamespace(dvbnamespace), transport_stream_id(tsid), original_network_id(onid)
96         {
97         }
98         eDVBChannelID():
99                         dvbnamespace(-1), transport_stream_id(-1), original_network_id(-1)
100         {
101         }
102         operator bool() const
103         {
104                 return (dvbnamespace != -1) && (transport_stream_id != -1) && (original_network_id != -1);
105         }
106 };
107
108 struct eServiceReferenceDVB: public eServiceReference
109 {
110         int getServiceType() const { return data[0]; }
111         void setServiceType(int service_type) { data[0]=service_type; }
112
113         eServiceID getServiceID() const { return eServiceID(data[1]); }
114         void setServiceID(eServiceID service_id) { data[1]=service_id.get(); }
115
116         eTransportStreamID getTransportStreamID() const { return eTransportStreamID(data[2]); }
117         void setTransportStreamID(eTransportStreamID transport_stream_id) { data[2]=transport_stream_id.get(); }
118
119         eOriginalNetworkID getOriginalNetworkID() const { return eOriginalNetworkID(data[3]); }
120         void setOriginalNetworkID(eOriginalNetworkID original_network_id) { data[3]=original_network_id.get(); }
121
122         eDVBNamespace getDVBNamespace() const { return eDVBNamespace(data[4]); }
123         void setDVBNamespace(eDVBNamespace dvbnamespace) { data[4]=dvbnamespace.get(); }
124
125         eServiceReferenceDVB(eDVBNamespace dvbnamespace, eTransportStreamID transport_stream_id, eOriginalNetworkID original_network_id, eServiceID service_id, int service_type)
126                 :eServiceReference(eServiceReference::idDVB, 0)
127         {
128                 setTransportStreamID(transport_stream_id);
129                 setOriginalNetworkID(original_network_id);
130                 setDVBNamespace(dvbnamespace);
131                 setServiceID(service_id);
132                 setServiceType(service_type);
133         }
134         
135         void set(const eDVBChannelID &chid)
136         {
137                 setDVBNamespace(chid.dvbnamespace);
138                 setOriginalNetworkID(chid.original_network_id);
139                 setTransportStreamID(chid.transport_stream_id);
140         }
141         
142         void getChannelID(eDVBChannelID &chid) const
143         {
144                 chid = eDVBChannelID(getDVBNamespace(), getTransportStreamID(), getOriginalNetworkID());
145         }
146
147         eServiceReferenceDVB()
148                 :eServiceReference(eServiceReference::idDVB, 0)
149         {
150         }
151 };
152
153
154 ////////////////// TODO: we need an interface here, but what exactly?
155
156 #include <set>
157 // btw, still implemented in db.cpp. FIX THIS, TOO.
158
159 class eDVBChannelQuery;
160
161 class eDVBService: public iStaticServiceInformation
162 {
163         DECLARE_REF(eDVBService);
164 public:
165         eDVBService();
166         std::string m_service_name;
167         std::string m_provider_name;
168         
169         int m_flags;
170         std::set<int> m_ca;
171         std::map<int,int> m_cache;
172         virtual ~eDVBService();
173         
174         eDVBService &operator=(const eDVBService &);
175         
176         // iStaticServiceInformation
177         RESULT getName(const eServiceReference &ref, std::string &name);
178         
179         // for filtering:
180         int checkFilter(const eServiceReferenceDVB &ref, const eDVBChannelQuery &query);
181 };
182
183 //////////////////
184
185 class iDVBChannel;
186 class iDVBDemux;
187 class iDVBFrontendParameters;
188
189 class iDVBChannelListQuery: public iObject
190 {
191 public:
192         virtual RESULT getNextResult(eServiceReferenceDVB &ref)=0;
193 };
194
195 class eDVBChannelQuery: public iObject
196 {
197         DECLARE_REF(eDVBChannelQuery);
198 public:
199         enum
200         {
201                 tName,
202                 tProvider,
203                 tType,
204                 tBouquet,
205                 tSatellitePosition,
206                 tChannelID,
207                 tAND,
208                 tOR
209         };
210         
211         int m_type;
212         int m_inverse;
213         
214         std::string m_string;
215         int m_int;
216         eDVBChannelID m_channelid;
217         
218         static RESULT compile(ePtr<eDVBChannelQuery> &res, std::string query);
219         
220         ePtr<eDVBChannelQuery> m_p1, m_p2;
221 };
222
223 class iDVBChannelList: public iObject
224 {
225 public:
226         virtual RESULT addChannelToList(const eDVBChannelID &id, iDVBFrontendParameters *feparm)=0;
227         virtual RESULT removeChannel(const eDVBChannelID &id)=0;
228         
229         virtual RESULT getChannelFrontendData(const eDVBChannelID &id, ePtr<iDVBFrontendParameters> &parm)=0;
230         
231         virtual RESULT addService(const eServiceReferenceDVB &service, eDVBService *service)=0;
232         virtual RESULT getService(const eServiceReferenceDVB &reference, ePtr<eDVBService> &service)=0;
233
234         virtual RESULT startQuery(ePtr<iDVBChannelListQuery> &query, eDVBChannelQuery *query)=0;
235 };
236
237 class SatelliteDeliverySystemDescriptor;
238 class CableDeliverySystemDescriptor;
239 class TerrestrialDeliverySystemDescriptor;
240
241 struct eDVBFrontendParametersSatellite
242 {
243         struct Polarisation
244         {
245                 enum {
246                         Horizontal, Vertical, CircularLeft, CircularRight
247                 };
248         };
249         struct Inversion
250         {
251                 enum {
252                         On, Off, Unknown
253                 };
254         };
255         struct FEC
256         {
257                 enum {
258                         fNone, f1_2, f2_3, f3_4, f5_6, f7_8, fAuto
259                 };
260         };
261         unsigned int frequency, symbol_rate;
262         int polarisation, fec, inversion, orbital_position;
263         
264         void set(const SatelliteDeliverySystemDescriptor  &);
265 };
266
267 struct eDVBFrontendParametersCable
268 {
269         unsigned int frequency, symbol_rate;
270         int modulation, inversion, fec_inner;
271         void set(const CableDeliverySystemDescriptor  &);
272 };
273
274 struct eDVBFrontendParametersTerrestrial
275 {
276         unsigned int frequency;
277         struct Bandwidth {
278                 enum { Bw8MHz, Bw7MHz, Bw6MHz, BwAuto };
279         };
280         
281         struct FEC
282         {
283                 enum {
284                         fNone, f1_2, f2_3, f3_4, f5_6, f7_8, fAuto
285                 };
286         };
287         
288         struct TransmissionMode {
289                 enum {
290                         TM2k, TM8k, TMAuto
291                 };
292         };
293         
294         struct GuardInterval {
295                 enum {
296                         GI_1_32, GI_1_16, GI_1_8, GI_1_4, GI_Auto
297                 };
298         };
299         
300         struct Hierarchy {
301                 enum {
302                         HNone, H1, H2, H4, HAuto
303                 };
304         };
305         
306         struct Modulation {
307                 enum {
308                         QPSK, QAM16, Auto
309                 };
310         };
311
312         struct Inversion
313         {
314                 enum {
315                         On, Off, Unknown
316                 };
317         };
318         
319         int bandwidth;
320         int code_rate_HP, code_rate_LP;
321         int modulation;
322         int transmission_mode;
323         int guard_interval;
324         int hierarchy;
325         int inversion;
326         
327         void set(const TerrestrialDeliverySystemDescriptor  &);
328 };
329
330 class iDVBFrontendParameters: public iObject
331 {
332 public:
333         virtual RESULT getSystem(int &type) const = 0;
334         virtual RESULT getDVBS(eDVBFrontendParametersSatellite &p) const = 0;
335         virtual RESULT getDVBC(eDVBFrontendParametersCable &p) const = 0;
336         virtual RESULT getDVBT(eDVBFrontendParametersTerrestrial &p) const = 0;
337         
338         virtual RESULT calculateDifference(const iDVBFrontendParameters *parm, int &diff) const = 0;
339         virtual RESULT getHash(unsigned long &hash) const = 0;
340 };
341
342 #define MAX_DISEQC_LENGTH  16
343
344 struct eDVBDiseqcCommand
345 {
346         int len;
347         __u8 data[MAX_DISEQC_LENGTH];
348 #if HAVE_DVB_API_VERSION < 3
349         int tone;
350         int voltage;
351 #endif
352 };
353
354 class iDVBSatelliteEquipmentControl;
355
356 class iDVBFrontend: public iObject
357 {
358 public:
359         enum {
360                 feSatellite, feCable, feTerrestrial
361         };
362         virtual RESULT getFrontendType(int &type)=0;
363         virtual RESULT tune(const iDVBFrontendParameters &where)=0;
364         virtual RESULT connectStateChange(const Slot1<void,iDVBFrontend*> &stateChange, ePtr<eConnection> &connection)=0;
365         enum {
366                 stateIdle = 0,
367                 stateTuning = 1,
368                 stateFailed = 2,
369                 stateLock = 3
370         };
371         virtual RESULT getState(int &state)=0;
372         enum {
373                 toneOn, toneOff
374         };
375         virtual RESULT setTone(int tone)=0;
376         enum {
377                 voltageOff, voltage13, voltage18
378         };
379         virtual RESULT setVoltage(int voltage)=0;
380         virtual RESULT sendDiseqc(const eDVBDiseqcCommand &diseqc)=0;
381         virtual RESULT setSEC(iDVBSatelliteEquipmentControl *sec)=0;
382 };
383
384 class iDVBSatelliteEquipmentControl: public iObject
385 {
386 public:
387         virtual RESULT prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, eDVBFrontendParametersSatellite &sat)=0;
388 };
389
390 struct eDVBCIRouting
391 {
392         int enabled;
393 };
394
395 class iDVBChannel: public iObject
396 {
397 public:
398         enum
399         {
400                 state_idle,        /* not yet tuned */
401                 state_tuning,      /* currently tuning (first time) */
402                 state_unavailable, /* currently unavailable, will be back without further interaction */
403                 state_ok           /* ok */
404         };
405         virtual RESULT connectStateChange(const Slot1<void,iDVBChannel*> &stateChange, ePtr<eConnection> &connection)=0;
406         virtual RESULT getState(int &state)=0;
407         enum
408         {
409                 cap_decode,
410                 cap_ci
411         };
412         virtual RESULT setCIRouting(const eDVBCIRouting &routing)=0;
413         virtual RESULT getDemux(ePtr<iDVBDemux> &demux)=0;
414         
415                 /* direct frontend access for raw channels and/or status inquiries. */
416         virtual RESULT getFrontend(ePtr<iDVBFrontend> &frontend)=0;
417 };
418
419 class iDVBSectionReader;
420 class iTSMPEGDecoder;
421
422 class iDVBDemux: public iObject
423 {
424 public:
425         virtual RESULT createSectionReader(eMainloop *context, ePtr<iDVBSectionReader> &reader)=0;
426         virtual RESULT getMPEGDecoder(ePtr<iTSMPEGDecoder> &reader)=0;
427 };
428
429 class iTSMPEGDecoder: public iObject
430 {
431 public:
432         enum { pidDisabled = -1 };
433                 /** Set Displayed Video PID */
434         virtual RESULT setVideoPID(int vpid)=0;
435
436         enum { af_MPEG, af_AC3, af_DTS };
437                 /** Set Displayed Audio PID and type */
438         virtual RESULT setAudioPID(int apid, int type)=0;
439
440                 /** Set Sync mode to PCR */
441         virtual RESULT setSyncPCR(int pcrpid)=0;
442         enum { sm_Audio, sm_Video };
443                 /** Set Sync mode to either audio or video master */
444         virtual RESULT setSyncMaster(int who)=0;
445         
446                 /** Apply settings */
447         virtual RESULT start()=0;
448         
449                 /** Freeze frame. Either continue decoding (without display) or halt. */
450         virtual RESULT freeze(int cont)=0;
451                 /** Continue after freeze. */
452         virtual RESULT unfreeze()=0;
453         
454                 // stop on .. Picture
455         enum { spm_I, spm_Ref, spm_Any };
456                 /** Stop on specific decoded picture. For I-Frame display. */
457         virtual RESULT setSinglePictureMode(int when)=0;
458         
459         enum { pkm_B, pkm_PB };
460                 /** Fast forward by skipping either B or P/B pictures */
461         virtual RESULT setPictureSkipMode(int what)=0;
462         
463                 /** Slow Motion by repeating pictures */
464         virtual RESULT setSlowMotion(int repeat)=0;
465         
466         enum { zoom_Normal, zoom_PanScan, zoom_Letterbox, zoom_Fullscreen };
467                 /** Set Zoom. mode *must* be fitting. */
468         virtual RESULT setZoom(int what)=0;
469 };
470
471 #endif