-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPATTable.py
47 lines (31 loc) · 1.2 KB
/
PATTable.py
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
""" PAT table """
from TSTable import TSTable
from BinaryPacketWrapper import BinaryPacketWrapper
class PATParseException(Exception):
pass
class PATEntry:
def __init__(self):
self.program_num: int = 0
self.reserved_bits: int = 0
# PID of program map table
self.program_map_pid: int = 0
class PATTable(TSTable):
def __init__(self):
super().__init__()
self._entries = []
def parse(self, wrapper: BinaryPacketWrapper):
super().parse(wrapper)
while self._section_parsed_bytes < self._section_length:
entry = PATEntry()
entry.program_num = int.from_bytes(wrapper.get_bytes(2), byteorder='big')
self._section_parsed_bytes += 2
pid_bytes = int.from_bytes(wrapper.get_bytes(2), byteorder='big')
entry.reserved_bits = (pid_bytes & 0xe000) >> 13
if entry.reserved_bits != 0x07:
raise PATParseException('Invalid value of PAT entry reserved bits')
entry.program_map_pid = (pid_bytes & 0x1fff)
self._section_parsed_bytes += 2
self._entries.append(entry)
@property
def entries(self):
return self._entries