From patchwork Mon Mar 1 15:01:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11419 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 7F091BD808 for ; Mon, 1 Mar 2021 15:00:52 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5C5E768A91; Mon, 1 Mar 2021 16:00:52 +0100 (CET) Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6F3A068A69 for ; Mon, 1 Mar 2021 16:00:50 +0100 (CET) X-Originating-IP: 93.61.96.190 Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 1182F40015; Mon, 1 Mar 2021 15:00:48 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Mar 2021 16:01:02 +0100 Message-Id: <20210301150111.61791-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210301150111.61791-1-jacopo@jmondi.org> References: <20210301150111.61791-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 01/10] meson: options: Add option to select the Android platform 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: , Cc: Han-lin Chen , Daniel Hung-yu Wu Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The Android Camera3 HAL implementation requires platform specific extensions, such as the selection of the memory backend to use and additional constraints depending on the target device. Define a combo option to select which platform to target and define the currently existing implementation as 'generic'. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Reviewed-by: Paul Elder --- meson_options.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/meson_options.txt b/meson_options.txt index 53f2675e99e2..d840543b01f5 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -5,6 +5,12 @@ option('android', value : 'disabled', description : 'Compile libcamera with Android Camera3 HAL interface') +option('android_platform', + type : 'combo', + choices : ['generic'], + value : 'generic', + description : 'Select the Android platform to compile for') + option('documentation', type : 'feature', description : 'Generate the project documentation') From patchwork Mon Mar 1 15:01:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11420 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 9D59EBD808 for ; Mon, 1 Mar 2021 15:00:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7A87E68A69; Mon, 1 Mar 2021 16:00:54 +0100 (CET) Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 36E2460521 for ; Mon, 1 Mar 2021 16:00:52 +0100 (CET) X-Originating-IP: 93.61.96.190 Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 9EECE4000D; Mon, 1 Mar 2021 15:00:50 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Mar 2021 16:01:03 +0100 Message-Id: <20210301150111.61791-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210301150111.61791-1-jacopo@jmondi.org> References: <20210301150111.61791-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 02/10] 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: , Cc: Han-lin Chen , Daniel Hung-yu Wu 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 and rename it in CameraBuffer. 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. Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- src/android/camera_buffer.h | 21 +++++++++++ src/android/camera_device.cpp | 34 +---------------- src/android/camera_device.h | 7 +--- src/android/meson.build | 2 + src/android/mm/generic_camera_buffer.cpp | 47 ++++++++++++++++++++++++ src/android/mm/meson.build | 6 +++ 6 files changed, 79 insertions(+), 38 deletions(-) create mode 100644 src/android/camera_buffer.h create mode 100644 src/android/mm/generic_camera_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..00b061502d6e --- /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 CameraBuffer : public libcamera::MappedBuffer +{ +public: + 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 16cb8c6d2b84..f47f28b8c7ee 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 * @@ -1892,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/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 9719c42b65c6..7004d32d4b23 100644 --- a/src/android/meson.build +++ b/src/android/meson.build @@ -52,6 +52,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/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp new file mode 100644 index 000000000000..bd9152cf9a16 --- /dev/null +++ b/src/android/mm/generic_camera_buffer.cpp @@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Google Inc. + * + * generic_camera_buffer.cpp - Generic Android frame buffer backend + */ + +#include "../camera_buffer.h" + +#include "libcamera/internal/log.h" + +using namespace libcamera; + +LOG_DECLARE_CATEGORY(HAL) + +CameraBuffer::CameraBuffer(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)); + } +} + +CameraBuffer::~CameraBuffer() +{ +} diff --git a/src/android/mm/meson.build b/src/android/mm/meson.build new file mode 100644 index 000000000000..97f83f2a7380 --- /dev/null +++ b/src/android/mm/meson.build @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: CC0-1.0 + +platform = get_option('android_platform') +if platform == 'generic' + android_hal_sources += files(['generic_camera_buffer.cpp']) +endif From patchwork Mon Mar 1 15:01:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11421 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 1050BBD808 for ; Mon, 1 Mar 2021 15:00:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DFBB768A95; Mon, 1 Mar 2021 16:00:56 +0100 (CET) Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8EB3A60521 for ; Mon, 1 Mar 2021 16:00:55 +0100 (CET) X-Originating-IP: 93.61.96.190 Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 60C5F40003; Mon, 1 Mar 2021 15:00:52 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Mar 2021 16:01:04 +0100 Message-Id: <20210301150111.61791-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210301150111.61791-1-jacopo@jmondi.org> References: <20210301150111.61791-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 03/10] 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: , Cc: Han-lin Chen , Daniel Hung-yu Wu 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. Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- src/android/camera_buffer.h | 2 +- src/android/mm/generic_camera_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/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp index bd9152cf9a16..d1407f9cddf4 100644 --- a/src/android/mm/generic_camera_buffer.cpp +++ b/src/android/mm/generic_camera_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 Mon Mar 1 15:01:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11422 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 3C497BD808 for ; Mon, 1 Mar 2021 15:00:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 187BA68A98; Mon, 1 Mar 2021 16:00:59 +0100 (CET) Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 05D8C60521 for ; Mon, 1 Mar 2021 16:00:58 +0100 (CET) X-Originating-IP: 93.61.96.190 Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id E607A4002C; Mon, 1 Mar 2021 15:00:55 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Mar 2021 16:01:05 +0100 Message-Id: <20210301150111.61791-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210301150111.61791-1-jacopo@jmondi.org> References: <20210301150111.61791-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 04/10] 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: , Cc: Han-lin Chen , Daniel Hung-yu Wu 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. Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- 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 Mon Mar 1 15:01:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11423 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 B35ABBD808 for ; Mon, 1 Mar 2021 15:01:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 90A8068A91; Mon, 1 Mar 2021 16:01:01 +0100 (CET) Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BCA9060521 for ; Mon, 1 Mar 2021 16:00:59 +0100 (CET) X-Originating-IP: 93.61.96.190 Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 2F5F54000F; Mon, 1 Mar 2021 15:00:58 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Mar 2021 16:01:06 +0100 Message-Id: <20210301150111.61791-6-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210301150111.61791-1-jacopo@jmondi.org> References: <20210301150111.61791-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 05/10] 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: , Cc: Han-lin Chen , Daniel Hung-yu Wu 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..b2f03b505199 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, + buffer_handle_t camera3Dest, const CameraMetadata &requestMetadata, CameraMetadata *resultMetadata) { if (!postProcessor_) return 0; - return postProcessor_->process(source, destination, - requestMetadata, resultMetadata); + /* + * \todo Buffer mapping and processing 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..f68fdd3a17cd 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, + buffer_handle_t camera3Dest, const CameraMetadata &requestMetadata, CameraMetadata *resultMetadata); libcamera::FrameBuffer *getBuffer(); From patchwork Mon Mar 1 15:01:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11424 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 D4F96BD808 for ; Mon, 1 Mar 2021 15:01:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AF4FA68A95; Mon, 1 Mar 2021 16:01:03 +0100 (CET) Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 782B060521 for ; Mon, 1 Mar 2021 16:01:01 +0100 (CET) X-Originating-IP: 93.61.96.190 Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id E803140012; Mon, 1 Mar 2021 15:00:59 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Mar 2021 16:01:07 +0100 Message-Id: <20210301150111.61791-7-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210301150111.61791-1-jacopo@jmondi.org> References: <20210301150111.61791-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 06/10] android: camera_buffer: Implement libcamera::Extensible 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: , Cc: Han-lin Chen , Daniel Hung-yu Wu 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 by inheriting from the libcamera::Extensible 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 Reviewed-by: Laurent Pinchart --- src/android/camera_buffer.h | 14 ++++- src/android/mm/generic_camera_buffer.cpp | 74 +++++++++++++++++++++++- 2 files changed, 86 insertions(+), 2 deletions(-) diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h index 0590cd84652b..ca4f4527c690 100644 --- a/src/android/camera_buffer.h +++ b/src/android/camera_buffer.h @@ -9,13 +9,25 @@ #include +#include #include +#include -class CameraBuffer : public libcamera::MappedBuffer +class CameraBuffer final : public libcamera::Extensible, + public libcamera::MappedBuffer { + LIBCAMERA_DECLARE_PRIVATE(CameraBuffer) + public: CameraBuffer(buffer_handle_t camera3Buffer, int flags); ~CameraBuffer(); + + bool isValid() const; + + unsigned int numPlanes() const; + + libcamera::Span plane(unsigned int plane) const; + libcamera::Span plane(unsigned int plane); }; #endif /* __ANDROID_CAMERA_BUFFER_H__ */ diff --git a/src/android/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp index d1407f9cddf4..eedf16b76542 100644 --- a/src/android/mm/generic_camera_buffer.cpp +++ b/src/android/mm/generic_camera_buffer.cpp @@ -13,7 +13,25 @@ using namespace libcamera; LOG_DECLARE_CATEGORY(HAL) -CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags) +class CameraBuffer::Private : public Extensible::Private, + public libcamera::MappedBuffer +{ + LIBCAMERA_DECLARE_PUBLIC(CameraBuffer) + +public: + Private(CameraBuffer *cameraBuffer, + buffer_handle_t camera3Buffer, int flags); + ~Private(); + + unsigned int numPlanes() const; + + Span plane(unsigned int plane) const; + Span plane(unsigned int plane); +}; + +CameraBuffer::Private::Private(CameraBuffer *cameraBuffer, + buffer_handle_t camera3Buffer, int flags) + : Extensible::Private(cameraBuffer) { maps_.reserve(camera3Buffer->numFds); error_ = 0; @@ -42,6 +60,60 @@ CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags) } } +CameraBuffer::Private::~Private() +{ +} + +unsigned int CameraBuffer::Private::numPlanes() const +{ + return maps_.size(); +} + +Span CameraBuffer::Private::plane(unsigned int plane) const +{ + if (plane >= maps_.size()) + return {}; + + return maps_[plane]; +} + +Span CameraBuffer::Private::plane(unsigned int plane) +{ + if (plane >= maps_.size()) + return {}; + + return maps_[plane]; +} + +CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags) + : Extensible(new Private(this, camera3Buffer, flags)) +{ +} + CameraBuffer::~CameraBuffer() { } + +bool CameraBuffer::isValid() const +{ + const Private *const d = LIBCAMERA_D_PTR(); + return d->isValid(); +} + +unsigned int CameraBuffer::numPlanes() const +{ + const Private *const d = LIBCAMERA_D_PTR(); + return d->numPlanes(); +} + +Span CameraBuffer::plane(unsigned int plane) const +{ + const Private *const d = LIBCAMERA_D_PTR(); + return d->plane(plane); +} + +Span CameraBuffer::plane(unsigned int plane) +{ + Private *const d = LIBCAMERA_D_PTR(); + return d->plane(plane); +} From patchwork Mon Mar 1 15:01:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11425 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 37A8CBD80C for ; Mon, 1 Mar 2021 15:01:04 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E1A4C68A98; Mon, 1 Mar 2021 16:01:03 +0100 (CET) Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5308868A7D for ; Mon, 1 Mar 2021 16:01:03 +0100 (CET) X-Originating-IP: 93.61.96.190 Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id ADE3140010; Mon, 1 Mar 2021 15:01:01 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Mar 2021 16:01:08 +0100 Message-Id: <20210301150111.61791-8-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210301150111.61791-1-jacopo@jmondi.org> References: <20210301150111.61791-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 07/10] 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: , Cc: Han-lin Chen , Daniel Hung-yu Wu 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 | 4 +--- src/android/jpeg/post_processor_jpeg.cpp | 25 ++++++++---------------- src/android/jpeg/post_processor_jpeg.h | 2 +- src/android/mm/generic_camera_buffer.cpp | 1 + src/android/post_processor.h | 4 +++- src/android/yuv/post_processor_yuv.cpp | 20 +++++++++---------- src/android/yuv/post_processor_yuv.h | 6 ++++-- 7 files changed, 28 insertions(+), 34 deletions(-) diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h index ca4f4527c690..2311cdaf96b2 100644 --- a/src/android/camera_buffer.h +++ b/src/android/camera_buffer.h @@ -10,11 +10,9 @@ #include #include -#include #include -class CameraBuffer final : public libcamera::Extensible, - public libcamera::MappedBuffer +class CameraBuffer final : public libcamera::Extensible { LIBCAMERA_DECLARE_PRIVATE(CameraBuffer) diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp index ab5b63844067..83244ce6769e 100644 --- a/src/android/jpeg/post_processor_jpeg.cpp +++ b/src/android/jpeg/post_processor_jpeg.cpp @@ -83,13 +83,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,28 +174,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), 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() - - sizeof(struct camera3_jpeg_blob); + /* Fill in the JPEG blob header. */ + uint8_t *resultPtr = destination->plane(0).data() + + destination->plane(0).size() + - sizeof(struct camera3_jpeg_blob); auto *blob = reinterpret_cast(resultPtr); blob->jpeg_blob_id = CAMERA3_JPEG_BLOB_ID; blob->jpeg_size = jpeg_size; 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/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp index eedf16b76542..ea85be805260 100644 --- a/src/android/mm/generic_camera_buffer.cpp +++ b/src/android/mm/generic_camera_buffer.cpp @@ -7,6 +7,7 @@ #include "../camera_buffer.h" +#include #include "libcamera/internal/log.h" using namespace libcamera; 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..b67364c8f147 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).data(), destinationStride_[0], - destination->maps()[1].data(), + destination->plane(1).data(), 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.plane(0).size() < destinationLength_[0] || + destination.plane(1).size() < destinationLength_[1]) { LOG(YUV, Error) << "The destination planes lengths are too small, actual size: {" - << destination.maps()[0].size() << ", " - << destination.maps()[1].size() + << destination.plane(0).size() << ", " + << destination.plane(1).size() << "}, 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..94620dd0a870 100644 --- a/src/android/yuv/post_processor_yuv.h +++ b/src/android/yuv/post_processor_yuv.h @@ -9,6 +9,8 @@ #include "../post_processor.h" +#include "../camera_buffer.h" + #include class CameraDevice; @@ -21,13 +23,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 Mon Mar 1 15:01:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11426 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 411DFBD808 for ; Mon, 1 Mar 2021 15:01:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1E28368A91; Mon, 1 Mar 2021 16:01:07 +0100 (CET) Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AAD4668A69 for ; Mon, 1 Mar 2021 16:01:05 +0100 (CET) X-Originating-IP: 93.61.96.190 Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 8A34340018; Mon, 1 Mar 2021 15:01:03 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Mar 2021 16:01:09 +0100 Message-Id: <20210301150111.61791-9-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210301150111.61791-1-jacopo@jmondi.org> References: <20210301150111.61791-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 08/10] 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: , Cc: Han-lin Chen , Daniel Hung-yu Wu 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 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/android/jpeg/post_processor_jpeg.cpp b/src/android/jpeg/post_processor_jpeg.cpp index 83244ce6769e..65ab6b196ad1 100644 --- a/src/android/jpeg/post_processor_jpeg.cpp +++ b/src/android/jpeg/post_processor_jpeg.cpp @@ -182,8 +182,16 @@ int PostProcessorJpeg::process(const FrameBuffer &source, } /* Fill in the JPEG blob header. */ - uint8_t *resultPtr = destination->plane(0).data() - + destination->plane(0).size() + /* + * \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->plane(0).size()); + uint8_t *resultPtr = destination->plane(0).data() + blobSize - sizeof(struct camera3_jpeg_blob); auto *blob = reinterpret_cast(resultPtr); blob->jpeg_blob_id = CAMERA3_JPEG_BLOB_ID; From patchwork Mon Mar 1 15:01:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11427 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 7211EBD808 for ; Mon, 1 Mar 2021 15:01:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4D5C668A7D; Mon, 1 Mar 2021 16:01:08 +0100 (CET) Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3304F68A94 for ; Mon, 1 Mar 2021 16:01:07 +0100 (CET) X-Originating-IP: 93.61.96.190 Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id DDCDD40003; Mon, 1 Mar 2021 15:01:05 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Mar 2021 16:01:10 +0100 Message-Id: <20210301150111.61791-10-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210301150111.61791-1-jacopo@jmondi.org> References: <20210301150111.61791-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 09/10] 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: , Cc: Han-lin Chen , Daniel Hung-yu Wu 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 Reviewed-by: Laurent Pinchart --- src/android/camera_buffer.h | 28 ++++++++++++++++++++ src/android/mm/generic_camera_buffer.cpp | 33 +----------------------- 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/android/camera_buffer.h b/src/android/camera_buffer.h index 2311cdaf96b2..ea73bf5b0ede 100644 --- a/src/android/camera_buffer.h +++ b/src/android/camera_buffer.h @@ -28,4 +28,32 @@ public: libcamera::Span plane(unsigned int plane); }; +#define PUBLIC_CAMERA_BUFFER \ +CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags) \ + : Extensible(new Private(this, camera3Buffer, flags)) \ +{ \ +} \ +CameraBuffer::~CameraBuffer() \ +{ \ +} \ +bool CameraBuffer::isValid() const \ +{ \ + const Private *const d = LIBCAMERA_D_PTR(); \ + return d->isValid(); \ +} \ +unsigned int CameraBuffer::numPlanes() const \ +{ \ + const Private *const d = LIBCAMERA_D_PTR(); \ + return d->numPlanes(); \ +} \ +Span CameraBuffer::plane(unsigned int plane) const \ +{ \ + const Private *const d = LIBCAMERA_D_PTR(); \ + return d->plane(plane); \ +} \ +Span CameraBuffer::plane(unsigned int plane) \ +{ \ + Private *const d = LIBCAMERA_D_PTR(); \ + return d->plane(plane); \ +} #endif /* __ANDROID_CAMERA_BUFFER_H__ */ diff --git a/src/android/mm/generic_camera_buffer.cpp b/src/android/mm/generic_camera_buffer.cpp index ea85be805260..5ea1339bc0ec 100644 --- a/src/android/mm/generic_camera_buffer.cpp +++ b/src/android/mm/generic_camera_buffer.cpp @@ -86,35 +86,4 @@ Span CameraBuffer::Private::plane(unsigned int plane) return maps_[plane]; } -CameraBuffer::CameraBuffer(buffer_handle_t camera3Buffer, int flags) - : Extensible(new Private(this, camera3Buffer, flags)) -{ -} - -CameraBuffer::~CameraBuffer() -{ -} - -bool CameraBuffer::isValid() const -{ - const Private *const d = LIBCAMERA_D_PTR(); - return d->isValid(); -} - -unsigned int CameraBuffer::numPlanes() const -{ - const Private *const d = LIBCAMERA_D_PTR(); - return d->numPlanes(); -} - -Span CameraBuffer::plane(unsigned int plane) const -{ - const Private *const d = LIBCAMERA_D_PTR(); - return d->plane(plane); -} - -Span CameraBuffer::plane(unsigned int plane) -{ - Private *const d = LIBCAMERA_D_PTR(); - return d->plane(plane); -} +PUBLIC_CAMERA_BUFFER From patchwork Mon Mar 1 15:01:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 11428 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 A7106BD808 for ; Mon, 1 Mar 2021 15:01:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 811BF68A7D; Mon, 1 Mar 2021 16:01:10 +0100 (CET) Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A418F68A94 for ; Mon, 1 Mar 2021 16:01:08 +0100 (CET) X-Originating-IP: 93.61.96.190 Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) (Authenticated sender: jacopo@jmondi.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 5F0D440010; Mon, 1 Mar 2021 15:01:07 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Mon, 1 Mar 2021 16:01:11 +0100 Message-Id: <20210301150111.61791-11-jacopo@jmondi.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210301150111.61791-1-jacopo@jmondi.org> References: <20210301150111.61791-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 10/10] android: Introduce Chromium OS buffer manager 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: , Cc: Han-lin Chen , Daniel Hung-yu Wu Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Introduce the CameraBuffer backend for the Chromium OS operating system and the associated meson option. The Chromium OS CameraBuffer implementation uses the cros::CameraBufferManager class to perform mapping of 1 plane and multiplane buffers and to retrieve size information. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- meson_options.txt | 2 +- src/android/mm/cros_camera_buffer.cpp | 141 ++++++++++++++++++++++++++ src/android/mm/meson.build | 3 + 3 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 src/android/mm/cros_camera_buffer.cpp diff --git a/meson_options.txt b/meson_options.txt index d840543b01f5..870914662f3e 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -7,7 +7,7 @@ option('android', option('android_platform', type : 'combo', - choices : ['generic'], + choices : ['generic', 'cros'], value : 'generic', description : 'Select the Android platform to compile for') diff --git a/src/android/mm/cros_camera_buffer.cpp b/src/android/mm/cros_camera_buffer.cpp new file mode 100644 index 000000000000..1103f4423c2f --- /dev/null +++ b/src/android/mm/cros_camera_buffer.cpp @@ -0,0 +1,141 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2021, Google Inc. + * + * cros_camera_buffer.cpp - Chromium OS buffer backend using CameraBufferManager + */ + +#include "../camera_buffer.h" + +#include "libcamera/internal/log.h" +#include + +#include "cros-camera/camera_buffer_manager.h" + +using namespace libcamera; + +LOG_DECLARE_CATEGORY(HAL) + +class CameraBuffer::Private : public Extensible::Private +{ + LIBCAMERA_DECLARE_PUBLIC(CameraBuffer) + +public: + Private(CameraBuffer *cameraBuffer, + buffer_handle_t camera3Buffer, int flags); + ~Private(); + + bool isValid() const { return valid_; } + + unsigned int numPlanes() const; + + Span plane(unsigned int plane) const; + Span plane(unsigned int plane); + +private: + cros::CameraBufferManager *bufferManager_; + buffer_handle_t handle_; + unsigned int numPlanes_; + bool valid_; + union { + void *addr; + android_ycbcr ycbcr; + } mem; + + const uint8_t *planeAddr(unsigned int plane) const; + uint8_t *planeAddr(unsigned int plane); +}; + +CameraBuffer::Private::Private(CameraBuffer *cameraBuffer, + buffer_handle_t camera3Buffer, int flags) + : Extensible::Private(cameraBuffer), 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::Private::~Private() +{ + bufferManager_->Unlock(handle_); + bufferManager_->Deregister(handle_); +} + +unsigned int CameraBuffer::Private::numPlanes() const +{ + return bufferManager_->GetNumPlanes(handle_); +} + +Span CameraBuffer::Private::plane(unsigned int plane) const +{ + const uint8_t *addr = planeAddr(plane); + return { addr, bufferManager_->GetPlaneSize(handle_, plane) }; +} + +Span CameraBuffer::Private::plane(unsigned int plane) +{ + uint8_t *addr = planeAddr(plane); + return { addr, bufferManager_->GetPlaneSize(handle_, plane) }; +} + +const uint8_t *CameraBuffer::Private::planeAddr(unsigned int plane) const +{ + const 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); +} + +uint8_t *CameraBuffer::Private::planeAddr(unsigned int plane) +{ + const CameraBuffer::Private *self = + const_cast(this); + return const_cast(self->planeAddr(plane)); +} + +PUBLIC_CAMERA_BUFFER diff --git a/src/android/mm/meson.build b/src/android/mm/meson.build index 97f83f2a7380..eeb5cc2e6a31 100644 --- a/src/android/mm/meson.build +++ b/src/android/mm/meson.build @@ -3,4 +3,7 @@ platform = get_option('android_platform') if platform == 'generic' android_hal_sources += files(['generic_camera_buffer.cpp']) +elif platform == 'cros' + android_hal_sources += files(['cros_camera_buffer.cpp']) + android_deps += [dependency('libcros_camera')] endif