-
Notifications
You must be signed in to change notification settings - Fork 3
/
pmt.hpp
76 lines (62 loc) · 1.54 KB
/
pmt.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef _TSD_PMT_HPP_
#define _TSD_PMT_HPP_
#include <vector>
#include <memory>
#include "util.hpp"
#include "descriptor.hpp"
namespace tsd
{
struct program_element
{
uint8_t stream_type;
uint16_t elementary_pid;
std::vector<descriptor> es_info;
void unpack(const uint8_t** pp, const uint8_t* pend) {
const uint8_t* p = *pp;
if(pend - p < 5)
std::runtime_error("");
stream_type = get8(p);
p += 1;
elementary_pid = get16(p) & 0x1FFF;
p += 2;
int32_t es_info_length = get16(p) & 0x0FFF;
p += 2;
const uint8_t* peiend = p + es_info_length;
es_info.clear();
while(peiend - p >= 2) {
es_info.resize(es_info.size()+1);
es_info.back().unpack(&p, pend);
}
p = peiend;
*pp = p;
}
};
struct program_map_table
{
uint16_t pcr_pid;
std::vector<descriptor> program_info;
std::vector<program_element> program_elements;
public:
void unpack(const char* data, size_t size) {
const uint8_t* p = reinterpret_cast<const uint8_t*>(data);
const uint8_t* pend = p+size;
pcr_pid = get16(p) & 0x1FFF;
p += 2;
int32_t program_info_length = get16(p) & 0x0FFF;
p += 2;
const uint8_t* piend = p + program_info_length;
program_info.clear();
while(piend - p >= 2) {
program_info.resize(program_info.size()+1);
program_info.back().unpack(&p, pend);
}
p = piend;
program_elements.clear();
while(pend - p >= 5+4) {
program_elements.resize(program_elements.size()+1);
program_elements.back().unpack(&p, pend);
}
}
};
}
#endif