From a86a697d8dd9aeef2ce02a49a4661dafaa1a8bd2 Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Tue, 26 Mar 2019 15:16:30 -0700 Subject: [PATCH] Add more loggings for GAPs Fixes #474. Change-Id: I32f097c8a0e8d3381a276e6a130cb888e3ddd7f6 --- packager/media/formats/mp2t/es_parser_h26x.cc | 14 ++++++++-- packager/mpd/base/representation.cc | 28 +++++++++++++++++-- packager/mpd/base/representation.h | 3 ++ 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/packager/media/formats/mp2t/es_parser_h26x.cc b/packager/media/formats/mp2t/es_parser_h26x.cc index 14cbf69fd0..9f3df7d61b 100644 --- a/packager/media/formats/mp2t/es_parser_h26x.cc +++ b/packager/media/formats/mp2t/es_parser_h26x.cc @@ -326,8 +326,18 @@ bool EsParserH26x::EmitFrame(int64_t access_unit_pos, const int64_t kArbitrarySmallDuration = 0.001 * kMpeg2Timescale; // 1ms. pending_sample_->set_duration(kArbitrarySmallDuration); } else { - pending_sample_duration_ = media_sample->dts() - pending_sample_->dts(); - pending_sample_->set_duration(pending_sample_duration_); + uint64_t sample_duration = media_sample->dts() - pending_sample_->dts(); + pending_sample_->set_duration(sample_duration); + + const int kArbitraryGapScale = 10; + if (sample_duration > kArbitraryGapScale * pending_sample_duration_) { + LOG(WARNING) << "[MPEG-2 TS] PID " << pid() << " Possible GAP at dts " + << pending_sample_->dts() << " with next sample at dts " + << media_sample->dts() << " (difference " + << sample_duration << ")"; + } + + pending_sample_duration_ = sample_duration; } emit_sample_cb_.Run(pid(), std::move(pending_sample_)); } diff --git a/packager/mpd/base/representation.cc b/packager/mpd/base/representation.cc index ebaa4e05fb..b1b46c8c2e 100644 --- a/packager/mpd/base/representation.cc +++ b/packager/mpd/base/representation.cc @@ -11,6 +11,7 @@ #include #include "packager/base/logging.h" +#include "packager/base/strings/stringprintf.h" #include "packager/file/file.h" #include "packager/media/base/muxer_util.h" #include "packager/mpd/base/mpd_options.h" @@ -358,7 +359,7 @@ void Representation::AddSegmentInfo(int64_t start_time, int64_t duration) { // A gap since previous. const int64_t kRoundingErrorGrace = 5; if (previous_segment_end_time + kRoundingErrorGrace < start_time) { - LOG(WARNING) << "Found a gap of size " + LOG(WARNING) << RepresentationAsString() << " Found a gap of size " << (start_time - previous_segment_end_time) << " > kRoundingErrorGrace (" << kRoundingErrorGrace << "). The new segment starts at " << start_time @@ -369,7 +370,8 @@ void Representation::AddSegmentInfo(int64_t start_time, int64_t duration) { // No overlapping segments. if (start_time < previous_segment_end_time - kRoundingErrorGrace) { LOG(WARNING) - << "Segments should not be overlapping. The new segment starts at " + << RepresentationAsString() + << " Segments should not be overlapping. The new segment starts at " << start_time << " but the previous segment ends at " << previous_segment_end_time << "."; } @@ -504,4 +506,26 @@ std::string Representation::GetTextMimeType() const { return ""; } +std::string Representation::RepresentationAsString() const { + std::string s = base::StringPrintf("Representation (id=%d,", id_); + if (media_info_.has_video_info()) { + const MediaInfo_VideoInfo& video_info = media_info_.video_info(); + base::StringAppendF(&s, "codec='%s',width=%d,height=%d", + video_info.codec().c_str(), video_info.width(), + video_info.height()); + } else if (media_info_.has_audio_info()) { + const MediaInfo_AudioInfo& audio_info = media_info_.audio_info(); + base::StringAppendF( + &s, "codec='%s',frequency=%d,language='%s'", audio_info.codec().c_str(), + audio_info.sampling_frequency(), audio_info.language().c_str()); + } else if (media_info_.has_text_info()) { + const MediaInfo_TextInfo& text_info = media_info_.text_info(); + base::StringAppendF(&s, "codec='%s',language='%s'", + text_info.codec().c_str(), + text_info.language().c_str()); + } + base::StringAppendF(&s, ")"); + return s; +} + } // namespace shaka diff --git a/packager/mpd/base/representation.h b/packager/mpd/base/representation.h index 6f336cf88f..813d43edc5 100644 --- a/packager/mpd/base/representation.h +++ b/packager/mpd/base/representation.h @@ -206,6 +206,9 @@ class Representation { std::string GetAudioMimeType() const; std::string GetTextMimeType() const; + // Get Representation as string. For debugging. + std::string RepresentationAsString() const; + // Init() checks that only one of VideoInfo, AudioInfo, or TextInfo is set. So // any logic using this can assume only one set. MediaInfo media_info_;