From 02fed02c00e506479047dd10e443d612107c2770 Mon Sep 17 00:00:00 2001 From: Sergey Silkin Date: Tue, 25 Sep 2018 13:48:19 +0200 Subject: [PATCH] Assign spatial_idx in FrameStatistics ctor. - Add spatial_idx to FrameStatistics ctor. - Pass FrameStatistics object to AddFrame. Bug: none Change-Id: I9d6de449b45a007438f6fd3317176bf45fb23806 Reviewed-on: https://webrtc-review.googlesource.com/101781 Reviewed-by: Rasmus Brandt Reviewed-by: Karl Wiberg Commit-Queue: Sergey Silkin Cr-Commit-Position: refs/heads/master@{#24856} --- api/test/videocodec_test_stats.cc | 7 +++++-- api/test/videocodec_test_stats.h | 6 ++++-- .../codecs/test/videocodec_test_stats_impl.cc | 13 ++++++------- .../codecs/test/videocodec_test_stats_impl.h | 2 +- .../videocodec_test_stats_impl_unittest.cc | 19 ++++++------------- .../codecs/test/videoprocessor.cc | 4 ++-- 6 files changed, 24 insertions(+), 27 deletions(-) diff --git a/api/test/videocodec_test_stats.cc b/api/test/videocodec_test_stats.cc index 8a935f3d96..7289060cf1 100644 --- a/api/test/videocodec_test_stats.cc +++ b/api/test/videocodec_test_stats.cc @@ -87,8 +87,11 @@ std::string VideoCodecTestStats::VideoStatistics::ToString( } VideoCodecTestStats::FrameStatistics::FrameStatistics(size_t frame_number, - size_t rtp_timestamp) - : frame_number(frame_number), rtp_timestamp(rtp_timestamp) {} + size_t rtp_timestamp, + size_t spatial_idx) + : frame_number(frame_number), + rtp_timestamp(rtp_timestamp), + spatial_idx(spatial_idx) {} VideoCodecTestStats::FrameStatistics::FrameStatistics( const FrameStatistics& rhs) = default; diff --git a/api/test/videocodec_test_stats.h b/api/test/videocodec_test_stats.h index de6d3500d4..b6957b811d 100644 --- a/api/test/videocodec_test_stats.h +++ b/api/test/videocodec_test_stats.h @@ -25,7 +25,9 @@ class VideoCodecTestStats { public: // Statistics for one processed frame. struct FrameStatistics { - FrameStatistics(size_t frame_number, size_t rtp_timestamp); + FrameStatistics(size_t frame_number, + size_t rtp_timestamp, + size_t spatial_idx); FrameStatistics(const FrameStatistics& rhs); std::string ToString() const; @@ -120,7 +122,7 @@ class VideoCodecTestStats { virtual ~VideoCodecTestStats() = default; // Creates a FrameStatistics for the next frame to be processed. - virtual FrameStatistics* AddFrame(size_t timestamp, size_t spatial_idx) = 0; + virtual void AddFrame(const FrameStatistics& frame_stat) = 0; // Returns the FrameStatistics corresponding to |frame_number| or |timestamp|. virtual FrameStatistics* GetFrame(size_t frame_number, diff --git a/modules/video_coding/codecs/test/videocodec_test_stats_impl.cc b/modules/video_coding/codecs/test/videocodec_test_stats_impl.cc index 37c38e8b42..dee31c4f7f 100644 --- a/modules/video_coding/codecs/test/videocodec_test_stats_impl.cc +++ b/modules/video_coding/codecs/test/videocodec_test_stats_impl.cc @@ -31,14 +31,13 @@ const int kMaxBitrateMismatchPercent = 20; VideoCodecTestStatsImpl::VideoCodecTestStatsImpl() = default; VideoCodecTestStatsImpl::~VideoCodecTestStatsImpl() = default; -FrameStatistics* VideoCodecTestStatsImpl::AddFrame(size_t timestamp, - size_t layer_idx) { +void VideoCodecTestStatsImpl::AddFrame(const FrameStatistics& frame_stat) { + const size_t timestamp = frame_stat.rtp_timestamp; + const size_t layer_idx = frame_stat.spatial_idx; RTC_DCHECK(rtp_timestamp_to_frame_num_[layer_idx].find(timestamp) == rtp_timestamp_to_frame_num_[layer_idx].end()); - const size_t frame_num = layer_stats_[layer_idx].size(); - rtp_timestamp_to_frame_num_[layer_idx][timestamp] = frame_num; - layer_stats_[layer_idx].emplace_back(frame_num, timestamp); - return &layer_stats_[layer_idx].back(); + rtp_timestamp_to_frame_num_[layer_idx][timestamp] = frame_stat.frame_number; + layer_stats_[layer_idx].push_back(frame_stat); } FrameStatistics* VideoCodecTestStatsImpl::GetFrame(size_t frame_num, @@ -188,7 +187,7 @@ VideoStatistics VideoCodecTestStatsImpl::SliceAndCalcVideoStatistic( size_t rtp_timestamp_first_frame = 0; size_t rtp_timestamp_prev_frame = 0; - FrameStatistics last_successfully_decoded_frame(0, 0); + FrameStatistics last_successfully_decoded_frame(0, 0, 0); const size_t target_bitrate_kbps = CalcLayerTargetBitrateKbps(first_frame_num, last_frame_num, spatial_idx, diff --git a/modules/video_coding/codecs/test/videocodec_test_stats_impl.h b/modules/video_coding/codecs/test/videocodec_test_stats_impl.h index a2b2a0a79b..9cc5e33e08 100644 --- a/modules/video_coding/codecs/test/videocodec_test_stats_impl.h +++ b/modules/video_coding/codecs/test/videocodec_test_stats_impl.h @@ -28,7 +28,7 @@ class VideoCodecTestStatsImpl : public VideoCodecTestStats { ~VideoCodecTestStatsImpl() override; // Creates a FrameStatistics for the next frame to be processed. - FrameStatistics* AddFrame(size_t timestamp, size_t spatial_idx) override; + void AddFrame(const FrameStatistics& frame_stat) override; // Returns the FrameStatistics corresponding to |frame_number| or |timestamp|. FrameStatistics* GetFrame(size_t frame_number, size_t spatial_idx) override; diff --git a/modules/video_coding/codecs/test/videocodec_test_stats_impl_unittest.cc b/modules/video_coding/codecs/test/videocodec_test_stats_impl_unittest.cc index 145b2514ce..077a858aef 100644 --- a/modules/video_coding/codecs/test/videocodec_test_stats_impl_unittest.cc +++ b/modules/video_coding/codecs/test/videocodec_test_stats_impl_unittest.cc @@ -19,27 +19,20 @@ namespace { const size_t kTimestamp = 12345; } // namespace -TEST(StatsTest, AddFrame) { +TEST(StatsTest, AddAndGetFrame) { VideoCodecTestStatsImpl stats; - FrameStatistics* frame_stat = stats.AddFrame(kTimestamp, 0); - EXPECT_EQ(0ull, frame_stat->frame_number); - EXPECT_EQ(kTimestamp, frame_stat->rtp_timestamp); - EXPECT_EQ(1u, stats.Size(0)); -} - -TEST(StatsTest, GetFrame) { - VideoCodecTestStatsImpl stats; - stats.AddFrame(kTimestamp, 0); + stats.AddFrame(FrameStatistics(0, kTimestamp, 0)); FrameStatistics* frame_stat = stats.GetFrame(0u, 0); EXPECT_EQ(0u, frame_stat->frame_number); EXPECT_EQ(kTimestamp, frame_stat->rtp_timestamp); } -TEST(StatsTest, AddFrames) { +TEST(StatsTest, AddAndGetFrames) { VideoCodecTestStatsImpl stats; const size_t kNumFrames = 1000; for (size_t i = 0; i < kNumFrames; ++i) { - FrameStatistics* frame_stat = stats.AddFrame(kTimestamp + i, 0); + stats.AddFrame(FrameStatistics(i, kTimestamp + i, 0)); + FrameStatistics* frame_stat = stats.GetFrame(i, 0); EXPECT_EQ(i, frame_stat->frame_number); EXPECT_EQ(kTimestamp + i, frame_stat->rtp_timestamp); } @@ -54,7 +47,7 @@ TEST(StatsTest, AddFrames) { TEST(StatsTest, AddFrameLayering) { VideoCodecTestStatsImpl stats; for (size_t i = 0; i < 3; ++i) { - stats.AddFrame(kTimestamp + i, i); + stats.AddFrame(FrameStatistics(0, kTimestamp + i, i)); FrameStatistics* frame_stat = stats.GetFrame(0u, i); EXPECT_EQ(0u, frame_stat->frame_number); EXPECT_EQ(kTimestamp, frame_stat->rtp_timestamp - i); diff --git a/modules/video_coding/codecs/test/videoprocessor.cc b/modules/video_coding/codecs/test/videoprocessor.cc index 75605aed8f..5e980cdcf1 100644 --- a/modules/video_coding/codecs/test/videoprocessor.cc +++ b/modules/video_coding/codecs/test/videoprocessor.cc @@ -275,7 +275,8 @@ void VideoProcessor::ProcessFrame() { // Create frame statistics object for all simulcast/spatial layers. for (size_t i = 0; i < num_simulcast_or_spatial_layers_; ++i) { - stats_->AddFrame(timestamp, i); + FrameStatistics frame_stat(frame_number, timestamp, i); + stats_->AddFrame(frame_stat); } // For the highest measurement accuracy of the encode time, the start/stop @@ -377,7 +378,6 @@ void VideoProcessor::FrameEncoded( frame_stat->length_bytes = encoded_image._length; frame_stat->frame_type = encoded_image._frameType; frame_stat->temporal_idx = temporal_idx; - frame_stat->spatial_idx = spatial_idx; frame_stat->max_nalu_size_bytes = GetMaxNaluSizeBytes(encoded_image, config_); frame_stat->qp = encoded_image.qp_;