4 #include <lib/base/ebase.h>
5 #include <lib/dvb/idvb.h>
6 #include <lib/dvb/demux.h>
7 #include <lib/dvb/frontend.h>
8 #include <lib/dvb/tstools.h>
9 #include <connection.h>
13 /* we do NOT handle resource conflicts here. instead, the allocateChannel
14 fails, and the application has to see why the channel is allocated
15 (and how to deallocate it). */
18 class eDVBRegisteredFrontend: public iObject, public Object
20 DECLARE_REF(eDVBRegisteredFrontend);
24 if (!m_inuse && m_frontend->closeFrontend()) // frontend busy
25 disable->start(60000, true); // retry close in 60secs
28 eDVBRegisteredFrontend(eDVBFrontend *fe, iDVBAdapter *adap)
29 :disable(new eTimer(eApp)), m_adapter(adap), m_frontend(fe), m_inuse(0)
31 disable = new eTimer(eApp);
32 CONNECT(disable->timeout, eDVBRegisteredFrontend::closeFrontend);
37 disable->start(3000, true);
42 m_frontend->openFrontend();
44 iDVBAdapter *m_adapter;
45 ePtr<eDVBFrontend> m_frontend;
49 struct eDVBRegisteredDemux
51 DECLARE_REF(eDVBRegisteredDemux);
53 iDVBAdapter *m_adapter;
54 ePtr<eDVBDemux> m_demux;
56 eDVBRegisteredDemux(eDVBDemux *demux, iDVBAdapter *adap): m_adapter(adap), m_demux(demux), m_inuse(0) { }
59 class eDVBAllocatedFrontend
61 DECLARE_REF(eDVBAllocatedFrontend);
64 eDVBAllocatedFrontend(eDVBRegisteredFrontend *fe);
65 ~eDVBAllocatedFrontend();
66 eDVBFrontend &get() { return *m_fe->m_frontend; }
67 operator eDVBRegisteredFrontend*() { return m_fe; }
68 operator eDVBFrontend*() { return m_fe->m_frontend; }
71 eDVBRegisteredFrontend *m_fe;
74 class eDVBAllocatedDemux
76 DECLARE_REF(eDVBAllocatedDemux);
79 eDVBAllocatedDemux(eDVBRegisteredDemux *demux);
80 ~eDVBAllocatedDemux();
81 eDVBDemux &get() { return *m_demux->m_demux; }
82 operator eDVBRegisteredDemux*() { return m_demux; }
83 operator eDVBDemux*() { return m_demux->m_demux; }
86 eDVBRegisteredDemux *m_demux;
89 class iDVBAdapter: public iObject
92 virtual int getNumDemux() = 0;
93 virtual RESULT getDemux(ePtr<eDVBDemux> &demux, int nr) = 0;
95 virtual int getNumFrontends() = 0;
96 virtual RESULT getFrontend(ePtr<eDVBFrontend> &fe, int nr) = 0;
99 class eDVBAdapterLinux: public iDVBAdapter
101 DECLARE_REF(eDVBAdapterLinux);
103 eDVBAdapterLinux(int nr);
106 RESULT getDemux(ePtr<eDVBDemux> &demux, int nr);
108 int getNumFrontends();
109 RESULT getFrontend(ePtr<eDVBFrontend> &fe, int nr);
111 static int exist(int nr);
114 eSmartPtrList<eDVBFrontend> m_frontend;
115 eSmartPtrList<eDVBDemux> m_demux;
118 class eDVBResourceManager: public iObject
120 DECLARE_REF(eDVBResourceManager);
123 eUsePtr<iDVBChannel> m_cached_channel;
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 eDVBResourceManager();
170 virtual ~eDVBResourceManager();
172 static RESULT getInstance(ePtr<eDVBResourceManager> &ptr) { if (instance) { ptr = instance; return 0; } return -1; }
174 RESULT setChannelList(iDVBChannelList *list);
175 RESULT getChannelList(ePtr<iDVBChannelList> &list);
183 /* allocate channel... */
184 RESULT allocateChannel(const eDVBChannelID &channelid, eUsePtr<iDVBChannel> &channel);
185 RESULT allocateRawChannel(eUsePtr<iDVBChannel> &channel, int frontend_index);
186 RESULT allocatePVRChannel(eUsePtr<iDVBPVRChannel> &channel);
188 RESULT connectChannelAdded(const Slot1<void,eDVBChannel*> &channelAdded, ePtr<eConnection> &connection);
190 bool canAllocateChannel(const eDVBChannelID &channelid, const eDVBChannelID &ignore);
193 class eFilePushThread;
195 /* iDVBPVRChannel includes iDVBChannel. don't panic. */
196 class eDVBChannel: public iDVBPVRChannel, public Object
198 DECLARE_REF(eDVBChannel);
200 eDVBChannel(eDVBResourceManager *mgr, eDVBAllocatedFrontend *frontend);
201 virtual ~eDVBChannel();
203 /* only for managed channels - effectively tunes to the channelid. should not be used... */
204 /* cannot be used for PVR channels. */
205 RESULT setChannel(const eDVBChannelID &id, ePtr<iDVBFrontendParameters> &feparam);
206 eDVBChannelID getChannelID() { return m_channel_id; }
208 RESULT connectStateChange(const Slot1<void,iDVBChannel*> &stateChange, ePtr<eConnection> &connection);
209 RESULT getState(int &state);
211 RESULT setCIRouting(const eDVBCIRouting &routing);
212 RESULT getDemux(ePtr<iDVBDemux> &demux, int cap);
213 RESULT getFrontend(ePtr<iDVBFrontend> &frontend);
216 RESULT playFile(const char *file);
217 RESULT getLength(pts_t &len);
218 RESULT getCurrentPosition(iDVBDemux *decoding_demux, pts_t &pos, int mode);
219 RESULT seekTo(iDVBDemux *decoding_demux, int relative, pts_t &pts);
220 /* seeking to relative positions won't work -
221 there is an unknown amount of buffers in between */
222 RESULT seekToPosition(iDVBDemux *decoding_demux, const off_t &off);
224 int getUseCount() { return m_use_count; }
226 ePtr<eDVBAllocatedFrontend> m_frontend;
227 ePtr<eDVBAllocatedDemux> m_demux, m_decoder_demux;
229 ePtr<iDVBFrontendParameters> m_current_frontend_parameters;
230 eDVBChannelID m_channel_id;
231 Signal1<void,iDVBChannel*> m_stateChanged;
234 /* for channel list */
235 ePtr<eDVBResourceManager> m_mgr;
237 void frontendStateChanged(iDVBFrontend*fe);
238 ePtr<eConnection> m_conn_frontendStateChanged;
240 /* for PVR playback */
241 eFilePushThread *m_pvr_thread;
242 int m_pvr_fd_src, m_pvr_fd_dst;
243 eDVBTSTools m_tstools;
245 friend class eUsePtr<eDVBChannel>;
247 oRefCount m_use_count;