{"id":12126,"url":"https://patchwork.libcamera.org/api/patches/12126/?format=json","web_url":"https://patchwork.libcamera.org/patch/12126/","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":"<20210428073617.373422-4-hiroh@chromium.org>","date":"2021-04-28T07:36:13","name":"[libcamera-devel,v3,3/7] libcamera: V4L2Device: Support v4l2 menu control","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"dd642670f696020cbb8a9845e3e10eb24927a643","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/people/63/?format=json","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/12126/mbox/","series":[{"id":1983,"url":"https://patchwork.libcamera.org/api/series/1983/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1983","date":"2021-04-28T07:36:10","name":"Report Android HAL client test pattern modes","version":3,"mbox":"https://patchwork.libcamera.org/series/1983/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/12126/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/12126/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 65005BDE44\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 28 Apr 2021 07:36:33 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BDDDE688CE;\n\tWed, 28 Apr 2021 09:36:32 +0200 (CEST)","from mail-pf1-x430.google.com (mail-pf1-x430.google.com\n\t[IPv6:2607:f8b0:4864:20::430])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3B90B688B7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 28 Apr 2021 09:36:29 +0200 (CEST)","by mail-pf1-x430.google.com with SMTP id a12so826138pfc.7\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 28 Apr 2021 00:36:29 -0700 (PDT)","from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:2:489:a5f4:117:7d51])\n\tby smtp.gmail.com with ESMTPSA id\n\tm11sm1661265pgs.4.2021.04.28.00.36.26\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 28 Apr 2021 00:36:27 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"BnBMCfgr\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=QMJniqxYRSeszAKe+yuZv/Z9+aZeAH8IQy9wC+Uydis=;\n\tb=BnBMCfgrb0eKcJuBIlyv26FSxME/KvskKOjap32veA2nn5bHpTsDY+58epHqKHccrz\n\ta068KxWTS1s6Cz+BaXd+OgkhnuwtQhdCzICDjXWpoSK80WI3a2yIMyp6Fla6EUgjzNyO\n\tgg8KNRpey0CZqbFr/P+/xVuula8JNeID3oHkY=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=QMJniqxYRSeszAKe+yuZv/Z9+aZeAH8IQy9wC+Uydis=;\n\tb=NyOjTSi2aZXDyB6jrInqhfSayCFDmcS9Ot3U6bpRgHKpJYDvxApJVh4vs+9Qw/Pmd9\n\tLke4pqCWKSmxOnPGoRPrO5exP2lwQxYN3W6cT9klcxCjqJVlXOrg4Yb7pgW9B/E7lmR7\n\tqqo/3YMJWZO9PvofF2z1EdHOl5fJqtdePfnV3va9gHFjH7mGrQ/iaxR7svj2PPerN06H\n\tBGWl1hTGURUHZv04dSTKJ/Il9KTWegSC/RsqK3lKIX4fy1XTiLJosvB2ItdwS/T/dXRC\n\twEh2jiY5aB5rH0EOuOCI+9MtwPk0ah1aSQXLNiLcUbvLLo6jMefkWtt2pQS49S8TTAWh\n\twIjg==","X-Gm-Message-State":"AOAM531YeVMFhbtMBn71+yRtvYBCZcZkirvzGya6xz3dVyDbaCJD8NuF\n\toLuSJunW7ME0T0spbN5EI+gEE3jYQf82AQ==","X-Google-Smtp-Source":"ABdhPJxCn/TSPoVM3E7yX6NwuKMMsAp9Qc0OBUcRvL+23/EmkLSk/vSsDaldqdCKTAqaKTDBXvIEWw==","X-Received":"by 2002:a62:aa09:0:b029:25c:3c28:e2b with SMTP id\n\te9-20020a62aa090000b029025c3c280e2bmr26414320pff.39.1619595387417; \n\tWed, 28 Apr 2021 00:36:27 -0700 (PDT)","From":"Hirokazu Honda <hiroh@chromium.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 28 Apr 2021 16:36:13 +0900","Message-Id":"<20210428073617.373422-4-hiroh@chromium.org>","X-Mailer":"git-send-email 2.31.1.498.g6c1eba8ee3d-goog","In-Reply-To":"<20210428073617.373422-1-hiroh@chromium.org>","References":"<20210428073617.373422-1-hiroh@chromium.org>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v3 3/7] libcamera: V4L2Device: Support\n\tv4l2 menu control","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>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"This adds a support of v4l2 menu.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n include/libcamera/internal/v4l2_device.h |  3 +\n src/libcamera/v4l2_device.cpp            | 73 +++++++++++++++++++++---\n 2 files changed, 69 insertions(+), 7 deletions(-)","diff":"diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h\nindex 087f07e7..c7a2539c 100644\n--- a/include/libcamera/internal/v4l2_device.h\n+++ b/include/libcamera/internal/v4l2_device.h\n@@ -54,6 +54,9 @@ protected:\n \tint fd() const { return fd_; }\n \n private:\n+\tbool createControlInfoForMenu(const v4l2_query_ext_ctrl &ctrl,\n+\t\t\t\t      ControlInfo &ctrlInfo);\n+\n \tvoid listControls();\n \tvoid updateControls(ControlList *ctrls,\n \t\t\t    Span<const v4l2_ext_control> v4l2Ctrls);\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex 64501523..f2a9038e 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -446,6 +446,7 @@ int V4L2Device::ioctl(unsigned long request, void *argp)\n \treturn 0;\n }\n \n+\n /**\n  * \\fn V4L2Device::deviceNode()\n  * \\brief Retrieve the device node path\n@@ -453,10 +454,55 @@ int V4L2Device::ioctl(unsigned long request, void *argp)\n  */\n \n /**\n- * \\fn V4L2Device::fd()\n- * \\brief Retrieve the V4L2 device file descriptor\n- * \\return The V4L2 device file descriptor, -1 if the device node is not open\n+ * \\brief Create ControlInfo for v4l2 menu ctrl.\n+ * \\param[in] ctrl The v4l2_query_ext_ctrl that represents a menu\n+ * \\param[out] ctrlInfo The created controlInfo\n+ *\n+ * The created ControlInfo contains not only values and also extra values, which\n+ * are indices and name/value acquired by VIDIOC_QUERYMENU, respectively. The\n+ * extra values contains std::string if the type of \\a ctrl is\n+ * V4L2_CTRL_TYPE_MENU or int64_t otherwise.\n+ *\n+ * \\return True on success or false otherwise\n  */\n+bool V4L2Device::createControlInfoForMenu(const v4l2_query_ext_ctrl &ctrl,\n+\t\t\t\t\t  ControlInfo &ctrlInfo)\n+{\n+\tASSERT(ctrl.type == V4L2_CTRL_TYPE_MENU ||\n+\t       ctrl.type == V4L2_CTRL_TYPE_INTEGER_MENU);\n+\tconst bool isName = ctrl.type == V4L2_CTRL_TYPE_MENU;\n+\n+\tstd::vector<ControlValue> indices;\n+\tstd::vector<ControlValue> values;\n+\tv4l2_querymenu menu;\n+\tmemset(&menu, 0, sizeof(menu));\n+\tmenu.id = ctrl.id;\n+\n+\tfor (menu.index = ctrl.minimum;\n+\t     static_cast<int>(menu.index) <= ctrl.maximum; menu.index++) {\n+\t\tif (ioctl(VIDIOC_QUERYMENU, &menu) != 0)\n+\t\t\tcontinue;\n+\n+\t\tindices.emplace_back(static_cast<int32_t>(menu.index));\n+\t\tif (isName) {\n+\t\t\tstd::string name(reinterpret_cast<const char *>(menu.name));\n+\t\t\tvalues.emplace_back(std::move(name));\n+\t\t} else {\n+\t\t\tvalues.emplace_back(static_cast<int64_t>(menu.value));\n+\t\t}\n+\t}\n+\n+\tif (values.empty()) {\n+\t\tLOG(V4L2, Error)\n+\t\t\t<< \"No applicable value: \" << utils::hex(ctrl.id);\n+\n+\t\treturn false;\n+\t}\n+\n+\tctrlInfo = ControlInfo(indices, values);\n+\n+\treturn true;\n+}\n \n /*\n  * \\brief List and store information about all controls supported by the\n@@ -467,7 +513,6 @@ void V4L2Device::listControls()\n \tControlInfoMap::Map ctrls;\n \tstruct v4l2_query_ext_ctrl ctrl = {};\n \n-\t/* \\todo Add support for menu controls. */\n \twhile (1) {\n \t\tctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL |\n \t\t\t   V4L2_CTRL_FLAG_NEXT_COMPOUND;\n@@ -478,15 +523,22 @@ void V4L2Device::listControls()\n \t\t    ctrl.flags & V4L2_CTRL_FLAG_DISABLED)\n \t\t\tcontinue;\n \n+\t\tControlInfo ctrlInfo;\n \t\tswitch (ctrl.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\tcase V4L2_CTRL_TYPE_U8:\n+\t\t\tctrlInfo = V4L2ControlInfo(ctrl);\n+\t\t\tbreak;\n+\n+\t\tcase V4L2_CTRL_TYPE_INTEGER_MENU:\n+\t\tcase V4L2_CTRL_TYPE_MENU:\n+\t\t\tif (!createControlInfoForMenu(ctrl, ctrlInfo))\n+\t\t\t\tcontinue;\n+\n \t\t\tbreak;\n \t\t/* \\todo Support other control types. */\n \t\tdefault:\n@@ -496,10 +548,13 @@ void V4L2Device::listControls()\n \t\t\tcontinue;\n \t\t}\n \n+\t\tLOG(V4L2, Debug) << \"Control: \" << ctrl.name\n+\t\t\t\t << \" (\" << utils::hex(ctrl.id) << \")\";\n+\n \t\tcontrolIds_.emplace_back(std::make_unique<V4L2ControlId>(ctrl));\n \t\tcontrolInfo_.emplace(ctrl.id, ctrl);\n \n-\t\tctrls.emplace(controlIds_.back().get(), V4L2ControlInfo(ctrl));\n+\t\tctrls.emplace(controlIds_.back().get(), ctrlInfo);\n \t}\n \n \tcontrols_ = std::move(ctrls);\n@@ -523,6 +578,10 @@ void V4L2Device::updateControls(ControlList *ctrls,\n \t\t\tvalue.set<int64_t>(v4l2Ctrl.value64);\n \t\t\tbreak;\n \n+\t\tcase ControlTypeInteger32:\n+\t\t\tvalue.set<int64_t>(v4l2Ctrl.value);\n+\t\t\tbreak;\n+\n \t\tcase ControlTypeByte:\n \t\t\t/*\n \t\t\t * No action required, the VIDIOC_[GS]_EXT_CTRLS ioctl\n","prefixes":["libcamera-devel","v3","3/7"]}