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>
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
20 DECLARE_REF(eDVBRegisteredFrontend);
22 iDVBAdapter *m_adapter;
23 ePtr<eDVBFrontend> m_frontend;
25 eDVBRegisteredFrontend(eDVBFrontend *fe, iDVBAdapter *adap): m_adapter(adap), m_frontend(fe), m_inuse(0) { }
28 struct eDVBRegisteredDemux
30 DECLARE_REF(eDVBRegisteredDemux);
32 iDVBAdapter *m_adapter;
33 ePtr<eDVBDemux> m_demux;
35 eDVBRegisteredDemux(eDVBDemux *demux, iDVBAdapter *adap): m_adapter(adap), m_demux(demux), m_inuse(0) { }
38 class eDVBAllocatedFrontend
40 DECLARE_REF(eDVBAllocatedFrontend);
43 eDVBAllocatedFrontend(eDVBRegisteredFrontend *fe);
44 ~eDVBAllocatedFrontend();
45 eDVBFrontend &get() { return *m_fe->m_frontend; }
46 operator eDVBRegisteredFrontend*() { return m_fe; }
47 operator eDVBFrontend*() { return m_fe->m_frontend; }
50 eDVBRegisteredFrontend *m_fe;
53 class eDVBAllocatedDemux
55 DECLARE_REF(eDVBAllocatedDemux);
58 eDVBAllocatedDemux(eDVBRegisteredDemux *demux);
59 ~eDVBAllocatedDemux();
60 eDVBDemux &get() { return *m_demux->m_demux; }
61 operator eDVBRegisteredDemux*() { return m_demux; }
62 operator eDVBDemux*() { return m_demux->m_demux; }
65 eDVBRegisteredDemux *m_demux;
68 class iDVBAdapter: public iObject
71 virtual int getNumDemux() = 0;
72 virtual RESULT getDemux(ePtr<eDVBDemux> &demux, int nr) = 0;
74 virtual int getNumFrontends() = 0;
75 virtual RESULT getFrontend(ePtr<eDVBFrontend> &fe, int nr) = 0;
78 class eDVBAdapterLinux: public iDVBAdapter
80 DECLARE_REF(eDVBAdapterLinux);
82 eDVBAdapterLinux(int nr);
85 RESULT getDemux(ePtr<eDVBDemux> &demux, int nr);
87 int getNumFrontends();
88 RESULT getFrontend(ePtr<eDVBFrontend> &fe, int nr);
90 static int exist(int nr);
93 eSmartPtrList<eDVBFrontend> m_frontend;
94 eSmartPtrList<eDVBDemux> m_demux;
97 class eDVBResourceManager: public iObject
99 DECLARE_REF(eDVBResourceManager);
102 eSmartPtrList<iDVBAdapter> m_adapter;
104 eSmartPtrList<eDVBRegisteredDemux> m_demux;
105 eSmartPtrList<eDVBRegisteredFrontend> m_frontend;
107 void addAdapter(iDVBAdapter *adapter);
109 /* allocates a frontend able to tune to frontend paramters 'feperm'.
110 the frontend must be tuned lateron. there is no guarante
111 that tuning will succeed - it just means that if this frontend
112 can't tune, no other frontend could do it.
114 there might be a priority given to certain frontend/chid
115 combinations. this will be evaluated here. */
117 RESULT allocateFrontend(ePtr<eDVBAllocatedFrontend> &fe, ePtr<iDVBFrontendParameters> &feparm);
118 RESULT allocateFrontendByIndex(ePtr<eDVBAllocatedFrontend> &fe, int index);
120 /* allocate a demux able to filter on the selected frontend. */
121 RESULT allocateDemux(eDVBRegisteredFrontend *fe, ePtr<eDVBAllocatedDemux> &demux, int cap);
123 struct active_channel
125 eDVBChannelID m_channel_id;
126 /* we don't hold a reference here. */
127 eDVBChannel *m_channel;
129 active_channel(const eDVBChannelID &chid, eDVBChannel *ch) : m_channel_id(chid), m_channel(ch) { }
132 std::list<active_channel> m_active_channels;
134 ePtr<iDVBChannelList> m_list;
135 ePtr<iDVBSatelliteEquipmentControl> m_sec;
136 static eDVBResourceManager *instance;
138 friend class eDVBChannel;
139 RESULT addChannel(const eDVBChannelID &chid, eDVBChannel *ch);
140 RESULT removeChannel(eDVBChannel *ch);
142 Signal1<void,eDVBChannel*> m_channelAdded;
143 Signal1<void,eDVBChannel*> m_channelRemoved;
144 Signal1<void,iDVBChannel*> m_channelRunning;
146 eDVBResourceManager();
147 virtual ~eDVBResourceManager();
149 static RESULT getInstance(ePtr<eDVBResourceManager> &ptr) { if (instance) { ptr = instance; return 0; } return -1; }
151 RESULT setChannelList(iDVBChannelList *list);
152 RESULT getChannelList(ePtr<iDVBChannelList> &list);
160 /* allocate channel... */
161 RESULT allocateChannel(const eDVBChannelID &channelid, eUsePtr<iDVBChannel> &channel);
162 RESULT allocateRawChannel(eUsePtr<iDVBChannel> &channel, int frontend_index);
163 RESULT allocatePVRChannel(eUsePtr<iDVBPVRChannel> &channel);
165 RESULT connectChannelAdded(const Slot1<void,eDVBChannel*> &channelAdded, ePtr<eConnection> &connection);
166 RESULT connectChannelRemoved(const Slot1<void,eDVBChannel*> &channelRemoved, ePtr<eConnection> &connection);
167 RESULT connectChannelRunning(const Slot1<void,iDVBChannel*> &channelRemoved, ePtr<eConnection> &connection);
170 class eFilePushThread;
172 /* iDVBPVRChannel includes iDVBChannel. don't panic. */
173 class eDVBChannel: public iDVBPVRChannel, public Object
175 DECLARE_REF(eDVBChannel);
177 eDVBChannel(eDVBResourceManager *mgr, eDVBAllocatedFrontend *frontend);
178 virtual ~eDVBChannel();
180 /* only for managed channels - effectively tunes to the channelid. should not be used... */
181 /* cannot be used for PVR channels. */
182 RESULT setChannel(const eDVBChannelID &id, ePtr<iDVBFrontendParameters> &feparam);
183 eDVBChannelID getChannelID() { return m_channel_id; }
185 RESULT connectStateChange(const Slot1<void,iDVBChannel*> &stateChange, ePtr<eConnection> &connection);
186 RESULT getState(int &state);
188 RESULT setCIRouting(const eDVBCIRouting &routing);
189 RESULT getDemux(ePtr<iDVBDemux> &demux, int cap);
190 RESULT getFrontend(ePtr<iDVBFrontend> &frontend);
193 RESULT playFile(const char *file);
194 RESULT getLength(pts_t &len);
195 RESULT getCurrentPosition(iDVBDemux *decoding_demux, pts_t &pos);
196 RESULT seekTo(iDVBDemux *decoding_demux, int relative, pts_t &pts);
197 /* seeking to relative positions won't work -
198 there is an unknown amount of buffers in between */
199 RESULT seekToPosition(iDVBDemux *decoding_demux, const off_t &off);
202 ePtr<eDVBAllocatedFrontend> m_frontend;
203 ePtr<eDVBAllocatedDemux> m_demux, m_decoder_demux;
205 ePtr<iDVBFrontendParameters> m_current_frontend_parameters;
206 eDVBChannelID m_channel_id;
207 Signal1<void,iDVBChannel*> m_stateChanged;
210 /* for channel list */
211 ePtr<eDVBResourceManager> m_mgr;
213 void frontendStateChanged(iDVBFrontend*fe);
214 ePtr<eConnection> m_conn_frontendStateChanged;
216 /* for PVR playback */
217 eFilePushThread *m_pvr_thread;
218 int m_pvr_fd_src, m_pvr_fd_dst;
219 eDVBTSTools m_tstools;
221 friend class eUsePtr<eDVBChannel>;
223 oRefCount m_use_count;