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 channelID "chid".
110 the frontend must be tuned lateron. there is no guarante
111 that tuning will suceed - 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(const eDVBChannelID &chid, ePtr<eDVBAllocatedFrontend> &fe);
119 /* allocate a demux able to filter on the selected frontend. */
120 RESULT allocateDemux(eDVBRegisteredFrontend *fe, ePtr<eDVBAllocatedDemux> &demux, int cap);
122 struct active_channel
124 eDVBChannelID m_channel_id;
125 /* we don't hold a reference here. */
126 eDVBChannel *m_channel;
128 active_channel(const eDVBChannelID &chid, eDVBChannel *ch) : m_channel_id(chid), m_channel(ch) { }
131 std::list<active_channel> m_active_channels;
133 ePtr<iDVBChannelList> m_list;
134 ePtr<iDVBSatelliteEquipmentControl> m_sec;
135 static eDVBResourceManager *instance;
137 friend class eDVBChannel;
138 RESULT addChannel(const eDVBChannelID &chid, eDVBChannel *ch);
139 RESULT removeChannel(eDVBChannel *ch);
141 Signal1<void,eDVBChannel*> m_channelAdded;
142 Signal1<void,eDVBChannel*> m_channelRemoved;
143 Signal1<void,iDVBChannel*> m_channelRunning;
145 eDVBResourceManager();
146 virtual ~eDVBResourceManager();
148 static RESULT getInstance(ePtr<eDVBResourceManager> &ptr) { if (instance) { ptr = instance; return 0; } return -1; }
150 RESULT setChannelList(iDVBChannelList *list);
151 RESULT getChannelList(ePtr<iDVBChannelList> &list);
159 /* allocate channel... */
160 RESULT allocateChannel(const eDVBChannelID &channelid, eUsePtr<iDVBChannel> &channel);
161 RESULT allocateRawChannel(eUsePtr<iDVBChannel> &channel);
162 RESULT allocatePVRChannel(eUsePtr<iDVBPVRChannel> &channel);
164 RESULT connectChannelAdded(const Slot1<void,eDVBChannel*> &channelAdded, ePtr<eConnection> &connection);
165 RESULT connectChannelRemoved(const Slot1<void,eDVBChannel*> &channelRemoved, ePtr<eConnection> &connection);
166 RESULT connectChannelRunning(const Slot1<void,iDVBChannel*> &channelRemoved, ePtr<eConnection> &connection);
169 class eFilePushThread;
171 /* iDVBPVRChannel includes iDVBChannel. don't panic. */
172 class eDVBChannel: public iDVBPVRChannel, public Object
174 DECLARE_REF(eDVBChannel);
176 eDVBChannel(eDVBResourceManager *mgr, eDVBAllocatedFrontend *frontend);
177 virtual ~eDVBChannel();
179 /* only for managed channels - effectively tunes to the channelid. should not be used... */
180 /* cannot be used for PVR channels. */
181 RESULT setChannel(const eDVBChannelID &id);
182 eDVBChannelID getChannelID() { return m_channel_id; }
184 RESULT connectStateChange(const Slot1<void,iDVBChannel*> &stateChange, ePtr<eConnection> &connection);
185 RESULT getState(int &state);
187 RESULT setCIRouting(const eDVBCIRouting &routing);
188 RESULT getDemux(ePtr<iDVBDemux> &demux, int cap);
189 RESULT getFrontend(ePtr<iDVBFrontend> &frontend);
192 RESULT playFile(const char *file);
193 RESULT getLength(pts_t &len);
194 RESULT getCurrentPosition(pts_t &pos);
195 RESULT seekTo(pts_t &pts);
196 RESULT seekToPosition(int relative, const off_t &off);
199 ePtr<eDVBAllocatedFrontend> m_frontend;
200 ePtr<eDVBAllocatedDemux> m_demux, m_decoder_demux;
202 ePtr<iDVBFrontendParameters> m_current_frontend_parameters;
203 eDVBChannelID m_channel_id;
204 Signal1<void,iDVBChannel*> m_stateChanged;
207 /* for channel list */
208 ePtr<eDVBResourceManager> m_mgr;
210 void frontendStateChanged(iDVBFrontend*fe);
211 ePtr<eConnection> m_conn_frontendStateChanged;
213 /* for PVR playback */
214 eFilePushThread *m_pvr_thread;
215 int m_pvr_fd_src, m_pvr_fd_dst;
216 eDVBTSTools m_tstools;
218 friend class eUsePtr<eDVBChannel>;
220 oRefCount m_use_count;