[libcamera-devel] [PATCH] tests: gstreamer: Test cameras' enumeration from GstDeviceProvider
Barnabás Pőcze
pobrn at protonmail.com
Tue Jul 4 20:50:43 CEST 2023
Hi
2023. július 4., kedd 17:53 keltezéssel, Umang Jain via libcamera-devel <libcamera-devel at lists.libcamera.org> írta:
> 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;
> +}
> +
> 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()));
> [...]
As far as I can tell these strings will be leaked. Why not use `std::string`?
Regards,
Barnabás Pőcze
More information about the libcamera-devel
mailing list