- actionmap component will not catch (wrong) exceptions anymore
[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 iDVBResourceManager: public iObject
238 {
239 public:
240         /*
241                         solange rumloopen bis eine resource gefunden wurde, die eine frequenz
242                         tunen will
243                         
244                         wenn natuerlich sowas schon vorhanden ist, dann einfach ne ref darauf
245                         geben. (zwei services auf dem gleichen transponder teilen sich einen
246                         channel)
247         */
248         virtual RESULT setChannelList(iDVBChannelList *list)=0;
249         virtual RESULT getChannelList(ePtr<iDVBChannelList> &list)=0;
250         virtual RESULT allocateChannel(const eDVBChannelID &channel, ePtr<iDVBChannel> &channel)=0;
251         virtual RESULT allocateRawChannel(ePtr<iDVBChannel> &channel)=0;
252         virtual RESULT allocatePVRChannel(int caps)=0;
253 };
254
255 class SatelliteDeliverySystemDescriptor;
256 class CableDeliverySystemDescriptor;
257 class TerrestrialDeliverySystemDescriptor;
258
259 struct eDVBFrontendParametersSatellite
260 {
261         struct Polarisation
262         {
263                 enum {
264                         Horizontal, Vertical, CircularLeft, CircularRight
265                 };
266         };
267         struct Inversion
268         {
269                 enum {
270                         On, Off, Unknown
271                 };
272         };
273         struct FEC
274         {
275                 enum {
276                         fNone, f1_2, f2_3, f3_4, f5_6, f7_8, fAuto
277                 };
278         };
279         unsigned int frequency, symbol_rate;
280         int polarisation, fec, inversion, orbital_position;
281         
282         void set(const SatelliteDeliverySystemDescriptor  &);
283 };
284
285 struct eDVBFrontendParametersCable
286 {
287         unsigned int frequency, symbol_rate;
288         int modulation, inversion, fec_inner;
289         void set(const CableDeliverySystemDescriptor  &);
290 };
291
292 struct eDVBFrontendParametersTerrestrial
293 {
294         unsigned int frequency;
295         struct Bandwidth {
296                 enum { Bw8MHz, Bw7MHz, Bw6MHz, BwAuto };
297         };
298         
299         struct FEC
300         {
301                 enum {
302                         fNone, f1_2, f2_3, f3_4, f5_6, f7_8, fAuto
303                 };
304         };
305         
306         struct TransmissionMode {
307                 enum {
308                         TM2k, TM8k, TMAuto
309                 };
310         };
311         
312         struct GuardInterval {
313                 enum {
314                         GI_1_32, GI_1_16, GI_1_8, GI_1_4, GI_Auto
315                 };
316         };
317         
318         struct Hierarchy {
319                 enum {
320                         HNone, H1, H2, H4, HAuto
321                 };
322         };
323         
324         struct Modulation {
325                 enum {
326                         QPSK, QAM16, Auto
327                 };
328         };
329
330         struct Inversion
331         {
332                 enum {
333                         On, Off, Unknown
334                 };
335         };
336         
337         int bandwidth;
338         int code_rate_HP, code_rate_LP;
339         int modulation;
340         int transmission_mode;
341         int guard_interval;
342         int hierarchy;
343         int inversion;
344         
345         void set(const TerrestrialDeliverySystemDescriptor  &);
346 };
347
348 class iDVBFrontendParameters: public iObject
349 {
350 public:
351         virtual RESULT getSystem(int &type) const = 0;
352         virtual RESULT getDVBS(eDVBFrontendParametersSatellite &p) const = 0;
353         virtual RESULT getDVBC(eDVBFrontendParametersCable &p) const = 0;
354         virtual RESULT getDVBT(eDVBFrontendParametersTerrestrial &p) const = 0;
355         
356         virtual RESULT calculateDifference(const iDVBFrontendParameters *parm, int &diff) const = 0;
357         virtual RESULT getHash(unsigned long &hash) const = 0;
358 };
359
360 #define MAX_DISEQC_LENGTH  16
361
362 struct eDVBDiseqcCommand
363 {
364         int len;
365         __u8 data[MAX_DISEQC_LENGTH];
366 #if HAVE_DVB_API_VERSION < 3
367         int tone;
368         int voltage;
369 #endif
370 };
371
372 class iDVBSatelliteEquipmentControl;
373
374 class iDVBFrontend: public iObject
375 {
376 public:
377         enum {
378                 feSatellite, feCable, feTerrestrial
379         };
380         virtual RESULT getFrontendType(int &type)=0;
381         virtual RESULT tune(const iDVBFrontendParameters &where)=0;
382         virtual RESULT connectStateChange(const Slot1<void,iDVBFrontend*> &stateChange, ePtr<eConnection> &connection)=0;
383         enum {
384                 stateIdle = 0,
385                 stateTuning = 1,
386                 stateFailed = 2,
387                 stateLock = 3
388         };
389         virtual RESULT getState(int &state)=0;
390         enum {
391                 toneOn, toneOff
392         };
393         virtual RESULT setTone(int tone)=0;
394         enum {
395                 voltageOff, voltage13, voltage18
396         };
397         virtual RESULT setVoltage(int voltage)=0;
398         virtual RESULT sendDiseqc(const eDVBDiseqcCommand &diseqc)=0;
399         virtual RESULT setSEC(iDVBSatelliteEquipmentControl *sec)=0;
400 };
401
402 class iDVBSatelliteEquipmentControl: public iObject
403 {
404 public:
405         virtual RESULT prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, eDVBFrontendParametersSatellite &sat)=0;
406 };
407
408 struct eDVBCIRouting
409 {
410         int enabled;
411 };
412
413 class iDVBChannel: public iObject
414 {
415 public:
416         enum
417         {
418                 state_idle,        /* not yet tuned */
419                 state_tuning,      /* currently tuning (first time) */
420                 state_unavailable, /* currently unavailable, will be back without further interaction */
421                 state_ok           /* ok */
422         };
423         virtual RESULT connectStateChange(const Slot1<void,iDVBChannel*> &stateChange, ePtr<eConnection> &connection)=0;
424         virtual RESULT getState(int &state)=0;
425         enum
426         {
427                 cap_decode,
428                 cap_ci
429         };
430         virtual RESULT setCIRouting(const eDVBCIRouting &routing)=0;
431         virtual RESULT getDemux(ePtr<iDVBDemux> &demux)=0;
432         
433                 /* direct frontend access for raw channels and/or status inquiries. */
434         virtual RESULT getFrontend(ePtr<iDVBFrontend> &frontend)=0;
435 };
436
437 class iDVBSectionReader;
438 class iTSMPEGDecoder;
439
440 class iDVBDemux: public iObject
441 {
442 public:
443         virtual RESULT createSectionReader(eMainloop *context, ePtr<iDVBSectionReader> &reader)=0;
444         virtual RESULT getMPEGDecoder(ePtr<iTSMPEGDecoder> &reader)=0;
445 };
446
447 class iTSMPEGDecoder: public iObject
448 {
449 public:
450         enum { pidDisabled = -1 };
451                 /** Set Displayed Video PID */
452         virtual RESULT setVideoPID(int vpid)=0;
453
454         enum { af_MPEG, af_AC3, af_DTS };
455                 /** Set Displayed Audio PID and type */
456         virtual RESULT setAudioPID(int apid, int type)=0;
457
458                 /** Set Sync mode to PCR */
459         virtual RESULT setSyncPCR(int pcrpid)=0;
460         enum { sm_Audio, sm_Video };
461                 /** Set Sync mode to either audio or video master */
462         virtual RESULT setSyncMaster(int who)=0;
463         
464                 /** Apply settings */
465         virtual RESULT start()=0;
466         
467                 /** Freeze frame. Either continue decoding (without display) or halt. */
468         virtual RESULT freeze(int cont)=0;
469                 /** Continue after freeze. */
470         virtual RESULT unfreeze()=0;
471         
472                 // stop on .. Picture
473         enum { spm_I, spm_Ref, spm_Any };
474                 /** Stop on specific decoded picture. For I-Frame display. */
475         virtual RESULT setSinglePictureMode(int when)=0;
476         
477         enum { pkm_B, pkm_PB };
478                 /** Fast forward by skipping either B or P/B pictures */
479         virtual RESULT setPictureSkipMode(int what)=0;
480         
481                 /** Slow Motion by repeating pictures */
482         virtual RESULT setSlowMotion(int repeat)=0;
483         
484         enum { zoom_Normal, zoom_PanScan, zoom_Letterbox, zoom_Fullscreen };
485                 /** Set Zoom. mode *must* be fitting. */
486         virtual RESULT setZoom(int what)=0;
487 };
488
489 #endif