diff options
authorVedant Paranjape <>2021-09-21 23:09:55 +0530
committerPaul Elder <>2021-09-23 16:03:15 +0900
commitc7daf645d449fc74415770b9d811ec21571e7823 (patch)
parentfa9a9d7f6b6452bf8d0fdd5de03512547b84204a (diff)
test: gstreamer: Simplify elements' ownerships
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] Signed-off-by: Vedant Paranjape <> Signed-off-by: Umang Jain <> Reviewed-by: Nicolas Dufresne <> Reviewed-by: Paul Elder <> Signed-off-by: Paul Elder <>
1 files changed, 4 insertions, 5 deletions
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<GstElement *>(g_steal_pointer(&libcameraSrc));
+ g_object_ref_sink(libcameraSrc_);
return TestPass;