{"id":12020,"url":"https://patchwork.libcamera.org/api/patches/12020/?format=json","web_url":"https://patchwork.libcamera.org/patch/12020/","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":"<20210421042346.312854-4-hiroh@chromium.org>","date":"2021-04-21T04:23:42","name":"[libcamera-devel,v2,3/7] libcamera: V4L2Device: Support v4l2 menu control","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"fc5e533ef0337bd05d82f6e538db954d4b4b59de","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/12020/mbox/","series":[{"id":1953,"url":"https://patchwork.libcamera.org/api/series/1953/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1953","date":"2021-04-21T04:23:39","name":"Report Android HAL client test pattern modes","version":2,"mbox":"https://patchwork.libcamera.org/series/1953/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/12020/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/12020/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 E3377BDB16\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 21 Apr 2021 04:24:01 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6B0FC68848;\n\tWed, 21 Apr 2021 06:24:01 +0200 (CEST)","from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com\n\t[IPv6:2607:f8b0:4864:20::52a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 53A2468839\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 21 Apr 2021 06:24:00 +0200 (CEST)","by mail-pg1-x52a.google.com with SMTP id p12so28545825pgj.10\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 20 Apr 2021 21:24:00 -0700 (PDT)","from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:2:7aaa:cbeb:5d87:4ab6])\n\tby smtp.gmail.com with ESMTPSA id\n\tz18sm461316pfa.39.2021.04.20.21.23.57\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 20 Apr 2021 21:23:58 -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=\"kvXPIsgM\"; 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=v7vOsb8DbMt3IBCLrf+iB6KOuge3VtWhyJKcdnF4+ec=;\n\tb=kvXPIsgM1Uuxj5tzi9tiFm+TbqRGqzk1VabmBVMAqEOYOWbbHZ9Xul9LSEZkKoV1DV\n\tpnuc8NYdQYe1sLydZ3MVTvMA4xI554Fmq6GXmVLnCHu9ArEfvERAljwOmvw+pV9CpCfL\n\tCDPQq2rPmorCQhnBp+EAgSV7Pf7yElTt/n4qg=","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=v7vOsb8DbMt3IBCLrf+iB6KOuge3VtWhyJKcdnF4+ec=;\n\tb=DxIpXjf0ucJdGi6Ql1KGIaYnQ8ppZpSz15ogbBlE4ypU/V7v5363alskN61MPfMF2l\n\t93YRl4uHmZdyv2kHSure1r6OkfdSrN73TMt/wvl8Paf6Ta1kTkemoEKEIzE3Sy+AjsUH\n\t62tfrg80Evq+pAVUmgy7TSbFCctBCpv0Z/rQWAdbwmkjL5tQpfDJmA4HrEMFhWzWjz6i\n\tgMCYmxvQdllc4dH50iNorNJ3t1KhJgA0Faz8P2m8BBP1AF0ladvFgZpsGPekIFxk3K4+\n\twn8C8aTkug+6v2x5qKLZP7QtQT8gpnEEPfu9tjNy3Ag5q1wJOHMh6f4l7RvHxMnXvlWU\n\tIUsA==","X-Gm-Message-State":"AOAM533q9xD0TZmKN9nXFYyvltv7V54e5csvjNg6HEvElVFuk8DooQqa\n\t7fNkVS//jty3ZTiNOWhepjbCFjHaYPnxfw==","X-Google-Smtp-Source":"ABdhPJwWtjwSTNk8tuAsQNm301roTJGBuYP+e8iVCMNV1R1+umgHv8G7PX/8PFCKm5bz8SW27k9W+w==","X-Received":"by 2002:a17:90a:b947:: with SMTP id\n\tf7mr8513650pjw.166.1618979038777; \n\tTue, 20 Apr 2021 21:23:58 -0700 (PDT)","From":"Hirokazu Honda <hiroh@chromium.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 21 Apr 2021 13:23:42 +0900","Message-Id":"<20210421042346.312854-4-hiroh@chromium.org>","X-Mailer":"git-send-email 2.31.1.368.gbe11c130af-goog","In-Reply-To":"<20210421042346.312854-1-hiroh@chromium.org>","References":"<20210421042346.312854-1-hiroh@chromium.org>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v2 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_controls.h |  1 +\n include/libcamera/internal/v4l2_device.h   |  3 +\n src/libcamera/v4l2_controls.cpp            | 10 ++-\n src/libcamera/v4l2_device.cpp              | 90 ++++++++++++++++++++--\n 4 files changed, 98 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..585e527b 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -459,6 +459,47 @@ 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+\tconst bool isName = ctrl.type == V4L2_CTRL_TYPE_MENU;\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 +515,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 +525,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 +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(), std::move(v4l2CtrlInfo));\n \t}\n \n \tcontrols_ = std::move(ctrls);\n@@ -539,7 +587,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","v2","3/7"]}