From patchwork Thu May 6 07:54:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12201 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 66A38BDE7F for ; Thu, 6 May 2021 07:55:03 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0739568922; Thu, 6 May 2021 09:55:03 +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="m1ZaEHBe"; dkim-atps=neutral Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 89A3068920 for ; Thu, 6 May 2021 09:55:00 +0200 (CEST) Received: by mail-pg1-x533.google.com with SMTP id y30so4148951pgl.7 for ; Thu, 06 May 2021 00:55:00 -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=vm6DZPElqUWcJh+QMJO2afXSbmkGZ/M93CLmkyHXhNY=; b=m1ZaEHBeu1VZS3yo0iRyFdisSTo1QExcRSyGjdvvufR9JMIqthLXf3eXoaQk+Ob+h/ Q2lGmkOqmXy+GFpcFaN139eGvFkubwBKw/BcqVC2gQIACpjWT/N2zOSW1RL8KYgC3hd1 9bHldDfZxp6bFXfKg8lcvDPcGWrYe9x4gowps= 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=vm6DZPElqUWcJh+QMJO2afXSbmkGZ/M93CLmkyHXhNY=; b=Ug6BcZymk76RnvKw7U2G0CGO37mg3rEioF+KVFFnHG8+tVKVOZ/vX8wVd7PTnBSi/g S+dW/Gf8uxRO2VZeYf1QVgGPNAIi5u4b0TTXZj2MP9BEWTt1KCNnkf9StTmU9AhTBb51 21+K/L6hsTyC3wiQtvzlqjrcxHN+0dRsriQtlU+lgT7MJEUpnSscaAdUbsGtbfDbQuhR grqB+LatkRJOlQi0zg8fdXrt/W4M93Nw2xKUh4Ocf7uOcYdTBvWY9U49PEGu/vNdRKSo gj5YJEIg4GismrJEg+MvOT32hjXjuUSLkWBGTi8KM21DO30FOPapDF6lrFGpzYohIXFd 4/zA== X-Gm-Message-State: AOAM5325OSaMizDcgVnw3tB8k5/LUfF8Os3JZ5oLlJ2CF1knPWDEDkUO LVykFFw7atucaKPiNbmggSjSDL3bzgXoBA== X-Google-Smtp-Source: ABdhPJzY+MGgdFk2ondpyNAAUe5+VkcnL/sylVGx7LNESWkVvSVZEMFyWi9J+dCjE2UkXoFyUDmI9A== X-Received: by 2002:a62:75c3:0:b029:27c:d30f:66a6 with SMTP id q186-20020a6275c30000b029027cd30f66a6mr3399930pfc.0.1620287698837; Thu, 06 May 2021 00:54:58 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:ede4:ae0e:d4a4:c0d3]) by smtp.gmail.com with ESMTPSA id f201sm1355546pfa.133.2021.05.06.00.54.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 May 2021 00:54:58 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Thu, 6 May 2021 16:54:45 +0900 Message-Id: <20210506075449.1761752-3-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.607.g51e8a6a459-goog In-Reply-To: <20210506075449.1761752-1-hiroh@chromium.org> References: <20210506075449.1761752-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 2/6] 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. The control info for v4l2 menu contains indices without names and 64bit values of querymenu. Signed-off-by: Hirokazu Honda --- include/libcamera/internal/v4l2_device.h | 3 ++ src/libcamera/v4l2_device.cpp | 65 +++++++++++++++++++++--- 2 files changed, 61 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 397029ac..7056c71a 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -452,6 +452,7 @@ int V4L2Device::ioctl(unsigned long request, void *argp) return 0; } + /** * \fn V4L2Device::deviceNode() * \brief Retrieve the device node path @@ -459,10 +460,47 @@ 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); + + std::vector indices; + 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 (indices.empty()) { + LOG(V4L2, Error) + << "No applicable value: " << utils::hex(ctrl.id); + + return false; + } + + ctrlInfo = ControlInfo(indices); + + return true; +} /* * \brief List and store information about all controls supported by the @@ -473,7 +511,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; @@ -484,15 +521,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: @@ -502,10 +546,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); @@ -535,6 +582,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