From patchwork Wed Jun 4 13:07:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 23462 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 99AF1C31E9 for ; Wed, 4 Jun 2025 13:07:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id ACB5C68DC2; Wed, 4 Jun 2025 15:07:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="tA52AUVh"; 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 C8B2868DA8 for ; Wed, 4 Jun 2025 15:07:52 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C507CD21; Wed, 4 Jun 2025 15:07:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1749042470; bh=oHdMYAWVQJ61xAla214M0VduvDQQTO3f+76Zlwi9opU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tA52AUVhIW/YwJLOyRNhwF0WcijKSpsi4Ao/37UeT8fguNcSJegm1p2uky+y7b6ef D1fr0gbiWp8gs3eM4U7yArW4BOvvNmFIYhiGjI7CRsbAW5djAZC3cJj6HZPGS6060Z OdyubfH1g8HGmJQcu1YkmVLBid92TLUSBJjtqGjU= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Hou Qi , Nicolas Dufresne Subject: [PATCH v2 1/7] gstreamer: Document improvements when updating minimum GStreamer version Date: Wed, 4 Jun 2025 16:07:35 +0300 Message-ID: <20250604130741.9228-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250604130741.9228-1-laurent.pinchart@ideasonboard.com> References: <20250604130741.9228-1-laurent.pinchart@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" A const_cast<> was recently added to fix a compilation issue with older GStreamer versions. Add a comment to indicate it can be removed when bumping the minimum GStreamer version requirement. While at it, also document a possible future improvement in the same function, and wrap long lines. Signed-off-by: Laurent Pinchart Reviewed-by: Nicolas Dufresne --- src/gstreamer/gstlibcamerasrc.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index b34f089778ec..6ede43b06a8a 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -285,10 +285,19 @@ gst_libcamera_extrapolate_info(GstVideoInfo *info, guint32 stride) } static GstFlowReturn -gst_libcamera_video_frame_copy(GstBuffer *src, GstBuffer *dest, const GstVideoInfo *dest_info, guint32 stride) +gst_libcamera_video_frame_copy(GstBuffer *src, GstBuffer *dest, + const GstVideoInfo *dest_info, guint32 stride) { - GstVideoInfo src_info = *dest_info; + /* + * When dropping support for versions earlier than v1.22.0, use + * + * g_auto (GstVideoFrame) src_frame = GST_VIDEO_FRAME_INIT; + * g_auto (GstVideoFrame) dest_frame = GST_VIDEO_FRAME_INIT; + * + * and drop the gst_video_frame_unmap() calls. + */ GstVideoFrame src_frame, dest_frame; + GstVideoInfo src_info = *dest_info; gst_libcamera_extrapolate_info(&src_info, stride); src_info.size = gst_buffer_get_size(src); @@ -298,7 +307,12 @@ gst_libcamera_video_frame_copy(GstBuffer *src, GstBuffer *dest, const GstVideoIn return GST_FLOW_ERROR; } - if (!gst_video_frame_map(&dest_frame, const_cast(dest_info), dest, GST_MAP_WRITE)) { + /* + * When dropping support for versions earlier than 1.20.0, drop the + * const_cast<>(). + */ + if (!gst_video_frame_map(&dest_frame, const_cast(dest_info), + dest, GST_MAP_WRITE)) { GST_ERROR("Could not map dest buffer"); gst_video_frame_unmap(&src_frame); return GST_FLOW_ERROR; From patchwork Wed Jun 4 13:07:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 23463 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 7689BC3292 for ; Wed, 4 Jun 2025 13:08:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9092F68DC7; Wed, 4 Jun 2025 15:07:58 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Xhbob2ib"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 84F5468DC1 for ; Wed, 4 Jun 2025 15:07:54 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2A126E9B; Wed, 4 Jun 2025 15:07:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1749042471; bh=ZkDsFV+6zDls/l9g2PWIQ13Lo2Mw0xjgolYQ/ZsZ2Mk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xhbob2ibEzLYIbQfekpclDa/DXt6Io3Da+OJoc34WiQd/afZflGqdp4i10Q2L+3dX VBISXS6z1noPdrZgkZDF26IQaAA/8k+o6NaahWOW8OT+fBvn91vhcnabVg2d0dIbj7 5fIxZYmhwsAstqLaheTUaEVWj0jwG8qjKDtorxeU= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Hou Qi , Nicolas Dufresne Subject: [PATCH v2 2/7] gstreamer: Factor out video pool creation Date: Wed, 4 Jun 2025 16:07:36 +0300 Message-ID: <20250604130741.9228-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250604130741.9228-1-laurent.pinchart@ideasonboard.com> References: <20250604130741.9228-1-laurent.pinchart@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" The gst_libcamera_src_negotiate() function uses 5 identation levels, causing long lines. Move video pool creation to a separate function to increase readability. Signed-off-by: Laurent Pinchart Reviewed-by: Nicolas Dufresne --- Changes since v1: - Document the gst_libcamera_create_video_pool() function - Keep the gst_libcamera_extrapolate_info() call out of the new function - Reorder function arguments --- src/gstreamer/gstlibcamerasrc.cpp | 114 +++++++++++++++++++----------- 1 file changed, 72 insertions(+), 42 deletions(-) -- Regards, Laurent Pinchart diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index 6ede43b06a8a..79b94c7ee7c2 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -521,6 +522,72 @@ gst_libcamera_src_open(GstLibcameraSrc *self) return true; } +/** + * \brief Create a video pool for a pad + * \param[in] self The libcamerasrc instance + * \param[in] srcpad The pad + * \param[in] caps The pad caps + * \param[in] info The video info for the pad + * + * This function creates and returns a video buffers pool for the given pad if + * needed to accommodate stride mismatch. If the peer element supports the meta + * API, the stride will be negotiated, and no pool if needed. + * + * \return A tuple containing the video buffers pool pointer and an error code. + * When no error occurs, the pool can be null if the peer element supports + * stride negotiation. + */ +static std::tuple +gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad, + GstCaps *caps, const GstVideoInfo *info) +{ + GstQuery *query = NULL; + const gboolean need_pool = true; + gboolean has_video_meta = false; + GstBufferPool *video_pool = NULL; + + query = gst_query_new_allocation(caps, need_pool); + if (!gst_pad_peer_query(srcpad, query)) + GST_DEBUG_OBJECT(self, "Didn't get downstream ALLOCATION hints"); + else + has_video_meta = gst_query_find_allocation_meta(query, GST_VIDEO_META_API_TYPE, NULL); + + if (!has_video_meta) { + GstBufferPool *pool = NULL; + + if (gst_query_get_n_allocation_pools(query) > 0) + gst_query_parse_nth_allocation_pool(query, 0, &pool, NULL, NULL, NULL); + + if (pool) + video_pool = pool; + else { + GstStructure *config; + guint min_buffers = 3; + video_pool = gst_video_buffer_pool_new(); + + config = gst_buffer_pool_get_config(video_pool); + gst_buffer_pool_config_set_params(config, caps, info->size, min_buffers, 0); + + GST_DEBUG_OBJECT(self, "Own pool config is %" GST_PTR_FORMAT, config); + + gst_buffer_pool_set_config(GST_BUFFER_POOL_CAST(video_pool), config); + } + + GST_WARNING_OBJECT(self, "Downstream doesn't support video meta, need to copy frame."); + + if (!gst_buffer_pool_set_active(video_pool, true)) { + gst_caps_unref(caps); + GST_ELEMENT_ERROR(self, RESOURCE, SETTINGS, + ("Failed to active buffer pool"), + ("gst_libcamera_src_negotiate() failed.")); + return { NULL, -EINVAL }; + } + } + + gst_query_unref(query); + return { video_pool, 0 }; +} + /* Must be called with stream_lock held. */ static bool gst_libcamera_src_negotiate(GstLibcameraSrc *self) @@ -603,50 +670,13 @@ gst_libcamera_src_negotiate(GstLibcameraSrc *self) /* Stride mismatch between camera stride and that calculated by video-info. */ if (static_cast(info.stride[0]) != stream_cfg.stride && GST_VIDEO_INFO_FORMAT(&info) != GST_VIDEO_FORMAT_ENCODED) { - GstQuery *query = NULL; - const gboolean need_pool = true; - gboolean has_video_meta = false; - gst_libcamera_extrapolate_info(&info, stream_cfg.stride); - query = gst_query_new_allocation(caps, need_pool); - if (!gst_pad_peer_query(srcpad, query)) - GST_DEBUG_OBJECT(self, "Didn't get downstream ALLOCATION hints"); - else - has_video_meta = gst_query_find_allocation_meta(query, GST_VIDEO_META_API_TYPE, NULL); - - if (!has_video_meta) { - GstBufferPool *pool = NULL; - - if (gst_query_get_n_allocation_pools(query) > 0) - gst_query_parse_nth_allocation_pool(query, 0, &pool, NULL, NULL, NULL); - - if (pool) - video_pool = pool; - else { - GstStructure *config; - guint min_buffers = 3; - video_pool = gst_video_buffer_pool_new(); - - config = gst_buffer_pool_get_config(video_pool); - gst_buffer_pool_config_set_params(config, caps, info.size, min_buffers, 0); - - GST_DEBUG_OBJECT(self, "Own pool config is %" GST_PTR_FORMAT, config); - - gst_buffer_pool_set_config(GST_BUFFER_POOL_CAST(video_pool), config); - } - - GST_WARNING_OBJECT(self, "Downstream doesn't support video meta, need to copy frame."); - - if (!gst_buffer_pool_set_active(video_pool, true)) { - gst_caps_unref(caps); - GST_ELEMENT_ERROR(self, RESOURCE, SETTINGS, - ("Failed to active buffer pool"), - ("gst_libcamera_src_negotiate() failed.")); - return false; - } - } - gst_query_unref(query); + std::tie(video_pool, ret) = + gst_libcamera_create_video_pool(self, srcpad, + caps, &info); + if (ret) + return false; } GstLibcameraPool *pool = gst_libcamera_pool_new(self->allocator, From patchwork Wed Jun 4 13:07:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 23464 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 2E14AC31E9 for ; Wed, 4 Jun 2025 13:08:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 89D0C68DCA; Wed, 4 Jun 2025 15:08:00 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="XFuNdR1R"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8C91068DC0 for ; Wed, 4 Jun 2025 15:07:55 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 873B2F06; Wed, 4 Jun 2025 15:07:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1749042472; bh=k5AMkQ9sZMlhVVl9Foe/Ti7UHKmGFRzesfL1xPPaMO0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XFuNdR1RfprzlQqRTGqy/ufiQdQ1xUlDpDaHXBz5cYfRzi9T1AJDGiGQw4+DHNqsx pQK9hbLhP1oQxlwmky5gRQAlRT1KN0eStRBti4xtpMe0WeIs048RdZ5NKoTBEkMV+n +pqbCm3fxlQko2b+TpTKcHixrt0EoDFz+dca0DM8= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Hou Qi , Nicolas Dufresne Subject: [PATCH v2 3/7] gstreamer: Reduce indentation in gst_libcamera_create_video_pool() Date: Wed, 4 Jun 2025 16:07:37 +0300 Message-ID: <20250604130741.9228-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250604130741.9228-1-laurent.pinchart@ideasonboard.com> References: <20250604130741.9228-1-laurent.pinchart@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" Now that video pool creation is handled by a dedicated function, the logic can be simplified by returning early instead of nesting scopes. Do so to decrease indentation and improve readability, and document the implementation of the function with comments. Signed-off-by: Laurent Pinchart Reviewed-by: Nicolas Dufresne --- Changes since v1: - Fixed regression that didn't allocate a pool when the peer allocation can't be queried - Document the implementation of the gst_libcamera_create_video_pool() function with comments --- src/gstreamer/gstlibcamerasrc.cpp | 57 ++++++++++++++++--------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index 79b94c7ee7c2..b907a5759740 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -543,45 +543,48 @@ gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad, { GstQuery *query = NULL; const gboolean need_pool = true; - gboolean has_video_meta = false; GstBufferPool *video_pool = NULL; + /* + * Get the peer allocation hints to check if it supports the meta API. + * If so, the stride will be negotiated, and there's no need to create a + * video pool. + */ query = gst_query_new_allocation(caps, need_pool); + if (!gst_pad_peer_query(srcpad, query)) GST_DEBUG_OBJECT(self, "Didn't get downstream ALLOCATION hints"); - else - has_video_meta = gst_query_find_allocation_meta(query, GST_VIDEO_META_API_TYPE, NULL); + else if (gst_query_find_allocation_meta(query, GST_VIDEO_META_API_TYPE, NULL)) + return { NULL, 0 }; - if (!has_video_meta) { - GstBufferPool *pool = NULL; + GST_WARNING_OBJECT(self, "Downstream doesn't support video meta, need to copy frame."); - if (gst_query_get_n_allocation_pools(query) > 0) - gst_query_parse_nth_allocation_pool(query, 0, &pool, NULL, NULL, NULL); + /* + * If the allocation query has pools, use the first one. Otherwise, + * create a new pool. + */ + if (gst_query_get_n_allocation_pools(query) > 0) + gst_query_parse_nth_allocation_pool(query, 0, &video_pool, NULL, NULL, NULL); - if (pool) - video_pool = pool; - else { - GstStructure *config; - guint min_buffers = 3; - video_pool = gst_video_buffer_pool_new(); + if (!video_pool) { + GstStructure *config; + guint min_buffers = 3; - config = gst_buffer_pool_get_config(video_pool); - gst_buffer_pool_config_set_params(config, caps, info->size, min_buffers, 0); + video_pool = gst_video_buffer_pool_new(); + config = gst_buffer_pool_get_config(video_pool); + gst_buffer_pool_config_set_params(config, caps, info->size, min_buffers, 0); - GST_DEBUG_OBJECT(self, "Own pool config is %" GST_PTR_FORMAT, config); + GST_DEBUG_OBJECT(self, "Own pool config is %" GST_PTR_FORMAT, config); - gst_buffer_pool_set_config(GST_BUFFER_POOL_CAST(video_pool), config); - } + gst_buffer_pool_set_config(GST_BUFFER_POOL_CAST(video_pool), config); + } - GST_WARNING_OBJECT(self, "Downstream doesn't support video meta, need to copy frame."); - - if (!gst_buffer_pool_set_active(video_pool, true)) { - gst_caps_unref(caps); - GST_ELEMENT_ERROR(self, RESOURCE, SETTINGS, - ("Failed to active buffer pool"), - ("gst_libcamera_src_negotiate() failed.")); - return { NULL, -EINVAL }; - } + if (!gst_buffer_pool_set_active(video_pool, true)) { + gst_caps_unref(caps); + GST_ELEMENT_ERROR(self, RESOURCE, SETTINGS, + ("Failed to active buffer pool"), + ("gst_libcamera_src_negotiate() failed.")); + return { NULL, -EINVAL }; } gst_query_unref(query); From patchwork Wed Jun 4 13:07:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 23465 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 1EB05C3292 for ; Wed, 4 Jun 2025 13:08:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 512D968DBF; Wed, 4 Jun 2025 15:08:02 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="lIKBnG2C"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EA92F68DBD for ; Wed, 4 Jun 2025 15:07:56 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E233714C7; Wed, 4 Jun 2025 15:07:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1749042474; bh=cHlXNgC6c6wPP2kbB9NZhy0+fGN3x5Sp5xrxbnbyiOM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lIKBnG2CQ7Ki1MJs/ms2tRjqJP6ojCBPOWRyOhsz6S2B+AGaRmJ6KdM0sKfyKUqLd DWJoiKI21Mr04TAfHrdjZftx/3nADHQpGrbPAabdynyif8FIKT9AinUzWuM1gAe5cn YVwRaEWBTEed3831y1Pm+HA6R+7m5e18SWecV3LE= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Hou Qi , Nicolas Dufresne Subject: [PATCH v2 4/7] gstreamer: Rename variable in gst_libcamera_create_video_pool() Date: Wed, 4 Jun 2025 16:07:38 +0300 Message-ID: <20250604130741.9228-5-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250604130741.9228-1-laurent.pinchart@ideasonboard.com> References: <20250604130741.9228-1-laurent.pinchart@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" Now that the code is isolated in a function, the video_pool variable in gst_libcamera_create_video_pool() can be renamed to pool without clashing with another local variable. Do so to reduce line length. Signed-off-by: Laurent Pinchart Reviewed-by: Nicolas Dufresne --- src/gstreamer/gstlibcamerasrc.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index b907a5759740..9c0ee491ab63 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -543,7 +543,7 @@ gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad, { GstQuery *query = NULL; const gboolean need_pool = true; - GstBufferPool *video_pool = NULL; + GstBufferPool *pool = NULL; /* * Get the peer allocation hints to check if it supports the meta API. @@ -564,22 +564,22 @@ gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad, * create a new pool. */ if (gst_query_get_n_allocation_pools(query) > 0) - gst_query_parse_nth_allocation_pool(query, 0, &video_pool, NULL, NULL, NULL); + gst_query_parse_nth_allocation_pool(query, 0, &pool, NULL, NULL, NULL); - if (!video_pool) { + if (!pool) { GstStructure *config; guint min_buffers = 3; - video_pool = gst_video_buffer_pool_new(); - config = gst_buffer_pool_get_config(video_pool); + pool = gst_video_buffer_pool_new(); + config = gst_buffer_pool_get_config(pool); gst_buffer_pool_config_set_params(config, caps, info->size, min_buffers, 0); GST_DEBUG_OBJECT(self, "Own pool config is %" GST_PTR_FORMAT, config); - gst_buffer_pool_set_config(GST_BUFFER_POOL_CAST(video_pool), config); + gst_buffer_pool_set_config(GST_BUFFER_POOL_CAST(pool), config); } - if (!gst_buffer_pool_set_active(video_pool, true)) { + if (!gst_buffer_pool_set_active(pool, true)) { gst_caps_unref(caps); GST_ELEMENT_ERROR(self, RESOURCE, SETTINGS, ("Failed to active buffer pool"), @@ -588,7 +588,7 @@ gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad, } gst_query_unref(query); - return { video_pool, 0 }; + return { pool, 0 }; } /* Must be called with stream_lock held. */ From patchwork Wed Jun 4 13:07:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 23466 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 9422DC3324 for ; Wed, 4 Jun 2025 13:08:06 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6519D68DCE; Wed, 4 Jun 2025 15:08:03 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="wdbVlFq+"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4ED3D68DBF for ; Wed, 4 Jun 2025 15:07:58 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 484C5E9B; Wed, 4 Jun 2025 15:07:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1749042475; bh=QWQ2kK76rVWquzW+ySsOqLsdhZGBy2YrMXigCm1Rr/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wdbVlFq+gLLbKVJDIrfAYrDMzNFoAU5QcCg9zOlS+3nky9/reASnuxbvGp9aMrW43 6gCzj3noqAWm20zDe9MXpgDIGPzLGV1WCpnup+r/hs4+Dpbom59bsdedo7Z4i1Tc5z +K+Ld7tjSwJgc+f4pYau0O/JGPSxu0Nip82ObDUI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Hou Qi , Nicolas Dufresne Subject: [PATCH v2 5/7] gstreamer: Fix leak of GstQuery and GstBufferPool in error path Date: Wed, 4 Jun 2025 16:07:39 +0300 Message-ID: <20250604130741.9228-6-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250604130741.9228-1-laurent.pinchart@ideasonboard.com> References: <20250604130741.9228-1-laurent.pinchart@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" The gst_libcamera_create_video_pool() function leaks a GstQuery instance and a GstBufferPool instance in an error path. Fix the leaks with g_autoptr(). Signed-off-by: Laurent Pinchart Reviewed-by: Barnabás Pőcze --- src/gstreamer/gstlibcamerasrc.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index 9c0ee491ab63..0be64dd836ca 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -541,9 +541,9 @@ static std::tuple gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad, GstCaps *caps, const GstVideoInfo *info) { - GstQuery *query = NULL; + g_autoptr(GstQuery) query = NULL; + g_autoptr(GstBufferPool) pool = NULL; const gboolean need_pool = true; - GstBufferPool *pool = NULL; /* * Get the peer allocation hints to check if it supports the meta API. @@ -587,8 +587,7 @@ gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad, return { NULL, -EINVAL }; } - gst_query_unref(query); - return { pool, 0 }; + return { reinterpret_cast(g_steal_pointer(&pool)), 0 }; } /* Must be called with stream_lock held. */ From patchwork Wed Jun 4 13:07:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 23467 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 C4BE8C3325 for ; Wed, 4 Jun 2025 13:08:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E8A4868DC5; Wed, 4 Jun 2025 15:08:05 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="S1JXnwc3"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B66B968DC5 for ; Wed, 4 Jun 2025 15:07:59 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9D3E978C; Wed, 4 Jun 2025 15:07:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1749042476; bh=SkeLm18ckEG3XsrwVUnJoIMS/uEPea6GyYTPfXM4I3s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S1JXnwc39gAv3FDhycoBYg7zb7E+MDr8PhYr31wmodqV8wuvsqwpzaSJeqiI/UnW6 GQ3ifcg5ZMC6oALn71UqYESi21IrXt1NPbOZ/e0fD/bqKBT/4wJE01VfLenJIsOQpE S/U+nJzZavEHiQnxaIKZnnKBxRLTao/EnR+Cu7eU= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Hou Qi , Nicolas Dufresne Subject: [PATCH v2 6/7] gstreamer: Drop incorrect unref on caps Date: Wed, 4 Jun 2025 16:07:40 +0300 Message-ID: <20250604130741.9228-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250604130741.9228-1-laurent.pinchart@ideasonboard.com> References: <20250604130741.9228-1-laurent.pinchart@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" The caps object passeed to the gst_libcamera_create_video_pool() function is managed as a g_autoptr() in the caller. The function doesn't acquire any new reference, so it shouldn't call gst_caps_unref(). Fix it. Signed-off-by: Laurent Pinchart Reviewed-by: Nicolas Dufresne --- I believe this is right (or I wouldn't send it), but a confirmation that nothing in gst_libcamera_create_video_pool() acquires a reference to the caps would be appreciated. --- src/gstreamer/gstlibcamerasrc.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index 0be64dd836ca..eec8163e88e7 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -580,7 +580,6 @@ gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad, } if (!gst_buffer_pool_set_active(pool, true)) { - gst_caps_unref(caps); GST_ELEMENT_ERROR(self, RESOURCE, SETTINGS, ("Failed to active buffer pool"), ("gst_libcamera_src_negotiate() failed.")); From patchwork Wed Jun 4 13:07:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 23468 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 8B02EC31E9 for ; Wed, 4 Jun 2025 13:08:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 83D4368DCC; Wed, 4 Jun 2025 15:08:07 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="AHP5W7Wc"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2100068DC4 for ; Wed, 4 Jun 2025 15:08:01 +0200 (CEST) Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 148B9E9B; Wed, 4 Jun 2025 15:07:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1749042478; bh=ngJzRp2goVAmlgmuUmxkDuVfDCLV776dIXKMxzo4xI8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AHP5W7Wcd6n++H4ZamyNMtcSarZjLAdZmtLFB+Ak6VxwKCKbvSGolGp3YqCTpoYIP BftRM/dZ8Ejbq8HsMqEQZpGe7Evwf1pumDc9V9/rzznhZ2+sPgEuObnpPBARzH8phh WLVRIB1Supuyulkw2RTHUN+B4+4tRkzT67KyTaN0= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Cc: Hou Qi , Nicolas Dufresne Subject: [PATCH v2 7/7] gstreamer: Replace NULL with nullptr Date: Wed, 4 Jun 2025 16:07:41 +0300 Message-ID: <20250604130741.9228-8-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250604130741.9228-1-laurent.pinchart@ideasonboard.com> References: <20250604130741.9228-1-laurent.pinchart@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" Usage of NULL has slowly crept in the libcamerasrc sources. Replace it with nullptr. Signed-off-by: Laurent Pinchart Reviewed-by: Barnabás Pőcze Reported-by: Nicolas Dufresne Reviewed-by: Nicolas Dufresne --- src/gstreamer/gstlibcamera-controls.cpp.in | 2 +- src/gstreamer/gstlibcamerapad.cpp | 2 +- src/gstreamer/gstlibcamerasrc.cpp | 23 +++++++++++----------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/gstreamer/gstlibcamera-controls.cpp.in b/src/gstreamer/gstlibcamera-controls.cpp.in index 89c530da0b4a..2a16b39a93d9 100644 --- a/src/gstreamer/gstlibcamera-controls.cpp.in +++ b/src/gstreamer/gstlibcamera-controls.cpp.in @@ -68,7 +68,7 @@ static const GEnumValue {{ ctrl.name|snake_case }}_types[] = { "{{ enum.gst_name }}" }, {%- endfor %} - {0, NULL, NULL} + {0, nullptr, nullptr} }; #define TYPE_{{ ctrl.name|snake_case|upper }} \ diff --git a/src/gstreamer/gstlibcamerapad.cpp b/src/gstreamer/gstlibcamerapad.cpp index 3bc2bc87e773..81a0ef44cc6f 100644 --- a/src/gstreamer/gstlibcamerapad.cpp +++ b/src/gstreamer/gstlibcamerapad.cpp @@ -102,7 +102,7 @@ gst_libcamera_stream_role_get_type() "libcamera::Viewfinder", "view-finder", }, - { 0, NULL, NULL } + { 0, nullptr, nullptr } }; if (!type) diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp index eec8163e88e7..16b1d08b3053 100644 --- a/src/gstreamer/gstlibcamerasrc.cpp +++ b/src/gstreamer/gstlibcamerasrc.cpp @@ -367,10 +367,10 @@ int GstLibcameraSrcState::processRequest() if (video_pool) { /* Only set video pool when a copy is needed. */ - GstBuffer *copy = NULL; + GstBuffer *copy = nullptr; const GstVideoInfo info = gst_libcamera_pad_get_video_info(srcpad); - ret = gst_buffer_pool_acquire_buffer(video_pool, ©, NULL); + ret = gst_buffer_pool_acquire_buffer(video_pool, ©, nullptr); if (ret != GST_FLOW_OK) { gst_buffer_unref(buffer); GST_ELEMENT_ERROR(src_, RESOURCE, SETTINGS, @@ -541,8 +541,8 @@ static std::tuple gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad, GstCaps *caps, const GstVideoInfo *info) { - g_autoptr(GstQuery) query = NULL; - g_autoptr(GstBufferPool) pool = NULL; + g_autoptr(GstQuery) query = nullptr; + g_autoptr(GstBufferPool) pool = nullptr; const gboolean need_pool = true; /* @@ -554,8 +554,8 @@ gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad, if (!gst_pad_peer_query(srcpad, query)) GST_DEBUG_OBJECT(self, "Didn't get downstream ALLOCATION hints"); - else if (gst_query_find_allocation_meta(query, GST_VIDEO_META_API_TYPE, NULL)) - return { NULL, 0 }; + else if (gst_query_find_allocation_meta(query, GST_VIDEO_META_API_TYPE, nullptr)) + return { nullptr, 0 }; GST_WARNING_OBJECT(self, "Downstream doesn't support video meta, need to copy frame."); @@ -564,7 +564,8 @@ gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad, * create a new pool. */ if (gst_query_get_n_allocation_pools(query) > 0) - gst_query_parse_nth_allocation_pool(query, 0, &pool, NULL, NULL, NULL); + gst_query_parse_nth_allocation_pool(query, 0, &pool, nullptr, + nullptr, nullptr); if (!pool) { GstStructure *config; @@ -583,7 +584,7 @@ gst_libcamera_create_video_pool(GstLibcameraSrc *self, GstPad *srcpad, GST_ELEMENT_ERROR(self, RESOURCE, SETTINGS, ("Failed to active buffer pool"), ("gst_libcamera_src_negotiate() failed.")); - return { NULL, -EINVAL }; + return { nullptr, -EINVAL }; } return { reinterpret_cast(g_steal_pointer(&pool)), 0 }; @@ -660,7 +661,7 @@ gst_libcamera_src_negotiate(GstLibcameraSrc *self) for (gsize i = 0; i < state->srcpads_.size(); i++) { GstPad *srcpad = state->srcpads_[i]; const StreamConfiguration &stream_cfg = state->config_->at(i); - GstBufferPool *video_pool = NULL; + GstBufferPool *video_pool = nullptr; GstVideoInfo info; g_autoptr(GstCaps) caps = gst_libcamera_stream_configuration_to_caps(stream_cfg, transfer[i]); @@ -1065,7 +1066,7 @@ gst_libcamera_src_request_new_pad(GstElement *element, GstPadTemplate *templ, const gchar *name, [[maybe_unused]] const GstCaps *caps) { GstLibcameraSrc *self = GST_LIBCAMERA_SRC(element); - g_autoptr(GstPad) pad = NULL; + g_autoptr(GstPad) pad = nullptr; GST_DEBUG_OBJECT(self, "new request pad created"); @@ -1079,7 +1080,7 @@ gst_libcamera_src_request_new_pad(GstElement *element, GstPadTemplate *templ, GST_ELEMENT_ERROR(element, STREAM, FAILED, ("Internal data stream error."), ("Could not add pad to element")); - return NULL; + return nullptr; } gst_child_proxy_child_added(GST_CHILD_PROXY(self), G_OBJECT(pad), GST_OBJECT_NAME(pad));