[libcamera-devel,v1,2/3] test: gstreamer: Simplify single stream test using functions from GstUtils
diff mbox series

Message ID 20210921115610.366553-2-vedantparanjape160201@gmail.com
State Accepted
Headers show
Series
  • [libcamera-devel,v1,1/3] test: gstreamer_single_stream_test: Fix memory leak
Related show

Commit Message

Vedant Paranjape Sept. 21, 2021, 11:56 a.m. UTC
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 <vedantparanjape160201@gmail.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
---
 .../gstreamer_single_stream_test.cpp          | 27 +++++++------------
 1 file changed, 10 insertions(+), 17 deletions(-)

Patch
diff mbox series

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<GstElement *>(g_steal_pointer(&convert0));
-		sink0_ = reinterpret_cast<GstElement *>(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)