{"id":1512,"url":"https://patchwork.libcamera.org/api/patches/1512/?format=json","web_url":"https://patchwork.libcamera.org/patch/1512/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20190625064830.951-3-jacopo@jmondi.org>","date":"2019-06-25T06:48:26","name":"[libcamera-devel,v7,2/6] libcamera: v4l2_device: List valid controls at open","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"b6bef83196a033cdb99585271abefd9ddc18a60f","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/1512/mbox/","series":[{"id":372,"url":"https://patchwork.libcamera.org/api/series/372/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=372","date":"2019-06-25T06:48:24","name":"Add support for V4L2 controls","version":6,"mbox":"https://patchwork.libcamera.org/series/372/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1512/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1512/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 075CE615BC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 25 Jun 2019 08:47:22 +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 relay11.mail.gandi.net (Postfix) with ESMTPSA id 72542100009;\n\tTue, 25 Jun 2019 06:47:21 +0000 (UTC)"],"From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 25 Jun 2019 08:48:26 +0200","Message-Id":"<20190625064830.951-3-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.21.0","In-Reply-To":"<20190625064830.951-1-jacopo@jmondi.org>","References":"<20190625064830.951-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v7 2/6] libcamera: v4l2_device: List valid\n\tcontrols at open","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":"Tue, 25 Jun 2019 06:47:22 -0000"},"content":"Enumerate all the valid controls a device supports at open() time.\nA control is valid only if its type is supported.\n\nStore the control information in a map inside the device to save\nquerying the control when setting or getting its value from the device\nand provide an operation to retrieve information by control ID.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/include/v4l2_device.h |  8 ++++\n src/libcamera/v4l2_device.cpp       | 57 +++++++++++++++++++++++++++++\n 2 files changed, 65 insertions(+)","diff":"diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\nindex 75f23a05b903..556960467e10 100644\n--- a/src/libcamera/include/v4l2_device.h\n+++ b/src/libcamera/include/v4l2_device.h\n@@ -7,18 +7,23 @@\n #ifndef __LIBCAMERA_V4L2_DEVICE_H__\n #define __LIBCAMERA_V4L2_DEVICE_H__\n \n+#include <map>\n #include <string>\n \n #include \"log.h\"\n \n namespace libcamera {\n \n+class V4L2ControlInfo;\n+\n class V4L2Device : protected Loggable\n {\n public:\n \tvoid close();\n \tbool isOpen() const { return fd_ != -1; }\n \n+\tconst V4L2ControlInfo *getControlInfo(unsigned int id) const;\n+\n \tconst std::string &deviceNode() const { return deviceNode_; }\n \n protected:\n@@ -32,6 +37,9 @@ protected:\n \tint fd() { return fd_; }\n \n private:\n+\tvoid listControls();\n+\n+\tstd::map<unsigned int, V4L2ControlInfo> controls_;\n \tstd::string deviceNode_;\n \tint fd_;\n };\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex 99621a724b96..51764b441f92 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -13,6 +13,7 @@\n #include <unistd.h>\n \n #include \"log.h\"\n+#include \"v4l2_controls.h\"\n \n /**\n  * \\file v4l2_device.h\n@@ -82,6 +83,8 @@ int V4L2Device::open(unsigned int flags)\n \n \tfd_ = ret;\n \n+\tlistControls();\n+\n \treturn 0;\n }\n \n@@ -107,6 +110,21 @@ void V4L2Device::close()\n  * \\return True if the V4L2 device node is open, false otherwise\n  */\n \n+/**\n+ * \\brief Retrieve information about a control\n+ * \\param[in] id The control ID\n+ * \\return A pointer to the V4L2ControlInfo for control \\a id, or nullptr\n+ * if the device doesn't have such a control\n+ */\n+const V4L2ControlInfo *V4L2Device::getControlInfo(unsigned int id) const\n+{\n+\tauto it = controls_.find(id);\n+\tif (it == controls_.end())\n+\t\treturn nullptr;\n+\n+\treturn &it->second;\n+}\n+\n /**\n  * \\brief Perform an IOCTL system call on the device node\n  * \\param[in] request The IOCTL request code\n@@ -137,4 +155,43 @@ int V4L2Device::ioctl(unsigned long request, void *argp)\n  * \\return The V4L2 device file descriptor, -1 if the device node is not open\n  */\n \n+/*\n+ * \\brief List and store information about all controls supported by the\n+ * V4L2 device\n+ */\n+void V4L2Device::listControls()\n+{\n+\tstruct v4l2_query_ext_ctrl ctrl = {};\n+\n+\t/* \\todo Add support for menu and compound controls. */\n+\tctrl.id = V4L2_CTRL_FLAG_NEXT_CTRL;\n+\twhile (ioctl(VIDIOC_QUERY_EXT_CTRL, &ctrl) == 0) {\n+\t\tif (ctrl.type == V4L2_CTRL_TYPE_CTRL_CLASS ||\n+\t\t    ctrl.flags & V4L2_CTRL_FLAG_DISABLED) {\n+\t\t\tctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL;\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tV4L2ControlInfo info(ctrl);\n+\t\tswitch (info.type()) {\n+\t\tcase V4L2_CTRL_TYPE_INTEGER:\n+\t\tcase V4L2_CTRL_TYPE_BOOLEAN:\n+\t\tcase V4L2_CTRL_TYPE_MENU:\n+\t\tcase V4L2_CTRL_TYPE_BUTTON:\n+\t\tcase V4L2_CTRL_TYPE_INTEGER64:\n+\t\tcase V4L2_CTRL_TYPE_BITMASK:\n+\t\tcase V4L2_CTRL_TYPE_INTEGER_MENU:\n+\t\t\tbreak;\n+\t\t/* \\todo Support compound controls. */\n+\t\tdefault:\n+\t\t\tLOG(V4L2, Error) << \"Control type '\" << info.type()\n+\t\t\t\t\t << \"' not supported\";\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\tcontrols_.emplace(ctrl.id, info);\n+\t\tctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL;\n+\t}\n+}\n+\n } /* namespace libcamera */\n","prefixes":["libcamera-devel","v7","2/6"]}