make eDVBResourceManager accessible from python (needed for allocate a raw iDVBChannel)
[vuplus_dvbapp] / lib / dvb / idvb.h
1 #ifndef __dvb_idvb_h
2 #define __dvb_idvb_h
3
4 #ifndef SWIG
5
6 #if HAVE_DVB_API_VERSION < 3
7 #include <ost/frontend.h>
8 #define FRONTENDPARAMETERS FrontendParameters
9 #else
10 #include <linux/dvb/frontend.h>
11 #define FRONTENDPARAMETERS struct dvb_frontend_parameters
12 #endif
13 #include <lib/dvb/frontendparms.h>
14 #include <lib/base/object.h>
15 #include <lib/base/ebase.h>
16 #include <lib/base/elock.h>
17 #include <lib/service/service.h>
18 #include <libsig_comp.h>
19 #include <connection.h>
20
21 struct eBouquet
22 {
23         std::string m_bouquet_name;
24         std::string m_filename;  // without path.. just name
25         typedef std::list<eServiceReference> list;
26         list m_services;
27 // the following five methods are implemented in db.cpp
28         RESULT flushChanges();
29         RESULT addService(const eServiceReference &);
30         RESULT removeService(const eServiceReference &);
31         RESULT moveService(const eServiceReference &, unsigned int);
32         RESULT setListName(const std::string &name);
33 };
34
35                 /* these structures have by intention no operator int() defined.
36                    the reason of these structures is to avoid mixing for example
37                    a onid and a tsid (as there's no general order for them).
38                    
39                    defining an operator int() would implicitely convert values
40                    between them over the constructor with the int argument.
41                    
42                    'explicit' doesn't here - eTransportStreamID(eOriginalNetworkID(n)) 
43                    would still work. */
44
45 struct eTransportStreamID
46 {
47 private:
48         int v;
49 public:
50         int get() const { return v; }
51         eTransportStreamID(int i): v(i) { }
52         eTransportStreamID(): v(-1) { }
53         bool operator == (const eTransportStreamID &c) const { return v == c.v; }
54         bool operator != (const eTransportStreamID &c) const { return v != c.v; }
55         bool operator < (const eTransportStreamID &c) const { return v < c.v; }
56         bool operator > (const eTransportStreamID &c) const { return v > c.v; }
57 };
58
59 struct eServiceID
60 {
61 private:
62         int v;
63 public:
64         int get() const { return v; }
65         eServiceID(int i): v(i) { }
66         eServiceID(): v(-1) { }
67         bool operator == (const eServiceID &c) const { return v == c.v; }
68         bool operator != (const eServiceID &c) const { return v != c.v; }
69         bool operator < (const eServiceID &c) const { return v < c.v; }
70         bool operator > (const eServiceID &c) const { return v > c.v; }
71 };
72
73 struct eOriginalNetworkID
74 {
75 private:
76         int v;
77 public:
78         int get() const { return v; }
79         eOriginalNetworkID(int i): v(i) { }
80         eOriginalNetworkID(): v(-1) { }
81         bool operator == (const eOriginalNetworkID &c) const { return v == c.v; }
82         bool operator != (const eOriginalNetworkID &c) const { return v != c.v; }
83         bool operator < (const eOriginalNetworkID &c) const { return v < c.v; }
84         bool operator > (const eOriginalNetworkID &c) const { return v > c.v; }
85 };
86
87 struct eDVBNamespace
88 {
89 private:
90         int v;
91 public:
92         int get() const { return v; }
93         eDVBNamespace(int i): v(i) { }
94         eDVBNamespace(): v(-1) { }
95         bool operator == (const eDVBNamespace &c) const { return v == c.v; }
96         bool operator != (const eDVBNamespace &c) const { return v != c.v; }
97         bool operator < (const eDVBNamespace &c) const { return v < c.v; }
98         bool operator > (const eDVBNamespace &c) const { return v > c.v; }
99 };
100
101 struct eDVBChannelID
102 {
103         eDVBNamespace dvbnamespace;
104         eTransportStreamID transport_stream_id;
105         eOriginalNetworkID original_network_id;
106         
107         bool operator==(const eDVBChannelID &c) const
108         {
109                 return dvbnamespace == c.dvbnamespace &&
110                         transport_stream_id == c.transport_stream_id &&
111                         original_network_id == c.original_network_id;
112         }
113         
114         bool operator<(const eDVBChannelID &c) const
115         {
116                 if (dvbnamespace < c.dvbnamespace)
117                         return 1;
118                 else if (dvbnamespace == c.dvbnamespace)
119                 {
120                         if (original_network_id < c.original_network_id)
121                                 return 1;
122                         else if (original_network_id == c.original_network_id)
123                                 if (transport_stream_id < c.transport_stream_id)
124                                         return 1;
125                 }
126                 return 0;
127         }
128         eDVBChannelID(eDVBNamespace dvbnamespace, eTransportStreamID tsid, eOriginalNetworkID onid): 
129                         dvbnamespace(dvbnamespace), transport_stream_id(tsid), original_network_id(onid)
130         {
131         }
132         eDVBChannelID():
133                         dvbnamespace(-1), transport_stream_id(-1), original_network_id(-1)
134         {
135         }
136         operator bool() const
137         {
138                 return (dvbnamespace != -1) && (transport_stream_id != -1) && (original_network_id != -1);
139         }
140 };
141
142 struct eServiceReferenceDVB: public eServiceReference
143 {
144         int getServiceType() const { return data[0]; }
145         void setServiceType(int service_type) { data[0]=service_type; }
146
147         eServiceID getServiceID() const { return eServiceID(data[1]); }
148         void setServiceID(eServiceID service_id) { data[1]=service_id.get(); }
149
150         eTransportStreamID getTransportStreamID() const { return eTransportStreamID(data[2]); }
151         void setTransportStreamID(eTransportStreamID transport_stream_id) { data[2]=transport_stream_id.get(); }
152
153         eOriginalNetworkID getOriginalNetworkID() const { return eOriginalNetworkID(data[3]); }
154         void setOriginalNetworkID(eOriginalNetworkID original_network_id) { data[3]=original_network_id.get(); }
155
156         eDVBNamespace getDVBNamespace() const { return eDVBNamespace(data[4]); }
157         void setDVBNamespace(eDVBNamespace dvbnamespace) { data[4]=dvbnamespace.get(); }
158
159         eServiceID getParentServiceID() const { return eServiceID(data[5]); }
160         void setParentServiceID( eServiceID sid ) { data[5]=sid.get(); }
161
162         eTransportStreamID getParentTransportStreamID() const { return eTransportStreamID(data[6]); }
163         void setParentTransportStreamID( eTransportStreamID tsid ) { data[6]=tsid.get(); }
164
165         eServiceReferenceDVB(eDVBNamespace dvbnamespace, eTransportStreamID transport_stream_id, eOriginalNetworkID original_network_id, eServiceID service_id, int service_type)
166                 :eServiceReference(eServiceReference::idDVB, 0)
167         {
168                 setTransportStreamID(transport_stream_id);
169                 setOriginalNetworkID(original_network_id);
170                 setDVBNamespace(dvbnamespace);
171                 setServiceID(service_id);
172                 setServiceType(service_type);
173         }
174         
175         void set(const eDVBChannelID &chid)
176         {
177                 setDVBNamespace(chid.dvbnamespace);
178                 setOriginalNetworkID(chid.original_network_id);
179                 setTransportStreamID(chid.transport_stream_id);
180         }
181         
182         void getChannelID(eDVBChannelID &chid) const
183         {
184                 chid = eDVBChannelID(getDVBNamespace(), getTransportStreamID(), getOriginalNetworkID());
185         }
186
187         eServiceReferenceDVB()
188                 :eServiceReference(eServiceReference::idDVB, 0)
189         {
190         }
191
192         eServiceReferenceDVB(const std::string &string)
193                 :eServiceReference(string)
194         {
195         }
196 };
197
198
199 ////////////////// TODO: we need an interface here, but what exactly?
200
201 #include <set>
202 // btw, still implemented in db.cpp. FIX THIS, TOO.
203
204 class eDVBChannelQuery;
205
206 class eDVBService: public iStaticServiceInformation
207 {
208         DECLARE_REF(eDVBService);
209 public:
210         enum cacheID
211         {
212                 cVPID, cAPID, cTPID, cPCRPID, cAC3PID, cacheMax
213         };
214
215         int getCachePID(cacheID);
216         void setCachePID(cacheID, int);
217         bool cacheEmpty() { return m_cache.empty(); }
218
219         eDVBService();
220                 /* m_service_name_sort is uppercase, with special chars removed, to increase sort performance. */
221         std::string m_service_name, m_service_name_sort;
222         std::string m_provider_name;
223         
224         void genSortName();
225         
226         int m_flags;
227         std::set<int> m_ca;
228         std::map<int,int> m_cache;
229         virtual ~eDVBService();
230         
231         eDVBService &operator=(const eDVBService &);
232         
233         // iStaticServiceInformation
234         RESULT getName(const eServiceReference &ref, std::string &name);
235         RESULT getEvent(const eServiceReference &ref, ePtr<eServiceEvent> &ptr, time_t start_time);
236         bool isPlayable(const eServiceReference &ref, const eServiceReference &ignore);
237
238                 /* for filtering: */
239         int checkFilter(const eServiceReferenceDVB &ref, const eDVBChannelQuery &query);
240 };
241
242 //////////////////
243
244 class iDVBChannel;
245 class iDVBDemux;
246 class iDVBFrontendParameters;
247
248 class iDVBChannelListQuery: public iObject
249 {
250 public:
251         virtual RESULT getNextResult(eServiceReferenceDVB &ref)=0;
252         virtual int compareLessEqual(const eServiceReferenceDVB &a, const eServiceReferenceDVB &b)=0;
253 };
254
255 class eDVBChannelQuery: public iObject
256 {
257         DECLARE_REF(eDVBChannelQuery);
258 public:
259         enum
260         {
261                 tName,
262                 tProvider,
263                 tType,
264                 tBouquet,
265                 tSatellitePosition,
266                 tChannelID,
267                 tAND,
268                 tOR
269         };
270         
271         int m_type;
272         int m_inverse;
273         
274         std::string m_string;
275         int m_int;
276         eDVBChannelID m_channelid;
277         
278                 /* sort is only valid in root, and must be from the enum above. */
279         int m_sort;
280         std::string m_bouquet_name;
281         
282         static RESULT compile(ePtr<eDVBChannelQuery> &res, std::string query);
283         
284         ePtr<eDVBChannelQuery> m_p1, m_p2;
285 };
286
287 class iDVBChannelList: public iObject
288 {
289 public:
290         virtual RESULT addChannelToList(const eDVBChannelID &id, iDVBFrontendParameters *feparm)=0;
291         virtual RESULT removeChannel(const eDVBChannelID &id)=0;
292         
293         virtual RESULT getChannelFrontendData(const eDVBChannelID &id, ePtr<iDVBFrontendParameters> &parm)=0;
294         
295         virtual RESULT addService(const eServiceReferenceDVB &service, eDVBService *service)=0;
296         virtual RESULT getService(const eServiceReferenceDVB &reference, ePtr<eDVBService> &service)=0;
297         virtual RESULT flush()=0;
298
299         virtual RESULT getBouquet(const eServiceReference &ref,  eBouquet* &bouquet)=0;
300
301         virtual RESULT startQuery(ePtr<iDVBChannelListQuery> &query, eDVBChannelQuery *query, const eServiceReference &source)=0;
302 };
303
304 #endif  // SWIG
305
306 class iDVBFrontendParameters: public iObject
307 {
308 #ifdef SWIG
309         iDVBFrontendParameters();
310         ~iDVBFrontendParameters();
311 #endif
312 public:
313         virtual RESULT getSystem(int &SWIG_OUTPUT) const = 0;
314         virtual RESULT getDVBS(eDVBFrontendParametersSatellite &SWIG_OUTPUT) const = 0;
315         virtual RESULT getDVBC(eDVBFrontendParametersCable &SWIG_OUTPUT) const = 0;
316         virtual RESULT getDVBT(eDVBFrontendParametersTerrestrial &SWIG_OUTPUT) const = 0;
317         
318         virtual RESULT calculateDifference(const iDVBFrontendParameters *parm, int &SWIG_OUTPUT) const = 0;
319         virtual RESULT getHash(unsigned long &SWIG_OUTPUT) const = 0;
320 };
321
322 #define MAX_DISEQC_LENGTH  16
323
324 class eDVBDiseqcCommand
325 {
326 public:
327         int len;
328 #ifndef SWIG
329         __u8 data[MAX_DISEQC_LENGTH];
330 #if HAVE_DVB_API_VERSION < 3
331         int tone;
332         int voltage;
333 #endif
334 #endif //SWIG
335         void setData(const char *str);
336 };
337
338 class iDVBSatelliteEquipmentControl;
339 class eSecCommandList;
340
341 class iDVBFrontend: public iObject
342 {
343 public:
344         enum {
345                 feSatellite, feCable, feTerrestrial
346         };
347         virtual RESULT getFrontendType(int &type)=0;
348         virtual RESULT tune(const iDVBFrontendParameters &where)=0;
349 #ifndef SWIG
350         virtual RESULT connectStateChange(const Slot1<void,iDVBFrontend*> &stateChange, ePtr<eConnection> &connection)=0;
351 #endif
352         enum {
353                 stateIdle = 0,
354                 stateTuning = 1,
355                 stateFailed = 2,
356                 stateLock = 3,
357                 stateLostLock = 4,
358         };
359         virtual RESULT getState(int &state)=0;
360         enum {
361                 toneOff, toneOn
362         };
363         virtual RESULT setTone(int tone)=0;
364         enum {
365                 voltageOff, voltage13, voltage18, voltage13_5, voltage18_5
366         };
367         virtual RESULT setVoltage(int voltage)=0;
368         virtual RESULT sendDiseqc(const eDVBDiseqcCommand &diseqc)=0;
369         virtual RESULT sendToneburst(int burst)=0;
370 #ifndef SWIG
371         virtual RESULT setSEC(iDVBSatelliteEquipmentControl *sec)=0;
372         virtual RESULT setSecSequence(const eSecCommandList &list)=0;
373 #endif
374         enum {
375                 bitErrorRate, signalPower, signalQuality, Locked, Synced
376         };
377         virtual int readFrontendData(int type)=0;
378         virtual PyObject *readTransponderData(bool original)=0;
379
380 #ifndef SWIG
381         virtual RESULT getData(int num, int &data)=0;
382         virtual RESULT setData(int num, int val)=0;
383                 /* 0 means: not compatible. other values are a priority. */
384         virtual int isCompatibleWith(ePtr<iDVBFrontendParameters> &feparm)=0;
385 #endif
386 };
387 TEMPLATE_TYPEDEF(ePtr<iDVBFrontend>, iDVBFrontendPtr);
388
389 #ifndef SWIG
390 class iDVBSatelliteEquipmentControl: public iObject
391 {
392 public:
393         virtual RESULT prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, const eDVBFrontendParametersSatellite &sat, int frontend_id)=0;
394         virtual int canTune(const eDVBFrontendParametersSatellite &feparm, iDVBFrontend *fe, int frontend_id)=0;
395         virtual void setRotorMoving(bool)=0;
396 };
397
398 struct eDVBCIRouting
399 {
400         int enabled;
401 };
402 #endif // SWIG
403
404 class iDVBChannel: public iObject
405 {
406 public:
407         enum
408         {
409                 state_idle,        /* not yet tuned */
410                 state_tuning,      /* currently tuning (first time) */
411                 state_failed,      /* tuning failed. */
412                 state_unavailable, /* currently unavailable, will be back without further interaction */
413                 state_ok,          /* ok */
414                 state_last_instance, /* just one reference to this channel is left */
415                 state_release      /* channel is being shut down. */
416         };
417         virtual RESULT getState(int &state)=0;  
418
419                 /* direct frontend access for raw channels and/or status inquiries. */
420         virtual RESULT getFrontend(ePtr<iDVBFrontend> &frontend)=0;
421
422 #ifndef SWIG
423         virtual RESULT getCurrentFrontendParameters(ePtr<iDVBFrontendParameters> &)=0;
424         enum 
425         {
426                 evtEOF, evtSOF, evtFailed
427         };
428         virtual RESULT connectStateChange(const Slot1<void,iDVBChannel*> &stateChange, ePtr<eConnection> &connection)=0;
429         virtual RESULT connectEvent(const Slot2<void,iDVBChannel*,int> &eventChange, ePtr<eConnection> &connection)=0;
430
431                 /* demux capabilities */
432         enum
433         {
434                 capDecode = 1,
435                 /* capCI = 2 */
436         };
437         virtual RESULT setCIRouting(const eDVBCIRouting &routing)=0;
438         virtual RESULT getDemux(ePtr<iDVBDemux> &demux, int cap=0)=0;
439         
440                 /* use count handling */
441         virtual void AddUse() = 0;
442         virtual void ReleaseUse() = 0;
443 #endif
444 };
445 TEMPLATE_TYPEDEF(ePtr<iDVBChannel>, iDVBChannelPtr);
446
447 #ifndef SWIG
448
449         /* signed, so we can express deltas. */
450         
451 typedef long long pts_t;
452
453 class iFilePushScatterGather;
454 class iTSMPEGDecoder;
455
456         /* note that a cue sheet describes the logical positions. thus 
457            everything is specified in pts and not file positions */
458
459         /* implemented in dvb.cpp */
460 class eCueSheet: public iObject, public Object
461 {
462         DECLARE_REF(eCueSheet);
463 public:
464         eCueSheet();
465         
466                         /* frontend */
467         void seekTo(int relative, const pts_t &pts);
468         
469         void clear();
470         void addSourceSpan(const pts_t &begin, const pts_t &end);
471         void commitSpans();
472         
473         void setSkipmode(const pts_t &ratio); /* 90000 is 1:1 */
474         void setDecodingDemux(iDVBDemux *demux, iTSMPEGDecoder *decoder);
475         
476                         /* frontend and backend */
477         eSingleLock m_lock;
478         
479                         /* backend */
480         enum { evtSeek, evtSkipmode, evtSpanChanged };
481         RESULT connectEvent(const Slot1<void, int> &event, ePtr<eConnection> &connection);
482
483         std::list<std::pair<pts_t,pts_t> > m_spans;     /* begin, end */
484         std::list<std::pair<int, pts_t> > m_seek_requests; /* relative, delta */
485         pts_t m_skipmode_ratio;
486         Signal1<void,int> m_event;
487         ePtr<iDVBDemux> m_decoding_demux;
488         ePtr<iTSMPEGDecoder> m_decoder;
489 };
490
491 class iDVBPVRChannel: public iDVBChannel
492 {
493 public:
494         enum
495         {
496                 state_eof = state_release + 1  /* end-of-file reached. */
497         };
498         
499                 /* FIXME: there are some very ugly buffer-end and ... related problems */
500                 /* so this is VERY UGLY. 
501                 
502                    ok, it's going to get better. but still...*/
503         virtual RESULT playFile(const char *file) = 0;
504         virtual void stopFile() = 0;
505         
506         virtual void setCueSheet(eCueSheet *cuesheet) = 0;
507         
508         virtual RESULT getLength(pts_t &pts) = 0;
509         
510                 /* we explicitely ask for the decoding demux here because a channel
511                    can be shared between multiple decoders.
512                 */
513         virtual RESULT getCurrentPosition(iDVBDemux *decoding_demux, pts_t &pos, int mode) = 0;
514                 /* skipping must be done with a cue sheet */
515 };
516
517 class iDVBSectionReader;
518 class iDVBTSRecorder;
519 class iTSMPEGDecoder;
520
521 class iDVBDemux: public iObject
522 {
523 public:
524         virtual RESULT createSectionReader(eMainloop *context, ePtr<iDVBSectionReader> &reader)=0;
525         virtual RESULT createTSRecorder(ePtr<iDVBTSRecorder> &recorder)=0;
526         virtual RESULT getMPEGDecoder(ePtr<iTSMPEGDecoder> &reader)=0;
527         virtual RESULT getSTC(pts_t &pts, int num=0)=0;
528         virtual RESULT getCADemuxID(uint8_t &id)=0;
529         virtual RESULT flush()=0;
530 };
531
532 class iTSMPEGDecoder: public iObject
533 {
534 public:
535         enum { pidDisabled = -1 };
536                 /** Set Displayed Video PID */
537         virtual RESULT setVideoPID(int vpid)=0;
538
539         enum { af_MPEG, af_AC3, af_DTS };
540                 /** Set Displayed Audio PID and type */
541         virtual RESULT setAudioPID(int apid, int type)=0;
542
543                 /** Set Displayed Videotext PID */
544         virtual RESULT setTextPID(int vpid)=0;
545
546                 /** Set Sync mode to PCR */
547         virtual RESULT setSyncPCR(int pcrpid)=0;
548         enum { sm_Audio, sm_Video };
549                 /** Set Sync mode to either audio or video master */
550         virtual RESULT setSyncMaster(int who)=0;
551
552                 /** Apply settings */
553         virtual RESULT start()=0;
554         
555                 /** Freeze frame. Either continue decoding (without display) or halt. */
556         virtual RESULT freeze(int cont)=0;
557                 /** Continue after freeze. */
558         virtual RESULT unfreeze()=0;
559         
560                 /** fast forward by skipping frames. 0 is disabled, 2 is twice-the-speed, ... */
561         virtual RESULT setFastForward(int skip=0)=0;
562         
563                 // stop on .. Picture
564         enum { spm_I, spm_Ref, spm_Any };
565                 /** Stop on specific decoded picture. For I-Frame display. */
566         virtual RESULT setSinglePictureMode(int when)=0;
567         
568         enum { pkm_B, pkm_PB };
569                 /** Fast forward by skipping either B or P/B pictures */
570         virtual RESULT setPictureSkipMode(int what)=0;
571         
572                 /** Slow Motion by repeating pictures */
573         virtual RESULT setSlowMotion(int repeat)=0;
574         
575         enum { zoom_Normal, zoom_PanScan, zoom_Letterbox, zoom_Fullscreen };
576                 /** Set Zoom. mode *must* be fitting. */
577         virtual RESULT setZoom(int what)=0;
578         
579         virtual RESULT setTrickmode(int what) = 0;
580         
581         virtual RESULT getPTS(int what, pts_t &pts) = 0;
582 };
583
584 #endif //SWIG
585 #endif