Commit 414e7336 authored by Alexandre Courbot's avatar Alexandre Courbot Committed by Commit Bot

media/gpu/v4l2vea: allocate as many buffers as possible in DMABUF mode

If we are operating in DMABUF mode, then we will try to keep the same
frame assigned to the same V4L2 buffer. However we don't know in advance
how many different frames the encoder will use, only that it is probably
larger than the default 2 we are currently allocating. If we undershoot
then we will spend a lot of time in-kernel unmapping/remapping DMABUFs.

Try to prevent this by allocating as many buffers as allowed by the V4L2
API (32) when operating in DMABUF mode. Since these buffers won't have
backing memory unless we attach a DMABUF to them, they are virtually
free if unused.

BUG=b:159688625
BUG=b:167412992
TEST=video.EncodeAccel.h264_360p_i420 passes on Kukui.

Change-Id: Ia24a6bd8574f5d3894237ca0e563ea4cbff3a631
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2415911
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: default avatarFritz Koenig <frkoenig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813545}
parent c2c02d5b
...@@ -1769,7 +1769,22 @@ bool V4L2VideoEncodeAccelerator::CreateInputBuffers() { ...@@ -1769,7 +1769,22 @@ bool V4L2VideoEncodeAccelerator::CreateInputBuffers() {
DCHECK_CALLED_ON_VALID_SEQUENCE(encoder_sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(encoder_sequence_checker_);
DCHECK(!input_queue_->IsStreaming()); DCHECK(!input_queue_->IsStreaming());
if (input_queue_->AllocateBuffers(kInputBufferCount, input_memory_type_) < // If using DMABUF input, we want to reuse the same V4L2 buffer index
// for the same input buffer as much as possible. But we don't know in advance
// how many different input buffers we will get. Therefore we allocate as
// many V4L2 buffers as possible (VIDEO_MAX_FRAME == 32). Unused indexes
// won't have a tangible cost since they don't have backing memory.
size_t num_buffers;
switch (input_memory_type_) {
case V4L2_MEMORY_DMABUF:
num_buffers = VIDEO_MAX_FRAME;
break;
default:
num_buffers = kInputBufferCount;
break;
}
if (input_queue_->AllocateBuffers(num_buffers, input_memory_type_) <
kInputBufferCount) { kInputBufferCount) {
VLOGF(1) << "Failed to allocate V4L2 input buffers."; VLOGF(1) << "Failed to allocate V4L2 input buffers.";
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