From patchwork Thu Jun 18 12:38:38 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: 26986 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 99DC7C3323 for ; Thu, 18 Jun 2026 12:39:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2C97765718; Thu, 18 Jun 2026 14:39:26 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="JHH/wm8h"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9D82E656C1 for ; Thu, 18 Jun 2026 14:38:52 +0200 (CEST) Received: from pb-laptop.local (185.182.214.63.nat.pool.zt.hu [185.182.214.63]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id BAECB2F8 for ; Thu, 18 Jun 2026 14:38:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1781786297; bh=DUQ/KdTHe3MZyPeFGHix4N1v0F/tbiou66p+M6o+MDM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=JHH/wm8hsEBmY1RxA5hcpOpXFh75UGMoamxiFqQgmX2SyUEtyTMbdY5VcqxkUloLK 4GhcUdNvIiamRYkvMHmiZrY6kuoAthmW3hcgxKape3m72Dle2a8pxeiTyEf0jtVCZm xn/GisakvCPXxXhQL0MT9sSCfv/YMUpw33TbB1Ik= From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= To: libcamera-devel@lists.libcamera.org Subject: [RFC PATCH v1 21/27] gstreamer: Use `FrameBuffer` cookie to associate with `GstBuffer` Date: Thu, 18 Jun 2026 14:38:38 +0200 Message-ID: <20260618123844.656396-22-barnabas.pocze@ideasonboard.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260618123844.656396-1-barnabas.pocze@ideasonboard.com> References: <20260618123844.656396-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" Use the `FrameBuffer`'s arbitrary "cookie" data to reference the associated `GstBuffer` while the `FrameBuffer` is attached to a particular request. Otherwise keep the cookie 0. This is allowed since the `FrameBuffer`s are allocated with the `FrameBufferAllocator`. This also removes the need for the explicit mapping of Stream -> GstBuffer in `RequestWrap`. Signed-off-by: Barnabás Pőcze --- src/gstreamer/gstlibcamerasrc.cpp | 37 ++++++++++++++++--------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index 5d3ee3a213..9061f9163c 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -52,7 +52,6 @@ struct RequestWrap { GstBuffer *detachBuffer(GstPad *srcpad); std::unique_ptr request_; - std::map buffers_; GstClockTime latency_; GstClockTime pts_; @@ -65,9 +64,15 @@ RequestWrap::RequestWrap(std::unique_ptr request) RequestWrap::~RequestWrap() { - for (std::pair &item : buffers_) { - if (item.second) - gst_buffer_unref(item.second); + if (!request_) + return; + + for (const auto &[stream, fb] : request_->buffers()) { + auto *buffer = reinterpret_cast(fb->cookie()); + if (buffer) + gst_buffer_unref(buffer); + + fb->setCookie(0); } } @@ -77,25 +82,21 @@ void RequestWrap::attachBuffer(GstPad *srcpad, GstBuffer *buffer) Stream *stream = gst_libcamera_pad_get_stream(srcpad); request_->addBuffer(stream, fb); - - auto item = buffers_.find(srcpad); - if (item != buffers_.end()) { - gst_buffer_unref(item->second); - item->second = buffer; - } else { - buffers_[srcpad] = buffer; - } + fb->setCookie(reinterpret_cast(buffer)); } GstBuffer *RequestWrap::detachBuffer(GstPad *srcpad) { - GstBuffer *buffer = nullptr; + const Stream *stream = gst_libcamera_pad_get_stream(srcpad); + FrameBuffer *fb = request_->findBuffer(stream); + if (!fb) + return nullptr; - auto item = buffers_.find(srcpad); - if (item != buffers_.end()) { - buffer = item->second; - item->second = nullptr; - } + auto *buffer = reinterpret_cast(fb->cookie()); + + fb->setCookie(0); + + g_assert(!buffer || fb == gst_libcamera_buffer_get_frame_buffer(buffer)); return buffer; }