From patchwork Mon Oct 5 10:46:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9948 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 EC65AC3B5D for ; Mon, 5 Oct 2020 10:47:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D80A563BD5; Mon, 5 Oct 2020 12:47:35 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="M9w+PjMN"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0249C63B27 for ; Mon, 5 Oct 2020 12:47:34 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7D04A59E; Mon, 5 Oct 2020 12:47:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1601894853; bh=MBaQ+et0K8HbJyUJ2dRExPCSZ6HjSHpAQg3PQ9uM3Zk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M9w+PjMNu+rl/eM0XTo4yRWt7/x847EFmPK38LTBj14jLEiZPuvxNSwHSjUda01ZK EbJmSb6zZMklIS+WL3p2MbRHNf4ML/ZlrvAwGz/860twaLVXO+YOuu1lJpx7b3Pl6e pyhAGkZuc3oZE5uTvFhUC0oDRrbuBTgFVmvmaL6Y= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Oct 2020 13:46:35 +0300 Message-Id: <20201005104649.10812-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> References: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 01/15] 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" From: Jacopo Mondi Break CameraStream out of the CameraDevice class. No functional changes, only the code is moved. Signed-off-by: Jacopo Mondi Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart Reviewed-by: Umang Jain --- src/android/camera_device.cpp | 6 ------ src/android/camera_device.h | 24 +-------------------- src/android/camera_stream.cpp | 16 ++++++++++++++ src/android/camera_stream.h | 40 +++++++++++++++++++++++++++++++++++ src/android/meson.build | 1 + 5 files changed, 58 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..01c62978ca3a --- /dev/null +++ b/src/android/camera_stream.cpp @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2020, Google Inc. + * + * camera_stream.cpp - Camera HAL stream + */ + +#include "camera_stream.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..10dece7beb69 --- /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 + +#include "jpeg/encoder.h" + +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 Mon Oct 5 10:46:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9949 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 0EDA7C3B5D for ; Mon, 5 Oct 2020 10:47:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6129D63C34; Mon, 5 Oct 2020 12:47:37 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="JicMObpR"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6026A63B27 for ; Mon, 5 Oct 2020 12:47:34 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DF6EB3B; Mon, 5 Oct 2020 12:47:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1601894854; bh=tcOfNVBq2DYis7v/Y49sS4pyeWJ1Xg1C9jAEJZ2Q/qs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JicMObpR43Ko2U5xbtovzb+0eEjVzriaNhDB6sK5h1FiyN+NScNWbY4FUDiluoxDn HTq1QUn/clxUJuC6azR6Budd5BlnGaDxGHjOwuovcG9h/wMDojvCI/yjW2J63+GC6N mqt+XRvKiGVyiIynHVAOTlJrl6neJaqNmeuBW2xo= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Oct 2020 13:46:36 +0300 Message-Id: <20201005104649.10812-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> References: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 02/15] 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" From: Jacopo Mondi 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 Reviewed-by: Laurent Pinchart --- 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 01c62978ca3a..585bf2b68f4f 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -10,7 +10,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 10dece7beb69..07c714e3a365 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -17,17 +17,101 @@ 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 + * is 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 Mon Oct 5 10:46:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9950 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 97AD1C3B5D for ; Mon, 5 Oct 2020 10:47:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AD38E63C48; Mon, 5 Oct 2020 12:47:37 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="WLclBpEl"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C0C9F63B27 for ; Mon, 5 Oct 2020 12:47:34 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 49AAB59E; Mon, 5 Oct 2020 12:47:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1601894854; bh=berp9T5tcX7IOm2p8Q9u0T8CRn9Ed9OI/Ti1r51BiII=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WLclBpElylXfgEUeFs8GLSEBmvE5oxmRjnEvuaNNGyUAus/Wx3b5cRpPcVcLZUvQN +si8dlnpBq59wMmb1cLWZthaTGn0IritnKi1djmtuJcGK8vqEQvUrsOsC6pbjxjH4y WuUNUPEC7X0K2lC0obbH78bpAPzF/Gu+yc8ifhI8= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Oct 2020 13:46:37 +0300 Message-Id: <20201005104649.10812-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> References: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 03/15] 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" From: Jacopo Mondi Delegate the construction of the encoder to the CameraStream class for streams that need post-processing. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Umang Jain --- src/android/camera_device.cpp | 23 ++++++++++------------- src/android/camera_stream.cpp | 17 ++++++++++++++--- src/android/camera_stream.h | 4 +++- 3 files changed, 27 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 585bf2b68f4f..5b2b625c563b 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -7,10 +7,21 @@ #include "camera_stream.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), encoder(nullptr) { + if (type_ == Type::Internal || type_ == Type::Mapped) + encoder_.reset(new EncoderLibJpeg); +} + +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 07c714e3a365..d0dc40d81151 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 Mon Oct 5 10:46:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9951 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 12B71C3B5D for ; Mon, 5 Oct 2020 10:47:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0684F63C4C; Mon, 5 Oct 2020 12:47:38 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="aWnHfiqp"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 275A363B27 for ; Mon, 5 Oct 2020 12:47:35 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id AC44D3B; Mon, 5 Oct 2020 12:47:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1601894854; bh=osi4Z+RtghKoXEuYdb+n5QvnBwR7M1NC0SwQftHsfZs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aWnHfiqp4Py+iYiZF8eSr+Z3kg1VX8ybSzprouftu7qqcxpJ1W6H7pBYhefixPTVn w1mv5yJMXytxcKhyfV4uUbL37RQ8Kn4BTezoNhFq4AA3pWAiJxgMA2+djBbHN/EbRG XWl9kktD1K/e8jCqKLX9DCakgp+xsx6Fj3tqtydU= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Oct 2020 13:46:38 +0300 Message-Id: <20201005104649.10812-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> References: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 04/15] 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" From: Jacopo Mondi A CameraStream maps a stream requested by Android to a libcamera::StreamConfiguration. It shall then be constructed with those information clearly specified. Change the CameraStream constructor to accept an Android camera3_stream_t and a libcamera::StreamConfiguration to copy the format and size information in the class members as no reference can be taken to the StreamConfiguration instances as they're subject to relocations. Pass to the CameraStream constructor a pointer to the CameraDevice class and make the CameraConfiguration accessible. It will be used to retrieve 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 required format should be used instead. Signed-off-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- src/android/camera_device.cpp | 11 +++++------ src/android/camera_device.h | 4 ++++ src/android/camera_stream.cpp | 14 ++++++++++++-- src/android/camera_stream.h | 18 ++++++++++++++++-- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 9c9a5cfa3c2f..2c4dd4dee28c 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->outputFormat() == 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->outputFormat() != 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 5b2b625c563b..5c1f1d7da416 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -7,13 +7,23 @@ #include "camera_stream.h" +#include "camera_device.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), encoder(nullptr) +CameraStream::CameraStream(CameraDevice *cameraDev, + camera3_stream_t *androidStream, + const libcamera::StreamConfiguration &cfg, + Type type, unsigned int index) + : cameraDevice_(cameraDev), androidStream_(androidStream), type_(type), + index_(index), encoder_(nullptr) { + config_ = cameraDevice_->cameraConfiguration(); + + format_ = cfg.pixelFormat; + size_ = cfg.size; + if (type_ == Type::Internal || type_ == Type::Mapped) encoder_.reset(new EncoderLibJpeg); } diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index d0dc40d81151..2d71a50c78a4 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -9,11 +9,16 @@ #include +#include + +#include #include #include #include "jpeg/encoder.h" +class CameraDevice; + class CameraStream { public: @@ -99,9 +104,12 @@ public: Internal, Mapped, }; - CameraStream(libcamera::PixelFormat format, libcamera::Size size, + CameraStream(CameraDevice *cameraDev, + camera3_stream_t *androidStream, + const libcamera::StreamConfiguration &cfg, Type type, unsigned int index); + int outputFormat() const { return androidStream_->format; } const libcamera::PixelFormat &format() const { return format_; } const libcamera::Size &size() const { return size_; } Type type() const { return type_; } @@ -111,9 +119,15 @@ public: int configure(const libcamera::StreamConfiguration &cfg); private: + CameraDevice *cameraDevice_; + libcamera::CameraConfiguration *config_; + camera3_stream_t *androidStream_; + 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 Mon Oct 5 10:46:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9952 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 0DF6AC3B5D for ; Mon, 5 Oct 2020 10:47:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CA4A663C44; Mon, 5 Oct 2020 12:47:39 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="T1+HbHJ4"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 93CC563BBF for ; Mon, 5 Oct 2020 12:47:35 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1CD3259E; Mon, 5 Oct 2020 12:47:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1601894855; bh=RManH8pi/+sohgrxew2NU1NnADGx9e/kDN5YNFRFAvY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T1+HbHJ4GEmZ4ZEjxMhTg4HG6Bj4RA/Y3f7GPHfn3j+QSQKKi+Ghi626jao7X2Da6 UUQrnvKhsmW6trPBLLODExkkrNzq1NKsnqgD/jIRCwITNHRb0KGl8DXRtAcbq9N1sa 3rCnynyS7IUi6/+auMk63YXs3pHF6LJmOh3B1JlI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Oct 2020 13:46:39 +0300 Message-Id: <20201005104649.10812-6-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> References: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 05/15] 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" From: Jacopo Mondi 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. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/android/camera_device.cpp | 68 ++--------------------------------- src/android/camera_device.h | 8 +++++ src/android/camera_stream.cpp | 63 ++++++++++++++++++++++++++++++++ src/android/camera_stream.h | 7 +++- 4 files changed, 80 insertions(+), 66 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 2c4dd4dee28c..c44904300e0a 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->outputFormat() != 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 5c1f1d7da416..072edc9457bb 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -8,10 +8,14 @@ #include "camera_stream.h" #include "camera_device.h" +#include "camera_metadata.h" #include "jpeg/encoder_libjpeg.h" +#include "jpeg/exif.h" using namespace libcamera; +LOG_DECLARE_CATEGORY(HAL); + CameraStream::CameraStream(CameraDevice *cameraDev, camera3_stream_t *androidStream, const libcamera::StreamConfiguration &cfg, @@ -35,3 +39,62 @@ int CameraStream::configure(const libcamera::StreamConfiguration &cfg) return 0; } + +int CameraStream::process(libcamera::FrameBuffer *source, MappedCamera3Buffer *dest, + CameraMetadata *metadata) +{ + if (!encoder_) + return -EINVAL; + + /* 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 2d71a50c78a4..dbcd1e53219f 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -11,6 +11,7 @@ #include +#include #include #include #include @@ -18,6 +19,8 @@ #include "jpeg/encoder.h" class CameraDevice; +class CameraMetadata; +class MappedCamera3Buffer; class CameraStream { @@ -114,9 +117,11 @@ 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(libcamera::FrameBuffer *source, + MappedCamera3Buffer *dest, + CameraMetadata *metadata); private: CameraDevice *cameraDevice_; From patchwork Mon Oct 5 10:46:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9953 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 92D3BC3B5D for ; Mon, 5 Oct 2020 10:47:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3AA8A63BED; Mon, 5 Oct 2020 12:47:40 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="r+Ank8XO"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F2D4563C1B for ; Mon, 5 Oct 2020 12:47:35 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 801A63B; Mon, 5 Oct 2020 12:47:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1601894855; bh=ohsfGkm3PRkU4OkzD2nGcCuQ2xkvTSNISOtuRFKSF8A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r+Ank8XOZoax3B4dAQSa3+8OfGfEzvpEqbhLG7Ad+sXaVZPejHnvUH6wi/NegeCDc QIHX6YAMu2Czsg2bzOyUlze39RXPeraKDnifvr6+OfArG8N923m5dot4ej8PzZUSX/ SiB0s8JtwAF0pD8SuzIbSwE9WCmiR/6900MnbEHQ= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Oct 2020 13:46:40 +0300 Message-Id: <20201005104649.10812-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> References: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 06/15] 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" From: Jacopo Mondi 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. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- 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 c44904300e0a..4f8f3e5790ca 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->streamConfiguration(); 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->outputFormat() != 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 072edc9457bb..250f0ab0a3b4 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -32,6 +32,16 @@ CameraStream::CameraStream(CameraDevice *cameraDev, encoder_.reset(new EncoderLibJpeg); } +const StreamConfiguration &CameraStream::streamConfiguration() const +{ + return config_->at(index_); +} + +Stream *CameraStream::stream() const +{ + return streamConfiguration().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 dbcd1e53219f..fa295a69404f 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -116,7 +116,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 &streamConfiguration() const; + libcamera::Stream *stream() const; int configure(const libcamera::StreamConfiguration &cfg); int process(libcamera::FrameBuffer *source, From patchwork Mon Oct 5 10:46:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9954 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 B9B65C3B5D for ; Mon, 5 Oct 2020 10:47:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8699263C28; Mon, 5 Oct 2020 12:47:41 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="u8cEvUwi"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 565AB63BE4 for ; Mon, 5 Oct 2020 12:47:36 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DE6D459E; Mon, 5 Oct 2020 12:47:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1601894856; bh=JYDBx5///bDfgq/WJy1yIFW5fPWTppIQIlFq5wDLLKw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u8cEvUwitNzfIJsyjYOT+YpsOox34nzFUU/Szbq01QSyiQ+bMw+rtcXvgr4ZGgFV1 q4zjaA+5bYUCwAwmqwwho23JuUtU2cwdVr/xv4Gel/5bv6ZyquwUrjVO3OhkmLK0HM 1tlRWLzRn8QZA+DVbtQLJwv9EGPEDlpgCQy4Wp2k= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Oct 2020 13:46:41 +0300 Message-Id: <20201005104649.10812-8-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> References: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 07/15] 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" From: Jacopo Mondi 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. Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 8 +++----- src/android/camera_stream.cpp | 23 ++++++++++++++--------- src/android/camera_stream.h | 18 ++++++------------ 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 4f8f3e5790ca..adaec54dbfdb 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 250f0ab0a3b4..6e7419ae31b8 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -16,18 +16,13 @@ using namespace libcamera; LOG_DECLARE_CATEGORY(HAL); -CameraStream::CameraStream(CameraDevice *cameraDev, - camera3_stream_t *androidStream, - const libcamera::StreamConfiguration &cfg, - Type type, unsigned int index) - : cameraDevice_(cameraDev), androidStream_(androidStream), type_(type), +CameraStream::CameraStream(CameraDevice *cameraDev, Type type, + camera3_stream_t *androidStream, unsigned int index) + : cameraDevice_(cameraDev), type_(type), androidStream_(androidStream), index_(index), encoder_(nullptr) { config_ = cameraDevice_->cameraConfiguration(); - format_ = cfg.pixelFormat; - size_ = cfg.size; - if (type_ == Type::Internal || type_ == Type::Mapped) encoder_.reset(new EncoderLibJpeg); } @@ -42,6 +37,16 @@ Stream *CameraStream::stream() const return streamConfiguration().stream(); } +const PixelFormat &CameraStream::format() const +{ + return streamConfiguration().pixelFormat; +} + +const Size &CameraStream::size() const +{ + return streamConfiguration().size; +} + int CameraStream::configure(const libcamera::StreamConfiguration &cfg) { if (encoder_) @@ -62,7 +67,7 @@ int CameraStream::process(libcamera::FrameBuffer *source, MappedCamera3Buffer *d exif.setMake("libcamera"); exif.setModel("cameraModel"); exif.setOrientation(cameraDevice_->orientation()); - exif.setSize(size_); + 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 diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index fa295a69404f..b67b4c0ca0b3 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -107,18 +107,16 @@ public: Internal, Mapped, }; - CameraStream(CameraDevice *cameraDev, - camera3_stream_t *androidStream, - const libcamera::StreamConfiguration &cfg, - Type type, unsigned int index); + CameraStream(CameraDevice *cameraDev, Type type, + camera3_stream_t *androidStream, unsigned int index); int outputFormat() const { return androidStream_->format; } - const libcamera::PixelFormat &format() const { return format_; } - const libcamera::Size &size() const { return size_; } Type type() const { return type_; } const libcamera::StreamConfiguration &streamConfiguration() const; libcamera::Stream *stream() const; + const libcamera::PixelFormat &format() const; + const libcamera::Size &size() const; int configure(const libcamera::StreamConfiguration &cfg); int process(libcamera::FrameBuffer *source, @@ -127,13 +125,8 @@ public: private: CameraDevice *cameraDevice_; - libcamera::CameraConfiguration *config_; - camera3_stream_t *androidStream_; Type type_; - - /* Libcamera facing format and sizes. */ - libcamera::PixelFormat format_; - libcamera::Size size_; + camera3_stream_t *androidStream_; /* * The index of the libcamera StreamConfiguration as added during @@ -141,6 +134,7 @@ private: * one or more streams to the Android framework. */ unsigned int index_; + libcamera::CameraConfiguration *config_; std::unique_ptr encoder_; }; From patchwork Mon Oct 5 10:46:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9955 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 25422C3B5D for ; Mon, 5 Oct 2020 10:47:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E5C5C63C55; Mon, 5 Oct 2020 12:47:41 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="TtDLmnXq"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BAB4A63B29 for ; Mon, 5 Oct 2020 12:47:36 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4728C3B; Mon, 5 Oct 2020 12:47:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1601894856; bh=hE1fRxS0Pzp6zORaf/amSh2fNu+Jhs7mi4LD2MTeV4Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TtDLmnXqH33EBqoQ7DUHsZhuhYu3iar9R3Tn7gSfaUnm1cAFBKODSYEocPvzR+Nb5 7s35yOi3en4soef2AMgdaxduwhUfYjtjDN6wp4ut1vcJENp3i0C/ISXmxXXN+gdgR+ ri6KkCrsJHbxdYeMNuE72KL7A0hP/ZPXpwiA2Viw= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Oct 2020 13:46:42 +0300 Message-Id: <20201005104649.10812-9-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> References: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 08/15] 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" From: Jacopo Mondi Return the Camera wrapped by the CameraDevice as a shared_ptr. This will be required to construct the FrameBuffer allocator in the CameraStream class. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- 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..e29eddbb5590 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.get() == camera->camera().get(); }); if (iter == cameras_.end()) return; From patchwork Mon Oct 5 10:46:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9956 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com 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 82ECDC3B5F for ; Mon, 5 Oct 2020 10:47:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4E6F363C30; Mon, 5 Oct 2020 12:47:42 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="gWuUuXcm"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 24E2863B82 for ; Mon, 5 Oct 2020 12:47:37 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id AA6D259E; Mon, 5 Oct 2020 12:47:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1601894856; bh=gWnFdfQ82p8qI2GH2SoAhdCVCPTo1HR0A/KgjeK/8uo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gWuUuXcmqmSGxc48KWcraaymvTR/fjtBgCN3Jz5n0ZTT8NN8ebyoWDbdMwhzv6lGo 7+7kg1wzwDFEwWx/KUSk6bL/riSluLqvqzv2zhEhNa/mKusmcqZxVyxaEnP7NFx8e8 9U6xvdtbNg8ALaEdQgLpXqJBs6J5rWv5nDIGE82Q= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Oct 2020 13:46:43 +0300 Message-Id: <20201005104649.10812-10-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> References: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 09/15] android: camera_stream: Add FrameBufferAllocator 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" From: Jacopo Mondi Add a FrameBufferAllocator class member to the CameraStream class. The allocator is constructed for CameraStream instances that needs internal allocation and deleted at class destruction time. The definition of a destructor for the class deletes the implicitly defined copy constructor, required as the CameraDevice stores CameraStream instances in a pre-reserved vector. In order to make the CameraStream copy-constructable it is required to make the encoder_ pointer decay to a raw pointer, as unique_ptr<> are not copy-constructable. Signed-off-by: Jacopo Mondi --- src/android/camera_stream.cpp | 13 +++++++++++-- src/android/camera_stream.h | 6 +++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index 6e7419ae31b8..9f3e7026b1a4 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -19,12 +19,21 @@ LOG_DECLARE_CATEGORY(HAL); CameraStream::CameraStream(CameraDevice *cameraDev, Type type, camera3_stream_t *androidStream, unsigned int index) : cameraDevice_(cameraDev), type_(type), androidStream_(androidStream), - index_(index), encoder_(nullptr) + index_(index), encoder_(nullptr), allocator_(nullptr) { config_ = cameraDevice_->cameraConfiguration(); if (type_ == Type::Internal || type_ == Type::Mapped) - encoder_.reset(new EncoderLibJpeg); + encoder_ = new EncoderLibJpeg(); + + if (type == Type::Internal) + allocator_ = new FrameBufferAllocator(cameraDevice_->camera()); +} + +CameraStream::~CameraStream() +{ + delete encoder_; + delete allocator_; } const StreamConfiguration &CameraStream::streamConfiguration() const diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index b67b4c0ca0b3..eaf4357ed096 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -109,6 +110,8 @@ public: }; CameraStream(CameraDevice *cameraDev, Type type, camera3_stream_t *androidStream, unsigned int index); + CameraStream(const CameraStream &) = default; + ~CameraStream(); int outputFormat() const { return androidStream_->format; } Type type() const { return type_; } @@ -135,7 +138,8 @@ private: */ unsigned int index_; libcamera::CameraConfiguration *config_; - std::unique_ptr encoder_; + Encoder *encoder_; + libcamera::FrameBufferAllocator *allocator_; }; #endif /* __ANDROID_CAMERA_STREAM__ */ From patchwork Mon Oct 5 10:46:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9957 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com 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 0225BC3B5D for ; Mon, 5 Oct 2020 10:47:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C1D4F63C13; Mon, 5 Oct 2020 12:47:42 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="QYATGk3v"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 939F563C46 for ; Mon, 5 Oct 2020 12:47:37 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 148933B; Mon, 5 Oct 2020 12:47:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1601894857; bh=d1I5ZDd1nX8LDOlGDOtqicY+AgyoAH2vn8nTc0v75wE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QYATGk3v6ETo5ARRyXwwbL+/1+3xkb5il3WorZsVxvzs4S6HIKMNVPj4/XtCch9ow TvUanfA0pmUfVsHGpBI9j5az7qcYTvIY4inYkQMekMahk0MoGdhCMnnJ39b0Wv+hZB ToJXPTz8eKXjyGKsEi8Vu3NrNr5zVyN+0cGu/nbA= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Oct 2020 13:46:44 +0300 Message-Id: <20201005104649.10812-11-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> References: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 10/15] android: camera_stream: Allocate FrameBuffers 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" From: Jacopo Mondi Allocate FrameBuffers using the allocator_ class member in the CameraStream class at CameraStream::configure() time. As FrameBuffer allocation can only happen after the Camera has been correctly configured, move the CameraStream configuration loop after the Camera::configure() call in CameraDevice. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/android/camera_device.cpp | 22 +++++++++++----------- src/android/camera_stream.cpp | 17 +++++++++++++++-- src/android/camera_stream.h | 2 ++ 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index adaec54dbfdb..537883b63f15 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 @@ -1300,17 +1311,6 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) stream->max_buffers = cfg.bufferCount; } - /* - * 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 9f3e7026b1a4..76e7d240f4e7 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -58,8 +58,21 @@ const Size &CameraStream::size() const int CameraStream::configure(const libcamera::StreamConfiguration &cfg) { - if (encoder_) - return encoder_->configure(cfg); + if (encoder_) { + int ret = encoder_->configure(cfg); + if (ret) + 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()); + } return 0; } diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index eaf4357ed096..e399e17b2a2f 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -8,6 +8,7 @@ #define __ANDROID_CAMERA_STREAM_H__ #include +#include #include @@ -140,6 +141,7 @@ private: libcamera::CameraConfiguration *config_; Encoder *encoder_; libcamera::FrameBufferAllocator *allocator_; + std::vector buffers_; }; #endif /* __ANDROID_CAMERA_STREAM__ */ From patchwork Mon Oct 5 10:46:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9958 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 7723AC3B5D for ; Mon, 5 Oct 2020 10:47:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 40C0A63BFE; Mon, 5 Oct 2020 12:47:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="fsKpfWAd"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E43C363C23 for ; Mon, 5 Oct 2020 12:47:37 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7D0CD59E; Mon, 5 Oct 2020 12:47:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1601894857; bh=mvN0I6FK3ed1Qwneht64CEk1suW1Vz1q+JMDrACRHGU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fsKpfWAdkxHJZNnp5r1Bm0g1ofUIUbZlyfUIZbJuR99XZjpSBBhpNjaSKTce9zyrb 5DS101MDEkDhetAduDWDoLx8gSqtraCivsqgHwxhHRE/vWnXXGEdPprAru+MTdyuH1 G53fIWiC5GrrN6ezZ8GfXrheK9nnfOhMQDndGQ7c= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Oct 2020 13:46:45 +0300 Message-Id: <20201005104649.10812-12-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> References: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 11/15] 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" From: Jacopo Mondi Loop over the CameraStream instances and use their interface to perform CameraStream configuration after the Camera::configure(). Signed-off-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- src/android/camera_device.cpp | 10 ++++------ src/android/camera_stream.cpp | 4 ++-- src/android/camera_stream.h | 3 ++- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 537883b63f15..62307726aea9 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1298,17 +1298,15 @@ 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->streamConfiguration(); + for (CameraStream &cameraStream : streams_) { + camera3_stream_t *stream = cameraStream.androidStream(); - int ret = cameraStream->configure(cfg); + int ret = cameraStream.configure(); if (ret) return ret; /* Use the bufferCount confirmed by the validation process. */ - stream->max_buffers = cfg.bufferCount; + stream->max_buffers = cameraStream.streamConfiguration().bufferCount; } return 0; diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index 76e7d240f4e7..dbde1e786300 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -56,10 +56,10 @@ const Size &CameraStream::size() const return streamConfiguration().size; } -int CameraStream::configure(const libcamera::StreamConfiguration &cfg) +int CameraStream::configure() { if (encoder_) { - int ret = encoder_->configure(cfg); + int ret = encoder_->configure(streamConfiguration()); if (ret) return ret; } diff --git a/src/android/camera_stream.h b/src/android/camera_stream.h index e399e17b2a2f..c6ff79230b7e 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -116,13 +116,14 @@ public: int outputFormat() const { return androidStream_->format; } Type type() const { return type_; } + camera3_stream_t *androidStream() const { return androidStream_; } const libcamera::StreamConfiguration &streamConfiguration() const; libcamera::Stream *stream() const; const libcamera::PixelFormat &format() const; const libcamera::Size &size() const; - int configure(const libcamera::StreamConfiguration &cfg); + int configure(); int process(libcamera::FrameBuffer *source, MappedCamera3Buffer *dest, CameraMetadata *metadata); From patchwork Mon Oct 5 10:46:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9959 X-Patchwork-Delegate: laurent.pinchart@ideasonboard.com 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 DDF1AC3B5D for ; Mon, 5 Oct 2020 10:47:43 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A817063C23; Mon, 5 Oct 2020 12:47:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="DSE2W315"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5B0B063B27 for ; Mon, 5 Oct 2020 12:47:38 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DEFB63B; Mon, 5 Oct 2020 12:47:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1601894858; bh=QTpINhxG3ul3V118LYtzIO7Rg0RhyTjI+kD3k6IdYqU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DSE2W315MY5Qve0yqx3I8fyQ6VXyGr3EpgjzF2CU3yL6UuI6WEX067HN9jlCBdEut sZH2fR+tRM7emfnck6CJeQhrpDuK92wkoxqb+Xj/BbFTzRcrXhq58HlKXCAMryE9Oc 89TYgGkvhiSWlJClOorq3IaqAEI9mn28tk/5dT+M= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Oct 2020 13:46:46 +0300 Message-Id: <20201005104649.10812-13-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> References: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 12/15] android: camera_stream: Add methods to get/put 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" From: Jacopo Mondi Add two methods to the CameraStream class to get and put FrameBuffer pointers from the pool of allocated buffers. Signed-off-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- src/android/camera_stream.cpp | 35 +++++++++++++++++++++++++++++++++-- src/android/camera_stream.h | 4 ++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/android/camera_stream.cpp b/src/android/camera_stream.cpp index dbde1e786300..c4b727eee63e 100644 --- a/src/android/camera_stream.cpp +++ b/src/android/camera_stream.cpp @@ -19,21 +19,24 @@ LOG_DECLARE_CATEGORY(HAL); CameraStream::CameraStream(CameraDevice *cameraDev, Type type, camera3_stream_t *androidStream, unsigned int index) : cameraDevice_(cameraDev), type_(type), androidStream_(androidStream), - index_(index), encoder_(nullptr), allocator_(nullptr) + index_(index), encoder_(nullptr), allocator_(nullptr), mutex_(nullptr) { config_ = cameraDevice_->cameraConfiguration(); if (type_ == Type::Internal || type_ == Type::Mapped) encoder_ = new EncoderLibJpeg(); - if (type == Type::Internal) + if (type == Type::Internal) { allocator_ = new FrameBufferAllocator(cameraDevice_->camera()); + mutex_ = new std::mutex(); + } } CameraStream::~CameraStream() { delete encoder_; delete allocator_; + delete mutex_; } const StreamConfiguration &CameraStream::streamConfiguration() const @@ -135,3 +138,31 @@ int CameraStream::process(libcamera::FrameBuffer *source, MappedCamera3Buffer *d 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 c6ff79230b7e..b79a97606c60 100644 --- a/src/android/camera_stream.h +++ b/src/android/camera_stream.h @@ -8,6 +8,7 @@ #define __ANDROID_CAMERA_STREAM_H__ #include +#include #include #include @@ -127,6 +128,8 @@ public: int process(libcamera::FrameBuffer *source, MappedCamera3Buffer *dest, CameraMetadata *metadata); + libcamera::FrameBuffer *getBuffer(); + void putBuffer(libcamera::FrameBuffer *buffer); private: CameraDevice *cameraDevice_; @@ -143,6 +146,7 @@ private: Encoder *encoder_; libcamera::FrameBufferAllocator *allocator_; std::vector buffers_; + std::mutex *mutex_; }; #endif /* __ANDROID_CAMERA_STREAM__ */ From patchwork Mon Oct 5 10:46:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9960 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 36B75C3B5F for ; Mon, 5 Oct 2020 10:47:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 02CB463C1F; Mon, 5 Oct 2020 12:47:44 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="phrqZ+Gk"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B9E4163C08 for ; Mon, 5 Oct 2020 12:47:38 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4D994A31; Mon, 5 Oct 2020 12:47:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1601894858; bh=UYKI8QlWPGQWBii1RikJ8CsvwuSY1PSlV+0b+XZHnJE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=phrqZ+Gkq6X2jh5T/sHhUTBinVlYgPp5El9SvmZBUQLRVhZgjyBwy8s3UQX/XEStc km4uxQXapyMx0MjWZ1mrD4v4RAeZpaQ4OsCa3Al+RZZl1iMnH1kdgdn5+IBiW3Kuxg ZOrmpU8xtUZr0mkeqgPra4Nl30V1qOeA8pgR04Jg= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Oct 2020 13:46:47 +0300 Message-Id: <20201005104649.10812-14-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> References: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 13/15] 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" From: Jacopo Mondi Now that CameraStream that require internal buffer allocation have been instrumented with a FrameBuffer pool, use them to create intermediate buffers in the CameraDevice. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/android/camera_device.cpp | 50 ++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 62307726aea9..186c9f724c3e 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1390,24 +1390,47 @@ 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->outputFormat() == 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; + 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); } @@ -1479,6 +1502,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 Mon Oct 5 10:46:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9961 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 92AC4C3B5D for ; Mon, 5 Oct 2020 10:47:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5B93363C73; Mon, 5 Oct 2020 12:47:44 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="G4CePw2D"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2907963C28 for ; Mon, 5 Oct 2020 12:47:39 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id AB2543B; Mon, 5 Oct 2020 12:47:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1601894858; bh=9IH1UHV2WxoRxVolEa8kzkFzDF5R9flzDxiv7hb/0Ac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G4CePw2Df4iQhYPE5rRKwrRxdp/kHlhJw40ySixY37mVtsiJPfrjrWzYN/3ZRoHtC kWrkL4eqEtOvYY8IisF9aRwf1m+LZ1x2IeLXg2bePz1imQTZAu/hgHJFYbtDtnqHmt eLf/IyJNZHTL+ir5Wm10+F2wdCOQLybNtgy3rUh0= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Oct 2020 13:46:48 +0300 Message-Id: <20201005104649.10812-15-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> References: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 14/15] 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" From: Jacopo Mondi 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: 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 186c9f724c3e..1a9af2e34340 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1379,7 +1379,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); @@ -1390,6 +1393,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->size().toString() << ")[" + << cameraStream->format().toString() << "]"; + /* * Inspect the camera stream type, create buffers opportunely * and add them to the Request if required. @@ -1401,6 +1411,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: @@ -1412,6 +1423,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: @@ -1423,6 +1435,7 @@ int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Reques * once it has been processed. */ buffer = cameraStream->getBuffer(); + LOG(HAL, Debug) << ss.str() << " (internal)"; break; } if (!buffer) { From patchwork Mon Oct 5 10:46:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9962 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 E8AB2C3B5F for ; Mon, 5 Oct 2020 10:47:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AF4F663C74; Mon, 5 Oct 2020 12:47:44 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="fLAHW+OU"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 80AF163BD5 for ; Mon, 5 Oct 2020 12:47:39 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1925859E; Mon, 5 Oct 2020 12:47:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1601894859; bh=9fnEmf+uRGJAlayAfulaFQMZza6rsz9bQhIEF1SdMX4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fLAHW+OUmIMFxM5TpH5t3+B2wnmU2r9Dba+0EYCUoSNKv/LaXMFVDjvuBEheI8CXZ olgu4vDL9ZP+gI+DjbJlDd4b6jfRf3mPokpihkUm4qs9DeIiHW081zQXFoaPmHt+uw hqgC2z9vuy4kaHBaWiPdYLZiQF1l/EAL9ES2PMjo= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 5 Oct 2020 13:46:49 +0300 Message-Id: <20201005104649.10812-16-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> References: <20201005104649.10812-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 15/15] 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" From: Jacopo Mondi 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. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- 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 1a9af2e34340..6bbdfcc4a28b 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();