-
Notifications
You must be signed in to change notification settings - Fork 0
/
PMTTable.py
50 lines (36 loc) · 1.41 KB
/
PMTTable.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
48
49
50
""" PMT table """
from TSTable import TSTable
from BinaryPacketWrapper import BinaryPacketWrapper
class PMTParseException(Exception):
pass
class PMTTable(TSTable):
def __init__(self, program_num, pmt_pid):
super().__init__()
self._program_num = program_num
self._associated_pids = []
self._associated_pids.append(pmt_pid)
def parse(self, wrapper: BinaryPacketWrapper):
super().parse(wrapper)
# Ignore reserved and PCR bits
wrapper.get_bytes(2)
self._section_parsed_bytes += 2
# Get program info length
wrapper.get_bytes(2)
self._section_parsed_bytes += 2
while self._section_parsed_bytes < self._section_length:
wrapper.get_byte()
self._section_parsed_bytes += 1
# Get associated PID
pid_bytes = int.from_bytes(wrapper.get_bytes(2), byteorder='big')
self._section_parsed_bytes += 2
associated_pid = pid_bytes & 0x1fff
self._associated_pids.append(associated_pid)
# Skip descriptors
desc_len_bytes = int.from_bytes(wrapper.get_bytes(2), byteorder='big')
self._section_parsed_bytes += 2
desc_len = desc_len_bytes & 0x03ff
wrapper.get_bytes(desc_len)
self._section_parsed_bytes += desc_len
@property
def associated_pids(self):
return self._associated_pids