chromium/media/gpu/test/video_encode_accelerator_perf_tests.cc

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <optional>
#include <vector>

#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/files/file_util.h"
#include "base/json/json_writer.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/time/time.h"
#include "media/base/bitstream_buffer.h"
#include "media/base/media_switches.h"
#include "media/base/media_util.h"
#include "media/base/test_data_util.h"
#include "media/base/video_decoder_config.h"
#include "media/gpu/test/raw_video.h"
#include "media/gpu/test/video_encoder/bitstream_file_writer.h"
#include "media/gpu/test/video_encoder/bitstream_validator.h"
#include "media/gpu/test/video_encoder/decoder_buffer_validator.h"
#include "media/gpu/test/video_encoder/video_encoder.h"
#include "media/gpu/test/video_encoder/video_encoder_client.h"
#include "media/gpu/test/video_encoder/video_encoder_test_environment.h"
#include "media/gpu/test/video_frame_validator.h"
#include "media/gpu/test/video_test_helpers.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace media {
namespace test {

namespace {

// Video encoder perf tests usage message. Make sure to also update the
// documentation under docs/media/gpu/video_encoder_perf_test_usage.md when
// making changes here.
// TODO(b/211783271): Add video_encoder_perf_test_usage.md
constexpr const char* usage_msg =;

// Video encoder performance tests help message.
constexpr const char* help_msg =;

// Default video to be used if no test video was specified.
constexpr base::FilePath::CharType kDefaultTestVideoPath[] =);

media::test::VideoEncoderTestEnvironment* g_env;

constexpr size_t kNumEncodeFramesForSpeedPerformance =;

// We use a longer event timeout because it takes much longer to encode,
// especially in 2160p, |kNumEncodeFramesForSpeedPerformance| frames in speed
// tests and decode and encode the entire videos in quality tests.
constexpr base::TimeDelta kSpeedTestEventTimeout =;
constexpr base::TimeDelta kQualityTestEventTimeout =;

// Default output folder used to store performance metrics.
constexpr const base::FilePath::CharType* kDefaultOutputFolder =);

// Struct storing various time-related statistics.
struct PerformanceTimeStats {};

PerformanceTimeStats::PerformanceTimeStats(const std::vector<double>& times) {}

// TODO(dstaessens): Investigate using more appropriate metrics for encoding.
struct PerformanceMetrics {};

// The performance evaluator can be plugged into the video encoder to collect
// various performance metrics.
class PerformanceEvaluator : public BitstreamProcessor {};

void PerformanceEvaluator::ProcessBitstream(
    scoped_refptr<BitstreamRef> bitstream,
    size_t frame_index) {}

void PerformanceEvaluator::StartMeasuring() {}

void PerformanceEvaluator::StopMeasuring() {}

void PerformanceMetrics::WriteToConsole() const {}

void PerformanceMetrics::WriteToFile() const {}

struct BitstreamQualityMetrics {};

BitstreamQualityMetrics::BitstreamQualityMetrics(
    const PSNRVideoFrameValidator* const psnr_validator,
    const SSIMVideoFrameValidator* const ssim_validator,
    const PSNRVideoFrameValidator* const bottom_row_psnr_validator,
    const LogLikelihoodRatioVideoFrameValidator* const log_likelihood_validator,
    const DecoderBufferValidator* const decoder_buffer_validator,
    const std::optional<size_t>& spatial_idx,
    const std::optional<size_t>& temporal_idx,
    size_t num_spatial_layers,
    SVCInterLayerPredMode inter_layer_pred_mode)
    :{}

// static
BitstreamQualityMetrics::QualityStats
BitstreamQualityMetrics::ComputeQualityStats(
    const std::map<size_t, double>& values) {}

// static
BitstreamQualityMetrics::QualityStats
BitstreamQualityMetrics::ComputeQualityStats(const std::vector<int>& values) {}

void BitstreamQualityMetrics::Output(uint32_t target_bitrate,
                                     uint32_t actual_bitrate) {}

void BitstreamQualityMetrics::WriteToConsole(
    const std::string& svc_text,
    const BitstreamQualityMetrics::QualityStats& psnr_stats,
    const BitstreamQualityMetrics::QualityStats& ssim_stats,
    const BitstreamQualityMetrics::QualityStats& bottom_row_psnr_stats,
    const BitstreamQualityMetrics::QualityStats& log_likelihood_stats,
    const BitstreamQualityMetrics::QualityStats& qp_stats,
    uint32_t target_bitrate,
    uint32_t actual_bitrate) const {}

void BitstreamQualityMetrics::WriteToFile(
    const std::string& svc_text,
    const BitstreamQualityMetrics::QualityStats& psnr_stats,
    const BitstreamQualityMetrics::QualityStats& ssim_stats,
    const BitstreamQualityMetrics::QualityStats& bottom_row_psnr_stats,
    const BitstreamQualityMetrics::QualityStats& log_likelihood_stats,
    const BitstreamQualityMetrics::QualityStats& qp_stats,
    uint32_t target_bitrate,
    uint32_t actual_bitrate) const {}

// Video encode test class. Performs setup and teardown for each single test.
// It measures the performance in encoding NV12 GpuMemoryBuffer based
// VideoFrame.
class VideoEncoderTest : public ::testing::Test {};

}  // namespace

// Encode |kNumEncodeFramesForSpeedPerformance| frames while measuring
// uncapped performance. This test will encode a video as fast as
// possible, and gives an idea about the maximum output of the
// encoder.
TEST_F(VideoEncoderTest, MeasureUncappedPerformance) {}

// TODO(b/211783279) The |performance_evaluator_| only keeps track of the last
// created encoder. We should instead keep track of multiple evaluators, and
// then decide how to aggregate/report those metrics.
TEST_F(VideoEncoderTest,
       MeasureUncappedPerformance_MultipleConcurrentEncoders) {}

// Encode |kNumEncodeFramesForSpeedPerformance| frames while measuring
// capped performance. This test will encode a video at a fixed ratio,
// 30fps. This test can be used to measure the cpu metrics during
// encoding.
TEST_F(VideoEncoderTest, DISABLED_MeasureCappedPerformance) {}

TEST_F(VideoEncoderTest, MeasureProducedBitstreamQuality) {}
}  // namespace test
}  // namespace media

int main(int argc, char** argv) {}