6 #include <lib/base/ebase.h>
7 #include <lib/base/filepush.h>
8 #include <lib/base/elock.h>
9 #include <lib/dvb/idvb.h>
10 #include <lib/dvb/demux.h>
11 #include <lib/dvb/frontend.h>
12 #include <lib/dvb/tstools.h>
13 #include <lib/dvb/esection.h>
14 #include <connection.h>
16 #include <dvbsi++/service_description_section.h>
20 /* we do NOT handle resource conflicts here. instead, the allocateChannel
21 fails, and the application has to see why the channel is allocated
22 (and how to deallocate it). */
25 class eDVBRegisteredFrontend: public iObject, public Object
27 DECLARE_REF(eDVBRegisteredFrontend);
31 if (!m_inuse && m_frontend->closeFrontend()) // frontend busy
32 disable->start(60000, true); // retry close in 60secs
35 Signal0<void> stateChanged;
36 eDVBRegisteredFrontend(eDVBFrontend *fe, iDVBAdapter *adap)
37 :disable(eTimer::create(eApp)), m_adapter(adap), m_frontend(fe), m_inuse(0)
39 CONNECT(disable->timeout, eDVBRegisteredFrontend::closeFrontend);
45 /* emit */ stateChanged();
46 disable->start(3000, true);
53 m_frontend->openFrontend();
54 /* emit */ stateChanged();
57 iDVBAdapter *m_adapter;
58 ePtr<eDVBFrontend> m_frontend;
62 struct eDVBRegisteredDemux
64 DECLARE_REF(eDVBRegisteredDemux);
66 iDVBAdapter *m_adapter;
67 ePtr<eDVBDemux> m_demux;
69 eDVBRegisteredDemux(eDVBDemux *demux, iDVBAdapter *adap): m_adapter(adap), m_demux(demux), m_inuse(0) { }
72 class eDVBAllocatedFrontend
74 DECLARE_REF(eDVBAllocatedFrontend);
77 eDVBAllocatedFrontend(eDVBRegisteredFrontend *fe);
78 ~eDVBAllocatedFrontend();
79 eDVBFrontend &get() { return *m_fe->m_frontend; }
80 operator eDVBRegisteredFrontend*() { return m_fe; }
81 operator eDVBFrontend*() { return m_fe->m_frontend; }
84 eDVBRegisteredFrontend *m_fe;
87 class eDVBAllocatedDemux
89 DECLARE_REF(eDVBAllocatedDemux);
92 eDVBAllocatedDemux(eDVBRegisteredDemux *demux);
93 ~eDVBAllocatedDemux();
94 eDVBDemux &get() { return *m_demux->m_demux; }
95 operator eDVBRegisteredDemux*() { return m_demux; }
96 operator eDVBDemux*() { return m_demux->m_demux; }
99 eDVBRegisteredDemux *m_demux;
102 class iDVBAdapter: public iObject
105 virtual int getNumDemux() = 0;
106 virtual RESULT getDemux(ePtr<eDVBDemux> &demux, int nr) = 0;
108 virtual int getNumFrontends() = 0;
109 virtual RESULT getFrontend(ePtr<eDVBFrontend> &fe, int nr, bool simulate=false) = 0;
112 class eDVBAdapterLinux: public iDVBAdapter
114 DECLARE_REF(eDVBAdapterLinux);
116 eDVBAdapterLinux(int nr);
119 RESULT getDemux(ePtr<eDVBDemux> &demux, int nr);
121 int getNumFrontends();
122 RESULT getFrontend(ePtr<eDVBFrontend> &fe, int nr, bool simulate=false);
124 static int exist(int nr);
127 eSmartPtrList<eDVBFrontend> m_frontend, m_simulate_frontend;
128 eSmartPtrList<eDVBDemux> m_demux;
132 SWIG_IGNORE(eDVBResourceManager);
133 class eDVBResourceManager: public iObject, public Object
135 DECLARE_REF(eDVBResourceManager);
138 eSmartPtrList<iDVBAdapter> m_adapter;
139 eSmartPtrList<eDVBRegisteredDemux> m_demux;
140 eSmartPtrList<eDVBRegisteredFrontend> m_frontend, m_simulate_frontend;
141 void addAdapter(iDVBAdapter *adapter);
143 struct active_channel
145 eDVBChannelID m_channel_id;
146 /* we don't hold a reference here. */
147 eDVBChannel *m_channel;
149 active_channel(const eDVBChannelID &chid, eDVBChannel *ch) : m_channel_id(chid), m_channel(ch) { }
152 std::list<active_channel> m_active_channels, m_active_simulate_channels;
154 ePtr<iDVBChannelList> m_list;
155 ePtr<iDVBSatelliteEquipmentControl> m_sec;
156 static eDVBResourceManager *instance;
158 friend class eDVBChannel;
159 RESULT addChannel(const eDVBChannelID &chid, eDVBChannel *ch);
160 RESULT removeChannel(eDVBChannel *ch);
162 Signal1<void,eDVBChannel*> m_channelAdded;
164 eUsePtr<iDVBChannel> m_cached_channel;
165 Connection m_cached_channel_state_changed_conn;
166 ePtr<eTimer> m_releaseCachedChannelTimer;
167 void DVBChannelStateChanged(iDVBChannel*);
168 void feStateChanged();
172 void releaseCachedChannel();
173 eDVBResourceManager();
174 virtual ~eDVBResourceManager();
176 RESULT setChannelList(iDVBChannelList *list);
177 RESULT getChannelList(ePtr<iDVBChannelList> &list);
180 /* errNoFrontend = -1 replaced by more spcific messages */
182 errChidNotFound = -3,
183 errNoChannelList = -4,
184 errChannelNotInList = -5,
185 errAllSourcesBusy = -6,
186 errNoSourceFound = -7,
189 RESULT connectChannelAdded(const Slot1<void,eDVBChannel*> &channelAdded, ePtr<eConnection> &connection);
190 int canAllocateChannel(const eDVBChannelID &channelid, const eDVBChannelID &ignore, bool simulate=false);
192 /* allocate channel... */
193 RESULT allocateChannel(const eDVBChannelID &channelid, eUsePtr<iDVBChannel> &channel, bool simulate=false);
194 RESULT allocatePVRChannel(eUsePtr<iDVBPVRChannel> &channel);
195 static RESULT getInstance(ePtr<eDVBResourceManager> &);
197 /* allocates a frontend able to tune to frontend paramters 'feperm'.
198 the frontend must be tuned lateron. there is no guarante
199 that tuning will succeed - it just means that if this frontend
200 can't tune, no other frontend could do it.
202 there might be a priority given to certain frontend/chid
203 combinations. this will be evaluated here. */
204 RESULT allocateFrontend(ePtr<eDVBAllocatedFrontend> &fe, ePtr<iDVBFrontendParameters> &feparm, bool simulate=false);
206 RESULT allocateFrontendByIndex(ePtr<eDVBAllocatedFrontend> &fe, int slot_index);
207 /* allocate a demux able to filter on the selected frontend. */
208 RESULT allocateDemux(eDVBRegisteredFrontend *fe, ePtr<eDVBAllocatedDemux> &demux, int cap);
212 int canAllocateFrontend(ePtr<iDVBFrontendParameters> &feparm, bool simulate=false);
213 bool canMeasureFrontendInputPower();
214 PSignal1<void,int> frontendUseMaskChanged;
215 SWIG_VOID(RESULT) allocateRawChannel(eUsePtr<iDVBChannel> &SWIG_OUTPUT, int slot_index);
216 PyObject *setFrontendSlotInformations(SWIG_PYOBJECT(ePyObject) list);
218 SWIG_TEMPLATE_TYPEDEF(ePtr<eDVBResourceManager>, eDVBResourceManager);
219 SWIG_EXTEND(ePtr<eDVBResourceManager>,
220 static ePtr<eDVBResourceManager> getInstance()
222 extern ePtr<eDVBResourceManager> NewResourceManagerPtr(void);
223 return NewResourceManagerPtr();
229 class eDVBChannelFilePush;
231 /* iDVBPVRChannel includes iDVBChannel. don't panic. */
232 class eDVBChannel: public iDVBPVRChannel, public iFilePushScatterGather, public Object
234 DECLARE_REF(eDVBChannel);
235 friend class eDVBResourceManager;
237 eDVBChannel(eDVBResourceManager *mgr, eDVBAllocatedFrontend *frontend);
238 virtual ~eDVBChannel();
240 /* only for managed channels - effectively tunes to the channelid. should not be used... */
241 /* cannot be used for PVR channels. */
242 RESULT setChannel(const eDVBChannelID &id, ePtr<iDVBFrontendParameters> &feparam);
243 eDVBChannelID getChannelID() { return m_channel_id; }
245 RESULT connectStateChange(const Slot1<void,iDVBChannel*> &stateChange, ePtr<eConnection> &connection);
246 RESULT connectEvent(const Slot2<void,iDVBChannel*,int> &eventChange, ePtr<eConnection> &connection);
248 RESULT getState(int &state);
250 RESULT setCIRouting(const eDVBCIRouting &routing);
251 RESULT getDemux(ePtr<iDVBDemux> &demux, int cap);
252 RESULT getFrontend(ePtr<iDVBFrontend> &frontend);
253 RESULT getCurrentFrontendParameters(ePtr<iDVBFrontendParameters> ¶m);
256 RESULT playFile(const char *file);
259 void setCueSheet(eCueSheet *cuesheet);
261 RESULT getLength(pts_t &len);
262 RESULT getCurrentPosition(iDVBDemux *decoding_demux, pts_t &pos, int mode);
264 int getUseCount() { return m_use_count; }
266 RESULT requestTsidOnid(ePyObject callback);
268 ePtr<eDVBAllocatedFrontend> m_frontend;
269 ePtr<eDVBAllocatedDemux> m_demux, m_decoder_demux;
271 ePtr<iDVBFrontendParameters> m_current_frontend_parameters;
272 eDVBChannelID m_channel_id;
273 Signal1<void,iDVBChannel*> m_stateChanged;
274 Signal2<void,iDVBChannel*,int> m_event;
277 /* for channel list */
278 ePtr<eDVBResourceManager> m_mgr;
280 void frontendStateChanged(iDVBFrontend*fe);
281 ePtr<eConnection> m_conn_frontendStateChanged;
283 /* for PVR playback */
284 eDVBChannelFilePush *m_pvr_thread;
285 void pvrEvent(int event);
288 eDVBTSTools m_tstools;
290 ePtr<eCueSheet> m_cue;
292 void cueSheetEvent(int event);
293 ePtr<eConnection> m_conn_cueSheetEvent;
294 int m_skipmode_m, m_skipmode_n;
296 std::list<std::pair<off_t, off_t> > m_source_span;
297 void getNextSourceSpan(off_t current_offset, size_t bytes_read, off_t &start, size_t &size);
298 void flushPVR(iDVBDemux *decoding_demux=0);
300 eSingleLock m_cuesheet_lock;
302 friend class eUsePtr<eDVBChannel>;
304 oRefCount m_use_count;
308 /* for tsid/onid read */
309 ePyObject m_tsid_onid_callback;
310 ePtr<iDVBDemux> m_tsid_onid_demux;
311 ePtr<eTable<ServiceDescriptionSection> > m_SDT;
312 void SDTready(int err);