From patchwork Mon Jun 29 16:29:53 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 27111 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 451D4C3261 for ; Mon, 29 Jun 2026 16:31:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C1B2C65F6E; Mon, 29 Jun 2026 18:31:22 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="nRJGZKit"; 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 ACD1E65F52 for ; Mon, 29 Jun 2026 18:30:27 +0200 (CEST) Received: from pb-laptop.local (185.221.140.128.nat.pool.zt.hu [185.221.140.128]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 889AB8D4 for ; Mon, 29 Jun 2026 18:29:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1782750584; bh=6zMfW1QrfaD4094EYcb4KWHpwrWoVkq8ywougfxB1r0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nRJGZKithasI2eBM2mfWr08BTCsZH6c9lzCKVCn/lFIOrrVgbvI/egBCUd2j+Gzy1 H1OUl/ejL/T+4NYULjB7Q20TdoXtg7ibwdrZ56y1amEwzZc2pojVOrwPQoA0jIeVTG co2Ojj6xVfIagNIrp1hIDlAdhRS+JsOf082IopdM= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [RFC PATCH v1 30/54] libcamera: camera: acquireBuffer(): Add Date: Mon, 29 Jun 2026 18:29:53 +0200 Message-ID: <20260629163017.863145-31-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260629163017.863145-1-barnabas.pocze@ideasonboard.com> References: <20260629163017.863145-1-barnabas.pocze@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add an internal function for pipeeline handlers that can be used to retrieve a buffer from the pool of a specific stream. Signed-off-by: Barnabás Pőcze --- include/libcamera/internal/camera.h | 11 +++++++++ src/libcamera/camera.cpp | 36 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/include/libcamera/internal/camera.h b/include/libcamera/internal/camera.h index 6ba77eb882..31914075f0 100644 --- a/include/libcamera/internal/camera.h +++ b/include/libcamera/internal/camera.h @@ -49,6 +49,17 @@ public: const CameraControlValidator *validator() const { return validator_.get(); } +#ifndef __DOXYGEN__ + struct FrameBufferPoolDeleter { + std::vector *pool = nullptr; + void operator()(FrameBuffer *buffer) const; + }; +#endif + + using PooledFrameBuffer = std::unique_ptr; + + [[nodiscard]] PooledFrameBuffer acquireBuffer(const Stream *stream); + private: enum State { CameraAvailable, diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 27dae3a403..016f36e796 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -754,6 +754,42 @@ Camera::Private::PendingFence::PendingFence(const Stream *s, FrameBuffer *b) buffer(b) { } + +/** + * \typedef Camera::Private::PooledFrameBuffer + * \brief An std::unique_ptr for automatically returning the FrameBuffer to the pool to simplify error handling. + */ + +#ifndef __DOXYGEN__ +void Camera::Private::FrameBufferPoolDeleter::operator()(FrameBuffer *buffer) const +{ + pool->push_back(buffer); +} +#endif + +/** + * \brief Acquire a buffer for a stream + * \param[in] stream The stream + * + * \return A buffer or an empty handle if not available + */ +Camera::Private::PooledFrameBuffer +Camera::Private::acquireBuffer(const Stream *stream) +{ + auto it = streamData_.find(stream); + if (it == streamData_.end() || !it->second.active || it->second.buffers.empty()) + return {}; + + FrameBuffer *buffer = it->second.buffers.back(); + buffer->_d()->stream_ = stream; + + LOG(Camera, Debug) + << "Camera:" << LIBCAMERA_O_PTR() << " acquired buffer:" + << buffer << " for stream:" << stream; + + it->second.buffers.pop_back(); + return { buffer, { &it->second.buffers } }; +} #endif /* __DOXYGEN_PUBLIC__ */ /**