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