Patch Detail
Show a patch.
GET /api/patches/1484/?format=api
{ "id": 1484, "url": "https://patchwork.libcamera.org/api/patches/1484/?format=api", "web_url": "https://patchwork.libcamera.org/patch/1484/", "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": "<20190620153144.5394-2-jacopo@jmondi.org>", "date": "2019-06-20T15:31:39", "name": "[libcamera-devel,v5,1/6] libcamera: Add V4L2Controls", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "0e7f592409688b4ad264a448b3e5f248fa154b79", "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/1484/mbox/", "series": [ { "id": 368, "url": "https://patchwork.libcamera.org/api/series/368/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=368", "date": "2019-06-20T15:31:38", "name": "Add support for V4L2 controls", "version": 5, "mbox": "https://patchwork.libcamera.org/series/368/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/1484/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/1484/checks/", "tags": {}, "headers": { "Return-Path": "<jacopo@jmondi.org>", "Received": [ "from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net\n\t[217.70.183.193])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 158A960BA1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 20 Jun 2019 17:30:41 +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 relay1-d.mail.gandi.net (Postfix) with ESMTPSA id A402124000A;\n\tThu, 20 Jun 2019 15:30:40 +0000 (UTC)" ], "X-Originating-IP": "2.224.242.101", "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Thu, 20 Jun 2019 17:31:39 +0200", "Message-Id": "<20190620153144.5394-2-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.21.0", "In-Reply-To": "<20190620153144.5394-1-jacopo@jmondi.org>", "References": "<20190620153144.5394-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v5 1/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": "Thu, 20 Jun 2019 15:30:41 -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 | 86 ++++++++\n src/libcamera/meson.build | 1 +\n src/libcamera/v4l2_controls.cpp | 282 ++++++++++++++++++++++++++\n 3 files changed, 369 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..acd23dabd831\n--- /dev/null\n+++ b/src/libcamera/include/v4l2_controls.h\n@@ -0,0 +1,86 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * v4l2_controls.h - V4L2 Controls Support\n+ */\n+\n+#ifndef __LIBCAMERA_V4L2_CONTROLS_H__\n+#define __LIBCAMERA_V4L2_CONTROLS_H__\n+\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 V4L2ControlInfo\n+{\n+public:\n+\tV4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl);\n+\n+\tunsigned int id() const { return id_; }\n+\tunsigned int type() const { return type_; }\n+\tsize_t size() const { return size_; }\n+\tconst std::string &name() const { return name_; }\n+\n+private:\n+\tunsigned int type_;\n+\tstd::string name_;\n+\tunsigned int id_;\n+\tsize_t size_;\n+};\n+\n+class V4L2Control\n+{\n+public:\n+\tV4L2Control(unsigned int id, int value = 0)\n+\t\t: id_(id), value_(value) {}\n+\n+\tint64_t value() const { return value_; }\n+\tvoid setValue(int64_t value) { value_ = value; }\n+\n+\tunsigned int id() const { return id_; }\n+\n+private:\n+\tunsigned int id_;\n+\tint64_t value_;\n+};\n+\n+class V4L2Controls\n+{\n+public:\n+\tV4L2Controls &operator=(const V4L2Controls &) = delete;\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+\tbool empty() const { return controls_.empty(); }\n+\tsize_t size() const { return controls_.size(); }\n+\n+\tvoid reset() { controls_.clear(); }\n+\tvoid add(unsigned int id, int64_t value = 0);\n+\n+\tV4L2Control *operator[](unsigned int index)\n+\t{\n+\t\treturn &controls_[index];\n+\t}\n+\n+\tV4L2Control *getControl(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 f26ad5b2dc57..985aa7e8ab0e 100644\n--- a/src/libcamera/meson.build\n+++ b/src/libcamera/meson.build\n@@ -23,6 +23,7 @@ libcamera_sources = files([\n 'stream.cpp',\n 'timer.cpp',\n 'utils.cpp',\n+ 'v4l2_controls.cpp',\n 'v4l2_device.cpp',\n 'v4l2_subdevice.cpp',\n 'v4l2_videodevice.cpp',\ndiff --git a/src/libcamera/v4l2_controls.cpp b/src/libcamera/v4l2_controls.cpp\nnew file mode 100644\nindex 000000000000..abf596e7f1ef\n--- /dev/null\n+++ b/src/libcamera/v4l2_controls.cpp\n@@ -0,0 +1,282 @@\n+/* SPDX-License-Identifier: LGPL-2.1-or-later */\n+/*\n+ * Copyright (C) 2019, Google Inc.\n+ *\n+ * v4l2_controls.cpp - V4L2 Controls 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. Each control has a value, which is the data\n+ * that can be modified with V4L2Device::setControls() or retrieved with\n+ * V4L2Device::getControls().\n+ *\n+ * The control's type along with the control's flags defines the type of the\n+ * control's value content. Controls might transport a single data value\n+ * stored in variable inside the control, or they might as well deal with more\n+ * complex data types, such as arrays of matrices, stored in a contiguous\n+ * memory locations associated with the control and called 'the payload'. Such\n+ * controls are called 'compound controls' and are currently not supported by\n+ * the libcamera V4L2 control framework.\n+ *\n+ * libcamera implements support for controls using the V4L2 'Extended Control'\n+ * API, which allows future handling of controls with payloads of arbitrary\n+ * sizes.\n+ *\n+ * The libcamera V4L2 Controls framework operates on lists of controls,\n+ * wrapped by the V4L2Controls class, to match the V4L2 extended controls API.\n+ * The interface to set and get control is implemented by the V4L2Device\n+ * class, and this file only provides the data type definitions.\n+ *\n+ * \\todo Add support for compound controls\n+ */\n+\n+namespace libcamera {\n+\n+/**\n+ * \\class V4L2ControlInfo\n+ * \\brief Information on a V4L2 control\n+ *\n+ * The V4L2ControlInfo class represent all the information related to\n+ * a V4L2 control, such as its ID, its type, its user-readable name and the\n+ * expected size of its value data.\n+ *\n+ * V4L2ControlInfo instances are created by inspecting the fieldS of a struct\n+ * v4l2_query_ext_ctrl structure, after it has been filled by the device\n+ * driver as a consequence of a VIDIOC_QUERY_EXT_CTRL ioctl call.\n+ *\n+ * This class does not contain the control value, but only static information\n+ * on the control, which shall be cached by the caller at initialisation time\n+ * or the first time the control information is accessed.\n+ */\n+\n+/**\n+ * \\brief Construct a V4L2ControlInfo from a struct v4l2_query_ext_ctrl\n+ * \\param ctrl The struct v4l2_query_ext_ctrl as returned by the kernel\n+ */\n+V4L2ControlInfo::V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl)\n+{\n+\tid_ = ctrl.id;\n+\ttype_ = ctrl.type;\n+\tname_ = static_cast<const char *>(ctrl.name);\n+\tsize_ = ctrl.elem_size * ctrl.elems;\n+}\n+\n+/**\n+ * \\fn V4L2ControlInfo::id()\n+ * \\brief Retrieve the control ID\n+ * \\return The V4L2 control ID\n+ */\n+\n+/**\n+ * \\fn V4L2ControlInfo::type()\n+ * \\brief Retrieve the control type as defined by V4L2_CTRL_TYPE_*\n+ * \\return The V4L2 control type\n+ */\n+\n+/**\n+ * \\fn V4L2ControlInfo::size()\n+ * \\brief Retrieve the control value data size (in bytes)\n+ * \\return The V4L2 control value data size\n+ */\n+\n+/**\n+ * \\fn V4L2ControlInfo::name()\n+ * \\brief Retrieve the control user readable name\n+ * \\return The V4L2 control user readable name\n+ */\n+\n+/**\n+ * \\class V4L2Control\n+ * \\brief A V4L2 control value\n+ *\n+ * The V4L2Control class represent the value of a V4L2 control.\n+ * The class stores values that have been read from or will be applied to\n+ * a V4L2 device.\n+ *\n+ * The value stored in the class instances does not reflect what is actually\n+ * applied to the hardware but is a pure software cache optionally initialized\n+ * at control creation time and only modified by a control read operation.\n+ *\n+ * The write and read controls the V4L2Control class instances are not meant\n+ * to be directly used but are instead intended to be grouped in\n+ * V4L2Controls instances, which are then passed as parameters to\n+ * V4L2Device::setControls() and V4L2Device::getControls() operations.\n+ */\n+\n+/**\n+ * \\fn V4L2Control::V4L2Control\n+ * \\brief Construct a V4L2 control with ID \\a id and value \\a value\n+ * \\param id The V4L2 control ID\n+ * \\param value The control value\n+ */\n+\n+/**\n+ * \\fn V4L2Control::value()\n+ * \\brief Retrieve the value of the control\n+ *\n+ * It is important to notice that the returned value is not read from the\n+ * hardware at the time this operation is called, but it's the cached value\n+ * obtained the most recent time the control has been read with\n+ * V4L2Device::getControls() or the value of the control has been set to by the\n+ * user with the add() operation.\n+ *\n+ * \\return The V4L2 control value. The value might be 0 if the control has\n+ * never been read from the device before this operation is called.\n+ */\n+\n+/**\n+ * \\fn V4L2Control::setValue()\n+ * \\brief Set the value of the control\n+ * \\param value The new V4L2 control value\n+ *\n+ * It is important to notice that the value is not applied to the\n+ * hardware at the time this operation is called, but it will only\n+ * be actually applied by calling V4L2Device::setControls().\n+ */\n+\n+/**\n+ * \\fn V4L2Control::id()\n+ * \\brief Retrieve the control ID this instance refers to\n+ * \\return The V4L2Control ID\n+ */\n+\n+/**\n+ * \\class V4L2Controls\n+ * \\brief Container of V4L2Control instances\n+ *\n+ * The V4L2Controls class works as a container for a list of V4L2Control\n+ * instances. The class provides operations to add a new control to the list,\n+ * get back a control value, and reset the list of controls it contains.\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, and use\n+ * them as argument for the V4L2Device::setControls() and\n+ * V4L2Device::getControls() operations, which write and read a list of\n+ * controls from or to a V4L2 device (a video device or a subdevice).\n+ *\n+ * Controls are added to a V4L2Controls instance with the add() method, with\n+ * or without an initial value.\n+ *\n+ * To write controls to a device, the controls of interest shall be added with\n+ * an initial value by calling V4L2Controls::add(unsigned int id, int64_t\n+ * value) to prepare for a write operation. Once the values of all controls of\n+ * interest have been added, the V4L2Controls instance is passed to the\n+ * V4L2Device::setControls(), which sets the controls on the device.\n+ *\n+ * To read controls from a device, the desired controls are added with\n+ * V4L2Controls::add(unsigned int id) to prepare for a read operation. The\n+ * V4L2Controls instance is then passed to V4L2Device::getControls(), which\n+ * reads the controls from the device and updates the values stored in\n+ * V4L2Controls.\n+ *\n+ * V4L2Controls instances can be reset to remove all controls they contain and\n+ * prepare to be re-used for a new control write/read sequence.\n+ */\n+\n+/**\n+ * \\typedef V4L2Controls::iterator\n+ * \\brief Iterator on the V4L2 controls contained in the instance\n+ */\n+\n+/**\n+ * \\typedef V4L2Controls::const_iterator\n+ * \\brief Const iterator on the V4L2 controls contained in the instance\n+ */\n+\n+/**\n+ * \\fn iterator V4L2Controls::begin()\n+ * \\brief Retrieve an iterator to the first V4L2Control in the instance\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 instance\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+ * instance\n+ * \\return An iterator to the element following the last V4L2 control in the\n+ * instance\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 instance\n+ * \\return A constant iterator to the element following the last V4L2 control\n+ * in the instance\n+ */\n+\n+/**\n+ * \\fn V4L2Controls::empty()\n+ * \\brief Verify if the instance does not contain any control\n+ * \\return True if the instance does not contain any control, false otherwise\n+ */\n+\n+/**\n+ * \\fn V4L2Controls::size()\n+ * \\brief Retrieve the number on controls in the instance\n+ * \\return The number of V4L2Control stored in the instance\n+ */\n+\n+/**\n+ * \\fn V4L2Controls::reset()\n+ * \\brief Removes all controls in the instance\n+ */\n+\n+/**\n+ * \\brief Add control with ID \\a id and optional \\a value to the instance\n+ * \\param id The V4L2 control ID (V4L2_CID_*)\n+ * \\param value The V4L2 control value\n+ *\n+ * V4L2Control can be added with an explicit value, or without one. In that\n+ * case the control's value is defaulted to 0.\n+ */\n+void V4L2Controls::add(unsigned int id, int64_t value)\n+{\n+\tcontrols_.emplace_back(id, value);\n+}\n+\n+/**\n+ * \\fn V4L2Controls::operator[](unsigned int index)\n+ * \\brief Access the control at index \\a index\n+ * \\param index The index to access\n+ * \\return The V4L2 control at index \\a index\n+ */\n+\n+/**\n+ * \\brief Get a pointer the control with ID \\a id\n+ * \\param id The V4L2 control ID (V4L2_CID_xx)\n+ * \\return A pointer to the V4L2Control with ID \\a id or nullptr if the\n+ * control ID is not part of this instance.\n+ */\n+V4L2Control *V4L2Controls::getControl(unsigned int id)\n+{\n+\tfor (V4L2Control &ctrl : controls_) {\n+\t\tif (ctrl.id() == id)\n+\t\t\treturn &ctrl;\n+\t}\n+\n+\treturn nullptr;\n+}\n+\n+} /* namespace libcamera */\n", "prefixes": [ "libcamera-devel", "v5", "1/6" ] }