From patchwork Tue Sep 14 12:16:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 13845 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 4E337BDB1D for ; Tue, 14 Sep 2021 12:17:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E16366918C; Tue, 14 Sep 2021 14:17:18 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="JYJw2/ID"; 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 01FDF60248 for ; Tue, 14 Sep 2021 14:17:17 +0200 (CEST) Received: from perceval.ideasonboard.com (unknown [103.251.226.94]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0667C2A5; Tue, 14 Sep 2021 14:17:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1631621836; bh=i4/i/y8SjMu8QvP4lRXhBnH7iaL03Fvjt7U33rtEXgE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JYJw2/IDODwabrU3UudfKIP3STmi8PtZs0huj12+jnLNbAAjn/68T6VldJZ1wKSR8 /w7B9p7CDUAlAIgNTukVHWNHRJAnqy0r+9zwQaBg6wXqW9/KAGQWxXYgzNmkCFYrd3 MpQsKFQr8hiWBRse+faMPYHY0u/KP9NnItSL9OI0= From: Umang Jain To: libcamera-devel@lists.libcamera.org Date: Tue, 14 Sep 2021 17:46:59 +0530 Message-Id: <20210914121700.122591-2-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210914121700.122591-1-umang.jain@ideasonboard.com> References: <20210914121700.122591-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/2] test: gstreamer: Simplify elements' ownerships 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" In gstreamer, when elements are created, usually a floating [1] reference is returned which simply means, there is no ownership transfer (yet). Once can simply check for NULL and return through an error path, without bothering to clean up. Hence, g_autoptr is not much of help here. If the NULL checks have been passed successfully, elements are ready to use. However, we must claim ownership/reference it before using them via g_object_ref_sink(). This patch build upon this principle and removes the g_autoptr from gstreamer tests whereever necessary to tide up the code. [1] https://gstreamer.freedesktop.org/documentation/additional/design/MT-refcounting.html?gi-language=c#refcounting1 Signed-off-by: Umang Jain Reviewed-by: Nicolas Dufresne --- test/gstreamer/gstreamer_single_stream_test.cpp | 14 ++++++-------- test/gstreamer/gstreamer_test.cpp | 9 ++++----- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/test/gstreamer/gstreamer_single_stream_test.cpp b/test/gstreamer/gstreamer_single_stream_test.cpp index 7292f328..d992455c 100644 --- a/test/gstreamer/gstreamer_single_stream_test.cpp +++ b/test/gstreamer/gstreamer_single_stream_test.cpp @@ -33,20 +33,18 @@ protected: if (status_ != TestPass) return status_; - g_autoptr(GstElement) convert0 = gst_element_factory_make("videoconvert", "convert0"); - g_autoptr(GstElement) sink0 = gst_element_factory_make("fakesink", "sink0"); - g_object_ref_sink(convert0); - g_object_ref_sink(sink0); + convert0_ = gst_element_factory_make("videoconvert", "convert0"); + sink0_ = gst_element_factory_make("fakesink", "sink0"); - if (!convert0 || !sink0) { + if (!convert0_ || !sink0_) { g_printerr("Not all elements could be created. %p.%p\n", - convert0, sink0); + convert0_, sink0_); return TestFail; } - convert0_ = reinterpret_cast(g_steal_pointer(&convert0)); - sink0_ = reinterpret_cast(g_steal_pointer(&sink0)); + g_object_ref_sink(convert0_); + g_object_ref_sink(sink0_); if (createPipeline() != TestPass) return TestFail; diff --git a/test/gstreamer/gstreamer_test.cpp b/test/gstreamer/gstreamer_test.cpp index 41712505..227a5c37 100644 --- a/test/gstreamer/gstreamer_test.cpp +++ b/test/gstreamer/gstreamer_test.cpp @@ -78,18 +78,17 @@ GstreamerTest::~GstreamerTest() int GstreamerTest::createPipeline() { - g_autoptr(GstElement) libcameraSrc = gst_element_factory_make("libcamerasrc", "libcamera"); + libcameraSrc_ = gst_element_factory_make("libcamerasrc", "libcamera"); pipeline_ = gst_pipeline_new("test-pipeline"); - g_object_ref_sink(libcameraSrc); - if (!libcameraSrc || !pipeline_) { + if (!libcameraSrc_ || !pipeline_) { g_printerr("Unable to create create pipeline %p.%p\n", - libcameraSrc, pipeline_); + libcameraSrc_, pipeline_); return TestFail; } - libcameraSrc_ = reinterpret_cast(g_steal_pointer(&libcameraSrc)); + g_object_ref_sink(libcameraSrc_); return TestPass; }