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 <lib/base/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 sigc::trackable
27 DECLARE_REF(eDVBRegisteredFrontend);
31 if (!m_inuse && m_frontend->closeFrontend()) // frontend busy
32 disable->start(60000, true); // retry close in 60secs
35 sigc::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 m_frontend->preClose();
47 disable->start(3000, true);
54 m_frontend->openFrontend();
55 /* emit */ stateChanged();
58 iDVBAdapter *m_adapter;
59 ePtr<eDVBFrontend> m_frontend;
63 struct eDVBRegisteredDemux: public iObject
65 DECLARE_REF(eDVBRegisteredDemux);
67 iDVBAdapter *m_adapter;
68 ePtr<eDVBDemux> m_demux;
70 bool m_have_descrambler;
71 eDVBRegisteredDemux(eDVBDemux *demux, iDVBAdapter *adap, bool have_descrambler)
72 :m_adapter(adap), m_demux(demux), m_inuse(0), m_have_descrambler(have_descrambler)
76 class eDVBAllocatedFrontend: public iObject
78 DECLARE_REF(eDVBAllocatedFrontend);
81 eDVBAllocatedFrontend(eDVBRegisteredFrontend *fe);
82 ~eDVBAllocatedFrontend();
83 eDVBFrontend &get() { return *m_fe->m_frontend; }
84 operator eDVBRegisteredFrontend*() { return m_fe; }
85 operator eDVBFrontend*() { return m_fe->m_frontend; }
88 eDVBRegisteredFrontend *m_fe;
91 class eDVBAllocatedDemux: public iObject
93 DECLARE_REF(eDVBAllocatedDemux);
96 eDVBAllocatedDemux(eDVBRegisteredDemux *demux);
97 ~eDVBAllocatedDemux();
98 eDVBDemux &get() { return *m_demux->m_demux; }
99 operator eDVBRegisteredDemux*() { return m_demux; }
100 operator eDVBDemux*() { return m_demux->m_demux; }
103 eDVBRegisteredDemux *m_demux;
106 class iDVBAdapter: public iObject
109 virtual int getNumDemux() = 0;
110 virtual RESULT getDemux(ePtr<eDVBDemux> &demux, int nr) = 0;
112 virtual int getNumFrontends() = 0;
113 virtual RESULT getFrontend(ePtr<eDVBFrontend> &fe, int nr, bool simulate=false) = 0;
115 virtual int getNumDecodersAudio() = 0;
116 virtual int getNumDecodersVideo() = 0;
117 virtual int getNumDescramblers() = 0;
120 class eDVBAdapterLinux: public iDVBAdapter
122 DECLARE_REF(eDVBAdapterLinux);
124 eDVBAdapterLinux(int nr);
127 RESULT getDemux(ePtr<eDVBDemux> &demux, int nr);
129 int getNumFrontends();
130 RESULT getFrontend(ePtr<eDVBFrontend> &fe, int nr, bool simulate=false);
132 int getNumDecodersAudio();
133 int getNumDecodersVideo();
134 int getNumDescramblers();
136 static int exist(int nr);
139 int m_nr_decoders_audio;
140 int m_nr_decoders_video;
141 int m_nr_descramblers;
142 eSmartPtrList<eDVBFrontend> m_frontend, m_simulate_frontend;
143 eSmartPtrList<eDVBDemux> m_demux;
147 SWIG_IGNORE(eDVBResourceManager);
148 class eDVBResourceManager: public iObject, public sigc::trackable
150 DECLARE_REF(eDVBResourceManager);
153 eSmartPtrList<iDVBAdapter> m_adapter;
154 eSmartPtrList<eDVBRegisteredDemux> m_demux;
155 eSmartPtrList<eDVBRegisteredFrontend> m_frontend, m_simulate_frontend;
156 void addAdapter(iDVBAdapter *adapter);
158 struct active_channel
160 eDVBChannelID m_channel_id;
161 /* we don't hold a reference here. */
162 eDVBChannel *m_channel;
164 active_channel(const eDVBChannelID &chid, eDVBChannel *ch) : m_channel_id(chid), m_channel(ch) { }
167 std::list<active_channel> m_active_channels, m_active_simulate_channels;
169 ePtr<iDVBChannelList> m_list;
170 ePtr<iDVBSatelliteEquipmentControl> m_sec;
171 static eDVBResourceManager *instance;
173 friend class eDVBChannel;
174 RESULT addChannel(const eDVBChannelID &chid, eDVBChannel *ch);
175 RESULT removeChannel(eDVBChannel *ch);
177 sigc::signal1<void,eDVBChannel*> m_channelAdded;
179 eUsePtr<iDVBChannel> m_cached_channel;
180 sigc::connection m_cached_channel_state_changed_conn;
181 ePtr<eTimer> m_releaseCachedChannelTimer;
182 void DVBChannelStateChanged(iDVBChannel*);
183 void feStateChanged();
187 void releaseCachedChannel();
188 eDVBResourceManager();
189 virtual ~eDVBResourceManager();
191 RESULT setChannelList(iDVBChannelList *list);
192 RESULT getChannelList(ePtr<iDVBChannelList> &list);
195 /* errNoFrontend = -1 replaced by more spcific messages */
197 errChidNotFound = -3,
198 errNoChannelList = -4,
199 errChannelNotInList = -5,
200 errAllSourcesBusy = -6,
201 errNoSourceFound = -7,
204 RESULT connectChannelAdded(const sigc::slot1<void,eDVBChannel*> &channelAdded, ePtr<eConnection> &connection);
205 int canAllocateChannel(const eDVBChannelID &channelid, const eDVBChannelID &ignore, bool simulate=false);
207 /* allocate channel... */
208 RESULT allocateChannel(const eDVBChannelID &channelid, eUsePtr<iDVBChannel> &channel, bool simulate=false);
209 /* allocate a pvr channel */
210 RESULT allocateChannel(const eDVBChannelID &channelid, eUsePtr<iDVBPVRChannel> &channel);
212 static RESULT getInstance(ePtr<eDVBResourceManager> &);
214 /* allocates a frontend able to tune to frontend paramters 'feperm'.
215 the frontend must be tuned lateron. there is no guarante
216 that tuning will succeed - it just means that if this frontend
217 can't tune, no other frontend could do it.
219 there might be a priority given to certain frontend/chid
220 combinations. this will be evaluated here. */
221 RESULT allocateFrontend(ePtr<eDVBAllocatedFrontend> &fe, ePtr<iDVBFrontendParameters> &feparm, bool simulate=false);
223 RESULT allocateFrontendByIndex(ePtr<eDVBAllocatedFrontend> &fe, int slot_index);
224 /* allocate a demux able to filter on the selected frontend. */
226 int canAllocateDemux(const eDVBRegisteredFrontend *fe, int cap);
228 RESULT allocateDemux(eDVBRegisteredFrontend *fe, ePtr<eDVBAllocatedDemux> &demux, int &cap);
229 /* allocate a demux able to filter on the selected pvr source. */
230 RESULT allocateDemux(const std::string &pvr_source, ePtr<eDVBAllocatedDemux> &demux, int &cap);
234 int canAllocateFrontend(ePtr<iDVBFrontendParameters> &feparm, bool simulate=false);
235 bool canMeasureFrontendInputPower();
236 eSignal1<void, int> frontendUseMaskChanged;
237 SWIG_VOID(RESULT) allocateRawChannel(eUsePtr<iDVBChannel> &SWIG_OUTPUT, int slot_index);
238 void setFrontendSlotInformations(std::list<std::tuple<int, std::string, bool, int, std::string> >);
240 SWIG_TEMPLATE_TYPEDEF(ePtr<eDVBResourceManager>, eDVBResourceManager);
241 SWIG_EXTEND(ePtr<eDVBResourceManager>,
242 static ePtr<eDVBResourceManager> getInstance()
244 extern ePtr<eDVBResourceManager> NewResourceManagerPtr(void);
245 return NewResourceManagerPtr();
251 class eDVBChannelFilePush;
253 /* iDVBPVRChannel includes iDVBChannel. don't panic. */
254 class eDVBChannel: public iDVBPVRChannel, public iFilePushScatterGather, public sigc::trackable
256 DECLARE_REF(eDVBChannel);
257 friend class eDVBResourceManager;
259 eDVBChannel(eDVBResourceManager *mgr, eDVBAllocatedFrontend *frontend);
260 virtual ~eDVBChannel();
262 /* only for managed channels - effectively tunes to the channelid. should not be used... */
263 /* cannot be used for PVR channels. */
264 RESULT setChannel(const eDVBChannelID &id, ePtr<iDVBFrontendParameters> &feparam);
265 eDVBChannelID getChannelID() { return m_channel_id; }
267 RESULT connectStateChange(const sigc::slot1<void,iDVBChannel*> &stateChange, ePtr<eConnection> &connection);
268 RESULT connectEvent(const sigc::slot2<void,iDVBChannel*,int> &eventChange, ePtr<eConnection> &connection);
270 RESULT getState(int &state);
272 RESULT getDemux(ePtr<iDVBDemux> &demux, int cap);
273 RESULT getFrontend(ePtr<iDVBFrontend> &frontend);
274 RESULT getCurrentFrontendParameters(ePtr<iDVBFrontendParameters> ¶m);
277 RESULT setChannel(const eDVBChannelID &id);
278 RESULT playFile(const char *file);
281 RESULT playSource(ePtr<iTsSource>& source, const char *priv=NULL);
284 void setCueSheet(eCueSheet *cuesheet);
286 RESULT getLength(pts_t &len);
287 RESULT getCurrentPosition(iDVBDemux *decoding_demux, pts_t &pos, int mode);
289 int getUseCount() { return m_use_count; }
291 RESULT requestTsidOnid(eSlot1<void, int> &cb_func);
294 ePtr<eDVBAllocatedFrontend> m_frontend;
295 ePtr<eDVBAllocatedDemux> m_demux, m_decoder_demux;
297 ePtr<iDVBFrontendParameters> m_current_frontend_parameters;
298 eDVBChannelID m_channel_id;
299 sigc::signal1<void,iDVBChannel*> m_stateChanged;
300 sigc::signal2<void,iDVBChannel*,int> m_event;
303 /* for channel list */
304 ePtr<eDVBResourceManager> m_mgr;
306 void frontendStateChanged(iDVBFrontend*fe);
307 ePtr<eConnection> m_conn_frontendStateChanged;
309 /* for PVR playback */
310 eDVBChannelFilePush *m_pvr_thread;
311 void pvrEvent(int event);
314 eDVBTSTools m_tstools;
316 ePtr<eCueSheet> m_cue;
318 void cueSheetEvent(int event);
319 ePtr<eConnection> m_conn_cueSheetEvent;
320 int m_skipmode_m, m_skipmode_n, m_skipmode_frames, m_skipmode_frames_remainder;
322 std::list<std::pair<uint64_t, uint64_t> > m_source_span;
323 void getNextSourceSpan(uint64_t current_offset, size_t bytes_read, uint64_t &start, size_t &size);
324 void flushPVR(iDVBDemux *decoding_demux=0);
326 eSingleLock m_cuesheet_lock;
328 friend class eUsePtr<eDVBChannel>;
330 oRefCount m_use_count;
334 /* for tsid/onid read */
335 eSignal1<void, int> m_tsid_onid_cb;
336 ePtr<iDVBDemux> m_tsid_onid_demux;
337 ePtr<eTable<ServiceDescriptionSection> > m_SDT;
338 void SDTready(int err);