mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-13 07:19:45 +03:00
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 <vedantparanjape160201@gmail.com> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
86 lines
1.8 KiB
C++
86 lines
1.8 KiB
C++
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* Copyright (C) 2021, Vedant Paranjape
|
|
*
|
|
* gstreamer_single_stream_test.cpp - GStreamer single stream capture test
|
|
*/
|
|
|
|
#include <iostream>
|
|
#include <unistd.h>
|
|
|
|
#include <libcamera/base/utils.h>
|
|
|
|
#include "libcamera/internal/source_paths.h"
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include "gstreamer_test.h"
|
|
#include "test.h"
|
|
|
|
using namespace std;
|
|
|
|
class GstreamerSingleStreamTest : public GstreamerTest, public Test
|
|
{
|
|
public:
|
|
GstreamerSingleStreamTest()
|
|
: GstreamerTest()
|
|
{
|
|
}
|
|
|
|
protected:
|
|
int init() override
|
|
{
|
|
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);
|
|
|
|
return TestFail;
|
|
}
|
|
|
|
convert0_ = reinterpret_cast<GstElement *>(g_steal_pointer(&convert0));
|
|
sink0_ = reinterpret_cast<GstElement *>(g_steal_pointer(&sink0));
|
|
|
|
if (createPipeline() != TestPass)
|
|
return TestFail;
|
|
|
|
return TestPass;
|
|
}
|
|
|
|
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) {
|
|
g_printerr("Elements could not be linked.\n");
|
|
return TestFail;
|
|
}
|
|
|
|
if (startPipeline() != TestPass)
|
|
return TestFail;
|
|
|
|
if (processEvent() != TestPass)
|
|
return TestFail;
|
|
|
|
return TestPass;
|
|
}
|
|
|
|
void cleanup() override
|
|
{
|
|
g_clear_object(&convert0_);
|
|
g_clear_object(&sink0_);
|
|
}
|
|
|
|
private:
|
|
GstElement *convert0_;
|
|
GstElement *sink0_;
|
|
};
|
|
|
|
TEST_REGISTER(GstreamerSingleStreamTest)
|