- added missing actions (sorry)
[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         int unknown;
295         void set(const TerrestrialDeliverySystemDescriptor  &);
296 };
297
298 class iDVBFrontendParameters: public iObject
299 {
300 public:
301         virtual RESULT getSystem(int &type) const = 0;
302         virtual RESULT getDVBS(eDVBFrontendParametersSatellite &p) const = 0;
303         virtual RESULT getDVBC(eDVBFrontendParametersCable &p) const = 0;
304         virtual RESULT getDVBT(eDVBFrontendParametersTerrestrial &p) const = 0;
305         
306         virtual RESULT calculateDifference(const iDVBFrontendParameters *parm, int &diff) const = 0;
307         virtual RESULT getHash(unsigned long &hash) const = 0;
308 };
309
310 #define MAX_DISEQC_LENGTH  16
311
312 struct eDVBDiseqcCommand
313 {
314         int len;
315         __u8 data[MAX_DISEQC_LENGTH];
316 };
317
318 class iDVBSatelliteEquipmentControl;
319
320 class iDVBFrontend: public iObject
321 {
322 public:
323         enum {
324                 feSatellite, feCable, feTerrestrial
325         };
326         virtual RESULT getFrontendType(int &type)=0;
327         virtual RESULT tune(const iDVBFrontendParameters &where)=0;
328         virtual RESULT connectStateChange(const Slot1<void,iDVBFrontend*> &stateChange, ePtr<eConnection> &connection)=0;
329         enum {
330                 stateIdle = 0,
331                 stateTuning = 1,
332                 stateFailed = 2,
333                 stateLock = 3
334         };
335         virtual RESULT getState(int &state)=0;
336         enum {
337                 toneOn, toneOff
338         };
339         virtual RESULT setTone(int tone)=0;
340         enum {
341                 voltageOff, voltage13, voltage18
342         };
343         virtual RESULT setVoltage(int voltage)=0;
344         virtual RESULT sendDiseqc(const eDVBDiseqcCommand &diseqc)=0;
345         virtual RESULT setSEC(iDVBSatelliteEquipmentControl *sec)=0;
346 };
347
348 class iDVBSatelliteEquipmentControl: public iObject
349 {
350 public:
351         virtual RESULT prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, eDVBFrontendParametersSatellite &sat)=0;
352 };
353
354 struct eDVBCIRouting
355 {
356         int enabled;
357 };
358
359 class iDVBChannel: public iObject
360 {
361 public:
362         enum
363         {
364                 state_idle,        /* not yet tuned */
365                 state_tuning,      /* currently tuning (first time) */
366                 state_unavailable, /* currently unavailable, will be back without further interaction */
367                 state_ok           /* ok */
368         };
369         virtual RESULT connectStateChange(const Slot1<void,iDVBChannel*> &stateChange, ePtr<eConnection> &connection)=0;
370         virtual RESULT getState(int &state)=0;
371         enum
372         {
373                 cap_decode,
374                 cap_ci
375         };
376         virtual RESULT setCIRouting(const eDVBCIRouting &routing)=0;
377         virtual RESULT getDemux(ePtr<iDVBDemux> &demux)=0;
378         
379                 /* direct frontend access for raw channels and/or status inquiries. */
380         virtual RESULT getFrontend(ePtr<iDVBFrontend> &frontend)=0;
381 };
382
383 class iDVBSectionReader;
384 class iTSMPEGDecoder;
385
386 class iDVBDemux: public iObject
387 {
388 public:
389         virtual RESULT createSectionReader(eMainloop *context, ePtr<iDVBSectionReader> &reader)=0;
390         virtual RESULT getMPEGDecoder(ePtr<iTSMPEGDecoder> &reader)=0;
391 };
392
393 class iTSMPEGDecoder: public iObject
394 {
395 public:
396         enum { pidDisabled = -1 };
397                 /** Set Displayed Video PID */
398         virtual RESULT setVideoPID(int vpid)=0;
399
400         enum { af_MPEG, af_AC3, af_DTS };
401                 /** Set Displayed Audio PID and type */
402         virtual RESULT setAudioPID(int apid, int type)=0;
403
404                 /** Set Sync mode to PCR */
405         virtual RESULT setSyncPCR(int pcrpid)=0;
406         enum { sm_Audio, sm_Video };
407                 /** Set Sync mode to either audio or video master */
408         virtual RESULT setSyncMaster(int who)=0;
409         
410                 /** Apply settings */
411         virtual RESULT start()=0;
412         
413                 /** Freeze frame. Either continue decoding (without display) or halt. */
414         virtual RESULT freeze(int cont)=0;
415                 /** Continue after freeze. */
416         virtual RESULT unfreeze()=0;
417         
418                 // stop on .. Picture
419         enum { spm_I, spm_Ref, spm_Any };
420                 /** Stop on specific decoded picture. For I-Frame display. */
421         virtual RESULT setSinglePictureMode(int when)=0;
422         
423         enum { pkm_B, pkm_PB };
424                 /** Fast forward by skipping either B or P/B pictures */
425         virtual RESULT setPictureSkipMode(int what)=0;
426         
427                 /** Slow Motion by repeating pictures */
428         virtual RESULT setSlowMotion(int repeat)=0;
429         
430         enum { zoom_Normal, zoom_PanScan, zoom_Letterbox, zoom_Fullscreen };
431                 /** Set Zoom. mode *must* be fitting. */
432         virtual RESULT setZoom(int what)=0;
433 };
434
435 #endif