1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
#include <lib/dvb/idvb.h>
#include <lib/base/eerror.h>
#include <lib/dvb/dvb.h>
#include <lib/dvb/sec.h>
#include <errno.h>
DEFINE_REF(eDVBResourceManager);
eDVBResourceManager *eDVBResourceManager::instance;
eDVBResourceManager::eDVBResourceManager(): ref(0)
{
avail = 1;
busy = 0;
m_sec = new eDVBSatelliteEquipmentControl;
if (!instance)
instance = this;
}
eDVBResourceManager::~eDVBResourceManager()
{
if (instance == this)
instance = 0;
}
RESULT eDVBResourceManager::setChannelList(iDVBChannelList *list)
{
m_list = list;
return 0;
}
RESULT eDVBResourceManager::getChannelList(ePtr<iDVBChannelList> &list)
{
list = m_list;
if (list)
return 0;
else
return -ENOENT;
}
RESULT eDVBResourceManager::allocateChannel(const eDVBChannelID &channelid, ePtr<iDVBChannel> &channel)
{
RESULT res;
eDVBChannel *ch;
channel = ch = new eDVBChannel(this, 0, 0, 0);
ePtr<iDVBFrontend> fe;
if (!channel->getFrontend(fe))
fe->setSEC(m_sec);
res = ch->setChannel(channelid);
if (res)
{
channel = 0;
return res;
}
return 0;
}
RESULT eDVBResourceManager::allocateRawChannel(ePtr<iDVBChannel> &channel)
{
channel = new eDVBChannel(this, 0, 0, 0);
ePtr<iDVBFrontend> fe;
if (!channel->getFrontend(fe))
fe->setSEC(m_sec);
return 0;
}
RESULT eDVBResourceManager::allocatePVRChannel(int caps)
{
return -1; // will nicht, mag nicht, und das interface ist auch kaputt
}
RESULT eDVBResourceManager::addChannel(const eDVBChannelID &chid, eDVBChannel *ch)
{
eDebug("add channel %p", ch);
m_active_channels.insert(std::pair<eDVBChannelID,eDVBChannel*>(chid, ch));
return 0;
}
RESULT eDVBResourceManager::removeChannel(const eDVBChannelID &chid, eDVBChannel *)
{
int cnt = m_active_channels.erase(chid);
eDebug("remove channel: removed %d channels", cnt);
ASSERT(cnt <= 1);
if (cnt == 1)
return 0;
return -ENOENT;
}
eDVBChannel::eDVBChannel(eDVBResourceManager *mgr, int adapter, int frontend, int demux): eDVBDemux(adapter, demux), m_state(state_idle), m_mgr(mgr)
{
if (frontend >= 0)
{
int ok;
m_frontend = new eDVBFrontend(adapter, frontend, ok);
if (!ok)
{
eDebug("warning, frontend failed");
m_frontend = 0;
return;
}
m_frontend->connectStateChange(slot(*this, &eDVBChannel::frontendStateChanged), m_conn_frontendStateChanged);
}
}
eDVBChannel::~eDVBChannel()
{
if (m_channel_id)
m_mgr->removeChannel(m_channel_id, this);
}
void eDVBChannel::frontendStateChanged(iDVBFrontend*fe)
{
eDebug("fe state changed!");
int state, ourstate = 0;
if (fe->getState(state))
return;
if (state == iDVBFrontend::stateLock)
{
eDebug("OURSTATE: ok");
ourstate = state_ok;
} else if (state == iDVBFrontend::stateTuning)
{
eDebug("OURSTATE: tuning");
ourstate = state_tuning;
} else if (state == iDVBFrontend::stateFailed)
{
eDebug("OURSTATE: failed/unavailable");
ourstate = state_unavailable;
} else
eFatal("state unknown");
if (ourstate != m_state)
{
m_state = ourstate;
m_stateChanged(this);
}
}
RESULT eDVBChannel::setChannel(const eDVBChannelID &channelid)
{
ePtr<iDVBChannelList> list;
if (m_mgr->getChannelList(list))
{
eDebug("no channel list set!");
return -ENOENT;
}
eDebug("tuning to chid: ns: %08x tsid %04x onid %04x",
channelid.dvbnamespace.get(), channelid.transport_stream_id.get(), channelid.original_network_id.get());
ePtr<iDVBFrontendParameters> feparm;
if (list->getChannelFrontendData(channelid, feparm))
{
eDebug("channel not found!");
return -ENOENT;
}
eDebug("allocateChannel: channel found..");
if (!m_frontend)
{
eDebug("no frontend to tune!");
return -ENODEV;
}
if (m_channel_id)
m_mgr->removeChannel(m_channel_id, this);
m_channel_id = channelid;
m_mgr->addChannel(m_channel_id, this);
m_state = state_tuning;
eDebug("%p", &*feparm);
return m_frontend->tune(*feparm);
}
RESULT eDVBChannel::connectStateChange(const Slot1<void,iDVBChannel*> &stateChange, ePtr<eConnection> &connection)
{
connection = new eConnection( m_stateChanged.connect(stateChange) );
return 0;
}
RESULT eDVBChannel::getState(int &state)
{
state = m_state;
return 0;
}
RESULT eDVBChannel::setCIRouting(const eDVBCIRouting &routing)
{
return -1;
}
RESULT eDVBChannel::getDemux(ePtr<iDVBDemux> &demux)
{
demux = this;
return 0;
}
RESULT eDVBChannel::getFrontend(ePtr<iDVBFrontend> &frontend)
{
frontend = m_frontend;
if (frontend)
return 0;
else
return -ENODEV;
}
|