Skip to content

Commit

Permalink
media/gpu/test: Add extra command line options to video decoder tests.
Browse files Browse the repository at this point in the history
This CL adds extra command line options to the video_decode_accelerator_tests to
control the format and amount of video frames saved to disk when --output_frames
is specified:
--output_format: allows switching the file format between png and yuv.
--output_limit: allows putting a limit on the number of frames saved to disk.

TEST=ran new VDA tests on caroline

BUG=962354

Change-Id: Ifc0556986b28309b79ac7df9597154b85f08cc29
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1831728
Commit-Queue: David Staessens <dstaessens@chromium.org>
Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702728}
  • Loading branch information
David Staessens authored and Commit Bot committed Oct 4, 2019
1 parent 1a2e637 commit d59cd9c
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 60 deletions.
15 changes: 10 additions & 5 deletions docs/media/gpu/video_decoder_test_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,19 @@ Multiple command line arguments can be given to the command:
-v enable verbose mode, e.g. -v=2.
--vmodule enable verbose mode for the specified module,
e.g. --vmodule=*media/gpu*=2.

--disable_validator disable frame validation.
--output_frames write the selected video frames to disk, possible
values are "all|corrupt", the default output folder
is "<testname>".
--output_folder overwrite the default output folder used when
"--output_frames" is specified.
--use_vd use the new VD-based video decoders, instead of
the default VDA-based video decoders.

--output_frames write the selected video frames to disk, possible
values are "all|corrupt".
--output_format set the format of frames saved to disk, supported
formats are "png" (default) and "yuv".
--output_limit limit the number of frames saved to disk.
--output_folder set the folder used to store frames, defaults to
"<testname>"

--gtest_help display the gtest help and exit.
--help display this help and exit.

Expand Down
1 change: 1 addition & 0 deletions media/gpu/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ static_library("video_player_test_environment") {
"//media/test/data/",
]
deps = [
":frame_file_writer",
":helpers",
":video_player",
"//media/gpu",
Expand Down
41 changes: 25 additions & 16 deletions media/gpu/test/video_player/video_player_test_environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ VideoPlayerTestEnvironment* VideoPlayerTestEnvironment::Create(
const base::FilePath& video_path,
const base::FilePath& video_metadata_path,
bool enable_validator,
FrameOutputMode frame_output_mode,
const base::FilePath& output_folder,
bool use_vd) {
bool use_vd,
const FrameOutputConfig& frame_output_config,
const base::FilePath& output_folder) {
auto video = std::make_unique<media::test::Video>(
video_path.empty() ? base::FilePath(kDefaultTestVideoPath) : video_path,
video_metadata_path);
Expand All @@ -34,21 +34,21 @@ VideoPlayerTestEnvironment* VideoPlayerTestEnvironment::Create(
}

return new VideoPlayerTestEnvironment(std::move(video), enable_validator,
frame_output_mode, output_folder,
use_vd);
use_vd, frame_output_config,
output_folder);
}

VideoPlayerTestEnvironment::VideoPlayerTestEnvironment(
std::unique_ptr<media::test::Video> video,
bool enable_validator,
FrameOutputMode frame_output_mode,
const base::FilePath& output_folder,
bool use_vd)
bool use_vd,
const FrameOutputConfig& frame_output_config,
const base::FilePath& output_folder)
: video_(std::move(video)),
enable_validator_(enable_validator),
frame_output_mode_(frame_output_mode),
output_folder_(output_folder),
use_vd_(use_vd) {}
use_vd_(use_vd),
frame_output_config_(frame_output_config),
output_folder_(output_folder) {}

VideoPlayerTestEnvironment::~VideoPlayerTestEnvironment() = default;

Expand Down Expand Up @@ -82,16 +82,25 @@ bool VideoPlayerTestEnvironment::IsValidatorEnabled() const {
return enable_validator_;
}

bool VideoPlayerTestEnvironment::UseVD() const {
return use_vd_;
}

FrameOutputMode VideoPlayerTestEnvironment::GetFrameOutputMode() const {
return frame_output_mode_;
return frame_output_config_.output_mode;
}

const base::FilePath& VideoPlayerTestEnvironment::OutputFolder() const {
return output_folder_;
VideoFrameFileWriter::OutputFormat
VideoPlayerTestEnvironment::GetFrameOutputFormat() const {
return frame_output_config_.output_format;
}

bool VideoPlayerTestEnvironment::UseVD() const {
return use_vd_;
uint64_t VideoPlayerTestEnvironment::GetFrameOutputLimit() const {
return frame_output_config_.output_limit;
}

const base::FilePath& VideoPlayerTestEnvironment::OutputFolder() const {
return output_folder_;
}

bool VideoPlayerTestEnvironment::ImportSupported() const {
Expand Down
41 changes: 31 additions & 10 deletions media/gpu/test/video_player/video_player_test_environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
#ifndef MEDIA_GPU_TEST_VIDEO_PLAYER_VIDEO_PLAYER_TEST_ENVIRONMENT_H_
#define MEDIA_GPU_TEST_VIDEO_PLAYER_VIDEO_PLAYER_TEST_ENVIRONMENT_H_

#include <limits>
#include <memory>

#include "base/files/file_path.h"
#include "media/gpu/test/video_frame_file_writer.h"
#include "media/gpu/test/video_test_environment.h"

namespace media {
Expand All @@ -25,6 +27,17 @@ enum class FrameOutputMode {
kAll // Output all frames.
};

// Frame output configuration.
struct FrameOutputConfig {
// The frame output mode controls which frames will be output.
FrameOutputMode output_mode = FrameOutputMode::kNone;
// The maximum number of frames that will be output.
uint64_t output_limit = std::numeric_limits<uint64_t>::max();
// The format of frames that are output.
VideoFrameFileWriter::OutputFormat output_format =
VideoFrameFileWriter::OutputFormat::kPNG;
};

// Test environment for video decode tests. Performs setup and teardown once for
// the entire test run.
class VideoPlayerTestEnvironment : public VideoTestEnvironment {
Expand All @@ -33,9 +46,9 @@ class VideoPlayerTestEnvironment : public VideoTestEnvironment {
const base::FilePath& video_path,
const base::FilePath& video_metadata_path,
bool enable_validator,
FrameOutputMode frame_output_mode,
const base::FilePath& output_folder,
bool use_vd);
bool use_vd,
const FrameOutputConfig& frame_output_config = FrameOutputConfig(),
const base::FilePath& output_folder = base::FilePath());
~VideoPlayerTestEnvironment() override;

// Set up video test environment, called once for entire test run.
Expand All @@ -45,27 +58,35 @@ class VideoPlayerTestEnvironment : public VideoTestEnvironment {
const media::test::Video* Video() const;
// Check whether frame validation is enabled.
bool IsValidatorEnabled() const;
// Check whether we should use VD-based video decoders instead of VDA-based.
bool UseVD() const;

// Get the frame output mode.
FrameOutputMode GetFrameOutputMode() const;
// Get the file format used when outputting frames.
VideoFrameFileWriter::OutputFormat GetFrameOutputFormat() const;
// Get the maximum number of frames that will be output.
uint64_t GetFrameOutputLimit() const;
// Get the output folder.
const base::FilePath& OutputFolder() const;
// Check whether we should use VD-based video decoders instead of VDA-based.
bool UseVD() const;

// Whether import mode is supported, valid after SetUp() has been called.
bool ImportSupported() const;

private:
VideoPlayerTestEnvironment(std::unique_ptr<media::test::Video> video,
bool enable_validator,
FrameOutputMode frame_output_mode,
const base::FilePath& output_folder,
bool use_vd);
bool use_vd,
const FrameOutputConfig& frame_output_config,
const base::FilePath& output_folder);

const std::unique_ptr<media::test::Video> video_;
const bool enable_validator_;
const FrameOutputMode frame_output_mode_;
const base::FilePath output_folder_;
const bool use_vd_;

const FrameOutputConfig frame_output_config_;
const base::FilePath output_folder_;

// TODO(dstaessens): Remove this once all allocate-only platforms reached EOL.
bool import_supported_ = false;
};
Expand Down
4 changes: 1 addition & 3 deletions media/gpu/video_decode_accelerator_perf_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,7 @@ int main(int argc, char** argv) {
// Set up our test environment.
media::test::VideoPlayerTestEnvironment* test_environment =
media::test::VideoPlayerTestEnvironment::Create(
video_path, video_metadata_path, false,
media::test::FrameOutputMode::kAll, base::FilePath(output_folder),
use_vd);
video_path, video_metadata_path, false, use_vd);
if (!test_environment)
return EXIT_FAILURE;

Expand Down
71 changes: 45 additions & 26 deletions media/gpu/video_decode_accelerator_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <limits>

#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/strings/string_number_conversions.h"
#include "media/base/test_data_util.h"
#include "media/gpu/test/video_frame_file_writer.h"
#include "media/gpu/test/video_frame_validator.h"
Expand All @@ -25,7 +28,8 @@ namespace {
constexpr const char* usage_msg =
"usage: video_decode_accelerator_tests\n"
" [-v=<level>] [--vmodule=<config>] [--disable_validator]\n"
" [--output_frames=(all|corrupt)] [--output_folder=<folder>]\n"
" [--output_frames=(all|corrupt)] [--output_format=(png|yuv)]\n"
" [--output_limit=<number>] [--output_folder=<folder>]\n"
" [--use_vd] [--gtest_help] [--help]\n"
" [<video path>] [<video metadata path>]\n";

Expand All @@ -40,24 +44,20 @@ constexpr const char* help_msg =
"\nThe following arguments are supported:\n"
" -v enable verbose mode, e.g. -v=2.\n"
" --vmodule enable verbose mode for the specified module,\n"
" e.g. --vmodule=*media/gpu*=2.\n"
" e.g. --vmodule=*media/gpu*=2.\n\n"
" --disable_validator disable frame validation.\n"
" --output_frames write the selected video frames to disk, possible\n"
" values are \"all|corrupt\", the default output\n"
" folder is \"<testname>\".\n"
" --output_folder overwrite the default output folder used when\n"
" \"--output_frames\" is specified.\n"
" --use_vd use the new VD-based video decoders, instead of\n"
" the default VDA-based video decoders.\n"
" the default VDA-based video decoders.\n\n"
" --output_frames write the selected video frames to disk, possible\n"
" values are \"all|corrupt\".\n"
" --output_format set the format of frames saved to disk, supported\n"
" formats are \"png\" (default) and \"yuv\".\n"
" --output_limit limit the number of frames saved to disk.\n"
" --output_folder set the folder used to store frames, defaults to\n"
" \"<testname>\".\n\n"
" --gtest_help display the gtest help and exit.\n"
" --help display this help and exit.\n";

// The output format used when writing frames to disk.
constexpr VideoFrameFileWriter::OutputFormat kOutputFormat =
VideoFrameFileWriter::OutputFormat::kPNG;
// The max number of corrupt frames to write to disk.
constexpr size_t kCorruptFrameWriteLimit = 3;

media::test::VideoPlayerTestEnvironment* g_env;

// Video decode test class. Performs setup and teardown for each single test.
Expand All @@ -82,22 +82,23 @@ class VideoDecoderTest : public ::testing::Test {
// mode is 'all'. Only supported if import mode is supported and enabled.
if (g_env->GetFrameOutputMode() == FrameOutputMode::kAll &&
config.allocation_mode == AllocationMode::kImport) {
frame_processors.push_back(
VideoFrameFileWriter::Create(output_folder, kOutputFormat));
frame_processors.push_back(VideoFrameFileWriter::Create(
output_folder, g_env->GetFrameOutputFormat(),
g_env->GetFrameOutputLimit()));
VLOG(0) << "Writing video frames to: " << output_folder;
}

// Use the video frame validator to validate decoded video frames if
// enabled. If the frame output mode is 'corrupt', a frame writer will be
// attached to forward corrupted frames to. The maximum number of corrupt
// frames written to disk will be limited, to reduce the size of generated
// test artifacts. Only supported if import mode is supported and enabled.
// attached to forward corrupted frames to. Only supported if import mode
// is supported and enabled.
if (g_env->IsValidatorEnabled() &&
config.allocation_mode == AllocationMode::kImport) {
std::unique_ptr<VideoFrameFileWriter> frame_writer;
if (g_env->GetFrameOutputMode() == FrameOutputMode::kCorrupt) {
frame_writer = VideoFrameFileWriter::Create(
output_folder, kOutputFormat, kCorruptFrameWriteLimit);
output_folder, g_env->GetFrameOutputFormat(),
g_env->GetFrameOutputLimit());
}
frame_processors.push_back(media::test::VideoFrameValidator::Create(
video->FrameChecksums(), PIXEL_FORMAT_I420, std::move(frame_writer)));
Expand Down Expand Up @@ -410,8 +411,7 @@ int main(int argc, char** argv) {

// Parse command line arguments.
bool enable_validator = true;
media::test::FrameOutputMode frame_output_mode =
media::test::FrameOutputMode::kNone;
media::test::FrameOutputConfig frame_output_config;
base::FilePath::StringType output_folder = base::FilePath::kCurrentDirectory;
bool use_vd = false;
base::CommandLine::SwitchMap switches = cmd_line->GetSwitches();
Expand All @@ -426,14 +426,33 @@ int main(int argc, char** argv) {
enable_validator = false;
} else if (it->first == "output_frames") {
if (it->second == "all") {
frame_output_mode = media::test::FrameOutputMode::kAll;
frame_output_config.output_mode = media::test::FrameOutputMode::kAll;
} else if (it->second == "corrupt") {
frame_output_mode = media::test::FrameOutputMode::kCorrupt;
frame_output_config.output_mode =
media::test::FrameOutputMode::kCorrupt;
} else {
std::cout << "unknown frame output mode \"" << it->second
<< "\", possible values are \"all|corrupt\"\n";
return EXIT_FAILURE;
}
} else if (it->first == "output_format") {
if (it->second == "png") {
frame_output_config.output_format =
media::test::VideoFrameFileWriter::OutputFormat::kPNG;
} else if (it->second == "yuv") {
frame_output_config.output_format =
media::test::VideoFrameFileWriter::OutputFormat::kYUV;
} else {
std::cout << "unknown frame output format \"" << it->second
<< "\", possible values are \"png|yuv\"\n";
return EXIT_FAILURE;
}
} else if (it->first == "output_limit") {
if (!base::StringToUint64(it->second,
&frame_output_config.output_limit)) {
std::cout << "invalid number \"" << it->second << "\n";
return EXIT_FAILURE;
}
} else if (it->first == "output_folder") {
output_folder = it->second;
} else if (it->first == "use_vd") {
Expand All @@ -450,8 +469,8 @@ int main(int argc, char** argv) {
// Set up our test environment.
media::test::VideoPlayerTestEnvironment* test_environment =
media::test::VideoPlayerTestEnvironment::Create(
video_path, video_metadata_path, enable_validator, frame_output_mode,
base::FilePath(output_folder), use_vd);
video_path, video_metadata_path, enable_validator, use_vd,
frame_output_config, base::FilePath(output_folder));
if (!test_environment)
return EXIT_FAILURE;

Expand Down

0 comments on commit d59cd9c

Please sign in to comment.