summaryrefslogtreecommitdiff
path: root/test/gstreamer/gstreamer_multi_stream_test.cpp
diff options
context:
space:
mode:
authorVedant Paranjape <vedantparanjape160201@gmail.com>2021-09-24 14:08:21 +0530
committerPaul Elder <paul.elder@ideasonboard.com>2021-09-24 18:01:15 +0900
commitd1713de60ab5c37c5b2de63fd75cb5b5e59248c5 (patch)
treec48de8376a5734c2bffbcd27c8a24c58da0a9bec /test/gstreamer/gstreamer_multi_stream_test.cpp
parent2cc4303b172a76ac5b431c4fb4df8a083f7d3fcf (diff)
test: gstreamer: Add a test for gstreamer multi stream
This patch adds a test to test if multi stream using libcamera's gstreamer element works. Test will run only on devices that support multistream capture, eg., devices that use IPU3 and raspberrypi pipeline. This was tested on a Raspberry Pi 4B+. Signed-off-by: Vedant Paranjape <vedantparanjape160201@gmail.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>
Diffstat (limited to 'test/gstreamer/gstreamer_multi_stream_test.cpp')
-rw-r--r--test/gstreamer/gstreamer_multi_stream_test.cpp124
1 files changed, 124 insertions, 0 deletions
diff --git a/test/gstreamer/gstreamer_multi_stream_test.cpp b/test/gstreamer/gstreamer_multi_stream_test.cpp
new file mode 100644
index 00000000..d3d7a9d3
--- /dev/null
+++ b/test/gstreamer/gstreamer_multi_stream_test.cpp
@@ -0,0 +1,124 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2021, Vedant Paranjape
+ *
+ * gstreamer_multi_stream_test.cpp - GStreamer multi stream capture test
+ */
+
+#include <iostream>
+#include <unistd.h>
+
+#include <libcamera/libcamera.h>
+
+#include <gst/gst.h>
+
+#include "gstreamer_test.h"
+#include "test.h"
+
+using namespace std;
+
+class GstreamerMultiStreamTest : public GstreamerTest, public Test
+{
+public:
+ GstreamerMultiStreamTest()
+ : GstreamerTest()
+ {
+ }
+
+protected:
+ int init() override
+ {
+ if (status_ != TestPass)
+ return status_;
+
+ /* Check if platform supports multistream capture */
+ libcamera::CameraManager cm;
+ cm.start();
+ bool cameraFound = false;
+ for (auto &camera : cm.cameras()) {
+ if (camera->streams().size() > 1) {
+ cameraName_ = camera->id();
+ cameraFound = true;
+ cm.stop();
+ break;
+ }
+ }
+
+ if (!cameraFound) {
+ cm.stop();
+ return TestSkip;
+ }
+
+ const gchar *streamDescription = "queue ! fakesink";
+ g_autoptr(GError) error = NULL;
+
+ stream0_ = gst_parse_bin_from_description_full(streamDescription, TRUE,
+ NULL,
+ GST_PARSE_FLAG_FATAL_ERRORS,
+ &error);
+ if (!stream0_) {
+ g_printerr("Stream0 could not be created (%s)\n", error->message);
+ return TestFail;
+ }
+ g_object_ref_sink(stream0_);
+
+ stream1_ = gst_parse_bin_from_description_full(streamDescription, TRUE,
+ NULL,
+ GST_PARSE_FLAG_FATAL_ERRORS,
+ &error);
+ if (!stream1_) {
+ g_printerr("Stream1 could not be created (%s)\n", error->message);
+ return TestFail;
+ }
+ g_object_ref_sink(stream1_);
+
+ if (createPipeline() != TestPass)
+ return TestFail;
+
+ return TestPass;
+ }
+
+ int run() override
+ {
+ g_object_set(libcameraSrc_, "camera-name", cameraName_.c_str(), NULL);
+
+ /* Build the pipeline */
+ gst_bin_add_many(GST_BIN(pipeline_), libcameraSrc_,
+ stream0_, stream1_, NULL);
+
+ g_autoptr(GstPad) src_pad = gst_element_get_static_pad(libcameraSrc_, "src");
+ g_autoptr(GstPad) request_pad = gst_element_get_request_pad(libcameraSrc_, "src_%u");
+
+ {
+ g_autoptr(GstPad) queue0_sink_pad = gst_element_get_static_pad(stream0_, "sink");
+ g_autoptr(GstPad) queue1_sink_pad = gst_element_get_static_pad(stream1_, "sink");
+
+ if (gst_pad_link(src_pad, queue0_sink_pad) != GST_PAD_LINK_OK ||
+ gst_pad_link(request_pad, queue1_sink_pad) != GST_PAD_LINK_OK) {
+ g_printerr("Pads 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_);
+ g_clear_object(&stream1_);
+ }
+
+private:
+ std::string cameraName_;
+ GstElement *stream0_;
+ GstElement *stream1_;
+};
+
+TEST_REGISTER(GstreamerMultiStreamTest)