{"id":947,"url":"https://patchwork.libcamera.org/api/1.1/patches/947/?format=json","web_url":"https://patchwork.libcamera.org/patch/947/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20190408134817.15247-8-niklas.soderlund@ragnatech.se>","date":"2019-04-08T13:48:16","name":"[libcamera-devel,v4,7/8] libcamera: camera: Add CameraConfiguration","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"ff211f72386a225c5fa71f64f1c4307d96eb9758","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/1.1/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/947/mbox/","series":[{"id":245,"url":"https://patchwork.libcamera.org/api/1.1/series/245/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=245","date":"2019-04-08T13:48:09","name":"libcamera: stream: Add basic stream usages","version":4,"mbox":"https://patchwork.libcamera.org/series/245/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/947/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/947/checks/","tags":{},"headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net\n\t[195.74.38.228])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7374E60004\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  8 Apr 2019 15:49:45 +0200 (CEST)","from bismarck.berto.se (unknown [89.233.230.99])\n\tby bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA\n\tid 2119dee3-5a05-11e9-846a-005056917a89;\n\tMon, 08 Apr 2019 15:49:39 +0200 (CEST)"],"X-Halon-ID":"2119dee3-5a05-11e9-846a-005056917a89","Authorized-sender":"niklas@soderlund.pp.se","From":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon,  8 Apr 2019 15:48:16 +0200","Message-Id":"<20190408134817.15247-8-niklas.soderlund@ragnatech.se>","X-Mailer":"git-send-email 2.21.0","In-Reply-To":"<20190408134817.15247-1-niklas.soderlund@ragnatech.se>","References":"<20190408134817.15247-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 7/8] libcamera: camera: Add\n\tCameraConfiguration","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Mon, 08 Apr 2019 13:49:45 -0000"},"content":"To properly support both multiple streams and stream usages the library\nmust provide a method to map the stream usages to the returned streams\nconfigurations. Add a camera configuration object to handle this\nmapping.\n\nApplications can iterate over the returned camera configuration to\nretrieve the streams selected by the library in the same order as the\nusages it provided to the library.\n\nApplication can use the operator[] to retrieve the stream pointer and\nthe stream configuration. Using a numerical index retrieves the stream\npointer, the numerical indexes corresponds to the insertion order of\nusages by the application, using the stream pointer retrieves the\nstream's configuration.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n include/libcamera/camera.h |  29 ++++++\n src/libcamera/camera.cpp   | 192 +++++++++++++++++++++++++++++++++++++\n 2 files changed, 221 insertions(+)","diff":"diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h\nindex 0386671c902e55e8..6038da63e9c5c67f 100644\n--- a/include/libcamera/camera.h\n+++ b/include/libcamera/camera.h\n@@ -24,6 +24,35 @@ class Stream;\n class StreamConfiguration;\n class StreamUsage;\n \n+class CameraConfiguration\n+{\n+public:\n+\tusing iterator = std::vector<Stream *>::iterator;\n+\tusing const_iterator = std::vector<Stream *>::const_iterator;\n+\n+\tCameraConfiguration();\n+\n+\titerator begin();\n+\titerator end();\n+\tconst_iterator begin() const;\n+\tconst_iterator end() const;\n+\n+\tbool isValid() const;\n+\tbool isEmpty() const;\n+\tstd::size_t size() const;\n+\n+\tStream *front();\n+\tconst Stream *front() const;\n+\n+\tStream *operator[](unsigned int index) const;\n+\tStreamConfiguration &operator[](Stream *stream);\n+\tconst StreamConfiguration &operator[](Stream *stream) const;\n+\n+private:\n+\tstd::vector<Stream *> order_;\n+\tstd::map<Stream *, StreamConfiguration> config_;\n+};\n+\n class Camera final\n {\n public:\ndiff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\nindex 63fde0ffc3d02d6c..c1b9561304b04ab5 100644\n--- a/src/libcamera/camera.cpp\n+++ b/src/libcamera/camera.cpp\n@@ -39,6 +39,198 @@ namespace libcamera {\n \n LOG_DECLARE_CATEGORY(Camera)\n \n+/**\n+ * \\class CameraConfiguration\n+ * \\brief Hold configuration for streams of the camera\n+\n+ * The CameraConfiguration holds an ordered list of streams and their associated\n+ * StreamConfiguration. From a data storage point of view, the class operates as\n+ * a map of Stream pointers to StreamConfiguration, with entries accessed with\n+ * operator[](Stream *). Accessing an entry for a Stream pointer not yet stored\n+ * in the configuration inserts a new empty entry.\n+ *\n+ * The class also suppors iterators, and from that point of view operates as a\n+ * vector of Stream pointers. The streams are iterated in insertion order, and\n+ * the operator[](int) returns the Stream pointer based on its insertion index.\n+ * Accessing a stream with an invalid index returns a null pointer.\n+ */\n+\n+/**\n+ * \\typedef CameraConfiguration::iterator\n+ * \\brief Iterator for the streams in the configuration\n+ */\n+\n+/**\n+ * \\typedef CameraConfiguration::const_iterator\n+ * \\brief Const iterator for the streams in the configuration\n+ */\n+\n+/**\n+ * \\brief Create an empty camera configuration\n+ */\n+CameraConfiguration::CameraConfiguration()\n+\t: order_({}), config_({})\n+{\n+}\n+\n+/**\n+ * \\brief Retrieve an iterator to the first stream in the sequence\n+ *\n+ * \\return An iterator to the first stream\n+ */\n+std::vector<Stream *>::iterator CameraConfiguration::begin()\n+{\n+\treturn order_.begin();\n+}\n+\n+/**\n+ * \\brief Retrieve an iterator pointing to the past-the-end stream in the\n+ * sequence\n+ *\n+ * \\return An iterator to the element following the last stream\n+ */\n+std::vector<Stream *>::iterator CameraConfiguration::end()\n+{\n+\treturn order_.end();\n+}\n+\n+/**\n+ * \\brief Retrieve a const iterator to the first element of the streams\n+ *\n+ * \\return A const iterator to the first stream\n+ */\n+std::vector<Stream *>::const_iterator CameraConfiguration::begin() const\n+{\n+\treturn order_.begin();\n+}\n+\n+/**\n+ * \\brief Retrieve a const iterator pointing to the past-the-end stream in the\n+ * sequence\n+ *\n+ * \\return A const iterator to the element following the last stream\n+ */\n+std::vector<Stream *>::const_iterator CameraConfiguration::end() const\n+{\n+\treturn order_.end();\n+}\n+\n+/**\n+ * \\brief Check if the camera configuration is valid\n+ *\n+ * A camera configuration is deemed to be valid if it contains at least one\n+ * stream configuration and that all stream configurations contain valid\n+ * information. Stream configurations are deemed to be valid if all fields are\n+ * none zero.\n+ *\n+ * \\return True if the configuration is valid\n+ */\n+bool CameraConfiguration::isValid() const\n+{\n+\tif (isEmpty())\n+\t\treturn false;\n+\n+\tfor (auto const &it : config_) {\n+\t\tconst StreamConfiguration &conf = it.second;\n+\n+\t\tif (conf.width == 0 || conf.height == 0 ||\n+\t\t    conf.pixelFormat == 0 || conf.bufferCount == 0)\n+\t\t\treturn false;\n+\t}\n+\n+\treturn true;\n+}\n+\n+/**\n+ * \\brief Check if the camera configuration is empty\n+ *\n+ * \\return True if the configuration is empty\n+ */\n+bool CameraConfiguration::isEmpty() const\n+{\n+\treturn order_.empty();\n+}\n+\n+/**\n+ * \\brief Retrieve the number of stream configurations\n+ *\n+ * \\return Number of stream configurations\n+ */\n+std::size_t CameraConfiguration::size() const\n+{\n+\treturn order_.size();\n+}\n+\n+/**\n+ * \\brief Access the first stream in the configuration\n+ *\n+ * \\return The first stream in the configuration\n+ */\n+Stream *CameraConfiguration::front()\n+{\n+\treturn order_.front();\n+}\n+\n+/**\n+ * \\brief Access the first stream in the configuration\n+ *\n+ * \\return The first const stream pointer in the configuration\n+ */\n+const Stream *CameraConfiguration::front() const\n+{\n+\treturn order_.front();\n+}\n+\n+/**\n+ * \\brief Retrieve a stream pointer from index\n+ * \\param[in] index Numerical index\n+ *\n+ * The \\a index represents the zero based insertion order of stream and stream\n+ * configuration into the camera configuration.\n+ *\n+ * \\return The stream pointer at index, or a nullptr if the index is out of\n+ * bounds\n+ */\n+Stream *CameraConfiguration::operator[](unsigned int index) const\n+{\n+\tif (index >= order_.size())\n+\t\treturn nullptr;\n+\n+\treturn order_.at(index);\n+}\n+\n+/**\n+ * \\brief Retrieve a reference to a stream configuration\n+ * \\param[in] stream Stream to retrieve configuration for\n+ *\n+ * If the camera configuration does not yet contain a configuration for\n+ * the requested stream, create and return an empty stream configuration.\n+ *\n+ * \\return The configuration for the stream\n+ */\n+StreamConfiguration &CameraConfiguration::operator[](Stream *stream)\n+{\n+\tif (config_.find(stream) == config_.end())\n+\t\torder_.push_back(stream);\n+\n+\treturn config_[stream];\n+}\n+\n+/**\n+ * \\brief Retrieve a const reference to a stream configuration\n+ * \\param[in] stream Stream to retrieve configuration for\n+ *\n+ * No new stream configuration is created if called with \\a stream that is not\n+ * already part of the camera configuration, doing so is an invalid operation\n+ * and results in undefined behaviour.\n+ *\n+ * \\return The configuration for the stream\n+ */\n+const StreamConfiguration &CameraConfiguration::operator[](Stream *stream) const\n+{\n+\treturn config_.at(stream);\n+}\n+\n /**\n  * \\class Camera\n  * \\brief Camera device\n","prefixes":["libcamera-devel","v4","7/8"]}