Commit e1d1f67d authored by Dean Liao's avatar Dean Liao Committed by Commit Bot

media/gpu: Use VideoFrameLayout in V4L2ImageProcessor.

Use VideoFrameLayout to store negotiated input/output format,
coded_size and buffer layout obtained from S_FMT command.

BUG=b:110815424,b:73752373
TEST=Run VEA VDA unittest on devices (peach_pit and elm)
VEA:
video_encode_accelerator_unittest \
--test_stream_data=bear-320x180.yuv:320:180:1:bear.mp4:100000:30 \
--disable_flush --single-process-tests -v=0

VDA:
video_decode_accelerator_unittest \
--test_stream_data=/usr/local/video/test-25fps.h264:320:240:250:258:\
35:150:1 -v=0 --disable_flush --single-process-tests --ozone-platform=gbm

Change-Id: If708cb66c5f33cb16ad8599339999a3aac9fcd47
Reviewed-on: https://chromium-review.googlesource.com/c/1340440
Commit-Queue: Shuo-Peng Liao <deanliao@google.com>
Reviewed-by: default avatarAlexandre Courbot <acourbot@chromium.org>
Reviewed-by: default avatarHirokazu Honda <hiroh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609211}
parent 3efc758c
This diff is collapsed.
...@@ -18,8 +18,7 @@ ...@@ -18,8 +18,7 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
#include "media/base/video_frame.h" #include "media/base/video_frame_layout.h"
#include "media/base/video_types.h"
#include "media/gpu/image_processor.h" #include "media/gpu/image_processor.h"
#include "media/gpu/media_gpu_export.h" #include "media/gpu/media_gpu_export.h"
#include "media/gpu/v4l2/v4l2_device.h" #include "media/gpu/v4l2/v4l2_device.h"
...@@ -69,12 +68,10 @@ class MEDIA_GPU_EXPORT V4L2ImageProcessor : public ImageProcessor { ...@@ -69,12 +68,10 @@ class MEDIA_GPU_EXPORT V4L2ImageProcessor : public ImageProcessor {
scoped_refptr<V4L2Device> device, scoped_refptr<V4L2Device> device,
v4l2_memory input_memory_type, v4l2_memory input_memory_type,
v4l2_memory output_memory_type, v4l2_memory output_memory_type,
VideoPixelFormat input_format, const VideoFrameLayout& input_layout,
VideoPixelFormat output_format, const VideoFrameLayout& output_layout,
gfx::Size input_visible_size, gfx::Size input_visible_size,
gfx::Size input_allocated_size,
gfx::Size output_visible_size, gfx::Size output_visible_size,
gfx::Size output_allocated_size,
size_t num_buffers, size_t num_buffers,
const base::Closure& error_cb); const base::Closure& error_cb);
...@@ -118,14 +115,10 @@ class MEDIA_GPU_EXPORT V4L2ImageProcessor : public ImageProcessor { ...@@ -118,14 +115,10 @@ class MEDIA_GPU_EXPORT V4L2ImageProcessor : public ImageProcessor {
V4L2ImageProcessor(scoped_refptr<V4L2Device> device, V4L2ImageProcessor(scoped_refptr<V4L2Device> device,
v4l2_memory input_memory_type, v4l2_memory input_memory_type,
v4l2_memory output_memory_type, v4l2_memory output_memory_type,
VideoPixelFormat input_format, const VideoFrameLayout& input_layout,
VideoPixelFormat output_format, const VideoFrameLayout& output_layout,
gfx::Size input_visible_size, gfx::Size input_visible_size,
gfx::Size input_allocated_size,
gfx::Size output_visible_size, gfx::Size output_visible_size,
gfx::Size output_allocated_size,
size_t input_planes_count,
size_t output_planes_count,
size_t num_buffers, size_t num_buffers,
const base::Closure& error_cb); const base::Closure& error_cb);
...@@ -160,23 +153,16 @@ class MEDIA_GPU_EXPORT V4L2ImageProcessor : public ImageProcessor { ...@@ -160,23 +153,16 @@ class MEDIA_GPU_EXPORT V4L2ImageProcessor : public ImageProcessor {
// callbacks will be invoked. // callbacks will be invoked.
void Destroy(); void Destroy();
// Size and format-related members remain constant after initialization. // Stores input frame's format, coded_size, buffer and plane layout.
// The visible/allocated sizes of the input frame. const VideoFrameLayout input_layout_;
const gfx::Size input_visible_size_; const gfx::Size input_visible_size_;
const gfx::Size input_allocated_size_; const v4l2_memory input_memory_type_;
// The visible/allocated sizes of the destination frame. // Stores input frame's format, coded_size, buffer and plane layout.
const VideoFrameLayout output_layout_;
const gfx::Size output_visible_size_; const gfx::Size output_visible_size_;
const gfx::Size output_allocated_size_;
const VideoPixelFormat input_format_;
const VideoPixelFormat output_format_;
const v4l2_memory input_memory_type_;
const v4l2_memory output_memory_type_; const v4l2_memory output_memory_type_;
const size_t input_planes_count_;
const size_t output_planes_count_;
// Our original calling task runner for the child thread. // Our original calling task runner for the child thread.
const scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_; const scoped_refptr<base::SingleThreadTaskRunner> child_task_runner_;
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "media/base/media_switches.h" #include "media/base/media_switches.h"
#include "media/base/scopedfd_helper.h" #include "media/base/scopedfd_helper.h"
#include "media/base/unaligned_shared_memory.h" #include "media/base/unaligned_shared_memory.h"
#include "media/base/video_frame_layout.h"
#include "media/base/video_types.h" #include "media/base/video_types.h"
#include "media/gpu/v4l2/v4l2_image_processor.h" #include "media/gpu/v4l2/v4l2_image_processor.h"
#include "media/video/h264_parser.h" #include "media/video/h264_parser.h"
...@@ -2357,13 +2358,26 @@ bool V4L2VideoDecodeAccelerator::CreateImageProcessor() { ...@@ -2357,13 +2358,26 @@ bool V4L2VideoDecodeAccelerator::CreateImageProcessor() {
(output_mode_ == Config::OutputMode::ALLOCATE ? V4L2_MEMORY_MMAP (output_mode_ == Config::OutputMode::ALLOCATE ? V4L2_MEMORY_MMAP
: V4L2_MEMORY_DMABUF); : V4L2_MEMORY_DMABUF);
auto input_layout = VideoFrameLayout::Create(
V4L2Device::V4L2PixFmtToVideoPixelFormat(output_format_fourcc_),
coded_size_);
if (!input_layout) {
VLOGF(1) << "Invalid input layout";
return false;
}
auto output_layout = VideoFrameLayout::Create(
V4L2Device::V4L2PixFmtToVideoPixelFormat(egl_image_format_fourcc_),
egl_image_size_);
if (!output_layout) {
VLOGF(1) << "Invalid output layout";
return false;
}
// Unretained is safe because |this| owns image processor and there will be // Unretained is safe because |this| owns image processor and there will be
// no callbacks after processor destroys. // no callbacks after processor destroys.
image_processor_ = V4L2ImageProcessor::Create( image_processor_ = V4L2ImageProcessor::Create(
image_processor_device_, input_memory_type, output_memory_type, image_processor_device_, input_memory_type, output_memory_type,
V4L2Device::V4L2PixFmtToVideoPixelFormat(output_format_fourcc_), *input_layout, *output_layout, visible_size_, visible_size_,
V4L2Device::V4L2PixFmtToVideoPixelFormat(egl_image_format_fourcc_),
visible_size_, coded_size_, visible_size_, egl_image_size_,
output_buffer_map_.size(), output_buffer_map_.size(),
base::Bind(&V4L2VideoDecodeAccelerator::ImageProcessorError, base::Bind(&V4L2VideoDecodeAccelerator::ImageProcessorError,
base::Unretained(this))); base::Unretained(this)));
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "media/base/scopedfd_helper.h" #include "media/base/scopedfd_helper.h"
#include "media/base/unaligned_shared_memory.h" #include "media/base/unaligned_shared_memory.h"
#include "media/base/video_types.h" #include "media/base/video_types.h"
#include "media/base/video_frame_layout.h"
#include "media/gpu/gpu_video_encode_accelerator_helpers.h" #include "media/gpu/gpu_video_encode_accelerator_helpers.h"
#include "media/gpu/v4l2/v4l2_image_processor.h" #include "media/gpu/v4l2/v4l2_image_processor.h"
#include "media/video/h264_parser.h" #include "media/video/h264_parser.h"
...@@ -209,19 +210,34 @@ bool V4L2VideoEncodeAccelerator::Initialize(const Config& config, ...@@ -209,19 +210,34 @@ bool V4L2VideoEncodeAccelerator::Initialize(const Config& config,
return false; return false;
} }
auto input_layout = VideoFrameLayout::Create(
V4L2Device::V4L2PixFmtToVideoPixelFormat(config.input_format),
visible_size_);
if (!input_layout) {
VLOGF(1) << "Invalid image processor input layout";
return false;
}
auto output_layout = VideoFrameLayout::Create(
V4L2Device::V4L2PixFmtToVideoPixelFormat(device_input_format_),
input_allocated_size_);
if (!output_layout) {
VLOGF(1) << "Invalid image processor output layout";
return false;
}
// Convert from |config.input_format| to |device_input_format_|, keeping the // Convert from |config.input_format| to |device_input_format_|, keeping the
// size at |visible_size_| and requiring the output buffers to be of at // size at |visible_size_| and requiring the output buffers to be of at
// least |input_allocated_size_|. Unretained is safe because |this| owns // least |input_allocated_size_|. Unretained is safe because |this| owns
// image processor and there will be no callbacks after processor destroys. // image processor and there will be no callbacks after processor destroys.
image_processor_ = V4L2ImageProcessor::Create( image_processor_ = V4L2ImageProcessor::Create(
V4L2Device::Create(), V4L2_MEMORY_USERPTR, V4L2_MEMORY_MMAP, V4L2Device::Create(), V4L2_MEMORY_USERPTR, V4L2_MEMORY_MMAP,
config.input_format, device_input_format_, visible_size_, visible_size_, *input_layout, *output_layout, visible_size_, visible_size_,
visible_size_, input_allocated_size_, kImageProcBufferCount, kImageProcBufferCount,
base::Bind(&V4L2VideoEncodeAccelerator::ImageProcessorError, base::Bind(&V4L2VideoEncodeAccelerator::ImageProcessorError,
base::Unretained(this))); base::Unretained(this)));
if (!image_processor_) { if (!image_processor_) {
VLOGF(1) << "Failed initializing image processor"; VLOGF(1) << "Failed initializing image processor";
return false; return false;
} }
// The output of image processor is the input of encoder. Output coded // The output of image processor is the input of encoder. Output coded
// width of processor must be the same as input coded width of encoder. // width of processor must be the same as input coded width of encoder.
......
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