fixes for old api.. not all tested..
[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 #endif
8 #include <lib/base/object.h>
9 #include <lib/base/ebase.h>
10 #include <lib/service/service.h>
11 #include <libsig_comp.h>
12 #include <connection.h>
13
14                 // bitte KEINE operator int() definieren, sonst bringt das ganze nix!
15 struct eTransportStreamID
16 {
17 private:
18         int v;
19 public:
20         int get() const { return v; }
21         eTransportStreamID(int i): v(i) { }
22         eTransportStreamID(): v(-1) { }
23         bool operator == (const eTransportStreamID &c) const { return v == c.v; }
24         bool operator != (const eTransportStreamID &c) const { return v != c.v; }
25         bool operator < (const eTransportStreamID &c) const { return v < c.v; }
26         bool operator > (const eTransportStreamID &c) const { return v > c.v; }
27 };
28
29 struct eServiceID
30 {
31 private:
32         int v;
33 public:
34         int get() const { return v; }
35         eServiceID(int i): v(i) { }
36         eServiceID(): v(-1) { }
37         bool operator == (const eServiceID &c) const { return v == c.v; }
38         bool operator != (const eServiceID &c) const { return v != c.v; }
39         bool operator < (const eServiceID &c) const { return v < c.v; }
40         bool operator > (const eServiceID &c) const { return v > c.v; }
41 };
42
43 struct eOriginalNetworkID
44 {
45 private:
46         int v;
47 public:
48         int get() const { return v; }
49         eOriginalNetworkID(int i): v(i) { }
50         eOriginalNetworkID(): v(-1) { }
51         bool operator == (const eOriginalNetworkID &c) const { return v == c.v; }
52         bool operator != (const eOriginalNetworkID &c) const { return v != c.v; }
53         bool operator < (const eOriginalNetworkID &c) const { return v < c.v; }
54         bool operator > (const eOriginalNetworkID &c) const { return v > c.v; }
55 };
56
57 struct eDVBNamespace
58 {
59 private:
60         int v;
61 public:
62         int get() const { return v; }
63         eDVBNamespace(int i): v(i) { }
64         eDVBNamespace(): v(-1) { }
65         bool operator == (const eDVBNamespace &c) const { return v == c.v; }
66         bool operator != (const eDVBNamespace &c) const { return v != c.v; }
67         bool operator < (const eDVBNamespace &c) const { return v < c.v; }
68         bool operator > (const eDVBNamespace &c) const { return v > c.v; }
69 };
70
71 struct eDVBChannelID
72 {
73         eDVBNamespace dvbnamespace;
74         eTransportStreamID transport_stream_id;
75         eOriginalNetworkID original_network_id;
76         bool operator<(const eDVBChannelID &c) const
77         {
78                 if (dvbnamespace < c.dvbnamespace)
79                         return 1;
80                 else if (dvbnamespace == c.dvbnamespace)
81                 {
82                         if (original_network_id < c.original_network_id)
83                                 return 1;
84                         else if (original_network_id == c.original_network_id)
85                                 if (transport_stream_id < c.transport_stream_id)
86                                         return 1;
87                 }
88                 return 0;
89         }
90         eDVBChannelID(eDVBNamespace dvbnamespace, eTransportStreamID tsid, eOriginalNetworkID onid): 
91                         dvbnamespace(dvbnamespace), transport_stream_id(tsid), original_network_id(onid)
92         {
93         }
94         eDVBChannelID():
95                         dvbnamespace(-1), transport_stream_id(-1), original_network_id(-1)
96         {
97         }
98         operator bool() const
99         {
100                 return (dvbnamespace != -1) && (transport_stream_id != -1) && (original_network_id != -1);
101         }
102 };
103
104 struct eServiceReferenceDVB: public eServiceReference
105 {
106         int getServiceType() const { return data[0]; }
107         void setServiceType(int service_type) { data[0]=service_type; }
108
109         eServiceID getServiceID() const { return eServiceID(data[1]); }
110         void setServiceID(eServiceID service_id) { data[1]=service_id.get(); }
111
112         eTransportStreamID getTransportStreamID() const { return eTransportStreamID(data[2]); }
113         void setTransportStreamID(eTransportStreamID transport_stream_id) { data[2]=transport_stream_id.get(); }
114
115         eOriginalNetworkID getOriginalNetworkID() const { return eOriginalNetworkID(data[3]); }
116         void setOriginalNetworkID(eOriginalNetworkID original_network_id) { data[3]=original_network_id.get(); }
117
118         eDVBNamespace getDVBNamespace() const { return eDVBNamespace(data[4]); }
119         void setDVBNamespace(eDVBNamespace dvbnamespace) { data[4]=dvbnamespace.get(); }
120
121         eServiceReferenceDVB(eDVBNamespace dvbnamespace, eTransportStreamID transport_stream_id, eOriginalNetworkID original_network_id, eServiceID service_id, int service_type)
122                 :eServiceReference(eServiceReference::idDVB, 0)
123         {
124                 setTransportStreamID(transport_stream_id);
125                 setOriginalNetworkID(original_network_id);
126                 setDVBNamespace(dvbnamespace);
127                 setServiceID(service_id);
128                 setServiceType(service_type);
129         }
130         
131         void set(const eDVBChannelID &chid)
132         {
133                 setDVBNamespace(chid.dvbnamespace);
134                 setOriginalNetworkID(chid.original_network_id);
135                 setTransportStreamID(chid.transport_stream_id);
136         }
137         
138         void getChannelID(eDVBChannelID &chid)
139         {
140                 chid = eDVBChannelID(getDVBNamespace(), getTransportStreamID(), getOriginalNetworkID());
141         }
142
143         eServiceReferenceDVB()
144                 :eServiceReference(eServiceReference::idDVB, 0)
145         {
146         }
147 };
148
149
150 class iDVBChannel;
151 class iDVBDemux;
152 class iDVBFrontendParameters;
153
154 class iDVBChannelList: public iObject
155 {
156 public:
157         virtual RESULT getChannelFrontendData(const eDVBChannelID &id, ePtr<iDVBFrontendParameters> &parm)=0;
158 };
159
160 class iDVBResourceManager: public iObject
161 {
162 public:
163         /*
164                         solange rumloopen bis eine resource gefunden wurde, die eine frequenz
165                         tunen will
166                         
167                         wenn natuerlich sowas schon vorhanden ist, dann einfach ne ref darauf
168                         geben. (zwei services auf dem gleichen transponder teilen sich einen
169                         channel)
170         */
171         virtual RESULT setChannelList(iDVBChannelList *list)=0;
172         virtual RESULT getChannelList(ePtr<iDVBChannelList> &list)=0;
173         virtual RESULT allocateChannel(const eDVBChannelID &channel, ePtr<iDVBChannel> &channel)=0;
174         virtual RESULT allocateRawChannel(ePtr<iDVBChannel> &channel)=0;
175         virtual RESULT allocatePVRChannel(int caps)=0;
176 };
177
178 class SatelliteDeliverySystemDescriptor;
179 class CableDeliverySystemDescriptor;
180 class TerrestrialDeliverySystemDescriptor;
181
182 struct eDVBFrontendParametersSatellite
183 {
184         struct Polarisation
185         {
186                 enum {
187                         Horizontal, Vertical, CircularLeft, CircularRight
188                 };
189         };
190         struct Inversion
191         {
192                 enum {
193                         On, Off, Unknown
194                 };
195         };
196         struct FEC
197         {
198                 enum {
199                         fNone, f1_2, f2_3, f3_4, f5_6, f7_8, fAuto
200                 };
201         };
202         unsigned int frequency, symbol_rate;
203         int polarisation, fec, inversion, orbital_position;
204         
205         void set(const SatelliteDeliverySystemDescriptor  &);
206 };
207
208 struct eDVBFrontendParametersCable
209 {
210         unsigned int frequency, symbol_rate;
211         int modulation, inversion, fec_inner;
212         void set(const CableDeliverySystemDescriptor  &);
213 };
214
215 struct eDVBFrontendParametersTerrestrial
216 {
217         int unknown;
218         void set(const TerrestrialDeliverySystemDescriptor  &);
219 };
220
221 class iDVBFrontendParameters: public iObject
222 {
223 public:
224         virtual RESULT getSystem(int &type) const = 0;
225         virtual RESULT getDVBS(eDVBFrontendParametersSatellite &p) const = 0;
226         virtual RESULT getDVBC(eDVBFrontendParametersCable &p) const = 0;
227         virtual RESULT getDVBT(eDVBFrontendParametersTerrestrial &p) const = 0;
228         
229         virtual RESULT calculateDifference(const iDVBFrontendParameters *parm, int &diff) const = 0;
230         virtual RESULT getHash(unsigned long &hash) const = 0;
231 };
232
233 #define MAX_DISEQC_LENGTH  16
234
235 struct eDVBDiseqcCommand
236 {
237         int len;
238         __u8 data[MAX_DISEQC_LENGTH];
239 };
240
241 class iDVBSatelliteEquipmentControl;
242
243 class iDVBFrontend: public iObject
244 {
245 public:
246         enum {
247                 feSatellite, feCable, feTerrestrial
248         };
249         virtual RESULT getFrontendType(int &type)=0;
250         virtual RESULT tune(const iDVBFrontendParameters &where)=0;
251         virtual RESULT connectStateChange(const Slot1<void,iDVBFrontend*> &stateChange, ePtr<eConnection> &connection)=0;
252         enum {
253                 stateIdle = 0,
254                 stateTuning = 1,
255                 stateFailed = 2,
256                 stateLock = 3
257         };
258         virtual RESULT getState(int &state)=0;
259         enum {
260                 toneOn, toneOff
261         };
262         virtual RESULT setTone(int tone)=0;
263         enum {
264                 voltageOff, voltage13, voltage18
265         };
266         virtual RESULT setVoltage(int voltage)=0;
267         virtual RESULT sendDiseqc(const eDVBDiseqcCommand &diseqc)=0;
268         virtual RESULT setSEC(iDVBSatelliteEquipmentControl *sec)=0;
269 };
270
271 class iDVBSatelliteEquipmentControl: public iObject
272 {
273 public:
274 #if HAVE_DVB_API_VERSION < 3
275         virtual RESULT prepare(iDVBFrontend &frontend, FrontendParameters &parm, eDVBFrontendParametersSatellite &sat)=0;
276 #else
277         virtual RESULT prepare(iDVBFrontend &frontend, struct dvb_frontend_parameters &parm, eDVBFrontendParametersSatellite &sat)=0;
278 #endif
279 };
280
281 struct eDVBCIRouting
282 {
283         int enabled;
284 };
285
286 class iDVBChannel: public iObject
287 {
288 public:
289         enum
290         {
291                 state_idle,        /* not yet tuned */
292                 state_tuning,      /* currently tuning (first time) */
293                 state_unavailable, /* currently unavailable, will be back without further interaction */
294                 state_ok           /* ok */
295         };
296         virtual RESULT connectStateChange(const Slot1<void,iDVBChannel*> &stateChange, ePtr<eConnection> &connection)=0;
297         virtual RESULT getState(int &state)=0;
298         enum
299         {
300                 cap_decode,
301                 cap_ci
302         };
303         virtual RESULT setCIRouting(const eDVBCIRouting &routing)=0;
304         virtual RESULT getDemux(ePtr<iDVBDemux> &demux)=0;
305         
306                 /* direct frontend access for raw channels and/or status inquiries. */
307         virtual RESULT getFrontend(ePtr<iDVBFrontend> &frontend)=0;
308 };
309
310 class iDVBSectionReader;
311 class iTSMPEGDecoder;
312
313 class iDVBDemux: public iObject
314 {
315 public:
316         virtual RESULT createSectionReader(eMainloop *context, ePtr<iDVBSectionReader> &reader)=0;
317         virtual RESULT getMPEGDecoder(ePtr<iTSMPEGDecoder> &reader)=0;
318 };
319
320 class iTSMPEGDecoder: public iObject
321 {
322 public:
323         enum { pidDisabled = -1 };
324                 /** Set Displayed Video PID */
325         virtual RESULT setVideoPID(int vpid)=0;
326
327         enum { af_MPEG, af_AC3, af_DTS };
328                 /** Set Displayed Audio PID and type */
329         virtual RESULT setAudioPID(int apid, int type)=0;
330
331                 /** Set Sync mode to PCR */
332         virtual RESULT setSyncPCR(int pcrpid)=0;
333         enum { sm_Audio, sm_Video };
334                 /** Set Sync mode to either audio or video master */
335         virtual RESULT setSyncMaster(int who)=0;
336         
337                 /** Apply settings */
338         virtual RESULT start()=0;
339         
340                 /** Freeze frame. Either continue decoding (without display) or halt. */
341         virtual RESULT freeze(int cont)=0;
342                 /** Continue after freeze. */
343         virtual RESULT unfreeze()=0;
344         
345                 // stop on .. Picture
346         enum { spm_I, spm_Ref, spm_Any };
347                 /** Stop on specific decoded picture. For I-Frame display. */
348         virtual RESULT setSinglePictureMode(int when)=0;
349         
350         enum { pkm_B, pkm_PB };
351                 /** Fast forward by skipping either B or P/B pictures */
352         virtual RESULT setPictureSkipMode(int what)=0;
353         
354                 /** Slow Motion by repeating pictures */
355         virtual RESULT setSlowMotion(int repeat)=0;
356         
357         enum { zoom_Normal, zoom_PanScan, zoom_Letterbox, zoom_Fullscreen };
358                 /** Set Zoom. mode *must* be fitting. */
359         virtual RESULT setZoom(int what)=0;
360 };
361
362 #endif