4 #include <lib/base/ebase.h>
5 #include <lib/base/filepush.h>
6 #include <lib/base/elock.h>
7 #include <lib/dvb/idvb.h>
8 #include <lib/dvb/demux.h>
9 #include <lib/dvb/frontend.h>
10 #include <lib/dvb/tstools.h>
11 #include <connection.h>
15 /* we do NOT handle resource conflicts here. instead, the allocateChannel
16 fails, and the application has to see why the channel is allocated
17 (and how to deallocate it). */
20 class eDVBRegisteredFrontend: public iObject, public Object
22 DECLARE_REF(eDVBRegisteredFrontend);
26 if (!m_inuse && m_frontend->closeFrontend()) // frontend busy
27 disable->start(60000, true); // retry close in 60secs
30 eDVBRegisteredFrontend(eDVBFrontend *fe, iDVBAdapter *adap)
31 :disable(new eTimer(eApp)), m_adapter(adap), m_frontend(fe), m_inuse(0)
33 disable = new eTimer(eApp);
34 CONNECT(disable->timeout, eDVBRegisteredFrontend::closeFrontend);
39 disable->start(3000, true);
44 m_frontend->openFrontend();
46 iDVBAdapter *m_adapter;
47 ePtr<eDVBFrontend> m_frontend;
51 struct eDVBRegisteredDemux
53 DECLARE_REF(eDVBRegisteredDemux);
55 iDVBAdapter *m_adapter;
56 ePtr<eDVBDemux> m_demux;
58 eDVBRegisteredDemux(eDVBDemux *demux, iDVBAdapter *adap): m_adapter(adap), m_demux(demux), m_inuse(0) { }
61 class eDVBAllocatedFrontend
63 DECLARE_REF(eDVBAllocatedFrontend);
66 eDVBAllocatedFrontend(eDVBRegisteredFrontend *fe);
67 ~eDVBAllocatedFrontend();
68 eDVBFrontend &get() { return *m_fe->m_frontend; }
69 operator eDVBRegisteredFrontend*() { return m_fe; }
70 operator eDVBFrontend*() { return m_fe->m_frontend; }
73 eDVBRegisteredFrontend *m_fe;
76 class eDVBAllocatedDemux
78 DECLARE_REF(eDVBAllocatedDemux);
81 eDVBAllocatedDemux(eDVBRegisteredDemux *demux);
82 ~eDVBAllocatedDemux();
83 eDVBDemux &get() { return *m_demux->m_demux; }
84 operator eDVBRegisteredDemux*() { return m_demux; }
85 operator eDVBDemux*() { return m_demux->m_demux; }
88 eDVBRegisteredDemux *m_demux;
91 class iDVBAdapter: public iObject
94 virtual int getNumDemux() = 0;
95 virtual RESULT getDemux(ePtr<eDVBDemux> &demux, int nr) = 0;
97 virtual int getNumFrontends() = 0;
98 virtual RESULT getFrontend(ePtr<eDVBFrontend> &fe, int nr) = 0;
101 class eDVBAdapterLinux: public iDVBAdapter
103 DECLARE_REF(eDVBAdapterLinux);
105 eDVBAdapterLinux(int nr);
108 RESULT getDemux(ePtr<eDVBDemux> &demux, int nr);
110 int getNumFrontends();
111 RESULT getFrontend(ePtr<eDVBFrontend> &fe, int nr);
113 static int exist(int nr);
116 eSmartPtrList<eDVBFrontend> m_frontend;
117 eSmartPtrList<eDVBDemux> m_demux;
120 class eDVBResourceManager: public iObject, public Object
122 DECLARE_REF(eDVBResourceManager);
125 eSmartPtrList<iDVBAdapter> m_adapter;
127 eSmartPtrList<eDVBRegisteredDemux> m_demux;
128 eSmartPtrList<eDVBRegisteredFrontend> m_frontend;
130 void addAdapter(iDVBAdapter *adapter);
132 /* allocates a frontend able to tune to frontend paramters 'feperm'.
133 the frontend must be tuned lateron. there is no guarante
134 that tuning will succeed - it just means that if this frontend
135 can't tune, no other frontend could do it.
137 there might be a priority given to certain frontend/chid
138 combinations. this will be evaluated here. */
140 RESULT allocateFrontend(ePtr<eDVBAllocatedFrontend> &fe, ePtr<iDVBFrontendParameters> &feparm);
141 RESULT allocateFrontendByIndex(ePtr<eDVBAllocatedFrontend> &fe, int index);
143 /* allocate a demux able to filter on the selected frontend. */
144 RESULT allocateDemux(eDVBRegisteredFrontend *fe, ePtr<eDVBAllocatedDemux> &demux, int cap);
146 struct active_channel
148 eDVBChannelID m_channel_id;
149 /* we don't hold a reference here. */
150 eDVBChannel *m_channel;
152 active_channel(const eDVBChannelID &chid, eDVBChannel *ch) : m_channel_id(chid), m_channel(ch) { }
155 std::list<active_channel> m_active_channels;
157 ePtr<iDVBChannelList> m_list;
158 ePtr<iDVBSatelliteEquipmentControl> m_sec;
159 static eDVBResourceManager *instance;
161 friend class eDVBChannel;
162 RESULT addChannel(const eDVBChannelID &chid, eDVBChannel *ch);
163 RESULT removeChannel(eDVBChannel *ch);
165 Signal1<void,eDVBChannel*> m_channelAdded;
167 bool canAllocateFrontend(ePtr<iDVBFrontendParameters> &feparm);
169 eUsePtr<iDVBChannel> m_cached_channel;
170 Connection m_cached_channel_state_changed_conn;
171 eTimer m_releaseCachedChannelTimer;
172 void DVBChannelStateChanged(iDVBChannel*);
173 void releaseCachedChannel();
175 eDVBResourceManager();
176 virtual ~eDVBResourceManager();
178 static RESULT getInstance(ePtr<eDVBResourceManager> &ptr) { if (instance) { ptr = instance; return 0; } return -1; }
180 RESULT setChannelList(iDVBChannelList *list);
181 RESULT getChannelList(ePtr<iDVBChannelList> &list);
189 /* allocate channel... */
190 RESULT allocateChannel(const eDVBChannelID &channelid, eUsePtr<iDVBChannel> &channel);
191 RESULT allocateRawChannel(eUsePtr<iDVBChannel> &channel, int frontend_index);
192 RESULT allocatePVRChannel(eUsePtr<iDVBPVRChannel> &channel);
194 RESULT connectChannelAdded(const Slot1<void,eDVBChannel*> &channelAdded, ePtr<eConnection> &connection);
196 bool canAllocateChannel(const eDVBChannelID &channelid, const eDVBChannelID &ignore);
199 /* iDVBPVRChannel includes iDVBChannel. don't panic. */
200 class eDVBChannel: public iDVBPVRChannel, public iFilePushScatterGather, public Object
202 DECLARE_REF(eDVBChannel);
203 friend class eDVBResourceManager;
205 eDVBChannel(eDVBResourceManager *mgr, eDVBAllocatedFrontend *frontend);
206 virtual ~eDVBChannel();
208 /* only for managed channels - effectively tunes to the channelid. should not be used... */
209 /* cannot be used for PVR channels. */
210 RESULT setChannel(const eDVBChannelID &id, ePtr<iDVBFrontendParameters> &feparam);
211 eDVBChannelID getChannelID() { return m_channel_id; }
213 RESULT connectStateChange(const Slot1<void,iDVBChannel*> &stateChange, ePtr<eConnection> &connection);
214 RESULT connectEvent(const Slot2<void,iDVBChannel*,int> &eventChange, ePtr<eConnection> &connection);
216 RESULT getState(int &state);
218 RESULT setCIRouting(const eDVBCIRouting &routing);
219 RESULT getDemux(ePtr<iDVBDemux> &demux, int cap);
220 RESULT getFrontend(ePtr<iDVBFrontend> &frontend);
223 RESULT playFile(const char *file);
226 void setCueSheet(eCueSheet *cuesheet);
228 RESULT getLength(pts_t &len);
229 RESULT getCurrentPosition(iDVBDemux *decoding_demux, pts_t &pos, int mode);
231 int getUseCount() { return m_use_count; }
233 ePtr<iDVBFrontendParameters> m_feparm; // for retune on lostlock
234 ePtr<eDVBAllocatedFrontend> m_frontend;
235 ePtr<eDVBAllocatedDemux> m_demux, m_decoder_demux;
237 ePtr<iDVBFrontendParameters> m_current_frontend_parameters;
238 eDVBChannelID m_channel_id;
239 Signal1<void,iDVBChannel*> m_stateChanged;
240 Signal2<void,iDVBChannel*,int> m_event;
243 /* for channel list */
244 ePtr<eDVBResourceManager> m_mgr;
246 void frontendStateChanged(iDVBFrontend*fe);
247 ePtr<eConnection> m_conn_frontendStateChanged;
249 /* for PVR playback */
250 eFilePushThread *m_pvr_thread;
251 void pvrEvent(int event);
253 int m_pvr_fd_src, m_pvr_fd_dst;
254 eDVBTSTools m_tstools;
256 ePtr<eCueSheet> m_cue;
258 void cueSheetEvent(int event);
259 ePtr<eConnection> m_conn_cueSheetEvent;
260 int m_skipmode_m, m_skipmode_n;
262 std::list<std::pair<off_t, off_t> > m_source_span;
263 void getNextSourceSpan(off_t current_offset, size_t bytes_read, off_t &start, size_t &size);
264 void flushPVR(iDVBDemux *decoding_demux=0);
266 eSingleLock m_cuesheet_lock;
268 friend class eUsePtr<eDVBChannel>;
270 oRefCount m_use_count;