Commit 1c05c665 authored by Chih-Yu Huang's avatar Chih-Yu Huang Committed by Commit Bot

media/gpu/test: Add parameter to support VD-based VDA using VdVDA.

This CL adds a parameter "--use_vd_vda" to the
video_decode_accelerator_tests and video_decode_accelerator_perf_tests
to support VD-based VDA using VdVDA.

Bug: b:136716838
Test: video_decode_accelerator_tests --use_vd_vda on Kevin and Eve
Test: video_decode_accelerator_perf_tests --use_vd_vda on Kevin and Eve

Change-Id: Ib515f97cef66412a3ff833686148d846148d6109
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1928519Reviewed-by: default avatarAlexandre Courbot <acourbot@chromium.org>
Reviewed-by: default avatarDavid Staessens <dstaessens@chromium.org>
Commit-Queue: Chih-Yu Huang <akahuang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#749522}
parent 4781aef0
......@@ -128,6 +128,7 @@ static_library("video_player_test_environment") {
deps = [
":frame_file_writer",
":helpers",
":video_player",
"//media/gpu",
]
}
......
......@@ -21,7 +21,9 @@
#include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION)
#include "media/gpu/chromeos/chromeos_video_decoder_factory.h"
#include "media/gpu/chromeos/platform_video_frame_utils.h"
#include "media/gpu/chromeos/vd_video_decode_accelerator.h"
#endif // BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION)
namespace media {
......@@ -34,12 +36,14 @@ constexpr size_t kTimestampCacheSize = 128;
TestVDAVideoDecoder::TestVDAVideoDecoder(
AllocationMode allocation_mode,
bool use_vd_vda,
const gfx::ColorSpace& target_color_space,
FrameRenderer* const frame_renderer,
gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory)
: output_mode_(allocation_mode == AllocationMode::kAllocate
? VideoDecodeAccelerator::Config::OutputMode::ALLOCATE
: VideoDecodeAccelerator::Config::OutputMode::IMPORT),
use_vd_vda_(use_vd_vda),
target_color_space_(target_color_space),
frame_renderer_(frame_renderer),
#if BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION)
......@@ -125,8 +129,19 @@ void TestVDAVideoDecoder::Initialize(const VideoDecoderConfig& config,
gpu::GpuDriverBugWorkarounds gpu_driver_bug_workarounds;
gpu::GpuPreferences gpu_preferences;
decoder_ = decoder_factory->CreateVDA(
this, vda_config, gpu_driver_bug_workarounds, gpu_preferences);
if (use_vd_vda_) {
#if BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION)
DVLOGF(2) << "Use VdVideoDecodeAccelerator";
vda_config.is_deferred_initialization_allowed = true;
decoder_ = media::VdVideoDecodeAccelerator::Create(
base::BindRepeating(&media::ChromeosVideoDecoderFactory::Create), this,
vda_config, base::SequencedTaskRunnerHandle::Get());
#endif // BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION)
} else {
DVLOGF(2) << "Use original VDA";
decoder_ = decoder_factory->CreateVDA(
this, vda_config, gpu_driver_bug_workarounds, gpu_preferences);
}
if (!decoder_) {
ASSERT_TRUE(decoder_) << "Failed to create VideoDecodeAccelerator factory";
......
......@@ -37,6 +37,7 @@ class TestVDAVideoDecoder : public media::VideoDecoder,
// whether allocating video frames will be done by the TestVDAVideoDecoder, or
// delegated to the underlying VDA.
TestVDAVideoDecoder(AllocationMode allocation_mode,
bool use_vd_vda,
const gfx::ColorSpace& target_color_space,
FrameRenderer* const frame_renderer,
gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory);
......@@ -105,6 +106,9 @@ class TestVDAVideoDecoder : public media::VideoDecoder,
// Video decode accelerator output mode.
const VideoDecodeAccelerator::Config::OutputMode output_mode_;
// Whether VdVideoDecodeAccelerator is used.
bool use_vd_vda_;
// Output color space, used as hint to decoder to avoid conversions.
const gfx::ColorSpace target_color_space_;
......
......@@ -181,24 +181,32 @@ void VideoDecoderClient::CreateDecoderTask(bool* success,
DCHECK_EQ(decoder_client_state_, VideoDecoderClientState::kUninitialized);
ASSERT_TRUE(!decoder_) << "Can't create decoder: already created";
if (decoder_client_config_.use_vd) {
switch (decoder_client_config_.implementation) {
case DecoderImplementation::kVD:
#if BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION)
if (decoder_client_config_.allocation_mode == AllocationMode::kImport) {
decoder_ = ChromeosVideoDecoderFactory::Create(
base::ThreadTaskRunnerHandle::Get(),
std::make_unique<PlatformVideoFramePool>(gpu_memory_buffer_factory_),
std::make_unique<VideoFrameConverter>(), gpu_memory_buffer_factory_);
} else {
LOG(ERROR) << "VD-based video decoders only support import mode";
}
if (decoder_client_config_.allocation_mode == AllocationMode::kImport) {
decoder_ = ChromeosVideoDecoderFactory::Create(
base::ThreadTaskRunnerHandle::Get(),
std::make_unique<PlatformVideoFramePool>(
gpu_memory_buffer_factory_),
std::make_unique<VideoFrameConverter>(),
gpu_memory_buffer_factory_);
} else {
LOG(ERROR) << "VD-based video decoders only support import mode";
}
#endif // BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION)
} else {
// The video decoder client expects decoders to use the VD interface. We
// can use the TestVDAVideoDecoder wrapper here to test VDA-based video
// decoders.
decoder_ = std::make_unique<TestVDAVideoDecoder>(
decoder_client_config_.allocation_mode, gfx::ColorSpace(),
frame_renderer_.get(), gpu_memory_buffer_factory_);
break;
case DecoderImplementation::kVDA:
case DecoderImplementation::kVDVDA:
// The video decoder client expects decoders to use the VD interface. We
// can use the TestVDAVideoDecoder wrapper here to test VDA-based video
// decoders.
decoder_ = std::make_unique<TestVDAVideoDecoder>(
decoder_client_config_.allocation_mode,
decoder_client_config_.implementation ==
DecoderImplementation::kVDVDA,
gfx::ColorSpace(), frame_renderer_.get(), gpu_memory_buffer_factory_);
break;
}
*success = (decoder_ != nullptr);
......
......@@ -38,6 +38,13 @@ enum class AllocationMode {
kAllocate, // Video decoder allocates video frame memory.
};
// The supported video decoding implementation.
enum class DecoderImplementation {
kVDA, // VDA-based video decoder.
kVD, // VD-based video decoder.
kVDVDA, // VD-based video decoder with VdVDA.
};
// Video decoder client configuration.
struct VideoDecoderClientConfig {
// The maximum number of bitstream buffer decodes that can be requested
......@@ -45,8 +52,7 @@ struct VideoDecoderClientConfig {
size_t max_outstanding_decode_requests = 1;
// How the pictures buffers should be allocated.
AllocationMode allocation_mode = AllocationMode::kImport;
// Use VD-based video decoders instead of VDA-based video decoders.
bool use_vd = false;
DecoderImplementation implementation = DecoderImplementation::kVDA;
};
// The video decoder client is responsible for the communication between the
......
......@@ -9,6 +9,7 @@
#include "base/system/sys_info.h"
#include "media/base/video_types.h"
#include "media/gpu/test/video.h"
#include "media/gpu/test/video_player/video_decoder_client.h"
namespace media {
namespace test {
......@@ -22,7 +23,7 @@ VideoPlayerTestEnvironment* VideoPlayerTestEnvironment::Create(
const base::FilePath& video_path,
const base::FilePath& video_metadata_path,
bool enable_validator,
bool use_vd,
const DecoderImplementation implementation,
const base::FilePath& output_folder,
const FrameOutputConfig& frame_output_config) {
auto video = std::make_unique<media::test::Video>(
......@@ -34,19 +35,19 @@ VideoPlayerTestEnvironment* VideoPlayerTestEnvironment::Create(
}
return new VideoPlayerTestEnvironment(std::move(video), enable_validator,
use_vd, output_folder,
implementation, output_folder,
frame_output_config);
}
VideoPlayerTestEnvironment::VideoPlayerTestEnvironment(
std::unique_ptr<media::test::Video> video,
bool enable_validator,
bool use_vd,
const DecoderImplementation implementation,
const base::FilePath& output_folder,
const FrameOutputConfig& frame_output_config)
: video_(std::move(video)),
enable_validator_(enable_validator),
use_vd_(use_vd),
implementation_(implementation),
frame_output_config_(frame_output_config),
output_folder_(output_folder),
gpu_memory_buffer_factory_(
......@@ -74,7 +75,7 @@ void VideoPlayerTestEnvironment::SetUp() {
#endif // defined(OS_CHROMEOS)
// VideoDecoders always require import mode to be supported.
DCHECK(!use_vd_ || import_supported_);
DCHECK(import_supported_ || implementation_ == DecoderImplementation::kVDA);
}
const media::test::Video* VideoPlayerTestEnvironment::Video() const {
......@@ -90,8 +91,9 @@ bool VideoPlayerTestEnvironment::IsValidatorEnabled() const {
return enable_validator_;
}
bool VideoPlayerTestEnvironment::UseVD() const {
return use_vd_;
DecoderImplementation VideoPlayerTestEnvironment::GetDecoderImplementation()
const {
return implementation_;
}
FrameOutputMode VideoPlayerTestEnvironment::GetFrameOutputMode() const {
......
......@@ -11,6 +11,7 @@
#include "base/files/file_path.h"
#include "gpu/ipc/service/gpu_memory_buffer_factory.h"
#include "media/gpu/test/video_frame_file_writer.h"
#include "media/gpu/test/video_player/video_decoder_client.h"
#include "media/gpu/test/video_test_environment.h"
namespace media {
......@@ -47,7 +48,7 @@ class VideoPlayerTestEnvironment : public VideoTestEnvironment {
const base::FilePath& video_path,
const base::FilePath& video_metadata_path,
bool enable_validator,
bool use_vd,
const DecoderImplementation implementation,
const base::FilePath& output_folder = base::FilePath(),
const FrameOutputConfig& frame_output_config = FrameOutputConfig());
~VideoPlayerTestEnvironment() override;
......@@ -59,8 +60,8 @@ 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;
// Return which implementation is used.
DecoderImplementation GetDecoderImplementation() const;
// Get the frame output mode.
FrameOutputMode GetFrameOutputMode() const;
......@@ -83,13 +84,13 @@ class VideoPlayerTestEnvironment : public VideoTestEnvironment {
private:
VideoPlayerTestEnvironment(std::unique_ptr<media::test::Video> video,
bool enable_validator,
bool use_vd,
const DecoderImplementation implementation,
const base::FilePath& output_folder,
const FrameOutputConfig& frame_output_config);
const std::unique_ptr<media::test::Video> video_;
const bool enable_validator_;
const bool use_vd_;
const DecoderImplementation implementation_;
const FrameOutputConfig frame_output_config_;
const base::FilePath output_folder_;
......
......@@ -29,7 +29,7 @@ namespace {
constexpr const char* usage_msg =
"usage: video_decode_accelerator_perf_tests\n"
" [-v=<level>] [--vmodule=<config>] [--output_folder]\n"
" [--use_vd] [--gtest_help] [--help]\n"
" ([--use_vd]|[--use_vd_vda]) [--gtest_help] [--help]\n"
" [<video path>] [<video metadata path>]\n";
// Video decoder perf tests help message.
......@@ -49,6 +49,10 @@ constexpr const char* help_msg =
" will be stored in the current working directory.\n"
" --use_vd use the new VD-based video decoders, instead of\n"
" the default VDA-based video decoders.\n"
" --use_vd_vda use the new VD-based video decoders with a wrapper"
" that translates to the VDA interface, used to test"
" interaction with older components expecting the VDA"
" interface.\n"
" --gtest_help display the gtest help and exit.\n"
" --help display this help and exit.\n";
......@@ -316,7 +320,7 @@ class VideoDecoderTest : public ::testing::Test {
// Use the new VD-based video decoders if requested.
VideoDecoderClientConfig config;
config.use_vd = g_env->UseVD();
config.implementation = g_env->GetDecoderImplementation();
// Force allocate mode if import mode is not supported.
if (!g_env->ImportSupported())
......@@ -399,6 +403,9 @@ int main(int argc, char** argv) {
// Parse command line arguments.
base::FilePath::StringType output_folder = media::test::kDefaultOutputFolder;
bool use_vd = false;
bool use_vd_vda = false;
media::test::DecoderImplementation implementation =
media::test::DecoderImplementation::kVDA;
base::CommandLine::SwitchMap switches = cmd_line->GetSwitches();
for (base::CommandLine::SwitchMap::const_iterator it = switches.begin();
it != switches.end(); ++it) {
......@@ -411,6 +418,10 @@ int main(int argc, char** argv) {
output_folder = it->second;
} else if (it->first == "use_vd") {
use_vd = true;
implementation = media::test::DecoderImplementation::kVD;
} else if (it->first == "use_vd_vda") {
use_vd_vda = true;
implementation = media::test::DecoderImplementation::kVDVDA;
} else {
std::cout << "unknown option: --" << it->first << "\n"
<< media::test::usage_msg;
......@@ -418,12 +429,18 @@ int main(int argc, char** argv) {
}
}
if (use_vd && use_vd_vda) {
std::cout << "--use_vd and --use_vd_vda cannot be enabled together.\n"
<< media::test::usage_msg;
return EXIT_FAILURE;
}
testing::InitGoogleTest(&argc, argv);
// Set up our test environment.
media::test::VideoPlayerTestEnvironment* test_environment =
media::test::VideoPlayerTestEnvironment::Create(
video_path, video_metadata_path, false, use_vd,
video_path, video_metadata_path, false, implementation,
base::FilePath(output_folder));
if (!test_environment)
return EXIT_FAILURE;
......
......@@ -30,7 +30,7 @@ constexpr const char* usage_msg =
" [-v=<level>] [--vmodule=<config>] [--disable_validator]\n"
" [--output_frames=(all|corrupt)] [--output_format=(png|yuv)]\n"
" [--output_limit=<number>] [--output_folder=<folder>]\n"
" [--use_vd] [--gtest_help] [--help]\n"
" ([--use_vd]|[--use_vd_vda]) [--gtest_help] [--help]\n"
" [<video path>] [<video metadata path>]\n";
// Video decoder tests help message.
......@@ -48,6 +48,10 @@ constexpr const char* help_msg =
" --disable_validator disable frame validation.\n"
" --use_vd use the new VD-based video decoders, instead of\n"
" the default VDA-based video decoders.\n\n"
" --use_vd_vda use the new VD-based video decoders with a wrapper"
" that translates to the VDA interface, used to test"
" interaction with older components expecting the VDA"
" interface.\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"
......@@ -104,8 +108,7 @@ class VideoDecoderTest : public ::testing::Test {
video->FrameChecksums(), PIXEL_FORMAT_I420, std::move(frame_writer)));
}
// Use the new VD-based video decoders if requested.
config.use_vd = g_env->UseVD();
config.implementation = g_env->GetDecoderImplementation();
auto video_player = VideoPlayer::Create(
config, g_env->GetGpuMemoryBufferFactory(), std::move(frame_renderer),
......@@ -324,8 +327,10 @@ TEST_F(VideoDecoderTest, FlushAtEndOfStream_RenderThumbnails) {
// specified as the new video decoders only support import mode.
// TODO(dstaessens): Deprecate after switching to new VD-based video decoders.
TEST_F(VideoDecoderTest, FlushAtEndOfStream_Allocate) {
if (!g_env->ImportSupported() || g_env->UseVD())
if (!g_env->ImportSupported() ||
g_env->GetDecoderImplementation() != DecoderImplementation::kVDA) {
GTEST_SKIP();
}
VideoDecoderClientConfig config;
config.allocation_mode = AllocationMode::kAllocate;
......@@ -352,7 +357,7 @@ TEST_F(VideoDecoderTest, Initialize) {
// the media::VideoDecoder interface, so the test will be skipped if --use_vd
// is not specified.
TEST_F(VideoDecoderTest, Reinitialize) {
if (!g_env->UseVD())
if (g_env->GetDecoderImplementation() != DecoderImplementation::kVD)
GTEST_SKIP();
// Create and initialize the video decoder.
......@@ -381,7 +386,7 @@ TEST_F(VideoDecoderTest, Reinitialize) {
// are triggered upon destroying.
TEST_F(VideoDecoderTest, DestroyBeforeInitialize) {
VideoDecoderClientConfig config = VideoDecoderClientConfig();
config.use_vd = g_env->UseVD();
config.implementation = g_env->GetDecoderImplementation();
auto tvp = VideoPlayer::Create(config, g_env->GetGpuMemoryBufferFactory(),
FrameRendererDummy::Create());
EXPECT_NE(tvp, nullptr);
......@@ -416,6 +421,9 @@ int main(int argc, char** argv) {
media::test::FrameOutputConfig frame_output_config;
base::FilePath::StringType output_folder = base::FilePath::kCurrentDirectory;
bool use_vd = false;
bool use_vd_vda = false;
media::test::DecoderImplementation implementation =
media::test::DecoderImplementation::kVDA;
base::CommandLine::SwitchMap switches = cmd_line->GetSwitches();
for (base::CommandLine::SwitchMap::const_iterator it = switches.begin();
it != switches.end(); ++it) {
......@@ -459,6 +467,10 @@ int main(int argc, char** argv) {
output_folder = it->second;
} else if (it->first == "use_vd") {
use_vd = true;
implementation = media::test::DecoderImplementation::kVD;
} else if (it->first == "use_vd_vda") {
use_vd_vda = true;
implementation = media::test::DecoderImplementation::kVDVDA;
} else {
std::cout << "unknown option: --" << it->first << "\n"
<< media::test::usage_msg;
......@@ -466,12 +478,18 @@ int main(int argc, char** argv) {
}
}
if (use_vd && use_vd_vda) {
std::cout << "--use_vd and --use_vd_vda cannot be enabled together.\n"
<< media::test::usage_msg;
return EXIT_FAILURE;
}
testing::InitGoogleTest(&argc, argv);
// Set up our test environment.
media::test::VideoPlayerTestEnvironment* test_environment =
media::test::VideoPlayerTestEnvironment::Create(
video_path, video_metadata_path, enable_validator, use_vd,
video_path, video_metadata_path, enable_validator, implementation,
base::FilePath(output_folder), frame_output_config);
if (!test_environment)
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