[libcamera-devel] [PATCH] tests: gstreamer: Test cameras' enumeration from GstDeviceProvider

Umang Jain umang.jain at ideasonboard.com
Tue Jul 4 21:27:26 CEST 2023


Hi Barnabás,

On 7/4/23 8:50 PM, Barnabás Pőcze wrote:
> 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`?

ik, yes these are leaked, thanks for noticing.
>
>
> Regards,
> Barnabás Pőcze



More information about the libcamera-devel mailing list