Skip to content

Commit

Permalink
Reland "media/gpu/VEA unittest: Verify encoded content on Chrome OS b…
Browse files Browse the repository at this point in the history
…y default"

VEA unittest verifies VEA's encoding content by
1. decode content by FFmepgVideoDecoder
2. compare it with the original VideoFrame and computes SSIM
3. check the SSIM less than or equal to the predetermined threshold, 10.0.

VEA unittest turns on this verifitcation by --verify_all_output and one of test
case parameters. This verification was always disabled on Chrome OS by setting
--verify_all_output false because of https://crbug.com/694131. I think the bug
is already fixed. We can re-enable the verification on Chrome OS now by default.

[email protected]

Bug: 923762
Test: VEA unittest on eve
Change-Id: I597346a9ecd114ccc37ebde1ab284b97103a6e4f
Reviewed-on: https://chromium-review.googlesource.com/c/1429307
Reviewed-by: Hirokazu Honda <[email protected]>
Commit-Queue: Hirokazu Honda <[email protected]>
Cr-Commit-Position: refs/heads/master@{#625101}
  • Loading branch information
rosetta-jpn authored and Commit Bot committed Jan 23, 2019
1 parent 95a3ced commit 233c771
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions media/gpu/video_encode_accelerator_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ bool g_run_at_fps = false;

bool g_needs_encode_latency = false;

bool g_verify_all_output = false;
bool g_verify_output = true;

bool g_fake_encoder = false;

Expand Down Expand Up @@ -498,14 +498,14 @@ class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment {
const base::FilePath& frame_stats_path,
bool run_at_fps,
bool needs_encode_latency,
bool verify_all_output)
bool verify_output)
: rendering_thread_("GLRenderingVEAClientThread"),
test_stream_data_(std::move(data)),
log_path_(log_path),
frame_stats_path_(frame_stats_path),
run_at_fps_(run_at_fps),
needs_encode_latency_(needs_encode_latency),
verify_all_output_(verify_all_output) {}
verify_output_(verify_output) {}

virtual void SetUp() {
if (!log_path_.empty()) {
Expand Down Expand Up @@ -575,8 +575,8 @@ class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment {
bool needs_encode_latency() const { return needs_encode_latency_; }

// Verify the encoder output of all testcases. This is set by the command line
// switch "--verify_all_output".
bool verify_all_output() const { return verify_all_output_; }
// switch "--verify_output".
bool verify_output() const { return verify_output_; }

const base::FilePath& frame_stats_path() const { return frame_stats_path_; }

Expand All @@ -590,7 +590,7 @@ class VideoEncodeAcceleratorTestEnvironment : public ::testing::Environment {
std::unique_ptr<base::File> log_file_;
bool run_at_fps_;
bool needs_encode_latency_;
bool verify_all_output_;
bool verify_output_;

#if defined(USE_OZONE)
std::unique_ptr<ui::OzoneGpuTestHelper> gpu_helper;
Expand Down Expand Up @@ -891,7 +891,7 @@ void VideoFrameQualityValidator::Initialize(const gfx::Size& coded_size,
DCHECK(thread_checker_.CalledOnValidThread());

gfx::Size natural_size(visible_size.size());
// The default output format of ffmpeg video decoder is YV12.
// The default output format of ffmpeg video decoder is I420.
VideoDecoderConfig config;
if (IsVP8(profile_))
config.Initialize(kCodecVP8, VP8PROFILE_ANY, pixel_format_,
Expand Down Expand Up @@ -1185,10 +1185,14 @@ void VideoFrameQualityValidator::VerifyOutputFrame(
// SSIM/PSNR metrics for thresholds instead of abs(difference) / size which
// correspond less to perceptive distortion.
if (verify_quality_) {
int planes[] = {VideoFrame::kYPlane, VideoFrame::kUPlane,
VideoFrame::kVPlane};
// TODO(crbug.com/923762): Support DMABUF and non-I420 format.
ASSERT_TRUE(original_frame->IsMappable());
ASSERT_TRUE(output_frame->IsMappable());
ASSERT_EQ(output_frame->format(), original_frame->format());

const size_t num_planes = VideoFrame::NumPlanes(original_frame->format());
double difference = 0;
for (int plane : planes) {
for (size_t plane = 0; plane < num_planes; ++plane) {
uint8_t* original_plane = original_frame->data(plane);
uint8_t* output_plane = output_frame->data(plane);

Expand All @@ -1208,7 +1212,7 @@ void VideoFrameQualityValidator::VerifyOutputFrame(

// Divide the difference by the size of frame.
difference /= VideoFrame::AllocationSize(pixel_format_, visible_size);
EXPECT_TRUE(difference <= kDecodeSimilarityThreshold)
EXPECT_LE(difference, kDecodeSimilarityThreshold)
<< "difference = " << difference << " > decode similarity threshold";
}
}
Expand Down Expand Up @@ -2406,10 +2410,11 @@ TEST_P(VideoEncodeAcceleratorTest, TestSimpleEncode) {
const bool test_perf = std::get<4>(GetParam());
const bool mid_stream_bitrate_switch = std::get<5>(GetParam());
const bool mid_stream_framerate_switch = std::get<6>(GetParam());
// TODO(crbug.com/923762): Support DMABUF and non-I420 format.
const bool verify_output =
std::get<7>(GetParam()) || g_env->verify_all_output();
std::get<7>(GetParam()) && g_env->verify_output() && !g_native_input &&
g_env->test_streams_[0]->pixel_format == PIXEL_FORMAT_I420;
const bool verify_output_timestamp = std::get<8>(GetParam());

std::vector<
std::unique_ptr<media::test::ClientStateNotification<ClientState>>>
notes;
Expand Down Expand Up @@ -2518,13 +2523,11 @@ TEST_P(VideoEncodeAcceleratorSimpleTest, TestSimpleEncode) {
}

#if defined(OS_CHROMEOS) || defined(OS_LINUX)
// TODO(kcwu): add back test of verify_output=true after
// https://crbug.com/694131 fixed.
INSTANTIATE_TEST_CASE_P(
SimpleEncode,
VideoEncodeAcceleratorTest,
::testing::Values(
std::make_tuple(1, true, 0, false, false, false, false, false, false)));
std::make_tuple(1, true, 0, false, false, false, false, true, false)));

INSTANTIATE_TEST_CASE_P(
EncoderPerf,
Expand All @@ -2541,20 +2544,20 @@ INSTANTIATE_TEST_CASE_P(ForceKeyframes,
false,
false,
false,
false,
true,
false)));

INSTANTIATE_TEST_CASE_P(
ForceBitrate,
VideoEncodeAcceleratorTest,
::testing::Values(
std::make_tuple(1, false, 0, true, false, false, false, false, false)));
std::make_tuple(1, false, 0, true, false, false, false, true, false)));

INSTANTIATE_TEST_CASE_P(
MidStreamParamSwitchBitrate,
VideoEncodeAcceleratorTest,
::testing::Values(
std::make_tuple(1, false, 0, true, false, true, false, false, false)));
std::make_tuple(1, false, 0, true, false, true, false, true, false)));

// TODO(kcwu): add back bitrate test after https://crbug.com/693336 fixed.
INSTANTIATE_TEST_CASE_P(
Expand All @@ -2567,14 +2570,14 @@ INSTANTIATE_TEST_CASE_P(
MultipleEncoders,
VideoEncodeAcceleratorTest,
::testing::Values(
std::make_tuple(3, false, 0, false, false, false, false, false, false),
std::make_tuple(3, false, 0, true, false, true, false, false, false)));
std::make_tuple(3, false, 0, false, false, false, false, true, false),
std::make_tuple(3, false, 0, true, false, true, false, true, false)));

INSTANTIATE_TEST_CASE_P(
VerifyTimestamp,
VideoEncodeAcceleratorTest,
::testing::Values(
std::make_tuple(1, false, 0, false, false, false, false, false, true)));
std::make_tuple(1, false, 0, false, false, false, false, true, true)));

INSTANTIATE_TEST_CASE_P(NoInputTest,
VideoEncodeAcceleratorSimpleTest,
Expand Down Expand Up @@ -2654,8 +2657,7 @@ class VEATestSuite : public base::TestSuite {
new media::VideoEncodeAcceleratorTestEnvironment(
std::move(media::g_test_stream_data), media::g_log_path,
media::g_frame_stats_path, media::g_run_at_fps,
media::g_needs_encode_latency,
media::g_verify_all_output)));
media::g_needs_encode_latency, media::g_verify_output)));

#if BUILDFLAG(USE_VAAPI)
media::VaapiWrapper::PreSandboxInitialization();
Expand Down Expand Up @@ -2720,8 +2722,10 @@ int main(int argc, char** argv) {
media::g_run_at_fps = true;
continue;
}
if (it->first == "verify_all_output") {
media::g_verify_all_output = true;
if (it->first == "verify_output") {
std::string input(it->second.begin(), it->second.end());
if (input == "false")
media::g_verify_output = false;
continue;
}

Expand Down

0 comments on commit 233c771

Please sign in to comment.