#ifdef UNSAFE_BUFFERS_BUILD
#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 {
constexpr const char* usage_msg = …;
constexpr const char* help_msg = …;
constexpr base::FilePath::CharType kDefaultTestVideoPath[] = …);
media::test::VideoEncoderTestEnvironment* g_env;
constexpr size_t kNumEncodeFramesForSpeedPerformance = …;
constexpr base::TimeDelta kSpeedTestEventTimeout = …;
constexpr base::TimeDelta kQualityTestEventTimeout = …;
constexpr const base::FilePath::CharType* kDefaultOutputFolder = …);
struct PerformanceTimeStats { … };
PerformanceTimeStats::PerformanceTimeStats(const std::vector<double>& times) { … }
struct PerformanceMetrics { … };
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)
: … { … }
BitstreamQualityMetrics::QualityStats
BitstreamQualityMetrics::ComputeQualityStats(
const std::map<size_t, double>& values) { … }
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 { … }
class VideoEncoderTest : public ::testing::Test { … };
}
TEST_F(VideoEncoderTest, MeasureUncappedPerformance) { … }
TEST_F(VideoEncoderTest,
MeasureUncappedPerformance_MultipleConcurrentEncoders) { … }
TEST_F(VideoEncoderTest, DISABLED_MeasureCappedPerformance) { … }
TEST_F(VideoEncoderTest, MeasureProducedBitstreamQuality) { … }
}
}
int main(int argc, char** argv) { … }