Commit 39eca077 authored by Hirokazu Honda's avatar Hirokazu Honda Committed by Commit Bot

media/gpu/IPTest: Save processed images with --save_images option

This CL introduces an option, --save_images, to save processed images in
ImageProcessor test. The usage documentation of image_processor_test will
also be shown with --help.

This CL enables VideoFrameFileWriter to save memory based VideoFrame, not only
DmaBuf-backed VideoFrame.

Bug: 917951
Test: image_processor_tests --save_images on atlas
Change-Id: I4b4d87bb564873fac0f1a0f51f3a4296a2d9bb1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1774011
Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: default avatarDavid Staessens <dstaessens@chromium.org>
Cr-Commit-Position: refs/heads/master@{#692025}
parent 03c30d39
...@@ -627,6 +627,7 @@ test("image_processor_test") { ...@@ -627,6 +627,7 @@ test("image_processor_test") {
deps = [ deps = [
":buildflags", ":buildflags",
":gpu", ":gpu",
"test:frame_file_writer",
"test:frame_validator", "test:frame_validator",
"test:helpers", "test:helpers",
"test:image_processor", "test:image_processor",
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "media/gpu/image_processor.h" #include "media/gpu/image_processor.h"
#include "media/gpu/test/image.h" #include "media/gpu/test/image.h"
#include "media/gpu/test/image_processor/image_processor_client.h" #include "media/gpu/test/image_processor/image_processor_client.h"
#include "media/gpu/test/video_frame_file_writer.h"
#include "media/gpu/test/video_frame_helpers.h" #include "media/gpu/test/video_frame_helpers.h"
#include "media/gpu/test/video_frame_validator.h" #include "media/gpu/test/video_frame_validator.h"
#include "media/gpu/test/video_test_environment.h" #include "media/gpu/test/video_test_environment.h"
...@@ -27,6 +28,25 @@ ...@@ -27,6 +28,25 @@
namespace media { namespace media {
namespace { namespace {
const char* usage_msg =
"usage: image_processor_test\n"
"[--gtest_help] [--help] [-v=<level>] [--vmodule=<config>] "
"[--save_images]\n";
const char* help_msg =
"Run the image processor tests.\n\n"
"The following arguments are supported:\n"
" --gtest_help display the gtest help and exit.\n"
" --help display this help and exit.\n"
" -v enable verbose mode, e.g. -v=2.\n"
" --vmodule enable verbose mode for the specified module.\n"
" --save_images write images processed by a image processor to\n"
" the \"<testname>\" folder.\n";
bool g_save_images = false;
media::test::VideoTestEnvironment* g_env;
// Files for pixel format conversion test. // Files for pixel format conversion test.
// TODO(crbug.com/944822): Use kI420Image for I420 -> NV12 test case. It is // TODO(crbug.com/944822): Use kI420Image for I420 -> NV12 test case. It is
// currently disabled because there is currently no way of creating DMABUF I420 // currently disabled because there is currently no way of creating DMABUF I420
...@@ -89,6 +109,19 @@ class ImageProcessorParamTest ...@@ -89,6 +109,19 @@ class ImageProcessorParamTest
{output_image.Checksum()}, output_image.PixelFormat()); {output_image.Checksum()}, output_image.PixelFormat());
frame_processors.push_back(std::move(vf_validator)); frame_processors.push_back(std::move(vf_validator));
} }
if (g_save_images) {
base::FilePath output_dir =
base::FilePath(base::FilePath::kCurrentDirectory)
.Append(base::FilePath(g_env->GetTestName()));
test::VideoFrameFileWriter::OutputFormat saved_file_format =
IsYuvPlanar(output_format)
? test::VideoFrameFileWriter::OutputFormat::kYUV
: test::VideoFrameFileWriter::OutputFormat::kPNG;
frame_processors.push_back(
test::VideoFrameFileWriter::Create(output_dir, saved_file_format));
}
auto ip_client = test::ImageProcessorClient::Create( auto ip_client = test::ImageProcessorClient::Create(
input_config, output_config, kNumBuffers, std::move(frame_processors)); input_config, output_config, kNumBuffers, std::move(frame_processors));
LOG_ASSERT(ip_client) << "Failed to create ImageProcessorClient"; LOG_ASSERT(ip_client) << "Failed to create ImageProcessorClient";
...@@ -201,15 +234,42 @@ INSTANTIATE_TEST_SUITE_P( ...@@ -201,15 +234,42 @@ INSTANTIATE_TEST_SUITE_P(
// TODO(hiroh): Add more tests. // TODO(hiroh): Add more tests.
// MEM->DMABUF (V4L2VideoEncodeAccelerator), // MEM->DMABUF (V4L2VideoEncodeAccelerator),
#endif #endif
} // namespace } // namespace
} // namespace media } // namespace media
int main(int argc, char** argv) { int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
base::CommandLine::Init(argc, argv); base::CommandLine::Init(argc, argv);
// Print the help message if requested. This needs to be done before
// initializing gtest, to overwrite the default gtest help message.
const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
LOG_ASSERT(cmd_line);
if (cmd_line->HasSwitch("help")) {
std::cout << media::usage_msg << "\n" << media::help_msg;
return 0;
}
base::CommandLine::SwitchMap switches = cmd_line->GetSwitches();
for (base::CommandLine::SwitchMap::const_iterator it = switches.begin();
it != switches.end(); ++it) {
if (it->first.find("gtest_") == 0 || // Handled by GoogleTest
it->first == "v" || it->first == "vmodule") { // Handled by Chrome
continue;
}
if (it->first == "save_images") {
media::g_save_images = true;
} else {
std::cout << "unknown option: --" << it->first << "\n"
<< media::usage_msg;
return EXIT_FAILURE;
}
}
testing::InitGoogleTest(&argc, argv);
auto* const test_environment = new media::test::VideoTestEnvironment; auto* const test_environment = new media::test::VideoTestEnvironment;
testing::AddGlobalTestEnvironment(test_environment); media::g_env = reinterpret_cast<media::test::VideoTestEnvironment*>(
testing::AddGlobalTestEnvironment(test_environment));
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "build/build_config.h"
#include "media/gpu/video_frame_mapper.h" #include "media/gpu/video_frame_mapper.h"
#include "media/gpu/video_frame_mapper_factory.h" #include "media/gpu/video_frame_mapper_factory.h"
#include "ui/gfx/codec/png_codec.h" #include "ui/gfx/codec/png_codec.h"
...@@ -134,13 +135,18 @@ void VideoFrameFileWriter::WriteVideoFramePNG( ...@@ -134,13 +135,18 @@ void VideoFrameFileWriter::WriteVideoFramePNG(
DCHECK_CALLED_ON_VALID_SEQUENCE(writer_thread_sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(writer_thread_sequence_checker_);
DCHECK(video_frame_mapper_); DCHECK(video_frame_mapper_);
auto mapped_frame = video_frame_mapper_->Map(std::move(video_frame)); auto mapped_frame = video_frame;
#if defined(OS_LINUX)
if (video_frame->storage_type() == VideoFrame::STORAGE_DMABUFS)
mapped_frame = video_frame_mapper_->Map(std::move(video_frame));
#endif
if (!mapped_frame) { if (!mapped_frame) {
LOG(ERROR) << "Failed to map video frame"; LOG(ERROR) << "Failed to map video frame";
return; return;
} }
scoped_refptr<VideoFrame> argb_out_frame = mapped_frame; scoped_refptr<const VideoFrame> argb_out_frame = mapped_frame;
if (argb_out_frame->format() != PIXEL_FORMAT_ARGB) { if (argb_out_frame->format() != PIXEL_FORMAT_ARGB) {
argb_out_frame = ConvertVideoFrame(argb_out_frame.get(), argb_out_frame = ConvertVideoFrame(argb_out_frame.get(),
VideoPixelFormat::PIXEL_FORMAT_ARGB); VideoPixelFormat::PIXEL_FORMAT_ARGB);
...@@ -171,13 +177,18 @@ void VideoFrameFileWriter::WriteVideoFrameYUV( ...@@ -171,13 +177,18 @@ void VideoFrameFileWriter::WriteVideoFrameYUV(
DCHECK_CALLED_ON_VALID_SEQUENCE(writer_thread_sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(writer_thread_sequence_checker_);
DCHECK(video_frame_mapper_); DCHECK(video_frame_mapper_);
auto mapped_frame = video_frame_mapper_->Map(std::move(video_frame)); auto mapped_frame = video_frame;
#if defined(OS_LINUX)
if (video_frame->storage_type() == VideoFrame::STORAGE_DMABUFS)
mapped_frame = video_frame_mapper_->Map(std::move(video_frame));
#endif
if (!mapped_frame) { if (!mapped_frame) {
LOG(ERROR) << "Failed to map video frame"; LOG(ERROR) << "Failed to map video frame";
return; return;
} }
scoped_refptr<VideoFrame> I420_out_frame = mapped_frame; scoped_refptr<const VideoFrame> I420_out_frame = mapped_frame;
if (I420_out_frame->format() != PIXEL_FORMAT_I420) { if (I420_out_frame->format() != PIXEL_FORMAT_I420) {
I420_out_frame = ConvertVideoFrame(I420_out_frame.get(), I420_out_frame = ConvertVideoFrame(I420_out_frame.get(),
VideoPixelFormat::PIXEL_FORMAT_I420); VideoPixelFormat::PIXEL_FORMAT_I420);
......
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