[libcamera-devel] [PATCH v2 7/8] libcamera: camera: Add CameraConfiguration

Niklas Söderlund niklas.soderlund at ragnatech.se
Fri Apr 5 04:02:55 CEST 2019


To properly support both multiple streams and usages the library must
provide a method to map the stream usages to the returned stream
configuration. Add a camera configuration object to handle this mapping.

Applications can iterate over the returned camera configuration to
retrieve the streams selected by the library in the same order as the
usages it provided to the library. Further more the application can use
the streams to retrieve there configuration using operator[] of the
camera configuration.

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

diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h
index 0386671c902e55e8..311a51e4070d135c 100644
--- a/include/libcamera/camera.h
+++ b/include/libcamera/camera.h
@@ -14,6 +14,7 @@
 
 #include <libcamera/request.h>
 #include <libcamera/signal.h>
+#include <libcamera/stream.h>
 
 namespace libcamera {
 
@@ -24,6 +25,31 @@ class Stream;
 class StreamConfiguration;
 class StreamUsage;
 
+class CameraConfiguration
+{
+public:
+	using iterator = std::vector<Stream *>::iterator;
+	using const_iterator = std::vector<Stream *>::const_iterator;
+
+	CameraConfiguration();
+
+	iterator begin();
+	iterator end();
+	const_iterator begin() const;
+	const_iterator end() const;
+
+	bool empty() const;
+	std::size_t size() const;
+
+	Stream *front();
+
+	StreamConfiguration &operator[](Stream *stream);
+
+private:
+	std::vector<Stream *> order_;
+	std::map<Stream *, StreamConfiguration> config_;
+};
+
 class Camera final
 {
 public:
diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp
index 63fde0ffc3d02d6c..16162c524297012f 100644
--- a/src/libcamera/camera.cpp
+++ b/src/libcamera/camera.cpp
@@ -39,6 +39,127 @@ namespace libcamera {
 
 LOG_DECLARE_CATEGORY(Camera)
 
+/**
+ * \class CameraConfiguration
+ * \brief Hold configuration for streams of the camera that applications
+ * wish to modify and apply.
+ *
+ * The CameraConfiguration is filled with information by the application either
+ * manually or with the streamConfiguration() helper. The helper takes a list
+ * list of usages describing how the application intents to use the camera, the
+ * application in returns is provided with a default camera configuration it
+ * can tweak.
+ *
+ * Applications iterates over the CameraConfiguration to discover which streams
+ * the camera have selected for its usages and can inspect the configuration
+ * using the operator[].
+ */
+
+/**
+ * \typedef CameraConfiguration::iterator
+ * \brief Iterator for the streams in the configuration
+ */
+
+/**
+ * \typedef CameraConfiguration::const_iterator
+ * \brief Const iterator for the streams in the configuration
+ */
+
+/**
+ * \brief Create an empty camera configuration
+ */
+CameraConfiguration::CameraConfiguration()
+	: order_({}), config_({})
+{
+}
+
+/**
+ * \brief Retrieve an iterator to the first element of the streams
+ *
+ * \return An iterator to the first stream
+ */
+std::vector<Stream *>::iterator CameraConfiguration::begin()
+{
+	return order_.begin();
+}
+
+/**
+ * \brief Retrieve an iterator to the end of the streams
+ *
+ * \return An iterator to the element following the last stream
+ */
+std::vector<Stream *>::iterator CameraConfiguration::end()
+{
+	return order_.end();
+}
+
+/**
+ * \brief Retrieve an iterator to the first element of the streams
+ *
+ * \return An iterator to the first stream
+ */
+std::vector<Stream *>::const_iterator CameraConfiguration::begin() const
+{
+	return order_.begin();
+}
+
+/**
+ * \brief Retrieve an iterator to the end of the streams
+ *
+ * \return An iterator to the element following the last stream
+ */
+std::vector<Stream *>::const_iterator CameraConfiguration::end() const
+{
+	return order_.end();
+}
+
+/**
+ * \brief Checks whether the camera configuration is empty
+ *
+ * \return True if the configuration is empty
+ */
+bool CameraConfiguration::empty() const
+{
+	return order_.empty();
+}
+
+/**
+ * \brief Check the number of stream configurations
+ *
+ * \return Number of stream configurations
+ */
+std::size_t CameraConfiguration::size() const
+{
+	return order_.size();
+}
+
+/**
+ * \brief Access the first stream in the configuration
+ *
+ * \return The first stream in the configuration
+ */
+Stream *CameraConfiguration::front()
+{
+	return order_.front();
+}
+
+/**
+ * \brief Retrieve a reference to a stream configuration
+ * \param[in] stream Stream to retrieve configuration for
+ *
+ * If the camera configuration do not yet contain configuration for the
+ * requested stream an empty stream configuration is created and returned.
+ *
+ * \return Configuration for the stream
+ */
+StreamConfiguration &CameraConfiguration::operator[](Stream *stream)
+{
+	if (config_.find(stream) == config_.end())
+		order_.push_back(stream);
+
+	return config_[stream];
+}
+
 /**
  * \class Camera
  * \brief Camera device
-- 
2.21.0



More information about the libcamera-devel mailing list