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(new eTimer(eApp)), m_adapter(adap), m_frontend(fe), m_inuse(0)
36 CONNECT(disable->timeout, eDVBRegisteredFrontend::closeFrontend);
38 ~eDVBRegisteredFrontend()
46 /* emit */ stateChanged();
47 disable->start(3000, true);
54 m_frontend->openFrontend();
55 /* emit */ stateChanged();
58 iDVBAdapter *m_adapter;
59 ePtr<eDVBFrontend> m_frontend;
63 struct eDVBRegisteredDemux
65 DECLARE_REF(eDVBRegisteredDemux);
67 iDVBAdapter *m_adapter;
68 ePtr<eDVBDemux> m_demux;
70 eDVBRegisteredDemux(eDVBDemux *demux, iDVBAdapter *adap): m_adapter(adap), m_demux(demux), m_inuse(0) { }
73 class eDVBAllocatedFrontend
75 DECLARE_REF(eDVBAllocatedFrontend);
78 eDVBAllocatedFrontend(eDVBRegisteredFrontend *fe);
79 ~eDVBAllocatedFrontend();
80 eDVBFrontend &get() { return *m_fe->m_frontend; }
81 operator eDVBRegisteredFrontend*() { return m_fe; }
82 operator eDVBFrontend*() { return m_fe->m_frontend; }
85 eDVBRegisteredFrontend *m_fe;
88 class eDVBAllocatedDemux
90 DECLARE_REF(eDVBAllocatedDemux);
93 eDVBAllocatedDemux(eDVBRegisteredDemux *demux);
94 ~eDVBAllocatedDemux();
95 eDVBDemux &get() { return *m_demux->m_demux; }
96 operator eDVBRegisteredDemux*() { return m_demux; }
97 operator eDVBDemux*() { return m_demux->m_demux; }
100 eDVBRegisteredDemux *m_demux;
103 class iDVBAdapter: public iObject
106 virtual int getNumDemux() = 0;
107 virtual RESULT getDemux(ePtr<eDVBDemux> &demux, int nr) = 0;
109 virtual int getNumFrontends() = 0;
110 virtual RESULT getFrontend(ePtr<eDVBFrontend> &fe, int nr) = 0;
113 class eDVBAdapterLinux: public iDVBAdapter
115 DECLARE_REF(eDVBAdapterLinux);
117 eDVBAdapterLinux(int nr);
120 RESULT getDemux(ePtr<eDVBDemux> &demux, int nr);
122 int getNumFrontends();
123 RESULT getFrontend(ePtr<eDVBFrontend> &fe, int nr);
125 static int exist(int nr);
128 eSmartPtrList<eDVBFrontend> m_frontend;
129 eSmartPtrList<eDVBDemux> m_demux;
133 SWIG_IGNORE(eDVBResourceManager);
134 class eDVBResourceManager: public iObject, public Object
136 DECLARE_REF(eDVBResourceManager);
139 eSmartPtrList<iDVBAdapter> m_adapter;
140 eSmartPtrList<eDVBRegisteredDemux> m_demux;
141 eSmartPtrList<eDVBRegisteredFrontend> m_frontend;
142 void addAdapter(iDVBAdapter *adapter);
144 struct active_channel
146 eDVBChannelID m_channel_id;
147 /* we don't hold a reference here. */
148 eDVBChannel *m_channel;
150 active_channel(const eDVBChannelID &chid, eDVBChannel *ch) : m_channel_id(chid), m_channel(ch) { }
153 std::list<active_channel> m_active_channels;
155 ePtr<iDVBChannelList> m_list;
156 ePtr<iDVBSatelliteEquipmentControl> m_sec;
157 static eDVBResourceManager *instance;
159 friend class eDVBChannel;
160 RESULT addChannel(const eDVBChannelID &chid, eDVBChannel *ch);
161 RESULT removeChannel(eDVBChannel *ch);
163 Signal1<void,eDVBChannel*> m_channelAdded;
165 eUsePtr<iDVBChannel> m_cached_channel;
166 Connection m_cached_channel_state_changed_conn;
167 eTimer m_releaseCachedChannelTimer;
168 void DVBChannelStateChanged(iDVBChannel*);
169 void feStateChanged();
173 void releaseCachedChannel();
174 eDVBResourceManager();
175 virtual ~eDVBResourceManager();
177 RESULT setChannelList(iDVBChannelList *list);
178 RESULT getChannelList(ePtr<iDVBChannelList> &list);
181 /* errNoFrontend = -1 replaced by more spcific messages */
183 errChidNotFound = -3,
184 errNoChannelList = -4,
185 errChannelNotInList = -5,
186 errAllSourcesBusy = -6,
187 errNoSourceFound = -7,
190 RESULT connectChannelAdded(const Slot1<void,eDVBChannel*> &channelAdded, ePtr<eConnection> &connection);
191 int canAllocateChannel(const eDVBChannelID &channelid, const eDVBChannelID &ignore);
193 /* allocate channel... */
194 RESULT allocateChannel(const eDVBChannelID &channelid, eUsePtr<iDVBChannel> &channel);
195 RESULT allocatePVRChannel(eUsePtr<iDVBPVRChannel> &channel);
196 static RESULT getInstance(ePtr<eDVBResourceManager> &);
198 /* allocates a frontend able to tune to frontend paramters 'feperm'.
199 the frontend must be tuned lateron. there is no guarante
200 that tuning will succeed - it just means that if this frontend
201 can't tune, no other frontend could do it.
203 there might be a priority given to certain frontend/chid
204 combinations. this will be evaluated here. */
205 RESULT allocateFrontend(ePtr<eDVBAllocatedFrontend> &fe, ePtr<iDVBFrontendParameters> &feparm);
207 RESULT allocateFrontendByIndex(ePtr<eDVBAllocatedFrontend> &fe, int slot_index);
208 /* allocate a demux able to filter on the selected frontend. */
209 RESULT allocateDemux(eDVBRegisteredFrontend *fe, ePtr<eDVBAllocatedDemux> &demux, int cap);
213 int canAllocateFrontend(ePtr<iDVBFrontendParameters> &feparm);
214 bool canMeasureFrontendInputPower();
215 PSignal1<void,int> frontendUseMaskChanged;
216 SWIG_VOID(RESULT) allocateRawChannel(eUsePtr<iDVBChannel> &SWIG_OUTPUT, int slot_index);
217 PyObject *setFrontendSlotInformations(SWIG_PYOBJECT(ePyObject) list);
219 SWIG_TEMPLATE_TYPEDEF(ePtr<eDVBResourceManager>, eDVBResourceManager);
220 SWIG_EXTEND(ePtr<eDVBResourceManager>,
221 static ePtr<eDVBResourceManager> getInstance()
223 extern ePtr<eDVBResourceManager> NewResourceManagerPtr(void);
224 return NewResourceManagerPtr();
230 class eDVBChannelFilePush;
232 /* iDVBPVRChannel includes iDVBChannel. don't panic. */
233 class eDVBChannel: public iDVBPVRChannel, public iFilePushScatterGather, public Object
235 DECLARE_REF(eDVBChannel);
236 friend class eDVBResourceManager;
238 eDVBChannel(eDVBResourceManager *mgr, eDVBAllocatedFrontend *frontend);
239 virtual ~eDVBChannel();
241 /* only for managed channels - effectively tunes to the channelid. should not be used... */
242 /* cannot be used for PVR channels. */
243 RESULT setChannel(const eDVBChannelID &id, ePtr<iDVBFrontendParameters> &feparam);
244 eDVBChannelID getChannelID() { return m_channel_id; }
246 RESULT connectStateChange(const Slot1<void,iDVBChannel*> &stateChange, ePtr<eConnection> &connection);
247 RESULT connectEvent(const Slot2<void,iDVBChannel*,int> &eventChange, ePtr<eConnection> &connection);
249 RESULT getState(int &state);
251 RESULT setCIRouting(const eDVBCIRouting &routing);
252 RESULT getDemux(ePtr<iDVBDemux> &demux, int cap);
253 RESULT getFrontend(ePtr<iDVBFrontend> &frontend);
254 RESULT getCurrentFrontendParameters(ePtr<iDVBFrontendParameters> ¶m);
257 RESULT playFile(const char *file);
260 void setCueSheet(eCueSheet *cuesheet);
262 RESULT getLength(pts_t &len);
263 RESULT getCurrentPosition(iDVBDemux *decoding_demux, pts_t &pos, int mode);
265 int getUseCount() { return m_use_count; }
267 ePtr<eDVBAllocatedFrontend> m_frontend;
268 ePtr<eDVBAllocatedDemux> m_demux, m_decoder_demux;
270 ePtr<iDVBFrontendParameters> m_current_frontend_parameters;
271 eDVBChannelID m_channel_id;
272 Signal1<void,iDVBChannel*> m_stateChanged;
273 Signal2<void,iDVBChannel*,int> m_event;
276 /* for channel list */
277 ePtr<eDVBResourceManager> m_mgr;
279 void frontendStateChanged(iDVBFrontend*fe);
280 ePtr<eConnection> m_conn_frontendStateChanged;
282 /* for PVR playback */
283 eDVBChannelFilePush *m_pvr_thread;
284 void pvrEvent(int event);
287 eDVBTSTools m_tstools;
289 ePtr<eCueSheet> m_cue;
291 void cueSheetEvent(int event);
292 ePtr<eConnection> m_conn_cueSheetEvent;
293 int m_skipmode_m, m_skipmode_n;
295 std::list<std::pair<off_t, off_t> > m_source_span;
296 void getNextSourceSpan(off_t current_offset, size_t bytes_read, off_t &start, size_t &size);
297 void flushPVR(iDVBDemux *decoding_demux=0);
299 eSingleLock m_cuesheet_lock;
301 friend class eUsePtr<eDVBChannel>;
303 oRefCount m_use_count;