[libcamera-devel,7/8] libcamera: camera: integrate streams and configuration

Message ID 20190122234505.32634-8-niklas.soderlund@ragnatech.se
State Superseded
Headers show
Series
  • libcamera: add basic support for Streams and format configuration
Related show

Commit Message

Niklas Söderlund Jan. 22, 2019, 11:45 p.m. UTC
Add retrieval and configuration of streams information and
configuration. The implementation in the Camera are minimalistic as the
heavily lifting are done by the pipeline handler implementations.

The single most important thing for the helpers in the Camera object is
to perform access control and making sure no request is forwarded to a
pipeline handler if the camera have been disconnected.

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

Patch

diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h
index 3cb1ab62b791ab87..9337fa970d26b0df 100644
--- a/include/libcamera/camera.h
+++ b/include/libcamera/camera.h
@@ -9,10 +9,13 @@ 
 
 #include <memory>
 #include <string>
+#include <vector>
 
 namespace libcamera {
 
 class PipelineHandler;
+class Stream;
+class StreamConfiguration;
 
 class Camera final
 {
@@ -30,6 +33,10 @@  public:
 	int acquire();
 	void release();
 
+	std::vector<Stream> streams() const;
+
+	int configure(std::vector<StreamConfiguration *> &config);
+
 private:
 	explicit Camera(const std::string &name, class PipelineHandler *pipe);
 	~Camera();
diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp
index ee5e6dedb242a1fd..6cae82669e454e35 100644
--- a/src/libcamera/camera.cpp
+++ b/src/libcamera/camera.cpp
@@ -6,6 +6,9 @@ 
  */
 
 #include <libcamera/camera.h>
+#include <libcamera/stream.h>
+
+#include "pipeline_handler.h"
 
 #include "log.h"
 
@@ -144,4 +147,49 @@  void Camera::release()
 	acquired_ = false;
 }
 
+/**
+ * \brief Retrieve the supported streams of the camera
+ *
+ * \return An array of streams supported by the camera device
+ */
+std::vector<Stream> Camera::streams() const
+{
+	std::vector<Stream> streams;
+
+	if (pipe_)
+		streams = pipe_->streams(this);
+
+	return streams;
+}
+
+/**
+ * \brief Configure the camera device prior to capture
+ *
+ * Prior to starting capture, the camera device must be configured to select a
+ * set of streams.
+ *
+ * The requested configuration \a config shall contain at least one stream and
+ * may contain multiple streams. For each stream an associated StreamFormat
+ * shall be supplied. Streams supported by the camera device not part of the
+ * \a config will be disabled.
+ *
+ * Exclusive access to the camera device shall be ensured by a call to
+ * Camera::acquire() before calling this function, otherwise an -EACCES error
+ * will be returned.
+ *
+ * \param[in] config Array of stream configurations to setup
+ *
+ * \return 0 on success or a negative error code on error.
+ */
+int Camera::configure(std::vector<StreamConfiguration *> &config)
+{
+	if (!pipe_)
+		return -ENODEV;
+
+	if (!acquired_)
+		return -EACCES;
+
+	return pipe_->configure(this, config);
+}
+
 } /* namespace libcamera */