[libcamera-devel,v4,10/11] libcamera: pipeline_handler: Add functions to lock a whole pipeline

Message ID 20190517005447.27171-11-niklas.soderlund@ragnatech.se
State Accepted
Headers show
Series
  • libcamerea: Add support for exclusive access to cameras between processes
Related show

Commit Message

Niklas Söderlund May 17, 2019, 12:54 a.m. UTC
Add lock() and unlock() which are backed by the MediaDevice
implementation and lock all media devices claimed by a pipeline handler
instance.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/libcamera/include/pipeline_handler.h |  3 ++
 src/libcamera/pipeline_handler.cpp       | 36 ++++++++++++++++++++++++
 2 files changed, 39 insertions(+)

Patch

diff --git a/src/libcamera/include/pipeline_handler.h b/src/libcamera/include/pipeline_handler.h
index 8e6a136dd4907d9f..9f5fe3d673e294c8 100644
--- a/src/libcamera/include/pipeline_handler.h
+++ b/src/libcamera/include/pipeline_handler.h
@@ -57,6 +57,9 @@  public:
 	MediaDevice *acquireMediaDevice(DeviceEnumerator *enumerator,
 					const DeviceMatch &dm);
 
+	bool lock();
+	void unlock();
+
 	virtual CameraConfiguration
 	streamConfiguration(Camera *camera, const std::vector<StreamUsage> &usages) = 0;
 	virtual int configureStreams(Camera *camera, const CameraConfiguration &config) = 0;
diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp
index c92ee782701f57bf..1eeaf4bb6dae8601 100644
--- a/src/libcamera/pipeline_handler.cpp
+++ b/src/libcamera/pipeline_handler.cpp
@@ -181,6 +181,42 @@  MediaDevice *PipelineHandler::acquireMediaDevice(DeviceEnumerator *enumerator,
 	return media.get();
 }
 
+/**
+ * \brief Lock all media devices acquired by the pipeline
+ *
+ * This method shall not be called from pipeline handler implementation, as the
+ * Camera class handles locking directly.
+ *
+ * \return True if the devices could be locked, false otherwise
+ * \sa unlock()
+ * \sa MediaDevice::lock()
+ */
+bool PipelineHandler::lock()
+{
+	for (std::shared_ptr<MediaDevice> &media : mediaDevices_) {
+		if (!media->lock()) {
+			unlock();
+			return false;
+		}
+	}
+
+	return true;
+}
+
+/**
+ * \brief Unlock all media devices acquired by the pipeline
+ *
+ * This method shall not be called from pipeline handler implementation, as the
+ * Camera class handles locking directly.
+ *
+ * \sa lock()
+ */
+void PipelineHandler::unlock()
+{
+	for (std::shared_ptr<MediaDevice> &media : mediaDevices_)
+		media->unlock();
+}
+
 /**
  * \fn PipelineHandler::streamConfiguration()
  * \brief Retrieve a group of stream configurations for a specified camera