Commit e19e04d5 authored by Hirokazu Honda's avatar Hirokazu Honda Committed by Commit Bot

media/gpu/chromeos/IPtest: Add cropping and cropping+scaling test cases

This adds
1.) cropping test case (crop 360p frame 480p frame), and
2.) cropping+scaling test case (crop 360p frame 480p frame and scale
    the image to 270p)

This adds visible rectangle element to media::test::Image.

Bug: 1034415
Test: IPtest on atlas
Change-Id: Ie16d413d0e81029b98209a7eec4eeac6c4691639
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1974303
Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: default avatarDavid Staessens <dstaessens@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728839}
parent e017fd73
...@@ -69,8 +69,12 @@ const base::FilePath::CharType* kNV12Image720P = ...@@ -69,8 +69,12 @@ const base::FilePath::CharType* kNV12Image720P =
FILE_PATH_LITERAL("puppets-1280x720.nv12.yuv"); FILE_PATH_LITERAL("puppets-1280x720.nv12.yuv");
const base::FilePath::CharType* kNV12Image360P = const base::FilePath::CharType* kNV12Image360P =
FILE_PATH_LITERAL("puppets-640x360.nv12.yuv"); FILE_PATH_LITERAL("puppets-640x360.nv12.yuv");
const base::FilePath::CharType* kNV12Image270P =
FILE_PATH_LITERAL("puppets-480x270.nv12.yuv");
const base::FilePath::CharType* kNV12Image180P = const base::FilePath::CharType* kNV12Image180P =
FILE_PATH_LITERAL("puppets-320x180.nv12.yuv"); FILE_PATH_LITERAL("puppets-320x180.nv12.yuv");
const base::FilePath::CharType* kNV12Image360PIn480P =
FILE_PATH_LITERAL("puppets-640x360_in_640x480.nv12.yuv");
class ImageProcessorParamTest class ImageProcessorParamTest
: public ::testing::Test, : public ::testing::Test,
...@@ -107,10 +111,10 @@ class ImageProcessorParamTest ...@@ -107,10 +111,10 @@ class ImageProcessorParamTest
LOG_ASSERT(input_layout && output_layout); LOG_ASSERT(input_layout && output_layout);
ImageProcessor::PortConfig input_config( ImageProcessor::PortConfig input_config(
input_fourcc, input_image.Size(), input_layout->planes(), input_fourcc, input_image.Size(), input_layout->planes(),
gfx::Rect(input_image.Size()), input_storage_types); input_image.VisibleRect(), input_storage_types);
ImageProcessor::PortConfig output_config( ImageProcessor::PortConfig output_config(
output_fourcc, output_image->Size(), output_layout->planes(), output_fourcc, output_image->Size(), output_layout->planes(),
gfx::Rect(output_image->Size()), output_storage_types); output_image->VisibleRect(), output_storage_types);
// 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());
...@@ -280,9 +284,22 @@ INSTANTIATE_TEST_SUITE_P( ...@@ -280,9 +284,22 @@ INSTANTIATE_TEST_SUITE_P(
NV12DownScaling, NV12DownScaling,
ImageProcessorParamTest, ImageProcessorParamTest,
::testing::Values(std::make_tuple(kNV12Image720P, kNV12Image360P), ::testing::Values(std::make_tuple(kNV12Image720P, kNV12Image360P),
std::make_tuple(kNV12Image720P, kNV12Image270P),
std::make_tuple(kNV12Image720P, kNV12Image180P), std::make_tuple(kNV12Image720P, kNV12Image180P),
std::make_tuple(kNV12Image360P, kNV12Image270P),
std::make_tuple(kNV12Image360P, kNV12Image180P))); std::make_tuple(kNV12Image360P, kNV12Image180P)));
// Crop 360P frame from 480P.
INSTANTIATE_TEST_SUITE_P(NV12Cropping,
ImageProcessorParamTest,
::testing::Values(std::make_tuple(kNV12Image360PIn480P,
kNV12Image360P)));
// Crop 360p frame from 480P and scale the area to 270P.
INSTANTIATE_TEST_SUITE_P(NV12CroppingAndScaling,
ImageProcessorParamTest,
::testing::Values(std::make_tuple(kNV12Image360PIn480P,
kNV12Image270P)));
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// TODO(hiroh): Add more tests. // TODO(hiroh): Add more tests.
// MEM->DMABUF (V4L2VideoEncodeAccelerator), // MEM->DMABUF (V4L2VideoEncodeAccelerator),
......
...@@ -11,8 +11,7 @@ ...@@ -11,8 +11,7 @@
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
#include "base/values.h" #include "base/values.h"
#include "media/base/test_data_util.h" #include "media/base/test_data_util.h"
#include "media/gpu/macros.h"
#define VLOGF(level) VLOG(level) << __func__ << "(): "
namespace media { namespace media {
namespace test { namespace test {
...@@ -145,6 +144,26 @@ bool Image::LoadMetadata() { ...@@ -145,6 +144,26 @@ bool Image::LoadMetadata() {
} }
size_ = gfx::Size(width->GetInt(), height->GetInt()); size_ = gfx::Size(width->GetInt(), height->GetInt());
// Try to get the visible rectangle of the image from the json data.
// These values are not in json data if all the image data is in the visible
// area.
visible_rect_ = gfx::Rect(size_);
const base::Value* visible_rect_info =
metadata->FindKeyOfType("visible_rect", base::Value::Type::LIST);
if (visible_rect_info) {
base::Value::ConstListView values = visible_rect_info->GetList();
if (values.size() != 4) {
VLOGF(1) << "unexpected json format for visible rectangle";
return false;
}
int origin_x = values[0].GetInt();
int origin_y = values[1].GetInt();
int visible_width = values[2].GetInt();
int visible_height = values[3].GetInt();
visible_rect_ =
gfx::Rect(origin_x, origin_y, visible_width, visible_height);
}
// Get the image checksum from the json data. // Get the image checksum from the json data.
const base::Value* checksum = const base::Value* checksum =
metadata->FindKeyOfType("checksum", base::Value::Type::STRING); metadata->FindKeyOfType("checksum", base::Value::Type::STRING);
...@@ -177,6 +196,10 @@ const gfx::Size& Image::Size() const { ...@@ -177,6 +196,10 @@ const gfx::Size& Image::Size() const {
return size_; return size_;
} }
const gfx::Rect& Image::VisibleRect() const {
return visible_rect_;
}
const char* Image::Checksum() const { const char* Image::Checksum() const {
return checksum_.data(); return checksum_.data();
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/files/memory_mapped_file.h" #include "base/files/memory_mapped_file.h"
#include "media/base/video_types.h" #include "media/base/video_types.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
namespace media { namespace media {
...@@ -42,6 +43,8 @@ class Image { ...@@ -42,6 +43,8 @@ class Image {
VideoPixelFormat PixelFormat() const; VideoPixelFormat PixelFormat() const;
// Get the image size. // Get the image size.
const gfx::Size& Size() const; const gfx::Size& Size() const;
// Get the visible rectangle of the image.
const gfx::Rect& VisibleRect() const;
// Get the image checksum. // Get the image checksum.
const char* Checksum() const; const char* Checksum() const;
...@@ -57,6 +60,8 @@ class Image { ...@@ -57,6 +60,8 @@ class Image {
VideoPixelFormat pixel_format_ = PIXEL_FORMAT_UNKNOWN; VideoPixelFormat pixel_format_ = PIXEL_FORMAT_UNKNOWN;
// The image size. // The image size.
gfx::Size size_; gfx::Size size_;
// The visible rectangle of the image.
gfx::Rect visible_rect_;
// The image md5 checksum. // The image md5 checksum.
std::string checksum_; std::string checksum_;
......
...@@ -318,14 +318,14 @@ scoped_refptr<VideoFrame> CreateGpuMemoryBufferVideoFrame( ...@@ -318,14 +318,14 @@ scoped_refptr<VideoFrame> CreateGpuMemoryBufferVideoFrame(
scoped_refptr<const VideoFrame> CreateVideoFrameFromImage(const Image& image) { scoped_refptr<const VideoFrame> CreateVideoFrameFromImage(const Image& image) {
DCHECK(image.IsLoaded()); DCHECK(image.IsLoaded());
const auto format = image.PixelFormat(); const auto format = image.PixelFormat();
const auto& visible_size = image.Size(); const auto& image_size = image.Size();
// Loaded image data must be tight. // Loaded image data must be tight.
DCHECK_EQ(image.DataSize(), VideoFrame::AllocationSize(format, visible_size)); DCHECK_EQ(image.DataSize(), VideoFrame::AllocationSize(format, image_size));
// Create planes for layout. We cannot use WrapExternalData() because it // Create planes for layout. We cannot use WrapExternalData() because it
// calls GetDefaultLayout() and it supports only a few pixel formats. // calls GetDefaultLayout() and it supports only a few pixel formats.
base::Optional<VideoFrameLayout> layout = base::Optional<VideoFrameLayout> layout =
CreateVideoFrameLayout(format, visible_size); CreateVideoFrameLayout(format, image_size);
if (!layout) { if (!layout) {
LOG(ERROR) << "Failed to create VideoFrameLayout"; LOG(ERROR) << "Failed to create VideoFrameLayout";
return nullptr; return nullptr;
...@@ -333,8 +333,8 @@ scoped_refptr<const VideoFrame> CreateVideoFrameFromImage(const Image& image) { ...@@ -333,8 +333,8 @@ scoped_refptr<const VideoFrame> CreateVideoFrameFromImage(const Image& image) {
scoped_refptr<const VideoFrame> video_frame = scoped_refptr<const VideoFrame> video_frame =
VideoFrame::WrapExternalDataWithLayout( VideoFrame::WrapExternalDataWithLayout(
*layout, gfx::Rect(visible_size), visible_size, image.Data(), *layout, image.VisibleRect(), image.VisibleRect().size(),
image.DataSize(), base::TimeDelta()); image.Data(), image.DataSize(), base::TimeDelta());
if (!video_frame) { if (!video_frame) {
LOG(ERROR) << "Failed to create VideoFrame"; LOG(ERROR) << "Failed to create VideoFrame";
return nullptr; return nullptr;
......
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