#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "media/gpu/test/video_frame_validator.h"
#include <string_view>
#include "base/containers/span.h"
#include "base/cpu.h"
#include "base/files/file.h"
#include "base/functional/bind.h"
#include "base/hash/md5.h"
#include "base/memory/ptr_util.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/string_util.h"
#include "base/system/sys_info.h"
#include "build/build_config.h"
#include "media/base/video_frame.h"
#include "media/gpu/buildflags.h"
#include "media/gpu/macros.h"
#include "media/gpu/test/image_quality_metrics.h"
#include "media/gpu/test/video_frame_helpers.h"
#include "media/gpu/test/video_test_helpers.h"
#include "media/gpu/video_frame_mapper.h"
#include "media/gpu/video_frame_mapper_factory.h"
#include "media/media_buildflags.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/gpu_memory_buffer.h"
#if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_LINUX)
#include <sys/mman.h>
#endif
#if BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION)
#include "media/gpu/chromeos/chromeos_compressed_gpu_memory_buffer_video_frame_utils.h"
#endif
namespace media {
namespace test {
VideoFrameValidator::VideoFrameValidator(
std::unique_ptr<VideoFrameProcessor> corrupt_frame_processor,
CropHelper crop_helper)
: … { … }
VideoFrameValidator::~VideoFrameValidator() { … }
bool VideoFrameValidator::Initialize() { … }
void VideoFrameValidator::CleanUpOnValidatorThread() { … }
void VideoFrameValidator::Destroy() { … }
void VideoFrameValidator::PrintMismatchedFramesInfo() const { … }
size_t VideoFrameValidator::GetMismatchedFramesCount() const { … }
void VideoFrameValidator::ProcessVideoFrame(
scoped_refptr<const VideoFrame> video_frame,
size_t frame_index) { … }
bool VideoFrameValidator::WaitUntilDone() { … }
bool VideoFrameValidator::Passed() const { … }
void VideoFrameValidator::ProcessVideoFrameTask(
const scoped_refptr<const VideoFrame> video_frame,
size_t frame_index) { … }
scoped_refptr<VideoFrame> VideoFrameValidator::CloneAndCropFrame(
scoped_refptr<const VideoFrame> frame) const { … }
gfx::Rect BottomRowCrop(int row_height, const VideoFrame& frame) { … }
struct MD5VideoFrameValidator::MD5MismatchedFrameInfo
: public VideoFrameValidator::MismatchedFrameInfo { … };
std::unique_ptr<MD5VideoFrameValidator> MD5VideoFrameValidator::Create(
const std::vector<std::string>& expected_frame_checksums,
VideoPixelFormat validation_format,
std::unique_ptr<VideoFrameProcessor> corrupt_frame_processor,
CropHelper crop_helper) { … }
MD5VideoFrameValidator::MD5VideoFrameValidator(
const std::vector<std::string>& expected_frame_checksums,
VideoPixelFormat validation_format,
std::unique_ptr<VideoFrameProcessor> corrupt_frame_processor,
CropHelper crop_helper)
: … { … }
MD5VideoFrameValidator::~MD5VideoFrameValidator() = default;
std::unique_ptr<VideoFrameValidator::MismatchedFrameInfo>
MD5VideoFrameValidator::Validate(scoped_refptr<const VideoFrame> frame,
size_t frame_index) { … }
std::string MD5VideoFrameValidator::ComputeMD5FromVideoFrame(
const VideoFrame& video_frame) const { … }
struct RawVideoFrameValidator::RawMismatchedFrameInfo
: public VideoFrameValidator::MismatchedFrameInfo { … };
std::unique_ptr<RawVideoFrameValidator> RawVideoFrameValidator::Create(
const GetModelFrameCB& get_model_frame_cb,
std::unique_ptr<VideoFrameProcessor> corrupt_frame_processor,
uint8_t tolerance,
CropHelper crop_helper) { … }
RawVideoFrameValidator::RawVideoFrameValidator(
const GetModelFrameCB& get_model_frame_cb,
std::unique_ptr<VideoFrameProcessor> corrupt_frame_processor,
uint8_t tolerance,
CropHelper crop_helper)
: … { … }
RawVideoFrameValidator::~RawVideoFrameValidator() = default;
std::unique_ptr<VideoFrameValidator::MismatchedFrameInfo>
RawVideoFrameValidator::Validate(scoped_refptr<const VideoFrame> frame,
size_t frame_index) { … }
struct PSNRVideoFrameValidator::PSNRMismatchedFrameInfo
: public VideoFrameValidator::MismatchedFrameInfo { … };
std::unique_ptr<PSNRVideoFrameValidator> PSNRVideoFrameValidator::Create(
const GetModelFrameCB& get_model_frame_cb,
std::unique_ptr<VideoFrameProcessor> corrupt_frame_processor,
ValidationMode validation_mode,
double tolerance,
CropHelper crop_helper) { … }
PSNRVideoFrameValidator::PSNRVideoFrameValidator(
const GetModelFrameCB& get_model_frame_cb,
std::unique_ptr<VideoFrameProcessor> corrupt_frame_processor,
ValidationMode validation_mode,
double tolerance,
CropHelper crop_helper)
: … { … }
PSNRVideoFrameValidator::~PSNRVideoFrameValidator() = default;
std::unique_ptr<VideoFrameValidator::MismatchedFrameInfo>
PSNRVideoFrameValidator::Validate(scoped_refptr<const VideoFrame> frame,
size_t frame_index) { … }
bool PSNRVideoFrameValidator::Passed() const { … }
struct SSIMVideoFrameValidator::SSIMMismatchedFrameInfo
: public VideoFrameValidator::MismatchedFrameInfo { … };
std::unique_ptr<SSIMVideoFrameValidator> SSIMVideoFrameValidator::Create(
const GetModelFrameCB& get_model_frame_cb,
std::unique_ptr<VideoFrameProcessor> corrupt_frame_processor,
ValidationMode validation_mode,
double tolerance,
CropHelper crop_helper) { … }
SSIMVideoFrameValidator::SSIMVideoFrameValidator(
const GetModelFrameCB& get_model_frame_cb,
std::unique_ptr<VideoFrameProcessor> corrupt_frame_processor,
ValidationMode validation_mode,
double tolerance,
CropHelper crop_helper)
: … { … }
SSIMVideoFrameValidator::~SSIMVideoFrameValidator() = default;
std::unique_ptr<VideoFrameValidator::MismatchedFrameInfo>
SSIMVideoFrameValidator::Validate(scoped_refptr<const VideoFrame> frame,
size_t frame_index) { … }
bool SSIMVideoFrameValidator::Passed() const { … }
struct LogLikelihoodRatioVideoFrameValidator::
LogLikelihoodRatioMismatchedFrameInfo
: public VideoFrameValidator::MismatchedFrameInfo { … };
std::unique_ptr<LogLikelihoodRatioVideoFrameValidator>
LogLikelihoodRatioVideoFrameValidator::Create(
const GetModelFrameCB& get_model_frame_cb,
std::unique_ptr<VideoFrameProcessor> corrupt_frame_processor,
ValidationMode validation_mode,
double tolerance,
CropHelper crop_helper) { … }
LogLikelihoodRatioVideoFrameValidator::LogLikelihoodRatioVideoFrameValidator(
const GetModelFrameCB& get_model_frame_cb,
std::unique_ptr<VideoFrameProcessor> corrupt_frame_processor,
ValidationMode validation_mode,
double tolerance,
CropHelper crop_helper)
: … { … }
LogLikelihoodRatioVideoFrameValidator::
~LogLikelihoodRatioVideoFrameValidator() = default;
std::unique_ptr<VideoFrameValidator::MismatchedFrameInfo>
LogLikelihoodRatioVideoFrameValidator::Validate(
scoped_refptr<const VideoFrame> frame,
size_t frame_index) { … }
}
}