summaryrefslogtreecommitdiff
path: root/src/gstreamer/gstlibcameraprovider.cpp
diff options
context:
space:
mode:
authorNicolas Dufresne <nicolas.dufresne@collabora.com>2021-08-26 09:23:45 -0400
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-08-26 16:42:52 +0300
commit9c49106b9709da130d81bff913db8ce2daecd9b6 (patch)
tree881cec1ba36b257129bbeaa863d83ed9c56247c8 /src/gstreamer/gstlibcameraprovider.cpp
parent1ca5513396b4fa52f7305e19b7db0ae525dbd730 (diff)
gstreamer: Fix concurrent access issues to CameraManager
It's not allowed to have multiple instances of CameraManager. This requirement is not easy for GStreamer were the device monitor and the camerasrc, or two camerasrc instances don't usually have any interaction between each other. Fix this by implementing a minimalist singleton around CameraManager constructor and start()/stop() operations. Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/gstreamer/gstlibcameraprovider.cpp')
-rw-r--r--src/gstreamer/gstlibcameraprovider.cpp22
1 files changed, 2 insertions, 20 deletions
diff --git a/src/gstreamer/gstlibcameraprovider.cpp b/src/gstreamer/gstlibcameraprovider.cpp
index 29da6c32..948ba0d1 100644
--- a/src/gstreamer/gstlibcameraprovider.cpp
+++ b/src/gstreamer/gstlibcameraprovider.cpp
@@ -158,7 +158,6 @@ gst_libcamera_device_new(const std::shared_ptr<Camera> &camera)
struct _GstLibcameraProvider {
GstDeviceProvider parent;
- CameraManager *cm;
};
G_DEFINE_TYPE_WITH_CODE(GstLibcameraProvider, gst_libcamera_provider,
@@ -170,7 +169,7 @@ static GList *
gst_libcamera_provider_probe(GstDeviceProvider *provider)
{
GstLibcameraProvider *self = GST_LIBCAMERA_PROVIDER(provider);
- CameraManager *cm = self->cm;
+ std::shared_ptr<CameraManager> cm;
GList *devices = nullptr;
gint ret;
@@ -181,7 +180,7 @@ gst_libcamera_provider_probe(GstDeviceProvider *provider)
* gains monitoring support. Meanwhile we need to cycle start()/stop()
* to ensure every probe() calls return the latest list.
*/
- ret = cm->start();
+ cm = gst_libcamera_get_camera_mananger(ret);
if (ret) {
GST_ERROR_OBJECT(self, "Failed to retrieve device list: %s",
g_strerror(-ret));
@@ -194,8 +193,6 @@ gst_libcamera_provider_probe(GstDeviceProvider *provider)
g_object_ref_sink(gst_libcamera_device_new(camera)));
}
- cm->stop();
-
return devices;
}
@@ -204,31 +201,16 @@ gst_libcamera_provider_init(GstLibcameraProvider *self)
{
GstDeviceProvider *provider = GST_DEVICE_PROVIDER(self);
- self->cm = new CameraManager();
-
/* Avoid devices being duplicated. */
gst_device_provider_hide_provider(provider, "v4l2deviceprovider");
}
static void
-gst_libcamera_provider_finalize(GObject *object)
-{
- GstLibcameraProvider *self = GST_LIBCAMERA_PROVIDER(object);
- gpointer klass = gst_libcamera_provider_parent_class;
-
- delete self->cm;
-
- return G_OBJECT_CLASS(klass)->finalize(object);
-}
-
-static void
gst_libcamera_provider_class_init(GstLibcameraProviderClass *klass)
{
GstDeviceProviderClass *provider_class = GST_DEVICE_PROVIDER_CLASS(klass);
- GObjectClass *object_class = G_OBJECT_CLASS(klass);
provider_class->probe = gst_libcamera_provider_probe;
- object_class->finalize = gst_libcamera_provider_finalize;
gst_device_provider_class_set_metadata(provider_class,
"libcamera Device Provider",