From patchwork Wed Sep 15 15:09:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vedant Paranjape X-Patchwork-Id: 13856 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 48439BDC71 for ; Wed, 15 Sep 2021 15:09:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 82AE360248; Wed, 15 Sep 2021 17:09:30 +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="bsp7Vimr"; dkim-atps=neutral Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E2B0560131 for ; Wed, 15 Sep 2021 17:09:28 +0200 (CEST) Received: by mail-pj1-x102b.google.com with SMTP id nn5-20020a17090b38c500b0019af1c4b31fso2436196pjb.3 for ; Wed, 15 Sep 2021 08:09:28 -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=T2qpSI1hlPWaYj+u2t173bDLVJ7aOw6f9jaTZhe3Ss4=; b=bsp7VimrYhIeGKzSZiXHLeFwVYQYWKojzZDroSu8abYR96Mb96rh2b70lcFFJCCYZD ZEYjmcNjm1BXxt12VMmmSqwCca6P4LhFCSPo5l0/2GjcGD1DNHgrKGwJz9uHda7KVuws sWkZIAjJdz0grQ4VSEnevUps/WuL2ezFAJUiwiQQeX0MIhIi2vEfaN8Hc3mIgav94xR8 gQmcaUjxyg6u1vioCxXURKaGupk8xsDj5Xdl5T/pIei2r3Q5lzFSTtLPJkORTn9oFlBS dYzSF1Uz90zguTl7hoMUEZ7MRcm1xoxLL/2xYUlqxewpCRutl1372Lwx9Ut3dq6m8A90 tkOw== 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=T2qpSI1hlPWaYj+u2t173bDLVJ7aOw6f9jaTZhe3Ss4=; b=21fm8n62FLcM59X7dD+MhOSrTcBh4UE7045nBzeE8yhxLWpEW+IMbn0tbKaPy7Dxo+ PHfQSYFwsasfYyMwUm6cn8xKXj0YET6sNv9YhNr4F3DOfpnX1z3VOr0tZnz4KY2Kyr9+ ni2pjzWf9LUw+tb/+wotfxGUvzmTgmtAUE1gD4UgrFpZVxWCNbpPyrUC8CnPhssg0snk 5hODEvxLmjU1xQ6apSWKQS5LEWMSimqCO8H697W5zLjeOAqdOftLlL5nlzdjI//fXQv2 UVmAmjZuR35w8E9ZjCD4strlcs4Ny0y16G+HSpEcbRDGnstqwdolfPKoKL9odK8N1C/P GGPQ== X-Gm-Message-State: AOAM530iff4c441lQnP9yxj3S1UQ5RGimj4CiTrMj4ZFCj0R1BmpH1GT nE00XUEI44KZqE+FeE3FEdwQFHp6Wx4vrQ== X-Google-Smtp-Source: ABdhPJyfL26aRpf5kvRN22Es2F0SBY3gUk6WHhXgdBREoRYrs9CrtYqCLdyScswEnTXgm3qMrjYE2g== X-Received: by 2002:a17:90b:17c1:: with SMTP id me1mr9306466pjb.28.1631718566985; Wed, 15 Sep 2021 08:09:26 -0700 (PDT) Received: from localhost.localdomain ([1.186.165.222]) by smtp.googlemail.com with ESMTPSA id t10sm318099pge.10.2021.09.15.08.09.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Sep 2021 08:09:26 -0700 (PDT) From: Vedant Paranjape To: libcamera-devel@lists.libcamera.org Date: Wed, 15 Sep 2021 20:39:07 +0530 Message-Id: <20210915150907.736222-1-vedantparanjape160201@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1] 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: 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]. It also fixed memory leak reported by Umang Jain, described in his fix [2]. [1] https://gstreamer.freedesktop.org/documentation/gstreamer/gstutils.html?gi-language=c#gst_parse_bin_from_description_full [2] https://patchwork.libcamera.org/patch/13845/ Signed-off-by: Vedant Paranjape Reviewed-by: Nicolas Dufresne --- .../gstreamer_single_stream_test.cpp | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/test/gstreamer/gstreamer_single_stream_test.cpp b/test/gstreamer/gstreamer_single_stream_test.cpp index 7292f3280617..a20d79109885 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; } @@ -72,9 +67,13 @@ protected: return TestPass; } + void cleanup() override + { + g_clear_object(&stream0_); + } + private: - GstElement *convert0_; - GstElement *sink0_; + GstElement *stream0_; }; TEST_REGISTER(GstreamerSingleStreamTest)