-
Notifications
You must be signed in to change notification settings - Fork 3
/
sdt.hpp
55 lines (41 loc) · 1.04 KB
/
sdt.hpp
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
#ifndef _TSD_SDT_HPP_
#define _TSD_SDT_HPP_
#include "util.hpp"
#include "descriptor.hpp"
namespace tsd
{
struct service_description_table
{
struct service
{
uint16_t service_id;
std::vector<descriptor> descriptors;
};
// Table ID 0x42 (self stream) 0x46 (other stream)
uint16_t original_network_id;
std::vector<service> services;
void unpack(const char* data, size_t size) {
const uint8_t* p = reinterpret_cast<const uint8_t*>(data);
const uint8_t* pend = p+size;
services.clear();
original_network_id = get16(p);
p += 3;
while(pend - p > 4) {
services.resize(services.size()+1);
auto& s = services.back();
s.service_id = get16(p);
p += 3;
size_t loop_length = get16(p) & 0x0FFF;
p += 2;
const uint8_t* ploop_end = p + loop_length;
if(pend - p - 4 < loop_length)
std::runtime_error("");
while(p < ploop_end) {
s.descriptors.resize(s.descriptors.size()+1);
s.descriptors.back().unpack(&p, ploop_end);
}
}
}
};
}
#endif