From bd3ab3abe640796b65422b18a3751b7dfb814680 Mon Sep 17 00:00:00 2001 From: Frank Galligan Date: Fri, 29 Apr 2016 11:51:16 -0700 Subject: [PATCH] Add flag to estimate last frame's duration to stats. BUG=https://bugs.chromium.org/p/webm/issues/detail?id=1204 Change-Id: Ie73e2981951f9eb6140bdfb0a6839320e009b7fe --- common/vp9_level_stats.cc | 13 +++++++++++-- common/vp9_level_stats.h | 15 ++++++++++++++- common/vp9_level_stats_tests.cc | 11 +++++++++-- webm_info.cc | 2 +- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/common/vp9_level_stats.cc b/common/vp9_level_stats.cc index 7459a85..79ef967 100644 --- a/common/vp9_level_stats.cc +++ b/common/vp9_level_stats.cc @@ -211,9 +211,18 @@ int64_t Vp9LevelStats::GetMaxLumaPictureSize() const { } double Vp9LevelStats::GetAverageBitRate() const { - const double duration_seconds = - ((duration_ns_ == -1) ? end_ns_ - start_ns_ : duration_ns_) / + const int64_t frame_duration_ns = end_ns_ - start_ns_; + double duration_seconds = + ((duration_ns_ == -1) ? frame_duration_ns : duration_ns_) / libwebm::kNanosecondsPerSecond; + if (estimate_last_frame_duration_ && + (duration_ns_ == -1 || duration_ns_ <= frame_duration_ns)) { + const double sec_per_frame = frame_duration_ns / + libwebm::kNanosecondsPerSecond / + (displayed_frames - 1); + duration_seconds += sec_per_frame; + } + return total_compressed_size_ / duration_seconds / 125.0; } diff --git a/common/vp9_level_stats.h b/common/vp9_level_stats.h index a106851..143dc44 100644 --- a/common/vp9_level_stats.h +++ b/common/vp9_level_stats.h @@ -87,7 +87,8 @@ class Vp9LevelStats { total_uncompressed_bits_(0), frames_refreshed_(0), max_frames_refreshed_(0), - max_column_tiles_(0) {} + max_column_tiles_(0), + estimate_last_frame_duration_(true) {} ~Vp9LevelStats() = default; Vp9LevelStats(Vp9LevelStats&& other) = delete; @@ -135,6 +136,16 @@ class Vp9LevelStats { // as the duration. void set_duration(int64_t time_ns) { duration_ns_ = time_ns; } + bool estimate_last_frame_duration() const { + return estimate_last_frame_duration_; + } + + // If true try to estimate the last frame's duration if the stream's duration + // is not set or the stream's duration equals the last frame's timestamp. + void set_estimate_last_frame_duration(bool flag) { + estimate_last_frame_duration_ = flag; + } + private: int frames; int displayed_frames; @@ -175,6 +186,8 @@ class Vp9LevelStats { int max_frames_refreshed_; int max_column_tiles_; + + bool estimate_last_frame_duration_; }; } // namespace vp9_parser diff --git a/common/vp9_level_stats_tests.cc b/common/vp9_level_stats_tests.cc index 9f916e2..a1abed3 100644 --- a/common/vp9_level_stats_tests.cc +++ b/common/vp9_level_stats_tests.cc @@ -129,12 +129,16 @@ TEST_F(Vp9LevelStatsTests, VideoOnlyFile) { EXPECT_EQ(11, stats_.GetLevel()); EXPECT_EQ(479232, stats_.GetMaxLumaSampleRate()); EXPECT_EQ(36864, stats_.GetMaxLumaPictureSize()); - EXPECT_DOUBLE_EQ(275.512, stats_.GetAverageBitRate()); + EXPECT_DOUBLE_EQ(264.03233333333333, stats_.GetAverageBitRate()); EXPECT_DOUBLE_EQ(147.136, stats_.GetMaxCpbSize()); EXPECT_DOUBLE_EQ(20.873079938441883, stats_.GetCompressionRatio()); EXPECT_EQ(1, stats_.GetMaxColumnTiles()); EXPECT_EQ(11, stats_.GetMinimumAltrefDistance()); EXPECT_EQ(3, stats_.GetMaxReferenceFrames()); + + EXPECT_TRUE(stats_.estimate_last_frame_duration()); + stats_.set_estimate_last_frame_duration(false); + EXPECT_DOUBLE_EQ(275.512, stats_.GetAverageBitRate()); } TEST_F(Vp9LevelStatsTests, Muxed) { @@ -148,12 +152,15 @@ TEST_F(Vp9LevelStatsTests, Muxed) { EXPECT_EQ(30, stats_.GetLevel()); EXPECT_EQ(9838080, stats_.GetMaxLumaSampleRate()); EXPECT_EQ(409920, stats_.GetMaxLumaPictureSize()); - EXPECT_DOUBLE_EQ(468.38413361169108, stats_.GetAverageBitRate()); + EXPECT_DOUBLE_EQ(447.09394572025053, stats_.GetAverageBitRate()); EXPECT_DOUBLE_EQ(118.464, stats_.GetMaxCpbSize()); EXPECT_DOUBLE_EQ(263.10185597889068, stats_.GetCompressionRatio()); EXPECT_EQ(2, stats_.GetMaxColumnTiles()); EXPECT_EQ(9, stats_.GetMinimumAltrefDistance()); EXPECT_EQ(3, stats_.GetMaxReferenceFrames()); + + stats_.set_estimate_last_frame_duration(false); + EXPECT_DOUBLE_EQ(468.38413361169108, stats_.GetAverageBitRate()); } TEST_F(Vp9LevelStatsTests, SetDuration) { diff --git a/webm_info.cc b/webm_info.cc index eb212ef..0b991c6 100644 --- a/webm_info.cc +++ b/webm_info.cc @@ -35,7 +35,7 @@ using libwebm::Indent; using libwebm::kNanosecondsPerSecond; using libwebm::kNanosecondsPerSecondi; -const char VERSION_STRING[] = "1.0.4.2"; +const char VERSION_STRING[] = "1.0.4.3"; struct Options { Options();