{"id":11901,"url":"https://patchwork.libcamera.org/api/1.1/patches/11901/?format=json","web_url":"https://patchwork.libcamera.org/patch/11901/","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":"<20210413075013.3069213-3-hiroh@chromium.org>","date":"2021-04-13T07:50:10","name":"[libcamera-devel,RFC,v2,2/5] libcamera: V4L2Device: Support v4l2 menu control","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"7440c61e5b19cf55f3486594344c6a98dc70e971","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/1.1/people/63/?format=json","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/11901/mbox/","series":[{"id":1916,"url":"https://patchwork.libcamera.org/api/1.1/series/1916/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1916","date":"2021-04-13T07:50:08","name":"Report available test pattern modes","version":2,"mbox":"https://patchwork.libcamera.org/series/1916/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/11901/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/11901/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 39E44BD224\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 13 Apr 2021 07:50:30 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id E5D2C687F4;\n\tTue, 13 Apr 2021 09:50:29 +0200 (CEST)","from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com\n\t[IPv6:2607:f8b0:4864:20::62a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5E55B687F3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 13 Apr 2021 09:50:28 +0200 (CEST)","by mail-pl1-x62a.google.com with SMTP id u7so5954292plr.6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 13 Apr 2021 00:50:28 -0700 (PDT)","from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:2:84f5:7981:dfbe:8f02])\n\tby smtp.gmail.com with ESMTPSA id\n\tn25sm11525125pff.154.2021.04.13.00.50.24\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 13 Apr 2021 00:50:26 -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=\"cqXgrn7R\"; 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=MAtwUFk5YBMKGPW17l5Cri2kGo7Z4b7JfXgabycfy1c=;\n\tb=cqXgrn7RMo1C+moOSwJSu2xxQwlYOjcm6xBRKiDDsb8WplO7WGhSnxDfUJ5irOi4Kv\n\t7AclWc/iITMjYWItKP/IH+YtpZf5U3oVcp/tmjHDYTaRRpVVfiM9vNFmJdWAGof275fy\n\tCjkZVHwGOYmG2T9VUTNUcoH6yoOE5ekTic/o8=","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=MAtwUFk5YBMKGPW17l5Cri2kGo7Z4b7JfXgabycfy1c=;\n\tb=js2+i+veNTJJO/PZEL8CPnaz6xcUFU1NYCrOTNtDfyTvrANH9vx5FW2Tg/1V5qmUgD\n\thsuEcDxASB2yGOjbu77qm7450mjajPERZyGwPsvb9i8hGCLgtql9CRD7q/w99PI7GafR\n\t9pozDJXvWrT3YqW6Dce0Ovoa6hQOA2aNXpzzfWZxVrqGt38yecIyrd2/ql4L6bwImXQl\n\tHX9T7F0q/SB5iylQWyd9Fyf+nxNyxvwcwyUbHn7o1Lc5jwh8AmqQmUUwr8bNJ47cHIiI\n\trTCiAVARacenHof6IXRJ/6nt2WxH/gpNx50CwIg5J2lfJL1sACfhb2CMq4FNuW3Fabzi\n\tuR6w==","X-Gm-Message-State":"AOAM531AHu/K9iKUzukp7/nHeW9XucWzJgJ8UCr0adGloCSqig4ezwcd\n\tADDsc9K/T1ncbdHyRa82sshk8IPvii8stg==","X-Google-Smtp-Source":"ABdhPJwPvkewKroQmBBlT2acqbck/uV1EHpkepfWORUyUi7Q/VTX9JJWO8GtnGnq8fzG1wFiZLkIBg==","X-Received":"by 2002:a17:90a:9512:: with SMTP id\n\tt18mr3402540pjo.44.1618300226779; \n\tTue, 13 Apr 2021 00:50:26 -0700 (PDT)","From":"Hirokazu Honda <hiroh@chromium.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue, 13 Apr 2021 16:50:10 +0900","Message-Id":"<20210413075013.3069213-3-hiroh@chromium.org>","X-Mailer":"git-send-email 2.31.1.295.g9ea45b61b8-goog","In-Reply-To":"<20210413075013.3069213-1-hiroh@chromium.org>","References":"<20210413075013.3069213-1-hiroh@chromium.org>","MIME-Version":"1.0","Subject":"[libcamera-devel] [RFC PATCH v2 2/5] 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>","Cc":"jmondi@jacopo.org","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_controls.h |   1 +\n include/libcamera/internal/v4l2_device.h   |   3 +\n src/libcamera/v4l2_controls.cpp            |  10 +-\n src/libcamera/v4l2_device.cpp              | 104 ++++++++++++++++++++-\n 4 files changed, 112 insertions(+), 6 deletions(-)","diff":"diff --git a/include/libcamera/internal/v4l2_controls.h b/include/libcamera/internal/v4l2_controls.h\nindex 0851b8dd..c42f2529 100644\n--- a/include/libcamera/internal/v4l2_controls.h\n+++ b/include/libcamera/internal/v4l2_controls.h\n@@ -24,6 +24,7 @@ class V4L2ControlInfo : public ControlInfo\n {\n public:\n \tV4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl);\n+\tV4L2ControlInfo(const ControlInfo &ctrl);\n };\n \n } /* namespace libcamera */\ndiff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h\nindex 4cce3840..2436a83c 100644\n--- a/include/libcamera/internal/v4l2_device.h\n+++ b/include/libcamera/internal/v4l2_device.h\n@@ -53,6 +53,9 @@ protected:\n \tint fd() const { return fd_; }\n \n private:\n+\tbool createV4L2ControlInfoForMenu(const v4l2_query_ext_ctrl &ctrl,\n+\t\t\t\t\t  V4L2ControlInfo &v4l2CtrlInfo);\n+\n \tvoid listControls();\n \tvoid updateControls(ControlList *ctrls,\n \t\t\t    const std::vector<v4l2_ext_control> &v4l2Ctrls);\ndiff --git a/src/libcamera/v4l2_controls.cpp b/src/libcamera/v4l2_controls.cpp\nindex 3f8ec6ca..2c965cfa 100644\n--- a/src/libcamera/v4l2_controls.cpp\n+++ b/src/libcamera/v4l2_controls.cpp\n@@ -73,9 +73,12 @@ ControlType v4l2_ctrl_type(const struct v4l2_query_ext_ctrl &ctrl)\n \t\treturn ControlTypeInteger64;\n \n \tcase V4L2_CTRL_TYPE_MENU:\n+\tcase V4L2_CTRL_TYPE_INTEGER_MENU:\n+\t\treturn ControlTypeMenu;\n+\n \tcase V4L2_CTRL_TYPE_BUTTON:\n \tcase V4L2_CTRL_TYPE_BITMASK:\n-\tcase V4L2_CTRL_TYPE_INTEGER_MENU:\n+\n \t\t/*\n \t\t * More precise types may be needed, for now use a 32-bit\n \t\t * integer type.\n@@ -148,4 +151,9 @@ V4L2ControlInfo::V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl)\n \t}\n }\n \n+V4L2ControlInfo::V4L2ControlInfo(const ControlInfo &ctrl)\n+\t: ControlInfo(ctrl)\n+{\n+}\n+\n } /* namespace libcamera */\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex 8f29cd7f..7fbca8b1 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -10,6 +10,7 @@\n #include <fcntl.h>\n #include <iomanip>\n #include <limits.h>\n+#include <linux/intel-ipu3.h>\n #include <stdlib.h>\n #include <string.h>\n #include <sys/ioctl.h>\n@@ -459,6 +460,60 @@ int V4L2Device::ioctl(unsigned long request, void *argp)\n  * \\return The device node path\n  */\n \n+bool V4L2Device::createV4L2ControlInfoForMenu(const v4l2_query_ext_ctrl &ctrl,\n+\t\t\t\t\t      V4L2ControlInfo &v4l2CtrlInfo)\n+{\n+\tASSERT(ctrl.type == V4L2_CTRL_TYPE_MENU ||\n+\t       ctrl.type == V4L2_CTRL_TYPE_INTEGER_MENU);\n+\tbool isName = false;\n+\tswitch (ctrl.id) {\n+\tcase V4L2_CID_TEST_PATTERN:\n+\tcase V4L2_CID_INTEL_IPU3_MODE:\n+\t\tisName = true;\n+\t\tbreak;\n+\tcase V4L2_CID_LINK_FREQ:\n+\t\tisName = false;\n+\t\tbreak;\n+\tdefault:\n+\t\tLOG(V4L2, Error) << \"Unsupported menu: \" << ctrl.name\n+\t\t\t\t << \" (\" << utils::hex(ctrl.id) << \")\";\n+\t\treturn false;\n+\t}\n+\n+\tstd::vector<ControlValue> values;\n+\tv4l2_querymenu menu;\n+\tmemset(&menu, 0, sizeof(menu));\n+\tmenu.id = ctrl.id;\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+\t\tControlMenu ctrlMenu;\n+\t\tctrlMenu.index = static_cast<int32_t>(menu.index);\n+\t\tctrlMenu.isName = isName;\n+\t\tif (isName) {\n+\t\t\tstrcpy(ctrlMenu.name,\n+\t\t\t       reinterpret_cast<const char *>(menu.name));\n+\t\t} else {\n+\t\t\tctrlMenu.value = menu.value;\n+\t\t}\n+\n+\t\tvalues.push_back(ControlValue(ctrlMenu));\n+\t}\n+\n+\tif (values.empty()) {\n+\t\tLOG(V4L2, Error)\n+\t\t\t<< \"No applicable value: \" << utils::hex(ctrl.id);\n+\t\treturn false;\n+\t}\n+\n+\tv4l2CtrlInfo = V4L2ControlInfo(\n+\t\tControlInfo(libcamera::Span<const ControlValue>(\n+\t\t\tvalues.data(), values.size())));\n+\n+\treturn true;\n+}\n+\n /**\n  * \\fn V4L2Device::fd()\n  * \\brief Retrieve the V4L2 device file descriptor\n@@ -474,7 +529,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@@ -485,15 +539,20 @@ void V4L2Device::listControls()\n \t\t    ctrl.flags & V4L2_CTRL_FLAG_DISABLED)\n \t\t\tcontinue;\n \n+\t\tV4L2ControlInfo v4l2CtrlInfo(ControlInfo(0));\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\tv4l2CtrlInfo = V4L2ControlInfo(ctrl);\n+\t\t\tbreak;\n+\t\tcase V4L2_CTRL_TYPE_MENU:\n+\t\tcase V4L2_CTRL_TYPE_INTEGER_MENU:\n+\t\t\tif (!createV4L2ControlInfoForMenu(ctrl, v4l2CtrlInfo))\n+\t\t\t\tcontinue;\n \t\t\tbreak;\n \t\t/* \\todo Support other control types. */\n \t\tdefault:\n@@ -503,10 +562,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(), std::move(v4l2CtrlInfo));\n \t}\n \n \tcontrols_ = std::move(ctrls);\n@@ -539,7 +601,39 @@ void V4L2Device::updateControls(ControlList *ctrls,\n \t\tcase ControlTypeInteger64:\n \t\t\tnewValue.set<int64_t>(v4l2Ctrl.value64);\n \t\t\tbreak;\n-\n+\t\tcase ControlTypeMenu:\n+\t\t\tswitch (v4l2Ctrl.id) {\n+\t\t\tcase V4L2_CID_TEST_PATTERN: {\n+\t\t\t\tControlMenu menu;\n+\t\t\t\tmenu.index = v4l2Ctrl.value;\n+\t\t\t\tmenu.isName = true;\n+\n+\t\t\t\tbool found = false;\n+\t\t\t\tfor (const ControlValue &validValue : it->second.values()) {\n+\t\t\t\t\tconst auto &ctrlMenu = validValue.get<ControlMenu>();\n+\t\t\t\t\tif (!ctrlMenu.isName)\n+\t\t\t\t\t\tcontinue;\n+\t\t\t\t\tif (menu.index == ctrlMenu.index) {\n+\t\t\t\t\t\tstrcpy(menu.name, ctrlMenu.name);\n+\t\t\t\t\t\tfound = true;\n+\t\t\t\t\t\tbreak;\n+\t\t\t\t\t}\n+\t\t\t\t}\n+\n+\t\t\t\tif (!found) {\n+\t\t\t\t\tLOG(V4L2, Error)\n+\t\t\t\t\t\t<< \"Matched value is not found\"\n+\t\t\t\t\t\t<< \", index=\" << menu.index;\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\n+\t\t\t\tnewValue.set<ControlMenu>(menu);\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tdefault:\n+\t\t\t\tLOG(V4L2, Error) << \"Unknown id: \" << v4l2Ctrl.id;\n+\t\t\t\tbreak;\n+\t\t\t}\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","RFC","v2","2/5"]}