Use TsStreamType for MP2T parser.

This also changes some of the logs to error so the user can see why
the parsing failed.

Change-Id: Ib8b7a5076462bccc718e17ef9e0a57d172d1f7b4
This commit is contained in:
Jacob Trimble 2021-01-25 12:16:32 -08:00
parent a6cce5e611
commit 5bcda6b88b
5 changed files with 21 additions and 24 deletions

View File

@ -99,7 +99,7 @@ bool PidState::PushTsPacket(const TsPacket& ts_packet) {
int expected_continuity_counter = (continuity_counter_ + 1) % 16; int expected_continuity_counter = (continuity_counter_ + 1) % 16;
if (continuity_counter_ >= 0 && if (continuity_counter_ >= 0 &&
ts_packet.continuity_counter() != expected_continuity_counter) { ts_packet.continuity_counter() != expected_continuity_counter) {
DVLOG(1) << "TS discontinuity detected for pid: " << pid_; LOG(ERROR) << "TS discontinuity detected for pid: " << pid_;
// TODO(tinskip): Handle discontinuity better. // TODO(tinskip): Handle discontinuity better.
return false; return false;
} }
@ -112,7 +112,7 @@ bool PidState::PushTsPacket(const TsPacket& ts_packet) {
// At the minimum, when parsing failed, auto reset the section parser. // At the minimum, when parsing failed, auto reset the section parser.
// Components that use the Mp2tMediaParser can take further action if needed. // Components that use the Mp2tMediaParser can take further action if needed.
if (!status) { if (!status) {
DVLOG(1) << "Parsing failed for pid = " << pid_; LOG(ERROR) << "Parsing failed for pid = " << pid_ << ", type=" << pid_type_;
ResetState(); ResetState();
} }
@ -234,8 +234,7 @@ bool Mp2tMediaParser::Parse(const uint8_t* buf, int size) {
} }
if (it != pids_.end()) { if (it != pids_.end()) {
if (!it->second->PushTsPacket(*ts_packet)) RCHECK(it->second->PushTsPacket(*ts_packet));
return false;
} else { } else {
DVLOG(LOG_LEVEL_TS) << "Ignoring TS packet for pid: " << ts_packet->pid(); DVLOG(LOG_LEVEL_TS) << "Ignoring TS packet for pid: " << ts_packet->pid();
} }
@ -274,12 +273,12 @@ void Mp2tMediaParser::RegisterPmt(int program_number, int pmt_pid) {
void Mp2tMediaParser::RegisterPes(int pmt_pid, void Mp2tMediaParser::RegisterPes(int pmt_pid,
int pes_pid, int pes_pid,
uint8_t stream_type) { TsStreamType stream_type) {
if (pids_.count(pes_pid) != 0) if (pids_.count(pes_pid) != 0)
return; return;
DVLOG(1) << "RegisterPes:" DVLOG(1) << "RegisterPes:"
<< " pes_pid=" << pes_pid << " stream_type=" << std::hex << " pes_pid=" << pes_pid << " stream_type=" << std::hex
<< stream_type << std::dec; << static_cast<int>(stream_type) << std::dec;
// Create a stream parser corresponding to the stream type. // Create a stream parser corresponding to the stream type.
bool is_audio = false; bool is_audio = false;
@ -288,7 +287,7 @@ void Mp2tMediaParser::RegisterPes(int pmt_pid,
base::Unretained(this), pes_pid); base::Unretained(this), pes_pid);
auto on_emit_media = base::Bind(&Mp2tMediaParser::OnEmitMediaSample, auto on_emit_media = base::Bind(&Mp2tMediaParser::OnEmitMediaSample,
base::Unretained(this), pes_pid); base::Unretained(this), pes_pid);
switch (static_cast<TsStreamType>(stream_type)) { switch (stream_type) {
case TsStreamType::kAvc: case TsStreamType::kAvc:
es_parser.reset(new EsParserH264(pes_pid, on_new_stream, on_emit_media)); es_parser.reset(new EsParserH264(pes_pid, on_new_stream, on_emit_media));
break; break;
@ -304,10 +303,11 @@ void Mp2tMediaParser::RegisterPes(int pmt_pid,
is_audio = true; is_audio = true;
break; break;
default: { default: {
LOG_IF(ERROR, !stream_type_logged_once_[stream_type]) auto type = static_cast<int>(stream_type);
<< "Ignore unsupported MPEG2TS stream type 0x" << std::hex LOG_IF(ERROR, !stream_type_logged_once_[type])
<< stream_type << std::dec; << "Ignore unsupported MPEG2TS stream type 0x" << std::hex << type
stream_type_logged_once_[stream_type] = true; << std::dec;
stream_type_logged_once_[type] = true;
return; return;
} }
} }
@ -427,18 +427,12 @@ bool Mp2tMediaParser::EmitRemainingSamples() {
// Buffer emission. // Buffer emission.
for (const auto& pid_pair : pids_) { for (const auto& pid_pair : pids_) {
for (auto sample : pid_pair.second->media_sample_queue_) { for (auto sample : pid_pair.second->media_sample_queue_) {
if (!new_media_sample_cb_.Run(pid_pair.first, sample)) { RCHECK(new_media_sample_cb_.Run(pid_pair.first, sample));
// Error processing sample. Propagate error condition.
return false;
}
} }
pid_pair.second->media_sample_queue_.clear(); pid_pair.second->media_sample_queue_.clear();
for (auto sample : pid_pair.second->text_sample_queue_) { for (auto sample : pid_pair.second->text_sample_queue_) {
if (!new_text_sample_cb_.Run(pid_pair.first, sample)) { RCHECK(new_text_sample_cb_.Run(pid_pair.first, sample));
// Error processing sample. Propagate error condition.
return false;
}
} }
pid_pair.second->text_sample_queue_.clear(); pid_pair.second->text_sample_queue_.clear();
} }

View File

@ -13,6 +13,7 @@
#include "packager/media/base/byte_queue.h" #include "packager/media/base/byte_queue.h"
#include "packager/media/base/media_parser.h" #include "packager/media/base/media_parser.h"
#include "packager/media/base/stream_info.h" #include "packager/media/base/stream_info.h"
#include "packager/media/formats/mp2t/ts_stream_type.h"
namespace shaka { namespace shaka {
namespace media { namespace media {
@ -49,7 +50,7 @@ class Mp2tMediaParser : public MediaParser {
// Possible values for |media_type| are defined in: // Possible values for |media_type| are defined in:
// ISO-13818.1 / ITU H.222 Table 2.34 "Media type assignments". // ISO-13818.1 / ITU H.222 Table 2.34 "Media type assignments".
// |pes_pid| is part of the Program Map Table refered by |pmt_pid|. // |pes_pid| is part of the Program Map Table refered by |pmt_pid|.
void RegisterPes(int pmt_pid, int pes_pid, uint8_t media_type); void RegisterPes(int pmt_pid, int pes_pid, TsStreamType media_type);
// Callback invoked each time the audio/video decoder configuration is // Callback invoked each time the audio/video decoder configuration is
// changed. // changed.

View File

@ -87,7 +87,7 @@ bool TsSectionPat::ParsePsiSection(BitReader* bit_reader) {
// Both the MSE and the HLS spec specifies that TS streams should convey // Both the MSE and the HLS spec specifies that TS streams should convey
// exactly one program. // exactly one program.
if (pmt_pid_count > 1) { if (pmt_pid_count > 1) {
DVLOG(1) << "Multiple programs detected in the Mpeg2 TS stream"; LOG(ERROR) << "Multiple programs detected in the Mpeg2 TS stream";
return false; return false;
} }

View File

@ -9,6 +9,7 @@
#include "packager/base/logging.h" #include "packager/base/logging.h"
#include "packager/media/base/bit_reader.h" #include "packager/media/base/bit_reader.h"
#include "packager/media/formats/mp2t/mp2t_common.h" #include "packager/media/formats/mp2t/mp2t_common.h"
#include "packager/media/formats/mp2t/ts_stream_type.h"
namespace shaka { namespace shaka {
namespace media { namespace media {
@ -75,10 +76,10 @@ bool TsSectionPmt::ParsePsiSection(BitReader* bit_reader) {
// The end of the PID map if 4 bytes away from the end of the section // The end of the PID map if 4 bytes away from the end of the section
// (4 bytes = size of the CRC). // (4 bytes = size of the CRC).
int pid_map_end_marker = section_start_marker - section_length + 4; int pid_map_end_marker = section_start_marker - section_length + 4;
std::map<int, uint8_t> pid_map; std::map<int, TsStreamType> pid_map;
while (static_cast<int>(bit_reader->bits_available()) > while (static_cast<int>(bit_reader->bits_available()) >
8 * pid_map_end_marker) { 8 * pid_map_end_marker) {
uint8_t stream_type; TsStreamType stream_type;
int pid_es; int pid_es;
int es_info_length; int es_info_length;
RCHECK(bit_reader->ReadBits(8, &stream_type)); RCHECK(bit_reader->ReadBits(8, &stream_type));

View File

@ -8,6 +8,7 @@
#include "packager/base/callback.h" #include "packager/base/callback.h"
#include "packager/base/compiler_specific.h" #include "packager/base/compiler_specific.h"
#include "packager/media/formats/mp2t/ts_section_psi.h" #include "packager/media/formats/mp2t/ts_section_psi.h"
#include "packager/media/formats/mp2t/ts_stream_type.h"
namespace shaka { namespace shaka {
namespace media { namespace media {
@ -18,7 +19,7 @@ class TsSectionPmt : public TsSectionPsi {
// RegisterPesCb::Run(int pes_pid, int stream_type); // RegisterPesCb::Run(int pes_pid, int stream_type);
// Stream type is defined in // Stream type is defined in
// "Table 2-34 Stream type assignments" in H.222 // "Table 2-34 Stream type assignments" in H.222
typedef base::Callback<void(int, uint8_t)> RegisterPesCb; typedef base::Callback<void(int, TsStreamType)> RegisterPesCb;
explicit TsSectionPmt(const RegisterPesCb& register_pes_cb); explicit TsSectionPmt(const RegisterPesCb& register_pes_cb);
~TsSectionPmt() override; ~TsSectionPmt() override;