Propagate Flush errors in MP2T parser.

Issue #832

Change-Id: I59f31ff491437b81ffc22ab5760ad0c059e9933e
This commit is contained in:
Jacob Trimble 2020-12-10 15:03:41 -08:00
parent 89d407f9ae
commit 2eb32ee177
11 changed files with 22 additions and 17 deletions

View File

@ -35,7 +35,7 @@ class EsParser {
int64_t dts) = 0; int64_t dts) = 0;
// Flush any pending buffer. // Flush any pending buffer.
virtual void Flush() = 0; virtual bool Flush() = 0;
// Reset the state of the ES parser. // Reset the state of the ES parser.
virtual void Reset() = 0; virtual void Reset() = 0;

View File

@ -182,7 +182,9 @@ bool EsParserAudio::Parse(const uint8_t* buf,
return true; return true;
} }
void EsParserAudio::Flush() {} bool EsParserAudio::Flush() {
return true;
}
void EsParserAudio::Reset() { void EsParserAudio::Reset() {
es_byte_queue_.Reset(); es_byte_queue_.Reset();

View File

@ -36,7 +36,7 @@ class EsParserAudio : public EsParser {
// EsParser implementation. // EsParser implementation.
bool Parse(const uint8_t* buf, int size, int64_t pts, int64_t dts) override; bool Parse(const uint8_t* buf, int size, int64_t pts, int64_t dts) override;
void Flush() override; bool Flush() override;
void Reset() override; void Reset() override;
private: private:

View File

@ -77,7 +77,7 @@ bool EsParserH26x::Parse(const uint8_t* buf,
return ParseInternal(); return ParseInternal();
} }
void EsParserH26x::Flush() { bool EsParserH26x::Flush() {
DVLOG(1) << "EsParserH26x::Flush"; DVLOG(1) << "EsParserH26x::Flush";
// Simulate two additional AUDs to force emitting the last access unit // Simulate two additional AUDs to force emitting the last access unit
@ -95,7 +95,7 @@ void EsParserH26x::Flush() {
es_queue_->Push(aud, sizeof(aud)); es_queue_->Push(aud, sizeof(aud));
} }
CHECK(ParseInternal()); RCHECK(ParseInternal());
if (pending_sample_) { if (pending_sample_) {
// Flush pending sample. // Flush pending sample.
@ -103,6 +103,7 @@ void EsParserH26x::Flush() {
pending_sample_->set_duration(pending_sample_duration_); pending_sample_->set_duration(pending_sample_duration_);
emit_sample_cb_.Run(std::move(pending_sample_)); emit_sample_cb_.Run(std::move(pending_sample_));
} }
return true;
} }
void EsParserH26x::Reset() { void EsParserH26x::Reset() {

View File

@ -35,7 +35,7 @@ class EsParserH26x : public EsParser {
// EsParser implementation overrides. // EsParser implementation overrides.
bool Parse(const uint8_t* buf, int size, int64_t pts, int64_t dts) override; bool Parse(const uint8_t* buf, int size, int64_t pts, int64_t dts) override;
void Flush() override; bool Flush() override;
void Reset() override; void Reset() override;
protected: protected:

View File

@ -45,7 +45,7 @@ class PidState {
// Flush the PID state (possibly emitting some pending frames) // Flush the PID state (possibly emitting some pending frames)
// and reset its state. // and reset its state.
void Flush(); bool Flush();
// Enable/disable the PID. // Enable/disable the PID.
// Disabling a PID will reset its state and ignore any further incoming TS // Disabling a PID will reset its state and ignore any further incoming TS
@ -119,9 +119,10 @@ bool PidState::PushTsPacket(const TsPacket& ts_packet) {
return status; return status;
} }
void PidState::Flush() { bool PidState::Flush() {
section_parser_->Flush(); RCHECK(section_parser_->Flush());
ResetState(); ResetState();
return true;
} }
void PidState::Enable() { void PidState::Enable() {
@ -174,7 +175,7 @@ bool Mp2tMediaParser::Flush() {
for (const auto& pair : pids_) { for (const auto& pair : pids_) {
DVLOG(1) << "Flushing PID: " << pair.first; DVLOG(1) << "Flushing PID: " << pair.first;
PidState* pid_state = pair.second.get(); PidState* pid_state = pair.second.get();
pid_state->Flush(); RCHECK(pid_state->Flush());
} }
bool result = EmitRemainingSamples(); bool result = EmitRemainingSamples();
pids_.clear(); pids_.clear();

View File

@ -30,7 +30,7 @@ class TsSection {
// Process bytes that have not been processed yet (pending buffers in the // Process bytes that have not been processed yet (pending buffers in the
// pipe). Flush might thus results in frame emission, as an example. // pipe). Flush might thus results in frame emission, as an example.
virtual void Flush() = 0; virtual bool Flush() = 0;
// Reset the state of the parser to its initial state. // Reset the state of the parser to its initial state.
virtual void Reset() = 0; virtual void Reset() = 0;

View File

@ -128,13 +128,13 @@ bool TsSectionPes::Parse(bool payload_unit_start_indicator,
return (parse_result && Emit(false)); return (parse_result && Emit(false));
} }
void TsSectionPes::Flush() { bool TsSectionPes::Flush() {
// Try emitting a packet since we might have a pending PES packet // Try emitting a packet since we might have a pending PES packet
// with an undefined size. // with an undefined size.
Emit(true); RCHECK(Emit(true));
// Flush the underlying ES parser. // Flush the underlying ES parser.
es_parser_->Flush(); return es_parser_->Flush();
} }
void TsSectionPes::Reset() { void TsSectionPes::Reset() {

View File

@ -26,7 +26,7 @@ class TsSectionPes : public TsSection {
bool Parse(bool payload_unit_start_indicator, bool Parse(bool payload_unit_start_indicator,
const uint8_t* buf, const uint8_t* buf,
int size) override; int size) override;
void Flush() override; bool Flush() override;
void Reset() override; void Reset() override;
private: private:

View File

@ -118,7 +118,8 @@ bool TsSectionPsi::Parse(bool payload_unit_start_indicator,
return status; return status;
} }
void TsSectionPsi::Flush() { bool TsSectionPsi::Flush() {
return true;
} }
void TsSectionPsi::Reset() { void TsSectionPsi::Reset() {

View File

@ -25,7 +25,7 @@ class TsSectionPsi : public TsSection {
bool Parse(bool payload_unit_start_indicator, bool Parse(bool payload_unit_start_indicator,
const uint8_t* buf, const uint8_t* buf,
int size) override; int size) override;
void Flush() override; bool Flush() override;
void Reset() override; void Reset() override;
// Parse the content of the PSI section. // Parse the content of the PSI section.