{"id":1475,"url":"https://patchwork.libcamera.org/api/patches/1475/?format=json","web_url":"https://patchwork.libcamera.org/patch/1475/","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":"<20190619110858.20980-3-jacopo@jmondi.org>","date":"2019-06-19T11:08:54","name":"[libcamera-devel,v4,2/6] libcamera: v4l2_device: List controls at device open","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"785c8bcb348cb7ae2db6a6e6addffcfd4863abf1","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/1475/mbox/","series":[{"id":364,"url":"https://patchwork.libcamera.org/api/series/364/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=364","date":"2019-06-19T11:08:52","name":"Add support for V4L2 Controls","version":4,"mbox":"https://patchwork.libcamera.org/series/364/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1475/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1475/checks/","tags":{},"headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net\n\t[217.70.183.199])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5824E6194F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 19 Jun 2019 13:07:50 +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 relay9-d.mail.gandi.net (Postfix) with ESMTPSA id EC0C9FF806;\n\tWed, 19 Jun 2019 11:07:49 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 19 Jun 2019 13:08:54 +0200","Message-Id":"<20190619110858.20980-3-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.21.0","In-Reply-To":"<20190619110858.20980-1-jacopo@jmondi.org>","References":"<20190619110858.20980-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 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":"Wed, 19 Jun 2019 11:07:50 -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       | 30 +++++++++++++++++++++++++++++\n 2 files changed, 37 insertions(+), 1 deletion(-)","diff":"diff --git a/src/libcamera/include/v4l2_device.h b/src/libcamera/include/v4l2_device.h\nindex 2c26f3eae2b4..563be151c257 100644\n--- a/src/libcamera/include/v4l2_device.h\n+++ b/src/libcamera/include/v4l2_device.h\n@@ -7,12 +7,15 @@\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@@ -22,7 +25,7 @@ public:\n \n protected:\n \tV4L2Device(const std::string &deviceNode, const std::string &logTag);\n-\t~V4L2Device() {}\n+\t~V4L2Device();\n \n \tint fd() { return fd_; }\n \n@@ -33,6 +36,9 @@ protected:\n \tstd::string logPrefix() const { return \"'\" + logTag_ + \"'\"; }\n \n private:\n+\tvoid listControls();\n+\n+\tstd::map<unsigned int, V4L2ControlInfo *> controls_;\n \tstd::string deviceNode_;\n \tstd::string logTag_;\n \tint fd_;\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex eeed0a70fb0e..58dd94836686 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,12 @@ V4L2Device::V4L2Device(const std::string &deviceNode, const std::string &logTag)\n {\n }\n \n+V4L2Device::~V4L2Device()\n+{\n+\tfor (auto &pair : controls_)\n+\t\tdelete pair.second;\n+}\n+\n /**\n  * \\fn V4L2Device::fd()\n  * \\brief Retrieve the V4L2 device file descriptor\n@@ -114,6 +121,8 @@ int V4L2Device::open(unsigned int flags)\n \n \tfd_ = ret;\n \n+\tlistControls();\n+\n \treturn 0;\n }\n \n@@ -141,4 +150,25 @@ int V4L2Device::ioctl(unsigned long request, void *argp)\n  * \\return The tag to prefix log messages with\n  */\n \n+/*\n+ * \\brief List and store all controls supported by the 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\tcontrols_[ctrl.id] = new V4L2ControlInfo(ctrl);\n+\t\tctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL;\n+\t}\n+}\n+\n } /* namespace libcamera */\n","prefixes":["libcamera-devel","v4","2/6"]}