From patchwork Wed Apr 28 07:36:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12126 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 65005BDE44 for ; Wed, 28 Apr 2021 07:36:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BDDDE688CE; Wed, 28 Apr 2021 09:36:32 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="BnBMCfgr"; dkim-atps=neutral Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3B90B688B7 for ; Wed, 28 Apr 2021 09:36:29 +0200 (CEST) Received: by mail-pf1-x430.google.com with SMTP id a12so826138pfc.7 for ; Wed, 28 Apr 2021 00:36:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QMJniqxYRSeszAKe+yuZv/Z9+aZeAH8IQy9wC+Uydis=; b=BnBMCfgrb0eKcJuBIlyv26FSxME/KvskKOjap32veA2nn5bHpTsDY+58epHqKHccrz a068KxWTS1s6Cz+BaXd+OgkhnuwtQhdCzICDjXWpoSK80WI3a2yIMyp6Fla6EUgjzNyO gg8KNRpey0CZqbFr/P+/xVuula8JNeID3oHkY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QMJniqxYRSeszAKe+yuZv/Z9+aZeAH8IQy9wC+Uydis=; b=NyOjTSi2aZXDyB6jrInqhfSayCFDmcS9Ot3U6bpRgHKpJYDvxApJVh4vs+9Qw/Pmd9 Lke4pqCWKSmxOnPGoRPrO5exP2lwQxYN3W6cT9klcxCjqJVlXOrg4Yb7pgW9B/E7lmR7 qqo/3YMJWZO9PvofF2z1EdHOl5fJqtdePfnV3va9gHFjH7mGrQ/iaxR7svj2PPerN06H BGWl1hTGURUHZv04dSTKJ/Il9KTWegSC/RsqK3lKIX4fy1XTiLJosvB2ItdwS/T/dXRC wEh2jiY5aB5rH0EOuOCI+9MtwPk0ah1aSQXLNiLcUbvLLo6jMefkWtt2pQS49S8TTAWh wIjg== X-Gm-Message-State: AOAM531YeVMFhbtMBn71+yRtvYBCZcZkirvzGya6xz3dVyDbaCJD8NuF oLuSJunW7ME0T0spbN5EI+gEE3jYQf82AQ== X-Google-Smtp-Source: ABdhPJxCn/TSPoVM3E7yX6NwuKMMsAp9Qc0OBUcRvL+23/EmkLSk/vSsDaldqdCKTAqaKTDBXvIEWw== X-Received: by 2002:a62:aa09:0:b029:25c:3c28:e2b with SMTP id e9-20020a62aa090000b029025c3c280e2bmr26414320pff.39.1619595387417; Wed, 28 Apr 2021 00:36:27 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:489:a5f4:117:7d51]) by smtp.gmail.com with ESMTPSA id m11sm1661265pgs.4.2021.04.28.00.36.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Apr 2021 00:36:27 -0700 (PDT) From: Hirokazu Honda 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 v4l2 menu control X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This adds a support of v4l2 menu. Signed-off-by: Hirokazu Honda --- include/libcamera/internal/v4l2_device.h | 3 + src/libcamera/v4l2_device.cpp | 73 +++++++++++++++++++++--- 2 files changed, 69 insertions(+), 7 deletions(-) diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h index 087f07e7..c7a2539c 100644 --- a/include/libcamera/internal/v4l2_device.h +++ b/include/libcamera/internal/v4l2_device.h @@ -54,6 +54,9 @@ protected: int fd() const { return fd_; } private: + bool createControlInfoForMenu(const v4l2_query_ext_ctrl &ctrl, + ControlInfo &ctrlInfo); + void listControls(); void updateControls(ControlList *ctrls, Span v4l2Ctrls); diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 64501523..f2a9038e 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -446,6 +446,7 @@ int V4L2Device::ioctl(unsigned long request, void *argp) return 0; } + /** * \fn V4L2Device::deviceNode() * \brief Retrieve the device node path @@ -453,10 +454,55 @@ int V4L2Device::ioctl(unsigned long request, void *argp) */ /** - * \fn V4L2Device::fd() - * \brief Retrieve the V4L2 device file descriptor - * \return The V4L2 device file descriptor, -1 if the device node is not open + * \brief Create ControlInfo for v4l2 menu ctrl. + * \param[in] ctrl The v4l2_query_ext_ctrl that represents a menu + * \param[out] ctrlInfo The created controlInfo + * + * The created ControlInfo contains not only values and also extra values, which + * are indices and name/value acquired by VIDIOC_QUERYMENU, respectively. The + * extra values contains std::string if the type of \a ctrl is + * V4L2_CTRL_TYPE_MENU or int64_t otherwise. + * + * \return True on success or false otherwise */ +bool V4L2Device::createControlInfoForMenu(const v4l2_query_ext_ctrl &ctrl, + ControlInfo &ctrlInfo) +{ + ASSERT(ctrl.type == V4L2_CTRL_TYPE_MENU || + ctrl.type == V4L2_CTRL_TYPE_INTEGER_MENU); + const bool isName = ctrl.type == V4L2_CTRL_TYPE_MENU; + + std::vector indices; + std::vector values; + v4l2_querymenu menu; + memset(&menu, 0, sizeof(menu)); + menu.id = ctrl.id; + + for (menu.index = ctrl.minimum; + static_cast(menu.index) <= ctrl.maximum; menu.index++) { + if (ioctl(VIDIOC_QUERYMENU, &menu) != 0) + continue; + + indices.emplace_back(static_cast(menu.index)); + if (isName) { + std::string name(reinterpret_cast(menu.name)); + values.emplace_back(std::move(name)); + } else { + values.emplace_back(static_cast(menu.value)); + } + } + + if (values.empty()) { + LOG(V4L2, Error) + << "No applicable value: " << utils::hex(ctrl.id); + + return false; + } + + ctrlInfo = ControlInfo(indices, values); + + return true; +} /* * \brief List and store information about all controls supported by the @@ -467,7 +513,6 @@ void V4L2Device::listControls() ControlInfoMap::Map ctrls; struct v4l2_query_ext_ctrl ctrl = {}; - /* \todo Add support for menu controls. */ while (1) { ctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL | V4L2_CTRL_FLAG_NEXT_COMPOUND; @@ -478,15 +523,22 @@ void V4L2Device::listControls() ctrl.flags & V4L2_CTRL_FLAG_DISABLED) continue; + ControlInfo ctrlInfo; switch (ctrl.type) { case V4L2_CTRL_TYPE_INTEGER: case V4L2_CTRL_TYPE_BOOLEAN: - case V4L2_CTRL_TYPE_MENU: case V4L2_CTRL_TYPE_BUTTON: case V4L2_CTRL_TYPE_INTEGER64: case V4L2_CTRL_TYPE_BITMASK: - case V4L2_CTRL_TYPE_INTEGER_MENU: case V4L2_CTRL_TYPE_U8: + ctrlInfo = V4L2ControlInfo(ctrl); + break; + + case V4L2_CTRL_TYPE_INTEGER_MENU: + case V4L2_CTRL_TYPE_MENU: + if (!createControlInfoForMenu(ctrl, ctrlInfo)) + continue; + break; /* \todo Support other control types. */ default: @@ -496,10 +548,13 @@ void V4L2Device::listControls() continue; } + LOG(V4L2, Debug) << "Control: " << ctrl.name + << " (" << utils::hex(ctrl.id) << ")"; + controlIds_.emplace_back(std::make_unique(ctrl)); controlInfo_.emplace(ctrl.id, ctrl); - ctrls.emplace(controlIds_.back().get(), V4L2ControlInfo(ctrl)); + ctrls.emplace(controlIds_.back().get(), ctrlInfo); } controls_ = std::move(ctrls); @@ -523,6 +578,10 @@ void V4L2Device::updateControls(ControlList *ctrls, value.set(v4l2Ctrl.value64); break; + case ControlTypeInteger32: + value.set(v4l2Ctrl.value); + break; + case ControlTypeByte: /* * No action required, the VIDIOC_[GS]_EXT_CTRLS ioctl