[libcamera-devel] [PATCH 17/27] libcamera: camera: Add helper to check for exclusive access

Laurent Pinchart laurent.pinchart at ideasonboard.com
Wed Feb 6 07:08:08 CET 2019


From: Niklas Söderlund <niklas.soderlund at ragnatech.se>

Some operations on the camera requires the application to have exclusive
access to the camera. To help check for this in these operations add a
helper.

Signed-off-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>
Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
 include/libcamera/camera.h |  1 +
 src/libcamera/camera.cpp   | 22 ++++++++++++++++++----
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h
index bbe2696e837b..36bf1cbb215b 100644
--- a/include/libcamera/camera.h
+++ b/include/libcamera/camera.h
@@ -50,6 +50,7 @@ private:
 
 	friend class PipelineHandler;
 	void disconnect();
+	int exclusiveAccess();
 
 	std::shared_ptr<PipelineHandler> pipe_;
 	std::string name_;
diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp
index e8dab6f0bab2..62291d2c9e6c 100644
--- a/src/libcamera/camera.cpp
+++ b/src/libcamera/camera.cpp
@@ -240,6 +240,23 @@ Camera::streamConfiguration(std::vector<Stream *> &streams)
  * \retval -EINVAL The configuration is not valid
  */
 int Camera::configureStreams(std::map<Stream *, StreamConfiguration> &config)
+{
+	int ret;
+
+	ret = exclusiveAccess();
+	if (ret)
+		return ret;
+
+	if (!config.size()) {
+		LOG(Camera, Error)
+			<< "Can't configure streams without a configuration";
+		return -EINVAL;
+	}
+
+	return pipe_->configureStreams(this, config);
+}
+
+int Camera::exclusiveAccess()
 {
 	if (disconnected_)
 		return -ENODEV;
@@ -247,10 +264,7 @@ int Camera::configureStreams(std::map<Stream *, StreamConfiguration> &config)
 	if (!acquired_)
 		return -EACCES;
 
-	if (!config.size())
-		return -EINVAL;
-
-	return pipe_->configureStreams(this, config);
+	return 0;
 }
 
 } /* namespace libcamera */
-- 
Regards,

Laurent Pinchart



More information about the libcamera-devel mailing list