From patchwork Fri Feb 26 13:29:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11394 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id DCB13BD1F1 for ; Fri, 26 Feb 2021 13:29:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C1A8468A6F; Fri, 26 Feb 2021 14:29:15 +0100 (CET) Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7A40A60106 for ; Fri, 26 Feb 2021 14:29:13 +0100 (CET) Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id 4214320000F for ; Fri, 26 Feb 2021 13:29:13 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Feb 2021 14:29:21 +0100 Message-Id: <20210226132932.165484-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210226132932.165484-1-jacopo@jmondi.org> References: <20210226132932.165484-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 01/12] meson: options: Add an option to select Android memory backend X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The Android Camera3 HAL implementation interfaces with platform specific implementations of the memory management infrastructure. On regular Android systems it is usually a vendor specific implementation of the gralloc framework, on Chromium OS memory is managed through the system-specific libcbm implementation and so far the only supported backend was a generic implementation that relies on the Linux kernel primitives to access memory buffer. Define a combo option to select which memory backend to use and define the currently existing implementation as 'android_generic'. Signed-off-by: Jacopo Mondi --- meson_options.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/meson_options.txt b/meson_options.txt index 22efb3235c19..34063172f4ba 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -10,6 +10,12 @@ option('cros', value : 'false', description : 'Compile libcamera with the cros Camera3 HAL interface (depends on android option)') +option('android_memory_backend', + type : 'combo', + choices : ['android_generic'], + value : 'android_generic', + description : 'Select the memory backend in use for the Android Camera3 HAL') + option('documentation', type : 'feature', description : 'Generate the project documentation') From patchwork Fri Feb 26 13:29:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11395 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 2DC1FBD1F1 for ; Fri, 26 Feb 2021 13:29:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7374C68A64; Fri, 26 Feb 2021 14:29:16 +0100 (CET) Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E0AAC60106 for ; Fri, 26 Feb 2021 14:29:13 +0100 (CET) Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id A4C77200005 for ; Fri, 26 Feb 2021 13:29:13 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Feb 2021 14:29:22 +0100 Message-Id: <20210226132932.165484-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210226132932.165484-1-jacopo@jmondi.org> References: <20210226132932.165484-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 02/12] android: Introduce CameraBuffer interface X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" In order to provide support for different memory backends, move the MappedCamera3Buffer class definition outside of the CameraDevice class to its own file. The interface defined in camera_buffer.h will be implemented by different backends that will be placed in the src/android/mm subdirectory. Provide a first implementation for the 'generic android' backend which matches the existing one. The MappedCamera3Buffer interface will be renamed in CameraBuffer in the next patch to match the name of the file and not in this patch to ease review. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/android/camera_buffer.h | 21 ++++++++++ src/android/camera_device.cpp | 30 -------------- src/android/camera_device.h | 7 +--- src/android/meson.build | 2 + src/android/mm/android_generic_buffer.cpp | 48 +++++++++++++++++++++++ src/android/mm/meson.build | 6 +++ 6 files changed, 78 insertions(+), 36 deletions(-) create mode 100644 src/android/camera_buffer.h create mode 100644 src/android/mm/android_generic_buffer.cpp create mode 100644 src/android/mm/meson.build diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h new file mode 100644 index 000000000000..a1fb97a3c6db --- /dev/null +++ b/src/android/camera_buffer.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Google Inc. + * + * camera_buffer.h - Frame buffer handling interface definition + */ +#ifndef __ANDROID_CAMERA_BUFFER_H__ +#define __ANDROID_CAMERA_BUFFER_H__ + +#include + +#include + +class MappedCamera3Buffer : public libcamera::MappedBuffer +{ +public: + MappedCamera3Buffer(const buffer_handle_t camera3buffer, int flags); + ~MappedCamera3Buffer(); +}; + +#endif /* __ANDROID_CAMERA_BUFFER_H__ */ diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 16cb8c6d2b84..a7a5b7986aa4 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -257,36 +257,6 @@ void sortCamera3StreamConfigs(std::vector &unsortedConfigs, } /* namespace */ -MappedCamera3Buffer::MappedCamera3Buffer(const buffer_handle_t camera3buffer, - int flags) -{ - maps_.reserve(camera3buffer->numFds); - error_ = 0; - - for (int i = 0; i < camera3buffer->numFds; i++) { - if (camera3buffer->data[i] == -1) - continue; - - off_t length = lseek(camera3buffer->data[i], 0, SEEK_END); - if (length < 0) { - error_ = -errno; - LOG(HAL, Error) << "Failed to query plane length"; - break; - } - - void *address = mmap(nullptr, length, flags, MAP_SHARED, - camera3buffer->data[i], 0); - if (address == MAP_FAILED) { - error_ = -errno; - LOG(HAL, Error) << "Failed to mmap plane"; - break; - } - - maps_.emplace_back(static_cast(address), - static_cast(length)); - } -} - /* * \struct Camera3RequestDescriptor * diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 9cbfcad38433..e6c192c2100b 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -24,17 +24,12 @@ #include "libcamera/internal/log.h" #include "libcamera/internal/message.h" +#include "camera_buffer.h" #include "camera_metadata.h" #include "camera_stream.h" #include "camera_worker.h" #include "jpeg/encoder.h" -class MappedCamera3Buffer : public libcamera::MappedBuffer -{ -public: - MappedCamera3Buffer(const buffer_handle_t camera3buffer, int flags); -}; - class CameraDevice : protected libcamera::Loggable { public: diff --git a/src/android/meson.build b/src/android/meson.build index a13ce63b1d58..fd41c74f78ef 100644 --- a/src/android/meson.build +++ b/src/android/meson.build @@ -57,6 +57,8 @@ android_hal_sources = files([ 'yuv/post_processor_yuv.cpp' ]) +subdir('mm') + android_camera_metadata_sources = files([ 'metadata/camera_metadata.c', ]) diff --git a/src/android/mm/android_generic_buffer.cpp b/src/android/mm/android_generic_buffer.cpp new file mode 100644 index 000000000000..2504d9276e9e --- /dev/null +++ b/src/android/mm/android_generic_buffer.cpp @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Google Inc. + * + * android_generic_buffer.cpp - Generic Android frame buffer backend + */ + +#include "../camera_buffer.h" + +#include "libcamera/internal/log.h" + +using namespace libcamera; + +LOG_DECLARE_CATEGORY(HAL) + +MappedCamera3Buffer::MappedCamera3Buffer(const buffer_handle_t camera3buffer, + int flags) +{ + maps_.reserve(camera3buffer->numFds); + error_ = 0; + + for (int i = 0; i < camera3buffer->numFds; i++) { + if (camera3buffer->data[i] == -1) + continue; + + off_t length = lseek(camera3buffer->data[i], 0, SEEK_END); + if (length < 0) { + error_ = -errno; + LOG(HAL, Error) << "Failed to query plane length"; + break; + } + + void *address = mmap(nullptr, length, flags, MAP_SHARED, + camera3buffer->data[i], 0); + if (address == MAP_FAILED) { + error_ = -errno; + LOG(HAL, Error) << "Failed to mmap plane"; + break; + } + + maps_.emplace_back(static_cast(address), + static_cast(length)); + } +} + +MappedCamera3Buffer::~MappedCamera3Buffer() +{ +} diff --git a/src/android/mm/meson.build b/src/android/mm/meson.build new file mode 100644 index 000000000000..39be8fec8567 --- /dev/null +++ b/src/android/mm/meson.build @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: CC0-1.0 + +memory_backend = get_option('android_memory_backend') +if memory_backend == 'android_generic' + android_hal_sources += files(['android_generic_buffer.cpp']) +endif From patchwork Fri Feb 26 13:29:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11396 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id EB6B1BD1F1 for ; Fri, 26 Feb 2021 13:29:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 106AE68A79; Fri, 26 Feb 2021 14:29:18 +0100 (CET) Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 520ED68A61 for ; Fri, 26 Feb 2021 14:29:14 +0100 (CET) Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id 1968F200010 for ; Fri, 26 Feb 2021 13:29:13 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Feb 2021 14:29:23 +0100 Message-Id: <20210226132932.165484-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210226132932.165484-1-jacopo@jmondi.org> References: <20210226132932.165484-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 03/12] android: Rename MappedCamera3Buffer to CameraBuffer X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Rename the MappedCamera3Buffer class to the simpler CameraBuffer to match the name of the header file where the interface is defined. Signed-off-by: Jacopo Mondi --- src/android/camera_buffer.h | 6 +++--- src/android/camera_device.cpp | 4 ++-- src/android/mm/android_generic_buffer.cpp | 5 ++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h index a1fb97a3c6db..00b061502d6e 100644 --- a/src/android/camera_buffer.h +++ b/src/android/camera_buffer.h @@ -11,11 +11,11 @@ #include -class MappedCamera3Buffer : public libcamera::MappedBuffer +class CameraBuffer : public libcamera::MappedBuffer { public: - MappedCamera3Buffer(const buffer_handle_t camera3buffer, int flags); - ~MappedCamera3Buffer(); + CameraBuffer(const buffer_handle_t camera3buffer, int flags); + ~CameraBuffer(); }; #endif /* __ANDROID_CAMERA_BUFFER_H__ */ diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index a7a5b7986aa4..f47f28b8c7ee 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1862,8 +1862,8 @@ void CameraDevice::requestComplete(Request *request) * separate thread. */ - MappedCamera3Buffer mapped(*descriptor->buffers_[i].buffer, - PROT_READ | PROT_WRITE); + CameraBuffer mapped(*descriptor->buffers_[i].buffer, + PROT_READ | PROT_WRITE); if (!mapped.isValid()) { LOG(HAL, Error) << "Failed to mmap android blob buffer"; continue; diff --git a/src/android/mm/android_generic_buffer.cpp b/src/android/mm/android_generic_buffer.cpp index 2504d9276e9e..6f41215bb0f9 100644 --- a/src/android/mm/android_generic_buffer.cpp +++ b/src/android/mm/android_generic_buffer.cpp @@ -13,8 +13,7 @@ using namespace libcamera; LOG_DECLARE_CATEGORY(HAL) -MappedCamera3Buffer::MappedCamera3Buffer(const buffer_handle_t camera3buffer, - int flags) +CameraBuffer::CameraBuffer(const buffer_handle_t camera3buffer, int flags) { maps_.reserve(camera3buffer->numFds); error_ = 0; @@ -43,6 +42,6 @@ MappedCamera3Buffer::MappedCamera3Buffer(const buffer_handle_t camera3buffer, } } -MappedCamera3Buffer::~MappedCamera3Buffer() +CameraBuffer::~CameraBuffer() { } From patchwork Fri Feb 26 13:29:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11397 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 75909BD1F1 for ; Fri, 26 Feb 2021 13:29:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3566868A7E; Fri, 26 Feb 2021 14:29:18 +0100 (CET) Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AFD4D68A61 for ; Fri, 26 Feb 2021 14:29:14 +0100 (CET) Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id 7751F200005 for ; Fri, 26 Feb 2021 13:29:14 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Feb 2021 14:29:24 +0100 Message-Id: <20210226132932.165484-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210226132932.165484-1-jacopo@jmondi.org> References: <20210226132932.165484-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 04/12] android: camera_buffer: Drop 'const' from buffer_handle_t X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The buffer_handle_t type is defined as 'const native_handle_t*'. Drop the 'const' specifier from the parameter of the CameraBuffer class constructor and in the Android generic memory backend. Also rename 'camera3buffer' in 'camera3Buffer' to comply with the coding style guidelines. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/android/camera_buffer.h | 2 +- src/android/mm/android_generic_buffer.cpp | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h index 00b061502d6e..0590cd84652b 100644 --- a/src/android/camera_buffer.h +++ b/src/android/camera_buffer.h @@ -14,7 +14,7 @@ class CameraBuffer : public libcamera::MappedBuffer { public: - CameraBuffer(const buffer_handle_t camera3buffer, int flags); + CameraBuffer(buffer_handle_t camera3Buffer, int flags); ~CameraBuffer(); }; diff --git a/src/android/mm/android_generic_buffer.cpp b/src/android/mm/android_generic_buffer.cpp index 6f41215bb0f9..807304a9e42d 100644 --- a/src/android/mm/android_generic_buffer.cpp +++ b/src/android/mm/android_generic_buffer.cpp @@ -13,16 +13,16 @@ using namespace libcamera; LOG_DECLARE_CATEGORY(HAL) -CameraBuffer::CameraBuffer(const buffer_handle_t camera3buffer, int flags) +CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags) { - maps_.reserve(camera3buffer->numFds); + maps_.reserve(camera3Buffer->numFds); error_ = 0; - for (int i = 0; i < camera3buffer->numFds; i++) { - if (camera3buffer->data[i] == -1) + for (int i = 0; i < camera3Buffer->numFds; i++) { + if (camera3Buffer->data[i] == -1) continue; - off_t length = lseek(camera3buffer->data[i], 0, SEEK_END); + off_t length = lseek(camera3Buffer->data[i], 0, SEEK_END); if (length < 0) { error_ = -errno; LOG(HAL, Error) << "Failed to query plane length"; @@ -30,7 +30,7 @@ CameraBuffer::CameraBuffer(const buffer_handle_t camera3buffer, int flags) } void *address = mmap(nullptr, length, flags, MAP_SHARED, - camera3buffer->data[i], 0); + camera3Buffer->data[i], 0); if (address == MAP_FAILED) { error_ = -errno; LOG(HAL, Error) << "Failed to mmap plane"; From patchwork Fri Feb 26 13:29:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11398 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id B4C74BD1F1 for ; Fri, 26 Feb 2021 13:29:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8EBBF68A89; Fri, 26 Feb 2021 14:29:21 +0100 (CET) Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 71E1768A6D for ; Fri, 26 Feb 2021 14:29:15 +0100 (CET) Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id F1687200005 for ; Fri, 26 Feb 2021 13:29:14 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Feb 2021 14:29:25 +0100 Message-Id: <20210226132932.165484-6-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210226132932.165484-1-jacopo@jmondi.org> References: <20210226132932.165484-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 05/12] android: camera_device: Rename buffer fields X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The buffers passed to the post processor are currently named 'buffer' and 'mapped', names that do not convey their role. Use 'src' and 'dest' instead. Cosmetic change only. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index f47f28b8c7ee..1c3b0f56ed28 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1851,8 +1851,8 @@ void CameraDevice::requestComplete(Request *request) if (cameraStream->camera3Stream().format != HAL_PIXEL_FORMAT_BLOB) continue; - FrameBuffer *buffer = request->findBuffer(cameraStream->stream()); - if (!buffer) { + FrameBuffer *src = request->findBuffer(cameraStream->stream()); + if (!src) { LOG(HAL, Error) << "Failed to find a source stream buffer"; continue; } @@ -1862,14 +1862,14 @@ void CameraDevice::requestComplete(Request *request) * separate thread. */ - CameraBuffer mapped(*descriptor->buffers_[i].buffer, - PROT_READ | PROT_WRITE); - if (!mapped.isValid()) { - LOG(HAL, Error) << "Failed to mmap android blob buffer"; + CameraBuffer dest(*descriptor->buffers_[i].buffer, + PROT_READ | PROT_WRITE); + if (!dest.isValid()) { + LOG(HAL, Error) << "Failed to map android blob buffer"; continue; } - int ret = cameraStream->process(*buffer, &mapped, + int ret = cameraStream->process(*src, &dest, descriptor->settings_, resultMetadata.get()); if (ret) { @@ -1882,7 +1882,7 @@ void CameraDevice::requestComplete(Request *request) * done processing it. */ if (cameraStream->type() == CameraStream::Type::Internal) - cameraStream->putBuffer(buffer); + cameraStream->putBuffer(src); } /* Prepare to call back the Android camera stack. */ From patchwork Fri Feb 26 13:29:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11399 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 23224BD1F1 for ; Fri, 26 Feb 2021 13:29:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B405F68A8C; Fri, 26 Feb 2021 14:29:21 +0100 (CET) Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A1D5868A61 for ; Fri, 26 Feb 2021 14:29:15 +0100 (CET) Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id 6690E200013 for ; Fri, 26 Feb 2021 13:29:15 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Feb 2021 14:29:26 +0100 Message-Id: <20210226132932.165484-7-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210226132932.165484-1-jacopo@jmondi.org> References: <20210226132932.165484-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 06/12] android: Move buffer mapping to CameraStream X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The destination buffer for the post-processing component is currently first mapped in the CameraDevice class and then passed to CameraStream which simply calls the post-processor interface. Move the mapping to CameraStream::process() to tie the buffer mapping to the lifetime of the CameraBuffer instance. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 15 ++------------- src/android/camera_device.h | 1 - src/android/camera_stream.cpp | 16 +++++++++++++--- src/android/camera_stream.h | 2 +- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 1c3b0f56ed28..ae01c362559e 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1857,19 +1857,8 @@ void CameraDevice::requestComplete(Request *request) continue; } - /* - * \todo Buffer mapping and compression should be moved to a - * separate thread. - */ - - CameraBuffer dest(*descriptor->buffers_[i].buffer, - PROT_READ | PROT_WRITE); - if (!dest.isValid()) { - LOG(HAL, Error) << "Failed to map android blob buffer"; - continue; - } - - int ret = cameraStream->process(*src, &dest, + int ret = cameraStream->process(*src, + *descriptor->buffers_[i].buffer, descriptor->settings_, resultMetadata.get()); if (ret) { diff --git a/src/android/camera_device.h b/src/android/camera_device.h index e6c192c2100b..4905958e63c6 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -24,7 +24,6 @@ #include "libcamera/internal/log.h" #include "libcamera/internal/message.h" -#include "camera_buffer.h" #include "camera_metadata.h" #include "camera_stream.h" #include "camera_worker.h" diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index 611ec0d1c42e..61b5bbf429ae 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -7,6 +7,7 @@ #include "camera_stream.h" +#include "camera_buffer.h" #include "camera_device.h" #include "camera_metadata.h" #include "jpeg/post_processor_jpeg.h" @@ -96,15 +97,24 @@ int CameraStream::configure() } int CameraStream::process(const libcamera::FrameBuffer &source, - libcamera::MappedBuffer *destination, + const buffer_handle_t camera3Dest, const CameraMetadata &requestMetadata, CameraMetadata *resultMetadata) { if (!postProcessor_) return 0; - return postProcessor_->process(source, destination, - requestMetadata, resultMetadata); + /* + * \todo Buffer mapping and compression should be moved to a + * separate thread. + */ + CameraBuffer dest(camera3Dest, PROT_READ | PROT_WRITE); + if (!dest.isValid()) { + LOG(HAL, Error) << "Failed to map android blob buffer"; + return -EINVAL; + } + + return postProcessor_->process(source, &dest, requestMetadata, resultMetadata); } FrameBuffer *CameraStream::getBuffer() diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index fc242b2aadf1..8673cacf15b0 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -120,7 +120,7 @@ public: int configure(); int process(const libcamera::FrameBuffer &source, - libcamera::MappedBuffer *destination, + const buffer_handle_t camera3Dest, const CameraMetadata &requestMetadata, CameraMetadata *resultMetadata); libcamera::FrameBuffer *getBuffer(); From patchwork Fri Feb 26 13:29:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11400 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 8CDEABD1F1 for ; Fri, 26 Feb 2021 13:29:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D556168A8E; Fri, 26 Feb 2021 14:29:21 +0100 (CET) Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0E9A668A71 for ; Fri, 26 Feb 2021 14:29:16 +0100 (CET) Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id C67E2200005 for ; Fri, 26 Feb 2021 13:29:15 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Feb 2021 14:29:27 +0100 Message-Id: <20210226132932.165484-8-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210226132932.165484-1-jacopo@jmondi.org> References: <20210226132932.165484-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 07/12] android: camera_buffer: Implement PIMPL pattern X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" In order to prepare to support more memory backends, make the CameraBuffer class implement the PIMPL (pointer-to-implementation) pattern. Define the CameraBuffer class interface whose actual implementation is delegated to an inner CameraBufferImpl class. Temporary maintain libcamera::MappedBuffer as the CameraBuffer base class to maintain compatibility of the CameraStream::process() interface that requires a MappedBuffer * as second argument and will be converted to use a CameraBuffer in the next patch. Signed-off-by: Jacopo Mondi --- src/android/camera_buffer.h | 12 ++++ src/android/mm/android_generic_buffer.cpp | 80 ++++++++++++++++++++++- 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h index 0590cd84652b..2a91e6a3c9c1 100644 --- a/src/android/camera_buffer.h +++ b/src/android/camera_buffer.h @@ -16,6 +16,18 @@ class CameraBuffer : public libcamera::MappedBuffer public: CameraBuffer(buffer_handle_t camera3Buffer, int flags); ~CameraBuffer(); + + bool isValid() const; + + unsigned int numPlanes() const; + ssize_t planeSize(unsigned int plane) const; + + const uint8_t *plane(unsigned int plane) const; + uint8_t *plane(unsigned int plane); + +private: + class CameraBufferImpl; + CameraBufferImpl *impl_; }; #endif /* __ANDROID_CAMERA_BUFFER_H__ */ diff --git a/src/android/mm/android_generic_buffer.cpp b/src/android/mm/android_generic_buffer.cpp index 807304a9e42d..10a43a61bd4d 100644 --- a/src/android/mm/android_generic_buffer.cpp +++ b/src/android/mm/android_generic_buffer.cpp @@ -13,7 +13,21 @@ using namespace libcamera; LOG_DECLARE_CATEGORY(HAL) -CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags) +class CameraBuffer::CameraBufferImpl : public libcamera::MappedBuffer +{ +public: + CameraBufferImpl(buffer_handle_t camera3Buffer, int flags); + ~CameraBufferImpl(); + + unsigned int numPlanes() const; + ssize_t planeSize(unsigned int plane) const; + + const uint8_t *plane(unsigned int plane) const; + uint8_t *plane(unsigned int plane); +}; + +CameraBuffer::CameraBufferImpl::CameraBufferImpl(buffer_handle_t camera3Buffer, + int flags) { maps_.reserve(camera3Buffer->numFds); error_ = 0; @@ -42,6 +56,70 @@ CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags) } } +CameraBuffer::CameraBufferImpl::~CameraBufferImpl() +{ +} + +unsigned int CameraBuffer::CameraBufferImpl::numPlanes() const +{ + return maps_.size(); +} + +ssize_t CameraBuffer::CameraBufferImpl::planeSize(unsigned int plane) const +{ + if (plane >= maps_.size()) + return -EINVAL; + + return maps_[plane].size(); +} + +const uint8_t *CameraBuffer::CameraBufferImpl::plane(unsigned int plane) const +{ + if (plane >= maps_.size()) + return nullptr; + + return maps_[plane].data(); +} + +uint8_t *CameraBuffer::CameraBufferImpl::plane(unsigned int plane) +{ + if (plane >= maps_.size()) + return nullptr; + + return maps_[plane].data(); +} + +CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags) + : impl_(new CameraBuffer::CameraBufferImpl(camera3Buffer, flags)) +{ +} + CameraBuffer::~CameraBuffer() { + delete impl_; +} + +bool CameraBuffer::isValid() const +{ + return impl_->isValid(); +} + +unsigned int CameraBuffer::numPlanes() const +{ + return impl_->numPlanes(); +} + +ssize_t CameraBuffer::planeSize(unsigned int plane) const +{ + return impl_->planeSize(plane); +} + +const uint8_t *CameraBuffer::plane(unsigned int plane) const +{ + return impl_->plane(plane); +} + +uint8_t *CameraBuffer::plane(unsigned int plane) +{ + return impl_->plane(plane); } From patchwork Fri Feb 26 13:29:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11401 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id EAD65BD1F1 for ; Fri, 26 Feb 2021 13:29:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6A02968A78; Fri, 26 Feb 2021 14:29:22 +0100 (CET) Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7A4D668A73 for ; Fri, 26 Feb 2021 14:29:16 +0100 (CET) Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id 34B1A200005 for ; Fri, 26 Feb 2021 13:29:16 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Feb 2021 14:29:28 +0100 Message-Id: <20210226132932.165484-9-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210226132932.165484-1-jacopo@jmondi.org> References: <20210226132932.165484-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 08/12] android: post_processor: Use CameraBuffer API X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Use the newly introduced CameraBuffer class as the type for the destination buffer in the PostProcessor class hierarchy in place of the libcamera::MappedFrameBuffer one and use its API to retrieve the length and the location of the CameraBuffer plane allocated for JPEG post-processing. Remove all the assumption on the underlying memory storage and only go through the CameraBuffer API when dealing with memory buffers. To do so rework the Encoder interface to use a raw pointer and an explicit size to remove access to the Span maps that serve as memory storage for the current implementation but might not be ideal for other memory backend. Now that the whole PostProcessor hierarchy has been converted to use the CameraBuffer API remove libcamera::MappedBuffer as base class of the CameraBuffer interface and only reply on its interface. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/android/camera_buffer.h | 2 +- src/android/jpeg/encoder.h | 4 +++- src/android/jpeg/encoder_libjpeg.cpp | 19 ++++++++-------- src/android/jpeg/encoder_libjpeg.h | 4 ++-- src/android/jpeg/post_processor_jpeg.cpp | 28 ++++++++++-------------- src/android/jpeg/post_processor_jpeg.h | 2 +- src/android/post_processor.h | 4 +++- src/android/yuv/post_processor_yuv.cpp | 20 ++++++++--------- src/android/yuv/post_processor_yuv.h | 4 ++-- 9 files changed, 42 insertions(+), 45 deletions(-) diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h index 2a91e6a3c9c1..b251e4514864 100644 --- a/src/android/camera_buffer.h +++ b/src/android/camera_buffer.h @@ -11,7 +11,7 @@ #include -class CameraBuffer : public libcamera::MappedBuffer +class CameraBuffer { public: CameraBuffer(buffer_handle_t camera3Buffer, int flags); diff --git a/src/android/jpeg/encoder.h b/src/android/jpeg/encoder.h index 8d449369869f..a3c47c09a06e 100644 --- a/src/android/jpeg/encoder.h +++ b/src/android/jpeg/encoder.h @@ -11,6 +11,8 @@ #include #include +#include "../camera_buffer.h" + class Encoder { public: @@ -18,7 +20,7 @@ public: virtual int configure(const libcamera::StreamConfiguration &cfg) = 0; virtual int encode(const libcamera::FrameBuffer &source, - libcamera::Span destination, + uint8_t *destination, size_t destinationSize, libcamera::Span exifData, unsigned int quality) = 0; }; diff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp index f006e1d1999a..a965620703df 100644 --- a/src/android/jpeg/encoder_libjpeg.cpp +++ b/src/android/jpeg/encoder_libjpeg.cpp @@ -177,8 +177,9 @@ void EncoderLibJpeg::compressNV(Span frame) } } -int EncoderLibJpeg::encode(const FrameBuffer &source, Span dest, - Span exifData, unsigned int quality) +int EncoderLibJpeg::encode(const FrameBuffer &source, uint8_t *destination, + size_t destinationSize, Span exifData, + unsigned int quality) { MappedFrameBuffer frame(&source, PROT_READ); if (!frame.isValid()) { @@ -187,15 +188,13 @@ int EncoderLibJpeg::encode(const FrameBuffer &source, Span dest, return frame.error(); } - return encode(frame.maps()[0], dest, exifData, quality); + return encode(frame.maps()[0], destination, destinationSize, exifData, quality); } -int EncoderLibJpeg::encode(Span src, Span dest, - Span exifData, unsigned int quality) +int EncoderLibJpeg::encode(Span src, uint8_t *destination, + size_t destinationSize, Span exifData, + unsigned int quality) { - unsigned char *destination = dest.data(); - unsigned long size = dest.size(); - jpeg_set_quality(&compress_, quality, TRUE); /* @@ -206,7 +205,7 @@ int EncoderLibJpeg::encode(Span src, Span dest, * \todo Implement our own custom memory destination to prevent * reallocation and prefer failure with correct reporting. */ - jpeg_mem_dest(&compress_, &destination, &size); + jpeg_mem_dest(&compress_, &destination, &destinationSize); jpeg_start_compress(&compress_, TRUE); @@ -226,5 +225,5 @@ int EncoderLibJpeg::encode(Span src, Span dest, jpeg_finish_compress(&compress_); - return size; + return destinationSize; } diff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h index 838da7728382..bda5c16089df 100644 --- a/src/android/jpeg/encoder_libjpeg.h +++ b/src/android/jpeg/encoder_libjpeg.h @@ -22,11 +22,11 @@ public: int configure(const libcamera::StreamConfiguration &cfg) override; int encode(const libcamera::FrameBuffer &source, - libcamera::Span destination, + uint8_t *destination, size_t destinationSize, libcamera::Span exifData, unsigned int quality) override; int encode(libcamera::Span source, - libcamera::Span destination, + uint8_t *destination, size_t destinationSize, libcamera::Span exifData, unsigned int quality); diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp index ab5b63844067..d6eeb962e81d 100644 --- a/src/android/jpeg/post_processor_jpeg.cpp +++ b/src/android/jpeg/post_processor_jpeg.cpp @@ -73,7 +73,9 @@ void PostProcessorJpeg::generateThumbnail(const FrameBuffer &source, thumbnail->resize(rawThumbnail.size()); int jpeg_size = thumbnailEncoder_.encode(rawThumbnail, - *thumbnail, {}, quality); + thumbnail->data(), + thumbnail->size(), + {}, quality); thumbnail->resize(jpeg_size); LOG(JPEG, Debug) @@ -83,13 +85,15 @@ void PostProcessorJpeg::generateThumbnail(const FrameBuffer &source, } int PostProcessorJpeg::process(const FrameBuffer &source, - libcamera::MappedBuffer *destination, + CameraBuffer *destination, const CameraMetadata &requestMetadata, CameraMetadata *resultMetadata) { if (!encoder_) return 0; + ASSERT(destination->numPlanes() == 1); + camera_metadata_ro_entry_t entry; int ret; @@ -172,27 +176,17 @@ int PostProcessorJpeg::process(const FrameBuffer &source, const uint8_t quality = ret ? *entry.data.u8 : 95; resultMetadata->addEntry(ANDROID_JPEG_QUALITY, &quality, 1); - int jpeg_size = encoder_->encode(source, destination->maps()[0], + int jpeg_size = encoder_->encode(source, destination->plane(0), + destination->planeSize(0), exif.data(), quality); if (jpeg_size < 0) { LOG(JPEG, Error) << "Failed to encode stream image"; return jpeg_size; } - /* - * Fill in the JPEG blob header. - * - * The mapped size of the buffer is being returned as - * substantially larger than the requested JPEG_MAX_SIZE - * (which is referenced from maxJpegBufferSize_). Utilise - * this static size to ensure the correct offset of the blob is - * determined. - * - * \todo Investigate if the buffer size mismatch is an issue or - * expected behaviour. - */ - uint8_t *resultPtr = destination->maps()[0].data() + - cameraDevice_->maxJpegBufferSize() - + /* Fill in the JPEG blob header. */ + uint8_t *resultPtr = destination->plane(0) + + destination->planeSize(0) - sizeof(struct camera3_jpeg_blob); auto *blob = reinterpret_cast(resultPtr); blob->jpeg_blob_id = CAMERA3_JPEG_BLOB_ID; diff --git a/src/android/jpeg/post_processor_jpeg.h b/src/android/jpeg/post_processor_jpeg.h index 7689de73c664..5d2d4ab224b1 100644 --- a/src/android/jpeg/post_processor_jpeg.h +++ b/src/android/jpeg/post_processor_jpeg.h @@ -25,7 +25,7 @@ public: int configure(const libcamera::StreamConfiguration &incfg, const libcamera::StreamConfiguration &outcfg) override; int process(const libcamera::FrameBuffer &source, - libcamera::MappedBuffer *destination, + CameraBuffer *destination, const CameraMetadata &requestMetadata, CameraMetadata *resultMetadata) override; diff --git a/src/android/post_processor.h b/src/android/post_processor.h index ac40d3414892..4944078b490c 100644 --- a/src/android/post_processor.h +++ b/src/android/post_processor.h @@ -12,6 +12,8 @@ #include +#include "camera_buffer.h" + class CameraMetadata; class PostProcessor @@ -22,7 +24,7 @@ public: virtual int configure(const libcamera::StreamConfiguration &inCfg, const libcamera::StreamConfiguration &outCfg) = 0; virtual int process(const libcamera::FrameBuffer &source, - libcamera::MappedBuffer *destination, + CameraBuffer *destination, const CameraMetadata &requestMetadata, CameraMetadata *resultMetadata) = 0; }; diff --git a/src/android/yuv/post_processor_yuv.cpp b/src/android/yuv/post_processor_yuv.cpp index 1318349ad66b..f1487185a95a 100644 --- a/src/android/yuv/post_processor_yuv.cpp +++ b/src/android/yuv/post_processor_yuv.cpp @@ -48,7 +48,7 @@ int PostProcessorYuv::configure(const StreamConfiguration &inCfg, } int PostProcessorYuv::process(const FrameBuffer &source, - libcamera::MappedBuffer *destination, + CameraBuffer *destination, [[maybe_unused]] const CameraMetadata &requestMetadata, [[maybe_unused]] CameraMetadata *metadata) { @@ -66,9 +66,9 @@ int PostProcessorYuv::process(const FrameBuffer &source, sourceMapped.maps()[1].data(), sourceStride_[1], sourceSize_.width, sourceSize_.height, - destination->maps()[0].data(), + destination->plane(0), destinationStride_[0], - destination->maps()[1].data(), + destination->plane(1), destinationStride_[1], destinationSize_.width, destinationSize_.height, @@ -82,16 +82,16 @@ int PostProcessorYuv::process(const FrameBuffer &source, } bool PostProcessorYuv::isValidBuffers(const FrameBuffer &source, - const libcamera::MappedBuffer &destination) const + const CameraBuffer &destination) const { if (source.planes().size() != 2) { LOG(YUV, Error) << "Invalid number of source planes: " << source.planes().size(); return false; } - if (destination.maps().size() != 2) { + if (destination.numPlanes() != 2) { LOG(YUV, Error) << "Invalid number of destination planes: " - << destination.maps().size(); + << destination.numPlanes(); return false; } @@ -106,12 +106,12 @@ bool PostProcessorYuv::isValidBuffers(const FrameBuffer &source, << sourceLength_[1] << "}"; return false; } - if (destination.maps()[0].size() < destinationLength_[0] || - destination.maps()[1].size() < destinationLength_[1]) { + if (destination.planeSize(0) < destinationLength_[0] || + destination.planeSize(1) < destinationLength_[1]) { LOG(YUV, Error) << "The destination planes lengths are too small, actual size: {" - << destination.maps()[0].size() << ", " - << destination.maps()[1].size() + << destination.planeSize(0) << ", " + << destination.planeSize(1) << "}, expected size: {" << sourceLength_[0] << ", " << sourceLength_[1] << "}"; diff --git a/src/android/yuv/post_processor_yuv.h b/src/android/yuv/post_processor_yuv.h index c58b4cf790fc..f8b1ba23fa6c 100644 --- a/src/android/yuv/post_processor_yuv.h +++ b/src/android/yuv/post_processor_yuv.h @@ -21,13 +21,13 @@ public: int configure(const libcamera::StreamConfiguration &incfg, const libcamera::StreamConfiguration &outcfg) override; int process(const libcamera::FrameBuffer &source, - libcamera::MappedBuffer *destination, + CameraBuffer *destination, const CameraMetadata &requestMetadata, CameraMetadata *metadata) override; private: bool isValidBuffers(const libcamera::FrameBuffer &source, - const libcamera::MappedBuffer &destination) const; + const CameraBuffer &destination) const; void calculateLengths(const libcamera::StreamConfiguration &inCfg, const libcamera::StreamConfiguration &outCfg); From patchwork Fri Feb 26 13:29:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11402 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 4175EBD80C for ; Fri, 26 Feb 2021 13:29:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0F19C68A82; Fri, 26 Feb 2021 14:29:23 +0100 (CET) Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EE92468A76 for ; Fri, 26 Feb 2021 14:29:16 +0100 (CET) Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id B22A7200005 for ; Fri, 26 Feb 2021 13:29:16 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Feb 2021 14:29:29 +0100 Message-Id: <20210226132932.165484-10-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210226132932.165484-1-jacopo@jmondi.org> References: <20210226132932.165484-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 09/12] android: jpeg: Use maxJpegBufferSize() for compatibility X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Platforms that do not provide a memory backend implementation should keep using the maxJpegBufferSize() value to calculate the location where to place the JPEG blob id, as the android_generic backend returns the allocated buffer size as calculated using lseek which is larger than the maximum JPEG frame size, which is where the framework expects the JPEG blob to be placed. Signed-off-by: Jacopo Mondi --- src/android/jpeg/post_processor_jpeg.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp index d6eeb962e81d..e7f66d66698c 100644 --- a/src/android/jpeg/post_processor_jpeg.cpp +++ b/src/android/jpeg/post_processor_jpeg.cpp @@ -185,9 +185,17 @@ int PostProcessorJpeg::process(const FrameBuffer &source, } /* Fill in the JPEG blob header. */ - uint8_t *resultPtr = destination->plane(0) + - destination->planeSize(0) - - sizeof(struct camera3_jpeg_blob); + /* + * \todo For backward compatibility reasons with the android_generic + * memory backend, continue using the maxJpegBufferSize in case the + * computed buffer size is larger. This can be dropped once all + * supported platforms will have a working memory backend that + * returns the correct buffer size. + */ + size_t blobSize = std::min(cameraDevice_->maxJpegBufferSize(), + destination->planeSize(0)); + uint8_t *resultPtr = destination->plane(0) + blobSize + - sizeof(struct camera3_jpeg_blob); auto *blob = reinterpret_cast(resultPtr); blob->jpeg_blob_id = CAMERA3_JPEG_BLOB_ID; blob->jpeg_size = jpeg_size; From patchwork Fri Feb 26 13:29:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11403 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id A6104BD1F1 for ; Fri, 26 Feb 2021 13:29:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7174568A83; Fri, 26 Feb 2021 14:29:23 +0100 (CET) Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 57F1960106 for ; Fri, 26 Feb 2021 14:29:17 +0100 (CET) Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id 206A5200005 for ; Fri, 26 Feb 2021 13:29:16 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Feb 2021 14:29:30 +0100 Message-Id: <20210226132932.165484-11-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210226132932.165484-1-jacopo@jmondi.org> References: <20210226132932.165484-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 10/12] meson: options: Introduce 'cros_cbm' memory backend X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add to the list of supported memory backends the 'cros_cbm' option. Signed-off-by: Jacopo Mondi --- meson_options.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson_options.txt b/meson_options.txt index 34063172f4ba..c43def09fe80 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -12,7 +12,7 @@ option('cros', option('android_memory_backend', type : 'combo', - choices : ['android_generic'], + choices : ['android_generic', 'cros_cbm'], value : 'android_generic', description : 'Select the memory backend in use for the Android Camera3 HAL') From patchwork Fri Feb 26 13:29:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11404 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 1097EBD80C for ; Fri, 26 Feb 2021 13:29:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C788F68A93; Fri, 26 Feb 2021 14:29:23 +0100 (CET) Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BB67D68A69 for ; Fri, 26 Feb 2021 14:29:17 +0100 (CET) Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id 7FF19200005 for ; Fri, 26 Feb 2021 13:29:17 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Feb 2021 14:29:31 +0100 Message-Id: <20210226132932.165484-12-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210226132932.165484-1-jacopo@jmondi.org> References: <20210226132932.165484-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 11/12] android: Introduce cros_cbm_buffer X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Introduce the CameraBuffer backend for the ChromeOS operating system. The cros_cbm CameraBuffer implementation uses the ChromeOS CameraBufferManager class to perform mapping of 1 plane and multiplane buffers. Signed-off-by: Jacopo Mondi --- src/android/mm/cros_cbm.cpp | 167 ++++++++++++++++++++++++++++++++++++ src/android/mm/meson.build | 3 + 2 files changed, 170 insertions(+) create mode 100644 src/android/mm/cros_cbm.cpp diff --git a/src/android/mm/cros_cbm.cpp b/src/android/mm/cros_cbm.cpp new file mode 100644 index 000000000000..6c931c99d2d0 --- /dev/null +++ b/src/android/mm/cros_cbm.cpp @@ -0,0 +1,167 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Google Inc. + * + * cros_cbm.cpp - ChromiumOS libcbm frame buffer backend + */ + +#include "../camera_buffer.h" + +#include "libcamera/internal/log.h" + +#include "cros-camera/camera_buffer_manager.h" + +using namespace libcamera; + +LOG_DECLARE_CATEGORY(HAL) + +class CameraBuffer::CameraBufferImpl : public libcamera::MappedBuffer +{ +public: + CameraBufferImpl(buffer_handle_t camera3Buffer, int flags); + ~CameraBufferImpl(); + + bool isValid() const { return valid_; } + + unsigned int numPlanes() const; + ssize_t planeSize(unsigned int plane) const; + + const uint8_t *plane(unsigned int plane) const; + uint8_t *plane(unsigned int plane); + +private: + cros::CameraBufferManager *bufferManager_; + buffer_handle_t handle_; + unsigned int numPlanes_; + bool valid_; + union { + void *addr; + android_ycbcr ycbcr; + } mem; +}; + +CameraBuffer::CameraBufferImpl::CameraBufferImpl(buffer_handle_t camera3Buffer, + int flags) + : handle_(camera3Buffer), numPlanes_(0), valid_(false) +{ + bufferManager_ = cros::CameraBufferManager::GetInstance(); + + bufferManager_->Register(camera3Buffer); + + numPlanes_ = bufferManager_->GetNumPlanes(camera3Buffer); + switch (numPlanes_) { + case 1: { + int ret = bufferManager_->Lock(handle_, 0, 0, 0, 0, 0, &mem.addr); + if (ret) { + LOG(HAL, Error) << "Single plane buffer mapping failed"; + return; + } + break; + } + case 2: { + case 3: + int ret = bufferManager_->LockYCbCr(handle_, 0, 0, 0, 0, 0, + &mem.ycbcr); + if (ret) { + LOG(HAL, Error) << "YCbCr buffer mapping failed"; + return; + } + break; + } + default: + LOG(HAL, Error) << "Invalid number of planes: " << numPlanes_; + return; + } + + valid_ = true; +} + +CameraBuffer::CameraBufferImpl::~CameraBufferImpl() +{ + bufferManager_->Unlock(handle_); + bufferManager_->Deregister(handle_); +} + +unsigned int CameraBuffer::CameraBufferImpl::numPlanes() const +{ + return bufferManager_->GetNumPlanes(handle_); +} + +ssize_t CameraBuffer::CameraBufferImpl::planeSize(unsigned int plane) const +{ + if (plane >= numPlanes()) + return -EINVAL; + + return bufferManager_->GetPlaneSize(handle_, plane); +} + +const uint8_t *CameraBuffer::CameraBufferImpl::plane(unsigned int plane) const +{ + if (plane >= numPlanes()) + return nullptr; + + return const_cast(this->plane(plane)); +} + +uint8_t *CameraBuffer::CameraBufferImpl::plane(unsigned int plane) +{ + if (plane >= numPlanes()) + return nullptr; + + void *addr; + switch (numPlanes()) { + case 1: + addr = mem.addr; + break; + default: + switch (plane) { + case 1: + addr = mem.ycbcr.y; + break; + case 2: + addr = mem.ycbcr.cb; + break; + case 3: + addr = mem.ycbcr.cr; + break; + } + } + + return static_cast(addr); +} + +CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags) + : impl_(new CameraBuffer::CameraBufferImpl(camera3Buffer, flags)) +{ +} + +CameraBuffer::~CameraBuffer() +{ + delete impl_; +} + +bool CameraBuffer::isValid() const +{ + return impl_->isValid(); +} + +unsigned int CameraBuffer::numPlanes() const +{ + return impl_->numPlanes(); +} + +ssize_t CameraBuffer::planeSize(unsigned int plane) const +{ + return impl_->planeSize(plane); +} + +const uint8_t *CameraBuffer::plane(unsigned int plane) const +{ + return impl_->plane(plane); +} + +uint8_t *CameraBuffer::plane(unsigned int plane) +{ + return impl_->plane(plane); +} + diff --git a/src/android/mm/meson.build b/src/android/mm/meson.build index 39be8fec8567..a801c54ff4f4 100644 --- a/src/android/mm/meson.build +++ b/src/android/mm/meson.build @@ -3,4 +3,7 @@ memory_backend = get_option('android_memory_backend') if memory_backend == 'android_generic' android_hal_sources += files(['android_generic_buffer.cpp']) +elif memory_backend == 'cros_cbm' + android_hal_sources += files(['cros_cbm.cpp']) + android_deps += [ dependency('libcros_camera') ] endif From patchwork Fri Feb 26 13:29:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11405 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 6DAB7BD1F1 for ; Fri, 26 Feb 2021 13:29:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 403A368A87; Fri, 26 Feb 2021 14:29:24 +0100 (CET) Received: from relay12.mail.gandi.net (relay12.mail.gandi.net [217.70.178.232]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2A05368A7D for ; Fri, 26 Feb 2021 14:29:18 +0100 (CET) Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay12.mail.gandi.net (Postfix) with ESMTPSA id E5994200007 for ; Fri, 26 Feb 2021 13:29:17 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Fri, 26 Feb 2021 14:29:32 +0100 Message-Id: <20210226132932.165484-13-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210226132932.165484-1-jacopo@jmondi.org> References: <20210226132932.165484-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 12/12] android: mm: Provide helper macro for PIMPL X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Each memory backend has to declare a CameraBuffer class implementation that bridges the API calls to each CameraBufferImpl implementation. As the code is likely the same for most (if not all) backends, provide a convenience macro that expands to the CameraBuffer class declaration. Signed-off-by: Jacopo Mondi --- src/android/camera_buffer.h | 31 +++++++++++++++++++ src/android/mm/android_generic_buffer.cpp | 35 +--------------------- src/android/mm/cros_cbm.cpp | 36 +---------------------- 3 files changed, 33 insertions(+), 69 deletions(-) diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h index b251e4514864..e7f50a4622f9 100644 --- a/src/android/camera_buffer.h +++ b/src/android/camera_buffer.h @@ -30,4 +30,35 @@ private: CameraBufferImpl *impl_; }; +#define CAMERA_BUFFER_PIMPL \ + CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags) \ + : impl_(new CameraBuffer::CameraBufferImpl(camera3Buffer, \ + flags)) \ + { \ + } \ + CameraBuffer::~CameraBuffer() \ + { \ + delete impl_; \ + } \ + bool CameraBuffer::isValid() const \ + { \ + return impl_->isValid(); \ + } \ + unsigned int CameraBuffer::numPlanes() const \ + { \ + return impl_->numPlanes(); \ + } \ + ssize_t CameraBuffer::planeSize(unsigned int plane) const \ + { \ + return impl_->planeSize(plane); \ + } \ + const uint8_t *CameraBuffer::plane(unsigned int plane) const \ + { \ + return impl_->plane(plane); \ + } \ + uint8_t *CameraBuffer::plane(unsigned int plane) \ + { \ + return impl_->plane(plane); \ + } + #endif /* __ANDROID_CAMERA_BUFFER_H__ */ diff --git a/src/android/mm/android_generic_buffer.cpp b/src/android/mm/android_generic_buffer.cpp index 10a43a61bd4d..2f532be83cc9 100644 --- a/src/android/mm/android_generic_buffer.cpp +++ b/src/android/mm/android_generic_buffer.cpp @@ -89,37 +89,4 @@ uint8_t *CameraBuffer::CameraBufferImpl::plane(unsigned int plane) return maps_[plane].data(); } -CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags) - : impl_(new CameraBuffer::CameraBufferImpl(camera3Buffer, flags)) -{ -} - -CameraBuffer::~CameraBuffer() -{ - delete impl_; -} - -bool CameraBuffer::isValid() const -{ - return impl_->isValid(); -} - -unsigned int CameraBuffer::numPlanes() const -{ - return impl_->numPlanes(); -} - -ssize_t CameraBuffer::planeSize(unsigned int plane) const -{ - return impl_->planeSize(plane); -} - -const uint8_t *CameraBuffer::plane(unsigned int plane) const -{ - return impl_->plane(plane); -} - -uint8_t *CameraBuffer::plane(unsigned int plane) -{ - return impl_->plane(plane); -} +CAMERA_BUFFER_PIMPL diff --git a/src/android/mm/cros_cbm.cpp b/src/android/mm/cros_cbm.cpp index 6c931c99d2d0..ad18aede663a 100644 --- a/src/android/mm/cros_cbm.cpp +++ b/src/android/mm/cros_cbm.cpp @@ -130,38 +130,4 @@ uint8_t *CameraBuffer::CameraBufferImpl::plane(unsigned int plane) return static_cast(addr); } -CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags) - : impl_(new CameraBuffer::CameraBufferImpl(camera3Buffer, flags)) -{ -} - -CameraBuffer::~CameraBuffer() -{ - delete impl_; -} - -bool CameraBuffer::isValid() const -{ - return impl_->isValid(); -} - -unsigned int CameraBuffer::numPlanes() const -{ - return impl_->numPlanes(); -} - -ssize_t CameraBuffer::planeSize(unsigned int plane) const -{ - return impl_->planeSize(plane); -} - -const uint8_t *CameraBuffer::plane(unsigned int plane) const -{ - return impl_->plane(plane); -} - -uint8_t *CameraBuffer::plane(unsigned int plane) -{ - return impl_->plane(plane); -} - +CAMERA_BUFFER_PIMPL