Commit cd4c2f1b authored by Hirokazu Honda's avatar Hirokazu Honda Committed by Commit Bot

media/gpu/test/VFValidator: Get model frame by callback

VideoFrameValidator compares a video frame passed on Process()
with the model frame. The model frames are set at
Initialize() and VideoFrameValidator keeps them during the test.

The memory usage of the model frame can be large if we use
VideoFrameValidator for encoder test. We would rather give
VideoFrameValidator a callback to get a model frame, so that
we can keep model frames needed at that time in the test.

Bug: 1044452
Test: image_processor_test on kevin
Change-Id: Id3a4a76c8d149bb5e4b349ab67a087bc9bdaf45d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2024769
Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: default avatarDavid Staessens <dstaessens@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744628}
parent 122f46e7
......@@ -82,7 +82,7 @@ class ImageProcessorParamTest
std::tuple<base::FilePath, base::FilePath>> {
public:
void SetUp() override {}
void TearDown() override {}
void TearDown() override { model_frames_.clear(); }
std::unique_ptr<test::ImageProcessorClient> CreateImageProcessorClient(
const test::Image& input_image,
......@@ -135,12 +135,15 @@ class ImageProcessorParamTest
scoped_refptr<const VideoFrame> model_frame =
CreateVideoFrameFromImage(*output_image);
LOG_ASSERT(model_frame) << "Failed to create from image";
model_frames_ = {model_frame};
// Scaling is not deterministic process. There are various algorithms to
// scale images. We set a weaker tolerance value, 32, to avoid false
// negative.
constexpr uint32_t kImageProcessorTestTorelance = 32;
auto vf_validator = test::VideoFrameValidator::Create(
{model_frame}, kImageProcessorTestTorelance);
base::BindRepeating(&ImageProcessorParamTest::GetModelFrame,
base::Unretained(this)),
kImageProcessorTestTorelance);
frame_processors.push_back(std::move(vf_validator));
}
}
......@@ -161,6 +164,18 @@ class ImageProcessorParamTest
input_config, output_config, kNumBuffers, std::move(frame_processors));
return ip_client;
}
private:
scoped_refptr<const VideoFrame> GetModelFrame(size_t frame_index) const {
if (frame_index >= model_frames_.size()) {
LOG(ERROR) << "Failed to get model frame with index=" << frame_index;
ADD_FAILURE();
return nullptr;
}
return model_frames_[frame_index];
}
std::vector<scoped_refptr<const VideoFrame>> model_frames_;
};
TEST_P(ImageProcessorParamTest, ConvertOneTime_MemToMem) {
......
......@@ -57,11 +57,12 @@ std::unique_ptr<VideoFrameValidator> VideoFrameValidator::Create(
}
std::unique_ptr<VideoFrameValidator> VideoFrameValidator::Create(
const std::vector<scoped_refptr<const VideoFrame>> model_frames,
GetModelFrameCB get_model_frame_cb,
const uint8_t tolerance,
std::unique_ptr<VideoFrameProcessor> corrupt_frame_processor) {
auto video_frame_validator = base::WrapUnique(new VideoFrameValidator(
std::move(model_frames), tolerance, std::move(corrupt_frame_processor)));
auto video_frame_validator = base::WrapUnique(
new VideoFrameValidator(std::move(get_model_frame_cb), tolerance,
std::move(corrupt_frame_processor)));
if (!video_frame_validator->Initialize()) {
LOG(ERROR) << "Failed to initialize VideoFrameValidator.";
return nullptr;
......@@ -86,11 +87,11 @@ VideoFrameValidator::VideoFrameValidator(
}
VideoFrameValidator::VideoFrameValidator(
const std::vector<scoped_refptr<const VideoFrame>> model_frames,
GetModelFrameCB get_model_frame_cb,
const uint8_t tolerance,
std::unique_ptr<VideoFrameProcessor> corrupt_frame_processor)
: validate_mode_(ValidateMode::RAW),
model_frames_(std::move(model_frames)),
get_model_frame_cb_(get_model_frame_cb),
tolerance_(tolerance),
corrupt_frame_processor_(std::move(corrupt_frame_processor)),
num_frames_validating_(0),
......@@ -139,15 +140,21 @@ void VideoFrameValidator::ProcessVideoFrame(
return;
}
scoped_refptr<const VideoFrame> model_frame;
if (validate_mode_ != ValidateMode::MD5) {
model_frame = get_model_frame_cb_.Run(frame_index);
ASSERT_TRUE(model_frame);
}
base::AutoLock auto_lock(frame_validator_lock_);
num_frames_validating_++;
// Unretained is safe here, as we should not destroy the validator while there
// are still frames being validated.
frame_validator_thread_.task_runner()->PostTask(
FROM_HERE,
base::BindOnce(&VideoFrameValidator::ProcessVideoFrameTask,
base::Unretained(this), video_frame, frame_index));
FROM_HERE, base::BindOnce(&VideoFrameValidator::ProcessVideoFrameTask,
base::Unretained(this), video_frame,
model_frame, frame_index));
}
bool VideoFrameValidator::WaitUntilDone() {
......@@ -168,6 +175,7 @@ bool VideoFrameValidator::WaitUntilDone() {
void VideoFrameValidator::ProcessVideoFrameTask(
const scoped_refptr<const VideoFrame> video_frame,
const scoped_refptr<const VideoFrame> model_frame,
size_t frame_index) {
DCHECK_CALLED_ON_VALID_SEQUENCE(validator_thread_sequence_checker_);
......@@ -208,7 +216,9 @@ void VideoFrameValidator::ProcessVideoFrameTask(
break;
}
case ValidateMode::RAW:
mismatched_info = ValidateRaw(*validated_frame, frame_index);
ASSERT_TRUE(model_frame);
mismatched_info =
ValidateRaw(*validated_frame, *model_frame, frame_index);
break;
}
......@@ -254,15 +264,12 @@ VideoFrameValidator::ValidateMD5(const VideoFrame& validated_frame,
base::Optional<VideoFrameValidator::MismatchedFrameInfo>
VideoFrameValidator::ValidateRaw(const VideoFrame& validated_frame,
const VideoFrame& model_frame,
size_t frame_index) {
if (model_frames_.size() > 0) {
LOG_IF(FATAL, frame_index >= model_frames_.size())
<< "Frame number is over than the number of given frames.";
size_t diff_cnt = CompareFramesWithErrorDiff(
validated_frame, *model_frames_[frame_index], tolerance_);
if (diff_cnt > 0)
return MismatchedFrameInfo{frame_index, diff_cnt};
}
size_t diff_cnt =
CompareFramesWithErrorDiff(validated_frame, model_frame, tolerance_);
if (diff_cnt > 0)
return MismatchedFrameInfo{frame_index, diff_cnt};
return base::nullopt;
}
} // namespace test
......
......@@ -10,6 +10,7 @@
#include <utility>
#include <vector>
#include "base/callback.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_refptr.h"
......@@ -38,6 +39,9 @@ namespace test {
// performance measurements.
class VideoFrameValidator : public VideoFrameProcessor {
public:
// Get the model frame from |frame_index|.
using GetModelFrameCB =
base::RepeatingCallback<scoped_refptr<const VideoFrame>(size_t)>;
static constexpr uint8_t kDefaultTolerance = 4;
// TODO(hiroh): Support a validation by PSNR and SSIM.
enum class ValidateMode {
......@@ -79,8 +83,11 @@ class VideoFrameValidator : public VideoFrameProcessor {
const VideoPixelFormat validation_format = PIXEL_FORMAT_I420,
std::unique_ptr<VideoFrameProcessor> corrupt_frame_processor = nullptr);
// Create an instance of the video frame validator. The VideoFrameValidator
// compares a given VideoFrame on ProcessVideoFrame() with the model frame got
// by |get_model_frame_cb|.
static std::unique_ptr<VideoFrameValidator> Create(
const std::vector<scoped_refptr<const VideoFrame>> model_frames,
GetModelFrameCB get_model_frame_cb,
const uint8_t tolerance = kDefaultTolerance,
std::unique_ptr<VideoFrameProcessor> corrupt_frame_processor = nullptr);
......@@ -110,7 +117,7 @@ class VideoFrameValidator : public VideoFrameProcessor {
std::unique_ptr<VideoFrameProcessor> corrupt_frame_processor);
VideoFrameValidator(
const std::vector<scoped_refptr<const VideoFrame>> model_frames,
GetModelFrameCB get_model_frame_cb,
const uint8_t tolerance,
std::unique_ptr<VideoFrameProcessor> corrupt_frame_processor);
......@@ -121,6 +128,7 @@ class VideoFrameValidator : public VideoFrameProcessor {
// Validate the |video_frame|'s content on the |frame_validator_thread_|.
void ProcessVideoFrameTask(const scoped_refptr<const VideoFrame> video_frame,
const scoped_refptr<const VideoFrame> model_frame,
size_t frame_index);
// Returns md5 values of video frame represented by |video_frame|.
......@@ -131,6 +139,7 @@ class VideoFrameValidator : public VideoFrameProcessor {
size_t frame_index);
base::Optional<MismatchedFrameInfo> ValidateRaw(
const VideoFrame& validated_frame,
const VideoFrame& model_frame,
size_t frame_index);
const ValidateMode validate_mode_;
......@@ -143,7 +152,7 @@ class VideoFrameValidator : public VideoFrameProcessor {
// Values used only if |validate_mode_| is RAW.
// The list of expected frames
const std::vector<scoped_refptr<const VideoFrame>> model_frames_;
const GetModelFrameCB get_model_frame_cb_;
const uint8_t tolerance_ = 0;
std::unique_ptr<VideoFrameMapper> video_frame_mapper_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment