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__ */