6 #if HAVE_DVB_API_VERSION < 3
7 #include <ost/frontend.h>
8 #define FRONTENDPARAMETERS FrontendParameters
10 #include <linux/dvb/frontend.h>
11 #include <linux/dvb/video.h>
12 #define FRONTENDPARAMETERS struct dvb_frontend_parameters
14 #include <lib/dvb/frontendparms.h>
15 #include <lib/base/object.h>
16 #include <lib/base/ebase.h>
17 #include <lib/base/elock.h>
18 #include <lib/service/service.h>
19 #include <libsig_comp.h>
20 #include <connection.h>
22 #if defined(__GNUC__) && ((__GNUC__ == 3 && __GNUC_MINOR__ >= 1) || __GNUC__ == 4 ) // check if gcc version >= 3.1
24 #define CAID_LIST __gnu_cxx::slist<uint16_t>
27 #define CAID_LIST std::slist<uint16_t>
30 #ifndef DMX_FILTER_SIZE
31 #define DMX_FILTER_SIZE 16
34 struct eDVBSectionFilterMask
37 /* mode is 0 for positive, 1 for negative filtering */
38 __u8 data[DMX_FILTER_SIZE], mask[DMX_FILTER_SIZE], mode[DMX_FILTER_SIZE];
48 int pid, tid, tidext, tid_mask, tidext_mask;
50 int timeout; /* timeout in ms */
55 tfAnyVersion filter ANY version
56 0 filter all EXCEPT given version (negative filtering)
57 tfThisVersion filter only THIS version
73 std::string m_bouquet_name;
74 std::string m_filename; // without path.. just name
75 typedef std::list<eServiceReference> list;
77 // the following five methods are implemented in db.cpp
78 RESULT flushChanges();
79 RESULT addService(const eServiceReference &, eServiceReference before=eServiceReference());
80 RESULT removeService(const eServiceReference &);
81 RESULT moveService(const eServiceReference &, unsigned int);
82 RESULT setListName(const std::string &name);
85 /* these structures have by intention no operator int() defined.
86 the reason of these structures is to avoid mixing for example
87 a onid and a tsid (as there's no general order for them).
89 defining an operator int() would implicitely convert values
90 between them over the constructor with the int argument.
92 'explicit' doesn't here - eTransportStreamID(eOriginalNetworkID(n))
95 struct eTransportStreamID
100 int get() const { return v; }
101 eTransportStreamID(int i): v(i) { }
102 eTransportStreamID(): v(-1) { }
103 bool operator == (const eTransportStreamID &c) const { return v == c.v; }
104 bool operator != (const eTransportStreamID &c) const { return v != c.v; }
105 bool operator < (const eTransportStreamID &c) const { return v < c.v; }
106 bool operator > (const eTransportStreamID &c) const { return v > c.v; }
114 int get() const { return v; }
115 eServiceID(int i): v(i) { }
116 eServiceID(): v(-1) { }
117 bool operator == (const eServiceID &c) const { return v == c.v; }
118 bool operator != (const eServiceID &c) const { return v != c.v; }
119 bool operator < (const eServiceID &c) const { return v < c.v; }
120 bool operator > (const eServiceID &c) const { return v > c.v; }
123 struct eOriginalNetworkID
128 int get() const { return v; }
129 eOriginalNetworkID(int i): v(i) { }
130 eOriginalNetworkID(): v(-1) { }
131 bool operator == (const eOriginalNetworkID &c) const { return v == c.v; }
132 bool operator != (const eOriginalNetworkID &c) const { return v != c.v; }
133 bool operator < (const eOriginalNetworkID &c) const { return v < c.v; }
134 bool operator > (const eOriginalNetworkID &c) const { return v > c.v; }
142 int get() const { return v; }
143 eDVBNamespace(int i): v(i) { }
144 eDVBNamespace(): v(-1) { }
145 bool operator == (const eDVBNamespace &c) const { return v == c.v; }
146 bool operator != (const eDVBNamespace &c) const { return v != c.v; }
147 bool operator < (const eDVBNamespace &c) const { return v < c.v; }
148 bool operator > (const eDVBNamespace &c) const { return v > c.v; }
153 eDVBNamespace dvbnamespace;
154 eTransportStreamID transport_stream_id;
155 eOriginalNetworkID original_network_id;
157 bool operator==(const eDVBChannelID &c) const
159 return dvbnamespace == c.dvbnamespace &&
160 transport_stream_id == c.transport_stream_id &&
161 original_network_id == c.original_network_id;
164 bool operator<(const eDVBChannelID &c) const
166 if (dvbnamespace < c.dvbnamespace)
168 else if (dvbnamespace == c.dvbnamespace)
170 if (original_network_id < c.original_network_id)
172 else if (original_network_id == c.original_network_id)
173 if (transport_stream_id < c.transport_stream_id)
178 eDVBChannelID(eDVBNamespace dvbnamespace, eTransportStreamID tsid, eOriginalNetworkID onid):
179 dvbnamespace(dvbnamespace), transport_stream_id(tsid), original_network_id(onid)
183 dvbnamespace(-1), transport_stream_id(-1), original_network_id(-1)
186 operator bool() const
188 return (dvbnamespace != -1) && (transport_stream_id != -1) && (original_network_id != -1);
192 struct eServiceReferenceDVB: public eServiceReference
194 int getServiceType() const { return data[0]; }
195 void setServiceType(int service_type) { data[0]=service_type; }
197 eServiceID getServiceID() const { return eServiceID(data[1]); }
198 void setServiceID(eServiceID service_id) { data[1]=service_id.get(); }
200 eTransportStreamID getTransportStreamID() const { return eTransportStreamID(data[2]); }
201 void setTransportStreamID(eTransportStreamID transport_stream_id) { data[2]=transport_stream_id.get(); }
203 eOriginalNetworkID getOriginalNetworkID() const { return eOriginalNetworkID(data[3]); }
204 void setOriginalNetworkID(eOriginalNetworkID original_network_id) { data[3]=original_network_id.get(); }
206 eDVBNamespace getDVBNamespace() const { return eDVBNamespace(data[4]); }
207 void setDVBNamespace(eDVBNamespace dvbnamespace) { data[4]=dvbnamespace.get(); }
209 eServiceID getParentServiceID() const { return eServiceID(data[5]); }
210 void setParentServiceID( eServiceID sid ) { data[5]=sid.get(); }
212 eTransportStreamID getParentTransportStreamID() const { return eTransportStreamID(data[6]); }
213 void setParentTransportStreamID( eTransportStreamID tsid ) { data[6]=tsid.get(); }
215 eServiceReferenceDVB getParentServiceReference() const
217 eServiceReferenceDVB tmp(*this);
218 if (data[5] && data[6])
220 tmp.data[1] = data[5];
221 tmp.data[2] = data[6];
222 tmp.data[5] = tmp.data[6] = 0;
225 tmp.type = idInvalid;
229 eServiceReferenceDVB(eDVBNamespace dvbnamespace, eTransportStreamID transport_stream_id, eOriginalNetworkID original_network_id, eServiceID service_id, int service_type)
230 :eServiceReference(eServiceReference::idDVB, 0)
232 setTransportStreamID(transport_stream_id);
233 setOriginalNetworkID(original_network_id);
234 setDVBNamespace(dvbnamespace);
235 setServiceID(service_id);
236 setServiceType(service_type);
239 void set(const eDVBChannelID &chid)
241 setDVBNamespace(chid.dvbnamespace);
242 setOriginalNetworkID(chid.original_network_id);
243 setTransportStreamID(chid.transport_stream_id);
246 void getChannelID(eDVBChannelID &chid) const
248 chid = eDVBChannelID(getDVBNamespace(), getTransportStreamID(), getOriginalNetworkID());
251 eServiceReferenceDVB()
252 :eServiceReference(eServiceReference::idDVB, 0)
256 eServiceReferenceDVB(const std::string &string)
257 :eServiceReference(string)
263 ////////////////// TODO: we need an interface here, but what exactly?
266 // btw, still implemented in db.cpp. FIX THIS, TOO.
268 class eDVBChannelQuery;
270 class eDVBService: public iStaticServiceInformation
272 DECLARE_REF(eDVBService);
275 void copyCache(int *source);
279 cVPID, cAPID, cTPID, cPCRPID, cAC3PID,
280 cVTYPE, cACHANNEL, cAC3DELAY, cPCMDELAY,
284 int getCacheEntry(cacheID);
285 void setCacheEntry(cacheID, int);
290 /* m_service_name_sort is uppercase, with special chars removed, to increase sort performance. */
291 std::string m_service_name, m_service_name_sort;
292 std::string m_provider_name;
299 dxNoSDT=1, // don't get SDT
301 dxNoDVB=4, // dont use PMT for this service ( use cached pids )
306 bool usePMT() const { return !(m_flags & dxNoDVB); }
307 bool isHidden() const { return m_flags & dxDontshow; }
311 virtual ~eDVBService();
313 eDVBService &operator=(const eDVBService &);
315 // iStaticServiceInformation
316 RESULT getName(const eServiceReference &ref, std::string &name);
317 RESULT getEvent(const eServiceReference &ref, ePtr<eServiceEvent> &ptr, time_t start_time);
318 int isPlayable(const eServiceReference &ref, const eServiceReference &ignore, bool simulate=false);
319 PyObject *getInfoObject(const eServiceReference &ref, int); // implemented in lib/service/servicedvb.h
322 int checkFilter(const eServiceReferenceDVB &ref, const eDVBChannelQuery &query);
329 class iDVBFrontendParameters;
331 class iDVBChannelListQuery: public iObject
334 virtual RESULT getNextResult(eServiceReferenceDVB &ref)=0;
335 virtual int compareLessEqual(const eServiceReferenceDVB &a, const eServiceReferenceDVB &b)=0;
338 class eDVBChannelQuery: public iObject
340 DECLARE_REF(eDVBChannelQuery);
359 std::string m_string;
361 eDVBChannelID m_channelid;
363 /* sort is only valid in root, and must be from the enum above. */
365 std::string m_bouquet_name;
367 static RESULT compile(ePtr<eDVBChannelQuery> &res, std::string query);
369 ePtr<eDVBChannelQuery> m_p1, m_p2;
372 class iDVBChannelList: public iObject
375 virtual RESULT removeService(const eServiceReference &service)=0;
376 virtual RESULT removeServices(eDVBChannelID chid=eDVBChannelID(), unsigned int orb_pos=0xFFFFFFFF)=0;
377 virtual RESULT removeServices(int dvb_namespace=-1, int tsid=-1, int onid=-1, unsigned int orb_pos=0xFFFFFFFF)=0;
378 virtual RESULT removeServices(iDVBFrontendParameters *feparm)=0;
379 virtual RESULT addFlag(const eServiceReference &service, unsigned int flagmask=0xFFFFFFFF)=0;
380 virtual RESULT removeFlag(const eServiceReference &service, unsigned int flagmask=0xFFFFFFFF)=0;
381 virtual RESULT removeFlags(unsigned int flagmask, eDVBChannelID chid=eDVBChannelID(), unsigned int orb_pos=0xFFFFFFFF)=0;
382 virtual RESULT removeFlags(unsigned int flagmask, int dvb_namespace=-1, int tsid=-1, int onid=-1, unsigned int orb_pos=0xFFFFFFFF)=0;
383 virtual RESULT addChannelToList(const eDVBChannelID &id, iDVBFrontendParameters *feparm)=0;
384 virtual RESULT removeChannel(const eDVBChannelID &id)=0;
386 virtual RESULT getChannelFrontendData(const eDVBChannelID &id, ePtr<iDVBFrontendParameters> &parm)=0;
388 virtual RESULT addService(const eServiceReferenceDVB &reference, eDVBService *service)=0;
389 virtual RESULT getService(const eServiceReferenceDVB &reference, ePtr<eDVBService> &service)=0;
390 virtual RESULT flush()=0;
392 virtual RESULT getBouquet(const eServiceReference &ref, eBouquet* &bouquet)=0;
394 virtual RESULT startQuery(ePtr<iDVBChannelListQuery> &query, eDVBChannelQuery *q, const eServiceReference &source)=0;
399 class iDVBFrontendParameters: public iObject
402 iDVBFrontendParameters();
403 ~iDVBFrontendParameters();
406 enum { flagOnlyFree = 1 };
407 virtual SWIG_VOID(RESULT) getSystem(int &SWIG_OUTPUT) const = 0;
408 virtual SWIG_VOID(RESULT) getDVBS(eDVBFrontendParametersSatellite &SWIG_OUTPUT) const = 0;
409 virtual SWIG_VOID(RESULT) getDVBC(eDVBFrontendParametersCable &SWIG_OUTPUT) const = 0;
410 virtual SWIG_VOID(RESULT) getDVBT(eDVBFrontendParametersTerrestrial &SWIG_OUTPUT) const = 0;
411 virtual SWIG_VOID(RESULT) getFlags(unsigned int &SWIG_OUTPUT) const = 0;
413 virtual SWIG_VOID(RESULT) calculateDifference(const iDVBFrontendParameters *parm, int &, bool exact) const = 0;
414 virtual SWIG_VOID(RESULT) getHash(unsigned long &) const = 0;
415 virtual SWIG_VOID(RESULT) calcLockTimeout(unsigned int &) const = 0;
418 SWIG_TEMPLATE_TYPEDEF(ePtr<iDVBFrontendParameters>, iDVBFrontendParametersPtr);
420 #define MAX_DISEQC_LENGTH 16
422 class eDVBDiseqcCommand
428 __u8 data[MAX_DISEQC_LENGTH];
429 #if HAVE_DVB_API_VERSION < 3
436 void setCommandString(const char *str);
439 class iDVBSatelliteEquipmentControl;
440 class eSecCommandList;
442 class iDVBFrontend_ENUMS
445 iDVBFrontend_ENUMS();
446 ~iDVBFrontend_ENUMS();
449 enum { feSatellite, feCable, feTerrestrial };
450 enum { stateIdle, stateTuning, stateFailed, stateLock, stateLostLock, stateClosed };
451 enum { toneOff, toneOn };
452 enum { voltageOff, voltage13, voltage18, voltage13_5, voltage18_5 };
453 enum { bitErrorRate, signalPower, signalQuality, locked, synced, frontendNumber, signalQualitydB };
456 SWIG_IGNORE(iDVBFrontend);
457 class iDVBFrontend: public iDVBFrontend_ENUMS, public iObject
460 virtual RESULT getFrontendType(int &SWIG_OUTPUT)=0;
461 virtual RESULT tune(const iDVBFrontendParameters &where)=0;
462 virtual int closeFrontend(bool force = false, bool no_delayed = false)=0;
463 virtual void reopenFrontend()=0;
465 virtual RESULT connectStateChange(const Slot1<void,iDVBFrontend*> &stateChange, ePtr<eConnection> &connection)=0;
467 virtual RESULT getState(int &SWIG_OUTPUT)=0;
468 virtual RESULT setTone(int tone)=0;
469 virtual RESULT setVoltage(int voltage)=0;
470 virtual RESULT sendDiseqc(const eDVBDiseqcCommand &diseqc)=0;
471 virtual RESULT sendToneburst(int burst)=0;
473 virtual RESULT setSEC(iDVBSatelliteEquipmentControl *sec)=0;
474 virtual RESULT setSecSequence(eSecCommandList &list)=0;
476 virtual int readFrontendData(int type)=0;
477 virtual void getFrontendStatus(SWIG_PYOBJECT(ePyObject) dest)=0;
478 virtual void getTransponderData(SWIG_PYOBJECT(ePyObject) dest, bool original)=0;
479 virtual void getFrontendData(SWIG_PYOBJECT(ePyObject) dest)=0;
481 virtual RESULT getData(int num, long &data)=0;
482 virtual RESULT setData(int num, long val)=0;
483 /* 0 means: not compatible. other values are a priority. */
484 virtual int isCompatibleWith(ePtr<iDVBFrontendParameters> &feparm)=0;
487 SWIG_TEMPLATE_TYPEDEF(ePtr<iDVBFrontend>, iDVBFrontendPtr);
490 class iDVBSatelliteEquipmentControl: public iObject
493 virtual RESULT prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, const eDVBFrontendParametersSatellite &sat, int frontend_id, unsigned int timeout)=0;
494 virtual void prepareTurnOffSatCR(iDVBFrontend &frontend, int satcr)=0;
495 virtual int canTune(const eDVBFrontendParametersSatellite &feparm, iDVBFrontend *fe, int frontend_id, int *highest_score_lnb=0)=0;
496 virtual void setRotorMoving(int slotid, bool)=0;
505 SWIG_IGNORE(iDVBChannel);
506 class iDVBChannel: public iObject
509 /* direct frontend access for raw channels and/or status inquiries. */
510 virtual SWIG_VOID(RESULT) getFrontend(ePtr<iDVBFrontend> &SWIG_OUTPUT)=0;
511 virtual RESULT requestTsidOnid(SWIG_PYOBJECT(ePyObject) callback) { return -1; }
512 virtual int reserveDemux() { return -1; }
516 state_idle, /* not yet tuned */
517 state_tuning, /* currently tuning (first time) */
518 state_failed, /* tuning failed. */
519 state_unavailable, /* currently unavailable, will be back without further interaction */
521 state_last_instance, /* just one reference to this channel is left */
522 state_release /* channel is being shut down. */
524 virtual RESULT getState(int &)=0;
526 virtual RESULT getCurrentFrontendParameters(ePtr<iDVBFrontendParameters> &)=0;
529 evtPreStart, evtEOF, evtSOF, evtFailed
531 virtual RESULT connectStateChange(const Slot1<void,iDVBChannel*> &stateChange, ePtr<eConnection> &connection)=0;
532 virtual RESULT connectEvent(const Slot2<void,iDVBChannel*,int> &eventChange, ePtr<eConnection> &connection)=0;
534 /* demux capabilities */
540 virtual RESULT setCIRouting(const eDVBCIRouting &routing)=0;
541 virtual RESULT getDemux(ePtr<iDVBDemux> &demux, int cap=0)=0;
543 /* use count handling */
544 virtual void AddUse() = 0;
545 virtual void ReleaseUse() = 0;
548 SWIG_TEMPLATE_TYPEDEF(eUsePtr<iDVBChannel>, iDVBChannelPtr);
551 /* signed, so we can express deltas. */
553 typedef long long pts_t;
555 class iFilePushScatterGather;
556 class iTSMPEGDecoder;
558 /* note that a cue sheet describes the logical positions. thus
559 everything is specified in pts and not file positions */
561 /* implemented in dvb.cpp */
562 class eCueSheet: public iObject, public Object
564 DECLARE_REF(eCueSheet);
569 void seekTo(int relative, const pts_t &pts);
572 void addSourceSpan(const pts_t &begin, const pts_t &end);
575 void setSkipmode(const pts_t &ratio); /* 90000 is 1:1 */
576 void setDecodingDemux(iDVBDemux *demux, iTSMPEGDecoder *decoder);
578 /* frontend and backend */
582 enum { evtSeek, evtSkipmode, evtSpanChanged };
583 RESULT connectEvent(const Slot1<void, int> &event, ePtr<eConnection> &connection);
585 std::list<std::pair<pts_t,pts_t> > m_spans; /* begin, end */
586 std::list<std::pair<int, pts_t> > m_seek_requests; /* relative, delta */
587 pts_t m_skipmode_ratio;
588 Signal1<void,int> m_event;
589 ePtr<iDVBDemux> m_decoding_demux;
590 ePtr<iTSMPEGDecoder> m_decoder;
593 class iDVBPVRChannel: public iDVBChannel
598 state_eof = state_release + 1 /* end-of-file reached. */
601 /* FIXME: there are some very ugly buffer-end and ... related problems */
602 /* so this is VERY UGLY.
604 ok, it's going to get better. but still...*/
605 virtual RESULT playFile(const char *file) = 0;
606 virtual void stopFile() = 0;
608 virtual void setCueSheet(eCueSheet *cuesheet) = 0;
610 virtual RESULT getLength(pts_t &pts) = 0;
612 /* we explicitely ask for the decoding demux here because a channel
613 can be shared between multiple decoders.
615 virtual RESULT getCurrentPosition(iDVBDemux *decoding_demux, pts_t &pos, int mode) = 0;
616 /* skipping must be done with a cue sheet */
619 class iDVBSectionReader;
621 class iDVBTSRecorder;
622 class iTSMPEGDecoder;
624 class iDVBDemux: public iObject
627 virtual RESULT createSectionReader(eMainloop *context, ePtr<iDVBSectionReader> &reader)=0;
628 virtual RESULT createPESReader(eMainloop *context, ePtr<iDVBPESReader> &reader)=0;
629 virtual RESULT createTSRecorder(ePtr<iDVBTSRecorder> &recorder)=0;
630 virtual RESULT getMPEGDecoder(ePtr<iTSMPEGDecoder> &reader, int primary=1)=0;
631 virtual RESULT getSTC(pts_t &pts, int num=0)=0;
632 virtual RESULT getCADemuxID(uint8_t &id)=0;
633 virtual RESULT flush()=0;
636 #if HAVE_DVB_API_VERSION < 3 && !defined(VIDEO_EVENT_SIZE_CHANGED)
637 #define VIDEO_EVENT_SIZE_CHANGED 1
638 #define VIDEO_EVENT_FRAME_RATE_CHANGED 2
641 class iTSMPEGDecoder: public iObject
644 enum { pidDisabled = -1 };
645 /** Set Displayed Video PID and type */
646 virtual RESULT setVideoPID(int vpid, int type)=0;
648 enum { af_MPEG, af_AC3, af_DTS, af_AAC };
649 /** Set Displayed Audio PID and type */
650 virtual RESULT setAudioPID(int apid, int type)=0;
652 enum { ac_left, ac_stereo, ac_right };
653 /** Set Displayed Audio Channel */
654 virtual RESULT setAudioChannel(int channel)=0;
655 virtual int getAudioChannel()=0;
657 virtual RESULT setPCMDelay(int delay)=0;
658 virtual int getPCMDelay()=0;
659 virtual RESULT setAC3Delay(int delay)=0;
660 virtual int getAC3Delay()=0;
662 /** Set Displayed Videotext PID */
663 virtual RESULT setTextPID(int vpid)=0;
665 /** Set Sync mode to PCR */
666 virtual RESULT setSyncPCR(int pcrpid)=0;
667 enum { sm_Audio, sm_Video };
668 /** Set Sync mode to either audio or video master */
669 virtual RESULT setSyncMaster(int who)=0;
671 /** Apply settings but don't change state */
672 virtual RESULT set()=0;
673 /* all those apply settings, then transition to the given state */
676 virtual RESULT play()=0;
678 virtual RESULT pause()=0;
680 /** fast forward by skipping frames. 0 is disabled, 2 is twice-the-speed, ... */
681 virtual RESULT setFastForward(int skip=0)=0;
683 /** Slow Motion by repeating pictures */
684 virtual RESULT setSlowMotion(int repeat)=0;
686 /** Display any complete data as fast as possible */
687 virtual RESULT setTrickmode()=0;
689 virtual RESULT getPTS(int what, pts_t &pts) = 0;
691 virtual RESULT showSinglePic(const char *filename) = 0;
693 virtual RESULT setRadioPic(const std::string &filename) = 0;
697 enum { eventUnknown = 0,
698 eventSizeChanged = VIDEO_EVENT_SIZE_CHANGED,
699 eventFrameRateChanged = VIDEO_EVENT_FRAME_RATE_CHANGED,
700 eventProgressiveChanged = 16
702 unsigned char aspect;
703 unsigned short height;
704 unsigned short width;
706 unsigned short framerate;
709 virtual RESULT connectVideoEvent(const Slot1<void, struct videoEvent> &event, ePtr<eConnection> &connection) = 0;
711 virtual int getVideoWidth() = 0;
712 virtual int getVideoHeight() = 0;
713 virtual int getVideoProgressive() = 0;
714 virtual int getVideoFrameRate() = 0;
715 virtual int getVideoAspect() = 0;