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 <connection.h>
17 /* we do NOT handle resource conflicts here. instead, the allocateChannel
18 fails, and the application has to see why the channel is allocated
19 (and how to deallocate it). */
22 class eDVBRegisteredFrontend: public iObject, public Object
24 DECLARE_REF(eDVBRegisteredFrontend);
28 if (!m_inuse && m_frontend->closeFrontend()) // frontend busy
29 disable->start(60000, true); // retry close in 60secs
32 Signal0<void> stateChanged;
33 eDVBRegisteredFrontend(eDVBFrontend *fe, iDVBAdapter *adap)
34 :disable(eTimer::create(eApp)), m_adapter(adap), m_frontend(fe), m_inuse(0)
36 CONNECT(disable->timeout, eDVBRegisteredFrontend::closeFrontend);
42 /* emit */ stateChanged();
43 disable->start(3000, true);
50 m_frontend->openFrontend();
51 /* emit */ stateChanged();
54 iDVBAdapter *m_adapter;
55 ePtr<eDVBFrontend> m_frontend;
59 struct eDVBRegisteredDemux
61 DECLARE_REF(eDVBRegisteredDemux);
63 iDVBAdapter *m_adapter;
64 ePtr<eDVBDemux> m_demux;
66 eDVBRegisteredDemux(eDVBDemux *demux, iDVBAdapter *adap): m_adapter(adap), m_demux(demux), m_inuse(0) { }
69 class eDVBAllocatedFrontend
71 DECLARE_REF(eDVBAllocatedFrontend);
74 eDVBAllocatedFrontend(eDVBRegisteredFrontend *fe);
75 ~eDVBAllocatedFrontend();
76 eDVBFrontend &get() { return *m_fe->m_frontend; }
77 operator eDVBRegisteredFrontend*() { return m_fe; }
78 operator eDVBFrontend*() { return m_fe->m_frontend; }
81 eDVBRegisteredFrontend *m_fe;
84 class eDVBAllocatedDemux
86 DECLARE_REF(eDVBAllocatedDemux);
89 eDVBAllocatedDemux(eDVBRegisteredDemux *demux);
90 ~eDVBAllocatedDemux();
91 eDVBDemux &get() { return *m_demux->m_demux; }
92 operator eDVBRegisteredDemux*() { return m_demux; }
93 operator eDVBDemux*() { return m_demux->m_demux; }
96 eDVBRegisteredDemux *m_demux;
99 class iDVBAdapter: public iObject
102 virtual int getNumDemux() = 0;
103 virtual RESULT getDemux(ePtr<eDVBDemux> &demux, int nr) = 0;
105 virtual int getNumFrontends() = 0;
106 virtual RESULT getFrontend(ePtr<eDVBFrontend> &fe, int nr, bool simulate=false) = 0;
109 class eDVBAdapterLinux: public iDVBAdapter
111 DECLARE_REF(eDVBAdapterLinux);
113 eDVBAdapterLinux(int nr);
116 RESULT getDemux(ePtr<eDVBDemux> &demux, int nr);
118 int getNumFrontends();
119 RESULT getFrontend(ePtr<eDVBFrontend> &fe, int nr, bool simulate=false);
121 static int exist(int nr);
124 eSmartPtrList<eDVBFrontend> m_frontend, m_simulate_frontend;
125 eSmartPtrList<eDVBDemux> m_demux;
129 SWIG_IGNORE(eDVBResourceManager);
130 class eDVBResourceManager: public iObject, public Object
132 DECLARE_REF(eDVBResourceManager);
135 eSmartPtrList<iDVBAdapter> m_adapter;
136 eSmartPtrList<eDVBRegisteredDemux> m_demux;
137 eSmartPtrList<eDVBRegisteredFrontend> m_frontend, m_simulate_frontend;
138 void addAdapter(iDVBAdapter *adapter);
140 struct active_channel
142 eDVBChannelID m_channel_id;
143 /* we don't hold a reference here. */
144 eDVBChannel *m_channel;
146 active_channel(const eDVBChannelID &chid, eDVBChannel *ch) : m_channel_id(chid), m_channel(ch) { }
149 std::list<active_channel> m_active_channels, m_active_simulate_channels;
151 ePtr<iDVBChannelList> m_list;
152 ePtr<iDVBSatelliteEquipmentControl> m_sec;
153 static eDVBResourceManager *instance;
155 friend class eDVBChannel;
156 RESULT addChannel(const eDVBChannelID &chid, eDVBChannel *ch);
157 RESULT removeChannel(eDVBChannel *ch);
159 Signal1<void,eDVBChannel*> m_channelAdded;
161 eUsePtr<iDVBChannel> m_cached_channel;
162 Connection m_cached_channel_state_changed_conn;
163 ePtr<eTimer> m_releaseCachedChannelTimer;
164 void DVBChannelStateChanged(iDVBChannel*);
165 void feStateChanged();
169 void releaseCachedChannel();
170 eDVBResourceManager();
171 virtual ~eDVBResourceManager();
173 RESULT setChannelList(iDVBChannelList *list);
174 RESULT getChannelList(ePtr<iDVBChannelList> &list);
177 /* errNoFrontend = -1 replaced by more spcific messages */
179 errChidNotFound = -3,
180 errNoChannelList = -4,
181 errChannelNotInList = -5,
182 errAllSourcesBusy = -6,
183 errNoSourceFound = -7,
186 RESULT connectChannelAdded(const Slot1<void,eDVBChannel*> &channelAdded, ePtr<eConnection> &connection);
187 int canAllocateChannel(const eDVBChannelID &channelid, const eDVBChannelID &ignore, bool simulate=false);
189 /* allocate channel... */
190 RESULT allocateChannel(const eDVBChannelID &channelid, eUsePtr<iDVBChannel> &channel, bool simulate=false);
191 RESULT allocatePVRChannel(eUsePtr<iDVBPVRChannel> &channel);
192 static RESULT getInstance(ePtr<eDVBResourceManager> &);
194 /* allocates a frontend able to tune to frontend paramters 'feperm'.
195 the frontend must be tuned lateron. there is no guarante
196 that tuning will succeed - it just means that if this frontend
197 can't tune, no other frontend could do it.
199 there might be a priority given to certain frontend/chid
200 combinations. this will be evaluated here. */
201 RESULT allocateFrontend(ePtr<eDVBAllocatedFrontend> &fe, ePtr<iDVBFrontendParameters> &feparm, bool simulate=false);
203 RESULT allocateFrontendByIndex(ePtr<eDVBAllocatedFrontend> &fe, int slot_index);
204 /* allocate a demux able to filter on the selected frontend. */
205 RESULT allocateDemux(eDVBRegisteredFrontend *fe, ePtr<eDVBAllocatedDemux> &demux, int cap);
209 int canAllocateFrontend(ePtr<iDVBFrontendParameters> &feparm, bool simulate=false);
210 bool canMeasureFrontendInputPower();
211 PSignal1<void,int> frontendUseMaskChanged;
212 SWIG_VOID(RESULT) allocateRawChannel(eUsePtr<iDVBChannel> &SWIG_OUTPUT, int slot_index);
213 PyObject *setFrontendSlotInformations(SWIG_PYOBJECT(ePyObject) list);
215 SWIG_TEMPLATE_TYPEDEF(ePtr<eDVBResourceManager>, eDVBResourceManager);
216 SWIG_EXTEND(ePtr<eDVBResourceManager>,
217 static ePtr<eDVBResourceManager> getInstance()
219 extern ePtr<eDVBResourceManager> NewResourceManagerPtr(void);
220 return NewResourceManagerPtr();
226 class eDVBChannelFilePush;
228 /* iDVBPVRChannel includes iDVBChannel. don't panic. */
229 class eDVBChannel: public iDVBPVRChannel, public iFilePushScatterGather, public Object
231 DECLARE_REF(eDVBChannel);
232 friend class eDVBResourceManager;
234 eDVBChannel(eDVBResourceManager *mgr, eDVBAllocatedFrontend *frontend);
235 virtual ~eDVBChannel();
237 /* only for managed channels - effectively tunes to the channelid. should not be used... */
238 /* cannot be used for PVR channels. */
239 RESULT setChannel(const eDVBChannelID &id, ePtr<iDVBFrontendParameters> &feparam);
240 eDVBChannelID getChannelID() { return m_channel_id; }
242 RESULT connectStateChange(const Slot1<void,iDVBChannel*> &stateChange, ePtr<eConnection> &connection);
243 RESULT connectEvent(const Slot2<void,iDVBChannel*,int> &eventChange, ePtr<eConnection> &connection);
245 RESULT getState(int &state);
247 RESULT setCIRouting(const eDVBCIRouting &routing);
248 RESULT getDemux(ePtr<iDVBDemux> &demux, int cap);
249 RESULT getFrontend(ePtr<iDVBFrontend> &frontend);
250 RESULT getCurrentFrontendParameters(ePtr<iDVBFrontendParameters> ¶m);
253 RESULT playFile(const char *file);
256 void setCueSheet(eCueSheet *cuesheet);
258 RESULT getLength(pts_t &len);
259 RESULT getCurrentPosition(iDVBDemux *decoding_demux, pts_t &pos, int mode);
261 int getUseCount() { return m_use_count; }
263 ePtr<eDVBAllocatedFrontend> m_frontend;
264 ePtr<eDVBAllocatedDemux> m_demux, m_decoder_demux;
266 ePtr<iDVBFrontendParameters> m_current_frontend_parameters;
267 eDVBChannelID m_channel_id;
268 Signal1<void,iDVBChannel*> m_stateChanged;
269 Signal2<void,iDVBChannel*,int> m_event;
272 /* for channel list */
273 ePtr<eDVBResourceManager> m_mgr;
275 void frontendStateChanged(iDVBFrontend*fe);
276 ePtr<eConnection> m_conn_frontendStateChanged;
278 /* for PVR playback */
279 eDVBChannelFilePush *m_pvr_thread;
280 void pvrEvent(int event);
283 eDVBTSTools m_tstools;
285 ePtr<eCueSheet> m_cue;
287 void cueSheetEvent(int event);
288 ePtr<eConnection> m_conn_cueSheetEvent;
289 int m_skipmode_m, m_skipmode_n;
291 std::list<std::pair<off_t, off_t> > m_source_span;
292 void getNextSourceSpan(off_t current_offset, size_t bytes_read, off_t &start, size_t &size);
293 void flushPVR(iDVBDemux *decoding_demux=0);
295 eSingleLock m_cuesheet_lock;
297 friend class eUsePtr<eDVBChannel>;
299 oRefCount m_use_count;