diff options
Diffstat (limited to 'test/gstreamer')
-rw-r--r-- | test/gstreamer/gstreamer_device_provider_test.cpp | 77 | ||||
-rw-r--r-- | test/gstreamer/gstreamer_multi_stream_test.cpp | 25 | ||||
-rw-r--r-- | test/gstreamer/gstreamer_single_stream_test.cpp | 29 | ||||
-rw-r--r-- | test/gstreamer/gstreamer_test.cpp | 65 | ||||
-rw-r--r-- | test/gstreamer/gstreamer_test.h | 12 | ||||
-rw-r--r-- | test/gstreamer/meson.build | 13 |
6 files changed, 143 insertions, 78 deletions
diff --git a/test/gstreamer/gstreamer_device_provider_test.cpp b/test/gstreamer/gstreamer_device_provider_test.cpp new file mode 100644 index 00000000..8b8e7cba --- /dev/null +++ b/test/gstreamer/gstreamer_device_provider_test.cpp @@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2023, Umang Jain <umang.jain@ideasonboard.com> + * + * GStreamer single stream capture test + */ + +#include <vector> + +#include <libcamera/libcamera.h> +#include <gst/gst.h> + +#include "gstreamer_test.h" +#include "test.h" + +using namespace std; + +class GstreamerDeviceProviderTest : public GstreamerTest, public Test +{ +public: + GstreamerDeviceProviderTest() + : GstreamerTest() + { + } + +protected: + int init() override + { + if (status_ != TestPass) + return status_; + + return TestPass; + } + + int run() override + { + g_autoptr(GstDeviceProvider) provider = NULL; + GList *devices, *l; + std::vector<std::string> cameraNames; + std::unique_ptr<libcamera::CameraManager> cm; + + cm = std::make_unique<libcamera::CameraManager>(); + cm->start(); + for (auto &camera : cm->cameras()) + cameraNames.push_back(camera->id()); + cm->stop(); + cm.reset(); + + provider = gst_device_provider_factory_get_by_name("libcameraprovider"); + devices = gst_device_provider_get_devices(provider); + + for (l = devices; l != NULL; l = g_list_next(l)) { + GstDevice *device = GST_DEVICE(l->data); + g_autofree gchar *gst_name; + bool matched = false; + + g_autoptr(GstElement) element = gst_device_create_element(device, NULL); + g_object_get(element, "camera-name", &gst_name, NULL); + + for (auto name : cameraNames) { + if (strcmp(name.c_str(), gst_name) == 0) { + matched = true; + break; + } + } + + if (!matched) + return TestFail; + } + + g_list_free_full(devices, (GDestroyNotify)gst_object_unref); + + return TestPass; + } +}; + +TEST_REGISTER(GstreamerDeviceProviderTest) diff --git a/test/gstreamer/gstreamer_multi_stream_test.cpp b/test/gstreamer/gstreamer_multi_stream_test.cpp index 112f1dee..263d1e86 100644 --- a/test/gstreamer/gstreamer_multi_stream_test.cpp +++ b/test/gstreamer/gstreamer_multi_stream_test.cpp @@ -2,7 +2,7 @@ /* * Copyright (C) 2021, Vedant Paranjape * - * gstreamer_multi_stream_test.cpp - GStreamer multi stream capture test + * GStreamer multi stream capture test */ #include <iostream> @@ -29,7 +29,7 @@ class GstreamerMultiStreamTest : public GstreamerTest, public Test { public: GstreamerMultiStreamTest() - : GstreamerTest() + : GstreamerTest(2) { } @@ -39,24 +39,6 @@ protected: 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; @@ -88,8 +70,6 @@ protected: 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); @@ -124,7 +104,6 @@ protected: } private: - std::string cameraName_; GstElement *stream0_; GstElement *stream1_; }; diff --git a/test/gstreamer/gstreamer_single_stream_test.cpp b/test/gstreamer/gstreamer_single_stream_test.cpp index a0dd12cf..3ef2d323 100644 --- a/test/gstreamer/gstreamer_single_stream_test.cpp +++ b/test/gstreamer/gstreamer_single_stream_test.cpp @@ -2,7 +2,7 @@ /* * Copyright (C) 2021, Vedant Paranjape * - * gstreamer_single_stream_test.cpp - GStreamer single stream capture test + * GStreamer single stream capture test */ #include <iostream> @@ -29,30 +29,21 @@ protected: if (status_ != TestPass) return status_; - const gchar *streamDescription = "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("Bin could not be created (%s)\n", error0->message); + fakesink_ = gst_element_factory_make("fakesink", nullptr); + if (!fakesink_) { + g_printerr("Your installation is missing 'fakesink'\n"); return TestFail; } - g_object_ref_sink(stream0_); - - if (createPipeline() != TestPass) - return TestFail; + g_object_ref_sink(fakesink_); - return TestPass; + return createPipeline(); } int run() override { /* Build the pipeline */ - gst_bin_add_many(GST_BIN(pipeline_), libcameraSrc_, stream0_, NULL); - if (gst_element_link(libcameraSrc_, stream0_) != TRUE) { + gst_bin_add_many(GST_BIN(pipeline_), libcameraSrc_, fakesink_, nullptr); + if (!gst_element_link(libcameraSrc_, fakesink_)) { g_printerr("Elements could not be linked.\n"); return TestFail; } @@ -68,11 +59,11 @@ protected: void cleanup() override { - g_clear_object(&stream0_); + g_clear_object(&fakesink_); } private: - GstElement *stream0_; + GstElement *fakesink_; }; TEST_REGISTER(GstreamerSingleStreamTest) diff --git a/test/gstreamer/gstreamer_test.cpp b/test/gstreamer/gstreamer_test.cpp index 227a5c37..e8119b85 100644 --- a/test/gstreamer/gstreamer_test.cpp +++ b/test/gstreamer/gstreamer_test.cpp @@ -5,6 +5,10 @@ * libcamera Gstreamer element API tests */ +#include <libcamera/libcamera.h> + +#include <libcamera/base/utils.h> + #include "gstreamer_test.h" #include "test.h" @@ -23,19 +27,18 @@ const char *__asan_default_options() } } -GstreamerTest::GstreamerTest() +GstreamerTest::GstreamerTest(unsigned int numStreams) : pipeline_(nullptr), libcameraSrc_(nullptr) { /* - * GStreamer by default spawns a process to run the - * gst-plugin-scanner helper. If libcamera is compiled with ASan - * enabled, and as GStreamer is most likely not, this causes the - * ASan link order check to fail when gst-plugin-scanner - * dlopen()s the plugin as many libraries will have already been - * loaded by then. Fix this issue by disabling spawning of a - * child helper process when scanning the build directory for - * plugins. - */ + * GStreamer by default spawns a process to run the gst-plugin-scanner + * helper. If libcamera is compiled with ASan enabled, and as GStreamer + * is most likely not, this causes the ASan link order check to fail + * when gst-plugin-scanner dlopen()s the plugin as many libraries will + * have already been loaded by then. Fix this issue by disabling + * spawning of a child helper process when scanning the build directory + * for plugins. + */ gst_registry_fork_set_enabled(false); /* Initialize GStreamer */ @@ -49,25 +52,38 @@ GstreamerTest::GstreamerTest() } /* - * Remove the system libcamera plugin, if any, and add the - * plugin from the build directory. - */ - GstRegistry *registry = gst_registry_get(); - g_autoptr(GstPlugin) plugin = gst_registry_lookup(registry, "libgstlibcamera.so"); - if (plugin) - gst_registry_remove_plugin(registry, plugin); - - std::string path = libcamera::utils::libcameraBuildPath() + "src/gstreamer"; - if (!gst_registry_scan_path(registry, path.c_str())) { - g_printerr("Failed to add plugin to registry\n"); - - status_ = TestFail; + * Atleast one camera should be available with numStreams streams, + * otherwise skip the test entirely. + */ + if (!checkMinCameraStreamsAndSetCameraName(numStreams)) { + status_ = TestSkip; return; } status_ = TestPass; } +bool GstreamerTest::checkMinCameraStreamsAndSetCameraName(unsigned int numStreams) +{ + libcamera::CameraManager cm; + bool cameraFound = false; + + cm.start(); + + for (auto &camera : cm.cameras()) { + if (camera->streams().size() < numStreams) + continue; + + cameraFound = true; + cameraName_ = camera->id(); + break; + } + + cm.stop(); + + return cameraFound; +} + GstreamerTest::~GstreamerTest() { g_clear_object(&pipeline_); @@ -82,12 +98,13 @@ int GstreamerTest::createPipeline() pipeline_ = gst_pipeline_new("test-pipeline"); if (!libcameraSrc_ || !pipeline_) { - g_printerr("Unable to create create pipeline %p.%p\n", + g_printerr("Unable to create pipeline %p.%p\n", libcameraSrc_, pipeline_); return TestFail; } + g_object_set(libcameraSrc_, "camera-name", cameraName_.c_str(), NULL); g_object_ref_sink(libcameraSrc_); return TestPass; diff --git a/test/gstreamer/gstreamer_test.h b/test/gstreamer/gstreamer_test.h index 9869d252..abb37c1b 100644 --- a/test/gstreamer/gstreamer_test.h +++ b/test/gstreamer/gstreamer_test.h @@ -2,7 +2,7 @@ /* * Copyright (C) 2021, Vedant Paranjape * - * gstreamer_test.cpp - GStreamer test base class + * GStreamer test base class */ #pragma once @@ -10,16 +10,12 @@ #include <iostream> #include <unistd.h> -#include <libcamera/base/utils.h> - -#include "libcamera/internal/source_paths.h" - #include <gst/gst.h> class GstreamerTest { public: - GstreamerTest(); + GstreamerTest(unsigned int numStreams = 1); virtual ~GstreamerTest(); protected: @@ -28,7 +24,11 @@ protected: int processEvent(); void printError(GstMessage *msg); + std::string cameraName_; GstElement *pipeline_; GstElement *libcameraSrc_; int status_; + +private: + bool checkMinCameraStreamsAndSetCameraName(unsigned int numStreams); }; diff --git a/test/gstreamer/meson.build b/test/gstreamer/meson.build index 10058fc5..f3ba5a23 100644 --- a/test/gstreamer/meson.build +++ b/test/gstreamer/meson.build @@ -5,16 +5,17 @@ if not gst_enabled endif gstreamer_tests = [ - ['single_stream_test', 'gstreamer_single_stream_test.cpp'], - ['multi_stream_test', 'gstreamer_multi_stream_test.cpp'], + {'name': 'single_stream_test', 'sources': ['gstreamer_single_stream_test.cpp']}, + {'name': 'multi_stream_test', 'sources': ['gstreamer_multi_stream_test.cpp']}, + {'name': 'device_provider_test', 'sources': ['gstreamer_device_provider_test.cpp']}, ] -gstreamer_dep = dependency('gstreamer-1.0', required: true) +gstreamer_dep = dependency('gstreamer-1.0', required : true) -foreach t : gstreamer_tests - exe = executable(t[0], t[1], 'gstreamer_test.cpp', +foreach test : gstreamer_tests + exe = executable(test['name'], test['sources'], 'gstreamer_test.cpp', dependencies : [libcamera_private, gstreamer_dep], link_with : test_libraries, include_directories : test_includes_internal) - test(t[0], exe, suite : 'gstreamer', is_parallel : false) + test(test['name'], exe, suite : 'gstreamer', is_parallel : false, env : gst_env) endforeach |