From patchwork Wed Oct 7 10:17:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9993 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 B30CBBEEDF for ; Wed, 7 Oct 2020 10:13:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 95630603C1; Wed, 7 Oct 2020 12:13:53 +0200 (CEST) Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 79F6460393 for ; Wed, 7 Oct 2020 12:13:52 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 9F80460005; Wed, 7 Oct 2020 10:13:51 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 7 Oct 2020 12:17:33 +0200 Message-Id: <20201007101745.15104-2-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201007101745.15104-1-jacopo@jmondi.org> References: <20201007101745.15104-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 01/13] android: camera_stream: Break out 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" Break CameraStream out of the CameraDevice class. No functional changes, only the code is moved. Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 6 ------ src/android/camera_device.h | 24 +-------------------- src/android/camera_stream.cpp | 18 ++++++++++++++++ src/android/camera_stream.h | 40 +++++++++++++++++++++++++++++++++++ src/android/meson.build | 1 + 5 files changed, 60 insertions(+), 29 deletions(-) create mode 100644 src/android/camera_stream.cpp create mode 100644 src/android/camera_stream.h diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 751699cd2113..bbc692fe109f 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -169,12 +169,6 @@ MappedCamera3Buffer::MappedCamera3Buffer(const buffer_handle_t camera3buffer, } } -CameraStream::CameraStream(PixelFormat format, Size size, - unsigned int index, Encoder *encoder) - : format_(format), size_(size), index_(index), encoder_(encoder) -{ -} - /* * \struct Camera3RequestDescriptor * diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 1837748d2efc..52923ec979a7 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -23,33 +23,11 @@ #include "libcamera/internal/log.h" #include "libcamera/internal/message.h" +#include "camera_stream.h" #include "jpeg/encoder.h" class CameraMetadata; -class CameraStream -{ -public: - CameraStream(libcamera::PixelFormat format, libcamera::Size size, - unsigned int index, Encoder *encoder = nullptr); - - const libcamera::PixelFormat &format() const { return format_; } - const libcamera::Size &size() const { return size_; } - unsigned int index() const { return index_; } - Encoder *encoder() const { return encoder_.get(); } - -private: - libcamera::PixelFormat format_; - libcamera::Size size_; - /* - * The index of the libcamera StreamConfiguration as added during - * configureStreams(). A single libcamera Stream may be used to deliver - * one or more streams to the Android framework. - */ - unsigned int index_; - std::unique_ptr encoder_; -}; - class CameraDevice : protected libcamera::Loggable { public: diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp new file mode 100644 index 000000000000..cd9084aeb51b --- /dev/null +++ b/src/android/camera_stream.cpp @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2020, Google Inc. + * + * camera_stream.cpp - Camera HAL stream + */ + +#include "camera_stream.h" + +#include "jpeg/encoder.h" + +using namespace libcamera; + +CameraStream::CameraStream(PixelFormat format, Size size, + unsigned int index, Encoder *encoder) + : format_(format), size_(size), index_(index), encoder_(encoder) +{ +} diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h new file mode 100644 index 000000000000..0de6b6fc6f8c --- /dev/null +++ b/src/android/camera_stream.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2020, Google Inc. + * + * camera_stream.h - Camera HAL stream + */ +#ifndef __ANDROID_CAMERA_STREAM_H__ +#define __ANDROID_CAMERA_STREAM_H__ + +#include + +#include +#include + +class Encoder; + +class CameraStream +{ +public: + CameraStream(libcamera::PixelFormat format, libcamera::Size size, + unsigned int index, Encoder *encoder = nullptr); + + const libcamera::PixelFormat &format() const { return format_; } + const libcamera::Size &size() const { return size_; } + unsigned int index() const { return index_; } + Encoder *encoder() const { return encoder_.get(); } + +private: + libcamera::PixelFormat format_; + libcamera::Size size_; + /* + * The index of the libcamera StreamConfiguration as added during + * configureStreams(). A single libcamera Stream may be used to deliver + * one or more streams to the Android framework. + */ + unsigned int index_; + std::unique_ptr encoder_; +}; + +#endif /* __ANDROID_CAMERA_STREAM__ */ diff --git a/src/android/meson.build b/src/android/meson.build index 0293c2036561..802bb89afe57 100644 --- a/src/android/meson.build +++ b/src/android/meson.build @@ -20,6 +20,7 @@ android_hal_sources = files([ 'camera_device.cpp', 'camera_metadata.cpp', 'camera_ops.cpp', + 'camera_stream.cpp', 'jpeg/encoder_libjpeg.cpp', 'jpeg/exif.cpp', ]) From patchwork Wed Oct 7 10:17:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9994 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 D1308BEEDF for ; Wed, 7 Oct 2020 10:13:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AD1266053B; Wed, 7 Oct 2020 12:13:55 +0200 (CEST) Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2B91360455 for ; Wed, 7 Oct 2020 12:13:54 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 9C1E960014; Wed, 7 Oct 2020 10:13:52 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 7 Oct 2020 12:17:34 +0200 Message-Id: <20201007101745.15104-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201007101745.15104-1-jacopo@jmondi.org> References: <20201007101745.15104-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 02/13] android: camera_stream: Add CameraStream::Type 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" Define the CameraStream::Type enumeration and assign it to each CameraStream instance at construction time. The CameraStream type will be used to decide if memory needs to be allocated on its behalf or if the stream is backed by memory externally allocated by the Android framework. Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Hirokazu Honda Reviewed-by: Niklas Söderlund Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 8 +++- src/android/camera_stream.cpp | 4 +- src/android/camera_stream.h | 86 ++++++++++++++++++++++++++++++++++- 3 files changed, 93 insertions(+), 5 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index bbc692fe109f..0600ebc81c64 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1216,12 +1216,14 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) config_->addConfiguration(streamConfiguration); unsigned int index = config_->size() - 1; - streams_.emplace_back(format, size, index); + streams_.emplace_back(format, size, CameraStream::Type::Direct, + index); stream->priv = static_cast(&streams_.back()); } /* Now handle the MJPEG streams, adding a new stream if required. */ if (jpegStream) { + CameraStream::Type type; int index = -1; /* Search for a compatible stream in the non-JPEG ones. */ @@ -1239,6 +1241,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) LOG(HAL, Info) << "Android JPEG stream mapped to libcamera stream " << i; + type = CameraStream::Type::Mapped; index = i; break; } @@ -1263,6 +1266,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) LOG(HAL, Info) << "Adding " << streamConfiguration.toString() << " for MJPEG support"; + type = CameraStream::Type::Internal; config_->addConfiguration(streamConfiguration); index = config_->size() - 1; } @@ -1281,7 +1285,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) return ret; } - streams_.emplace_back(formats::MJPEG, cfg.size, index, encoder); + streams_.emplace_back(formats::MJPEG, cfg.size, type, index, encoder); jpegStream->priv = static_cast(&streams_.back()); } diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index cd9084aeb51b..7205721dbeb9 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -12,7 +12,7 @@ using namespace libcamera; CameraStream::CameraStream(PixelFormat format, Size size, - unsigned int index, Encoder *encoder) - : format_(format), size_(size), index_(index), encoder_(encoder) + Type type, unsigned int index, Encoder *encoder) + : format_(format), size_(size), type_(type), index_(index), encoder_(encoder) { } diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index 0de6b6fc6f8c..e54276868a19 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -17,17 +17,101 @@ class Encoder; class CameraStream { public: + /* + * Enumeration of CameraStream types. + * + * A camera stream associates an Android stream to a libcamera stream. + * This enumeration describes how the two streams are associated and how + * and where data produced from libcamera are delivered to the + * Android framework. + * + * Direct: + * + * The Android stream is directly mapped onto a libcamera stream: frames + * are delivered by the library directly in the memory location + * specified by the Android stream (buffer_handle_t->data) and provided + * to the framework as they are. The Android stream characteristics are + * directly translated to the libcamera stream configuration. + * + * +-----+ +-----+ + * | A | | L | + * +-----+ +-----+ + * | | + * V V + * +-----+ +------+ + * | B |<---------------| FB | + * +-----+ +------+ + * + * + * Internal: + * + * Data for the Android stream is produced by processing a libcamera + * stream created by the HAL for that purpose. The libcamera stream + * needs to be supplied with intermediate buffers where the library + * delivers frames to be processed and then provided to the framework. + * The libcamera stream configuration is not a direct translation of the + * Android stream characteristics, but it describes the format and size + * required for the processing procedure to produce frames in the + * Android required format. + * + * +-----+ +-----+ + * | A | | L | + * +-----+ +-----+ + * | | + * V V + * +-----+ +------+ + * | B | | FB | + * +-----+ +------+ + * ^ | + * |-------Processing------| + * + * + * Mapped: + * + * Data for the Android stream is produced by processing a libcamera + * stream associated with another CameraStream. Mapped camera streams do + * not need any memory to be reserved for them as they process data + * produced by libcamera for a different stream whose format and size + * are compatible with the processing procedure requirements to produce + * frames in the Android required format. + * + * +-----+ +-----+ +-----+ + * | A | | A' | | L | + * +-----+ +-----+ +-----+ + * | | | + * V V V + * +-----+ +-----+ +------+ + * | B | | B' |<---------| FB | + * +-----+ +-----+ +------+ + * ^ | + * |--Processing--| + * + * + * -------------------------------------------------------------------- + * A = Android stream + * L = libcamera stream + * B = memory buffer + * FB = libcamera FrameBuffer + * "Processing" = Frame processing procedure (Encoding, scaling etc) + */ + enum class Type { + Direct, + Internal, + Mapped, + }; CameraStream(libcamera::PixelFormat format, libcamera::Size size, - unsigned int index, Encoder *encoder = nullptr); + Type type, unsigned int index, Encoder *encoder = nullptr); const libcamera::PixelFormat &format() const { return format_; } const libcamera::Size &size() const { return size_; } + Type type() const { return type_; } unsigned int index() const { return index_; } Encoder *encoder() const { return encoder_.get(); } private: libcamera::PixelFormat format_; libcamera::Size size_; + Type type_; /* * The index of the libcamera StreamConfiguration as added during * configureStreams(). A single libcamera Stream may be used to deliver From patchwork Wed Oct 7 10:17:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9995 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 EE874BEEDF for ; Wed, 7 Oct 2020 10:13:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C9FD36039B; Wed, 7 Oct 2020 12:13:56 +0200 (CEST) Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7FAB760396 for ; Wed, 7 Oct 2020 12:13:55 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 539506000D; Wed, 7 Oct 2020 10:13:54 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 7 Oct 2020 12:17:35 +0200 Message-Id: <20201007101745.15104-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201007101745.15104-1-jacopo@jmondi.org> References: <20201007101745.15104-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 03/13] android: camera_stream: Delegate Encoder construction 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" Delegate the construction of the encoder to the CameraStream class for streams that need post-processing. Reviewed-by: Umang Jain Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 23 ++++++++++------------- src/android/camera_stream.cpp | 16 +++++++++++++--- src/android/camera_stream.h | 4 +++- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 0600ebc81c64..9c9a5cfa3c2f 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1273,19 +1273,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) StreamConfiguration &cfg = config_->at(index); - /* - * Construct a software encoder for the MJPEG streams from the - * chosen libcamera source stream. - */ - Encoder *encoder = new EncoderLibJpeg(); - int ret = encoder->configure(cfg); - if (ret) { - LOG(HAL, Error) << "Failed to configure encoder"; - delete encoder; - return ret; - } - - streams_.emplace_back(formats::MJPEG, cfg.size, type, index, encoder); + streams_.emplace_back(formats::MJPEG, cfg.size, type, index); jpegStream->priv = static_cast(&streams_.back()); } @@ -1306,11 +1294,20 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) return -EINVAL; } + /* + * Configure the HAL CameraStream instances using the associated + * StreamConfiguration and set the number of required buffers in + * the Android camera3_stream_t. + */ for (unsigned int i = 0; i < stream_list->num_streams; ++i) { camera3_stream_t *stream = stream_list->streams[i]; CameraStream *cameraStream = static_cast(stream->priv); StreamConfiguration &cfg = config_->at(cameraStream->index()); + int ret = cameraStream->configure(cfg); + if (ret) + return ret; + /* Use the bufferCount confirmed by the validation process. */ stream->max_buffers = cfg.bufferCount; } diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index 7205721dbeb9..2d0c6ff99ac6 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -8,11 +8,21 @@ #include "camera_stream.h" #include "jpeg/encoder.h" +#include "jpeg/encoder_libjpeg.h" using namespace libcamera; -CameraStream::CameraStream(PixelFormat format, Size size, - Type type, unsigned int index, Encoder *encoder) - : format_(format), size_(size), type_(type), index_(index), encoder_(encoder) +CameraStream::CameraStream(PixelFormat format, Size size, Type type, unsigned int index) + : format_(format), size_(size), type_(type), index_(index) { + if (type_ == Type::Internal || type_ == Type::Mapped) + encoder_ = std::make_unique(); +} + +int CameraStream::configure(const libcamera::StreamConfiguration &cfg) +{ + if (encoder_) + return encoder_->configure(cfg); + + return 0; } diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index e54276868a19..2f49d3d41a7f 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -100,7 +100,7 @@ public: Mapped, }; CameraStream(libcamera::PixelFormat format, libcamera::Size size, - Type type, unsigned int index, Encoder *encoder = nullptr); + Type type, unsigned int index); const libcamera::PixelFormat &format() const { return format_; } const libcamera::Size &size() const { return size_; } @@ -108,6 +108,8 @@ public: unsigned int index() const { return index_; } Encoder *encoder() const { return encoder_.get(); } + int configure(const libcamera::StreamConfiguration &cfg); + private: libcamera::PixelFormat format_; libcamera::Size size_; From patchwork Wed Oct 7 10:17:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9996 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 1D49CBEEE1 for ; Wed, 7 Oct 2020 10:13:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id ED98C6054D; Wed, 7 Oct 2020 12:13:56 +0200 (CEST) Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2E71E60396 for ; Wed, 7 Oct 2020 12:13:56 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id A5E1C60005; Wed, 7 Oct 2020 10:13:55 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 7 Oct 2020 12:17:36 +0200 Message-Id: <20201007101745.15104-5-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201007101745.15104-1-jacopo@jmondi.org> References: <20201007101745.15104-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 04/13] android: camera_stream: Construct with Android stream 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" Pass the android camera3_stream_t, and a libcamera::StreamConfiguration to identify the source and destination parameters of this stream. Pass a CameraDevice pointer to the CameraStream constructor to allow retrieval of the StreamConfiguration associated with the CameraStream. Also change the format on which the CameraDevice performs checks to decide if post-processing is required, as the libcamera facing format is not meaningful anymore, but the Android requested format should be used instead. Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 11 +++++------ src/android/camera_device.h | 4 ++++ src/android/camera_stream.cpp | 14 ++++++++++++-- src/android/camera_stream.h | 17 +++++++++++++++-- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 9c9a5cfa3c2f..68970eb4a94c 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1216,8 +1216,8 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) config_->addConfiguration(streamConfiguration); unsigned int index = config_->size() - 1; - streams_.emplace_back(format, size, CameraStream::Type::Direct, - index); + streams_.emplace_back(this, stream, streamConfiguration, + CameraStream::Type::Direct, index); stream->priv = static_cast(&streams_.back()); } @@ -1272,8 +1272,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) } StreamConfiguration &cfg = config_->at(index); - - streams_.emplace_back(formats::MJPEG, cfg.size, type, index); + streams_.emplace_back(this, jpegStream, cfg, type, index); jpegStream->priv = static_cast(&streams_.back()); } @@ -1405,7 +1404,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques descriptor->buffers[i].buffer = camera3Buffers[i].buffer; /* Software streams are handled after hardware streams complete. */ - if (cameraStream->format() == formats::MJPEG) + if (cameraStream->camera3Stream().format == HAL_PIXEL_FORMAT_BLOB) continue; /* @@ -1469,7 +1468,7 @@ void CameraDevice::requestComplete(Request *request) CameraStream *cameraStream = static_cast(descriptor->buffers[i].stream->priv); - if (cameraStream->format() != formats::MJPEG) + if (cameraStream->camera3Stream().format != HAL_PIXEL_FORMAT_BLOB) continue; Encoder *encoder = cameraStream->encoder(); diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 52923ec979a7..4e326fa3e1fb 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -43,6 +43,10 @@ public: unsigned int id() const { return id_; } camera3_device_t *camera3Device() { return &camera3Device_; } const libcamera::Camera *camera() const { return camera_.get(); } + libcamera::CameraConfiguration *cameraConfiguration() const + { + return config_.get(); + } int facing() const { return facing_; } int orientation() const { return orientation_; } diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index 2d0c6ff99ac6..b3d345afc61a 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -7,14 +7,24 @@ #include "camera_stream.h" +#include "camera_device.h" #include "jpeg/encoder.h" #include "jpeg/encoder_libjpeg.h" using namespace libcamera; -CameraStream::CameraStream(PixelFormat format, Size size, Type type, unsigned int index) - : format_(format), size_(size), type_(type), index_(index) +CameraStream::CameraStream(CameraDevice *cameraDevice, + camera3_stream_t *camera3Stream, + const libcamera::StreamConfiguration &cfg, + Type type, unsigned int index) + : cameraDevice_(cameraDevice), camera3Stream_(camera3Stream), + type_(type), index_(index) { + config_ = cameraDevice_->cameraConfiguration(); + + format_ = cfg.pixelFormat; + size_ = cfg.size; + if (type_ == Type::Internal || type_ == Type::Mapped) encoder_ = std::make_unique(); } diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index 2f49d3d41a7f..ccc822b4980f 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -9,9 +9,13 @@ #include +#include + +#include #include #include +class CameraDevice; class Encoder; class CameraStream @@ -99,9 +103,12 @@ public: Internal, Mapped, }; - CameraStream(libcamera::PixelFormat format, libcamera::Size size, + CameraStream(CameraDevice *cameraDevice, + camera3_stream_t *androidStream, + const libcamera::StreamConfiguration &cfg, Type type, unsigned int index); + const camera3_stream_t &camera3Stream() const { return *camera3Stream_; } const libcamera::PixelFormat &format() const { return format_; } const libcamera::Size &size() const { return size_; } Type type() const { return type_; } @@ -111,9 +118,15 @@ public: int configure(const libcamera::StreamConfiguration &cfg); private: + CameraDevice *cameraDevice_; + libcamera::CameraConfiguration *config_; + camera3_stream_t *camera3Stream_; + Type type_; + + /* Libcamera facing format and sizes. */ libcamera::PixelFormat format_; libcamera::Size size_; - Type type_; + /* * The index of the libcamera StreamConfiguration as added during * configureStreams(). A single libcamera Stream may be used to deliver From patchwork Wed Oct 7 10:17:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9997 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 7765DBEEDF for ; Wed, 7 Oct 2020 10:13:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5174A6049A; Wed, 7 Oct 2020 12:13:59 +0200 (CEST) Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5931E60546 for ; Wed, 7 Oct 2020 12:13:57 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 5FF7060005; Wed, 7 Oct 2020 10:13:56 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 7 Oct 2020 12:17:37 +0200 Message-Id: <20201007101745.15104-6-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201007101745.15104-1-jacopo@jmondi.org> References: <20201007101745.15104-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 05/13] android: camera_device: Move processing 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" Move the JPEG processing procedure to the individual CameraStream by augmenting the class with a CameraStream::process() method. This allows removing the CameraStream::encoder() method. Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 68 ++--------------------------------- src/android/camera_device.h | 8 +++++ src/android/camera_stream.cpp | 63 ++++++++++++++++++++++++++++++++ src/android/camera_stream.h | 8 +++-- 4 files changed, 80 insertions(+), 67 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 68970eb4a94c..914e66b8f96a 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -23,9 +23,6 @@ #include "camera_metadata.h" #include "system/graphics.h" -#include "jpeg/encoder_libjpeg.h" -#include "jpeg/exif.h" - using namespace libcamera; namespace { @@ -133,12 +130,6 @@ const std::map camera3FormatsMap = { LOG_DECLARE_CATEGORY(HAL); -class MappedCamera3Buffer : public MappedBuffer -{ -public: - MappedCamera3Buffer(const buffer_handle_t camera3buffer, int flags); -}; - MappedCamera3Buffer::MappedCamera3Buffer(const buffer_handle_t camera3buffer, int flags) { @@ -1471,12 +1462,6 @@ void CameraDevice::requestComplete(Request *request) if (cameraStream->camera3Stream().format != HAL_PIXEL_FORMAT_BLOB) continue; - Encoder *encoder = cameraStream->encoder(); - if (!encoder) { - LOG(HAL, Error) << "Failed to identify encoder"; - continue; - } - StreamConfiguration *streamConfiguration = &config_->at(cameraStream->index()); Stream *stream = streamConfiguration->stream(); FrameBuffer *buffer = request->findBuffer(stream); @@ -1497,59 +1482,12 @@ void CameraDevice::requestComplete(Request *request) continue; } - /* Set EXIF metadata for various tags. */ - Exif exif; - /* \todo Set Make and Model from external vendor tags. */ - exif.setMake("libcamera"); - exif.setModel("cameraModel"); - exif.setOrientation(orientation_); - exif.setSize(cameraStream->size()); - /* - * We set the frame's EXIF timestamp as the time of encode. - * Since the precision we need for EXIF timestamp is only one - * second, it is good enough. - */ - exif.setTimestamp(std::time(nullptr)); - if (exif.generate() != 0) - LOG(HAL, Error) << "Failed to generate valid EXIF data"; - - int jpeg_size = encoder->encode(buffer, mapped.maps()[0], exif.data()); - if (jpeg_size < 0) { - LOG(HAL, Error) << "Failed to encode stream image"; + int ret = cameraStream->process(*buffer, &mapped, + resultMetadata.get()); + if (ret) { status = CAMERA3_BUFFER_STATUS_ERROR; continue; } - - /* - * 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 = mapped.maps()[0].data() + - maxJpegBufferSize_ - - sizeof(struct camera3_jpeg_blob); - auto *blob = reinterpret_cast(resultPtr); - blob->jpeg_blob_id = CAMERA3_JPEG_BLOB_ID; - blob->jpeg_size = jpeg_size; - - /* Update the JPEG result Metadata. */ - resultMetadata->addEntry(ANDROID_JPEG_SIZE, - &jpeg_size, 1); - - const uint32_t jpeg_quality = 95; - resultMetadata->addEntry(ANDROID_JPEG_QUALITY, - &jpeg_quality, 1); - - const uint32_t jpeg_orientation = 0; - resultMetadata->addEntry(ANDROID_JPEG_ORIENTATION, - &jpeg_orientation, 1); } /* Prepare to call back the Android camera stack. */ diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 4e326fa3e1fb..826023b453f7 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -20,6 +20,7 @@ #include #include +#include "libcamera/internal/buffer.h" #include "libcamera/internal/log.h" #include "libcamera/internal/message.h" @@ -28,6 +29,12 @@ class CameraMetadata; +class MappedCamera3Buffer : public libcamera::MappedBuffer +{ +public: + MappedCamera3Buffer(const buffer_handle_t camera3buffer, int flags); +}; + class CameraDevice : protected libcamera::Loggable { public: @@ -50,6 +57,7 @@ public: int facing() const { return facing_; } int orientation() const { return orientation_; } + unsigned int maxJpegBufferSize() const { return maxJpegBufferSize_; } void setCallbacks(const camera3_callback_ops_t *callbacks); const camera_metadata_t *getStaticMetadata(); diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index b3d345afc61a..e86a7ba60d46 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -8,11 +8,15 @@ #include "camera_stream.h" #include "camera_device.h" +#include "camera_metadata.h" #include "jpeg/encoder.h" #include "jpeg/encoder_libjpeg.h" +#include "jpeg/exif.h" using namespace libcamera; +LOG_DECLARE_CATEGORY(HAL); + CameraStream::CameraStream(CameraDevice *cameraDevice, camera3_stream_t *camera3Stream, const libcamera::StreamConfiguration &cfg, @@ -36,3 +40,62 @@ int CameraStream::configure(const libcamera::StreamConfiguration &cfg) return 0; } + +int CameraStream::process(const libcamera::FrameBuffer &source, + MappedCamera3Buffer *dest, CameraMetadata *metadata) +{ + if (!encoder_) + return 0; + + /* Set EXIF metadata for various tags. */ + Exif exif; + /* \todo Set Make and Model from external vendor tags. */ + exif.setMake("libcamera"); + exif.setModel("cameraModel"); + exif.setOrientation(cameraDevice_->orientation()); + exif.setSize(size_); + /* + * We set the frame's EXIF timestamp as the time of encode. + * Since the precision we need for EXIF timestamp is only one + * second, it is good enough. + */ + exif.setTimestamp(std::time(nullptr)); + if (exif.generate() != 0) + LOG(HAL, Error) << "Failed to generate valid EXIF data"; + + int jpeg_size = encoder_->encode(&source, dest->maps()[0], exif.data()); + if (jpeg_size < 0) { + LOG(HAL, 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 = dest->maps()[0].data() + + cameraDevice_->maxJpegBufferSize() - + sizeof(struct camera3_jpeg_blob); + auto *blob = reinterpret_cast(resultPtr); + blob->jpeg_blob_id = CAMERA3_JPEG_BLOB_ID; + blob->jpeg_size = jpeg_size; + + /* Update the JPEG result Metadata. */ + metadata->addEntry(ANDROID_JPEG_SIZE, &jpeg_size, 1); + + const uint32_t jpeg_quality = 95; + metadata->addEntry(ANDROID_JPEG_QUALITY, &jpeg_quality, 1); + + const uint32_t jpeg_orientation = 0; + metadata->addEntry(ANDROID_JPEG_ORIENTATION, &jpeg_orientation, 1); + + return 0; +} diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index ccc822b4980f..d95c2a3831b0 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -11,12 +11,15 @@ #include +#include #include #include #include -class CameraDevice; class Encoder; +class CameraDevice; +class CameraMetadata; +class MappedCamera3Buffer; class CameraStream { @@ -113,9 +116,10 @@ public: const libcamera::Size &size() const { return size_; } Type type() const { return type_; } unsigned int index() const { return index_; } - Encoder *encoder() const { return encoder_.get(); } int configure(const libcamera::StreamConfiguration &cfg); + int process(const libcamera::FrameBuffer &source, + MappedCamera3Buffer *dest, CameraMetadata *metadata); private: CameraDevice *cameraDevice_; From patchwork Wed Oct 7 10:17:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9998 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 986BCBEEDF for ; Wed, 7 Oct 2020 10:14:00 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 72E626039B; Wed, 7 Oct 2020 12:14:00 +0200 (CEST) Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0B53960396 for ; Wed, 7 Oct 2020 12:13:59 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 9588860008; Wed, 7 Oct 2020 10:13:57 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 7 Oct 2020 12:17:38 +0200 Message-Id: <20201007101745.15104-7-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201007101745.15104-1-jacopo@jmondi.org> References: <20201007101745.15104-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 06/13] android: camera_stream: Retrieve Stream and Configuration 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" It's a common pattern to access the libcamera::Stream and libcamera::StreamConfiguration using the CameraStream instance's index. Add two methods to the CameraStream to shorten access to the two fields. This allows removing the index() method from the class interface. Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 11 +++-------- src/android/camera_stream.cpp | 10 ++++++++++ src/android/camera_stream.h | 4 +++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 914e66b8f96a..47c423195796 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1292,7 +1292,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) for (unsigned int i = 0; i < stream_list->num_streams; ++i) { camera3_stream_t *stream = stream_list->streams[i]; CameraStream *cameraStream = static_cast(stream->priv); - StreamConfiguration &cfg = config_->at(cameraStream->index()); + const StreamConfiguration &cfg = cameraStream->configuration(); int ret = cameraStream->configure(cfg); if (ret) @@ -1413,10 +1413,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques } descriptor->frameBuffers.emplace_back(buffer); - StreamConfiguration *streamConfiguration = &config_->at(cameraStream->index()); - Stream *stream = streamConfiguration->stream(); - - request->addBuffer(stream, buffer); + request->addBuffer(cameraStream->stream(), buffer); } int ret = camera_->queueRequest(request); @@ -1462,9 +1459,7 @@ void CameraDevice::requestComplete(Request *request) if (cameraStream->camera3Stream().format != HAL_PIXEL_FORMAT_BLOB) continue; - StreamConfiguration *streamConfiguration = &config_->at(cameraStream->index()); - Stream *stream = streamConfiguration->stream(); - FrameBuffer *buffer = request->findBuffer(stream); + FrameBuffer *buffer = request->findBuffer(cameraStream->stream()); if (!buffer) { LOG(HAL, Error) << "Failed to find a source stream buffer"; continue; diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index e86a7ba60d46..9c7819efb679 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -33,6 +33,16 @@ CameraStream::CameraStream(CameraDevice *cameraDevice, encoder_ = std::make_unique(); } +const StreamConfiguration &CameraStream::configuration() const +{ + return config_->at(index_); +} + +Stream *CameraStream::stream() const +{ + return configuration().stream(); +} + int CameraStream::configure(const libcamera::StreamConfiguration &cfg) { if (encoder_) diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index d95c2a3831b0..d8d9d8c4b237 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -115,7 +115,9 @@ public: const libcamera::PixelFormat &format() const { return format_; } const libcamera::Size &size() const { return size_; } Type type() const { return type_; } - unsigned int index() const { return index_; } + + const libcamera::StreamConfiguration &configuration() const; + libcamera::Stream *stream() const; int configure(const libcamera::StreamConfiguration &cfg); int process(const libcamera::FrameBuffer &source, From patchwork Wed Oct 7 10:17:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9999 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 D8C12BEEDF for ; Wed, 7 Oct 2020 10:14:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9B04760455; Wed, 7 Oct 2020 12:14:01 +0200 (CEST) Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 098F56039B for ; Wed, 7 Oct 2020 12:14:00 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 32D3060005; Wed, 7 Oct 2020 10:13:59 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 7 Oct 2020 12:17:39 +0200 Message-Id: <20201007101745.15104-8-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201007101745.15104-1-jacopo@jmondi.org> References: <20201007101745.15104-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 07/13] android: camera_stream: Fetch format and size from configuration 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" Fetch the format and size of the libcamera::StreamConfiguration associated with a CameraStream by accessing the configuration by index. This removes the need to store the libcamera stream format and sizes as class members and avoid duplicating information that might get out of sync. It also allows to remove the StreamConfiguration from the constructor parameters list, as it can be identified by its index. While at it, re-order the constructor parameters order. Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 8 +++----- src/android/camera_stream.cpp | 15 +++++---------- src/android/camera_stream.h | 18 ++++-------------- 3 files changed, 12 insertions(+), 29 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 47c423195796..678dca609003 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1206,9 +1206,8 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) streamConfiguration.pixelFormat = format; config_->addConfiguration(streamConfiguration); - unsigned int index = config_->size() - 1; - streams_.emplace_back(this, stream, streamConfiguration, - CameraStream::Type::Direct, index); + streams_.emplace_back(this, CameraStream::Type::Direct, + stream, config_->size() - 1); stream->priv = static_cast(&streams_.back()); } @@ -1262,8 +1261,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) index = config_->size() - 1; } - StreamConfiguration &cfg = config_->at(index); - streams_.emplace_back(this, jpegStream, cfg, type, index); + streams_.emplace_back(this, type, jpegStream, index); jpegStream->priv = static_cast(&streams_.back()); } diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index 9c7819efb679..3946a2cdf844 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -17,18 +17,13 @@ using namespace libcamera; LOG_DECLARE_CATEGORY(HAL); -CameraStream::CameraStream(CameraDevice *cameraDevice, - camera3_stream_t *camera3Stream, - const libcamera::StreamConfiguration &cfg, - Type type, unsigned int index) - : cameraDevice_(cameraDevice), camera3Stream_(camera3Stream), - type_(type), index_(index) +CameraStream::CameraStream(CameraDevice *cameraDevice, Type type, + camera3_stream_t *camera3Stream, unsigned int index) + : cameraDevice_(cameraDevice), type_(type), + camera3Stream_(camera3Stream), index_(index) { config_ = cameraDevice_->cameraConfiguration(); - format_ = cfg.pixelFormat; - size_ = cfg.size; - if (type_ == Type::Internal || type_ == Type::Mapped) encoder_ = std::make_unique(); } @@ -63,7 +58,7 @@ int CameraStream::process(const libcamera::FrameBuffer &source, exif.setMake("libcamera"); exif.setModel("cameraModel"); exif.setOrientation(cameraDevice_->orientation()); - exif.setSize(size_); + exif.setSize(configuration().size); /* * We set the frame's EXIF timestamp as the time of encode. * Since the precision we need for EXIF timestamp is only one diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index d8d9d8c4b237..f46cfd605d03 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -106,16 +106,11 @@ public: Internal, Mapped, }; - CameraStream(CameraDevice *cameraDevice, - camera3_stream_t *androidStream, - const libcamera::StreamConfiguration &cfg, - Type type, unsigned int index); + CameraStream(CameraDevice *cameraDevice, Type type, + camera3_stream_t *camera3Stream, unsigned int index); - const camera3_stream_t &camera3Stream() const { return *camera3Stream_; } - const libcamera::PixelFormat &format() const { return format_; } - const libcamera::Size &size() const { return size_; } Type type() const { return type_; } - + const camera3_stream_t &camera3Stream() const { return *camera3Stream_; } const libcamera::StreamConfiguration &configuration() const; libcamera::Stream *stream() const; @@ -126,13 +121,8 @@ public: private: CameraDevice *cameraDevice_; libcamera::CameraConfiguration *config_; - camera3_stream_t *camera3Stream_; Type type_; - - /* Libcamera facing format and sizes. */ - libcamera::PixelFormat format_; - libcamera::Size size_; - + camera3_stream_t *camera3Stream_; /* * The index of the libcamera StreamConfiguration as added during * configureStreams(). A single libcamera Stream may be used to deliver From patchwork Wed Oct 7 10:17:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10000 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 19172BEEDF for ; Wed, 7 Oct 2020 10:14:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E1EAD60553; Wed, 7 Oct 2020 12:14:02 +0200 (CEST) Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 20F4760455 for ; Wed, 7 Oct 2020 12:14:01 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 3A5A46000E; Wed, 7 Oct 2020 10:14:00 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 7 Oct 2020 12:17:40 +0200 Message-Id: <20201007101745.15104-9-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201007101745.15104-1-jacopo@jmondi.org> References: <20201007101745.15104-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 08/13] android: camera_device: Return Camera as shared_ptr 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" Return the Camera wrapped by the CameraDevice as a shared_ptr. This will be required to construct the FrameBuffer allocator in the CameraStream class. Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- src/android/camera_device.h | 2 +- src/android/camera_hal_manager.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 826023b453f7..777d1a35e801 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -49,7 +49,7 @@ public: unsigned int id() const { return id_; } camera3_device_t *camera3Device() { return &camera3Device_; } - const libcamera::Camera *camera() const { return camera_.get(); } + std::shared_ptr camera() const { return camera_; } libcamera::CameraConfiguration *cameraConfiguration() const { return config_.get(); diff --git a/src/android/camera_hal_manager.cpp b/src/android/camera_hal_manager.cpp index 05b474010b1d..2a33f9b17112 100644 --- a/src/android/camera_hal_manager.cpp +++ b/src/android/camera_hal_manager.cpp @@ -155,7 +155,7 @@ void CameraHalManager::cameraRemoved(std::shared_ptr cam) auto iter = std::find_if(cameras_.begin(), cameras_.end(), [&cam](std::shared_ptr &camera) { - return cam.get() == camera->camera(); + return cam == camera->camera(); }); if (iter == cameras_.end()) return; From patchwork Wed Oct 7 10:17:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10001 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 7748DBEEE1 for ; Wed, 7 Oct 2020 10:14:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3CDE360557; Wed, 7 Oct 2020 12:14:03 +0200 (CEST) Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 31AF560494 for ; Wed, 7 Oct 2020 12:14:02 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 47D0F60014; Wed, 7 Oct 2020 10:14:01 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 7 Oct 2020 12:17:41 +0200 Message-Id: <20201007101745.15104-10-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201007101745.15104-1-jacopo@jmondi.org> References: <20201007101745.15104-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 09/13] android: camera_device: Make CameraStream configuration nicer 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" Loop over the CameraStream instances and use their interface to perform CameraStream configuration. Modify CameraStream::configure() to configure the android stream buffer count and to retrieve the StreamConfiguration by index instead of receiving it as a parameter. Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 15 +++++---------- src/android/camera_stream.cpp | 11 ++++++++--- src/android/camera_stream.h | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 678dca609003..1e2cbeeb92d1 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1287,17 +1287,12 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) * StreamConfiguration and set the number of required buffers in * the Android camera3_stream_t. */ - for (unsigned int i = 0; i < stream_list->num_streams; ++i) { - camera3_stream_t *stream = stream_list->streams[i]; - CameraStream *cameraStream = static_cast(stream->priv); - const StreamConfiguration &cfg = cameraStream->configuration(); - - int ret = cameraStream->configure(cfg); - if (ret) + for (CameraStream &cameraStream : streams_) { + int ret = cameraStream.configure(); + if (ret) { + LOG(HAL, Error) << "Failed to configure camera stream"; return ret; - - /* Use the bufferCount confirmed by the validation process. */ - stream->max_buffers = cfg.bufferCount; + } } /* diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index 3946a2cdf844..f899be4fe007 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -38,10 +38,15 @@ Stream *CameraStream::stream() const return configuration().stream(); } -int CameraStream::configure(const libcamera::StreamConfiguration &cfg) +int CameraStream::configure() { - if (encoder_) - return encoder_->configure(cfg); + if (encoder_) { + int ret = encoder_->configure(configuration()); + if (ret) + return ret; + } + + camera3Stream_->max_buffers = configuration().bufferCount; return 0; } diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index f46cfd605d03..4c51f0fb3393 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -114,7 +114,7 @@ public: const libcamera::StreamConfiguration &configuration() const; libcamera::Stream *stream() const; - int configure(const libcamera::StreamConfiguration &cfg); + int configure(); int process(const libcamera::FrameBuffer &source, MappedCamera3Buffer *dest, CameraMetadata *metadata); From patchwork Wed Oct 7 10:17:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10002 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 16DFFBEEDF for ; Wed, 7 Oct 2020 10:14:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E0CF760455; Wed, 7 Oct 2020 12:14:05 +0200 (CEST) Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 847FB60396 for ; Wed, 7 Oct 2020 12:14:03 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 9727660005; Wed, 7 Oct 2020 10:14:02 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 7 Oct 2020 12:17:42 +0200 Message-Id: <20201007101745.15104-11-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201007101745.15104-1-jacopo@jmondi.org> References: <20201007101745.15104-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 10/13] android: camera_stream: Create buffer pool 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 a FrameBufferAllocator class member to the CameraStream class. The allocator is constructed for CameraStream instances that needs internal allocation and automatically deleted. Allocate FrameBuffers using the allocator_ class member in the CameraStream class at CameraStream::configure() time and add two methods to the CameraStream class to get and put FrameBuffer pointers from the pool of allocated buffers. As buffer allocation can take place only after the Camera has been configured, move the CameraStream configuration loop in the CameraDevice class after camera_->configure() call. The newly created pool will be used to provide buffers to CameraStream that need to provide memory to libcamera where to deliver frames. Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 22 +++++++++--------- src/android/camera_stream.cpp | 43 +++++++++++++++++++++++++++++++++++ src/android/camera_stream.h | 9 ++++++++ 3 files changed, 63 insertions(+), 11 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 1e2cbeeb92d1..ecdc0922e90b 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1282,6 +1282,17 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) return -EINVAL; } + /* + * Once the CameraConfiguration has been adjusted/validated + * it can be applied to the camera. + */ + int ret = camera_->configure(config_.get()); + if (ret) { + LOG(HAL, Error) << "Failed to configure camera '" + << camera_->id() << "'"; + return ret; + } + /* * Configure the HAL CameraStream instances using the associated * StreamConfiguration and set the number of required buffers in @@ -1295,17 +1306,6 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) } } - /* - * Once the CameraConfiguration has been adjusted/validated - * it can be applied to the camera. - */ - int ret = camera_->configure(config_.get()); - if (ret) { - LOG(HAL, Error) << "Failed to configure camera '" - << camera_->id() << "'"; - return ret; - } - return 0; } diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index f899be4fe007..eac1480530f8 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -26,6 +26,11 @@ CameraStream::CameraStream(CameraDevice *cameraDevice, Type type, if (type_ == Type::Internal || type_ == Type::Mapped) encoder_ = std::make_unique(); + + if (type == Type::Internal) { + allocator_ = std::make_unique(cameraDevice_->camera()); + mutex_ = std::make_unique(); + } } const StreamConfiguration &CameraStream::configuration() const @@ -46,6 +51,16 @@ int CameraStream::configure() return ret; } + if (allocator_) { + int ret = allocator_->allocate(stream()); + if (ret < 0) + return ret; + + /* Save a pointer to the reserved frame buffers */ + for (const auto &frameBuffer : allocator_->buffers(stream())) + buffers_.push_back(frameBuffer.get()); + } + camera3Stream_->max_buffers = configuration().bufferCount; return 0; @@ -109,3 +124,31 @@ int CameraStream::process(const libcamera::FrameBuffer &source, return 0; } + +FrameBuffer *CameraStream::getBuffer() +{ + if (!allocator_) + return nullptr; + + std::lock_guard locker(*mutex_); + + if (buffers_.empty()) { + LOG(HAL, Error) << "Buffer underrun"; + return nullptr; + } + + FrameBuffer *buffer = buffers_.back(); + buffers_.pop_back(); + + return buffer; +} + +void CameraStream::putBuffer(libcamera::FrameBuffer *buffer) +{ + if (!allocator_) + return; + + std::lock_guard locker(*mutex_); + + buffers_.push_back(buffer); +} diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index 4c51f0fb3393..f929e8260ae3 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -8,11 +8,14 @@ #define __ANDROID_CAMERA_STREAM_H__ #include +#include +#include #include #include #include +#include #include #include @@ -117,6 +120,8 @@ public: int configure(); int process(const libcamera::FrameBuffer &source, MappedCamera3Buffer *dest, CameraMetadata *metadata); + libcamera::FrameBuffer *getBuffer(); + void putBuffer(libcamera::FrameBuffer *buffer); private: CameraDevice *cameraDevice_; @@ -129,7 +134,11 @@ private: * one or more streams to the Android framework. */ unsigned int index_; + std::unique_ptr encoder_; + std::unique_ptr allocator_; + std::vector buffers_; + std::unique_ptr mutex_; }; #endif /* __ANDROID_CAMERA_STREAM__ */ From patchwork Wed Oct 7 10:17:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10003 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 E2DB8BEEDF for ; Wed, 7 Oct 2020 10:14:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BCA0860553; Wed, 7 Oct 2020 12:14:07 +0200 (CEST) Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 067936039B for ; Wed, 7 Oct 2020 12:14:05 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id A397960014; Wed, 7 Oct 2020 10:14:03 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 7 Oct 2020 12:17:43 +0200 Message-Id: <20201007101745.15104-12-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201007101745.15104-1-jacopo@jmondi.org> References: <20201007101745.15104-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 11/13] android: camera_device: Use CameraStream buffers 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" Now that CameraStream that require internal memory allocation have been instrumented with a FrameBuffer pool, use them to create intermediate buffers in the CameraDevice. Reviewed-by: Umang Jain Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 51 ++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index ecdc0922e90b..257ffdf233c2 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1387,24 +1387,48 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques descriptor->buffers[i].stream = camera3Buffers[i].stream; descriptor->buffers[i].buffer = camera3Buffers[i].buffer; - /* Software streams are handled after hardware streams complete. */ - if (cameraStream->camera3Stream().format == HAL_PIXEL_FORMAT_BLOB) - continue; - /* - * Create a libcamera buffer using the dmabuf descriptors of - * the camera3Buffer for each stream. The FrameBuffer is - * directly associated with the Camera3RequestDescriptor for - * lifetime management only. + * Inspect the camera stream type, create buffers opportunely + * and add them to the Request if required. */ - FrameBuffer *buffer = createFrameBuffer(*camera3Buffers[i].buffer); + FrameBuffer *buffer = nullptr; + switch (cameraStream->type()) { + case CameraStream::Type::Mapped: + /* + * Mapped streams don't need buffers added to the + * Request. + */ + continue; + + case CameraStream::Type::Direct: + /* + * Create a libcamera buffer using the dmabuf + * descriptors of the camera3Buffer for each stream and + * associate it with the Camera3RequestDescriptor for + * lifetime management only. + */ + buffer = createFrameBuffer(*camera3Buffers[i].buffer); + descriptor->frameBuffers.emplace_back(buffer); + break; + + case CameraStream::Type::Internal: + /* + * Get the frame buffer from the CameraStream internal + * buffer pool. + * + * The buffer has to be returned to the CameraStream + * once it has been processed. + */ + buffer = cameraStream->getBuffer(); + break; + } + if (!buffer) { LOG(HAL, Error) << "Failed to create buffer"; delete request; delete descriptor; return -ENOMEM; } - descriptor->frameBuffers.emplace_back(buffer); request->addBuffer(cameraStream->stream(), buffer); } @@ -1476,6 +1500,13 @@ void CameraDevice::requestComplete(Request *request) status = CAMERA3_BUFFER_STATUS_ERROR; continue; } + + /* + * Return the FrameBuffer to the CameraStream now that we're + * done processing it. + */ + if (cameraStream->type() == CameraStream::Type::Internal) + cameraStream->putBuffer(buffer); } /* Prepare to call back the Android camera stack. */ From patchwork Wed Oct 7 10:17:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10004 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 39DA9BEEE1 for ; Wed, 7 Oct 2020 10:14:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 126C960423; Wed, 7 Oct 2020 12:14:08 +0200 (CEST) Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E70F860396 for ; Wed, 7 Oct 2020 12:14:06 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 549A16001A; Wed, 7 Oct 2020 10:14:04 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 7 Oct 2020 12:17:44 +0200 Message-Id: <20201007101745.15104-13-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201007101745.15104-1-jacopo@jmondi.org> References: <20201007101745.15104-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 12/13] android: camera_device: Add stream mapping log 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" To ease following how Android streams get mapped to libcamera ones add a (quite verbose) printout before queueing a request to libcamera. The output looks like: 0 - (320x240)[0x00000022] -> (320x240)[NV12] (direct) 1 - (640x480)[0x00000021] -> (640x480)[NV12] (internal) Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Hirokazu Honda Reviewed-by: Niklas Söderlund Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 257ffdf233c2..c6b6fe4b3ae3 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1376,7 +1376,10 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques Request *request = camera_->createRequest(reinterpret_cast(descriptor)); + LOG(HAL, Debug) << "Queueing Request to libcamera with " + << descriptor->numBuffers << " HAL streams"; for (unsigned int i = 0; i < descriptor->numBuffers; ++i) { + camera3_stream *camera3Stream = camera3Buffers[i].stream; CameraStream *cameraStream = static_cast(camera3Buffers[i].stream->priv); @@ -1387,6 +1390,13 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques descriptor->buffers[i].stream = camera3Buffers[i].stream; descriptor->buffers[i].buffer = camera3Buffers[i].buffer; + std::stringstream ss; + ss << i << " - (" << camera3Stream->width << "x" + << camera3Stream->height << ")" + << "[" << utils::hex(camera3Stream->format) << "] -> " + << "(" << cameraStream->configuration().size.toString() << ")[" + << cameraStream->configuration().pixelFormat.toString() << "]"; + /* * Inspect the camera stream type, create buffers opportunely * and add them to the Request if required. @@ -1398,6 +1408,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques * Mapped streams don't need buffers added to the * Request. */ + LOG(HAL, Debug) << ss.str() << " (mapped)"; continue; case CameraStream::Type::Direct: @@ -1409,6 +1420,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques */ buffer = createFrameBuffer(*camera3Buffers[i].buffer); descriptor->frameBuffers.emplace_back(buffer); + LOG(HAL, Debug) << ss.str() << " (direct)"; break; case CameraStream::Type::Internal: @@ -1420,6 +1432,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques * once it has been processed. */ buffer = cameraStream->getBuffer(); + LOG(HAL, Debug) << ss.str() << " (internal)"; break; } From patchwork Wed Oct 7 10:17:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 10005 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 6EC7BBEEDF for ; Wed, 7 Oct 2020 10:14:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 48CC860423; Wed, 7 Oct 2020 12:14:10 +0200 (CEST) Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BC2DA6049A for ; Wed, 7 Oct 2020 12:14:08 +0200 (CEST) X-Originating-IP: 93.34.118.233 Received: from uno.lan (93-34-118-233.ip49.fastwebnet.it [93.34.118.233]) (Authenticated sender: jacopo@jmondi.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 19BB260012; Wed, 7 Oct 2020 10:14:06 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 7 Oct 2020 12:17:45 +0200 Message-Id: <20201007101745.15104-14-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201007101745.15104-1-jacopo@jmondi.org> References: <20201007101745.15104-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 13/13] android: camera_device: Clear streams_ at stop time 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" When the CameraDevice is stopped, we need to clear the vector of CameraStream instances to make sure they get deleted and all the resources they have acquired get released. Reviewed-by: Umang Jain Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index c6b6fe4b3ae3..0a94c1ae17ac 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -517,6 +517,8 @@ int CameraDevice::open(const hw_module_t *hardwareModule) void CameraDevice::close() { + streams_.clear(); + camera_->stop(); camera_->release();