5 #include "packager/media/formats/mp2t/ts_section_pat.h"
9 #include "packager/base/logging.h"
10 #include "packager/media/base/bit_reader.h"
11 #include "packager/media/formats/mp2t/mp2t_common.h"
17 TsSectionPat::TsSectionPat(
const RegisterPmtCb& register_pmt_cb)
18 : register_pmt_cb_(register_pmt_cb),
22 TsSectionPat::~TsSectionPat() {
25 bool TsSectionPat::ParsePsiSection(BitReader* bit_reader) {
28 int section_syntax_indicator;
32 int transport_stream_id;
34 int current_next_indicator;
36 int last_section_number;
37 RCHECK(bit_reader->ReadBits(8, &table_id));
38 RCHECK(bit_reader->ReadBits(1, §ion_syntax_indicator));
39 RCHECK(bit_reader->ReadBits(1, &dummy_zero));
40 RCHECK(bit_reader->ReadBits(2, &reserved));
41 RCHECK(bit_reader->ReadBits(12, §ion_length));
42 RCHECK(section_length >= 5);
43 RCHECK(section_length <= 1021);
44 RCHECK(bit_reader->ReadBits(16, &transport_stream_id));
45 RCHECK(bit_reader->ReadBits(2, &reserved));
46 RCHECK(bit_reader->ReadBits(5, &version_number));
47 RCHECK(bit_reader->ReadBits(1, ¤t_next_indicator));
48 RCHECK(bit_reader->ReadBits(8, §ion_number));
49 RCHECK(bit_reader->ReadBits(8, &last_section_number));
56 RCHECK(table_id == 0x0);
57 RCHECK(section_syntax_indicator);
62 RCHECK((section_length % 4) == 0);
63 int pmt_pid_count = (section_length - 4) / 4;
66 std::vector<int> program_number_array(pmt_pid_count);
67 std::vector<int> pmt_pid_array(pmt_pid_count);
68 for (
int k = 0; k < pmt_pid_count; k++) {
70 RCHECK(bit_reader->ReadBits(16, &program_number_array[k]));
71 RCHECK(bit_reader->ReadBits(3, &reserved));
72 RCHECK(bit_reader->ReadBits(13, &pmt_pid_array[k]));
75 RCHECK(bit_reader->ReadBits(32, &crc32));
78 if (!current_next_indicator) {
79 DVLOG(1) <<
"Not supported: received a PAT not applicable yet";
84 if (version_number == version_number_)
89 if (pmt_pid_count > 1) {
90 DVLOG(1) <<
"Multiple programs detected in the Mpeg2 TS stream";
96 int expected_version_number = version_number;
97 if (version_number_ >= 0)
98 expected_version_number = (version_number_ + 1) % 32;
99 DVLOG_IF(1, version_number != expected_version_number)
100 <<
"Unexpected version number: "
101 << version_number <<
" vs " << version_number_;
103 for (
int k = 0; k < pmt_pid_count; k++) {
104 if (program_number_array[k] != 0) {
106 register_pmt_cb_.Run(program_number_array[k], pmt_pid_array[k]);
112 version_number_ = version_number;
117 void TsSectionPat::ResetPsiSection() {
118 version_number_ = -1;