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