From patchwork Tue Sep 21 11:56:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 13875 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 62D81BDC71 for ; Tue, 21 Sep 2021 11:56:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BA02C6918A; Tue, 21 Sep 2021 13:56:28 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Eo9wtLPT"; dkim-atps=neutral Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 03CF860247 for ; Tue, 21 Sep 2021 13:56:27 +0200 (CEST) Received: by mail-pg1-x52e.google.com with SMTP id g184so20453940pgc.6 for ; Tue, 21 Sep 2021 04:56:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=AjTUusiayGb8XNBYuRtkKRQ3PtUl1WcJg3+jWBjSajQ=; b=Eo9wtLPTwScp/79+GQkakjzWElUPvNdfo/DZra2jhXWwyEaUNthNJ1jfIHQ6ADY8GR sBeIQ0QCMbFxzCc13IRcTbydk85uJXFi66KMER2mtnMOmHquXYcY7CKrUu9oq76TkAyT YdpGrN8FMsjKwfGvBlpsQjOwkdg1Qh93suc6EVXB7DnqB6cB/WU2bpKUyRBlq8Tz8dws G4b8QoJMbK34bwC37I6QBVGjo33+LJkBpdb9NC3zaskCUKEXhCWiCSZWpIVggOPbHjgD BV81M/pMENtRSAgLftjjntOJnh53B4kfRq0IzornmcLGktZmU7coBXADvAgvZWvUpiRl WMmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=AjTUusiayGb8XNBYuRtkKRQ3PtUl1WcJg3+jWBjSajQ=; b=wOeQmKs2iQEd+YCVoqSpJCNIhMicKCaGjEkFlCiePwO/54tDjK4IMyWFKP/euh7u61 YNUjy78JS00aB0w4N73620QNyzaN5pLACNkGTSW/zehTh3hCWI3taEMpjYYjiKxIoSnE sQMpU8Wfp0VN1hcLE5r/azO4VunRK/Jv56GEi65ekJYcv/CBRwMW4PnhpEUNCO+CUUdD sD0tGpkwP5LmZxbhjijGQXx7ovlazM9EmSbowNd+t+UPe44d23sTGPVHLfGiPekyRMaq Vz7hJCjupK3Pnui7mjULU6IU1ub9rVN2mNeZsuXkKOa+p45hY+OeJskVWdUPnlIY4nMJ oyxg== X-Gm-Message-State: AOAM531C47sHufRVi925adSFU+hJKluRvJgsg5by0kDpBuKA6jk55hN9 am7C5uYsNLNSsVUxhiVWUTdpLntEloRTTw== X-Google-Smtp-Source: ABdhPJwpMgy++9+ThNBA2BrV576aH8VroXj17N9ZKDmC/D4sDBdLemQFNTFGoZn1sZXULQR1NAb0gQ== X-Received: by 2002:a63:788d:: with SMTP id t135mr27507177pgc.116.1632225385057; Tue, 21 Sep 2021 04:56:25 -0700 (PDT) Received: from localhost.localdomain ([1.186.167.167]) by smtp.googlemail.com with ESMTPSA id y5sm16654906pfb.207.2021.09.21.04.56.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 04:56:24 -0700 (PDT) From: Vedant Paranjape To: libcamera-devel@lists.libcamera.org Date: Tue, 21 Sep 2021 17:26:08 +0530 Message-Id: <20210921115610.366553-1-vedantparanjape160201@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 1/3] test: gstreamer_single_stream_test: Fix memory leak 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: , Cc: Nicolas Dufresne , Vedant Paranjape Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The test hold a valid reference to convert0_ and sink0_ but not released. This results in a memory leak and can be checked via valgrind. Drop the references with test cleanup() virtual function. Valgrind log (glib and gst suppression files were used): ==345380== LEAK SUMMARY: ==345380== definitely lost: 1,688 bytes in 2 blocks ==345380== indirectly lost: 7,069 bytes in 42 blocks The patch fixes the leaks reported by valgrind above to: ==348870== LEAK SUMMARY: ==348870== definitely lost: 0 bytes in 0 blocks ==348870== indirectly lost: 0 bytes in 0 blocks Signed-off-by: Vedant Paranjape Signed-off-by: Umang Jain Reviewed-by: Nicolas Dufresne --- test/gstreamer/gstreamer_single_stream_test.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/gstreamer/gstreamer_single_stream_test.cpp b/test/gstreamer/gstreamer_single_stream_test.cpp index 7292f3280617..2b561d6bf9f2 100644 --- a/test/gstreamer/gstreamer_single_stream_test.cpp +++ b/test/gstreamer/gstreamer_single_stream_test.cpp @@ -72,6 +72,12 @@ protected: return TestPass; } + void cleanup() override + { + g_clear_object(&convert0_); + g_clear_object(&sink0_); + } + private: GstElement *convert0_; GstElement *sink0_; From patchwork Tue Sep 21 11:56:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 13876 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 637FFBDC71 for ; Tue, 21 Sep 2021 11:56:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 256E36918A; Tue, 21 Sep 2021 13:56:32 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Ve6gaG/k"; dkim-atps=neutral Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 59CFC60247 for ; Tue, 21 Sep 2021 13:56:30 +0200 (CEST) Received: by mail-pf1-x436.google.com with SMTP id s16so10967742pfk.0 for ; Tue, 21 Sep 2021 04:56:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Vx16wBbKP5BTxQUAX9O9bcOJnM+jEFATAluVPu/+z2I=; b=Ve6gaG/kfExq1L1ijIUauIy2XxJipOuCMpOzbJm40pwwnjKJMS2z4/Y8Q9Bh/z9Y8M wLanFbREd+pMrHm8zfvzWRnVb4SHR5HwRBDwy/zA4RAP445aJX+/8YdHRTw/zWP3aVIN gWgp7Xcrucbn9i0oe4T+8ns1H8WfNEZYpIol4+/F2eT3Y6W3BOkW3XJV2kQfLf8RE70o tzY39l4KQRCJHbucIquVkBNteqAkArfsJHdwC9W8KtZuah6ejDtTWPNRHBH+sLjuTcHR rjxUBC9toJgaiEkAmZgVcaRQPx5JQgrAXm4+B/YOdwEIUXmWyfunUlMbGyybWE1qhFPX 40GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Vx16wBbKP5BTxQUAX9O9bcOJnM+jEFATAluVPu/+z2I=; b=GYts/tAVsN1AzICL9/yNDwSdgBnAvtit/+SvC9dwMjdBy76MPKFvc+KJPh89NmuyX8 51ZJiMCBIUp3loayrKqoWE+lyhoRPN5BilMYyYuaJ+pRCtBSt261hHSLWCaD9wEPYLMq m3mfGXelXVDXkTnBbw0WAIoqXo6WGuIloV9nH8CJNbIs55wvdg+dMeYpbx0nOr5PjY1M WMklHpeIvjsxhE0PNwgssM1numQzn8JBo54q2HnIDkkO99blngTR7AOSRidvk0Oko6L2 xjdmvbyeGc5harcMf/imW19NLFGNqHgH5Bi2HbUboLrUnj3XKz3lgC+GhK/VJItZUqGR FEAQ== X-Gm-Message-State: AOAM532LcMB4ikDV8j5muixqYQIPTljVGyHCbfHv3pIghXvjj9+DJFrV LhXOJugNvoGoqhzNG5b8vhODyreARbIYow== X-Google-Smtp-Source: ABdhPJxq5bNHHV3K4bdQVtqyaZMQaYc7LEeG0x2z8Qm/FTzwqy3Vzv8FShQan/kjDcobIrHVN0Nueg== X-Received: by 2002:a63:9911:: with SMTP id d17mr28145328pge.111.1632225388448; Tue, 21 Sep 2021 04:56:28 -0700 (PDT) Received: from localhost.localdomain ([1.186.167.167]) by smtp.googlemail.com with ESMTPSA id y5sm16654906pfb.207.2021.09.21.04.56.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 04:56:28 -0700 (PDT) From: Vedant Paranjape To: libcamera-devel@lists.libcamera.org Date: Tue, 21 Sep 2021 17:26:09 +0530 Message-Id: <20210921115610.366553-2-vedantparanjape160201@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210921115610.366553-1-vedantparanjape160201@gmail.com> References: <20210921115610.366553-1-vedantparanjape160201@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 2/3] test: gstreamer: Simplify single stream test using functions from GstUtils 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: , Cc: Nicolas Dufresne , Vedant Paranjape Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Simplify memory handling and complexity of the test by using gst_parse_bin_from_description_full [1]. [1]: https://gstreamer.freedesktop.org/documentation/gstreamer/gstutils.html?gi-language=c#gst_parse_bin_from_description_full Signed-off-by: Vedant Paranjape Reviewed-by: Nicolas Dufresne --- .../gstreamer_single_stream_test.cpp | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/test/gstreamer/gstreamer_single_stream_test.cpp b/test/gstreamer/gstreamer_single_stream_test.cpp index 2b561d6bf9f2..5fa52bf710be 100644 --- a/test/gstreamer/gstreamer_single_stream_test.cpp +++ b/test/gstreamer/gstreamer_single_stream_test.cpp @@ -33,20 +33,15 @@ 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); - - if (!convert0 || !sink0) { - g_printerr("Not all elements could be created. %p.%p\n", - convert0, sink0); + const gchar *streamDescription = "queue ! videoconvert ! fakesink"; + g_autoptr(GError) error0 = NULL; + stream0_ = gst_parse_bin_from_description_full(streamDescription, TRUE, NULL, GST_PARSE_FLAG_FATAL_ERRORS, &error0); + if (!stream0_) { + g_printerr("Not all bins could be created. %p\n", stream0_); return TestFail; } - - convert0_ = reinterpret_cast(g_steal_pointer(&convert0)); - sink0_ = reinterpret_cast(g_steal_pointer(&sink0)); + g_object_ref_sink(stream0_); if (createPipeline() != TestPass) return TestFail; @@ -57,8 +52,8 @@ protected: int run() override { /* Build the pipeline */ - gst_bin_add_many(GST_BIN(pipeline_), libcameraSrc_, convert0_, sink0_, NULL); - if (gst_element_link_many(libcameraSrc_, convert0_, sink0_, NULL) != TRUE) { + gst_bin_add_many(GST_BIN(pipeline_), libcameraSrc_, stream0_, NULL); + if (gst_element_link(libcameraSrc_, stream0_) != TRUE) { g_printerr("Elements could not be linked.\n"); return TestFail; } @@ -74,13 +69,11 @@ protected: void cleanup() override { - g_clear_object(&convert0_); - g_clear_object(&sink0_); + g_clear_object(&stream0_); } private: - GstElement *convert0_; - GstElement *sink0_; + GstElement *stream0_; }; TEST_REGISTER(GstreamerSingleStreamTest) From patchwork Tue Sep 21 11:56:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 13877 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 59AE0BDC71 for ; Tue, 21 Sep 2021 11:56:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 28C356918A; Tue, 21 Sep 2021 13:56:35 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Gxh3cDRz"; dkim-atps=neutral Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9348460247 for ; Tue, 21 Sep 2021 13:56:33 +0200 (CEST) Received: by mail-pf1-x430.google.com with SMTP id j6so19242338pfa.4 for ; Tue, 21 Sep 2021 04:56:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+Ae9N/Ehz4QT7RYpuRU7NvHlnRTxJlESW1W2mEkgbGg=; b=Gxh3cDRzTS6c+x+/pZrfGJQq47uxBfZJG8s++5YJEa8itNHUknO4Z9srQj626IxR2W FdBvutdW7gZn1kKk/q6jGeqgNddREnVQQcYqZOsyz5/Y139Tw5Waya4uRdf8w2ejOQHt blxqCzI86L5h3EuSrwq2UmLFIdAcL/cZuiTUAB6K2ENm5bWPKcWEYNwcVUm7fqOxcRqQ kcI5HyfxGOf1kpBYlDNhRG4PWKyQ4zUBPNlTr0bna135bYvM7UHMLHdkJW3ttEEOQ0iS A7KAPoSStogs0FGzjjEaXMwVjHwmkXQUVolAb8PCugXIsZ8qUWwP6s/xinyWMac5yo0D 4K6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+Ae9N/Ehz4QT7RYpuRU7NvHlnRTxJlESW1W2mEkgbGg=; b=fTRS1pkFqy7+GEcovU8jT59rV5hBq72Xrs+wdTIqL65O6Jw6r0mj17n9f6i+P4ZpnD NCZE08AbyNs9gXsoYbfiTR+pon3vehJdVDCz1YKNuWbdFnPS12Rm6+ta7uMKRo0ST1jV VPvcv38b2sQj2ctBYO6sHHjkXU+OYTJwx1V36ViFVuJTHr8XRkeqH6DCRH54h4P5/hiL 1yBg+aJudfzCF6QisF1jDdD8GtTxtzZXOYq43GKzpBJ39xWnlXI1wBN/vfSEFG5u43Qf mXxhZxY8OBP9wFW1GynihumrxDrW6e8OhxZSOHRRsh3VemxsMlFPLNP/g8aPcTqcanlT 8o4Q== X-Gm-Message-State: AOAM531P3tO1JUMyqfU3cEFolWWo1OXLgBsf36Ll/8jnPc3u1pLkjMrN WDRWJNtcmHcF5dUjqsSiS29GtauB5Jyzcg== X-Google-Smtp-Source: ABdhPJxHVGiB0qgrnF8TtBI1i2ZMksgn3oyxRWQsmvWe552OULUE3tTmixQexKp/vrT+fxuflARMrQ== X-Received: by 2002:a63:9dc7:: with SMTP id i190mr6845698pgd.261.1632225391710; Tue, 21 Sep 2021 04:56:31 -0700 (PDT) Received: from localhost.localdomain ([1.186.167.167]) by smtp.googlemail.com with ESMTPSA id y5sm16654906pfb.207.2021.09.21.04.56.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Sep 2021 04:56:31 -0700 (PDT) From: Vedant Paranjape To: libcamera-devel@lists.libcamera.org Date: Tue, 21 Sep 2021 17:26:10 +0530 Message-Id: <20210921115610.366553-3-vedantparanjape160201@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210921115610.366553-1-vedantparanjape160201@gmail.com> References: <20210921115610.366553-1-vedantparanjape160201@gmail.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 3/3] 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: , Cc: Nicolas Dufresne , Vedant Paranjape 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 test base class (gstreamer_test.cpp) 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: Vedant Paranjape Signed-off-by: Umang Jain Reviewed-by: Nicolas Dufresne --- test/gstreamer/gstreamer_test.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/gstreamer/gstreamer_test.cpp b/test/gstreamer/gstreamer_test.cpp index 4171250584e6..227a5c37fbe1 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; }