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

media/gpu: Change visible size to visible rect in ImageProcessor config

It is necessary to configure an image processor with a visible
rectangle if the image processor will crop a given frame.

Bug: 1034415
Test: vda_tests w/wo --use_vd and IP test
Change-Id: I701cc4cf1c31bc69c59efc856f9ded6dc60248d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1980519
Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: default avatarChih-Yu Huang <akahuang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#727445}
parent 4f9161f2
...@@ -40,22 +40,22 @@ ImageProcessorBackend::PortConfig::PortConfig( ...@@ -40,22 +40,22 @@ ImageProcessorBackend::PortConfig::PortConfig(
Fourcc fourcc, Fourcc fourcc,
const gfx::Size& size, const gfx::Size& size,
const std::vector<ColorPlaneLayout>& planes, const std::vector<ColorPlaneLayout>& planes,
const gfx::Size& visible_size, const gfx::Rect& visible_rect,
const std::vector<VideoFrame::StorageType>& preferred_storage_types) const std::vector<VideoFrame::StorageType>& preferred_storage_types)
: fourcc(fourcc), : fourcc(fourcc),
size(size), size(size),
planes(planes), planes(planes),
visible_size(visible_size), visible_rect(visible_rect),
preferred_storage_types(preferred_storage_types) {} preferred_storage_types(preferred_storage_types) {}
ImageProcessorBackend::PortConfig::~PortConfig() = default; ImageProcessorBackend::PortConfig::~PortConfig() = default;
std::string ImageProcessorBackend::PortConfig::ToString() const { std::string ImageProcessorBackend::PortConfig::ToString() const {
return base::StringPrintf( return base::StringPrintf(
"PortConfig(format:%s, size:%s, planes: %s, visible_size:%s, " "PortConfig(format:%s, size:%s, planes: %s, visible_rect:%s, "
"storage_types:%s)", "storage_types:%s)",
fourcc.ToString().c_str(), size.ToString().c_str(), fourcc.ToString().c_str(), size.ToString().c_str(),
VectorToString(planes).c_str(), visible_size.ToString().c_str(), VectorToString(planes).c_str(), visible_rect.ToString().c_str(),
VectorToString(preferred_storage_types).c_str()); VectorToString(preferred_storage_types).c_str());
} }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "media/base/video_frame.h" #include "media/base/video_frame.h"
#include "media/gpu/chromeos/fourcc.h" #include "media/gpu/chromeos/fourcc.h"
#include "media/gpu/media_gpu_export.h" #include "media/gpu/media_gpu_export.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
namespace media { namespace media {
...@@ -49,7 +50,7 @@ class MEDIA_GPU_EXPORT ImageProcessorBackend { ...@@ -49,7 +50,7 @@ class MEDIA_GPU_EXPORT ImageProcessorBackend {
Fourcc fourcc, Fourcc fourcc,
const gfx::Size& size, const gfx::Size& size,
const std::vector<ColorPlaneLayout>& planes, const std::vector<ColorPlaneLayout>& planes,
const gfx::Size& visible_size, const gfx::Rect& visible_rect,
const std::vector<VideoFrame::StorageType>& preferred_storage_types); const std::vector<VideoFrame::StorageType>& preferred_storage_types);
~PortConfig(); ~PortConfig();
...@@ -63,7 +64,7 @@ class MEDIA_GPU_EXPORT ImageProcessorBackend { ...@@ -63,7 +64,7 @@ class MEDIA_GPU_EXPORT ImageProcessorBackend {
// Output human readable string of PortConfig. // Output human readable string of PortConfig.
// Example: // Example:
// PortConfig(format::NV12, size:640x480, planes:[(640, 0, 307200), // PortConfig(format::NV12, size:640x480, planes:[(640, 0, 307200),
// (640,0,153600)], visible_size:640x480, storage_types:[DMABUFS]) // (640,0,153600)], visible_rect:0, 0, 640x480, storage_types:[DMABUFS])
std::string ToString() const; std::string ToString() const;
// Video frame format represented as fourcc type. // Video frame format represented as fourcc type.
...@@ -77,7 +78,7 @@ class MEDIA_GPU_EXPORT ImageProcessorBackend { ...@@ -77,7 +78,7 @@ class MEDIA_GPU_EXPORT ImageProcessorBackend {
// Layout property (stride, offset, size of bytes) for each color plane. // Layout property (stride, offset, size of bytes) for each color plane.
const std::vector<ColorPlaneLayout> planes; const std::vector<ColorPlaneLayout> planes;
const gfx::Size visible_size; const gfx::Rect visible_rect;
// List of preferred storage types. // List of preferred storage types.
const std::vector<VideoFrame::StorageType> preferred_storage_types; const std::vector<VideoFrame::StorageType> preferred_storage_types;
}; };
......
...@@ -107,10 +107,10 @@ class ImageProcessorParamTest ...@@ -107,10 +107,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(),
input_image.Size(), input_storage_types); gfx::Rect(input_image.Size()), 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(),
output_image->Size(), output_storage_types); gfx::Rect(output_image->Size()), 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());
......
...@@ -19,8 +19,7 @@ std::unique_ptr<ImageProcessorWithPool> ImageProcessorWithPool::Create( ...@@ -19,8 +19,7 @@ std::unique_ptr<ImageProcessorWithPool> ImageProcessorWithPool::Create(
const scoped_refptr<base::SequencedTaskRunner> task_runner) { const scoped_refptr<base::SequencedTaskRunner> task_runner) {
const ImageProcessor::PortConfig& config = image_processor->output_config(); const ImageProcessor::PortConfig& config = image_processor->output_config();
base::Optional<GpuBufferLayout> layout = frame_pool->RequestFrames( base::Optional<GpuBufferLayout> layout = frame_pool->RequestFrames(
config.fourcc, config.size, gfx::Rect(config.visible_size), config.size, config.fourcc, config.size, config.visible_rect, config.size, num_frames);
num_frames);
if (!layout || layout->size() != config.size) { if (!layout || layout->size() != config.size) {
VLOGF(1) << "Failed to request frame with correct size. " VLOGF(1) << "Failed to request frame with correct size. "
<< config.size.ToString() << " != " << config.size.ToString() << " != "
......
...@@ -116,10 +116,10 @@ std::unique_ptr<ImageProcessorBackend> LibYUVImageProcessorBackend::Create( ...@@ -116,10 +116,10 @@ std::unique_ptr<ImageProcessorBackend> LibYUVImageProcessorBackend::Create(
scoped_refptr<VideoFrame> intermediate_frame; scoped_refptr<VideoFrame> intermediate_frame;
if (res == SupportResult::SupportedWithPivot) { if (res == SupportResult::SupportedWithPivot) {
intermediate_frame = intermediate_frame = VideoFrame::CreateFrame(
VideoFrame::CreateFrame(PIXEL_FORMAT_I420, input_config.visible_size, PIXEL_FORMAT_I420, input_config.visible_rect.size(),
gfx::Rect(input_config.visible_size), input_config.visible_rect, input_config.visible_rect.size(),
input_config.visible_size, base::TimeDelta()); base::TimeDelta());
if (!intermediate_frame) { if (!intermediate_frame) {
VLOGF(1) << "Failed to create intermediate frame"; VLOGF(1) << "Failed to create intermediate frame";
return nullptr; return nullptr;
...@@ -130,10 +130,10 @@ std::unique_ptr<ImageProcessorBackend> LibYUVImageProcessorBackend::Create( ...@@ -130,10 +130,10 @@ std::unique_ptr<ImageProcessorBackend> LibYUVImageProcessorBackend::Create(
base::WrapUnique<ImageProcessorBackend>(new LibYUVImageProcessorBackend( base::WrapUnique<ImageProcessorBackend>(new LibYUVImageProcessorBackend(
std::move(video_frame_mapper), std::move(intermediate_frame), std::move(video_frame_mapper), std::move(intermediate_frame),
PortConfig(input_config.fourcc, input_config.size, PortConfig(input_config.fourcc, input_config.size,
input_config.planes, input_config.visible_size, input_config.planes, input_config.visible_rect,
{input_storage_type}), {input_storage_type}),
PortConfig(output_config.fourcc, output_config.size, PortConfig(output_config.fourcc, output_config.size,
output_config.planes, output_config.visible_size, output_config.planes, output_config.visible_rect,
{output_storage_type}), {output_storage_type}),
OutputMode::IMPORT, std::move(error_cb), OutputMode::IMPORT, std::move(error_cb),
std::move(backend_task_runner))); std::move(backend_task_runner)));
......
...@@ -87,6 +87,15 @@ void FillV4L2BufferByGpuMemoryBufferHandle( ...@@ -87,6 +87,15 @@ void FillV4L2BufferByGpuMemoryBufferHandle(
} }
} }
struct v4l2_rect ToV4L2Rect(const gfx::Rect& visible_rect) {
struct v4l2_rect rect;
rect.left = base::checked_cast<__u32>(visible_rect.x());
rect.top = base::checked_cast<__u32>(visible_rect.y());
rect.width = base::checked_cast<__u32>(visible_rect.width());
rect.height = base::checked_cast<__u32>(visible_rect.height());
return rect;
}
} // namespace } // namespace
V4L2ImageProcessorBackend::JobRecord::JobRecord() V4L2ImageProcessorBackend::JobRecord::JobRecord()
...@@ -305,12 +314,11 @@ V4L2ImageProcessorBackend::CreateWithOutputMode( ...@@ -305,12 +314,11 @@ V4L2ImageProcessorBackend::CreateWithOutputMode(
const v4l2_pix_format_mplane& pix_mp = format.fmt.pix_mp; const v4l2_pix_format_mplane& pix_mp = format.fmt.pix_mp;
const gfx::Size negotiated_input_size(pix_mp.width, pix_mp.height); const gfx::Size negotiated_input_size(pix_mp.width, pix_mp.height);
if (!gfx::Rect(negotiated_input_size) if (!gfx::Rect(negotiated_input_size).Contains(input_config.visible_rect)) {
.Contains(gfx::Rect(input_config.visible_size))) {
VLOGF(1) << "Negotiated input allocated size: " VLOGF(1) << "Negotiated input allocated size: "
<< negotiated_input_size.ToString() << negotiated_input_size.ToString()
<< " should contain visible size: " << " should contain visible size: "
<< input_config.visible_size.ToString(); << input_config.visible_rect.size().ToString();
return nullptr; return nullptr;
} }
std::vector<ColorPlaneLayout> input_planes(pix_mp.num_planes); std::vector<ColorPlaneLayout> input_planes(pix_mp.num_planes);
...@@ -362,9 +370,9 @@ V4L2ImageProcessorBackend::CreateWithOutputMode( ...@@ -362,9 +370,9 @@ V4L2ImageProcessorBackend::CreateWithOutputMode(
new V4L2ImageProcessorBackend( new V4L2ImageProcessorBackend(
backend_task_runner, std::move(device), backend_task_runner, std::move(device),
PortConfig(input_config.fourcc, negotiated_input_size, input_planes, PortConfig(input_config.fourcc, negotiated_input_size, input_planes,
input_config.visible_size, {input_storage_type}), input_config.visible_rect, {input_storage_type}),
PortConfig(output_config.fourcc, negotiated_output_size, PortConfig(output_config.fourcc, negotiated_output_size,
output_planes, output_config.visible_size, output_planes, output_config.visible_rect,
{output_storage_type}), {output_storage_type}),
input_memory_type, output_memory_type, output_mode, num_buffers, input_memory_type, output_memory_type, output_mode, num_buffers,
std::move(error_cb))); std::move(error_cb)));
...@@ -592,13 +600,7 @@ bool V4L2ImageProcessorBackend::CreateInputBuffers() { ...@@ -592,13 +600,7 @@ bool V4L2ImageProcessorBackend::CreateInputBuffers() {
if (device_->Ioctl(VIDIOC_S_CTRL, &control) != 0) if (device_->Ioctl(VIDIOC_S_CTRL, &control) != 0)
DVLOGF(4) << "V4L2_CID_ALPHA_COMPONENT is not supported"; DVLOGF(4) << "V4L2_CID_ALPHA_COMPONENT is not supported";
struct v4l2_rect visible_rect; struct v4l2_rect visible_rect = ToV4L2Rect(input_config_.visible_rect);
visible_rect.left = 0;
visible_rect.top = 0;
visible_rect.width =
base::checked_cast<__u32>(input_config_.visible_size.width());
visible_rect.height =
base::checked_cast<__u32>(input_config_.visible_size.height());
struct v4l2_selection selection_arg; struct v4l2_selection selection_arg;
memset(&selection_arg, 0, sizeof(selection_arg)); memset(&selection_arg, 0, sizeof(selection_arg));
...@@ -636,13 +638,7 @@ bool V4L2ImageProcessorBackend::CreateOutputBuffers() { ...@@ -636,13 +638,7 @@ bool V4L2ImageProcessorBackend::CreateOutputBuffers() {
DCHECK_CALLED_ON_VALID_SEQUENCE(backend_sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(backend_sequence_checker_);
DCHECK_EQ(output_queue_, nullptr); DCHECK_EQ(output_queue_, nullptr);
struct v4l2_rect visible_rect; struct v4l2_rect visible_rect = ToV4L2Rect(output_config_.visible_rect);
visible_rect.left = 0;
visible_rect.top = 0;
visible_rect.width =
base::checked_cast<__u32>(output_config_.visible_size.width());
visible_rect.height =
base::checked_cast<__u32>(output_config_.visible_size.height());
output_queue_ = device_->GetQueue(V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); output_queue_ = device_->GetQueue(V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
if (!output_queue_) if (!output_queue_)
......
...@@ -79,9 +79,11 @@ std::unique_ptr<ImageProcessor> CreateImageProcessor( ...@@ -79,9 +79,11 @@ std::unique_ptr<ImageProcessor> CreateImageProcessor(
base::BindRepeating(&V4L2ImageProcessorBackend::Create, base::BindRepeating(&V4L2ImageProcessorBackend::Create,
image_processor_device, nb_buffers), image_processor_device, nb_buffers),
ImageProcessor::PortConfig(vda_output_format, vda_output_coded_size, {}, ImageProcessor::PortConfig(vda_output_format, vda_output_coded_size, {},
visible_size, {VideoFrame::STORAGE_DMABUFS}), gfx::Rect(visible_size),
{VideoFrame::STORAGE_DMABUFS}),
ImageProcessor::PortConfig(ip_output_format, ip_output_coded_size, {}, ImageProcessor::PortConfig(ip_output_format, ip_output_coded_size, {},
visible_size, {VideoFrame::STORAGE_DMABUFS}), gfx::Rect(visible_size),
{VideoFrame::STORAGE_DMABUFS}),
{image_processor_output_mode}, std::move(error_cb), {image_processor_output_mode}, std::move(error_cb),
std::move(client_task_runner)); std::move(client_task_runner));
if (!image_processor) if (!image_processor)
......
...@@ -102,7 +102,7 @@ namespace { ...@@ -102,7 +102,7 @@ namespace {
// Convert VideoFrameLayout to ImageProcessor::PortConfig. // Convert VideoFrameLayout to ImageProcessor::PortConfig.
base::Optional<ImageProcessor::PortConfig> VideoFrameLayoutToPortConfig( base::Optional<ImageProcessor::PortConfig> VideoFrameLayoutToPortConfig(
const VideoFrameLayout& layout, const VideoFrameLayout& layout,
const gfx::Size& visible_size, const gfx::Rect& visible_rect,
const std::vector<VideoFrame::StorageType>& preferred_storage_types) { const std::vector<VideoFrame::StorageType>& preferred_storage_types) {
auto fourcc = auto fourcc =
Fourcc::FromVideoPixelFormat(layout.format(), !layout.is_multi_planar()); Fourcc::FromVideoPixelFormat(layout.format(), !layout.is_multi_planar());
...@@ -112,7 +112,7 @@ base::Optional<ImageProcessor::PortConfig> VideoFrameLayoutToPortConfig( ...@@ -112,7 +112,7 @@ base::Optional<ImageProcessor::PortConfig> VideoFrameLayoutToPortConfig(
return base::nullopt; return base::nullopt;
} }
return ImageProcessor::PortConfig(*fourcc, layout.coded_size(), return ImageProcessor::PortConfig(*fourcc, layout.coded_size(),
layout.planes(), visible_size, layout.planes(), visible_rect,
preferred_storage_types); preferred_storage_types);
} }
} // namespace } // namespace
...@@ -321,12 +321,13 @@ bool V4L2VideoEncodeAccelerator::CreateImageProcessor( ...@@ -321,12 +321,13 @@ bool V4L2VideoEncodeAccelerator::CreateImageProcessor(
// However, it doesn't matter VideoFrame::STORAGE_OWNED_MEMORY is specified // However, it doesn't matter VideoFrame::STORAGE_OWNED_MEMORY is specified
// for |input_storage_type| here, as long as VideoFrame on Process()'s data // for |input_storage_type| here, as long as VideoFrame on Process()'s data
// can be accessed by VideoFrame::data(). // can be accessed by VideoFrame::data().
auto input_config = VideoFrameLayoutToPortConfig( auto input_config =
input_layout, visible_size, {VideoFrame::STORAGE_OWNED_MEMORY}); VideoFrameLayoutToPortConfig(input_layout, gfx::Rect(visible_size),
{VideoFrame::STORAGE_OWNED_MEMORY});
if (!input_config) if (!input_config)
return false; return false;
auto output_config = VideoFrameLayoutToPortConfig( auto output_config = VideoFrameLayoutToPortConfig(
output_layout, visible_size, output_layout, gfx::Rect(visible_size),
{VideoFrame::STORAGE_DMABUFS, VideoFrame::STORAGE_OWNED_MEMORY}); {VideoFrame::STORAGE_DMABUFS, VideoFrame::STORAGE_OWNED_MEMORY});
if (!output_config) if (!output_config)
return false; return false;
......
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