summaryrefslogtreecommitdiff
path: root/chromium/media/gpu/v4l2/v4l2_image_processor_backend.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/media/gpu/v4l2/v4l2_image_processor_backend.cc')
-rw-r--r--chromium/media/gpu/v4l2/v4l2_image_processor_backend.cc53
1 files changed, 42 insertions, 11 deletions
diff --git a/chromium/media/gpu/v4l2/v4l2_image_processor_backend.cc b/chromium/media/gpu/v4l2/v4l2_image_processor_backend.cc
index b90b1c9a4ac..bbf7959e21a 100644
--- a/chromium/media/gpu/v4l2/v4l2_image_processor_backend.cc
+++ b/chromium/media/gpu/v4l2/v4l2_image_processor_backend.cc
@@ -1,4 +1,4 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -152,13 +152,17 @@ void V4L2ImageProcessorBackend::Destroy() {
backend_weak_this_factory_.InvalidateWeakPtrs();
if (input_queue_) {
- input_queue_->Streamoff();
- input_queue_->DeallocateBuffers();
+ if (!input_queue_->Streamoff())
+ VLOGF(1) << "Failed to turn stream off";
+ if (!input_queue_->DeallocateBuffers())
+ VLOGF(1) << "Failed to deallocate buffers";
input_queue_ = nullptr;
}
if (output_queue_) {
- output_queue_->Streamoff();
- output_queue_->DeallocateBuffers();
+ if (!output_queue_->Streamoff())
+ VLOGF(1) << "Failed to turn stream off";
+ if (!output_queue_->DeallocateBuffers())
+ VLOGF(1) << "Failed to deallocate buffers";
output_queue_ = nullptr;
}
@@ -205,7 +209,6 @@ v4l2_memory InputStorageTypeToV4L2Memory(VideoFrame::StorageType storage_type) {
case VideoFrame::STORAGE_OWNED_MEMORY:
case VideoFrame::STORAGE_UNOWNED_MEMORY:
case VideoFrame::STORAGE_SHMEM:
- case VideoFrame::STORAGE_MOJO_SHARED_BUFFER:
return V4L2_MEMORY_USERPTR;
case VideoFrame::STORAGE_DMABUFS:
case VideoFrame::STORAGE_GPU_MEMORY_BUFFER:
@@ -921,18 +924,41 @@ bool V4L2ImageProcessorBackend::EnqueueInputRecord(
switch (input_memory_type_) {
case V4L2_MEMORY_USERPTR: {
+ VideoFrame& frame = *job_record->input_frame;
const size_t num_planes = V4L2Device::GetNumPlanesOfV4L2PixFmt(
input_config_.fourcc.ToV4L2PixFmt());
std::vector<void*> user_ptrs(num_planes);
+ if (frame.storage_type() == VideoFrame::STORAGE_SHMEM) {
+ // TODO(b/243883312): This copies the video frame to a writable buffer
+ // since the USERPTR API requires writable permission. Remove this
+ // workaround once the unreasonable permission is fixed.
+ const size_t buffer_size = frame.shm_region()->GetSize();
+ std::vector<uint8_t> writable_buffer(buffer_size);
+ std::memcpy(writable_buffer.data(), frame.data(0), buffer_size);
+ for (size_t i = 0; i < num_planes; ++i) {
+ const std::intptr_t plane_offset =
+ reinterpret_cast<std::intptr_t>(frame.data(i)) -
+ reinterpret_cast<std::intptr_t>(frame.data(0));
+ user_ptrs[i] = writable_buffer.data() + plane_offset;
+ }
+ job_record->input_frame->AddDestructionObserver(base::BindOnce(
+ [](std::vector<uint8_t>) {}, std::move(writable_buffer)));
+ } else {
+ for (size_t i = 0; i < num_planes; ++i)
+ user_ptrs[i] = frame.writable_data(i);
+ }
+
for (size_t i = 0; i < num_planes; ++i) {
int bytes_used =
- VideoFrame::PlaneSize(job_record->input_frame->format(), i,
- input_config_.size)
+ VideoFrame::PlaneSize(frame.format(), i, input_config_.size)
.GetArea();
buffer.SetPlaneBytesUsed(i, bytes_used);
- user_ptrs[i] = job_record->input_frame->data(i);
}
- std::move(buffer).QueueUserPtr(user_ptrs);
+ if (!std::move(buffer).QueueUserPtr(user_ptrs)) {
+ VPLOGF(1) << "Failed to queue a DMABUF buffer to input queue";
+ NotifyError();
+ return false;
+ }
break;
}
case V4L2_MEMORY_DMABUF: {
@@ -945,7 +971,12 @@ bool V4L2ImageProcessorBackend::EnqueueInputRecord(
FillV4L2BufferByGpuMemoryBufferHandle(
input_config_.fourcc, input_config_.size, *input_handle, &buffer);
- std::move(buffer).QueueDMABuf(input_handle->native_pixmap_handle.planes);
+ if (!std::move(buffer).QueueDMABuf(
+ input_handle->native_pixmap_handle.planes)) {
+ VPLOGF(1) << "Failed to queue a DMABUF buffer to input queue";
+ NotifyError();
+ return false;
+ }
break;
}
default: