[libcamera-devel,RFC,3/7] libcamera: camera: implement start and stop of a camera

Message ID 20190205000702.15370-4-niklas.soderlund@ragnatech.se
State Superseded
Delegated to: Niklas Söderlund
Headers show
Series
  • libcamera: extend camera and pipeline to support requests
Related show

Commit Message

Niklas Söderlund Feb. 5, 2019, 12:06 a.m. UTC
Add an interface for the application to start and stop a camera. Once a
camera is started the pipeline handler of the camera will begin
processing request queued to the camera by the application until it's
stopped.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 include/libcamera/camera.h |  4 ++++
 src/libcamera/camera.cpp   | 48 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)

Patch

diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h
index 4940c344440e2ca2..de338c616641c074 100644
--- a/include/libcamera/camera.h
+++ b/include/libcamera/camera.h
@@ -15,6 +15,7 @@ 
 
 namespace libcamera {
 
+class Buffer;
 class PipelineHandler;
 class Stream;
 class StreamConfiguration;
@@ -41,6 +42,9 @@  public:
 	streamConfiguration(std::vector<Stream *> &streams);
 	int configureStreams(std::map<Stream *, StreamConfiguration> &config);
 
+	int start();
+	int stop();
+
 private:
 	Camera(PipelineHandler *pipe, const std::string &name);
 	~Camera();
diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp
index bcf3d54ab1c3eb29..bf09acfdb9cd0007 100644
--- a/src/libcamera/camera.cpp
+++ b/src/libcamera/camera.cpp
@@ -6,6 +6,7 @@ 
  */
 
 #include <libcamera/camera.h>
+#include <libcamera/request.h>
 #include <libcamera/stream.h>
 
 #include "log.h"
@@ -248,4 +249,51 @@  int Camera::configureStreams(std::map<Stream *, StreamConfiguration> &config)
 	return pipe_->configureStreams(this, config);
 }
 
+/**
+ * \brief Start capture from camera
+ *
+ * Start the camera capture session. Once the camera is started the application
+ * can queue requests to the camera to process and return to the application
+ * until the capture session is terminated with \a stop().
+ *
+ * \return 0 on success or a negative error code on error.
+ * \retval -ENODEV The camera is not connected to any hardware
+ * \retval -EACCES The user has not acquired exclusive access to the camera
+ */
+int Camera::start()
+{
+	if (disconnected_)
+		return -ENODEV;
+
+	if (!acquired_)
+		return -EACCES;
+
+	return pipe_->start(this);
+}
+
+/**
+ * \brief Stop capture from camera
+ *
+ * Stop the running capture session. Once the camera is stooped the may not
+ * queue any new requests and any already queued requests might that have not
+ * been queued to the hardware might be returned to the application not
+ * fulfilled.
+ *
+ * \return 0 on success or a negative error code on error.
+ * \retval -ENODEV The camera is not connected to any hardware
+ * \retval -EACCES The user has not acquired exclusive access to the camera
+ */
+int Camera::stop()
+{
+	if (disconnected_)
+		return -ENODEV;
+
+	if (!acquired_)
+		return -EACCES;
+
+	pipe_->stop(this);
+
+	return 0;
+}
+
 } /* namespace libcamera */