From patchwork Fri May 28 03:05:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12464 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 1CA15C3205 for ; Fri, 28 May 2021 03:05:42 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D126A6891E; Fri, 28 May 2021 05:05:41 +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="acjk/D7L"; 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 C558B6891D for ; Fri, 28 May 2021 05:05:39 +0200 (CEST) Received: by mail-pf1-x430.google.com with SMTP id y15so2136853pfn.13 for ; Thu, 27 May 2021 20:05:39 -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=oFqBC1evGDoYaQp4OZbBwiSe0Fjh0ge5LISerDTqP00=; b=acjk/D7LLgl8i/d1XqfAxvasis026S0I3S+TlWWjdhd2ALdRVQEInMsO1iqanRizHT CUWfU3Y2CQAD2G+POeJUexCAWfFqJSI6vbOhKxRa2yjbwMUJwOdx8O3E09Ad1eN2ayi6 bTcNYeRU62RdOKzSuG20Wr9VZOd4mL18PJOuo= 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=oFqBC1evGDoYaQp4OZbBwiSe0Fjh0ge5LISerDTqP00=; b=c+Uc5Ew/t5r40hJAoKLTdshWmk+a81XCdMMEBj8vdzszhsc+Mj09hOejqiLH2RsPbd pTb4tUWgr7rUw/FE3Ih49AXRYo/L/q11hBIx4CIb/09Ag17PGsJPXrBd6WbFxD3OvvhB 4zlrmTlk0F/gUOgXS61d476g6RMFEyK5KbQf5H3WrplU/y2vTgEacr5y035GK59dqgES hnQJTgM779BM9XNhD39pO/7zFGgbLOML1WSfkVgykTnKAIrrt5uVnQIx3+nmgS1Qb56V TSSufozkFdchS26Afmad99qlZmlN4jjbwozHGpnbpFuAqHNmIXQWt/+Ky/q4uZNnKJop ys3Q== X-Gm-Message-State: AOAM532TQCIbkFoiFWB26Fdz5SpdcJTCXPHK39P0D6QNi48zL4gZMdWx 4VE/wOkgFZsU/YpxF3ZhB2RhmW0LlPuJwg== X-Google-Smtp-Source: ABdhPJzeyP/3xNelM89a/stvmQdRPU/TdbUrKXmLo2jDZIoyW/yDL1lU6myfjIs3IKmNpShLKyIwVg== X-Received: by 2002:a62:8389:0:b029:27d:28f4:d583 with SMTP id h131-20020a6283890000b029027d28f4d583mr1669540pfe.33.1622171138207; Thu, 27 May 2021 20:05:38 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:caec:ab3b:ea16:3d01]) by smtp.gmail.com with ESMTPSA id l20sm2892051pjq.38.2021.05.27.20.05.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 May 2021 20:05:37 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Fri, 28 May 2021 12:05:27 +0900 Message-Id: <20210528030531.189492-2-hiroh@chromium.org> X-Mailer: git-send-email 2.32.0.rc0.204.g9fa02ecfa5-goog In-Reply-To: <20210528030531.189492-1-hiroh@chromium.org> References: <20210528030531.189492-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v6 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 | 2 + src/libcamera/v4l2_device.cpp | 47 ++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h index b82e2a14..687be9b2 100644 --- a/include/libcamera/internal/v4l2_device.h +++ b/include/libcamera/internal/v4l2_device.h @@ -56,6 +56,8 @@ protected: int fd() const { return fd_; } private: + ControlInfo v4l2MenuControlInfo(const v4l2_query_ext_ctrl &ctrl); + void listControls(); void updateControls(ControlList *ctrls, Span v4l2Ctrls); diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index caafbc2d..032252bb 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -530,6 +530,33 @@ int V4L2Device::ioctl(unsigned long request, void *argp) * \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 indices acquired by VIDIOC_QUERYMENU. + * + * \return ControlInfo for v4l2 menu ctrl. + */ +ControlInfo V4L2Device::v4l2MenuControlInfo(const v4l2_query_ext_ctrl &ctrl) +{ + 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)); + } + + return ControlInfo(indices); +} + /* * \brief List and store information about all controls supported by the * V4L2 device @@ -539,7 +566,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; @@ -550,16 +576,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: + ctrlInfo = v4l2MenuControlInfo(ctrl); break; + /* \todo Support other control types. */ default: LOG(V4L2, Debug) @@ -568,10 +600,13 @@ void V4L2Device::listControls() continue; } + LOG(V4L2, Debug) << "Control: " << ctrl.name + << " (" << utils::hex(ctrl.id) << ")"; + controlIds_.emplace_back(v4l2ControlId(ctrl)); controlInfo_.emplace(ctrl.id, ctrl); - ctrls.emplace(controlIds_.back().get(), v4l2ControlInfo(ctrl)); + ctrls.emplace(controlIds_.back().get(), std::move(ctrlInfo)); } controls_ = std::move(ctrls); @@ -638,6 +673,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