[libcamera-devel,v2] tests: gstreamer: Test cameras' enumeration from GstDeviceProvider
diff mbox series

Message ID 20230704212343.78465-1-umang.jain@ideasonboard.com
State Accepted
Headers show
Series
  • [libcamera-devel,v2] tests: gstreamer: Test cameras' enumeration from GstDeviceProvider
Related show

Commit Message

Umang Jain July 4, 2023, 9:23 p.m. UTC
Test the enumeration of the cameras through GstDeviceProvider against
the libcamera camera manager.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
---
Changes in v2:
- Split out to dedicated device provider test
- Use gst_device_provider_factory_get_by_name() to find
  libcameraprovider
- Use "camera-name" to compare camera ids with camera-manager
  instead of gst_device_get_display_name()
---
 .../gstreamer_device_provider_test.cpp        | 77 +++++++++++++++++++
 test/gstreamer/meson.build                    |  1 +
 2 files changed, 78 insertions(+)
 create mode 100644 test/gstreamer/gstreamer_device_provider_test.cpp

Comments

Nicolas Dufresne July 5, 2023, 3:09 p.m. UTC | #1
Thanks for the fixes.

Le mardi 04 juillet 2023 à 23:23 +0200, Umang Jain a écrit :
> Test the enumeration of the cameras through GstDeviceProvider against
> the libcamera camera manager.
> 
> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>

Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>

> ---
> Changes in v2:
> - Split out to dedicated device provider test
> - Use gst_device_provider_factory_get_by_name() to find
>   libcameraprovider
> - Use "camera-name" to compare camera ids with camera-manager
>   instead of gst_device_get_display_name()
> ---
>  .../gstreamer_device_provider_test.cpp        | 77 +++++++++++++++++++
>  test/gstreamer/meson.build                    |  1 +
>  2 files changed, 78 insertions(+)
>  create mode 100644 test/gstreamer/gstreamer_device_provider_test.cpp
> 
> diff --git a/test/gstreamer/gstreamer_device_provider_test.cpp b/test/gstreamer/gstreamer_device_provider_test.cpp
> new file mode 100644
> index 00000000..69e110c7
> --- /dev/null
> +++ b/test/gstreamer/gstreamer_device_provider_test.cpp
> @@ -0,0 +1,77 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Copyright 2023 Umang Jain <umang.jain@ideasonboard.com>
> + *
> + * gstreamer_single_stream_test.cpp - 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;
> +		GList *devices, *l;
> +		std::vector<std::string> cameraNames;
> +		std::unique_ptr<libcamera::CameraManager> 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/meson.build b/test/gstreamer/meson.build
> index 74572586..0904ee0d 100644
> --- a/test/gstreamer/meson.build
> +++ b/test/gstreamer/meson.build
> @@ -7,6 +7,7 @@ endif
>  gstreamer_tests = [
>      {'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)
>

Patch
diff mbox series

diff --git a/test/gstreamer/gstreamer_device_provider_test.cpp b/test/gstreamer/gstreamer_device_provider_test.cpp
new file mode 100644
index 00000000..69e110c7
--- /dev/null
+++ b/test/gstreamer/gstreamer_device_provider_test.cpp
@@ -0,0 +1,77 @@ 
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright 2023 Umang Jain <umang.jain@ideasonboard.com>
+ *
+ * gstreamer_single_stream_test.cpp - 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;
+		GList *devices, *l;
+		std::vector<std::string> cameraNames;
+		std::unique_ptr<libcamera::CameraManager> 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/meson.build b/test/gstreamer/meson.build
index 74572586..0904ee0d 100644
--- a/test/gstreamer/meson.build
+++ b/test/gstreamer/meson.build
@@ -7,6 +7,7 @@  endif
 gstreamer_tests = [
     {'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)