This source file includes following definitions.
- version_number_
- ParsePsiSection
- ResetPsiSection
#include "media/formats/mp2t/ts_section_pat.h"
#include <vector>
#include "base/logging.h"
#include "media/base/bit_reader.h"
#include "media/formats/mp2t/mp2t_common.h"
namespace media {
namespace mp2t {
TsSectionPat::TsSectionPat(const RegisterPmtCb& register_pmt_cb)
: register_pmt_cb_(register_pmt_cb),
version_number_(-1) {
}
TsSectionPat::~TsSectionPat() {
}
bool TsSectionPat::ParsePsiSection(BitReader* bit_reader) {
int table_id;
int section_syntax_indicator;
int dummy_zero;
int reserved;
int section_length;
int transport_stream_id;
int version_number;
int current_next_indicator;
int section_number;
int last_section_number;
RCHECK(bit_reader->ReadBits(8, &table_id));
RCHECK(bit_reader->ReadBits(1, §ion_syntax_indicator));
RCHECK(bit_reader->ReadBits(1, &dummy_zero));
RCHECK(bit_reader->ReadBits(2, &reserved));
RCHECK(bit_reader->ReadBits(12, §ion_length));
RCHECK(section_length >= 5);
RCHECK(section_length <= 1021);
RCHECK(bit_reader->ReadBits(16, &transport_stream_id));
RCHECK(bit_reader->ReadBits(2, &reserved));
RCHECK(bit_reader->ReadBits(5, &version_number));
RCHECK(bit_reader->ReadBits(1, ¤t_next_indicator));
RCHECK(bit_reader->ReadBits(8, §ion_number));
RCHECK(bit_reader->ReadBits(8, &last_section_number));
section_length -= 5;
RCHECK(table_id == 0x0);
RCHECK(section_syntax_indicator);
RCHECK(!dummy_zero);
RCHECK((section_length % 4) == 0);
int pmt_pid_count = (section_length - 4) / 4;
std::vector<int> program_number_array(pmt_pid_count);
std::vector<int> pmt_pid_array(pmt_pid_count);
for (int k = 0; k < pmt_pid_count; k++) {
int reserved;
RCHECK(bit_reader->ReadBits(16, &program_number_array[k]));
RCHECK(bit_reader->ReadBits(3, &reserved));
RCHECK(bit_reader->ReadBits(13, &pmt_pid_array[k]));
}
int crc32;
RCHECK(bit_reader->ReadBits(32, &crc32));
if (!current_next_indicator) {
DVLOG(1) << "Not supported: received a PAT not applicable yet";
return true;
}
if (version_number == version_number_)
return true;
if (pmt_pid_count > 1) {
DVLOG(1) << "Multiple programs detected in the Mpeg2 TS stream";
return false;
}
#if !defined(NDEBUG)
int expected_version_number = version_number;
if (version_number_ >= 0)
expected_version_number = (version_number_ + 1) % 32;
DVLOG_IF(1, version_number != expected_version_number)
<< "Unexpected version number: "
<< version_number << " vs " << version_number_;
#endif
for (int k = 0; k < pmt_pid_count; k++) {
if (program_number_array[k] != 0) {
register_pmt_cb_.Run(program_number_array[k], pmt_pid_array[k]);
break;
}
}
version_number_ = version_number;
return true;
}
void TsSectionPat::ResetPsiSection() {
version_number_ = -1;
}
}
}