| Index: media/gpu/v4l2_video_encode_accelerator.cc
|
| diff --git a/media/gpu/v4l2_video_encode_accelerator.cc b/media/gpu/v4l2_video_encode_accelerator.cc
|
| index 7312a237cda640775801d4c12f60a17eff3ec9e4..4ba1ffc144b8db0c8a2ea2229af8cdd4b2551edb 100644
|
| --- a/media/gpu/v4l2_video_encode_accelerator.cc
|
| +++ b/media/gpu/v4l2_video_encode_accelerator.cc
|
| @@ -14,6 +14,7 @@
|
|
|
| #include <utility>
|
|
|
| +#include "base/bits.h"
|
| #include "base/callback.h"
|
| #include "base/command_line.h"
|
| #include "base/macros.h"
|
| @@ -202,7 +203,7 @@ bool V4L2VideoEncodeAccelerator::Initialize(VideoPixelFormat input_format,
|
| if (!image_processor_->Initialize(
|
| input_format, device_input_format_, V4L2_MEMORY_USERPTR,
|
| V4L2_MEMORY_MMAP, visible_size_, visible_size_, visible_size_,
|
| - input_allocated_size_, kImageProcBufferCount,
|
| + input_coded_size_, kImageProcBufferCount,
|
| base::Bind(&V4L2VideoEncodeAccelerator::ImageProcessorError,
|
| base::Unretained(this)))) {
|
| LOG(ERROR) << "Failed initializing image processor";
|
| @@ -214,13 +215,13 @@ bool V4L2VideoEncodeAccelerator::Initialize(VideoPixelFormat input_format,
|
| // input coded height of encoder. For example, suppose input size of encoder
|
| // is 320x193. It is OK if the output of processor is 320x208.
|
| if (image_processor_->output_allocated_size().width() !=
|
| - input_allocated_size_.width() ||
|
| + input_coded_size_.width() ||
|
| image_processor_->output_allocated_size().height() <
|
| - input_allocated_size_.height()) {
|
| + input_coded_size_.height()) {
|
| LOG(ERROR) << "Invalid image processor output coded size "
|
| << image_processor_->output_allocated_size().ToString()
|
| << ", encode input coded size is "
|
| - << input_allocated_size_.ToString();
|
| + << input_coded_size_.ToString();
|
| return false;
|
| }
|
|
|
| @@ -755,12 +756,13 @@ bool V4L2VideoEncodeAccelerator::EnqueueInputRecord() {
|
| DCHECK_EQ(device_input_format_, frame->format());
|
| for (size_t i = 0; i < input_planes_count_; ++i) {
|
| qbuf.m.planes[i].bytesused = base::checked_cast<__u32>(
|
| - VideoFrame::PlaneSize(frame->format(), i, input_allocated_size_)
|
| - .GetArea());
|
| + VideoFrame::PlaneSize(frame->format(), i, input_coded_size_).GetArea());
|
|
|
| switch (input_memory_type_) {
|
| case V4L2_MEMORY_USERPTR:
|
| - qbuf.m.planes[i].length = qbuf.m.planes[i].bytesused;
|
| + qbuf.m.planes[i].length = base::checked_cast<__u32>(
|
| + VideoFrame::PlaneSize(frame->format(), i, input_allocated_size_)
|
| + .GetArea());
|
| qbuf.m.planes[i].m.userptr =
|
| reinterpret_cast<unsigned long>(frame->data(i));
|
| DCHECK(qbuf.m.planes[i].m.userptr);
|
| @@ -1056,13 +1058,26 @@ bool V4L2VideoEncodeAccelerator::NegotiateInputFormat(
|
|
|
| // Take device-adjusted sizes for allocated size. If the size is adjusted
|
| // down, it means the input is too big and the hardware does not support it.
|
| - input_allocated_size_ = V4L2Device::CodedSizeFromV4L2Format(format);
|
| - if (!gfx::Rect(input_allocated_size_).Contains(gfx::Rect(visible_size_))) {
|
| + input_coded_size_ = V4L2Device::CodedSizeFromV4L2Format(format);
|
| + if (!gfx::Rect(input_coded_size_).Contains(gfx::Rect(visible_size_))) {
|
| DVLOG(1) << "Input size too big " << visible_size_.ToString()
|
| - << ", adjusted to " << input_allocated_size_.ToString();
|
| + << ", adjusted to " << input_coded_size_.ToString();
|
| return false;
|
| }
|
|
|
| + // Make sure the size of each plane is multiple of 128. If the width is
|
| + // multiple of 16 and the height is multiple of 32, U or V plane size will
|
| + // be multiple of 16 * 32 / 4 = 128.
|
| + if (input_coded_size_.width() % 16 != 0) {
|
| + LOG(ERROR) << "Input coded width is not multiple of 16";
|
| + return false;
|
| + }
|
| + input_allocated_size_.set_width(input_coded_size_.width());
|
| + input_allocated_size_.set_height(
|
| + base::bits::Align(input_coded_size_.height(), 32));
|
| + DVLOG(1) << "Input coded size=" << input_coded_size_.ToString()
|
| + << ", input allocated size=" << input_allocated_size_.ToString();
|
| +
|
| device_input_format_ = input_format;
|
| input_planes_count_ = input_planes_count;
|
| return true;
|
|
|