Patch Detail
Show a patch.
GET /api/patches/1332/?format=api
{ "id": 1332, "url": "https://patchwork.libcamera.org/api/patches/1332/?format=api", "web_url": "https://patchwork.libcamera.org/patch/1332/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/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": "<20190602130435.18780-4-jacopo@jmondi.org>", "date": "2019-06-02T13:04:32", "name": "[libcamera-devel,3/6] libcamera: Add V4L2Controls", "commit_ref": null, "pull_url": null, "state": "accepted", "archived": false, "hash": "6563200da5bde26336f7f0cf071ab4b43786b5e6", "submitter": { "id": 3, "url": "https://patchwork.libcamera.org/api/people/3/?format=api", "name": "Jacopo Mondi", "email": "jacopo@jmondi.org" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/1332/mbox/", "series": [ { "id": 333, "url": "https://patchwork.libcamera.org/api/series/333/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=333", "date": "2019-06-02T13:04:29", "name": "libcamera: v4l2_controls: Add support for V4L2 controls", "version": 1, "mbox": "https://patchwork.libcamera.org/series/333/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/1332/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/1332/checks/", "tags": {}, "headers": { "Return-Path": "<jacopo@jmondi.org>", "Received": [ "from relay11.mail.gandi.net (relay11.mail.gandi.net\n\t[217.70.178.231])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 16A2760BFA\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 2 Jun 2019 15:03:47 +0200 (CEST)", "from uno.homenet.telecomitalia.it (unknown [79.35.79.123])\n\t(Authenticated sender: jacopo@jmondi.org)\n\tby relay11.mail.gandi.net (Postfix) with ESMTPSA id EE40C100005;\n\tSun, 2 Jun 2019 13:03:45 +0000 (UTC)" ], "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Sun, 2 Jun 2019 15:04:32 +0200", "Message-Id": "<20190602130435.18780-4-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.21.0", "In-Reply-To": "<20190602130435.18780-1-jacopo@jmondi.org>", "References": "<20190602130435.18780-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH 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": "Sun, 02 Jun 2019 13:03:47 -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 | 147 +++++++++++++\n src/libcamera/meson.build | 1 +\n src/libcamera/v4l2_controls.cpp | 301 ++++++++++++++++++++++++++\n 3 files changed, 449 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..df955c2e10b2\n--- /dev/null\n+++ b/src/libcamera/include/v4l2_controls.h\n@@ -0,0 +1,147 @@\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_CONTROL_H__\n+#define __LIBCAMERA_V4L2_CONTROL_H__\n+\n+#include <cstring>\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 memvalue_; }\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\tmemvalue_ = 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\tmemvalue_ = static_cast<T *>(new T[size]);\n+\t\tmemcpy(memvalue_, value, size);\n+\t}\n+\n+\t~V4L2ControlValue()\n+\t{\n+\t\tdelete[] memvalue_;\n+\t}\n+\n+private:\n+\tT value_;\n+\tT *memvalue_;\n+};\n+\n+class V4L2IntControl : public V4L2ControlValue<int32_t>\n+{\n+public:\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+public:\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+public:\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+public:\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+public:\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+public:\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+public:\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+}; /* namespace libcamera */\n+\n+#endif /* __LIBCAMERA_V4L2_CONTROL_H__ */\n+\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..f50f3cdfa7d7\n--- /dev/null\n+++ b/src/libcamera/v4l2_controls.cpp\n@@ -0,0 +1,301 @@\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+/**\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 'setControl()' operation call or\n+ * retrieved with a '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+ * matrixes, 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, to match\n+ * the V4L2 extended controls framework, but also provides operations to get\n+ * and set single controls. The interface to set and get control is implemented\n+ * by the V4L2Base class, while this file only provides the data type\n+ * definitions.\n+ *\n+ * The Libcamera V4L2 control framework data types 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 in the\n+ * standard library provided containers.\n+ *\n+ * A parametric derived class V4L2ControlValue stores the control's value and\n+ * provide accessors to the value itself for control with no payload, or to the\n+ * memory area that contains the control's data payload. This class is not\n+ * intended to be directly used and cannot be constructed, but it is used\n+ * instead to define specialized derived classes which specialize the control's\n+ * data value type.\n+ *\n+ * In order to set and get controls, user of the Libcamera V4L2 control\n+ * framework should create instances of the specialized derived classes,\n+ * which are publicly constructible, and use them to access the control's data\n+ * content using the 'value()' method for controls with no payload, or\n+ * retrieving reference to the memory location that contains the data payload\n+ * with the 'mem()' operation for controls which transport a data payload.\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+ * instantiating one of the provided specialized derived classes.\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 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+ * Access a control's value by calling the value() operation on instances\n+ * of the specialized derived classes.\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. Access the memory\n+ * location of the control's data by calling the mem() operation on instances\n+ * of the specialized derived classes.\n+ */\n+\n+/**\n+ * \\class V4L2IntControl\n+ * \\brief Specialized V4L2Control class that handles controls of\n+ * V4L2_CTRL_TYPE_INTEGER type.\n+ *\n+ * Access the control's data value by using the value() operation.\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 the control's data value by using the value() operation.\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+ * Access the control's data value by using the value() operation.\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 the control's data value by using the value() operation.\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 the control's data value by using the retrieving the memory location\n+ * where the data payload is stored with the mem() operation. The size of\n+ * the payload data can be retrieved with the size() 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 the control's data value by using the retrieving the memory location\n+ * where the data payload is stored with the mem() operation. The size of\n+ * the payload data can be retrieved with the size() 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 the control's data value by using the retrieving the memory location\n+ * where the data payload is stored with the mem() operation. The size of\n+ * the payload data can be retrieved with the size() 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+}; /* namespace libcamera */\n", "prefixes": [ "libcamera-devel", "3/6" ] }