libcamera/test/gstreamer/gstreamer_single_stream_test.cpp
Laurent Pinchart 17d8b89deb test: gstreamer: Remove videoconvert element from pipeline
The GStreamer single stream test uses the following pipeline:

	libcamerasrc ! videoconvert ! fakesink

The videoconvert element isn't useful as the data is thrown away by the
fakesink anyway. We can shorten the pipeline to

	libcamerasrc ! fakesink

to save CPU time and to avoid depending on the gstreamer1.0-plugins-base
package to run the unit tests.

The test could be further simplified by replacing
gst_parse_bin_from_description_full() with gst_element_factory_make(),
now that we only add one element to the bin. The extra cost incurred by
the bin only impacts initialization time, and using a bin will make it
easier to add other elements in the future if needed. Keep the bin, and
only drop the videoconvert element.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-12-07 18:59:42 +02:00

78 lines
1.5 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 <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_;
const gchar *streamDescription = "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("Bin could not be created (%s)\n", error0->message);
return TestFail;
}
g_object_ref_sink(stream0_);
if (createPipeline() != TestPass)
return TestFail;
return TestPass;
}
int run() override
{
/* Build the pipeline */
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;
}
if (startPipeline() != TestPass)
return TestFail;
if (processEvent() != TestPass)
return TestFail;
return TestPass;
}
void cleanup() override
{
g_clear_object(&stream0_);
}
private:
GstElement *stream0_;
};
TEST_REGISTER(GstreamerSingleStreamTest)