Patch Detail
Show a patch.
GET /api/1.1/patches/1425/?format=api
{ "id": 1425, "url": "https://patchwork.libcamera.org/api/1.1/patches/1425/?format=api", "web_url": "https://patchwork.libcamera.org/patch/1425/", "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": "<20190613112046.25260-2-jacopo@jmondi.org>", "date": "2019-06-13T11:20:41", "name": "[libcamera-devel,v3,1/6] libcamera: Add V4L2Controls", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "46233827fa2b885dcbe8353c12ef37586c0e480b", "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/1425/mbox/", "series": [ { "id": 357, "url": "https://patchwork.libcamera.org/api/1.1/series/357/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=357", "date": "2019-06-13T11:20:40", "name": "Add support for V4L2 Controls", "version": 3, "mbox": "https://patchwork.libcamera.org/series/357/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/1425/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/1425/checks/", "tags": {}, "headers": { "Return-Path": "<jacopo@jmondi.org>", "Received": [ "from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net\n\t[217.70.183.198])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4DAEF61BD1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 13 Jun 2019 13:19:42 +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 relay6-d.mail.gandi.net (Postfix) with ESMTPSA id C27D9C000C;\n\tThu, 13 Jun 2019 11:19:41 +0000 (UTC)" ], "X-Originating-IP": "2.224.242.101", "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Thu, 13 Jun 2019 13:20:41 +0200", "Message-Id": "<20190613112046.25260-2-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.21.0", "In-Reply-To": "<20190613112046.25260-1-jacopo@jmondi.org>", "References": "<20190613112046.25260-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v3 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, 13 Jun 2019 11:19:42 -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 | 96 ++++++++\n src/libcamera/meson.build | 1 +\n src/libcamera/v4l2_controls.cpp | 337 ++++++++++++++++++++++++++\n 3 files changed, 434 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..d7b12801329e\n--- /dev/null\n+++ b/src/libcamera/include/v4l2_controls.h\n@@ -0,0 +1,96 @@\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 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+\tunsigned int id() const { return id_; }\n+\n+private:\n+\tfriend class V4L2Device;\n+\tfriend class V4L2Controls;\n+\n+\tV4L2Control(unsigned int id)\n+\t\t: id_(id) {}\n+\tV4L2Control(unsigned int id, int value)\n+\t\t: id_(id), value_(value) {}\n+\n+\tlong int value() const { return value_; }\n+\tvoid setValue(long int value) { value_ = value; }\n+\n+\tunsigned int id_;\n+\tlong int 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() { return controls_.size(); }\n+\tvoid reset() { controls_.clear(); }\n+\n+\tV4L2Control *operator[](unsigned int index)\n+\t{\n+\t\treturn &controls_[index];\n+\t}\n+\n+\tvoid add(unsigned int id, long int value);\n+\tvoid add(unsigned int id);\n+\n+\tint get(unsigned int id);\n+\tint set(unsigned int id, long int value);\n+\n+private:\n+\tV4L2Control *getControl(unsigned int id);\n+\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..75b9c29ca133\n--- /dev/null\n+++ b/src/libcamera/v4l2_controls.cpp\n@@ -0,0 +1,337 @@\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 call to the 'V4L2Device::setControls()'\n+ * operation or retrieved with a call to 'V4L2Device::getControls()'.\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'. Such controls are called 'compound controls' and\n+ * are currently not supported by the Libcamera V4L2 control framework.\n+ *\n+ * \\todo Add support for compound controls\n+ *\n+ * Libcamera implements support for control using the V4L2 'Extended Control'\n+ * framework, which allows easier future handling of controls with payloads\n+ * 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 V4L2Device class,\n+ * and this file only provides the data type definitions.\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 informations relative 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 field of\n+ * a struct v4l2_query_ext_ctrl structure, after it has been filled by the\n+ * device driver as a consequence of an VIDIOC_QUERY_EXT_CTRL ioctl call.\n+ *\n+ * This class does not contain the control value, but only static informations\n+ * on the control, which should ideally be cached the first time the control\n+ * is accessed to be reused each time the control value need to be read or\n+ * applied to the hardware.\n+ */\n+\n+/**\n+ * \\brief Construct a V4L2ControlInfo from a struct v4l2_query_ext_ctrl\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 this instance refers to\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 or a\n+ * call to V4L2Controls::set().\n+ *\n+ * The V4L2Control class instances are not meant to be directly used but are\n+ * instead intended to be grouped in V4L2Controls instances, which are then\n+ * passed as parameters to the set and get control operations implemented in\n+ * V4L2Device::setControls() and V4L2Device::setControls() respectively.\n+ *\n+ * In facts, access to the class constructor and to the control value accessor\n+ * and modifier are restricted to the friend V4L2Controls and V4L2Device\n+ * classes.\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 Wraps a list of V4L2Control\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 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 should be added\n+ * with an initial value by calling V4L2Controls::add(unsigned int id, long\n+ * int value) to prepare for a write operation. The value of controls which\n+ * are already part of the instance could be updated with a call to\n+ * V4L2Controls::set() operation. Once the values of all controls of interest\n+ * have been initialized in a V4L2Controls instance, this should be then\n+ * passed to the V4L2Device::setControls() operation, which applies each\n+ * control in the list to the hardware.\n+ *\n+ * Alternatively a control can be add without any initial value by calling\n+ * V4L2Controls::add(unsigned int id) and then read from the device passing\n+ * the V4L2Controls instance to V4L2Device::getControls() which read each\n+ * control value from the hardware.\n+ *\n+ * Reading controls with an initialized value from the device, overwrites the\n+ * control's value, reflecting what has been actually read from the hardware.\n+ *\n+ * V4L2Controls instances can be reset to remove all controls it contains and\n+ * prepare to be re-used for a new control write/read sequence. Alternatively,\n+ * the value of a control already part of the instance could be updated by using\n+ * the V4L2Controls::set() method, to avoid going through a reset() when a\n+ * control has to be read then written to the hardware in sequence.\n+ *\n+ * In facts, the following pseudo-code sequences lead to the same result:\n+ *\n+ * V4L2Controls controls;\n+ * controls.add(V4L2_CID_xx);\n+ * dev->getControls(&controls);\n+ * controls.set(V4L2_CID_xx, value);\n+ * dev->setControls(&controls);\n+ *\n+ * V4L2Controls controls;\n+ * controls.add(V4L2_CID_xx);\n+ * dev->getControls(&controls);\n+ * controls.reset();\n+ * controls.add(V4L2_CID_xx, value);\n+ * dev->setControls(&controls);\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+ * \\fn V4L2Controls::operator[](unsigned int index)\n+ * \\brief Access the control at index \\a index\n+ * \\param index The index to access\n+ */\n+\n+/**\n+ * \\brief Add control \\a id with a \\a value to the instance\n+ * \\param id The V4L2 control id (V4L2_CID_xx)\n+ * \\param value The V4L2 control value\n+ */\n+void V4L2Controls::add(unsigned int id, long int value)\n+{\n+\t/* Cannot use emplace_back() as the V4L2Control ctor is private. */\n+\tV4L2Control ctrl(id, value);\n+\tcontrols_.push_back(ctrl);\n+}\n+\n+/**\n+ * \\brief Add control \\a id without an initial value to the instance\n+ * \\param id The V4L2 control id (V4L2_CID_xx)\n+ */\n+void V4L2Controls::add(unsigned int id)\n+{\n+\t/* Cannot use emplace_back() as the V4L2Control ctor is private. */\n+\tV4L2Control ctrl(id);\n+\tcontrols_.push_back(ctrl);\n+}\n+\n+/**\n+ * \\brief Retrieve the value of the control with \\a id\n+ * \\param id The V4L2 control id (V4L2_CID_xx)\n+ *\n+ * Retrieve the value of the control with id \\a id.\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() or set() operation.\n+ *\n+ * \\return The V4L2 control value or a negative error code if the control id\n+ * is not part of this instance\n+ */\n+int V4L2Controls::get(unsigned int id)\n+{\n+\tV4L2Control *ctrl = getControl(id);\n+\tif (!ctrl)\n+\t\treturn -EINVAL;\n+\n+\treturn ctrl->value();\n+}\n+\n+/**\n+ * \\brief Set the value of the control with \\a id\n+ * \\param id The V4L2 control id (V4L2_CID_xx)\n+ * \\param value The new V4L2 control value\n+ *\n+ * Set the value of the control with id \\a id.\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 pplied only by calling V4L2Device::setControls().\n+ *\n+ * \\return 0 on success or a negative error code if the control id\n+ * is not part of this instance\n+ */\n+int V4L2Controls::set(unsigned int id, long int value)\n+{\n+\tV4L2Control *ctrl = getControl(id);\n+\tif (!ctrl)\n+\t\treturn -EINVAL;\n+\n+\tctrl->setValue(value);\n+\n+\treturn 0;\n+}\n+\n+/*\n+ * \\brief Get a pointer the control with \\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", "v3", "1/6" ] }