4 #include <lib/base/ebase.h>
5 #include <lib/base/filepush.h>
6 #include <lib/dvb/idvb.h>
7 #include <lib/dvb/demux.h>
8 #include <lib/dvb/frontend.h>
9 #include <lib/dvb/tstools.h>
10 #include <connection.h>
14 /* we do NOT handle resource conflicts here. instead, the allocateChannel
15 fails, and the application has to see why the channel is allocated
16 (and how to deallocate it). */
19 class eDVBRegisteredFrontend: public iObject, public Object
21 DECLARE_REF(eDVBRegisteredFrontend);
25 if (!m_inuse && m_frontend->closeFrontend()) // frontend busy
26 disable->start(60000, true); // retry close in 60secs
29 eDVBRegisteredFrontend(eDVBFrontend *fe, iDVBAdapter *adap)
30 :disable(new eTimer(eApp)), m_adapter(adap), m_frontend(fe), m_inuse(0)
32 disable = new eTimer(eApp);
33 CONNECT(disable->timeout, eDVBRegisteredFrontend::closeFrontend);
38 disable->start(3000, true);
43 m_frontend->openFrontend();
45 iDVBAdapter *m_adapter;
46 ePtr<eDVBFrontend> m_frontend;
50 struct eDVBRegisteredDemux
52 DECLARE_REF(eDVBRegisteredDemux);
54 iDVBAdapter *m_adapter;
55 ePtr<eDVBDemux> m_demux;
57 eDVBRegisteredDemux(eDVBDemux *demux, iDVBAdapter *adap): m_adapter(adap), m_demux(demux), m_inuse(0) { }
60 class eDVBAllocatedFrontend
62 DECLARE_REF(eDVBAllocatedFrontend);
65 eDVBAllocatedFrontend(eDVBRegisteredFrontend *fe);
66 ~eDVBAllocatedFrontend();
67 eDVBFrontend &get() { return *m_fe->m_frontend; }
68 operator eDVBRegisteredFrontend*() { return m_fe; }
69 operator eDVBFrontend*() { return m_fe->m_frontend; }
72 eDVBRegisteredFrontend *m_fe;
75 class eDVBAllocatedDemux
77 DECLARE_REF(eDVBAllocatedDemux);
80 eDVBAllocatedDemux(eDVBRegisteredDemux *demux);
81 ~eDVBAllocatedDemux();
82 eDVBDemux &get() { return *m_demux->m_demux; }
83 operator eDVBRegisteredDemux*() { return m_demux; }
84 operator eDVBDemux*() { return m_demux->m_demux; }
87 eDVBRegisteredDemux *m_demux;
90 class iDVBAdapter: public iObject
93 virtual int getNumDemux() = 0;
94 virtual RESULT getDemux(ePtr<eDVBDemux> &demux, int nr) = 0;
96 virtual int getNumFrontends() = 0;
97 virtual RESULT getFrontend(ePtr<eDVBFrontend> &fe, int nr) = 0;
100 class eDVBAdapterLinux: public iDVBAdapter
102 DECLARE_REF(eDVBAdapterLinux);
104 eDVBAdapterLinux(int nr);
107 RESULT getDemux(ePtr<eDVBDemux> &demux, int nr);
109 int getNumFrontends();
110 RESULT getFrontend(ePtr<eDVBFrontend> &fe, int nr);
112 static int exist(int nr);
115 eSmartPtrList<eDVBFrontend> m_frontend;
116 eSmartPtrList<eDVBDemux> m_demux;
119 class eDVBResourceManager: public iObject
121 DECLARE_REF(eDVBResourceManager);
124 eUsePtr<iDVBChannel> m_cached_channel;
126 eSmartPtrList<iDVBAdapter> m_adapter;
128 eSmartPtrList<eDVBRegisteredDemux> m_demux;
129 eSmartPtrList<eDVBRegisteredFrontend> m_frontend;
131 void addAdapter(iDVBAdapter *adapter);
133 /* allocates a frontend able to tune to frontend paramters 'feperm'.
134 the frontend must be tuned lateron. there is no guarante
135 that tuning will succeed - it just means that if this frontend
136 can't tune, no other frontend could do it.
138 there might be a priority given to certain frontend/chid
139 combinations. this will be evaluated here. */
141 RESULT allocateFrontend(ePtr<eDVBAllocatedFrontend> &fe, ePtr<iDVBFrontendParameters> &feparm);
142 RESULT allocateFrontendByIndex(ePtr<eDVBAllocatedFrontend> &fe, int index);
144 /* allocate a demux able to filter on the selected frontend. */
145 RESULT allocateDemux(eDVBRegisteredFrontend *fe, ePtr<eDVBAllocatedDemux> &demux, int cap);
147 struct active_channel
149 eDVBChannelID m_channel_id;
150 /* we don't hold a reference here. */
151 eDVBChannel *m_channel;
153 active_channel(const eDVBChannelID &chid, eDVBChannel *ch) : m_channel_id(chid), m_channel(ch) { }
156 std::list<active_channel> m_active_channels;
158 ePtr<iDVBChannelList> m_list;
159 ePtr<iDVBSatelliteEquipmentControl> m_sec;
160 static eDVBResourceManager *instance;
162 friend class eDVBChannel;
163 RESULT addChannel(const eDVBChannelID &chid, eDVBChannel *ch);
164 RESULT removeChannel(eDVBChannel *ch);
166 Signal1<void,eDVBChannel*> m_channelAdded;
168 bool canAllocateFrontend(ePtr<iDVBFrontendParameters> &feparm);
170 eDVBResourceManager();
171 virtual ~eDVBResourceManager();
173 static RESULT getInstance(ePtr<eDVBResourceManager> &ptr) { if (instance) { ptr = instance; return 0; } return -1; }
175 RESULT setChannelList(iDVBChannelList *list);
176 RESULT getChannelList(ePtr<iDVBChannelList> &list);
184 /* allocate channel... */
185 RESULT allocateChannel(const eDVBChannelID &channelid, eUsePtr<iDVBChannel> &channel);
186 RESULT allocateRawChannel(eUsePtr<iDVBChannel> &channel, int frontend_index);
187 RESULT allocatePVRChannel(eUsePtr<iDVBPVRChannel> &channel);
189 RESULT connectChannelAdded(const Slot1<void,eDVBChannel*> &channelAdded, ePtr<eConnection> &connection);
191 bool canAllocateChannel(const eDVBChannelID &channelid, const eDVBChannelID &ignore);
194 /* iDVBPVRChannel includes iDVBChannel. don't panic. */
195 class eDVBChannel: public iDVBPVRChannel, public iFilePushScatterGather, public Object
197 DECLARE_REF(eDVBChannel);
199 eDVBChannel(eDVBResourceManager *mgr, eDVBAllocatedFrontend *frontend);
200 virtual ~eDVBChannel();
202 /* only for managed channels - effectively tunes to the channelid. should not be used... */
203 /* cannot be used for PVR channels. */
204 RESULT setChannel(const eDVBChannelID &id, ePtr<iDVBFrontendParameters> &feparam);
205 eDVBChannelID getChannelID() { return m_channel_id; }
207 RESULT connectStateChange(const Slot1<void,iDVBChannel*> &stateChange, ePtr<eConnection> &connection);
208 RESULT connectEvent(const Slot2<void,iDVBChannel*,int> &eventChange, ePtr<eConnection> &connection);
210 RESULT getState(int &state);
212 RESULT setCIRouting(const eDVBCIRouting &routing);
213 RESULT getDemux(ePtr<iDVBDemux> &demux, int cap);
214 RESULT getFrontend(ePtr<iDVBFrontend> &frontend);
217 RESULT playFile(const char *file);
220 void setCueSheet(eCueSheet *cuesheet);
222 RESULT getLength(pts_t &len);
223 RESULT getCurrentPosition(iDVBDemux *decoding_demux, pts_t &pos, int mode);
225 int getUseCount() { return m_use_count; }
227 ePtr<iDVBFrontendParameters> m_feparm; // for retune on lostlock
228 ePtr<eDVBAllocatedFrontend> m_frontend;
229 ePtr<eDVBAllocatedDemux> m_demux, m_decoder_demux;
231 ePtr<iDVBFrontendParameters> m_current_frontend_parameters;
232 eDVBChannelID m_channel_id;
233 Signal1<void,iDVBChannel*> m_stateChanged;
234 Signal2<void,iDVBChannel*,int> m_event;
237 /* for channel list */
238 ePtr<eDVBResourceManager> m_mgr;
240 void frontendStateChanged(iDVBFrontend*fe);
241 ePtr<eConnection> m_conn_frontendStateChanged;
243 /* for PVR playback */
244 eFilePushThread *m_pvr_thread;
245 void pvrEvent(int event);
247 int m_pvr_fd_src, m_pvr_fd_dst;
248 eDVBTSTools m_tstools;
250 ePtr<eCueSheet> m_cue;
252 void cueSheetEvent(int event);
253 ePtr<eConnection> m_conn_cueSheetEvent;
254 int m_skipmode_m, m_skipmode_n;
256 std::list<std::pair<off_t, off_t> > m_source_span;
257 void getNextSourceSpan(off_t current_offset, size_t bytes_read, off_t &start, size_t &size);
258 void flushPVR(iDVBDemux *decoding_demux=0);
260 friend class eUsePtr<eDVBChannel>;
262 oRefCount m_use_count;