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>
32 std::string m_bouquet_name;
33 std::string m_filename; // without path.. just name
34 typedef std::list<eServiceReference> list;
36 // the following five methods are implemented in db.cpp
37 RESULT flushChanges();
38 RESULT addService(const eServiceReference &, eServiceReference before=eServiceReference());
39 RESULT removeService(const eServiceReference &);
40 RESULT moveService(const eServiceReference &, unsigned int);
41 RESULT setListName(const std::string &name);
44 /* these structures have by intention no operator int() defined.
45 the reason of these structures is to avoid mixing for example
46 a onid and a tsid (as there's no general order for them).
48 defining an operator int() would implicitely convert values
49 between them over the constructor with the int argument.
51 'explicit' doesn't here - eTransportStreamID(eOriginalNetworkID(n))
54 struct eTransportStreamID
59 int get() const { return v; }
60 eTransportStreamID(int i): v(i) { }
61 eTransportStreamID(): v(-1) { }
62 bool operator == (const eTransportStreamID &c) const { return v == c.v; }
63 bool operator != (const eTransportStreamID &c) const { return v != c.v; }
64 bool operator < (const eTransportStreamID &c) const { return v < c.v; }
65 bool operator > (const eTransportStreamID &c) const { return v > c.v; }
73 int get() const { return v; }
74 eServiceID(int i): v(i) { }
75 eServiceID(): v(-1) { }
76 bool operator == (const eServiceID &c) const { return v == c.v; }
77 bool operator != (const eServiceID &c) const { return v != c.v; }
78 bool operator < (const eServiceID &c) const { return v < c.v; }
79 bool operator > (const eServiceID &c) const { return v > c.v; }
82 struct eOriginalNetworkID
87 int get() const { return v; }
88 eOriginalNetworkID(int i): v(i) { }
89 eOriginalNetworkID(): v(-1) { }
90 bool operator == (const eOriginalNetworkID &c) const { return v == c.v; }
91 bool operator != (const eOriginalNetworkID &c) const { return v != c.v; }
92 bool operator < (const eOriginalNetworkID &c) const { return v < c.v; }
93 bool operator > (const eOriginalNetworkID &c) const { return v > c.v; }
101 int get() const { return v; }
102 eDVBNamespace(int i): v(i) { }
103 eDVBNamespace(): v(-1) { }
104 bool operator == (const eDVBNamespace &c) const { return v == c.v; }
105 bool operator != (const eDVBNamespace &c) const { return v != c.v; }
106 bool operator < (const eDVBNamespace &c) const { return v < c.v; }
107 bool operator > (const eDVBNamespace &c) const { return v > c.v; }
112 eDVBNamespace dvbnamespace;
113 eTransportStreamID transport_stream_id;
114 eOriginalNetworkID original_network_id;
116 bool operator==(const eDVBChannelID &c) const
118 return dvbnamespace == c.dvbnamespace &&
119 transport_stream_id == c.transport_stream_id &&
120 original_network_id == c.original_network_id;
123 bool operator<(const eDVBChannelID &c) const
125 if (dvbnamespace < c.dvbnamespace)
127 else if (dvbnamespace == c.dvbnamespace)
129 if (original_network_id < c.original_network_id)
131 else if (original_network_id == c.original_network_id)
132 if (transport_stream_id < c.transport_stream_id)
137 eDVBChannelID(eDVBNamespace dvbnamespace, eTransportStreamID tsid, eOriginalNetworkID onid):
138 dvbnamespace(dvbnamespace), transport_stream_id(tsid), original_network_id(onid)
142 dvbnamespace(-1), transport_stream_id(-1), original_network_id(-1)
145 operator bool() const
147 return (dvbnamespace != -1) && (transport_stream_id != -1) && (original_network_id != -1);
151 struct eServiceReferenceDVB: public eServiceReference
153 int getServiceType() const { return data[0]; }
154 void setServiceType(int service_type) { data[0]=service_type; }
156 eServiceID getServiceID() const { return eServiceID(data[1]); }
157 void setServiceID(eServiceID service_id) { data[1]=service_id.get(); }
159 eTransportStreamID getTransportStreamID() const { return eTransportStreamID(data[2]); }
160 void setTransportStreamID(eTransportStreamID transport_stream_id) { data[2]=transport_stream_id.get(); }
162 eOriginalNetworkID getOriginalNetworkID() const { return eOriginalNetworkID(data[3]); }
163 void setOriginalNetworkID(eOriginalNetworkID original_network_id) { data[3]=original_network_id.get(); }
165 eDVBNamespace getDVBNamespace() const { return eDVBNamespace(data[4]); }
166 void setDVBNamespace(eDVBNamespace dvbnamespace) { data[4]=dvbnamespace.get(); }
168 eServiceID getParentServiceID() const { return eServiceID(data[5]); }
169 void setParentServiceID( eServiceID sid ) { data[5]=sid.get(); }
171 eTransportStreamID getParentTransportStreamID() const { return eTransportStreamID(data[6]); }
172 void setParentTransportStreamID( eTransportStreamID tsid ) { data[6]=tsid.get(); }
174 eServiceReferenceDVB getParentServiceReference() const
176 eServiceReferenceDVB tmp(*this);
177 if (data[5] && data[6])
179 tmp.data[1] = data[5];
180 tmp.data[2] = data[6];
181 tmp.data[5] = tmp.data[6] = 0;
184 tmp.type = idInvalid;
188 eServiceReferenceDVB(eDVBNamespace dvbnamespace, eTransportStreamID transport_stream_id, eOriginalNetworkID original_network_id, eServiceID service_id, int service_type)
189 :eServiceReference(eServiceReference::idDVB, 0)
191 setTransportStreamID(transport_stream_id);
192 setOriginalNetworkID(original_network_id);
193 setDVBNamespace(dvbnamespace);
194 setServiceID(service_id);
195 setServiceType(service_type);
198 void set(const eDVBChannelID &chid)
200 setDVBNamespace(chid.dvbnamespace);
201 setOriginalNetworkID(chid.original_network_id);
202 setTransportStreamID(chid.transport_stream_id);
205 void getChannelID(eDVBChannelID &chid) const
207 chid = eDVBChannelID(getDVBNamespace(), getTransportStreamID(), getOriginalNetworkID());
210 eServiceReferenceDVB()
211 :eServiceReference(eServiceReference::idDVB, 0)
215 eServiceReferenceDVB(const std::string &string)
216 :eServiceReference(string)
222 ////////////////// TODO: we need an interface here, but what exactly?
225 // btw, still implemented in db.cpp. FIX THIS, TOO.
227 class eDVBChannelQuery;
229 class eDVBService: public iStaticServiceInformation
231 DECLARE_REF(eDVBService);
234 void copyCache(int *source);
238 cVPID, cAPID, cTPID, cPCRPID, cAC3PID,
239 cVTYPE, cACHANNEL, cAC3DELAY, cPCMDELAY,
243 int getCacheEntry(cacheID);
244 void setCacheEntry(cacheID, int);
249 /* m_service_name_sort is uppercase, with special chars removed, to increase sort performance. */
250 std::string m_service_name, m_service_name_sort;
251 std::string m_provider_name;
258 dxNoSDT=1, // don't get SDT
260 dxNoDVB=4, // dont use PMT for this service ( use cached pids )
265 bool usePMT() const { return !(m_flags & dxNoDVB); }
269 virtual ~eDVBService();
271 eDVBService &operator=(const eDVBService &);
273 // iStaticServiceInformation
274 RESULT getName(const eServiceReference &ref, std::string &name);
275 RESULT getEvent(const eServiceReference &ref, ePtr<eServiceEvent> &ptr, time_t start_time);
276 int isPlayable(const eServiceReference &ref, const eServiceReference &ignore);
279 int checkFilter(const eServiceReferenceDVB &ref, const eDVBChannelQuery &query);
286 class iDVBFrontendParameters;
288 class iDVBChannelListQuery: public iObject
291 virtual RESULT getNextResult(eServiceReferenceDVB &ref)=0;
292 virtual int compareLessEqual(const eServiceReferenceDVB &a, const eServiceReferenceDVB &b)=0;
295 class eDVBChannelQuery: public iObject
297 DECLARE_REF(eDVBChannelQuery);
316 std::string m_string;
318 eDVBChannelID m_channelid;
320 /* sort is only valid in root, and must be from the enum above. */
322 std::string m_bouquet_name;
324 static RESULT compile(ePtr<eDVBChannelQuery> &res, std::string query);
326 ePtr<eDVBChannelQuery> m_p1, m_p2;
329 class iDVBChannelList: public iObject
332 virtual RESULT removeService(const eServiceReference &service)=0;
333 virtual RESULT removeServices(eDVBChannelID chid=eDVBChannelID(), unsigned int orb_pos=0xFFFFFFFF)=0;
334 virtual RESULT removeServices(int dvb_namespace=-1, int tsid=-1, int onid=-1, unsigned int orb_pos=0xFFFFFFFF)=0;
335 virtual RESULT addFlag(const eServiceReference &service, unsigned int flagmask=0xFFFFFFFF)=0;
336 virtual RESULT removeFlag(const eServiceReference &service, unsigned int flagmask=0xFFFFFFFF)=0;
337 virtual RESULT removeFlags(unsigned int flagmask, eDVBChannelID chid=eDVBChannelID(), unsigned int orb_pos=0xFFFFFFFF)=0;
338 virtual RESULT removeFlags(unsigned int flagmask, int dvb_namespace=-1, int tsid=-1, int onid=-1, unsigned int orb_pos=0xFFFFFFFF)=0;
339 virtual RESULT addChannelToList(const eDVBChannelID &id, iDVBFrontendParameters *feparm)=0;
340 virtual RESULT removeChannel(const eDVBChannelID &id)=0;
342 virtual RESULT getChannelFrontendData(const eDVBChannelID &id, ePtr<iDVBFrontendParameters> &parm)=0;
344 virtual RESULT addService(const eServiceReferenceDVB &service, eDVBService *service)=0;
345 virtual RESULT getService(const eServiceReferenceDVB &reference, ePtr<eDVBService> &service)=0;
346 virtual RESULT flush()=0;
348 virtual RESULT getBouquet(const eServiceReference &ref, eBouquet* &bouquet)=0;
350 virtual RESULT startQuery(ePtr<iDVBChannelListQuery> &query, eDVBChannelQuery *query, const eServiceReference &source)=0;
355 class iDVBFrontendParameters: public iObject
358 iDVBFrontendParameters();
359 ~iDVBFrontendParameters();
362 virtual RESULT getSystem(int &SWIG_OUTPUT) const = 0;
363 virtual RESULT getDVBS(eDVBFrontendParametersSatellite &SWIG_OUTPUT) const = 0;
364 virtual RESULT getDVBC(eDVBFrontendParametersCable &SWIG_OUTPUT) const = 0;
365 virtual RESULT getDVBT(eDVBFrontendParametersTerrestrial &SWIG_OUTPUT) const = 0;
367 virtual RESULT calculateDifference(const iDVBFrontendParameters *parm, int &SWIG_OUTPUT, bool exact) const = 0;
368 virtual RESULT getHash(unsigned long &SWIG_OUTPUT) const = 0;
371 #define MAX_DISEQC_LENGTH 16
373 class eDVBDiseqcCommand
379 __u8 data[MAX_DISEQC_LENGTH];
380 #if HAVE_DVB_API_VERSION < 3
387 void setCommandString(const char *str);
390 class iDVBSatelliteEquipmentControl;
391 class eSecCommandList;
393 class iDVBFrontend: public iObject
397 feSatellite, feCable, feTerrestrial
399 virtual RESULT getFrontendType(int &SWIG_OUTPUT)=0;
400 virtual RESULT tune(const iDVBFrontendParameters &where)=0;
402 virtual RESULT connectStateChange(const Slot1<void,iDVBFrontend*> &stateChange, ePtr<eConnection> &connection)=0;
411 virtual RESULT getState(int &SWIG_OUTPUT)=0;
415 virtual RESULT setTone(int tone)=0;
417 voltageOff, voltage13, voltage18, voltage13_5, voltage18_5
419 virtual RESULT setVoltage(int voltage)=0;
420 virtual RESULT sendDiseqc(const eDVBDiseqcCommand &diseqc)=0;
421 virtual RESULT sendToneburst(int burst)=0;
423 virtual RESULT setSEC(iDVBSatelliteEquipmentControl *sec)=0;
424 virtual RESULT setSecSequence(const eSecCommandList &list)=0;
427 bitErrorRate, signalPower, signalQuality, locked, synced, frontendNumber
429 virtual int readFrontendData(int type)=0;
430 virtual PyObject *readTransponderData(bool original)=0;
433 virtual RESULT getData(int num, int &data)=0;
434 virtual RESULT setData(int num, int val)=0;
435 /* 0 means: not compatible. other values are a priority. */
436 virtual int isCompatibleWith(ePtr<iDVBFrontendParameters> &feparm)=0;
439 TEMPLATE_TYPEDEF(ePtr<iDVBFrontend>, iDVBFrontendPtr);
442 class iDVBSatelliteEquipmentControl: public iObject
445 virtual RESULT prepare(iDVBFrontend &frontend, FRONTENDPARAMETERS &parm, const eDVBFrontendParametersSatellite &sat, int frontend_id)=0;
446 virtual int canTune(const eDVBFrontendParametersSatellite &feparm, iDVBFrontend *fe, int frontend_id)=0;
447 virtual void setRotorMoving(bool)=0;
456 class iDVBChannel: public iObject
461 state_idle, /* not yet tuned */
462 state_tuning, /* currently tuning (first time) */
463 state_failed, /* tuning failed. */
464 state_unavailable, /* currently unavailable, will be back without further interaction */
466 state_last_instance, /* just one reference to this channel is left */
467 state_release /* channel is being shut down. */
469 virtual RESULT getState(int &SWIG_OUTPUT)=0;
471 /* direct frontend access for raw channels and/or status inquiries. */
472 virtual RESULT getFrontend(ePtr<iDVBFrontend> &)=0;
475 virtual RESULT getCurrentFrontendParameters(ePtr<iDVBFrontendParameters> &)=0;
478 evtEOF, evtSOF, evtFailed
480 virtual RESULT connectStateChange(const Slot1<void,iDVBChannel*> &stateChange, ePtr<eConnection> &connection)=0;
481 virtual RESULT connectEvent(const Slot2<void,iDVBChannel*,int> &eventChange, ePtr<eConnection> &connection)=0;
483 /* demux capabilities */
489 virtual RESULT setCIRouting(const eDVBCIRouting &routing)=0;
490 virtual RESULT getDemux(ePtr<iDVBDemux> &demux, int cap=0)=0;
492 /* use count handling */
493 virtual void AddUse() = 0;
494 virtual void ReleaseUse() = 0;
497 TEMPLATE_TYPEDEF(eUsePtr<iDVBChannel>, iDVBChannelPtr);
501 /* signed, so we can express deltas. */
503 typedef long long pts_t;
505 class iFilePushScatterGather;
506 class iTSMPEGDecoder;
508 /* note that a cue sheet describes the logical positions. thus
509 everything is specified in pts and not file positions */
511 /* implemented in dvb.cpp */
512 class eCueSheet: public iObject, public Object
514 DECLARE_REF(eCueSheet);
519 void seekTo(int relative, const pts_t &pts);
522 void addSourceSpan(const pts_t &begin, const pts_t &end);
525 void setSkipmode(const pts_t &ratio); /* 90000 is 1:1 */
526 void setDecodingDemux(iDVBDemux *demux, iTSMPEGDecoder *decoder);
528 /* frontend and backend */
532 enum { evtSeek, evtSkipmode, evtSpanChanged };
533 RESULT connectEvent(const Slot1<void, int> &event, ePtr<eConnection> &connection);
535 std::list<std::pair<pts_t,pts_t> > m_spans; /* begin, end */
536 std::list<std::pair<int, pts_t> > m_seek_requests; /* relative, delta */
537 pts_t m_skipmode_ratio;
538 Signal1<void,int> m_event;
539 ePtr<iDVBDemux> m_decoding_demux;
540 ePtr<iTSMPEGDecoder> m_decoder;
543 class iDVBPVRChannel: public iDVBChannel
548 state_eof = state_release + 1 /* end-of-file reached. */
551 /* FIXME: there are some very ugly buffer-end and ... related problems */
552 /* so this is VERY UGLY.
554 ok, it's going to get better. but still...*/
555 virtual RESULT playFile(const char *file) = 0;
556 virtual void stopFile() = 0;
558 virtual void setCueSheet(eCueSheet *cuesheet) = 0;
560 virtual RESULT getLength(pts_t &pts) = 0;
562 /* we explicitely ask for the decoding demux here because a channel
563 can be shared between multiple decoders.
565 virtual RESULT getCurrentPosition(iDVBDemux *decoding_demux, pts_t &pos, int mode) = 0;
566 /* skipping must be done with a cue sheet */
569 class iDVBSectionReader;
571 class iDVBTSRecorder;
572 class iTSMPEGDecoder;
574 class iDVBDemux: public iObject
577 virtual RESULT createSectionReader(eMainloop *context, ePtr<iDVBSectionReader> &reader)=0;
578 virtual RESULT createPESReader(eMainloop *context, ePtr<iDVBPESReader> &reader)=0;
579 virtual RESULT createTSRecorder(ePtr<iDVBTSRecorder> &recorder)=0;
580 virtual RESULT getMPEGDecoder(ePtr<iTSMPEGDecoder> &reader, int primary=1)=0;
581 virtual RESULT getSTC(pts_t &pts, int num=0)=0;
582 virtual RESULT getCADemuxID(uint8_t &id)=0;
583 virtual RESULT flush()=0;
586 class iTSMPEGDecoder: public iObject
589 enum { pidDisabled = -1 };
590 /** Set Displayed Video PID and type */
591 virtual RESULT setVideoPID(int vpid, int type)=0;
593 enum { af_MPEG, af_AC3, af_DTS, af_AAC };
594 /** Set Displayed Audio PID and type */
595 virtual RESULT setAudioPID(int apid, int type)=0;
597 enum { ac_left, ac_stereo, ac_right };
598 /** Set Displayed Audio Channel */
599 virtual RESULT setAudioChannel(int channel)=0;
600 virtual int getAudioChannel()=0;
602 virtual RESULT setPCMDelay(int delay)=0;
603 virtual int getPCMDelay()=0;
604 virtual RESULT setAC3Delay(int delay)=0;
605 virtual int getAC3Delay()=0;
607 /** Set Displayed Videotext PID */
608 virtual RESULT setTextPID(int vpid)=0;
610 /** Set Sync mode to PCR */
611 virtual RESULT setSyncPCR(int pcrpid)=0;
612 enum { sm_Audio, sm_Video };
613 /** Set Sync mode to either audio or video master */
614 virtual RESULT setSyncMaster(int who)=0;
616 /** Apply settings */
617 virtual RESULT start()=0;
619 /** Freeze frame. Either continue decoding (without display) or halt. */
620 virtual RESULT freeze(int cont)=0;
621 /** Continue after freeze. */
622 virtual RESULT unfreeze()=0;
624 /** fast forward by skipping frames. 0 is disabled, 2 is twice-the-speed, ... */
625 virtual RESULT setFastForward(int skip=0)=0;
627 // stop on .. Picture
628 enum { spm_I, spm_Ref, spm_Any };
629 /** Stop on specific decoded picture. For I-Frame display. */
630 virtual RESULT setSinglePictureMode(int when)=0;
632 enum { pkm_B, pkm_PB };
633 /** Fast forward by skipping either B or P/B pictures */
634 virtual RESULT setPictureSkipMode(int what)=0;
636 /** Slow Motion by repeating pictures */
637 virtual RESULT setSlowMotion(int repeat)=0;
639 enum { zoom_Normal, zoom_PanScan, zoom_Letterbox, zoom_Fullscreen };
640 /** Set Zoom. mode *must* be fitting. */
641 virtual RESULT setZoom(int what)=0;
643 virtual RESULT setTrickmode(int what) = 0;
645 virtual RESULT getPTS(int what, pts_t &pts) = 0;
647 virtual RESULT showSinglePic(const char *filename) = 0;
649 virtual RESULT setRadioPic(const std::string &filename) = 0;
653 enum { eventUnknown = 0, eventSizeChanged = VIDEO_EVENT_SIZE_CHANGED } type;
654 unsigned char aspect;
655 unsigned short height;
656 unsigned short width;
659 virtual RESULT connectVideoEvent(const Slot1<void, struct videoEvent> &event, ePtr<eConnection> &connection) = 0;