Commit 0b904222 authored by Hirokazu Honda's avatar Hirokazu Honda Committed by Commit Bot

media/gpu/v4l2IP: Factorize code to allocate v4l2 buffers

Bug: 1033799
Test: ip_test on kukui
Test: appr.tc on kukui
Change-Id: I9378d91c2bc97edb5a49aa54612d01923ab29177
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2102368Reviewed-by: default avatarAlexandre Courbot <acourbot@chromium.org>
Commit-Queue: Hirokazu Honda <hiroh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751225}
parent d1d3a42a
...@@ -97,6 +97,22 @@ struct v4l2_rect ToV4L2Rect(const gfx::Rect& visible_rect) { ...@@ -97,6 +97,22 @@ struct v4l2_rect ToV4L2Rect(const gfx::Rect& visible_rect) {
return rect; return rect;
} }
bool AllocateV4L2Buffers(V4L2Queue* queue,
size_t num_buffers,
v4l2_memory memory_type) {
DCHECK(queue);
if (queue->AllocateBuffers(num_buffers, memory_type) == 0u)
return false;
if (queue->AllocatedBuffersCount() != num_buffers) {
VLOGF(1) << "Failed to allocate buffers. Allocated number="
<< queue->AllocatedBuffersCount()
<< ", Requested number=" << num_buffers;
return false;
}
return true;
}
} // namespace } // namespace
V4L2ImageProcessorBackend::JobRecord::JobRecord() V4L2ImageProcessorBackend::JobRecord::JobRecord()
...@@ -626,20 +642,8 @@ bool V4L2ImageProcessorBackend::CreateInputBuffers() { ...@@ -626,20 +642,8 @@ bool V4L2ImageProcessorBackend::CreateInputBuffers() {
} }
input_queue_ = device_->GetQueue(V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE); input_queue_ = device_->GetQueue(V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE);
if (!input_queue_) return input_queue_ && AllocateV4L2Buffers(input_queue_.get(), num_buffers_,
return false; input_memory_type_);
if (input_queue_->AllocateBuffers(num_buffers_, input_memory_type_) == 0u)
return false;
if (input_queue_->AllocatedBuffersCount() != num_buffers_) {
VLOGF(1) << "Failed to allocate the required number of input buffers. "
<< "Requested " << num_buffers_ << ", got "
<< input_queue_->AllocatedBuffersCount() << ".";
return false;
}
return true;
} }
bool V4L2ImageProcessorBackend::CreateOutputBuffers() { bool V4L2ImageProcessorBackend::CreateOutputBuffers() {
...@@ -648,11 +652,6 @@ bool V4L2ImageProcessorBackend::CreateOutputBuffers() { ...@@ -648,11 +652,6 @@ bool V4L2ImageProcessorBackend::CreateOutputBuffers() {
DCHECK_EQ(output_queue_, nullptr); DCHECK_EQ(output_queue_, nullptr);
struct v4l2_rect visible_rect = ToV4L2Rect(output_config_.visible_rect); struct v4l2_rect visible_rect = ToV4L2Rect(output_config_.visible_rect);
output_queue_ = device_->GetQueue(V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
if (!output_queue_)
return false;
struct v4l2_selection selection_arg; struct v4l2_selection selection_arg;
memset(&selection_arg, 0, sizeof(selection_arg)); memset(&selection_arg, 0, sizeof(selection_arg));
selection_arg.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; selection_arg.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
...@@ -667,17 +666,9 @@ bool V4L2ImageProcessorBackend::CreateOutputBuffers() { ...@@ -667,17 +666,9 @@ bool V4L2ImageProcessorBackend::CreateOutputBuffers() {
IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_S_CROP, &crop); IOCTL_OR_ERROR_RETURN_FALSE(VIDIOC_S_CROP, &crop);
} }
if (output_queue_->AllocateBuffers(num_buffers_, output_memory_type_) == 0) output_queue_ = device_->GetQueue(V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
return false; return output_queue_ && AllocateV4L2Buffers(output_queue_.get(), num_buffers_,
output_memory_type_);
if (output_queue_->AllocatedBuffersCount() != num_buffers_) {
VLOGF(1) << "Failed to allocate output buffers. Allocated number="
<< output_queue_->AllocatedBuffersCount()
<< ", Requested number=" << num_buffers_;
return false;
}
return true;
} }
void V4L2ImageProcessorBackend::DevicePollTask(bool poll_device) { void V4L2ImageProcessorBackend::DevicePollTask(bool poll_device) {
......
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