From patchwork Tue Oct 6 14:44:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9972 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 7A06DBEEDF for ; Tue, 6 Oct 2020 14:40:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 56B7563C9F; Tue, 6 Oct 2020 16:40:44 +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 F102863C13 for ; Tue, 6 Oct 2020 16:40:42 +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 AB09760002; Tue, 6 Oct 2020 14:40:41 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 6 Oct 2020 16:44:22 +0200 Message-Id: <20201006144432.22908-4-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201006144432.22908-1-jacopo@jmondi.org> References: <20201006144432.22908-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 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_;