- added iStaticServiceInformation
[vuplus_dvbapp] / 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;
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;
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 getChannelFrontendData(const eDVBChannelID &id, ePtr<iDVBFrontendParameters> &parm)=0;
227         virtual RESULT getService(const eServiceReferenceDVB &reference, ePtr<eDVBService> &service)=0;
228         virtual RESULT startQuery(ePtr<iDVBChannelListQuery> &query, eDVBChannelQuery *query)=0;
229 };
230
231 class iDVBResourceManager: public iObject
232 {
233 public:
234         /*
235                         solange rumloopen bis eine resource gefunden wurde, die eine frequenz
236                         tunen will
237                         
238                         wenn natuerlich sowas schon vorhanden ist, dann einfach ne ref darauf
239                         geben. (zwei services auf dem gleichen transponder teilen sich einen
240                         channel)
241         */
242         virtual RESULT setChannelList(iDVBChannelList *list)=0;
243         virtual RESULT getChannelList(ePtr<iDVBChannelList> &list)=0;
244         virtual RESULT allocateChannel(const eDVBChannelID &channel, ePtr<iDVBChannel> &channel)=0;
245         virtual RESULT allocateRawChannel(ePtr<iDVBChannel> &channel)=0;
246         virtual RESULT allocatePVRChannel(int caps)=0;
247 };
248
249 class SatelliteDeliverySystemDescriptor;
250 class CableDeliverySystemDescriptor;
251 class TerrestrialDeliverySystemDescriptor;
252
253 struct eDVBFrontendParametersSatellite
254 {
255         struct Polarisation
256         {
257                 enum {
258                         Horizontal, Vertical, CircularLeft, CircularRight
259                 };
260         };
261         struct Inversion
262         {
263                 enum {
264                         On, Off, Unknown
265                 };
266         };
267         struct FEC
268         {
269                 enum {
270                         fNone, f1_2, f2_3, f3_4, f5_6, f7_8, fAuto
271                 };
272         };
273         unsigned int frequency, symbol_rate;
274         int polarisation, fec, inversion, orbital_position;
275         
276         void set(const SatelliteDeliverySystemDescriptor  &);
277 };
278
279 struct eDVBFrontendParametersCable
280 {
281         unsigned int frequency, symbol_rate;
282         int modulation, inversion, fec_inner;
283         void set(const CableDeliverySystemDescriptor  &);
284 };
285
286 struct eDVBFrontendParametersTerrestrial
287 {
288         int unknown;
289         void set(const TerrestrialDeliverySystemDescriptor  &);
290 };
291
292 class iDVBFrontendParameters: public iObject
293 {
294 public:
295         virtual RESULT getSystem(int &type) const = 0;
296         virtual RESULT getDVBS(eDVBFrontendParametersSatellite &p) const = 0;
297         virtual RESULT getDVBC(eDVBFrontendParametersCable &p) const = 0;
298         virtual RESULT getDVBT(eDVBFrontendParametersTerrestrial &p) const = 0;
299         
300         virtual RESULT calculateDifference(const iDVBFrontendParameters *parm, int &diff) const = 0;
301         virtual RESULT getHash(unsigned long &hash) const = 0;
302 };
303
304 #define MAX_DISEQC_LENGTH  16
305
306 struct eDVBDiseqcCommand
307 {
308         int len;
309         __u8 data[MAX_DISEQC_LENGTH];
310 };
311
312 class iDVBSatelliteEquipmentControl;
313
314 class iDVBFrontend: public iObject
315 {
316 public:
317         enum {
318                 feSatellite, feCable, feTerrestrial
319         };
320         virtual RESULT getFrontendType(int &type)=0;
321         virtual RESULT tune(const iDVBFrontendParameters &where)=0;
322         virtual RESULT connectStateChange(const Slot1<void,iDVBFrontend*> &stateChange, ePtr<eConnection> &connection)=0;
323         enum {
324                 stateIdle = 0,
325                 stateTuning = 1,
326                 stateFailed = 2,
327                 stateLock = 3
328         };
329         virtual RESULT getState(int &state)=0;
330         enum {
331                 toneOn, toneOff
332         };
333         virtual RESULT setTone(int tone)=0;
334         enum {
335                 voltageOff, voltage13, voltage18
336         };
337         virtual RESULT setVoltage(int voltage)=0;
338         virtual RESULT sendDiseqc(const eDVBDiseqcCommand &diseqc)=0;
339         virtual RESULT setSEC(iDVBSatelliteEquipmentControl *sec)=0;
340 };
341
342 class iDVBSatelliteEquipmentControl: public iObject
343 {
344 public:
345         virtual RESULT prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, eDVBFrontendParametersSatellite &sat)=0;
346 };
347
348 struct eDVBCIRouting
349 {
350         int enabled;
351 };
352
353 class iDVBChannel: public iObject
354 {
355 public:
356         enum
357         {
358                 state_idle,        /* not yet tuned */
359                 state_tuning,      /* currently tuning (first time) */
360                 state_unavailable, /* currently unavailable, will be back without further interaction */
361                 state_ok           /* ok */
362         };
363         virtual RESULT connectStateChange(const Slot1<void,iDVBChannel*> &stateChange, ePtr<eConnection> &connection)=0;
364         virtual RESULT getState(int &state)=0;
365         enum
366         {
367                 cap_decode,
368                 cap_ci
369         };
370         virtual RESULT setCIRouting(const eDVBCIRouting &routing)=0;
371         virtual RESULT getDemux(ePtr<iDVBDemux> &demux)=0;
372         
373                 /* direct frontend access for raw channels and/or status inquiries. */
374         virtual RESULT getFrontend(ePtr<iDVBFrontend> &frontend)=0;
375 };
376
377 class iDVBSectionReader;
378 class iTSMPEGDecoder;
379
380 class iDVBDemux: public iObject
381 {
382 public:
383         virtual RESULT createSectionReader(eMainloop *context, ePtr<iDVBSectionReader> &reader)=0;
384         virtual RESULT getMPEGDecoder(ePtr<iTSMPEGDecoder> &reader)=0;
385 };
386
387 class iTSMPEGDecoder: public iObject
388 {
389 public:
390         enum { pidDisabled = -1 };
391                 /** Set Displayed Video PID */
392         virtual RESULT setVideoPID(int vpid)=0;
393
394         enum { af_MPEG, af_AC3, af_DTS };
395                 /** Set Displayed Audio PID and type */
396         virtual RESULT setAudioPID(int apid, int type)=0;
397
398                 /** Set Sync mode to PCR */
399         virtual RESULT setSyncPCR(int pcrpid)=0;
400         enum { sm_Audio, sm_Video };
401                 /** Set Sync mode to either audio or video master */
402         virtual RESULT setSyncMaster(int who)=0;
403         
404                 /** Apply settings */
405         virtual RESULT start()=0;
406         
407                 /** Freeze frame. Either continue decoding (without display) or halt. */
408         virtual RESULT freeze(int cont)=0;
409                 /** Continue after freeze. */
410         virtual RESULT unfreeze()=0;
411         
412                 // stop on .. Picture
413         enum { spm_I, spm_Ref, spm_Any };
414                 /** Stop on specific decoded picture. For I-Frame display. */
415         virtual RESULT setSinglePictureMode(int when)=0;
416         
417         enum { pkm_B, pkm_PB };
418                 /** Fast forward by skipping either B or P/B pictures */
419         virtual RESULT setPictureSkipMode(int what)=0;
420         
421                 /** Slow Motion by repeating pictures */
422         virtual RESULT setSlowMotion(int repeat)=0;
423         
424         enum { zoom_Normal, zoom_PanScan, zoom_Letterbox, zoom_Fullscreen };
425                 /** Set Zoom. mode *must* be fitting. */
426         virtual RESULT setZoom(int what)=0;
427 };
428
429 #endif