{"id":1426,"url":"https://patchwork.libcamera.org/api/1.1/patches/1426/?format=json","web_url":"https://patchwork.libcamera.org/patch/1426/","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":"<20190613112046.25260-3-jacopo@jmondi.org>","date":"2019-06-13T11:20:42","name":"[libcamera-devel,v3,2/6] libcamera: v4l2_device: List controls at device open","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"863cc21726aba38eda4badfad241e848d95e8b51","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/1426/mbox/","series":[{"id":357,"url":"https://patchwork.libcamera.org/api/1.1/series/357/?format=json","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/1426/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1426/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 E5D4561BD1\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 7866FC0014;\n\tThu, 13 Jun 2019 11:19:42 +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:42 +0200","Message-Id":"<20190613112046.25260-3-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 2/6] libcamera: v4l2_device: List\n\tcontrols at device 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, 13 Jun 2019 11:19:43 -0000"},"content":"Enumerate all the controls a device supports at open() time.\nStore the control informations in a map inside the device to save\nquerying the control when setting or getting its value from the device.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/include/v4l2_device.h |  8 +++++++-\n src/libcamera/v4l2_device.cpp       | 31 +++++++++++++++++++++++++++++\n 2 files changed, 38 insertions(+), 1 deletion(-)","diff":"diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\nindex a73e1b600500..727b9d2e210a 100644\n--- a/src/libcamera/include/v4l2_device.h\n+++ b/src/libcamera/include/v4l2_device.h\n@@ -7,14 +7,17 @@\n #ifndef __LIBCAMERA_V4L2_DEVICE_H__\n #define __LIBCAMERA_V4L2_DEVICE_H__\n \n+#include <map>\n #include <string>\n \n namespace libcamera {\n \n+class V4L2ControlInfo;\n+\n class V4L2Device\n {\n public:\n-\tvirtual ~V4L2Device() { close(); }\n+\tvirtual ~V4L2Device();\n \n protected:\n \tV4L2Device();\n@@ -28,7 +31,10 @@ protected:\n \tint ioctl(unsigned long request, void *argp);\n \n private:\n+\tint listControls();\n+\n \tint fd_;\n+\tstd::map<unsigned int, V4L2ControlInfo *> controls_;\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex 6cbfc212a725..b60b446050e9 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@@ -50,6 +51,14 @@ V4L2Device::V4L2Device()\n {\n }\n \n+V4L2Device::~V4L2Device()\n+{\n+\tfor (auto &pair : controls_)\n+\t\tdelete pair.second;\n+\n+\tclose();\n+}\n+\n /**\n  * \\fn V4L2Device::fd()\n  * \\brief Retrieve the V4L2 device file descriptor\n@@ -82,6 +91,28 @@ int V4L2Device::open(const std::string &pathname, unsigned int flags)\n \n \tfd_ = ret;\n \n+\tlistControls();\n+\n+\treturn 0;\n+}\n+\n+int 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\tcontrols_[ctrl.id] = new V4L2ControlInfo(ctrl);\n+\t\tctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL;\n+\t}\n+\n \treturn 0;\n }\n \n","prefixes":["libcamera-devel","v3","2/6"]}