This source file includes following definitions.
- ParsePsiSection
- ResetPsiSection
#include "media/formats/mp2t/ts_section_pmt.h"
#include <map>
#include "base/logging.h"
#include "media/base/bit_reader.h"
#include "media/formats/mp2t/mp2t_common.h"
namespace media {
namespace mp2t {
TsSectionPmt::TsSectionPmt(const RegisterPesCb& register_pes_cb)
: register_pes_cb_(register_pes_cb) {
}
TsSectionPmt::~TsSectionPmt() {
}
bool TsSectionPmt::ParsePsiSection(BitReader* bit_reader) {
int table_id;
int section_syntax_indicator;
int dummy_zero;
int reserved;
int section_length;
int program_number;
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));
int section_start_marker = bit_reader->bits_available() / 8;
RCHECK(bit_reader->ReadBits(16, &program_number));
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));
RCHECK(table_id == 0x2);
RCHECK(section_syntax_indicator);
RCHECK(!dummy_zero);
RCHECK(section_length <= 1021);
RCHECK(section_number == 0);
RCHECK(last_section_number == 0);
int pcr_pid;
int program_info_length;
RCHECK(bit_reader->ReadBits(3, &reserved));
RCHECK(bit_reader->ReadBits(13, &pcr_pid));
RCHECK(bit_reader->ReadBits(4, &reserved));
RCHECK(bit_reader->ReadBits(12, &program_info_length));
RCHECK(program_info_length < 1024);
RCHECK(bit_reader->SkipBits(8 * program_info_length));
int pid_map_end_marker = section_start_marker - section_length + 4;
std::map<int, int> pid_map;
while (bit_reader->bits_available() > 8 * pid_map_end_marker) {
int stream_type;
int reserved;
int pid_es;
int es_info_length;
RCHECK(bit_reader->ReadBits(8, &stream_type));
RCHECK(bit_reader->ReadBits(3, &reserved));
RCHECK(bit_reader->ReadBits(13, &pid_es));
RCHECK(bit_reader->ReadBits(4, &reserved));
RCHECK(bit_reader->ReadBits(12, &es_info_length));
pid_map.insert(std::pair<int, int>(pid_es, stream_type));
RCHECK(bit_reader->SkipBits(8 * es_info_length));
}
int crc32;
RCHECK(bit_reader->ReadBits(32, &crc32));
for (std::map<int, int>::iterator it = pid_map.begin();
it != pid_map.end(); ++it)
register_pes_cb_.Run(it->first, it->second);
return true;
}
void TsSectionPmt::ResetPsiSection() {
}
}
}