Commit 82d603ea authored by Hirokazu Honda's avatar Hirokazu Honda Committed by Commit Bot

media/gpu/IPTest: Add test cases for the conversion from Dmabuf to memory

This adds test cases for the conversion from Dmabuf to memory on all the
exitsting conversion cases except I420 to NV12. This is because there is
currently no way of creating I420 buffer using NativePixmap.

Bug: 944822
Test: image_processor_test on octopus
Change-Id: Id9f51f00e78c6c391ac2fc76c41da96841c3a71a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1574870
Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: default avatarDavid Staessens <dstaessens@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659414}
parent d2634623
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#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_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 "mojo/core/embedder/embedder.h" #include "mojo/core/embedder/embedder.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
...@@ -26,8 +27,11 @@ ...@@ -26,8 +27,11 @@
namespace media { namespace media {
namespace { namespace {
constexpr const base::FilePath::CharType* kI420Image = // TODO(crbug.com/944822): Use kI420Image for I420 -> NV12 test case. It is
FILE_PATH_LITERAL("bear_320x192.i420.yuv"); // currently disabled because there is currently no way of creating DMABUF I420
// buffer by NativePixmap.
// constexpr const base::FilePath::CharType* kI420Image =
// FILE_PATH_LITERAL("bear_320x192.i420.yuv");
constexpr const base::FilePath::CharType* kNV12Image = constexpr const base::FilePath::CharType* kNV12Image =
FILE_PATH_LITERAL("bear_320x192.nv12.yuv"); FILE_PATH_LITERAL("bear_320x192.nv12.yuv");
constexpr const base::FilePath::CharType* kRGBAImage = constexpr const base::FilePath::CharType* kRGBAImage =
...@@ -42,13 +46,14 @@ class ImageProcessorSimpleParamTest ...@@ -42,13 +46,14 @@ class ImageProcessorSimpleParamTest
public ::testing::WithParamInterface< public ::testing::WithParamInterface<
std::tuple<base::FilePath, base::FilePath>> { std::tuple<base::FilePath, base::FilePath>> {
public: public:
// TODO(crbug.com/917951): Initialize Ozone once.
void SetUp() override {} void SetUp() override {}
void TearDown() override {} void TearDown() override {}
std::unique_ptr<test::ImageProcessorClient> CreateImageProcessorClient( std::unique_ptr<test::ImageProcessorClient> CreateImageProcessorClient(
const test::Image& input_image, const test::Image& input_image,
const test::Image& output_image) { const std::vector<VideoFrame::StorageType>& input_storage_types,
const test::Image& output_image,
const std::vector<VideoFrame::StorageType>& output_storage_types) {
const VideoPixelFormat input_format = input_image.PixelFormat(); const VideoPixelFormat input_format = input_image.PixelFormat();
const VideoPixelFormat output_format = output_image.PixelFormat(); const VideoPixelFormat output_format = output_image.PixelFormat();
auto input_config_layout = test::CreateVideoFrameLayout( auto input_config_layout = test::CreateVideoFrameLayout(
...@@ -58,12 +63,10 @@ class ImageProcessorSimpleParamTest ...@@ -58,12 +63,10 @@ class ImageProcessorSimpleParamTest
VideoFrame::NumPlanes(output_format)); VideoFrame::NumPlanes(output_format));
LOG_ASSERT(input_config_layout); LOG_ASSERT(input_config_layout);
LOG_ASSERT(output_config_layout); LOG_ASSERT(output_config_layout);
ImageProcessor::PortConfig input_config(*input_config_layout, ImageProcessor::PortConfig input_config(
input_image.Size(), *input_config_layout, input_image.Size(), input_storage_types);
{VideoFrame::STORAGE_OWNED_MEMORY});
ImageProcessor::PortConfig output_config( ImageProcessor::PortConfig output_config(
*output_config_layout, output_image.Size(), *output_config_layout, output_image.Size(), output_storage_types);
{VideoFrame::STORAGE_OWNED_MEMORY});
// TODO(crbug.com/917951): Select more appropriate number of buffers. // TODO(crbug.com/917951): Select more appropriate number of buffers.
constexpr size_t kNumBuffers = 1; constexpr size_t kNumBuffers = 1;
LOG_ASSERT(output_image.IsMetadataLoaded()); LOG_ASSERT(output_image.IsMetadataLoaded());
...@@ -81,7 +84,7 @@ class ImageProcessorSimpleParamTest ...@@ -81,7 +84,7 @@ class ImageProcessorSimpleParamTest
} }
}; };
TEST_P(ImageProcessorSimpleParamTest, ConvertOneTimeFromMemToMem) { TEST_P(ImageProcessorSimpleParamTest, ConvertOneTime_MemToMem) {
// Load the test input image. We only need the output image's metadata so we // Load the test input image. We only need the output image's metadata so we
// can compare checksums. // can compare checksums.
test::Image input_image(std::get<0>(GetParam())); test::Image input_image(std::get<0>(GetParam()));
...@@ -89,23 +92,54 @@ TEST_P(ImageProcessorSimpleParamTest, ConvertOneTimeFromMemToMem) { ...@@ -89,23 +92,54 @@ TEST_P(ImageProcessorSimpleParamTest, ConvertOneTimeFromMemToMem) {
ASSERT_TRUE(input_image.Load()); ASSERT_TRUE(input_image.Load());
ASSERT_TRUE(output_image.LoadMetadata()); ASSERT_TRUE(output_image.LoadMetadata());
auto ip_client = CreateImageProcessorClient(input_image, output_image); auto ip_client = CreateImageProcessorClient(
input_image, {VideoFrame::STORAGE_OWNED_MEMORY}, output_image,
{VideoFrame::STORAGE_OWNED_MEMORY});
ip_client->Process(input_image, output_image);
EXPECT_TRUE(ip_client->WaitUntilNumImageProcessed(1u));
EXPECT_EQ(ip_client->GetErrorCount(), 0u);
EXPECT_EQ(ip_client->GetNumOfProcessedImages(), 1u);
EXPECT_TRUE(ip_client->WaitForFrameProcessors());
}
#if defined(OS_CHROMEOS)
// We don't yet have the function to create Dmabuf-backed VideoFrame on
// platforms except ChromeOS. So MemToDmabuf test is limited on ChromeOS.
TEST_P(ImageProcessorSimpleParamTest, ConvertOneTime_MemToDmabuf) {
// Load the test input image. We only need the output image's metadata so we
// can compare checksums.
test::Image input_image(std::get<0>(GetParam()));
test::Image output_image(std::get<1>(GetParam()));
ASSERT_TRUE(input_image.Load());
ASSERT_TRUE(output_image.LoadMetadata());
auto ip_client = CreateImageProcessorClient(
input_image, {VideoFrame::STORAGE_OWNED_MEMORY}, output_image,
{VideoFrame::STORAGE_OWNED_MEMORY});
ip_client->Process(input_image, output_image); ip_client->Process(input_image, output_image);
EXPECT_TRUE(ip_client->WaitUntilNumImageProcessed(1u)); EXPECT_TRUE(ip_client->WaitUntilNumImageProcessed(1u));
EXPECT_EQ(ip_client->GetErrorCount(), 0u); EXPECT_EQ(ip_client->GetErrorCount(), 0u);
EXPECT_EQ(ip_client->GetNumOfProcessedImages(), 1u); EXPECT_EQ(ip_client->GetNumOfProcessedImages(), 1u);
EXPECT_TRUE(ip_client->WaitForFrameProcessors()); EXPECT_TRUE(ip_client->WaitForFrameProcessors());
} }
#endif // defined(OS_CHROMEOS)
// BGRA->NV12 // BGRA -> NV12
// I420->NV12 // I420 -> NV12
// RGBA->NV12 // RGBA -> NV12
// YV12->NV12 // YV12 -> NV12
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
ConvertToNV12, ConvertToNV12,
ImageProcessorSimpleParamTest, ImageProcessorSimpleParamTest,
::testing::Values(std::make_tuple(kBGRAImage, kNV12Image), ::testing::Values(std::make_tuple(kBGRAImage, kNV12Image),
std::make_tuple(kI420Image, kNV12Image), // TODO(crbug.com/944822): Add I420 -> NV12 test case.
// There is currently no way of creating DMABUF
// I420 buffer by NativePixmap.
// std::make_tuple(kI420Image, kNV12Image),
std::make_tuple(kRGBAImage, kNV12Image), std::make_tuple(kRGBAImage, kNV12Image),
std::make_tuple(kYV12Image, kNV12Image))); std::make_tuple(kYV12Image, kNV12Image)));
...@@ -121,14 +155,8 @@ INSTANTIATE_TEST_SUITE_P( ...@@ -121,14 +155,8 @@ INSTANTIATE_TEST_SUITE_P(
int main(int argc, char** argv) { int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
base::CommandLine::Init(argc, argv); base::CommandLine::Init(argc, argv);
// Using shared memory requires mojo to be initialized (crbug.com/849207).
mojo::core::Init();
base::ShadowingAtExitManager at_exit_manager;
// Needed to enable DVLOG through --vmodule.
logging::LoggingSettings settings;
settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
LOG_ASSERT(logging::InitLogging(settings));
auto* const test_environment = new media::test::VideoTestEnvironment;
testing::AddGlobalTestEnvironment(test_environment);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }
...@@ -115,9 +115,9 @@ scoped_refptr<VideoFrame> ImageProcessorClient::CreateInputFrame( ...@@ -115,9 +115,9 @@ scoped_refptr<VideoFrame> ImageProcessorClient::CreateInputFrame(
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
LOG_ASSERT(image_processor_->input_storage_type() == LOG_ASSERT(image_processor_->input_storage_type() ==
VideoFrame::STORAGE_DMABUFS); VideoFrame::STORAGE_DMABUFS);
return CloneVideoFrame(CreateVideoFrameFromImage(input_image).get(),
input_layout, VideoFrame::STORAGE_DMABUFS);
#endif #endif
// TODO(crbug.com/917951): Support Dmabuf.
NOTIMPLEMENTED();
return nullptr; return nullptr;
} }
} }
...@@ -130,13 +130,13 @@ scoped_refptr<VideoFrame> ImageProcessorClient::CreateOutputFrame( ...@@ -130,13 +130,13 @@ scoped_refptr<VideoFrame> ImageProcessorClient::CreateOutputFrame(
const auto& output_layout = image_processor_->output_layout(); const auto& output_layout = image_processor_->output_layout();
if (VideoFrame::IsStorageTypeMappable( if (VideoFrame::IsStorageTypeMappable(
image_processor_->input_storage_type())) { image_processor_->output_storage_type())) {
return VideoFrame::CreateFrameWithLayout( return VideoFrame::CreateFrameWithLayout(
output_layout, gfx::Rect(output_image.Size()), output_image.Size(), output_layout, gfx::Rect(output_image.Size()), output_image.Size(),
base::TimeDelta(), false /* zero_initialize_memory*/); base::TimeDelta(), false /* zero_initialize_memory*/);
} else { } else {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
LOG_ASSERT(image_processor_->input_storage_type() == LOG_ASSERT(image_processor_->output_storage_type() ==
VideoFrame::STORAGE_DMABUFS); VideoFrame::STORAGE_DMABUFS);
#endif #endif
// TODO(crbug.com/917951): Support Dmabuf. // TODO(crbug.com/917951): Support Dmabuf.
......
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