1 #include <lib/dvb/idvb.h>
2 #include <lib/base/eerror.h>
3 #include <lib/dvb/dvb.h>
4 #include <lib/dvb/sec.h>
7 DEFINE_REF(eDVBResourceManager);
9 eDVBResourceManager *eDVBResourceManager::instance;
11 eDVBResourceManager::eDVBResourceManager(): ref(0)
15 m_sec = new eDVBSatelliteEquipmentControl;
20 eDVBResourceManager::~eDVBResourceManager()
26 RESULT eDVBResourceManager::setChannelList(iDVBChannelList *list)
32 RESULT eDVBResourceManager::getChannelList(ePtr<iDVBChannelList> &list)
42 RESULT eDVBResourceManager::allocateChannel(const eDVBChannelID &channelid, ePtr<iDVBChannel> &channel)
46 channel = ch = new eDVBChannel(this, 0, 0, 0);
48 ePtr<iDVBFrontend> fe;
49 if (!channel->getFrontend(fe))
52 res = ch->setChannel(channelid);
61 RESULT eDVBResourceManager::allocateRawChannel(ePtr<iDVBChannel> &channel)
63 channel = new eDVBChannel(this, 0, 0, 0);
64 ePtr<iDVBFrontend> fe;
65 if (!channel->getFrontend(fe))
71 RESULT eDVBResourceManager::allocatePVRChannel(int caps)
73 return -1; // will nicht, mag nicht, und das interface ist auch kaputt
76 RESULT eDVBResourceManager::addChannel(const eDVBChannelID &chid, eDVBChannel *ch)
78 eDebug("add channel %p", ch);
79 m_active_channels.insert(std::pair<eDVBChannelID,eDVBChannel*>(chid, ch));
83 RESULT eDVBResourceManager::removeChannel(const eDVBChannelID &chid, eDVBChannel *)
85 int cnt = m_active_channels.erase(chid);
86 eDebug("remove channel: removed %d channels", cnt);
93 eDVBChannel::eDVBChannel(eDVBResourceManager *mgr, int adapter, int frontend, int demux): eDVBDemux(adapter, demux), m_state(state_idle), m_mgr(mgr)
98 m_frontend = new eDVBFrontend(adapter, frontend, ok);
101 eDebug("warning, frontend failed");
105 m_frontend->connectStateChange(slot(*this, &eDVBChannel::frontendStateChanged), m_conn_frontendStateChanged);
109 eDVBChannel::~eDVBChannel()
112 m_mgr->removeChannel(m_channel_id, this);
115 void eDVBChannel::frontendStateChanged(iDVBFrontend*fe)
117 eDebug("fe state changed!");
118 int state, ourstate = 0;
119 if (fe->getState(state))
122 if (state == iDVBFrontend::stateLock)
124 eDebug("OURSTATE: ok");
126 } else if (state == iDVBFrontend::stateTuning)
128 eDebug("OURSTATE: tuning");
129 ourstate = state_tuning;
130 } else if (state == iDVBFrontend::stateFailed)
132 eDebug("OURSTATE: failed/unavailable");
133 ourstate = state_unavailable;
135 eFatal("state unknown");
137 if (ourstate != m_state)
140 m_stateChanged(this);
144 RESULT eDVBChannel::setChannel(const eDVBChannelID &channelid)
146 ePtr<iDVBChannelList> list;
148 if (m_mgr->getChannelList(list))
150 eDebug("no channel list set!");
154 eDebug("tuning to chid: ns: %08x tsid %04x onid %04x",
155 channelid.dvbnamespace.get(), channelid.transport_stream_id.get(), channelid.original_network_id.get());
158 ePtr<iDVBFrontendParameters> feparm;
159 if (list->getChannelFrontendData(channelid, feparm))
161 eDebug("channel not found!");
164 eDebug("allocateChannel: channel found..");
168 eDebug("no frontend to tune!");
173 m_mgr->removeChannel(m_channel_id, this);
174 m_channel_id = channelid;
175 m_mgr->addChannel(m_channel_id, this);
176 m_state = state_tuning;
177 eDebug("%p", &*feparm);
178 return m_frontend->tune(*feparm);
181 RESULT eDVBChannel::connectStateChange(const Slot1<void,iDVBChannel*> &stateChange, ePtr<eConnection> &connection)
183 connection = new eConnection(this, m_stateChanged.connect(stateChange));
187 RESULT eDVBChannel::getState(int &state)
193 RESULT eDVBChannel::setCIRouting(const eDVBCIRouting &routing)
198 RESULT eDVBChannel::getDemux(ePtr<iDVBDemux> &demux)
204 RESULT eDVBChannel::getFrontend(ePtr<iDVBFrontend> &frontend)
206 frontend = m_frontend;