4 #include <lib/dvb/idvb.h>
5 #include <lib/dvb/demux.h>
6 #include <lib/dvb/frontend.h>
7 #include <lib/dvb/tstools.h>
8 #include <connection.h>
12 /* we do NOT handle resource conflicts here. instead, the allocateChannel
13 fails, and the application has to see why the channel is allocated
14 (and how to deallocate it). */
17 class eDVBRegisteredFrontend: public iObject
19 DECLARE_REF(eDVBRegisteredFrontend);
21 iDVBAdapter *m_adapter;
22 ePtr<eDVBFrontend> m_frontend;
24 eDVBRegisteredFrontend(eDVBFrontend *fe, iDVBAdapter *adap): m_adapter(adap), m_frontend(fe), m_inuse(0) { }
27 struct eDVBRegisteredDemux
29 DECLARE_REF(eDVBRegisteredDemux);
31 iDVBAdapter *m_adapter;
32 ePtr<eDVBDemux> m_demux;
34 eDVBRegisteredDemux(eDVBDemux *demux, iDVBAdapter *adap): m_adapter(adap), m_demux(demux), m_inuse(0) { }
37 class eDVBAllocatedFrontend
39 DECLARE_REF(eDVBAllocatedFrontend);
42 eDVBAllocatedFrontend(eDVBRegisteredFrontend *fe);
43 ~eDVBAllocatedFrontend();
44 eDVBFrontend &get() { return *m_fe->m_frontend; }
45 operator eDVBRegisteredFrontend*() { return m_fe; }
46 operator eDVBFrontend*() { return m_fe->m_frontend; }
49 eDVBRegisteredFrontend *m_fe;
52 class eDVBAllocatedDemux
54 DECLARE_REF(eDVBAllocatedDemux);
57 eDVBAllocatedDemux(eDVBRegisteredDemux *demux);
58 ~eDVBAllocatedDemux();
59 eDVBDemux &get() { return *m_demux->m_demux; }
60 operator eDVBRegisteredDemux*() { return m_demux; }
61 operator eDVBDemux*() { return m_demux->m_demux; }
64 eDVBRegisteredDemux *m_demux;
67 class iDVBAdapter: public iObject
70 virtual int getNumDemux() = 0;
71 virtual RESULT getDemux(ePtr<eDVBDemux> &demux, int nr) = 0;
73 virtual int getNumFrontends() = 0;
74 virtual RESULT getFrontend(ePtr<eDVBFrontend> &fe, int nr) = 0;
77 class eDVBAdapterLinux: public iDVBAdapter
79 DECLARE_REF(eDVBAdapterLinux);
81 eDVBAdapterLinux(int nr);
84 RESULT getDemux(ePtr<eDVBDemux> &demux, int nr);
86 int getNumFrontends();
87 RESULT getFrontend(ePtr<eDVBFrontend> &fe, int nr);
89 static int exist(int nr);
92 eSmartPtrList<eDVBFrontend> m_frontend;
93 eSmartPtrList<eDVBDemux> m_demux;
96 class eDVBResourceManager: public iObject
98 DECLARE_REF(eDVBResourceManager);
101 eUsePtr<iDVBChannel> m_cached_channel;
103 eSmartPtrList<iDVBAdapter> m_adapter;
105 eSmartPtrList<eDVBRegisteredDemux> m_demux;
106 eSmartPtrList<eDVBRegisteredFrontend> m_frontend;
108 void addAdapter(iDVBAdapter *adapter);
110 /* allocates a frontend able to tune to frontend paramters 'feperm'.
111 the frontend must be tuned lateron. there is no guarante
112 that tuning will succeed - it just means that if this frontend
113 can't tune, no other frontend could do it.
115 there might be a priority given to certain frontend/chid
116 combinations. this will be evaluated here. */
118 RESULT allocateFrontend(ePtr<eDVBAllocatedFrontend> &fe, ePtr<iDVBFrontendParameters> &feparm);
119 RESULT allocateFrontendByIndex(ePtr<eDVBAllocatedFrontend> &fe, int index);
121 /* allocate a demux able to filter on the selected frontend. */
122 RESULT allocateDemux(eDVBRegisteredFrontend *fe, ePtr<eDVBAllocatedDemux> &demux, int cap);
124 struct active_channel
126 eDVBChannelID m_channel_id;
127 /* we don't hold a reference here. */
128 eDVBChannel *m_channel;
130 active_channel(const eDVBChannelID &chid, eDVBChannel *ch) : m_channel_id(chid), m_channel(ch) { }
133 std::list<active_channel> m_active_channels;
135 ePtr<iDVBChannelList> m_list;
136 ePtr<iDVBSatelliteEquipmentControl> m_sec;
137 static eDVBResourceManager *instance;
139 friend class eDVBChannel;
140 RESULT addChannel(const eDVBChannelID &chid, eDVBChannel *ch);
141 RESULT removeChannel(eDVBChannel *ch);
143 Signal1<void,eDVBChannel*> m_channelAdded;
145 bool canAllocateFrontend(ePtr<iDVBFrontendParameters> &feparm);
147 eDVBResourceManager();
148 virtual ~eDVBResourceManager();
150 static RESULT getInstance(ePtr<eDVBResourceManager> &ptr) { if (instance) { ptr = instance; return 0; } return -1; }
152 RESULT setChannelList(iDVBChannelList *list);
153 RESULT getChannelList(ePtr<iDVBChannelList> &list);
161 /* allocate channel... */
162 RESULT allocateChannel(const eDVBChannelID &channelid, eUsePtr<iDVBChannel> &channel);
163 RESULT allocateRawChannel(eUsePtr<iDVBChannel> &channel, int frontend_index);
164 RESULT allocatePVRChannel(eUsePtr<iDVBPVRChannel> &channel);
166 RESULT connectChannelAdded(const Slot1<void,eDVBChannel*> &channelAdded, ePtr<eConnection> &connection);
168 bool canAllocateChannel(const eDVBChannelID &channelid, const eDVBChannelID &ignore);
171 class eFilePushThread;
173 /* iDVBPVRChannel includes iDVBChannel. don't panic. */
174 class eDVBChannel: public iDVBPVRChannel, public Object
176 DECLARE_REF(eDVBChannel);
178 eDVBChannel(eDVBResourceManager *mgr, eDVBAllocatedFrontend *frontend);
179 virtual ~eDVBChannel();
181 /* only for managed channels - effectively tunes to the channelid. should not be used... */
182 /* cannot be used for PVR channels. */
183 RESULT setChannel(const eDVBChannelID &id, ePtr<iDVBFrontendParameters> &feparam);
184 eDVBChannelID getChannelID() { return m_channel_id; }
186 RESULT connectStateChange(const Slot1<void,iDVBChannel*> &stateChange, ePtr<eConnection> &connection);
187 RESULT getState(int &state);
189 RESULT setCIRouting(const eDVBCIRouting &routing);
190 RESULT getDemux(ePtr<iDVBDemux> &demux, int cap);
191 RESULT getFrontend(ePtr<iDVBFrontend> &frontend);
194 RESULT playFile(const char *file);
195 RESULT getLength(pts_t &len);
196 RESULT getCurrentPosition(iDVBDemux *decoding_demux, pts_t &pos);
197 RESULT seekTo(iDVBDemux *decoding_demux, int relative, pts_t &pts);
198 /* seeking to relative positions won't work -
199 there is an unknown amount of buffers in between */
200 RESULT seekToPosition(iDVBDemux *decoding_demux, const off_t &off);
202 int getUseCount() { return m_use_count; }
204 ePtr<eDVBAllocatedFrontend> m_frontend;
205 ePtr<eDVBAllocatedDemux> m_demux, m_decoder_demux;
207 ePtr<iDVBFrontendParameters> m_current_frontend_parameters;
208 eDVBChannelID m_channel_id;
209 Signal1<void,iDVBChannel*> m_stateChanged;
212 /* for channel list */
213 ePtr<eDVBResourceManager> m_mgr;
215 void frontendStateChanged(iDVBFrontend*fe);
216 ePtr<eConnection> m_conn_frontendStateChanged;
218 /* for PVR playback */
219 eFilePushThread *m_pvr_thread;
220 int m_pvr_fd_src, m_pvr_fd_dst;
221 eDVBTSTools m_tstools;
223 friend class eUsePtr<eDVBChannel>;
225 oRefCount m_use_count;