5 #include <packager/media/formats/mp2t/ts_section_pat.h>
9 #include <absl/log/log.h>
11 #include <packager/macros/logging.h>
12 #include <packager/media/base/bit_reader.h>
13 #include <packager/media/formats/mp2t/mp2t_common.h>
19 TsSectionPat::TsSectionPat(
const RegisterPmtCb& register_pmt_cb)
20 : register_pmt_cb_(register_pmt_cb),
24 TsSectionPat::~TsSectionPat() {
27 bool TsSectionPat::ParsePsiSection(BitReader* bit_reader) {
30 int section_syntax_indicator;
34 int transport_stream_id;
36 int current_next_indicator;
38 int last_section_number;
39 RCHECK(bit_reader->ReadBits(8, &table_id));
40 RCHECK(bit_reader->ReadBits(1, §ion_syntax_indicator));
41 RCHECK(bit_reader->ReadBits(1, &dummy_zero));
42 RCHECK(bit_reader->ReadBits(2, &reserved));
43 RCHECK(bit_reader->ReadBits(12, §ion_length));
44 RCHECK(section_length >= 5);
45 RCHECK(section_length <= 1021);
46 RCHECK(bit_reader->ReadBits(16, &transport_stream_id));
47 RCHECK(bit_reader->ReadBits(2, &reserved));
48 RCHECK(bit_reader->ReadBits(5, &version_number));
49 RCHECK(bit_reader->ReadBits(1, ¤t_next_indicator));
50 RCHECK(bit_reader->ReadBits(8, §ion_number));
51 RCHECK(bit_reader->ReadBits(8, &last_section_number));
58 RCHECK(table_id == 0x0);
59 RCHECK(section_syntax_indicator);
64 RCHECK((section_length % 4) == 0);
65 int pmt_pid_count = (section_length - 4) / 4;
68 std::vector<int> program_number_array(pmt_pid_count);
69 std::vector<int> pmt_pid_array(pmt_pid_count);
70 for (
int k = 0; k < pmt_pid_count; k++) {
71 RCHECK(bit_reader->ReadBits(16, &program_number_array[k]));
72 RCHECK(bit_reader->ReadBits(3, &reserved));
73 RCHECK(bit_reader->ReadBits(13, &pmt_pid_array[k]));
76 RCHECK(bit_reader->ReadBits(32, &crc32));
79 if (!current_next_indicator) {
80 DVLOG(1) <<
"Not supported: received a PAT not applicable yet";
85 if (version_number == version_number_)
90 if (pmt_pid_count > 1) {
91 LOG(ERROR) <<
"Multiple programs detected in the Mpeg2 TS stream";
97 int expected_version_number = version_number;
98 if (version_number_ >= 0)
99 expected_version_number = (version_number_ + 1) % 32;
100 if (version_number != expected_version_number) {
101 VLOG(1) <<
"Unexpected version number: " << version_number <<
" vs "
105 for (
int k = 0; k < pmt_pid_count; k++) {
106 if (program_number_array[k] != 0) {
108 register_pmt_cb_(program_number_array[k], pmt_pid_array[k]);
114 version_number_ = version_number;
119 void TsSectionPat::ResetPsiSection() {
120 version_number_ = -1;
All the methods that are virtual are virtual for mocking.