{"id":2134,"url":"https://patchwork.libcamera.org/api/1.1/patches/2134/?format=json","web_url":"https://patchwork.libcamera.org/patch/2134/","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":"<20191007224642.6597-7-laurent.pinchart@ideasonboard.com>","date":"2019-10-07T22:46:39","name":"[libcamera-devel,6/9] libcamera: v4l2_controls: Add V4L2ControlId","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"6c9d3b0f11e14884c7c0c8983afbe9d0b8f6c442","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/2134/mbox/","series":[{"id":526,"url":"https://patchwork.libcamera.org/api/1.1/series/526/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=526","date":"2019-10-07T22:46:33","name":"Use ControlList for both libcamera and V4L2 controls","version":1,"mbox":"https://patchwork.libcamera.org/series/526/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/2134/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/2134/checks/","tags":{},"headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9FCC961974\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  8 Oct 2019 00:46:56 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(modemcable118.64-20-96.mc.videotron.ca [96.20.64.118])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id EF0A1B2D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  8 Oct 2019 00:46:55 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1570488416;\n\tbh=DqeXG14ytkkFz0F+Phy0EQ9TMq5xHDAFzIPV+bH9CiI=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=tQz1S00RYC1UVeNGLXF7libtAyUAZE0oGnOc/LlQl8UkRacV716DeC87ZGa8d2h5o\n\tnBckGlugeGKpOcG2oLD6sbCjlabYJ6Ll2OD0SXdS6PBhZZMLplKRnn2lbEEKRBiQfX\n\t2Xh6x7J3bl4xRnjAqLYnF/KKxHv1UdNj2H0DC2yU=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue,  8 Oct 2019 01:46:39 +0300","Message-Id":"<20191007224642.6597-7-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.21.0","In-Reply-To":"<20191007224642.6597-1-laurent.pinchart@ideasonboard.com>","References":"<20191007224642.6597-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH 6/9] libcamera: v4l2_controls: Add\n\tV4L2ControlId","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","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, 07 Oct 2019 22:46:56 -0000"},"content":"Add a V4L2 specialisation of the ControlId class, in order to construct\na ControlId from a v4l2_query_ext_ctrl. This is needed in order to use\nControlList for V4L2 controls.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/include/v4l2_controls.h | 12 +++--\n src/libcamera/v4l2_controls.cpp       | 67 +++++++++++++++++++++++----\n src/libcamera/v4l2_device.cpp         |  4 +-\n 3 files changed, 68 insertions(+), 15 deletions(-)","diff":"diff --git a/src/libcamera/include/v4l2_controls.h b/src/libcamera/include/v4l2_controls.h\nindex b39370b2e90e..71ce377fe4c5 100644\n--- a/src/libcamera/include/v4l2_controls.h\n+++ b/src/libcamera/include/v4l2_controls.h\n@@ -20,23 +20,27 @@\n \n namespace libcamera {\n \n+class V4L2ControlId : public ControlId\n+{\n+public:\n+\tV4L2ControlId(const struct v4l2_query_ext_ctrl &ctrl);\n+};\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+\tconst ControlId &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 \tconst ControlRange &range() const { return range_; }\n \n private:\n-\tunsigned int id_;\n+\tV4L2ControlId id_;\n \tunsigned int type_;\n \tsize_t size_;\n-\tstd::string name_;\n \n \tControlRange range_;\n };\ndiff --git a/src/libcamera/v4l2_controls.cpp b/src/libcamera/v4l2_controls.cpp\nindex 6f5f1578b139..a630a2583d33 100644\n--- a/src/libcamera/v4l2_controls.cpp\n+++ b/src/libcamera/v4l2_controls.cpp\n@@ -7,6 +7,8 @@\n \n #include \"v4l2_controls.h\"\n \n+#include <string.h>\n+\n /**\n  * \\file v4l2_controls.h\n  * \\brief Support for V4L2 Controls using the V4L2 Extended Controls APIs\n@@ -47,6 +49,60 @@\n \n namespace libcamera {\n \n+namespace {\n+\n+std::string v4l2_ctrl_name(const struct v4l2_query_ext_ctrl &ctrl)\n+{\n+\tsize_t len = strnlen(ctrl.name, sizeof(ctrl.name));\n+\treturn std::string(static_cast<const char *>(ctrl.name), len);\n+}\n+\n+ControlType v4l2_ctrl_type(const struct v4l2_query_ext_ctrl &ctrl)\n+{\n+\tswitch (ctrl.type) {\n+\tcase V4L2_CTRL_TYPE_BOOLEAN:\n+\t\treturn ControlTypeBool;\n+\n+\tcase V4L2_CTRL_TYPE_INTEGER:\n+\t\treturn ControlTypeInteger32;\n+\n+\tcase V4L2_CTRL_TYPE_INTEGER64:\n+\t\treturn ControlTypeInteger64;\n+\n+\tcase V4L2_CTRL_TYPE_MENU:\n+\tcase V4L2_CTRL_TYPE_BUTTON:\n+\tcase V4L2_CTRL_TYPE_BITMASK:\n+\tcase V4L2_CTRL_TYPE_INTEGER_MENU:\n+\t\t/*\n+\t\t * More precise types may be needed, for now use a 32-bit\n+\t\t * integer type.\n+\t\t */\n+\t\treturn ControlTypeInteger32;\n+\n+\tdefault:\n+\t\treturn ControlTypeNone;\n+\t}\n+}\n+\n+} /* namespace */\n+\n+/**\n+ * \\class V4L2ControlId\n+ * \\brief V4L2 control static metadata\n+ *\n+ * The V4L2ControlId class is a specialisation of the ControlId for V4L2\n+ * controls.\n+ */\n+\n+/**\n+ * \\brief Construct a V4L2ControlId from a struct v4l2_query_ext_ctrl\n+ * \\param[in] ctrl The struct v4l2_query_ext_ctrl as returned by the kernel\n+ */\n+V4L2ControlId::V4L2ControlId(const struct v4l2_query_ext_ctrl &ctrl)\n+\t: ControlId(ctrl.id, v4l2_ctrl_name(ctrl), v4l2_ctrl_type(ctrl))\n+{\n+}\n+\n /**\n  * \\class V4L2ControlInfo\n  * \\brief Information on a V4L2 control\n@@ -66,13 +122,12 @@ namespace libcamera {\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+ * \\param[in] ctrl The struct v4l2_query_ext_ctrl as returned by the kernel\n  */\n V4L2ControlInfo::V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl)\n+\t: id_(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 \tif (ctrl.type == V4L2_CTRL_TYPE_INTEGER64)\n@@ -101,12 +156,6 @@ V4L2ControlInfo::V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl)\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  * \\fn V4L2ControlInfo::range()\n  * \\brief Retrieve the control value range\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex 3bd82ff23212..466c3d41f6e3 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -184,7 +184,7 @@ int V4L2Device::getControls(V4L2ControlList *ctrls)\n \n \t\tconst V4L2ControlInfo *info = &iter->second;\n \t\tcontrolInfo[i] = info;\n-\t\tv4l2Ctrls[i].id = info->id();\n+\t\tv4l2Ctrls[i].id = ctrl->id();\n \t}\n \n \tstruct v4l2_ext_controls v4l2ExtCtrls = {};\n@@ -259,7 +259,7 @@ int V4L2Device::setControls(V4L2ControlList *ctrls)\n \n \t\tconst V4L2ControlInfo *info = &iter->second;\n \t\tcontrolInfo[i] = info;\n-\t\tv4l2Ctrls[i].id = info->id();\n+\t\tv4l2Ctrls[i].id = ctrl->id();\n \n \t\t/* Set the v4l2_ext_control value for the write operation. */\n \t\tswitch (info->type()) {\n","prefixes":["libcamera-devel","6/9"]}