Patch Detail
Show a patch.
GET /api/patches/1504/?format=api
{ "id": 1504, "url": "https://patchwork.libcamera.org/api/patches/1504/?format=api", "web_url": "https://patchwork.libcamera.org/patch/1504/", "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": "<20190624142859.19313-2-jacopo@jmondi.org>", "date": "2019-06-24T14:28:54", "name": "[libcamera-devel,v6,1/6] libcamera: Add V4L2Controls", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "f32f5d9da28ccb88b30f6aee1669f49eb2ee26da", "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/1504/mbox/", "series": [ { "id": 371, "url": "https://patchwork.libcamera.org/api/series/371/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=371", "date": "2019-06-24T14:28:53", "name": "Add support for V4L2 controls", "version": 6, "mbox": "https://patchwork.libcamera.org/series/371/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/1504/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/1504/checks/", "tags": {}, "headers": { "Return-Path": "<jacopo@jmondi.org>", "Received": [ "from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net\n\t[217.70.183.200])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 082F361580\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 24 Jun 2019 16:27:51 +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 relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 936A72000C;\n\tMon, 24 Jun 2019 14:27:50 +0000 (UTC)" ], "X-Originating-IP": "2.224.242.101", "From": "Jacopo Mondi <jacopo@jmondi.org>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Mon, 24 Jun 2019 16:28:54 +0200", "Message-Id": "<20190624142859.19313-2-jacopo@jmondi.org>", "X-Mailer": "git-send-email 2.21.0", "In-Reply-To": "<20190624142859.19313-1-jacopo@jmondi.org>", "References": "<20190624142859.19313-1-jacopo@jmondi.org>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v6 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": "Mon, 24 Jun 2019 14:27:51 -0000" }, "content": "Add libcamera V4L2 control support, implemented using the V4L2 Extended\nControl APIs. This patch defines the types used to create and manage\ncontrols.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/include/v4l2_controls.h | 79 ++++++++\n src/libcamera/meson.build | 1 +\n src/libcamera/v4l2_controls.cpp | 281 ++++++++++++++++++++++++++\n 3 files changed, 361 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..aad4ef14ed31\n--- /dev/null\n+++ b/src/libcamera/include/v4l2_controls.h\n@@ -0,0 +1,79 @@\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 id_;\n+\tunsigned int type_;\n+\tsize_t size_;\n+\tstd::string name_;\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 V4L2ControlList\n+{\n+public:\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+\tstd::size_t size() const { return controls_.size(); }\n+\n+\tvoid clear() { controls_.clear(); }\n+\tint add(unsigned int id, int64_t value = 0);\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..ac932d855dd6\n--- /dev/null\n+++ b/src/libcamera/v4l2_controls.cpp\n@@ -0,0 +1,281 @@\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 Control API allows application to inspect and modify sets of\n+ * 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 that\n+ * can be modified with V4L2Device::setControls() or retrieved with\n+ * V4L2Device::getControls().\n+ *\n+ * The control's type along with the control's flags define the type of the\n+ * control's value content. Controls can transport a single data value stored in\n+ * variable inside the control, or they might as well deal with more complex\n+ * data types, such as arrays of matrices, stored in a contiguous memory\n+ * locations associated with the control and called 'the payload'. Such controls\n+ * are called 'compound controls' and are currently not supported by the\n+ * 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, wrapped\n+ * by the V4L2ControlList class, to match the V4L2 extended controls API. The\n+ * interface to set and get control is implemented by the V4L2Device class, and\n+ * 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 represents all the information related to a V4L2\n+ * control, such as its ID, its type, its user-readable name and the expected\n+ * 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 driver\n+ * 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 on\n+ * the control, which shall be cached by the caller at initialisation time or\n+ * 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. The class\n+ * stores values that have been read from or will be applied to 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 modified by a control read or write 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+ * V4L2ControlList 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 \\a id and \\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+ * This method returns the cached control value, initially set by\n+ * V4L2ControlList::add() and then updated when the controls are read or\n+ * written with V4L2Device::getControls() and V4L2Device::setControls().\n+ *\n+ * \\return The V4L2 control value\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+ * This method stores the control value, which will be applied to the\n+ * device when 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 V4L2ControlList\n+ * \\brief Container of V4L2Control instances\n+ *\n+ * The V4L2ControlList 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 V4L2ControlList 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 to or from a V4L2 device (a video device or a subdevice).\n+ *\n+ * Controls are added to a V4L2ControlList instance with the add() method, with\n+ * or without a value.\n+ *\n+ * To write controls to a device, the controls of interest shall be added with\n+ * an initial value by calling V4L2ControlList::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 V4L2ControlList 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+ * V4L2ControlList::add(unsigned int id) to prepare for a read operation. The\n+ * V4L2ControlList instance is then passed to V4L2Device::getControls(), which\n+ * reads the controls from the device and updates the values stored in\n+ * V4L2ControlList.\n+ *\n+ * V4L2ControlList instances can be reset to remove all controls they contain\n+ * and prepare to be re-used for a new control write/read sequence.\n+ */\n+\n+/**\n+ * \\typedef V4L2ControlList::iterator\n+ * \\brief Iterator on the V4L2 controls contained in the instance\n+ */\n+\n+/**\n+ * \\typedef V4L2ControlList::const_iterator\n+ * \\brief Const iterator on the V4L2 controls contained in the instance\n+ */\n+\n+/**\n+ * \\fn iterator V4L2ControlList::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 V4L2ControlList::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 V4L2ControlList::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 V4L2ControlList::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 V4L2ControlList::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 V4L2ControlList::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 V4L2ControlList::clear()\n+ * \\brief Remove all controls in the instance\n+ */\n+\n+/**\n+ * \\brief Add control with \\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+ * This methods add a new V4L2 control to the V4L2ControlList. The newly\n+ * inserted control should be unique (no other control with \\a id should be\n+ * part of the V4L2 control list) otherwise a negative error code is returned.\n+ *\n+ * \\return 0 on success or a negative error code otherwise\n+ * \\retval -EBUSY A control with \\a id already exists\n+ */\n+int V4L2ControlList::add(unsigned int id, int64_t value)\n+{\n+\tfor (const V4L2Control &ctrl : controls_) {\n+\t\tif (ctrl.id() == id)\n+\t\t\treturn -EBUSY;\n+\t}\n+\n+\tcontrols_.emplace_back(id, 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 \\a id or nullptr if the\n+ * control ID is not part of this instance.\n+ */\n+V4L2Control *V4L2ControlList::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", "v6", "1/6" ] }