From patchwork Tue Sep 22 09:47:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 9689 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 33F6EBF01C for ; Tue, 22 Sep 2020 09:44:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0775B62FD4; Tue, 22 Sep 2020 11:44:27 +0200 (CEST) Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 34A1A60364 for ; Tue, 22 Sep 2020 11:44:26 +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 relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 36CF7E0008; Tue, 22 Sep 2020 09:44:18 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Tue, 22 Sep 2020 11:47:35 +0200 Message-Id: <20200922094738.5327-6-jacopo@jmondi.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200922094738.5327-1-jacopo@jmondi.org> References: <20200922094738.5327-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 5/8] android: camera_device: Allocate buffer pools X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: hanlinchen@chromium.org Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" After the Camera has been configured, walk the list of collected CameraStream instances and allocate memory for the ones that needs intermediate buffers reserved by the libcamera FrameBufferAllocator. Maintain a map between each Stream and a vector of pointers to the associated buffers. Reviewed-by: Niklas Söderlund Signed-off-by: Jacopo Mondi --- src/android/camera_device.cpp | 36 +++++++++++++++++++++++++++++++++++ src/android/camera_device.h | 6 ++++++ 2 files changed, 42 insertions(+) diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp index 42fb9ea4e113..f96ea7321a67 100644 --- a/src/android/camera_device.cpp +++ b/src/android/camera_device.cpp @@ -1189,6 +1189,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) streams_.clear(); streams_.reserve(stream_list->num_streams); allocator_.clear(); + bufferPool_.clear(); /* First handle all non-MJPEG streams. */ camera3_stream_t *jpegStream = nullptr; @@ -1336,6 +1337,25 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list) return ret; } + /* + * Now that the camera has been configured allocate buffers for + * the streams that need memory reserved by libcamera. + */ + for (const CameraStream &cameraStream : streams_) { + const StreamConfiguration &cfg = config_->at(cameraStream.index()); + Stream *stream = cfg.stream(); + + if (cameraStream.type() != CameraStream::Type::Internal) + continue; + + ret = allocateBuffersPool(stream); + if (ret) { + LOG(HAL, Error) << "Failed to allocate buffers for stream " + << cameraStream.index(); + return ret; + } + } + return 0; } @@ -1369,6 +1389,22 @@ FrameBuffer *CameraDevice::createFrameBuffer(const buffer_handle_t camera3buffer return new FrameBuffer(std::move(planes)); } +int CameraDevice::allocateBuffersPool(Stream *stream) +{ + int ret = allocator_.allocate(stream); + if (ret < 0) + return ret; + + /* + * Save a pointer to the reserved frame buffer for usage in + * the HAL. + */ + for (const auto &frameBuffer : allocator_.buffers(stream)) + bufferPool_[stream].push_back(frameBuffer.get()); + + return 0; +} + int CameraDevice::processCaptureRequest(camera3_capture_request_t *camera3Request) { if (!camera3Request->num_output_buffers) { diff --git a/src/android/camera_device.h b/src/android/camera_device.h index 84f636f7a93c..4cef34c01a49 100644 --- a/src/android/camera_device.h +++ b/src/android/camera_device.h @@ -166,6 +166,9 @@ protected: std::string logPrefix() const override; private: + using FrameBufferPool = std::map>; + CameraDevice(unsigned int id, const std::shared_ptr &camera); struct Camera3RequestDescriptor { @@ -194,6 +197,8 @@ private: std::tuple calculateStaticMetadataSize(); libcamera::FrameBuffer *createFrameBuffer(const buffer_handle_t camera3buffer); + int allocateBuffersPool(libcamera::Stream *stream); + void notifyShutter(uint32_t frameNumber, uint64_t timestamp); void notifyError(uint32_t frameNumber, camera3_stream_t *stream); CameraMetadata *requestTemplatePreview(); @@ -208,6 +213,7 @@ private: std::shared_ptr camera_; std::unique_ptr config_; libcamera::FrameBufferAllocator allocator_; + FrameBufferPool bufferPool_; CameraMetadata *staticMetadata_; std::map requestTemplates_;