[libcamera-devel] [PATCH] tests: gstreamer: Test cameras' enumeration from GstDeviceProvider
Olivier Crête
olivier.crete at collabora.com
Tue Jul 4 21:10:55 CEST 2023
On Tue, 2023-07-04 at 17:53 +0200, Umang Jain via libcamera-devel
wrote:
> Test the enumeration of the cameras through GstDeviceProvider against
> the libcamera camera manager.
>
> Signed-off-by: Umang Jain <umang.jain at ideasonboard.com>
> ---
> test/gstreamer/gstreamer_test.cpp | 52 +++++++++++++++++++++++++++++++
> test/gstreamer/gstreamer_test.h | 1 +
> 2 files changed, 53 insertions(+)
>
> diff --git a/test/gstreamer/gstreamer_test.cpp b/test/gstreamer/gstreamer_test.cpp
> index 6ad0c15c..f94f3fd9 100644
> --- a/test/gstreamer/gstreamer_test.cpp
> +++ b/test/gstreamer/gstreamer_test.cpp
> @@ -27,6 +27,18 @@ const char *__asan_default_options()
> }
> }
>
> +static GstDeviceMonitor *
> +libcamerasrc_get_device_provider()
> +{
> + GstDeviceMonitor *monitor = gst_device_monitor_new();
> +
> + gst_device_monitor_add_filter(monitor, "Video/Source", NULL);
> +
> + gst_device_monitor_start(monitor);
> +
> + return monitor;
> +}
You may instead want to do something like to make sure your testing the
provider you actually want to test:
GstDeviceProviderFactory *factory = gst_device_provider_factory_find
("libcameraprovider");
GstDeviceProvider *provider = gst_device_provider_factory_get (fact);
gst_object_unref(fact);
GList *devices = gst_device_provider_get_devices(provider);
// validate devices
g_list_free_full (devices, gst_object_unref);
gst_object_unref(provider);
Olivier
> +
> GstreamerTest::GstreamerTest(unsigned int numStreams)
> : pipeline_(nullptr), libcameraSrc_(nullptr)
> {
> @@ -78,6 +90,12 @@ GstreamerTest::GstreamerTest(unsigned int numStreams)
> return;
> }
>
> + if (!checkCameraEnumeration()) {
> + g_printerr("Failed to enumerate cameras on GstDeviceProvider\n");
> + status_ = TestFail;
> + return;
> + }
> +
> status_ = TestPass;
> }
>
> @@ -102,6 +120,40 @@ bool GstreamerTest::checkMinCameraStreamsAndSetCameraName(unsigned int numStream
> return cameraFound;
> }
>
> +bool GstreamerTest::checkCameraEnumeration()
> +{
> + GstDeviceMonitor *monitor;
> + GList *devices, *l;
> + std::vector<const char *> cameraNames;
> + std::unique_ptr<libcamera::CameraManager> cm
> + = std::make_unique<libcamera::CameraManager>();
> +
> + cm->start();
> + for (auto &camera : cm->cameras())
> + cameraNames.push_back(strdup(camera->id().c_str()));
> + cm->stop();
> + cm.reset();
> +
> + monitor = libcamerasrc_get_device_provider();
> + devices = gst_device_monitor_get_devices(monitor);
> +
> + for (l = devices; l != NULL; l = g_list_next(l)) {
> + bool matched = false;
> + GstDevice *device = GST_DEVICE(l->data);
> + for (const gchar *name : cameraNames) {
> + if (strcmp(name, gst_device_get_display_name(device)) == 0) {
> + matched = true;
> + break;
> + }
> + }
> +
> + if (!matched)
> + return false;
> + }
> +
> + return true;
> +}
> +
> GstreamerTest::~GstreamerTest()
> {
> g_clear_object(&pipeline_);
> diff --git a/test/gstreamer/gstreamer_test.h b/test/gstreamer/gstreamer_test.h
> index aa2261e2..3479c7c4 100644
> --- a/test/gstreamer/gstreamer_test.h
> +++ b/test/gstreamer/gstreamer_test.h
> @@ -31,4 +31,5 @@ protected:
>
> private:
> bool checkMinCameraStreamsAndSetCameraName(unsigned int numStreams);
> + bool checkCameraEnumeration();
> };
--
Olivier Crête
olivier.crete at collabora.com
Multimedia Lead
More information about the libcamera-devel
mailing list