Commit 6195d0b0 authored by Hirokazu Honda's avatar Hirokazu Honda Committed by Commit Bot

media/gpu/vea-tests: Add output codec option

There is no way to specify codec profile that VideoEncodeAccelerator
must produce in video_encode_accelerator_tests. This adds the
command line option to specify it.

Bug: 1045825
Test: video_encode_accelerator_tests on eve
Change-Id: Iaaea9443abac4d6e1d6dd0ad8950538ea90185f3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2203556Reviewed-by: default avatarDavid Staessens <dstaessens@chromium.org>
Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#769941}
parent 839f9cd9
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "media/gpu/test/video_encoder/video_encoder_test_environment.h" #include "media/gpu/test/video_encoder/video_encoder_test_environment.h"
#include <algorithm>
#include <utility> #include <utility>
#include "gpu/ipc/service/gpu_memory_buffer_factory.h" #include "gpu/ipc/service/gpu_memory_buffer_factory.h"
...@@ -12,12 +13,23 @@ ...@@ -12,12 +13,23 @@
namespace media { namespace media {
namespace test { namespace test {
namespace {
struct CodecParamToProfile {
const char* codec;
const VideoCodecProfile profile;
} kCodecParamToProfile[] = {
{"h264baseline", H264PROFILE_BASELINE}, {"h264", H264PROFILE_MAIN},
{"h264main", H264PROFILE_MAIN}, {"vp8", VP8PROFILE_ANY},
{"vp9", VP9PROFILE_PROFILE0},
};
} // namespace
// static // static
VideoEncoderTestEnvironment* VideoEncoderTestEnvironment::Create( VideoEncoderTestEnvironment* VideoEncoderTestEnvironment::Create(
const base::FilePath& video_path, const base::FilePath& video_path,
const base::FilePath& video_metadata_path, const base::FilePath& video_metadata_path,
const base::FilePath& output_folder) { const base::FilePath& output_folder,
const std::string& codec) {
if (video_path.empty()) { if (video_path.empty()) {
LOG(ERROR) << "No video specified"; LOG(ERROR) << "No video specified";
return nullptr; return nullptr;
...@@ -47,14 +59,25 @@ VideoEncoderTestEnvironment* VideoEncoderTestEnvironment::Create( ...@@ -47,14 +59,25 @@ VideoEncoderTestEnvironment* VideoEncoderTestEnvironment::Create(
return nullptr; return nullptr;
} }
return new VideoEncoderTestEnvironment(std::move(video), output_folder); const auto* it = std::find_if(
std::begin(kCodecParamToProfile), std::end(kCodecParamToProfile),
[codec](const auto& cp) { return cp.codec == codec; });
if (it == std::end(kCodecParamToProfile)) {
LOG(ERROR) << "Unknown codec: " << codec;
return nullptr;
}
VideoCodecProfile profile = it->profile;
return new VideoEncoderTestEnvironment(std::move(video), output_folder,
profile);
} }
VideoEncoderTestEnvironment::VideoEncoderTestEnvironment( VideoEncoderTestEnvironment::VideoEncoderTestEnvironment(
std::unique_ptr<media::test::Video> video, std::unique_ptr<media::test::Video> video,
const base::FilePath& output_folder) const base::FilePath& output_folder,
VideoCodecProfile profile)
: video_(std::move(video)), : video_(std::move(video)),
output_folder_(output_folder), output_folder_(output_folder),
profile_(profile),
gpu_memory_buffer_factory_( gpu_memory_buffer_factory_(
gpu::GpuMemoryBufferFactory::CreateNativeType(nullptr)) {} gpu::GpuMemoryBufferFactory::CreateNativeType(nullptr)) {}
...@@ -68,6 +91,10 @@ const base::FilePath& VideoEncoderTestEnvironment::OutputFolder() const { ...@@ -68,6 +91,10 @@ const base::FilePath& VideoEncoderTestEnvironment::OutputFolder() const {
return output_folder_; return output_folder_;
} }
VideoCodecProfile VideoEncoderTestEnvironment::Profile() const {
return profile_;
}
gpu::GpuMemoryBufferFactory* gpu::GpuMemoryBufferFactory*
VideoEncoderTestEnvironment::GetGpuMemoryBufferFactory() const { VideoEncoderTestEnvironment::GetGpuMemoryBufferFactory() const {
return gpu_memory_buffer_factory_.get(); return gpu_memory_buffer_factory_.get();
......
...@@ -7,8 +7,10 @@ ...@@ -7,8 +7,10 @@
#include <limits> #include <limits>
#include <memory> #include <memory>
#include <string>
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "media/base/video_codecs.h"
#include "media/gpu/test/video_test_environment.h" #include "media/gpu/test/video_test_environment.h"
namespace gpu { namespace gpu {
...@@ -27,13 +29,16 @@ class VideoEncoderTestEnvironment : public VideoTestEnvironment { ...@@ -27,13 +29,16 @@ class VideoEncoderTestEnvironment : public VideoTestEnvironment {
static VideoEncoderTestEnvironment* Create( static VideoEncoderTestEnvironment* Create(
const base::FilePath& video_path, const base::FilePath& video_path,
const base::FilePath& video_metadata_path, const base::FilePath& video_metadata_path,
const base::FilePath& output_folder); const base::FilePath& output_folder,
const std::string& codec);
~VideoEncoderTestEnvironment() override; ~VideoEncoderTestEnvironment() override;
// Get the video the tests will be ran on. // Get the video the tests will be ran on.
const media::test::Video* Video() const; const media::test::Video* Video() const;
// Get the output folder. // Get the output folder.
const base::FilePath& OutputFolder() const; const base::FilePath& OutputFolder() const;
// Get the output codec profile.
VideoCodecProfile Profile() const;
// Get the GpuMemoryBufferFactory for doing buffer allocations. This needs to // Get the GpuMemoryBufferFactory for doing buffer allocations. This needs to
// survive as long as the process is alive just like in production which is // survive as long as the process is alive just like in production which is
...@@ -43,12 +48,15 @@ class VideoEncoderTestEnvironment : public VideoTestEnvironment { ...@@ -43,12 +48,15 @@ class VideoEncoderTestEnvironment : public VideoTestEnvironment {
private: private:
VideoEncoderTestEnvironment(std::unique_ptr<media::test::Video> video, VideoEncoderTestEnvironment(std::unique_ptr<media::test::Video> video,
const base::FilePath& output_folder); const base::FilePath& output_folder,
VideoCodecProfile profile);
// Video file to be used for testing. // Video file to be used for testing.
const std::unique_ptr<media::test::Video> video_; const std::unique_ptr<media::test::Video> video_;
// Output folder to be used to store test artifacts (e.g. perf metrics). // Output folder to be used to store test artifacts (e.g. perf metrics).
const base::FilePath output_folder_; const base::FilePath output_folder_;
// VideoCodecProfile to be produced by VideoEncoder.
const VideoCodecProfile profile_;
std::unique_ptr<gpu::GpuMemoryBufferFactory> gpu_memory_buffer_factory_; std::unique_ptr<gpu::GpuMemoryBufferFactory> gpu_memory_buffer_factory_;
}; };
......
...@@ -29,6 +29,7 @@ namespace { ...@@ -29,6 +29,7 @@ namespace {
// TODO(dstaessens): Add video_encoder_perf_test_usage.md // TODO(dstaessens): Add video_encoder_perf_test_usage.md
constexpr const char* usage_msg = constexpr const char* usage_msg =
"usage: video_encode_accelerator_perf_tests\n" "usage: video_encode_accelerator_perf_tests\n"
" [--codec=<codec>]\n"
" [-v=<level>] [--vmodule=<config>] [--output_folder]\n" " [-v=<level>] [--vmodule=<config>] [--output_folder]\n"
" [--gtest_help] [--help]\n" " [--gtest_help] [--help]\n"
" [<video path>] [<video metadata path>]\n"; " [<video path>] [<video metadata path>]\n";
...@@ -42,6 +43,8 @@ constexpr const char* help_msg = ...@@ -42,6 +43,8 @@ constexpr const char* help_msg =
"containing the video's metadata. By default <video path>.json will be\n" "containing the video's metadata. By default <video path>.json will be\n"
"used.\n" "used.\n"
"\nThe following arguments are supported:\n" "\nThe following arguments are supported:\n"
" --codec codec profile to encode, \"h264 (baseline)\",\n"
" \"h264main, \"h264high\", \"vp8\" and \"vp9\"\n"
" -v enable verbose mode, e.g. -v=2.\n" " -v enable verbose mode, e.g. -v=2.\n"
" --vmodule enable verbose mode for the specified module,\n" " --vmodule enable verbose mode for the specified module,\n"
" --output_folder overwrite the output folder used to store\n" " --output_folder overwrite the output folder used to store\n"
...@@ -270,7 +273,8 @@ void PerformanceMetrics::WriteToFile() const { ...@@ -270,7 +273,8 @@ void PerformanceMetrics::WriteToFile() const {
class VideoEncoderTest : public ::testing::Test { class VideoEncoderTest : public ::testing::Test {
public: public:
// Create a new video encoder instance. // Create a new video encoder instance.
std::unique_ptr<VideoEncoder> CreateVideoEncoder(const Video* video) { std::unique_ptr<VideoEncoder> CreateVideoEncoder(const Video* video,
VideoCodecProfile profile) {
LOG_ASSERT(video); LOG_ASSERT(video);
std::vector<std::unique_ptr<BitstreamProcessor>> bitstream_processors; std::vector<std::unique_ptr<BitstreamProcessor>> bitstream_processors;
...@@ -280,6 +284,7 @@ class VideoEncoderTest : public ::testing::Test { ...@@ -280,6 +284,7 @@ class VideoEncoderTest : public ::testing::Test {
VideoEncoderClientConfig config; VideoEncoderClientConfig config;
config.framerate = video->FrameRate(); config.framerate = video->FrameRate();
config.output_profile = profile;
auto video_encoder = auto video_encoder =
VideoEncoder::Create(config, std::move(bitstream_processors)); VideoEncoder::Create(config, std::move(bitstream_processors));
LOG_ASSERT(video_encoder); LOG_ASSERT(video_encoder);
...@@ -297,7 +302,7 @@ class VideoEncoderTest : public ::testing::Test { ...@@ -297,7 +302,7 @@ class VideoEncoderTest : public ::testing::Test {
// test will encode a video as fast as possible, and gives an idea about the // test will encode a video as fast as possible, and gives an idea about the
// maximum output of the encoder. // maximum output of the encoder.
TEST_F(VideoEncoderTest, MeasureUncappedPerformance) { TEST_F(VideoEncoderTest, MeasureUncappedPerformance) {
auto encoder = CreateVideoEncoder(g_env->Video()); auto encoder = CreateVideoEncoder(g_env->Video(), g_env->Profile());
performance_evaluator_->StartMeasuring(); performance_evaluator_->StartMeasuring();
encoder->Encode(); encoder->Encode();
...@@ -336,6 +341,7 @@ int main(int argc, char** argv) { ...@@ -336,6 +341,7 @@ int main(int argc, char** argv) {
: base::FilePath(media::test::kDefaultTestVideoPath); : base::FilePath(media::test::kDefaultTestVideoPath);
base::FilePath video_metadata_path = base::FilePath video_metadata_path =
(args.size() >= 2) ? base::FilePath(args[1]) : base::FilePath(); (args.size() >= 2) ? base::FilePath(args[1]) : base::FilePath();
std::string codec = "h264";
// Parse command line arguments. // Parse command line arguments.
base::FilePath::StringType output_folder = media::test::kDefaultOutputFolder; base::FilePath::StringType output_folder = media::test::kDefaultOutputFolder;
...@@ -349,6 +355,8 @@ int main(int argc, char** argv) { ...@@ -349,6 +355,8 @@ int main(int argc, char** argv) {
if (it->first == "output_folder") { if (it->first == "output_folder") {
output_folder = it->second; output_folder = it->second;
} else if (it->first == "codec") {
codec = it->second;
} else { } else {
std::cout << "unknown option: --" << it->first << "\n" std::cout << "unknown option: --" << it->first << "\n"
<< media::test::usage_msg; << media::test::usage_msg;
...@@ -361,7 +369,8 @@ int main(int argc, char** argv) { ...@@ -361,7 +369,8 @@ int main(int argc, char** argv) {
// Set up our test environment. // Set up our test environment.
media::test::VideoEncoderTestEnvironment* test_environment = media::test::VideoEncoderTestEnvironment* test_environment =
media::test::VideoEncoderTestEnvironment::Create( media::test::VideoEncoderTestEnvironment::Create(
video_path, video_metadata_path, base::FilePath(output_folder)); video_path, video_metadata_path, base::FilePath(output_folder),
codec);
if (!test_environment) if (!test_environment)
return EXIT_FAILURE; return EXIT_FAILURE;
......
...@@ -23,6 +23,7 @@ namespace { ...@@ -23,6 +23,7 @@ namespace {
// TODO(dstaessens): Add video_encoder_test_usage.md // TODO(dstaessens): Add video_encoder_test_usage.md
constexpr const char* usage_msg = constexpr const char* usage_msg =
"usage: video_encode_accelerator_tests\n" "usage: video_encode_accelerator_tests\n"
" [--codec=<codec>]\n"
" [-v=<level>] [--vmodule=<config>] [--gtest_help] [--help]\n" " [-v=<level>] [--vmodule=<config>] [--gtest_help] [--help]\n"
" [<video path>] [<video metadata path>]\n"; " [<video path>] [<video metadata path>]\n";
...@@ -35,6 +36,8 @@ constexpr const char* help_msg = ...@@ -35,6 +36,8 @@ constexpr const char* help_msg =
"containing the video's metadata, such as frame checksums. By default\n" "containing the video's metadata, such as frame checksums. By default\n"
"<video path>.json will be used.\n" "<video path>.json will be used.\n"
"\nThe following arguments are supported:\n" "\nThe following arguments are supported:\n"
" --codec codec profile to encode, \"h264 (baseline)\",\n"
" \"h264main, \"h264high\", \"vp8\" and \"vp9\"\n"
" -v enable verbose mode, e.g. -v=2.\n" " -v enable verbose mode, e.g. -v=2.\n"
" --vmodule enable verbose mode for the specified module,\n" " --vmodule enable verbose mode for the specified module,\n"
" e.g. --vmodule=*media/gpu*=2.\n\n" " e.g. --vmodule=*media/gpu*=2.\n\n"
...@@ -77,6 +80,7 @@ class VideoEncoderTest : public ::testing::Test { ...@@ -77,6 +80,7 @@ class VideoEncoderTest : public ::testing::Test {
TEST_F(VideoEncoderTest, FlushAtEndOfStream) { TEST_F(VideoEncoderTest, FlushAtEndOfStream) {
VideoEncoderClientConfig config = VideoEncoderClientConfig(); VideoEncoderClientConfig config = VideoEncoderClientConfig();
config.framerate = g_env->Video()->FrameRate(); config.framerate = g_env->Video()->FrameRate();
config.output_profile = g_env->Profile();
auto encoder = CreateVideoEncoder(g_env->Video(), config); auto encoder = CreateVideoEncoder(g_env->Video(), config);
encoder->Encode(); encoder->Encode();
...@@ -111,6 +115,7 @@ int main(int argc, char** argv) { ...@@ -111,6 +115,7 @@ int main(int argc, char** argv) {
: base::FilePath(media::test::kDefaultTestVideoPath); : base::FilePath(media::test::kDefaultTestVideoPath);
base::FilePath video_metadata_path = base::FilePath video_metadata_path =
(args.size() >= 2) ? base::FilePath(args[1]) : base::FilePath(); (args.size() >= 2) ? base::FilePath(args[1]) : base::FilePath();
std::string codec = "h264";
// Parse command line arguments. // Parse command line arguments.
base::CommandLine::SwitchMap switches = cmd_line->GetSwitches(); base::CommandLine::SwitchMap switches = cmd_line->GetSwitches();
...@@ -121,9 +126,13 @@ int main(int argc, char** argv) { ...@@ -121,9 +126,13 @@ int main(int argc, char** argv) {
continue; continue;
} }
std::cout << "unknown option: --" << it->first << "\n" if (it->first == "codec") {
<< media::test::usage_msg; codec = it->second;
return EXIT_FAILURE; } else {
std::cout << "unknown option: --" << it->first << "\n"
<< media::test::usage_msg;
return EXIT_FAILURE;
}
} }
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
...@@ -131,7 +140,7 @@ int main(int argc, char** argv) { ...@@ -131,7 +140,7 @@ int main(int argc, char** argv) {
// Set up our test environment. // Set up our test environment.
media::test::VideoEncoderTestEnvironment* test_environment = media::test::VideoEncoderTestEnvironment* test_environment =
media::test::VideoEncoderTestEnvironment::Create( media::test::VideoEncoderTestEnvironment::Create(
video_path, video_metadata_path, base::FilePath()); video_path, video_metadata_path, base::FilePath(), codec);
if (!test_environment) if (!test_environment)
return EXIT_FAILURE; return EXIT_FAILURE;
......
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