{"id":12316,"url":"https://patchwork.libcamera.org/api/1.1/patches/12316/?format=json","web_url":"https://patchwork.libcamera.org/patch/12316/","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":"<20210519075941.1337388-2-hiroh@chromium.org>","date":"2021-05-19T07:59:37","name":"[libcamera-devel,v5,2/6] libcamera: V4L2Device: Support v4l2 menu control","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"40aa6619d89cff8f0f92656d6a36f02d944034b0","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/12316/mbox/","series":[{"id":2037,"url":"https://patchwork.libcamera.org/api/1.1/series/2037/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2037","date":"2021-05-19T07:59:36","name":"[libcamera-devel,v5,1/6] libcamera: controls: Add sensor test pattern mode","version":5,"mbox":"https://patchwork.libcamera.org/series/2037/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/12316/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/12316/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 456DAC31FF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 19 May 2021 07:59:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0600C68923;\n\tWed, 19 May 2021 09:59:52 +0200 (CEST)","from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com\n\t[IPv6:2607:f8b0:4864:20::1029])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 86DEB68919\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 19 May 2021 09:59:50 +0200 (CEST)","by mail-pj1-x1029.google.com with SMTP id\n\tn6-20020a17090ac686b029015d2f7aeea8so3068726pjt.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 19 May 2021 00:59:50 -0700 (PDT)","from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:2:3948:91a2:b8ec:1976])\n\tby smtp.gmail.com with ESMTPSA id\n\t80sm1160847pfw.200.2021.05.19.00.59.47\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 19 May 2021 00:59:48 -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=\"g05lM9Hh\"; 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=XvpU9XSIklCLusLhGV0gcYd6hZ2nh7eCwQ9FWr7nZx8=;\n\tb=g05lM9HhDD/FOJV0y1DdtA3XJVmdufOpXgRoDenyrL0AWc4HlVlsFSNwtaf2DELiNy\n\tN2+YdxV/0zZ19nAqzoWzEd+TZv8zk20X9QlPYcvRibu7480glmnw+xwiOYnXb8QXPyo3\n\tnQKaqVVKArv3tk2QQiayNSAvLlp8Q0OC+Q/8o=","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=XvpU9XSIklCLusLhGV0gcYd6hZ2nh7eCwQ9FWr7nZx8=;\n\tb=IJQQpoSrlChi8tTb9hdS5DXUlF1br+yseVTeQd2tSCZCkX+ucDA28H0pDqqAqU2uVs\n\ttx8C3AfuxoUMCCfTLjX+9ZsHp1rBCmfU17JGUJecKUtWGS+GnKZTEuPki+H5R8jzLC4A\n\tX7jRVKkB2kqZE9Maq7aL5d3q9gmAZOZGpnWtSs6hs6O6SZGFiT8cGIYS3vB8dC7yRRbT\n\t+K7aFhSHCKufiY3arZYG8epPp7XERFcoffxv8SZgdQPPoVBpC/kqklTzsBOp2bD+zUdw\n\tDQ3ylxMEm++qokANpLIQw4NRuiMonGnvp4eRIQhNa/pwkP/He5p9rH7acX0rzQ4Lkbmy\n\tFkPQ==","X-Gm-Message-State":"AOAM531YnTfLlxCFd2kcitkHvpnDPnmJWyLQ0RivPIZYowih+q2hB4A+\n\tFSgnF1jjBZJZ8hYNvp9VeJnG2s1gGEG+qQ==","X-Google-Smtp-Source":"ABdhPJwF9VBs94sy+iOo9XykSWn698oAJpK0Rp+zKzPP9hrnwwFw8HT0HUIct4mv1B7pczJr2uD9pA==","X-Received":"by 2002:a17:902:8a8a:b029:ec:857a:4d51 with SMTP id\n\tp10-20020a1709028a8ab02900ec857a4d51mr9375219plo.68.1621411188894; \n\tWed, 19 May 2021 00:59:48 -0700 (PDT)","From":"Hirokazu Honda <hiroh@chromium.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 19 May 2021 16:59:37 +0900","Message-Id":"<20210519075941.1337388-2-hiroh@chromium.org>","X-Mailer":"git-send-email 2.31.1.751.gd2f1c929bd-goog","In-Reply-To":"<20210519075941.1337388-1-hiroh@chromium.org>","References":"<20210519075941.1337388-1-hiroh@chromium.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v5 2/6] 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>","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. The control info for v4l2 menu\ncontains indices without names and 64bit values of querymenu.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n include/libcamera/internal/v4l2_device.h |  3 ++\n src/libcamera/v4l2_device.cpp            | 64 ++++++++++++++++++++++--\n 2 files changed, 63 insertions(+), 4 deletions(-)","diff":"diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h\nindex 5ba9b23b..34080b07 100644\n--- a/include/libcamera/internal/v4l2_device.h\n+++ b/include/libcamera/internal/v4l2_device.h\n@@ -56,6 +56,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 515cbdfe..9f7873f1 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -464,6 +464,49 @@ int V4L2Device::ioctl(unsigned long request, void *argp)\n  * \\return The V4L2 device file descriptor, -1 if the device node is not open\n  */\n \n+/**\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+\n+\tstd::vector<ControlValue> indices;\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}\n+\n+\tif (indices.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);\n+\n+\treturn true;\n+}\n+\n /*\n  * \\brief List and store information about all controls supported by the\n  * V4L2 device\n@@ -473,7 +516,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@@ -484,15 +526,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@@ -502,10 +551,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@@ -572,6 +624,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<int32_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","v5","2/6"]}