Patch Detail
Show a patch.
GET /api/1.1/patches/1384/?format=api
{ "id": 1384, "url": "https://patchwork.libcamera.org/api/1.1/patches/1384/?format=api", "web_url": "https://patchwork.libcamera.org/patch/1384/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20190610164052.30741-4-jacopo@jmondi.org>", "date": "2019-06-10T16:40:49", "name": "[libcamera-devel,v2,3/6] libcamera: Add V4L2Controls", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "e0643a06b87a43e468840577125f190aca953dd3", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/1.1/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/1384/mbox/", "series": [ { "id": 344, "url": "https://patchwork.libcamera.org/api/1.1/series/344/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=344", "date": "2019-06-10T16:40:46", "name": "Add support for V4L2 Controls", "version": 2, "mbox": "https://patchwork.libcamera.org/series/344/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/1384/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/1384/checks/", "tags": {}, "headers": { "Return-Path": "<jacopo@jmondi.org>", "Received": [ "from relay10.mail.gandi.net (relay10.mail.gandi.net\n\t[217.70.178.230])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 7F35D635E9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 10 Jun 2019 18:39:47 +0200 (CEST)", "from uno.lan (2-224-242-101.ip172.fastwebnet.it [2.224.242.101])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay10.mail.gandi.net (Postfix) with ESMTPSA id DE2DA24000B;\n\tMon, 10 Jun 2019 16:39:46 +0000 (UTC)" ], "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 10 Jun 2019 18:40:49 +0200", "Message-Id": "<20190610164052.30741-4-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.21.0", "In-Reply-To": "<20190610164052.30741-1-jacopo@jmondi.org>", "References": "<20190610164052.30741-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 3/6] libcamera: Add V4L2Controls", "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, 10 Jun 2019 16:39:48 -0000" }, "content": "Add Libcamera V4L2 control support, implemented using the V4L2 Extended\nControl APIs. This patch defines the types used to define and manage controls.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/include/v4l2_controls.h | 210 +++++++++\n src/libcamera/meson.build | 1 +\n src/libcamera/v4l2_controls.cpp | 632 ++++++++++++++++++++++++++\n 3 files changed, 843 insertions(+)\n create mode 100644 src/libcamera/include/v4l2_controls.h\n create mode 100644 src/libcamera/v4l2_controls.cpp", "diff": "diff --git a/src/libcamera/include/v4l2_controls.h b/src/libcamera/include/v4l2_controls.h\nnew file mode 100644\nindex 000000000000..bca5ccc29de3\n--- /dev/null\n+++ b/src/libcamera/include/v4l2_controls.h\n@@ -0,0 +1,210 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * v4l2_controls.h - V4L2 Extended Control Support\n+ */\n+\n+#ifndef __LIBCAMERA_V4L2_CONTROLS_H__\n+#define __LIBCAMERA_V4L2_CONTROLS_H__\n+\n+#include <cstring>\n+#include <string>\n+#include <vector>\n+\n+#include <stdint.h>\n+\n+#include <linux/v4l2-controls.h>\n+#include <linux/videodev2.h>\n+\n+namespace libcamera {\n+\n+class V4L2Control\n+{\n+public:\n+\tvirtual ~V4L2Control()\n+\t{\n+\t}\n+\n+\tunsigned int id() { return id_; }\n+\tunsigned int size() { return size_; }\n+\tenum v4l2_ctrl_type type() const { return type_; }\n+\n+protected:\n+\tV4L2Control(unsigned int id, unsigned int size,\n+\t\t enum v4l2_ctrl_type type)\n+\t\t: id_(id), size_(size), type_(type)\n+\t{\n+\t}\n+\n+private:\n+\tunsigned int id_;\n+\tunsigned int size_;\n+\tenum v4l2_ctrl_type type_;\n+};\n+\n+template<typename T>\n+class V4L2ControlValue : public V4L2Control\n+{\n+public:\n+\tT value() const { return value_; }\n+\tT *mem() const { return mem_; }\n+\n+protected:\n+\tV4L2ControlValue(unsigned int id, unsigned int size,\n+\t\t\t enum v4l2_ctrl_type type, T value)\n+\t\t: V4L2Control(id, size, type)\n+\t{\n+\t\tvalue_ = value;\n+\t\tmem_ = nullptr;\n+\t}\n+\n+\tV4L2ControlValue(unsigned int id, unsigned int size,\n+\t\t\t enum v4l2_ctrl_type type, T *value)\n+\t\t: V4L2Control(id, size, type)\n+\t{\n+\t\tvalue_ = 0;\n+\t\tmem_ = static_cast<T *>(new T[size]);\n+\t\tmemcpy(mem_, value, size);\n+\t}\n+\n+\t~V4L2ControlValue()\n+\t{\n+\t\tdelete[] mem_;\n+\t}\n+\n+private:\n+\tT value_;\n+\tT *mem_;\n+};\n+\n+class V4L2IntControl : public V4L2ControlValue<int32_t>\n+{\n+private:\n+\tfriend class V4L2Controls;\n+\n+\tV4L2IntControl(unsigned int id, int32_t value)\n+\t\t: V4L2ControlValue<int32_t>(id, sizeof(int32_t),\n+\t\t\t\t\t V4L2_CTRL_TYPE_INTEGER, value)\n+\t{\n+\t}\n+};\n+\n+class V4L2Int64Control : public V4L2ControlValue<int64_t>\n+{\n+private:\n+\tfriend class V4L2Controls;\n+\n+\tV4L2Int64Control(unsigned int id, int64_t value)\n+\t\t: V4L2ControlValue<int64_t>(id, sizeof(int64_t),\n+\t\t\t\t\t V4L2_CTRL_TYPE_INTEGER64, value)\n+\t{\n+\t}\n+};\n+\n+class V4L2BoolControl : public V4L2ControlValue<bool>\n+{\n+private:\n+\tfriend class V4L2Controls;\n+\n+\tV4L2BoolControl(unsigned int id, bool value)\n+\t\t: V4L2ControlValue<bool>(id, sizeof(bool),\n+\t\t\t\t\t V4L2_CTRL_TYPE_BOOLEAN, value)\n+\t{\n+\t}\n+};\n+\n+class V4L2StringControl : public V4L2ControlValue<std::string>\n+{\n+private:\n+\tfriend class V4L2Controls;\n+\n+\tV4L2StringControl(unsigned int id, std::string value)\n+\t\t: V4L2ControlValue<std::string>(id, value.length(),\n+\t\t\t\t\t\tV4L2_CTRL_TYPE_STRING, value)\n+\t{\n+\t}\n+};\n+\n+class V4L2U8Control : public V4L2ControlValue<uint8_t>\n+{\n+private:\n+\tfriend class V4L2Controls;\n+\n+\tV4L2U8Control(unsigned int id, unsigned int size, uint8_t *mem)\n+\t\t: V4L2ControlValue<uint8_t>(id, size, V4L2_CTRL_TYPE_U8, mem)\n+\t{\n+\t}\n+};\n+\n+class V4L2U16Control : public V4L2ControlValue<uint16_t>\n+{\n+private:\n+\tfriend class V4L2Controls;\n+\n+\tV4L2U16Control(unsigned int id, unsigned int size, uint16_t *mem)\n+\t\t: V4L2ControlValue<uint16_t>(id, size, V4L2_CTRL_TYPE_U16, mem)\n+\t{\n+\t}\n+};\n+\n+class V4L2U32Control : public V4L2ControlValue<uint32_t>\n+{\n+private:\n+\tfriend class V4L2Controls;\n+\n+\tV4L2U32Control(unsigned int id, unsigned int size, uint32_t *mem)\n+\t\t: V4L2ControlValue<uint32_t>(id, size, V4L2_CTRL_TYPE_U32, mem)\n+\t{\n+\t}\n+};\n+\n+class V4L2Controls {\n+public:\n+\t~V4L2Controls()\n+\t{\n+\t\tclear();\n+\t}\n+\n+\tusing iterator = std::vector<V4L2Control *>::iterator;\n+\tusing const_iterator = std::vector<V4L2Control *>::const_iterator;\n+\n+\titerator begin() { return controls_.begin(); }\n+\tconst_iterator begin() const { return controls_.begin(); }\n+\titerator end() { return controls_.end(); }\n+\tconst_iterator end() const { return controls_.end(); }\n+\n+\tsize_t size() { return controls_.size(); }\n+\tvoid clear();\n+\n+\tV4L2Control *operator[](unsigned int index) const\n+\t{\n+\t\treturn controls_[index];\n+\t}\n+\n+\tbool empty() const { return controls_.size() == 0; }\n+\n+\tvoid set(unsigned int id, unsigned int value);\n+\tvoid set(unsigned int id, int32_t value);\n+\tvoid set(unsigned int id, int64_t value);\n+\tvoid set(unsigned int id, bool value);\n+\tvoid set(unsigned int id, std::string value);\n+\tvoid set(unsigned int id, size_t size, uint8_t *value);\n+\tvoid set(unsigned int id, size_t size, uint16_t *value);\n+\tvoid set(unsigned int id, size_t size, uint32_t *value);\n+\n+\tint32_t getInt(unsigned int id);\n+\tint64_t getInt64(unsigned int id);\n+\tbool getBool(unsigned int id);\n+\tstd::string getString(unsigned int id);\n+\tuint8_t *getU8(unsigned int id);\n+\tuint16_t *getU16(unsigned int id);\n+\tuint32_t *getU32(unsigned int id);\n+\n+private:\n+\tstd::vector<V4L2Control *> controls_;\n+};\n+\n+}; /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_V4L2_CONTROLS_H__ */\ndiff --git a/src/libcamera/meson.build b/src/libcamera/meson.build\nindex 6d858a22531e..fa1fbcb5faf5 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -22,6 +22,7 @@ libcamera_sources = files([\n 'timer.cpp',\n 'utils.cpp',\n 'v4l2_base.cpp',\n+ 'v4l2_controls.cpp',\n 'v4l2_device.cpp',\n 'v4l2_subdevice.cpp',\n ])\ndiff --git a/src/libcamera/v4l2_controls.cpp b/src/libcamera/v4l2_controls.cpp\nnew file mode 100644\nindex 000000000000..bd68d07f37bf\n--- /dev/null\n+++ b/src/libcamera/v4l2_controls.cpp\n@@ -0,0 +1,632 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * v4l2_controls.cpp - V4L2 Extended Control Support\n+ */\n+\n+#include \"v4l2_controls.h\"\n+\n+/**\n+ * \\file v4l2_controls.h\n+ * \\brief Support for V4L2 Controls using the V4L2 Extended Controls APIs.\n+ *\n+ * The V4L2 defined \"Control API\" allows application to inspect and modify set\n+ * of configurable parameters on the video device or subdevice of interest. The\n+ * nature of the parameters an application could modify using the control\n+ * framework depends on what the driver implements support for, and on the\n+ * characteristics of the underlying hardware platform. Generally controls are\n+ * used to modify user visible settings, such as the image brightness and\n+ * exposure time, or non-standard parameters which cannot be controlled through\n+ * the V4L2 format negotiation API.\n+ *\n+ * Controls are identified by a numerical id, defined by the V4L2 kernel headers\n+ * and have an associated type and class. Each control has a 'value', which is\n+ * the data that can be modified with a 'V4L2Base::setControl()' operation call\n+ * or retrieved with a 'V4L2Base::getControl()' one.\n+ *\n+ * A control class defines the control purpose while its type (along with the\n+ * control's flags) defines the type of the control's value content. Controls\n+ * might transport a single data value stored in variable inside the control, or\n+ * they might as well deal with more complex data types, such as arrays of\n+ * matrices, stored in a contiguous memory locations associated with the control\n+ * and called 'the payload'. The content have to be opportunely copied into the\n+ * application memory when retrieving a control's value and provided to the V4L2\n+ * device when setting it.\n+ *\n+ * Libcamera supports control using the V4L2 'Extended Control' framework, which\n+ * allows easier handling of controls with payloads of arbitrary sizes.\n+ *\n+ * The Libcamera V4L2 Controls framework operates on lists of controls, wrapped\n+ * by the V4L2Controls class, to match the V4L2 extended controls framework.\n+ * The interface to set and get control is implemented by the V4L2Base class,\n+ * while this file only provides the data type definitions.\n+ *\n+ * The Libcamera V4L2 control framework define a base class\n+ * V4L2Control that contains the fields common to all controls, regardless of\n+ * their type, such as the control's id, its type and the expected control's\n+ * value data size. The V4L2Control class is not meant to be instantiated\n+ * directly, but is instead used as placeholder to store controls inside the\n+ * publicly constructible V4L2Controls class.\n+ *\n+ * A parametric derived class V4L2ControlValue stores the control's value and\n+ * provide accessors to the data values for controls with no payload, or to the\n+ * memory area that contains the control's data payload. These classes are not\n+ * intended to be directly used and cannot be constructed, but are used instead\n+ * to define specialized derived classes which provide accessors to the\n+ * control's data values.\n+ *\n+ * In order to set and get controls, user of the Libcamera V4L2 control\n+ * framework should operate on instances of the V4L2Controls class, iterating\n+ * on the V4L2Controls it contains, and use the V4L2Controls::set() and\n+ * V4L2Controls::get() methods to set or access the control's data\n+ * content.\n+ *\n+ * \\todo Support setting controls with data payload.\n+ */\n+\n+namespace libcamera {\n+\n+/**\n+ * \\class V4L2Control\n+ * \\brief Base class for V4L2 Controls\n+ *\n+ * The V4L2Control base class is the base class that contains the fields common\n+ * to all controls (id, type and size).\n+ *\n+ * This class is not meant to be instantiated directly, but is instead used as a\n+ * place holder to store controls in arrays or other containers. User of the\n+ * libcamera V4L2 control framework should access the controls content by\n+ * using accessors provided by the V4L2Controls class.\n+ */\n+\n+/**\n+ * \\fn V4L2Control::V4L2Control\n+ * \\brief Construct a V4L2Control instance\n+ * \\param id The control's id\n+ * \\param size The control's data size\n+ * \\param type The control's type\n+ */\n+\n+/**\n+ * \\fn V4L2Control::id()\n+ * \\brief Retrieve the control's id\n+ *\n+ * Retrieve the control's numerical id value as defined by the V4L2\n+ * specification.\n+ *\n+ * \\return The control's id\n+ */\n+\n+/**\n+ * \\fn V4L2Control::size()\n+ * \\brief Retrieve the control's data value size in bytes\n+ *\n+ * \\todo Better define the value of size() for controls with payload data.\n+ *\n+ * \\return The control's size\n+ */\n+\n+/**\n+ * \\fn V4L2Control::type()\n+ * \\brief Retrieve the control's type\n+ *\n+ * Retrieve the control's type as defined by the V4L2 specification.\n+ *\n+ * \\return The control's type\n+ */\n+\n+/**\n+ * \\class V4L2ControlValue\n+ * \\brief Template base class that represent values of a V4L2 control\n+ *\n+ * The V4L2ControlValue template base class represents a V4L2 control with\n+ * its different value types.\n+ *\n+ * It provides two operations to access the control's value or the pointer\n+ * to the memory location that contains to the control's value data payload.\n+ */\n+\n+/**\n+ * \\fn V4L2ControlValue::V4L2ControlValue(unsigned int id, unsigned int size, enum v4l2_ctrl_type type, T value)\n+ * \\brief Contruct a V4L2ControlValue with a parametric value\n+ * \\param id The control's id\n+ * \\param size The control's size\n+ * \\param type The control's type\n+ * \\param value The control's value\n+ */\n+\n+/**\n+ * \\fn V4L2ControlValue::V4L2ControlValue(unsigned int id, unsigned int size, enum v4l2_ctrl_type type, T* value)\n+ * \\brief Contruct a V4L2ControlValue with a pointer to a data payload\n+ * \\param id The control's id\n+ * \\param size The control's size\n+ * \\param type The control's type\n+ * \\param value The pointer to the control's data payload\n+ */\n+\n+/**\n+ * \\fn V4L2ControlValue::~V4L2ControlValue\n+ * \\brief Release the memory reserved for the control's data payload, if any\n+ */\n+\n+/**\n+ * \\fn V4L2ControlValue::value()\n+ * \\brief Retrieve the control's value\n+ *\n+ * Retrieve the control's value. Valid only for controls with no payload.\n+ */\n+\n+/**\n+ * \\fn V4L2ControlValue::mem()\n+ * \\brief Retrieve a pointer to the memory location of the control's data\n+ *\n+ * Retrieve a pointer to the memory location that contains the control's data\n+ * payload. Valid only for controls with data payload.\n+ */\n+\n+/**\n+ * \\class V4L2IntControl\n+ * \\brief Specialized V4L2Control class that handles controls of\n+ * V4L2_CTRL_TYPE_INTEGER type.\n+ *\n+ * Access to the control's data value by using the value() operation is\n+ * restricted to the proxy V4L2Controls class.\n+ */\n+\n+/**\n+ * \\fn V4L2IntControl::V4L2IntControl()\n+ * \\brief Construct a V4L2Control that contains an int value\n+ * \\param id The control's id\n+ * \\param value The control's value\n+ */\n+\n+/**\n+ * \\class V4L2Int64Control\n+ * \\brief Specialized V4L2Control class that handles controls of\n+ * V4L2_CTRL_TYPE_INTEGER64 type.\n+ *\n+ * Access to the control's data value by using the value() operation is\n+ * restricted to the proxy V4L2Controls class.\n+ */\n+\n+/**\n+ * \\fn V4L2Int64Control::V4L2Int64Control()\n+ * \\brief Construct a V4L2Control that contains an int64 value\n+ * \\param id The control's id\n+ * \\param value The control's value\n+ */\n+\n+/**\n+ * \\class V4L2BoolControl\n+ * \\brief Specialized V4L2Control class that handles controls of\n+ * V4L2_CTRL_TYPE_BOOLEAN type.\n+ *\n+ *\n+ * Access to the control's data value by using the value() operation is\n+ * restricted to the proxy V4L2Controls class.\n+ */\n+\n+/**\n+ * \\fn V4L2BoolControl::V4L2BoolControl()\n+ * \\brief Construct a V4L2Control that contains a boolean value\n+ * \\param id The control's id\n+ * \\param value The control's value\n+ */\n+\n+/**\n+ * \\class V4L2StringControl\n+ * \\brief Specialized V4L2Control class that handles controls of\n+ * V4L2_CTRL_TYPE_STRING type.\n+ *\n+ * Access to the control's data value by using the value() operation is\n+ * restricted to the proxy V4L2Controls class.\n+ */\n+\n+/**\n+ * \\fn V4L2StringControl::V4L2StringControl()\n+ * \\brief Construct a V4L2Control that contains a string value\n+ * \\param id The control's id\n+ * \\param value The control's value\n+ */\n+\n+/**\n+ * \\class V4L2U8Control\n+ * \\brief Specialized V4L2Control class that handles controls with payload of\n+ * V4L2_CTRL_TYPE_U8 type.\n+ *\n+ * Access to the control's mem() operation is reserved to the V4L2Controls\n+ * proxy class. The size of the payload data can be retrieved with the size()\n+ * operation.\n+ */\n+\n+/**\n+ * \\fn V4L2U8Control::V4L2U8Control()\n+ * \\brief Construct a V4L2Control with payload of uin8_t data\n+ * \\param id The control's id\n+ * \\param size The size in bytes of the payload content\n+ * \\param mem Pointer to the memory location of the payload content\n+ *\n+ * Memory is reserved in the newly created instance to hold the data payload\n+ * and the data content is copied there. The reserved memory is then freed when\n+ * the Control is destroyed. The memory where the control's payload was copied\n+ * from should be released by the caller.\n+ */\n+\n+/**\n+ * \\class V4L2U16Control\n+ * \\brief Specialized V4L2Control class that handles controls with payload of\n+ * V4L2_CTRL_TYPE_U16 type.\n+ *\n+ * Access to the control's mem() operation is reserved to the V4L2Controls\n+ * proxy class. The size of the payload data can be retrieved with the size()\n+ * operation.\n+ */\n+\n+/**\n+ * \\fn V4L2U16Control::V4L2U16Control(unsigned int id, unsigned int size, uint16_t *mem)\n+ * \\brief Construct a V4L2Control with payload of uin16_t data\n+ * \\param id The control's id\n+ * \\param size The size in bytes of the payload content\n+ * \\param mem Pointer to the memory location of the payload content\n+ *\n+ * Memory is reserved in the newly created instance to hold the data payload\n+ * and the data content is copied there. The reserved memory is then freed when\n+ * the Control is destroyed. The memory where the control's payload was copied\n+ * from should be released by the caller.\n+ */\n+\n+/**\n+ * \\class V4L2U32Control\n+ * \\brief Specialized V4L2Control class that handles controls with payload of\n+ * V4L2_CTRL_TYPE_U32 type.\n+ *\n+ * Access to the control's mem() operation is reserved to the V4L2Controls\n+ * proxy class. The size of the payload data can be retrieved with the size()\n+ * operation.\n+ */\n+\n+/**\n+ * \\fn V4L2U32Control::V4L2U32Control(unsigned int id, unsigned int size, uint32_t *mem)\n+ * \\brief Construct a V4L2Control with payload of uin32_t data\n+ * \\param id The control's id\n+ * \\param size The size in bytes of the payload content\n+ * \\param mem Pointer to the memory location of the payload content\n+ *\n+ * Memory is reserved in the newly created instance to hold the data payload\n+ * and the data content is copied there. The reserved memory is then freed when\n+ * the Control is destroyed. The memory where the control's payload was copied\n+ * from should be released by the caller.\n+ */\n+\n+/**\n+ * \\class V4L2Controls\n+ * \\brief Wraps a list of V4L2Control and provide accessors to each control's\n+ * data\n+ *\n+ * The V4L2Controls class works as a wrapper for a list of V4L2Control\n+ * instances. The class provides operations to add a new control (set()) and\n+ * to get back it's content.\n+ *\n+ * User of the Libcamera V4L2 control framework which want to set controls on\n+ * a video device or subdevice should create instances of the V4L2Controls\n+ * class and start filling it with control values. Once ready the instance\n+ * should be passed to the V4L2Base::setControls() operation, that applies the\n+ * control values to the underlying hardware.\n+ *\n+ * When reading control, a V4L2Controls instance is passed to the\n+ * V4L2Base::getControls() operation, along with a list of control IDs, and it\n+ * filled by the V4L2Base operation with V4L2Control instances, the user can\n+ * access by ID using on the provided V4L2Controls::get() operations.\n+ */\n+\n+/**\n+ * \\fn V4L2Controls::~V4L2Controls()\n+ * \\brief Destroy all V4L2Control stored in the instance\n+ *\n+ * \\sa V4L2Controls::clear()\n+ */\n+\n+/**\n+ * \\typedef V4L2Controls::iterator\n+ * \\brief Iterator on the V4L2 controls contained in the V4L2Controls\n+ */\n+\n+/**\n+ * \\typedef CameraConfiguration::const_iterator\n+ * \\brief Const iterator on the V4L2 controls contained in the V4L2Controls\n+ */\n+\n+/**\n+ * \\fn V4L2Controls::begin\n+ * \\brief Retrieve an iterator to the first V4L2Control in the sequence\n+ * \\return An iterator to the first V4L2 control\n+ */\n+\n+/**\n+ * \\fn iterator V4L2Controls::begin()\n+ * \\brief Retrieve an iterator to the first V4L2Control in the sequence\n+ * \\return An iterator to the first V4L2 control\n+ */\n+\n+/**\n+ * \\fn const_iterator V4L2Controls::begin() const\n+ * \\brief Retrieve a constant iterator to the first V4L2Control in the sequence\n+ * \\return A constant iterator to the first V4L2 control\n+ */\n+\n+/**\n+ * \\fn iterator V4L2Controls::end()\n+ * \\brief Retrieve an iterator pointing to the past-the-end V4L2Control in the\n+ * sequence\n+ * \\return An iterator to the element following the last V4L2 control in the\n+ * sequence\n+ */\n+\n+/**\n+ * \\fn const_iterator V4L2Controls::end() const\n+ * \\brief Retrieve a constant iterator pointing to the past-the-end V4L2Control\n+ * in the sequence\n+ * \\return A constant iterator to the element following the last V4L2 control\n+ * in the sequence\n+ */\n+\n+/**\n+ * \\fn V4L2Controls::size()\n+ * \\brief Retrieve the number on stored controls\n+ * \\return The number of V4L2Control stored in the instance\n+ */\n+\n+/**\n+ * \\brief Destroy each control stored in the instance\n+ *\n+ * Destroy all the V4L2Control instances stored in this V4L2Controls instance.\n+ * Reset the instance size to 0, and release all memory reserved by each\n+ * control.\n+ */\n+void V4L2Controls::clear()\n+{\n+\tfor (unsigned int i = 0; i < controls_.size(); ++i)\n+\t\tdelete controls_[i];\n+\n+\tcontrols_.clear();\n+}\n+\n+/**\n+ * \\fn V4L2Controls::operator[]\n+ * \\brief Access the control at index \\a index\n+ * \\param index The index to access\n+ */\n+\n+/**\n+ * \\fn V4L2Controls::empty()\n+ * \\brief Retrieve if the instance is empty\n+ * \\return True if the instance does not contain any control, false otherwise\n+ */\n+\n+/**\n+ * \\brief Store a new control with integer value\n+ * \\param id The control's id\n+ * \\param value The control's value\n+ */\n+void V4L2Controls::set(unsigned int id, unsigned int value)\n+{\n+\tset(id, static_cast<int32_t>(value));\n+}\n+\n+/**\n+ * \\brief Store a new control with integer value\n+ * \\param id The control's id\n+ * \\param value The control's value\n+ */\n+void V4L2Controls::set(unsigned int id, int32_t value)\n+{\n+\tV4L2IntControl *c = new V4L2IntControl(id, value);\n+\tcontrols_.push_back(c);\n+}\n+\n+/**\n+ * \\brief Store a new control with 64-bit integer value\n+ * \\param id The control's id\n+ * \\param value The control's value\n+ */\n+void V4L2Controls::set(unsigned int id, int64_t value)\n+{\n+\tV4L2Int64Control *c = new V4L2Int64Control(id, value);\n+\tcontrols_.push_back(c);\n+}\n+\n+/**\n+ * \\brief Store a new control with boolean value\n+ * \\param id The control's id\n+ * \\param value The control's value\n+ */\n+void V4L2Controls::set(unsigned int id, bool value)\n+{\n+\tV4L2BoolControl *c = new V4L2BoolControl(id, value);\n+\tcontrols_.push_back(c);\n+}\n+\n+/**\n+ * \\brief Store a new control with string value\n+ * \\param id The control's id\n+ * \\param value The control's value\n+ */\n+void V4L2Controls::set(unsigned int id, std::string value)\n+{\n+\tV4L2StringControl *c = new V4L2StringControl(id, value);\n+\tcontrols_.push_back(c);\n+}\n+\n+/**\n+ * \\brief Store a new control with pointer to payload\n+ * \\param id The control's id\n+ * \\param size The payload size\n+ * \\param value The pointer to the data payload\n+ */\n+void V4L2Controls::set(unsigned int id, size_t size, uint8_t *value)\n+{\n+\tV4L2U8Control *c = new V4L2U8Control(id, size, value);\n+\tcontrols_.push_back(c);\n+}\n+\n+/**\n+ * \\brief Store a new control with pointer to payload\n+ * \\param id The control's id\n+ * \\param size The payload size\n+ * \\param value The pointer to the data payload\n+ */\n+void V4L2Controls::set(unsigned int id, size_t size, uint16_t *value)\n+{\n+\tV4L2U16Control *c = new V4L2U16Control(id, size, value);\n+\tcontrols_.push_back(c);\n+}\n+\n+/**\n+ * \\brief Store a new control with pointer to payload\n+ * \\param id The control's id\n+ * \\param size The payload size\n+ * \\param value The pointer to the data payload\n+ */\n+void V4L2Controls::set(unsigned int id, size_t size, uint32_t *value)\n+{\n+\tV4L2U32Control *c = new V4L2U32Control(id, size, value);\n+\tcontrols_.push_back(c);\n+\n+}\n+\n+/**\n+ * \\brief Retrieve the control's integer value\n+ * \\param id The control's id\n+ * \\return The value of control with \\a id, a negative error code if the control\n+ * does not exist in the instance\n+ */\n+int32_t V4L2Controls::getInt(unsigned int id)\n+{\n+\tfor (V4L2Control *c : controls_) {\n+\t\tif (c->id() != id)\n+\t\t\tcontinue;\n+\n+\t\tV4L2IntControl *ic = static_cast<V4L2IntControl *>(c);\n+\t\treturn ic->value();\n+\t}\n+\n+\treturn -EINVAL;\n+}\n+\n+/**\n+ * \\brief Retrieve the control's 64-bit integer value\n+ * \\param id The control's id\n+ * \\return The value of control with \\a id, a negative error code if the control\n+ * does not exist in the instance\n+ */\n+int64_t V4L2Controls::getInt64(unsigned int id)\n+{\n+\tfor (V4L2Control *c : controls_) {\n+\t\tif (c->id() != id)\n+\t\t\tcontinue;\n+\n+\t\tV4L2Int64Control *ic = static_cast<V4L2Int64Control *>(c);\n+\t\treturn ic->value();\n+\t}\n+\n+\treturn -EINVAL;\n+}\n+\n+/**\n+ * \\brief Retrieve the control's boolean value\n+ * \\param id The control's id\n+ * \\return The value of control with \\a id, false if the control does not exist\n+ * in the instance\n+ */\n+bool V4L2Controls::getBool(unsigned int id)\n+{\n+\tfor (V4L2Control *c : controls_) {\n+\t\tif (c->id() != id)\n+\t\t\tcontinue;\n+\n+\t\tV4L2BoolControl *ic = static_cast<V4L2BoolControl *>(c);\n+\t\treturn ic->value();\n+\t}\n+\n+\treturn false;\n+}\n+\n+/**\n+ * \\brief Retrieve the control's string value\n+ * \\param id The control's id\n+ * \\return The value of control with \\a id, an empty string if the control\n+ * does not exist in the instance\n+ */\n+std::string V4L2Controls::getString(unsigned int id)\n+{\n+\tfor (V4L2Control *c : controls_) {\n+\t\tif (c->id() != id)\n+\t\t\tcontinue;\n+\n+\t\tV4L2StringControl *ic = static_cast<V4L2StringControl *>(c);\n+\t\treturn ic->value();\n+\t}\n+\n+\treturn \"\";\n+}\n+\n+/**\n+ * \\brief Retrieve a pointer to the control's payload\n+ * \\param id The control's id\n+ * \\return A pointer to the control's payload, nullptr if the control\n+ * does not exist in the instance\n+ */\n+uint8_t *V4L2Controls::getU8(unsigned int id)\n+{\n+\tfor (V4L2Control *c : controls_) {\n+\t\tif (c->id() != id)\n+\t\t\tcontinue;\n+\n+\t\tV4L2U8Control *ic = static_cast<V4L2U8Control *>(c);\n+\t\treturn ic->mem();\n+\t}\n+\n+\treturn nullptr;\n+\n+}\n+\n+/**\n+ * \\brief Retrieve a pointer to the control's payload\n+ * \\param id The control's id\n+ * \\return A pointer to the control's payload, nullptr if the control\n+ * does not exist in the instance\n+ */\n+uint16_t *V4L2Controls::getU16(unsigned int id)\n+{\n+\tfor (V4L2Control *c : controls_) {\n+\t\tif (c->id() != id)\n+\t\t\tcontinue;\n+\n+\t\tV4L2U16Control *ic = static_cast<V4L2U16Control *>(c);\n+\t\treturn ic->mem();\n+\t}\n+\n+\treturn nullptr;\n+}\n+\n+/**\n+ * \\brief Retrieve a pointer to the control's payload\n+ * \\param id The control's id\n+ * \\return A pointer to the control's payload, nullptr if the control\n+ * does not exist in the instance\n+ */\n+uint32_t *V4L2Controls::getU32(unsigned int id)\n+{\n+\tfor (V4L2Control *c : controls_) {\n+\t\tif (c->id() != id)\n+\t\t\tcontinue;\n+\n+\t\tV4L2U32Control *ic = static_cast<V4L2U32Control *>(c);\n+\t\treturn ic->mem();\n+\t}\n+\n+\treturn nullptr;\n+}\n+\n+}; /* namespace libcamera */\n", "prefixes": [ "libcamera-devel", "v2", "3/6" ] }