From patchwork Fri Apr 5 02:02:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 921 Return-Path: Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3A215611B9 for ; Fri, 5 Apr 2019 04:03:11 +0200 (CEST) X-Halon-ID: f390a0c1-5746-11e9-8144-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id f390a0c1-5746-11e9-8144-0050569116f7; Fri, 05 Apr 2019 04:03:05 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Fri, 5 Apr 2019 04:02:55 +0200 Message-Id: <20190405020256.22520-8-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190405020256.22520-1-niklas.soderlund@ragnatech.se> References: <20190405020256.22520-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 7/8] libcamera: camera: Add CameraConfiguration X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Apr 2019 02:03:12 -0000 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 --- 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 #include +#include namespace libcamera { @@ -24,6 +25,31 @@ class Stream; class StreamConfiguration; class StreamUsage; +class CameraConfiguration +{ +public: + using iterator = std::vector::iterator; + using const_iterator = std::vector::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 order_; + std::map 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::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::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::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::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