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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
#include "network.h"
#include "table.impl.h"
#include <boost/bind.hpp>
#include <linux/dvb/frontend.h>
#include <safeMapFind.h>
#include <compileTimeFormatter.h>
namespace AdHoc {
StreamWriterT('x') {
template<typename ... Pn>
static void write(stream & s, const int & p, const Pn & ... pn)
{
s << std::hex << p;
StreamWriter::next(s, pn...);
}
};
}
namespace P2PVR {
namespace DVBSI {
struct NetworkStreamsHeader {
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
u_char reserved1 :4;
u_char transport_stream_loop_length_hi :4;
#else
u_char transport_stream_loop_length_hi :4;
u_char reserved1 :4;
#endif
u_char transport_stream_loop_length_lo;
u_char data[];
} __attribute__((packed));
struct TransportStream {
uint16_t transportStreamId;
uint16_t originalNetworkId;
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
u_char reserved1 :4;
u_char descriptors_length_hi :4;
#else
u_char descriptors_length_hi :4;
u_char reserved1 :4;
#endif
u_char descriptors_length_lo;
u_char data[];
} __attribute__((packed));
struct TerrestrialDeliveryDescriptor {
uint32_t Frequency;
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
uint8_t Bandwidth : 3;
uint8_t Priority : 1;
uint8_t TimeSlicing : 1;
uint8_t MpeFec : 1;
uint8_t _reserved1 : 2;
#else
uint8_t _reserved1 : 2;
uint8_t MpeFec : 1;
uint8_t TimeSlicing : 1;
uint8_t Priority : 1;
uint8_t Bandwidth : 3;
#endif
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
uint8_t Constellation : 2;
uint8_t Hierarchy : 3;
uint8_t CodeRateHP : 3;
#else
uint8_t CodeRateHP : 3;
uint8_t Hierarchy : 3;
uint8_t Constellation : 2;
#endif
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
uint8_t CodeRateLP : 3;
uint8_t GuardInterval : 2;
uint8_t TransmissionMode : 2;
uint8_t OtherFrequencyFlag : 1;
#else
uint8_t OtherFrequencyFlag : 1;
uint8_t TransmissionMode : 2;
uint8_t GuardInterval : 2;
uint8_t CodeRateLP : 3;
#endif
uint32_t _reserved2;
} __attribute__((packed));
struct CableDeliveryDescriptor {
uint32_t Frequency;
uint8_t _reserved2;
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
uint8_t _reserved1 : 4;
uint8_t FecOuter : 4;
#else
uint8_t FecOuter : 4;
uint8_t _reserved1 : 4;
#endif
uint8_t Modulation;
uint8_t SymbolRate1;
uint8_t SymbolRate2;
uint8_t SymbolRate3;
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
uint8_t SymbolRate4 : 4;
uint8_t FecInner : 4;
#else
uint8_t FecInner : 4;
uint8_t SymbolRate4 : 4;
#endif
} __attribute__((packed));
struct SatelliteDeliveryDescriptor {
uint32_t Frequency;
uint16_t OrbitalPosition;
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
uint8_t WestEastFlag : 1;
uint8_t Polarization : 2;
uint8_t RollOff : 2;
uint8_t ModulationSystem : 1;
uint8_t ModulationType : 2;
#else
uint8_t ModulationType : 2;
uint8_t ModulationSystem : 1;
uint8_t RollOff : 2;
uint8_t Polarization : 2;
uint8_t WestEastFlag : 1;
#endif
uint8_t SymbolRate1;
uint8_t SymbolRate2;
uint8_t SymbolRate3;
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
uint8_t SymbolRate4 : 4;
uint8_t FecInner : 4;
#else
uint8_t FecInner : 4;
uint8_t SymbolRate4 : 4;
#endif
} __attribute__((packed));
struct ServiceListDescriptor {
uint16_t ServiceId;
uint8_t ServiceType;
} __attribute__((packed));
bool
SiNetworkInformationParser::CheckTableId(u_char tableId) const
{
return (tableId == 0x40 || tableId == 0x041);
}
void
SiNetworkInformationParser::ParseSiTable(const struct NetworkInformation * nit, const ::DVBSI::NetworkPtr & n)
{
n->NetworkId = ntohs(nit->header.content_id);
auto nsh = ParseDescriptors<NetworkStreamsHeader>(nit->data, HILO(nit->network_descriptor_length),
0x40, boost::bind(&SiNetworkInformationParser::parseDescriptor_NetworkName, n, _1, _2));
LoopOver<TransportStream>(nsh->data, HILO(nsh->transport_stream_loop_length), [this,n](const TransportStream * ts) {
::DVBSI::NetworkTransportStreamPtr nts = new ::DVBSI::NetworkTransportStream();
nts->TransportStreamId = ntohs(ts->transportStreamId);
nts->NetworkId = n->NetworkId;
nts->OriginalNetworkId = ntohs(ts->originalNetworkId);
ParseDescriptors(ts->data, HILO(ts->descriptors_length),
0x41, boost::bind(&SiNetworkInformationParser::parseDescriptor_ServiceList, nts, _1, _2),
0x43, boost::bind(&SiNetworkInformationParser::parseDescriptor_SatelliteDelivery, nts, _1, _2),
0x44, boost::bind(&SiNetworkInformationParser::parseDescriptor_CableDelivery, nts, _1, _2),
0x5a, boost::bind(&SiNetworkInformationParser::parseDescriptor_TerrestrialDelivery, nts, _1, _2));
n->TransportStreams.push_back(nts);
});
}
void
SiNetworkInformationParser::parseDescriptor_NetworkName(::DVBSI::NetworkPtr n, const u_char * p, size_t len)
{
n->Name = *convert((const char *)p, len);
}
AdHocFormatter(WhatIsntSupported, "%? %x");
class NotSupported : public std::runtime_error {
public:
NotSupported(const char * what, int id) : std::runtime_error(WhatIsntSupported::get(what, id)) { }
};
#define SINOTSUPPORTED(What) \
class What##NotSupported : public NotSupported { \
public: What##NotSupported(short id) : NotSupported(#What, id) { } \
};
std::map<short, fe_bandwidth_t> tbandwidths {
{0, BANDWIDTH_8_MHZ},
{1, BANDWIDTH_7_MHZ},
{2, BANDWIDTH_6_MHZ},
{3, BANDWIDTH_5_MHZ}
};
SINOTSUPPORTED(Bandwidth);
std::map<short, fe_modulation_t> tconstellations {
{0, QPSK},
{1, QAM_16},
{2, QAM_64}
};
SINOTSUPPORTED(Constellation);
std::map<short, fe_hierarchy_t> thierarchies {
{0, HIERARCHY_NONE},
{1, HIERARCHY_1},
{2, HIERARCHY_2},
{3, HIERARCHY_4},
{4, HIERARCHY_NONE},
{5, HIERARCHY_1},
{6, HIERARCHY_2},
{7, HIERARCHY_4}
};
SINOTSUPPORTED(Hierarchy);
std::map<short, fe_code_rate_t> tcoderates {
{0, FEC_1_2},
{1, FEC_2_3},
{2, FEC_3_4},
{3, FEC_5_6},
{4, FEC_7_8}
};
SINOTSUPPORTED(CodeRate);
std::map<short, fe_guard_interval_t> tguardintervals {
{0, GUARD_INTERVAL_1_32},
{1, GUARD_INTERVAL_1_16},
{2, GUARD_INTERVAL_1_8},
{3, GUARD_INTERVAL_1_4}
};
SINOTSUPPORTED(GuardInterval);
std::map<short, fe_transmit_mode_t> ttransmitmodes {
{0, TRANSMISSION_MODE_2K},
{1, TRANSMISSION_MODE_8K},
{2, TRANSMISSION_MODE_4K}
};
SINOTSUPPORTED(TransmissionMode);
void
SiNetworkInformationParser::parseDescriptor_TerrestrialDelivery(::DVBSI::NetworkTransportStreamPtr nts, const u_char * data, size_t len)
{
assert(len == sizeof(TerrestrialDeliveryDescriptor));
auto tdd = reinterpret_cast<const TerrestrialDeliveryDescriptor *>(data);
::DVBSI::TerrestrialDeliveryPtr td = new ::DVBSI::TerrestrialDelivery;
td->Frequency = ((uint64_t)ntohl(tdd->Frequency)) * 10;
td->TransportStreamId = nts->TransportStreamId;
td->Bandwidth = AdHoc::safeMapLookup<BandwidthNotSupported>(tbandwidths, tdd->Bandwidth);
td->Priority = tdd->Priority;
td->TimeSlicing = tdd->TimeSlicing;
td->MpeFec = tdd->MpeFec;
td->Constellation = AdHoc::safeMapLookup<ConstellationNotSupported>(tconstellations, tdd->Constellation);
td->Hierarchy = AdHoc::safeMapLookup<HierarchyNotSupported>(thierarchies, tdd->Hierarchy);
td->CodeRateHP = AdHoc::safeMapLookup<CodeRateNotSupported>(tcoderates, tdd->CodeRateHP);
td->CodeRateLP = AdHoc::safeMapLookup<CodeRateNotSupported>(tcoderates, tdd->CodeRateLP);
td->GuardInterval = AdHoc::safeMapLookup<GuardIntervalNotSupported>(tguardintervals, tdd->GuardInterval);
td->TransmissionMode = AdHoc::safeMapLookup<TransmissionModeNotSupported>(ttransmitmodes, tdd->TransmissionMode);
td->OtherFrequencyFlag = tdd->OtherFrequencyFlag;
nts->Terrestrial = td;
}
void
SiNetworkInformationParser::parseDescriptor_CableDelivery(::DVBSI::NetworkTransportStreamPtr nts, const u_char * data, size_t len)
{
assert(len == sizeof(CableDeliveryDescriptor));
auto cdd = reinterpret_cast<const CableDeliveryDescriptor *>(data);
::DVBSI::CableDeliveryPtr cd = new ::DVBSI::CableDelivery;
cd->Frequency = ((uint64_t)ntohl(cdd->Frequency)) * 10;
cd->TransportStreamId = nts->TransportStreamId;
cd->FecOuter = cdd->FecOuter;
cd->Modulation = cdd->Modulation;
cd->SymbolRate = HILO4(cdd->SymbolRate);
cd->FecInner = cdd->FecInner;
nts->Cable = cd;
}
void
SiNetworkInformationParser::parseDescriptor_SatelliteDelivery(::DVBSI::NetworkTransportStreamPtr nts, const u_char * data, size_t len)
{
assert(len == sizeof(SatelliteDeliveryDescriptor));
auto sdd = reinterpret_cast<const SatelliteDeliveryDescriptor *>(data);
::DVBSI::SatelliteDeliveryPtr sd = new ::DVBSI::SatelliteDelivery;
sd->Frequency = ((uint64_t)ntohl(sdd->Frequency)) * 10;
sd->TransportStreamId = nts->TransportStreamId;
sd->OrbitalPosition = ntohs(sdd->OrbitalPosition);
sd->WestEastFlag = sdd->WestEastFlag;
sd->Polarization = sdd->Polarization;
sd->RollOff = sdd->RollOff;
sd->ModulationSystem = sdd->ModulationSystem;
sd->ModulationType = sdd->ModulationType;
sd->SymbolRate = HILO4(sdd->SymbolRate);
sd->FecInner = sdd->FecInner;
nts->Satellite = sd;
}
void
SiNetworkInformationParser::parseDescriptor_ServiceList(::DVBSI::NetworkTransportStreamPtr nts, const u_char * data, size_t len)
{
auto end = data + len;
while (data < end) {
auto d = reinterpret_cast<const ServiceListDescriptor *>(data);
nts->Services.push_back({ ntohs(d->ServiceId), nts->TransportStreamId, d->ServiceType });
data += sizeof(ServiceListDescriptor);
}
}
template DLL_PUBLIC SiTableParser<NetworkInformation, ::DVBSI::NetworkPtr, u_char>::SiTableParser();
template bool DLL_PUBLIC SiTableParser<NetworkInformation, ::DVBSI::NetworkPtr, u_char>::ParseInfoTable(const u_char * data, size_t len);
}
}
|