{"id":1485,"url":"https://patchwork.libcamera.org/api/1.1/patches/1485/?format=json","web_url":"https://patchwork.libcamera.org/patch/1485/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20190620153144.5394-3-jacopo@jmondi.org>","date":"2019-06-20T15:31:40","name":"[libcamera-devel,v5,2/6] libcamera: v4l2_device: List valid controls at open","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"d65c50c14d6305b5d5de89bf60e8bc07705be3e9","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/1.1/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/1485/mbox/","series":[{"id":368,"url":"https://patchwork.libcamera.org/api/1.1/series/368/?format=json","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/1485/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1485/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 9C95060BA1\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 3D466240007;\n\tThu, 20 Jun 2019 15:30:41 +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:40 +0200","Message-Id":"<20190620153144.5394-3-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 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":"Thu, 20 Jun 2019 15:30:42 -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 informations 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>\n---\n src/libcamera/include/v4l2_device.h |  9 ++++\n src/libcamera/v4l2_device.cpp       | 72 +++++++++++++++++++++++++++++\n 2 files changed, 81 insertions(+)","diff":"diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\nindex 75f23a05b903..91a72fcecbcc 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,10 @@ protected:\n \tint fd() { return fd_; }\n \n private:\n+\tvoid listControls();\n+\tint validateControlType(const V4L2ControlInfo *info);\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..b113ff77e3cf 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,58 @@ 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\tif (validateControlType(&info))\n+\t\t\tcontinue;\n+\n+\t\tcontrols_.insert(std::pair<unsigned int, V4L2ControlInfo>\n+\t\t\t\t (ctrl.id, info));\n+\t\tctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL;\n+\t}\n+}\n+\n+/*\n+ * \\brief Make sure the control type is supported\n+ * \\param[in] info The V4L2ControlInfo to inspect type of\n+ * \\return 0 on success or a negative error code otherwise\n+ * \\retval -EINVAL The control type is not supported\n+ */\n+int V4L2Device::validateControlType(const V4L2ControlInfo *info)\n+{\n+\t/* \\todo Support compound controls. */\n+\tswitch (info->type()) {\n+\tcase V4L2_CTRL_TYPE_INTEGER:\n+\tcase V4L2_CTRL_TYPE_BOOLEAN:\n+\tcase V4L2_CTRL_TYPE_MENU:\n+\tcase V4L2_CTRL_TYPE_BUTTON:\n+\tcase V4L2_CTRL_TYPE_INTEGER64:\n+\tcase V4L2_CTRL_TYPE_BITMASK:\n+\tcase V4L2_CTRL_TYPE_INTEGER_MENU:\n+\t\tbreak;\n+\tdefault:\n+\t\tLOG(V4L2, Error) << \"Control type '\" << info->type()\n+\t\t\t\t << \"' not supported\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\treturn 0;\n+}\n+\n } /* namespace libcamera */\n","prefixes":["libcamera-devel","v5","2/6"]}