summaryrefslogtreecommitdiff
path: root/src/gstreamer/gstlibcamerasrc.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/gstlibcamerasrc.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/gstlibcamerasrc.cpp')
-rw-r--r--src/gstreamer/gstlibcamerasrc.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/gstreamer/gstlibcamerasrc.cpp b/src/gstreamer/gstlibcamerasrc.cpp
index b243aeb3..512fbbc1 100644
--- a/src/gstreamer/gstlibcamerasrc.cpp
+++ b/src/gstreamer/gstlibcamerasrc.cpp
@@ -108,7 +108,7 @@ GstBuffer *RequestWrap::detachBuffer(Stream *stream)
struct GstLibcameraSrcState {
GstLibcameraSrc *src_;
- std::unique_ptr<CameraManager> cm_;
+ std::shared_ptr<CameraManager> cm_;
std::shared_ptr<Camera> cam_;
std::unique_ptr<CameraConfiguration> config_;
std::vector<GstPad *> srcpads_;
@@ -202,13 +202,13 @@ GstLibcameraSrcState::requestCompleted(Request *request)
static bool
gst_libcamera_src_open(GstLibcameraSrc *self)
{
- std::unique_ptr<CameraManager> cm = std::make_unique<CameraManager>();
+ std::shared_ptr<CameraManager> cm;
std::shared_ptr<Camera> cam;
- gint ret = 0;
+ gint ret;
GST_DEBUG_OBJECT(self, "Opening camera device ...");
- ret = cm->start();
+ cm = gst_libcamera_get_camera_mananger(ret);
if (ret) {
GST_ELEMENT_ERROR(self, LIBRARY, INIT,
("Failed listing cameras."),
@@ -254,7 +254,7 @@ gst_libcamera_src_open(GstLibcameraSrc *self)
cam->requestCompleted.connect(self->state, &GstLibcameraSrcState::requestCompleted);
/* No need to lock here, we didn't start our threads yet. */
- self->state->cm_ = std::move(cm);
+ self->state->cm_ = cm;
self->state->cam_ = cam;
return true;
@@ -521,7 +521,6 @@ gst_libcamera_src_close(GstLibcameraSrc *self)
}
state->cam_.reset();
- state->cm_->stop();
state->cm_.reset();
}