From patchwork Mon Jun 7 01:13:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 12495 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 AE378C320B for ; Mon, 7 Jun 2021 01:14:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A3F566892E; Mon, 7 Jun 2021 03:14:11 +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="jJHB4uWS"; dkim-atps=neutral Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B570268925 for ; Mon, 7 Jun 2021 03:14:10 +0200 (CEST) Received: by mail-pl1-x62f.google.com with SMTP id v12so7716562plo.10 for ; Sun, 06 Jun 2021 18:14:10 -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=nIXJzulVYV45F/GbsYfMi+KlzCrxZO8w1wziyYXO8mA=; b=jJHB4uWS9MQCiaqor9jjpoS70Ai39V1EFCfeyxjXj7MgpeiZmLdJlw+oGt7tISDCvA mdSQmEdaA64n+p8y7lgmJET+zhHJYM6xaau9OOrE4c7gwB0eJ8rzaxPUBcufpY5Pgeyq zv2jdQLRZOChZ5oxcSciSbsskMp1RXYv08x6I= 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=nIXJzulVYV45F/GbsYfMi+KlzCrxZO8w1wziyYXO8mA=; b=MrCGysRS6IHC4zLC2q5DBZYhs+piGlzofPl5Lxz+R5kPp70jXjK/mncT6V22AfQ+o8 AS5nv6Q7NmmehZ9dhn7wX4xNHjqvdtwL4EBCSgIJ6OQTpR/Kmz1HNN5gmTWzTUYFI0Xl RiLJSV9WASm3Eu1PidjblaEGI6CtX87Bd9b475ISJt1+XkfdaLpgIVszSmaTDv2+DnNm RQhH9YtEVgvSsrVbl8qbESf5UGQz5XytQyqpXRy+ZOjyfUWIF3/DDFJA2w91v+HXaqUD /6uZTcz4GejtmQvnvGChwaSZv0ZV7pNxt1oxzueq0Htxb4aXSTm1FUr/hRss3dWcxkyv bZGg== X-Gm-Message-State: AOAM531GpSNHD1btyA3x8xNJf1uACWoQ/4/eYoHoRQEKAaDS709yKkel xUyiZ7TaRVsnrGMJa4v++AxZoUV/QL5byQ== X-Google-Smtp-Source: ABdhPJx9FL2pqdJ5LgAW9CdTtFNCMGfxqLpLQ7aFweyu5rwPLjLHsqeeCqZD0HnKaDe+kW3VbZ6M8g== X-Received: by 2002:a17:902:8602:b029:10b:df79:d7ca with SMTP id f2-20020a1709028602b029010bdf79d7camr15524384plo.56.1623028448928; Sun, 06 Jun 2021 18:14:08 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:203:6eb1:2d91:79ee:2043]) by smtp.gmail.com with ESMTPSA id h12sm7303655pgn.54.2021.06.06.18.14.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Jun 2021 18:14:08 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 7 Jun 2021 10:13:58 +0900 Message-Id: <20210607011402.55331-2-hiroh@chromium.org> X-Mailer: git-send-email 2.32.0.rc1.229.g3e70b5a671-goog In-Reply-To: <20210607011402.55331-1-hiroh@chromium.org> References: <20210607011402.55331-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v7 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 Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- include/libcamera/internal/v4l2_device.h | 2 + src/libcamera/v4l2_device.cpp | 53 ++++++++++++++++++++++-- 2 files changed, 51 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 b39c6266..40e2c74c 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -524,6 +524,38 @@ 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 a V4L2 menu ctrl + * \param[in] ctrl The v4l2_query_ext_ctrl that represents a menu + * + * The created ControlInfo contains indices acquired by VIDIOC_QUERYMENU. + * + * \return ControlInfo for a V4L2 menu ctrl. + */ +ControlInfo V4L2Device::v4l2MenuControlInfo( + const struct v4l2_query_ext_ctrl &ctrl) +{ + std::vector indices; + struct v4l2_querymenu menu = {}; + menu.id = ctrl.id; + + if (ctrl.minimum < 0) + return ControlInfo(); + + ControlValue def = {}; + for (int32_t index = ctrl.minimum; index <= ctrl.maximum; ++index) { + menu.index = index; + if (ioctl(VIDIOC_QUERYMENU, &menu) != 0) + continue; + + indices.push_back(index); + if (index == ctrl.default_value) + def = ControlValue(index); + } + + return ControlInfo(indices, def); +} + /* * \brief List and store information about all controls supported by the * V4L2 device @@ -533,7 +565,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; @@ -544,16 +575,23 @@ 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) @@ -562,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); @@ -630,6 +671,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