From patchwork Mon Nov 3 21:30:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 24955 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 05F30BDE4C for ; Mon, 3 Nov 2025 21:29:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2890460A8A; Mon, 3 Nov 2025 22:29:45 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.b="rLmw9oMa"; dkim-atps=neutral Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8A48F609D8 for ; Mon, 3 Nov 2025 22:29:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=/vMh/6/YtHaKdQ17o9NZ4SR1gcacTFRGywsSl3TKXmA=; b=rLmw9oMaznn4TAT+SaYLxdCEtx ioYeP5IGD+EtB8DHUZ3rnS5RH7Vmm6LX5ZgxEDkMki2+jW4+6ZNHMQQMvuq3+t2TZr6MQkcNKRKpJ rI//ejG2bULqNqB8pvxGfiji7F0GhirC715+zuexLekFgcXbsKaxcebMcSJH9hKWkkGKg4J+tO4tc TguLgK5JQsaFqWfazb8dSGCrGdk5S/kNcSR7nW3fcVrijx9GE/ANIrMgxA11yHD+Qw+kXUgm29n+i hZ1alqBLN92njhKlZIME1eltzBZvV6lyYmaFQtAPPfH1Byhs1J79oTlx45eHoBe87AfhHBsPwlgTX ci2hHmoA==; Received: from [81.140.124.245] (helo=uajain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1vG27S-0013tS-1T; Mon, 03 Nov 2025 22:29:42 +0100 From: Umang Jain To: libcamera-devel@lists.libcamera.org Cc: Nicolas Dufresne , Umang Jain Subject: [PATCH v4 1/3] gstreamer: Associate libcamera::Stream with GstPad Date: Mon, 3 Nov 2025 21:30:12 +0000 Message-ID: <20251103213014.62713-2-uajain@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251103213014.62713-1-uajain@igalia.com> References: <20251103213014.62713-1-uajain@igalia.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" Instead of trying to figure out which libcamera::Stream, the GstPad is configured with (from the libcamera pool), associate the Stream with the GstPad directly. The association can be set using gst_pad_set_element_private(). Add the gst_libcamera_pad_set_stream() helper to associate the stream with the pad. Additionally, modify the gst_libcamera_pad_get_stream() to use to the getter helper gst_pad_get_element_private(). Signed-off-by: Umang Jain --- src/gstreamer/gstlibcamerapad.cpp | 11 ++++++----- src/gstreamer/gstlibcamerapad.h | 2 ++ src/gstreamer/gstlibcamerasrc.cpp | 6 +++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/gstreamer/gstlibcamerapad.cpp b/src/gstreamer/gstlibcamerapad.cpp index 22b96719..b37c4b34 100644 --- a/src/gstreamer/gstlibcamerapad.cpp +++ b/src/gstreamer/gstlibcamerapad.cpp @@ -192,12 +192,13 @@ void gst_libcamera_pad_set_video_info(GstPad *pad, const GstVideoInfo *info) Stream * gst_libcamera_pad_get_stream(GstPad *pad) { - auto *self = GST_LIBCAMERA_PAD(pad); - - if (self->pool) - return gst_libcamera_pool_get_stream(self->pool); + return static_cast(gst_pad_get_element_private(pad)); +} - return nullptr; +void +gst_libcamera_pad_set_stream(GstPad *pad, Stream *stream) +{ + gst_pad_set_element_private(pad, stream); } void diff --git a/src/gstreamer/gstlibcamerapad.h b/src/gstreamer/gstlibcamerapad.h index f98b8a7f..bbd7c687 100644 --- a/src/gstreamer/gstlibcamerapad.h +++ b/src/gstreamer/gstlibcamerapad.h @@ -33,4 +33,6 @@ void gst_libcamera_pad_set_video_info(GstPad *pad, const GstVideoInfo *info); libcamera::Stream *gst_libcamera_pad_get_stream(GstPad *pad); +void gst_libcamera_pad_set_stream(GstPad *pad, libcamera::Stream *stream); + void gst_libcamera_pad_set_latency(GstPad *pad, GstClockTime latency); diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index 011a12fc..bd79b769 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -357,7 +357,7 @@ int GstLibcameraSrcState::processRequest() GstBuffer *buffer = wrap->detachBuffer(stream); FrameBuffer *fb = gst_libcamera_buffer_get_frame_buffer(buffer); - const StreamConfiguration &stream_cfg = config_->at(i); + const StreamConfiguration &stream_cfg = stream->configuration(); GstBufferPool *video_pool = gst_libcamera_pad_get_video_pool(srcpad); if (video_pool) { @@ -692,6 +692,9 @@ gst_libcamera_src_negotiate(GstLibcameraSrc *self) gst_libcamera_pad_set_pool(srcpad, pool); gst_libcamera_pad_set_video_pool(srcpad, video_pool); + /* Associate the configured stream with the source pad. */ + gst_libcamera_pad_set_stream(srcpad, stream_cfg.stream()); + /* Clear all reconfigure flags. */ gst_pad_check_reconfigure(srcpad); } @@ -888,6 +891,7 @@ gst_libcamera_src_task_leave([[maybe_unused]] GstTask *task, for (GstPad *srcpad : state->srcpads_) { gst_libcamera_pad_set_latency(srcpad, GST_CLOCK_TIME_NONE); gst_libcamera_pad_set_pool(srcpad, nullptr); + gst_libcamera_pad_set_stream(srcpad, nullptr); } } From patchwork Mon Nov 3 21:30:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 24956 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 F2C54BDE4C for ; Mon, 3 Nov 2025 21:29:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1C6D3609E0; Mon, 3 Nov 2025 22:29:46 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.b="NvGM0LLe"; dkim-atps=neutral Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 86CF9606A0 for ; Mon, 3 Nov 2025 22:29:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=5LplDBP1uUWMozLUJOJ1wlxSmSi8jM+UCwkHsYU5698=; b=NvGM0LLeQKM7bd16RF4H6ulWfA 36FKiLJ+zIATbSckt4EaJQH08sjUPLVmSARFxB7LLmXeriqw0ZViJr68NPKhyptLtzMrs25IEYlLv xDBinKVynP/5SvvZ1lskh+0nCKObXZieBbiNCQG/B2mR3rOeSFSAMpWeLLmPSMAHIDxiNqXDIkZ7Q p/1rIN2hTalZx7HgWycKqCl4+GZPfCbHp/n3GwelY9YcX8jIpC+fLp2NKZ5LHLDQP9QFcE8bCkAM2 GIWzO9cX7dI2BzVDQRrmi7Cn0Hj+6af8297I9ffZ8HUDz8GUrOA8kIfHizSaOKc8uoppGrI1/+WX8 fkG2Ryiw==; Received: from [81.140.124.245] (helo=uajain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1vG27S-0013tS-Ee; Mon, 03 Nov 2025 22:29:42 +0100 From: Umang Jain To: libcamera-devel@lists.libcamera.org Cc: Nicolas Dufresne , Umang Jain , =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v4 2/3] gstreamer: Improve logging for buffer pool activation Date: Mon, 3 Nov 2025 21:30:13 +0000 Message-ID: <20251103213014.62713-3-uajain@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251103213014.62713-1-uajain@igalia.com> References: <20251103213014.62713-1-uajain@igalia.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" If the negotiation is going to fail, log the GST_ELEMENT_ERROR in gst_libcamera_src_negotiate(), instead of logging in downstream method chain. Signed-off-by: Umang Jain Reviewed-by: Nicolas Dufresne Reviewed-by: Barnabás Pőcze --- src/gstreamer/gstlibcamerasrc.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index bd79b769..5443b062 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -574,12 +574,8 @@ gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad, gst_buffer_pool_set_config(GST_BUFFER_POOL_CAST(pool), config); } - if (!gst_buffer_pool_set_active(pool, true)) { - GST_ELEMENT_ERROR(self, RESOURCE, SETTINGS, - ("Failed to active buffer pool"), - ("gst_libcamera_src_negotiate() failed.")); + if (!gst_buffer_pool_set_active(pool, true)) return { nullptr, -EINVAL }; - } return { std::exchange(pool, nullptr), 0 }; } @@ -680,8 +676,12 @@ gst_libcamera_src_negotiate(GstLibcameraSrc *self) std::tie(video_pool, ret) = gst_libcamera_create_video_pool(self, srcpad, caps, &info); - if (ret) + if (ret) { + GST_ELEMENT_ERROR(self, RESOURCE, SETTINGS, + ("Failed to create video pool: %s", g_strerror(-ret)), + ("gst_libcamera_src_negotiate() failed.")); return false; + } } GstLibcameraPool *pool = gst_libcamera_pool_new(self->allocator, From patchwork Mon Nov 3 21:30:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 24957 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 DF34FC3259 for ; Mon, 3 Nov 2025 21:29:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A817360A9D; Mon, 3 Nov 2025 22:29:46 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.b="b7Yk6EvQ"; dkim-atps=neutral Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 91CAE60A80 for ; Mon, 3 Nov 2025 22:29:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=CnC0/1uAbE7yMbEwOPuIdEUN5t/5It+svlclkEm+FRc=; b=b7Yk6EvQKrpT1GnL9/tlOkh5aW zDdWSls0MmOuGQeFIiXs1GCeFhvgKeEZ5P/irelow6mhEu/Y47HZj8cuMbt8zi5aEo05Fkd9FzX6L NYYnjnguWgVgjOslvA2/EOBLeAQDDO1PxstX3KbnG2P4cJV3KIFyGr1ofQ9JuxCxWWDhJd0hUcNV4 4MbJ0gXI0MHIJ4l0HTYH1T06/TsSmffT5w3gCAbtnH5XSRdqQuar6ZpCWUxMQd7r9Y2Z61LedGAtg tPWJqYsEudTrzOPJZ2gDQD8rh2eEevm7CyreBrpnJECTtcW70Z58rWP733joL3090XWztweOf/QRL FAMOe3Dw==; Received: from [81.140.124.245] (helo=uajain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1vG27S-0013tS-QQ; Mon, 03 Nov 2025 22:29:42 +0100 From: Umang Jain To: libcamera-devel@lists.libcamera.org Cc: Nicolas Dufresne , Umang Jain Subject: [PATCH v4 3/3] gstreamer: Track RequestWrap's GstBuffer using GstPad Date: Mon, 3 Nov 2025 21:30:14 +0000 Message-ID: <20251103213014.62713-4-uajain@igalia.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251103213014.62713-1-uajain@igalia.com> References: <20251103213014.62713-1-uajain@igalia.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" GstPad is the link point where the buffers are pushed/pulled in the gstreamer pipeline hence, it makes more sense to associate and track GstBuffer(s) using GstPad rather than libcamera::Stream in RequestWrap. No functional changes intended as there is only one stream per pad configuration followed in libcamerasrc. Signed-off-by: Umang Jain Reviewed-by: Nicolas Dufresne --- src/gstreamer/gstlibcamerasrc.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index 5443b062..391b228d 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -48,11 +48,11 @@ struct RequestWrap { RequestWrap(std::unique_ptr request); ~RequestWrap(); - void attachBuffer(Stream *stream, GstBuffer *buffer); - GstBuffer *detachBuffer(Stream *stream); + void attachBuffer(GstPad *srcpad, GstBuffer *buffer); + GstBuffer *detachBuffer(GstPad *srcpad); std::unique_ptr request_; - std::map buffers_; + std::map buffers_; GstClockTime latency_; GstClockTime pts_; @@ -65,32 +65,33 @@ RequestWrap::RequestWrap(std::unique_ptr request) RequestWrap::~RequestWrap() { - for (std::pair &item : buffers_) { + for (std::pair &item : buffers_) { if (item.second) gst_buffer_unref(item.second); } } -void RequestWrap::attachBuffer(Stream *stream, GstBuffer *buffer) +void RequestWrap::attachBuffer(GstPad *srcpad, GstBuffer *buffer) { FrameBuffer *fb = gst_libcamera_buffer_get_frame_buffer(buffer); + Stream *stream = gst_libcamera_pad_get_stream(srcpad); request_->addBuffer(stream, fb); - auto item = buffers_.find(stream); + auto item = buffers_.find(srcpad); if (item != buffers_.end()) { gst_buffer_unref(item->second); item->second = buffer; } else { - buffers_[stream] = buffer; + buffers_[srcpad] = buffer; } } -GstBuffer *RequestWrap::detachBuffer(Stream *stream) +GstBuffer *RequestWrap::detachBuffer(GstPad *srcpad) { GstBuffer *buffer = nullptr; - auto item = buffers_.find(stream); + auto item = buffers_.find(srcpad); if (item != buffers_.end()) { buffer = item->second; item->second = nullptr; @@ -189,7 +190,6 @@ int GstLibcameraSrcState::queueRequest() std::make_unique(std::move(request)); for (GstPad *srcpad : srcpads_) { - Stream *stream = gst_libcamera_pad_get_stream(srcpad); GstLibcameraPool *pool = gst_libcamera_pad_get_pool(srcpad); GstBuffer *buffer; GstFlowReturn ret; @@ -204,7 +204,7 @@ int GstLibcameraSrcState::queueRequest() return -ENOBUFS; } - wrap->attachBuffer(stream, buffer); + wrap->attachBuffer(srcpad, buffer); } GST_TRACE_OBJECT(src_, "Requesting buffers"); @@ -354,7 +354,7 @@ int GstLibcameraSrcState::processRequest() for (gsize i = 0; i < srcpads_.size(); i++) { GstPad *srcpad = srcpads_[i]; Stream *stream = gst_libcamera_pad_get_stream(srcpad); - GstBuffer *buffer = wrap->detachBuffer(stream); + GstBuffer *buffer = wrap->detachBuffer(srcpad); FrameBuffer *fb = gst_libcamera_buffer_get_frame_buffer(buffer); const StreamConfiguration &stream_cfg = stream->configuration();