{"id":1298,"url":"https://patchwork.libcamera.org/api/patches/1298/?format=json","web_url":"https://patchwork.libcamera.org/patch/1298/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20190527001543.13593-6-niklas.soderlund@ragnatech.se>","date":"2019-05-27T00:15:31","name":"[libcamera-devel,05/17] libcamera: formats: Add V4L2DeviceFormats and V4L2DeviceFormats","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"a80c3b134a46c435ed7235b2f12141528f9d9f59","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/1298/mbox/","series":[{"id":328,"url":"https://patchwork.libcamera.org/api/series/328/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=328","date":"2019-05-27T00:15:28","name":"libcamera: Add support for format information and validation","version":1,"mbox":"https://patchwork.libcamera.org/series/328/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1298/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1298/checks/","tags":{},"headers":{"Return-Path":"<niklas.soderlund@ragnatech.se>","Received":["from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net\n\t[195.74.38.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 45CC9618F5\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 27 May 2019 02:16:08 +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 9d973116-8014-11e9-8ab4-005056917a89;\n\tMon, 27 May 2019 02:16:04 +0200 (CEST)"],"X-Halon-ID":"9d973116-8014-11e9-8ab4-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, 27 May 2019 02:15:31 +0200","Message-Id":"<20190527001543.13593-6-niklas.soderlund@ragnatech.se>","X-Mailer":"git-send-email 2.21.0","In-Reply-To":"<20190527001543.13593-1-niklas.soderlund@ragnatech.se>","References":"<20190527001543.13593-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 05/17] libcamera: formats: Add\n\tV4L2DeviceFormats and V4L2DeviceFormats","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, 27 May 2019 00:16:08 -0000"},"content":"Add two new objects to hold v4l2 format information for v4l2 devices and\nsubdevices. There is much code which can be shared between the two so\nhave both of them inherit from a base class to reduce code duplication.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/libcamera/formats.cpp       | 158 ++++++++++++++++++++++++++++++++\n src/libcamera/include/formats.h |  35 +++++++\n 2 files changed, 193 insertions(+)","diff":"diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp\nindex 56f4ddb51ffad4d3..f5841b38cea5686c 100644\n--- a/src/libcamera/formats.cpp\n+++ b/src/libcamera/formats.cpp\n@@ -24,4 +24,162 @@ namespace libcamera {\n  * resolutions represented by SizeRange items.\n  */\n \n+\n+/**\n+ * \\class DeviceFormats\n+ * \\brief Base class for V4L2Device and V4L2SubDevice Formats\n+ *\n+ * The base class holds common functionallity between V4L2DeviceFormats and\n+ * V4L2SubDeviceForamts.\n+ *\n+ * \\sa V4L2DeviceFormats\n+ * \\sa V4L2SubDeviceForamts\n+ */\n+\n+/**\n+ * \\brief Create an empty DeviceFormats\n+ */\n+DeviceFormats::DeviceFormats()\n+{\n+}\n+\n+/**\n+ * \\brief Create a DeviceFormats with data\n+ */\n+DeviceFormats::DeviceFormats(const std::map<unsigned int, std::vector<SizeRange>> &data)\n+\t: data_(data)\n+{\n+}\n+\n+DeviceFormats::~DeviceFormats()\n+{\n+}\n+\n+/**\n+ * \\brief Retrieve all sizes for a specific format\n+ * \\param[in] format A pixelformat or mbus code\n+ *\n+ * Retrieves all SizeRanges for a specific format. For V4L2Device \\a format is a\n+ * pixelformoat while for a V4L2Subdevice \\a format is a media bus code.\n+ *\n+ * \\return List of SizeRanges for \\a format, empty list if format is not valid\n+ */\n+std::vector<SizeRange> DeviceFormats::sizes(unsigned int format) const\n+{\n+\tauto const &it = data_.find(format);\n+\tif (it == data_.end())\n+\t\treturn {};\n+\n+\treturn it->second;\n+}\n+\n+/**\n+ * \\brief Check if the device formats is empty\n+ * \\return True if the formats are empty\n+ */\n+bool DeviceFormats::empty() const\n+{\n+\treturn data_.empty();\n+}\n+\n+/**\n+ * \\brief Retrieve the raw dataA\n+ * \\return Raw map containgin formats to SizeRanges\n+ */\n+const std::map<unsigned int, std::vector<SizeRange>> &DeviceFormats::data()\n+{\n+\treturn data_;\n+}\n+\n+/**\n+ * \\brief Retrieve a list all contained formats\n+ *\n+ * This is a helper function intended to be used by V4L2DeviceFormats and\n+ * V4L2SubdeviceFormats.\n+ *\n+ * \\return A list of formats contained\n+ */\n+std::vector<unsigned int> DeviceFormats::formats() const\n+{\n+\tstd::vector<unsigned int> formats;\n+\n+\tfor (auto const &it : data_)\n+\t\tformats.push_back(it.first);\n+\n+\treturn formats;\n+}\n+\n+/**\n+ * \\var DeviceFormats::data_\n+ * \\brief The map holding format and SizeRange information\n+ */\n+\n+/**\n+ * \\class V4L2SubdeviceFormats\n+ * \\brief Holds media bus codes to frame sizes information for a v4l2 subdevice\n+ *\n+ * Hold media bus codes and frame sizes which describes a v4l2 subdevice. The\n+ * intended user of this object is pipeline handlers which can create it\n+ * from a V4L2Subdevice and use it to describe and validate formats.\n+ */\n+\n+/**\n+ * \\brief Create an empty V4L2SubdeviceFormats\n+ */\n+V4L2SubdeviceFormats::V4L2SubdeviceFormats()\n+\t: DeviceFormats()\n+{\n+}\n+\n+/**\n+ * \\brief Create an V4L2SubdeviceFormats with data\n+ */\n+V4L2SubdeviceFormats::V4L2SubdeviceFormats(const std::map<unsigned int, std::vector<SizeRange>> &data)\n+\t: DeviceFormats(data)\n+{\n+}\n+\n+/**\n+ * \\brief Retrieve media bus codes which are described\n+ * \\return List of media bus codes\n+ */\n+std::vector<unsigned int> V4L2SubdeviceFormats::codes() const\n+{\n+\treturn formats();\n+}\n+\n+/**\n+ * \\class V4L2DeviceFormats\n+ * \\brief Holds pixelformats to frame sizes information for a v4l2 device\n+ *\n+ * Hold pixelformats and frame sizes which describes a v4l2 device. The\n+ * intended user of this object is pipeline handlers which can create it\n+ * from a V4L2Device and use it to describe and validate formats.\n+ */\n+\n+/**\n+ * \\brief Create an empty V4L2DeviceFormats\n+ */\n+V4L2DeviceFormats::V4L2DeviceFormats()\n+\t: DeviceFormats()\n+{\n+}\n+\n+/**\n+ * \\brief Create an V4L2DeviceFormats with data\n+ */\n+V4L2DeviceFormats::V4L2DeviceFormats(const std::map<unsigned int, std::vector<SizeRange>> &data)\n+\t: DeviceFormats(data)\n+{\n+}\n+\n+/**\n+ * \\brief Retrieve pixelformats which are described\n+ * \\return List of pixelformats\n+ */\n+std::vector<unsigned int> V4L2DeviceFormats::pixelformats() const\n+{\n+\treturn formats();\n+}\n+\n } /* namespace libcamera */\ndiff --git a/src/libcamera/include/formats.h b/src/libcamera/include/formats.h\nindex a73772b1eda068b4..372f6e6d71b236dd 100644\n--- a/src/libcamera/include/formats.h\n+++ b/src/libcamera/include/formats.h\n@@ -17,6 +17,41 @@ namespace libcamera {\n \n typedef std::map<unsigned int, std::vector<SizeRange>> FormatEnum;\n \n+class DeviceFormats\n+{\n+public:\n+\tvirtual ~DeviceFormats();\n+\n+\tstd::vector<SizeRange> sizes(unsigned int format) const;\n+\tbool empty() const;\n+\tconst std::map<unsigned int, std::vector<SizeRange>> &data();\n+\n+protected:\n+\tDeviceFormats();\n+\tDeviceFormats(const std::map<unsigned int, std::vector<SizeRange>> &data);\n+\tstd::vector<unsigned int> formats() const;\n+\n+\tstd::map<unsigned int, std::vector<SizeRange>> data_;\n+};\n+\n+class V4L2SubdeviceFormats : public DeviceFormats\n+{\n+public:\n+\tV4L2SubdeviceFormats();\n+\tV4L2SubdeviceFormats(const std::map<unsigned int, std::vector<SizeRange>> &data);\n+\n+\tstd::vector<unsigned int> codes() const;\n+};\n+\n+class V4L2DeviceFormats : public DeviceFormats\n+{\n+public:\n+\tV4L2DeviceFormats();\n+\tV4L2DeviceFormats(const std::map<unsigned int, std::vector<SizeRange>> &data);\n+\n+\tstd::vector<unsigned int> pixelformats() const;\n+};\n+\n } /* namespace libcamera */\n \n #endif /* __LIBCAMERA_FORMATS_H__ */\n","prefixes":["libcamera-devel","05/17"]}