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