Change VideoCodecTestStats API.

- Add GetFrameStatistics API:
  This is useful for downstream test users that want to read frame-level stats.
- Remove other APIs that are not used by downstream tests:
    * AddFrame
    * GetFrame
    * GetFrameWithTimestamp
    * SliceAndCalcAggregatedVideoStatistic
    * PrintFrameStatistics
    * Size
    * Clear
  The implementations, which are used by the fixture implementation, are kept.

Bug: webrtc:10349
Change-Id: Id2f6fa5a36b8341a5ccb365725f71ebe0c0f1570
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/128779
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Sergey Silkin <ssilkin@webrtc.org>
Commit-Queue: Rasmus Brandt <brandtr@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27306}
This commit is contained in:
Rasmus Brandt
2019-03-26 16:56:14 +01:00
committed by Commit Bot
parent c8ba8b2409
commit 7d72d0fb39
8 changed files with 87 additions and 54 deletions

View File

@ -12,6 +12,7 @@
#include <algorithm>
#include <cmath>
#include <iterator>
#include <limits>
#include <numeric>
@ -56,6 +57,22 @@ FrameStatistics* VideoCodecTestStatsImpl::GetFrameWithTimestamp(
return GetFrame(rtp_timestamp_to_frame_num_[layer_idx][timestamp], layer_idx);
}
std::vector<FrameStatistics> VideoCodecTestStatsImpl::GetFrameStatistics() {
size_t capacity = 0;
for (const auto& layer_stat : layer_stats_) {
capacity += layer_stat.second.size();
}
std::vector<FrameStatistics> frame_statistics;
frame_statistics.reserve(capacity);
for (const auto& layer_stat : layer_stats_) {
std::copy(layer_stat.second.cbegin(), layer_stat.second.cend(),
std::back_inserter(frame_statistics));
}
return frame_statistics;
}
std::vector<VideoStatistics>
VideoCodecTestStatsImpl::SliceAndCalcLayerVideoStatistic(
size_t first_frame_num,

View File

@ -27,26 +27,26 @@ class VideoCodecTestStatsImpl : public VideoCodecTestStats {
~VideoCodecTestStatsImpl() override;
// Creates a FrameStatistics for the next frame to be processed.
void AddFrame(const FrameStatistics& frame_stat) override;
void AddFrame(const FrameStatistics& frame_stat);
// Returns the FrameStatistics corresponding to |frame_number| or |timestamp|.
FrameStatistics* GetFrame(size_t frame_number, size_t spatial_idx) override;
FrameStatistics* GetFrameWithTimestamp(size_t timestamp,
size_t spatial_idx) override;
FrameStatistics* GetFrame(size_t frame_number, size_t spatial_idx);
FrameStatistics* GetFrameWithTimestamp(size_t timestamp, size_t spatial_idx);
// Implements VideoCodecTestStats.
std::vector<FrameStatistics> GetFrameStatistics() override;
std::vector<VideoStatistics> SliceAndCalcLayerVideoStatistic(
size_t first_frame_num,
size_t last_frame_num) override;
VideoStatistics SliceAndCalcAggregatedVideoStatistic(
size_t first_frame_num,
size_t last_frame_num) override;
VideoStatistics SliceAndCalcAggregatedVideoStatistic(size_t first_frame_num,
size_t last_frame_num);
void PrintFrameStatistics() override;
void PrintFrameStatistics();
size_t Size(size_t spatial_idx) override;
size_t Size(size_t spatial_idx);
void Clear() override;
void Clear();
private:
VideoCodecTestStats::FrameStatistics AggregateFrameStatistic(

View File

@ -10,13 +10,24 @@
#include "modules/video_coding/codecs/test/videocodec_test_stats_impl.h"
#include <vector>
#include "test/gmock.h"
#include "test/gtest.h"
namespace webrtc {
namespace test {
using FrameStatistics = VideoCodecTestStatsImpl::FrameStatistics;
namespace {
const size_t kTimestamp = 12345;
using ::testing::AllOf;
using ::testing::Contains;
using ::testing::Field;
} // namespace
TEST(StatsTest, AddAndGetFrame) {
@ -55,5 +66,25 @@ TEST(StatsTest, AddFrameLayering) {
}
}
TEST(StatsTest, GetFrameStatistics) {
VideoCodecTestStatsImpl stats;
stats.AddFrame(FrameStatistics(0, kTimestamp, 0));
stats.AddFrame(FrameStatistics(0, kTimestamp, 1));
stats.AddFrame(FrameStatistics(1, kTimestamp + 3000, 0));
stats.AddFrame(FrameStatistics(1, kTimestamp + 3000, 1));
const std::vector<FrameStatistics> frame_stats = stats.GetFrameStatistics();
auto field_matcher = [](size_t frame_number, size_t spatial_idx) {
return AllOf(Field(&FrameStatistics::frame_number, frame_number),
Field(&FrameStatistics::spatial_idx, spatial_idx));
};
EXPECT_THAT(frame_stats, Contains(field_matcher(0, 0)));
EXPECT_THAT(frame_stats, Contains(field_matcher(0, 1)));
EXPECT_THAT(frame_stats, Contains(field_matcher(1, 0)));
EXPECT_THAT(frame_stats, Contains(field_matcher(1, 1)));
}
} // namespace test
} // namespace webrtc

View File

@ -164,7 +164,7 @@ VideoProcessor::VideoProcessor(webrtc::VideoEncoder* encoder,
VideoDecoderList* decoders,
FrameReader* input_frame_reader,
const VideoCodecTestFixture::Config& config,
VideoCodecTestStats* stats,
VideoCodecTestStatsImpl* stats,
IvfFileWriterMap* encoded_frame_writers,
FrameWriterList* decoded_frame_writers)
: config_(config),

View File

@ -23,7 +23,6 @@
#include "api/task_queue/queued_task.h"
#include "api/task_queue/task_queue_base.h"
#include "api/test/videocodec_test_fixture.h"
#include "api/test/videocodec_test_stats.h"
#include "api/video/encoded_image.h"
#include "api/video/video_bitrate_allocation.h"
#include "api/video/video_bitrate_allocator.h"
@ -32,6 +31,7 @@
#include "api/video_codecs/video_encoder.h"
#include "common_types.h" // NOLINT(build/include)
#include "modules/include/module_common_types.h"
#include "modules/video_coding/codecs/test/videocodec_test_stats_impl.h"
#include "modules/video_coding/include/video_codec_interface.h"
#include "modules/video_coding/utility/ivf_file_writer.h"
#include "rtc_base/buffer.h"
@ -64,7 +64,7 @@ class VideoProcessor {
VideoDecoderList* decoders,
FrameReader* input_frame_reader,
const VideoCodecTestFixture::Config& config,
VideoCodecTestStats* stats,
VideoCodecTestStatsImpl* stats,
IvfFileWriterMap* encoded_frame_writers,
FrameWriterList* decoded_frame_writers);
~VideoProcessor();
@ -187,7 +187,7 @@ class VideoProcessor {
// Test input/output.
VideoCodecTestFixture::Config config_ RTC_GUARDED_BY(sequence_checker_);
const size_t num_simulcast_or_spatial_layers_;
VideoCodecTestStats* const stats_;
VideoCodecTestStatsImpl* const stats_;
// Codecs.
webrtc::VideoEncoder* const encoder_;