From patchwork Tue Apr 13 07:50:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11900 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 CDE5EBD224 for ; Tue, 13 Apr 2021 07:50:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9297468804; Tue, 13 Apr 2021 09:50:27 +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="ExghdpUA"; dkim-atps=neutral Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 45856687F3 for ; Tue, 13 Apr 2021 09:50:26 +0200 (CEST) Received: by mail-pf1-x42f.google.com with SMTP id w8so7427029pfn.9 for ; Tue, 13 Apr 2021 00:50:26 -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=MDvFpdtStUN6KFcq+Pbwh/UcIbxE1T9/3tNXLwDD1Sc=; b=ExghdpUAqBshvvZyhOwBt0o0Ilca544OdfveolXroT35xXHq2I0lp8dY+b8/Idbgqw eiSm/+3autIU893Tk4nolvJDEaRY386qwPAwRk9lMRU5vH/BzJLLMKC4y2fhYTHSdH8s w8FkQ9CbOhc+MoJkcUh5RCuFfH7XvKnbZeCEg= 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=MDvFpdtStUN6KFcq+Pbwh/UcIbxE1T9/3tNXLwDD1Sc=; b=e+DRfD2L5vw9bf+0BE+g7h1tiG0l6HKy6LthgrjwlePeR57rjATAy8qgTdt1aClSun bneXKEaQ4JW4oE/mbhXMF52rCFvW/dH/f2e1Vqx7idzr+Dr9jX4qHBkAM93MyaVt+xw5 aYnyJpLTLIiD1saeoIPM6DUA5rXlwfevmb6eaCy6bm3C2XRLAr0YFvmJclE/p31uRuLH R7b/I5jDNVu2TP9u811E6bcBhFnpGQwNubRPSCDrLZE/HYJ6IgFBedrsltX1N3VIrSMi cE3ukDkPXtBaHfEYKyIAD4VIecsF9nzm6WEtuJs6u8L8+0tw08nsRRT3xKl+OQQgh+sm +Ahg== X-Gm-Message-State: AOAM530DZU4cFfuZ8JT9Zz/VANUcWROSltgOgz9Bl1pcaNsgUPWRmW9K +A1LZkyw0Ks9kiwZE8xXcubASteNE91zRQ== X-Google-Smtp-Source: ABdhPJz7LsD22I5o7pWwbY9Yw8XRjwHMNr3Ogp0Vb3MQ+5xTZlEgP3n1PKLNiXtcmq7pw/6evc8tOg== X-Received: by 2002:a05:6a00:15c6:b029:24e:9dd1:8813 with SMTP id o6-20020a056a0015c6b029024e9dd18813mr5720881pfu.80.1618300224648; Tue, 13 Apr 2021 00:50:24 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:84f5:7981:dfbe:8f02]) by smtp.gmail.com with ESMTPSA id n25sm11525125pff.154.2021.04.13.00.50.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Apr 2021 00:50:24 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 13 Apr 2021 16:50:09 +0900 Message-Id: <20210413075013.3069213-2-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.295.g9ea45b61b8-goog In-Reply-To: <20210413075013.3069213-1-hiroh@chromium.org> References: <20210413075013.3069213-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v2 1/5] libcamera: Controls: Add ControlTypeMenu 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: , Cc: jmondi@jacopo.org Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This adds control type for v4l2 menu. Signed-off-by: Hirokazu Honda --- include/libcamera/controls.h | 28 ++++++++++++++++++++++++++++ src/libcamera/controls.cpp | 7 +++++++ 2 files changed, 35 insertions(+) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 1a5690a5..357819e7 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -9,6 +9,7 @@ #define __LIBCAMERA_CONTROLS_H__ #include +#include #include #include #include @@ -32,6 +33,28 @@ enum ControlType { ControlTypeString, ControlTypeRectangle, ControlTypeSize, + ControlTypeMenu, +}; + +struct ControlMenu { + uint32_t index; + bool isName = false; + + union { + char name[28]; + int64_t value; + }; + + std::string toString() const + { + std::stringstream ss; + ss << "index: " << index; + if (isName) + ss << "name: " << name; + else + ss << "value: " << value; + return ss.str(); + } }; namespace details { @@ -85,6 +108,11 @@ struct control_type { static constexpr ControlType value = ControlTypeSize; }; +template<> +struct control_type { + static constexpr ControlType value = ControlTypeMenu; +}; + template struct control_type> : public control_type> { }; diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index c58ed394..8ab5ac92 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -60,6 +60,7 @@ static constexpr size_t ControlValueSize[] = { [ControlTypeString] = sizeof(char), [ControlTypeRectangle] = sizeof(Rectangle), [ControlTypeSize] = sizeof(Size), + [ControlTypeMenu] = sizeof(ControlMenu), }; } /* namespace */ @@ -254,6 +255,12 @@ std::string ControlValue::toString() const str += value->toString(); break; } + case ControlTypeMenu: { + const ControlMenu *value = + reinterpret_cast(data); + str += value->toString(); + break; + } case ControlTypeNone: case ControlTypeString: break; From patchwork Tue Apr 13 07:50:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11901 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 39E44BD224 for ; Tue, 13 Apr 2021 07:50:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E5D2C687F4; Tue, 13 Apr 2021 09:50:29 +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="cqXgrn7R"; dkim-atps=neutral Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5E55B687F3 for ; Tue, 13 Apr 2021 09:50:28 +0200 (CEST) Received: by mail-pl1-x62a.google.com with SMTP id u7so5954292plr.6 for ; Tue, 13 Apr 2021 00:50:28 -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=MAtwUFk5YBMKGPW17l5Cri2kGo7Z4b7JfXgabycfy1c=; b=cqXgrn7RMo1C+moOSwJSu2xxQwlYOjcm6xBRKiDDsb8WplO7WGhSnxDfUJ5irOi4Kv 7AclWc/iITMjYWItKP/IH+YtpZf5U3oVcp/tmjHDYTaRRpVVfiM9vNFmJdWAGof275fy CjkZVHwGOYmG2T9VUTNUcoH6yoOE5ekTic/o8= 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=MAtwUFk5YBMKGPW17l5Cri2kGo7Z4b7JfXgabycfy1c=; b=js2+i+veNTJJO/PZEL8CPnaz6xcUFU1NYCrOTNtDfyTvrANH9vx5FW2Tg/1V5qmUgD hsuEcDxASB2yGOjbu77qm7450mjajPERZyGwPsvb9i8hGCLgtql9CRD7q/w99PI7GafR 9pozDJXvWrT3YqW6Dce0Ovoa6hQOA2aNXpzzfWZxVrqGt38yecIyrd2/ql4L6bwImXQl HX9T7F0q/SB5iylQWyd9Fyf+nxNyxvwcwyUbHn7o1Lc5jwh8AmqQmUUwr8bNJ47cHIiI rTCiAVARacenHof6IXRJ/6nt2WxH/gpNx50CwIg5J2lfJL1sACfhb2CMq4FNuW3Fabzi uR6w== X-Gm-Message-State: AOAM531AHu/K9iKUzukp7/nHeW9XucWzJgJ8UCr0adGloCSqig4ezwcd ADDsc9K/T1ncbdHyRa82sshk8IPvii8stg== X-Google-Smtp-Source: ABdhPJwPvkewKroQmBBlT2acqbck/uV1EHpkepfWORUyUi7Q/VTX9JJWO8GtnGnq8fzG1wFiZLkIBg== X-Received: by 2002:a17:90a:9512:: with SMTP id t18mr3402540pjo.44.1618300226779; Tue, 13 Apr 2021 00:50:26 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:84f5:7981:dfbe:8f02]) by smtp.gmail.com with ESMTPSA id n25sm11525125pff.154.2021.04.13.00.50.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Apr 2021 00:50:26 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 13 Apr 2021 16:50:10 +0900 Message-Id: <20210413075013.3069213-3-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.295.g9ea45b61b8-goog In-Reply-To: <20210413075013.3069213-1-hiroh@chromium.org> References: <20210413075013.3069213-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v2 2/5] 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: , Cc: jmondi@jacopo.org 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_controls.h | 1 + include/libcamera/internal/v4l2_device.h | 3 + src/libcamera/v4l2_controls.cpp | 10 +- src/libcamera/v4l2_device.cpp | 104 ++++++++++++++++++++- 4 files changed, 112 insertions(+), 6 deletions(-) diff --git a/include/libcamera/internal/v4l2_controls.h b/include/libcamera/internal/v4l2_controls.h index 0851b8dd..c42f2529 100644 --- a/include/libcamera/internal/v4l2_controls.h +++ b/include/libcamera/internal/v4l2_controls.h @@ -24,6 +24,7 @@ class V4L2ControlInfo : public ControlInfo { public: V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl); + V4L2ControlInfo(const ControlInfo &ctrl); }; } /* namespace libcamera */ diff --git a/include/libcamera/internal/v4l2_device.h b/include/libcamera/internal/v4l2_device.h index 4cce3840..2436a83c 100644 --- a/include/libcamera/internal/v4l2_device.h +++ b/include/libcamera/internal/v4l2_device.h @@ -53,6 +53,9 @@ protected: int fd() const { return fd_; } private: + bool createV4L2ControlInfoForMenu(const v4l2_query_ext_ctrl &ctrl, + V4L2ControlInfo &v4l2CtrlInfo); + void listControls(); void updateControls(ControlList *ctrls, const std::vector &v4l2Ctrls); diff --git a/src/libcamera/v4l2_controls.cpp b/src/libcamera/v4l2_controls.cpp index 3f8ec6ca..2c965cfa 100644 --- a/src/libcamera/v4l2_controls.cpp +++ b/src/libcamera/v4l2_controls.cpp @@ -73,9 +73,12 @@ ControlType v4l2_ctrl_type(const struct v4l2_query_ext_ctrl &ctrl) return ControlTypeInteger64; case V4L2_CTRL_TYPE_MENU: + case V4L2_CTRL_TYPE_INTEGER_MENU: + return ControlTypeMenu; + case V4L2_CTRL_TYPE_BUTTON: case V4L2_CTRL_TYPE_BITMASK: - case V4L2_CTRL_TYPE_INTEGER_MENU: + /* * More precise types may be needed, for now use a 32-bit * integer type. @@ -148,4 +151,9 @@ V4L2ControlInfo::V4L2ControlInfo(const struct v4l2_query_ext_ctrl &ctrl) } } +V4L2ControlInfo::V4L2ControlInfo(const ControlInfo &ctrl) + : ControlInfo(ctrl) +{ +} + } /* namespace libcamera */ diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 8f29cd7f..7fbca8b1 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -459,6 +460,60 @@ int V4L2Device::ioctl(unsigned long request, void *argp) * \return The device node path */ +bool V4L2Device::createV4L2ControlInfoForMenu(const v4l2_query_ext_ctrl &ctrl, + V4L2ControlInfo &v4l2CtrlInfo) +{ + ASSERT(ctrl.type == V4L2_CTRL_TYPE_MENU || + ctrl.type == V4L2_CTRL_TYPE_INTEGER_MENU); + bool isName = false; + switch (ctrl.id) { + case V4L2_CID_TEST_PATTERN: + case V4L2_CID_INTEL_IPU3_MODE: + isName = true; + break; + case V4L2_CID_LINK_FREQ: + isName = false; + break; + default: + LOG(V4L2, Error) << "Unsupported menu: " << ctrl.name + << " (" << utils::hex(ctrl.id) << ")"; + return false; + } + + 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; + ControlMenu ctrlMenu; + ctrlMenu.index = static_cast(menu.index); + ctrlMenu.isName = isName; + if (isName) { + strcpy(ctrlMenu.name, + reinterpret_cast(menu.name)); + } else { + ctrlMenu.value = menu.value; + } + + values.push_back(ControlValue(ctrlMenu)); + } + + if (values.empty()) { + LOG(V4L2, Error) + << "No applicable value: " << utils::hex(ctrl.id); + return false; + } + + v4l2CtrlInfo = V4L2ControlInfo( + ControlInfo(libcamera::Span( + values.data(), values.size()))); + + return true; +} + /** * \fn V4L2Device::fd() * \brief Retrieve the V4L2 device file descriptor @@ -474,7 +529,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; @@ -485,15 +539,20 @@ void V4L2Device::listControls() ctrl.flags & V4L2_CTRL_FLAG_DISABLED) continue; + V4L2ControlInfo v4l2CtrlInfo(ControlInfo(0)); 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: + v4l2CtrlInfo = V4L2ControlInfo(ctrl); + break; + case V4L2_CTRL_TYPE_MENU: + case V4L2_CTRL_TYPE_INTEGER_MENU: + if (!createV4L2ControlInfoForMenu(ctrl, v4l2CtrlInfo)) + continue; break; /* \todo Support other control types. */ default: @@ -503,10 +562,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(), std::move(v4l2CtrlInfo)); } controls_ = std::move(ctrls); @@ -539,7 +601,39 @@ void V4L2Device::updateControls(ControlList *ctrls, case ControlTypeInteger64: newValue.set(v4l2Ctrl.value64); break; - + case ControlTypeMenu: + switch (v4l2Ctrl.id) { + case V4L2_CID_TEST_PATTERN: { + ControlMenu menu; + menu.index = v4l2Ctrl.value; + menu.isName = true; + + bool found = false; + for (const ControlValue &validValue : it->second.values()) { + const auto &ctrlMenu = validValue.get(); + if (!ctrlMenu.isName) + continue; + if (menu.index == ctrlMenu.index) { + strcpy(menu.name, ctrlMenu.name); + found = true; + break; + } + } + + if (!found) { + LOG(V4L2, Error) + << "Matched value is not found" + << ", index=" << menu.index; + continue; + } + + newValue.set(menu); + break; + } + default: + LOG(V4L2, Error) << "Unknown id: " << v4l2Ctrl.id; + break; + } case ControlTypeByte: /* * No action required, the VIDIOC_[GS]_EXT_CTRLS ioctl From patchwork Tue Apr 13 07:50:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11902 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 9A92ABD224 for ; Tue, 13 Apr 2021 07:50:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5802068806; Tue, 13 Apr 2021 09:50:31 +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="TwC0j3iP"; dkim-atps=neutral Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 43C9668807 for ; Tue, 13 Apr 2021 09:50:30 +0200 (CEST) Received: by mail-pj1-x1031.google.com with SMTP id nm3-20020a17090b19c3b029014e1bbf6c60so4370038pjb.4 for ; Tue, 13 Apr 2021 00:50:30 -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=rlsUuEqcdG8AY1Z79fV2Ci85GOWZ0WM8QyxR3iApWQg=; b=TwC0j3iP7GMddqP7G4IDRT68fxUc7ivUaP89NXGOR0XmImlAwQEeZHpFU1hw3ei9Ck 5ecNVT8R0YRQA2CNgZ8AvCPo3uY6L15w+gffxmUt69xP9LoYWW7wivCXLyaoojIh3Dkg X8Xpw7eexvgYZYWrUuQdKDuUoCdnyO9tSVy40= 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=rlsUuEqcdG8AY1Z79fV2Ci85GOWZ0WM8QyxR3iApWQg=; b=f1ftk3X/7zaJ7XCs/rpYRuebDN5qkL3kBAV4jrmADYPSgBJpy4Htx6GPmPqAVkVRGC oCeF2XsjZ5TC7TB1I7ZZm4hbtRb/aBxCx/B09zdhZivpfMwd+/O57zLkt5wA77pbIIE5 pvO7aFhNwQJ5q19tCmSmIAf3l1LrJkQGCtDyeScBnJNhLdemaruHuYVDLjFq8s+LZvLz AhOoRHXdlh0yxitp2ZClfbYEsdltB068gYf4Ol5LaRcAA+IF0cskhixOchcDQLyx2+l9 83rVbusKypxmN4NFFW7q9LmdIpPC+70xdyi6IsdSOrbkKUQrbbe8q2dzHDQezDA4x8CV pojQ== X-Gm-Message-State: AOAM531860bpupAPK2Yvp/MIC2NtQpJisgOCzTm7LtRQYlyLx4OxrpH3 mICyEcTBH0wh1wlwCJQOrQVeB21M7zk18w== X-Google-Smtp-Source: ABdhPJyIkl3NS4wKy1q1H8Nox9M0bKnCZ3QdFrAALsPkLbjuGroC4Px0niPk6Qc5lhgeWDWQITeYvw== X-Received: by 2002:a17:90a:c3:: with SMTP id v3mr3633754pjd.55.1618300228720; Tue, 13 Apr 2021 00:50:28 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:84f5:7981:dfbe:8f02]) by smtp.gmail.com with ESMTPSA id n25sm11525125pff.154.2021.04.13.00.50.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Apr 2021 00:50:28 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 13 Apr 2021 16:50:11 +0900 Message-Id: <20210413075013.3069213-4-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.295.g9ea45b61b8-goog In-Reply-To: <20210413075013.3069213-1-hiroh@chromium.org> References: <20210413075013.3069213-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v2 3/5] libcamera: SensorDatabase: Adds table of v4l2 name and test pattern 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: , Cc: jmondi@jacopo.org Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" In V4L2 API, a driver returns a name to represent a test pattern, but it is a driver specific what test pattern is represented by the name. Therefore, this adds a mapping table from the name to a test pattern into a static configuration of a sensor. Signed-off-by: Hirokazu Honda --- include/libcamera/internal/sensor_database.h | 2 ++ src/libcamera/sensor_database.cpp | 37 ++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/include/libcamera/internal/sensor_database.h b/include/libcamera/internal/sensor_database.h index 7d743e46..c0b181f8 100644 --- a/include/libcamera/internal/sensor_database.h +++ b/include/libcamera/internal/sensor_database.h @@ -10,11 +10,13 @@ #include #include +#include namespace libcamera { struct SensorInfo { Size unitCellSize; + Span> testPatternModeMap; }; class SensorDatabase diff --git a/src/libcamera/sensor_database.cpp b/src/libcamera/sensor_database.cpp index 68e69e8b..a71e8958 100644 --- a/src/libcamera/sensor_database.cpp +++ b/src/libcamera/sensor_database.cpp @@ -9,6 +9,8 @@ #include +#include "libcamera/control_ids.h" + namespace libcamera { /** @@ -43,25 +45,54 @@ namespace libcamera { namespace { +constexpr std::pair imx219TestPatternModeMap[] = { + { "Disabled", controls::draft::SensorTestPatternModeOff }, + { "Color Bars", controls::draft::SensorTestPatternModeColorBars }, + { "Solid Color", controls::draft::SensorTestPatternModeSolidColor }, + { "Grey Color Bars", controls::draft::SensorTestPatternModeColorBarsFadeToGray }, + { "PN9", controls::draft::SensorTestPatternModePn9 }, +}; + +constexpr std::pair ov5670TestPatternModeMap[] = { + { "Disabled", controls::draft::SensorTestPatternModeOff }, + { "Vertical Color Bar Type 1", controls::draft::SensorTestPatternModeColorBars }, +}; + +constexpr std::pair ov13858TestPatternModeMap[] = { + { "Disabled", controls::draft::SensorTestPatternModeOff }, + { "Vertical Color Bar Type 1", controls::draft::SensorTestPatternModeColorBars }, + { "Vertical Color Bar Type 2", controls::draft::SensorTestPatternModeColorBarsFadeToGray }, +}; + /** * \brief Sony IMX219 sensor properties */ constexpr SensorInfo imx219Info = { - .unitCellSize = { 1120, 1120 } + .unitCellSize = { 1120, 1120 }, + .testPatternModeMap = + libcamera::Span>( + imx219TestPatternModeMap), }; /** * \brief Omnivision ov5670 sensor properties */ constexpr SensorInfo ov5670Info = { - .unitCellSize = { 1120, 1120 } + .unitCellSize = { 1120, 1120 }, + .testPatternModeMap = + libcamera::Span>( + ov5670TestPatternModeMap), }; /** * \brief Omnivision 13858 sensor properties */ constexpr SensorInfo ov13858Info = { - .unitCellSize = { 1120, 1120 } + .unitCellSize = { 1120, 1120 }, + .testPatternModeMap = + libcamera::Span>( + ov13858TestPatternModeMap), + }; #define SENSOR_INFO(_sensor) \ From patchwork Tue Apr 13 07:50:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11903 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 2166DBD224 for ; Tue, 13 Apr 2021 07:50:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D2E3C68804; Tue, 13 Apr 2021 09:50:34 +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="YNujL2sQ"; dkim-atps=neutral Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9D3C1687FF for ; Tue, 13 Apr 2021 09:50:32 +0200 (CEST) Received: by mail-pf1-x42f.google.com with SMTP id i190so10887614pfc.12 for ; Tue, 13 Apr 2021 00:50:32 -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=3hSgGx1cbP3KI7myLORs12z6yfh34QoYFMukHPMp0PY=; b=YNujL2sQmmGBC0adVaUlrH05ckirDBFSaXifh+OoKJYXK4ihXwBfbqI2N0grsSbTTM uz+6ROuaox7FWjDsQxgGKFofqUiF0YFlFSERT49ty5a1qOt8Wr/kpoUDCwL9+WKDMEW5 oNAI6Jl6Y6nSPnc6SRP4JFVB7MbKMYMvNcAPM= 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=3hSgGx1cbP3KI7myLORs12z6yfh34QoYFMukHPMp0PY=; b=fBJP2Onla/+4HLeQedKjNBaFvuAXUJ9qVY8V7Cs1o61gWgEWYxWSPC26/33ahnkDOr Cb17Vk3SyQnqrRBOW/+xsQfNoxdZgBKCBj9+RC/BCfWTuTlAYxbpHLbEajkpH4Atan1r COePXrT48B7jjtHyQcp3fmDpknAAvyCtmhTQESWbW/XSl8L6buQsWF3/NBzPNbAEJ1b0 7bnRwLtCVwh81NQZxSfp6tYNOWa3y81xhub6kJ/u6kjfjZef62wdz4Qa5fXd5g898W5l hPsrkVTGFIg5jHL0HE39t0anxuVRjPV7hT+dwVCg/BDK/k4kmrSq/7+fjxJf4ip9ort1 dy2w== X-Gm-Message-State: AOAM530Gd9ZzJo/Y3cBAzzD3FYL0zmWaXfyweS1YcsbCQCoOqS10Quae ozrSUZbzAcK6jg1SQEdgES8lM380pIUmJw== X-Google-Smtp-Source: ABdhPJwZV1H38Sfga37Y3UM9Ne4GuqgxVC9cf2Q9Lld/h7Vi8JnhMNulAPVyCb8Rvt6z0Fwq2OgBjg== X-Received: by 2002:a62:1591:0:b029:251:27c2:c185 with SMTP id 139-20020a6215910000b029025127c2c185mr926071pfv.33.1618300230730; Tue, 13 Apr 2021 00:50:30 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:84f5:7981:dfbe:8f02]) by smtp.gmail.com with ESMTPSA id n25sm11525125pff.154.2021.04.13.00.50.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Apr 2021 00:50:30 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 13 Apr 2021 16:50:12 +0900 Message-Id: <20210413075013.3069213-5-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.295.g9ea45b61b8-goog In-Reply-To: <20210413075013.3069213-1-hiroh@chromium.org> References: <20210413075013.3069213-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v2 4/5] libcamera: CameraSensor: Attach available test pattern modes 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: , Cc: jmondi@jacopo.org Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" This add available test pattern modes to libcamera to CameraSensorInfo. Signed-off-by: Hirokazu Honda --- include/libcamera/internal/camera_sensor.h | 2 ++ src/libcamera/camera_sensor.cpp | 38 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index 3fa3a419..75b884db 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -38,6 +38,8 @@ struct CameraSensorInfo { uint32_t minFrameLength; uint32_t maxFrameLength; + + std::vector availableTestPatternModes; }; class CameraSensor : protected Loggable diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index c012385f..81d6af44 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -840,6 +840,44 @@ int CameraSensor::sensorInfo(CameraSensorInfo *info) const info->minFrameLength = info->outputSize.height + vblank.min().get(); info->maxFrameLength = info->outputSize.height + vblank.max().get(); + const SensorInfo *staticInfo = SensorDatabase::get(model_); + if (!staticInfo) { + LOG(CameraSensor, Warning) + << "No static properties available for '" << model_ << "'"; + LOG(CameraSensor, Warning) + << "Please consider updating the sensor database"; + return -EINVAL; + } + + const auto &v4l2TestPattern = controls().find(V4L2_CID_TEST_PATTERN); + if (v4l2TestPattern == controls().end()) { + LOG(CameraSensor, Error) << "No static test pattern map for \'" + << model() << "\'"; + return 0; + } + + for (const ControlValue &value : v4l2TestPattern->second.values()) { + const ControlMenu &menu = value.get(); + ASSERT(menu.isName); + + int32_t matchedTestPattern = -1; + for (const auto &[name, testPattern] : staticInfo->testPatternModeMap) { + if (strcmp(menu.name, name) == 0) { + matchedTestPattern = testPattern; + break; + } + } + + if (matchedTestPattern != -1) { + LOG(CameraSensor, Debug) << "Test pattern mode named \'" + << menu.name << "\' added"; + info->availableTestPatternModes.push_back(matchedTestPattern); + } else { + LOG(CameraSensor, Debug) << "Test pattern mode named \'" + << menu.name << "\' ignored"; + } + } + return 0; } From patchwork Tue Apr 13 07:50: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: 11904 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 89F68BD224 for ; Tue, 13 Apr 2021 07:50:35 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3F08E68809; Tue, 13 Apr 2021 09:50:35 +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="FPVAt6BC"; dkim-atps=neutral Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 452A668800 for ; Tue, 13 Apr 2021 09:50:34 +0200 (CEST) Received: by mail-pj1-x1035.google.com with SMTP id nm3-20020a17090b19c3b029014e1bbf6c60so4370113pjb.4 for ; Tue, 13 Apr 2021 00:50:34 -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=wJ/ceasRA1QDOVgYJaZJ4VnwamEf/ayurSs05yfPadY=; b=FPVAt6BCv/sI0kztWNr15HDv9eCIKXALwdjKNan4a4pthpHGk95w3lTObwDsmYXaRt Zg4IwMaKOVay/VXRTmORvYaETJccKJHXJELM9u7LCzOsxJXS/eUnNdBFbz0etpvvE4yE WjkgYlEzdddL8qFm3WKOTQoDEkwOCN6RxM0Nk= 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=wJ/ceasRA1QDOVgYJaZJ4VnwamEf/ayurSs05yfPadY=; b=chCR1bl20bgKteEohyi1ttHarMnp0MfLl3hjTh2JYyS996hsQSOU7hB3rDBumGn16U HFSCM7xl+PBZZiT4Xxa7CEJpL96A3hqHGN3ipVVX/+42zNmCFDdYS/ZHhocyM2kihFqx awX2pmntjWvLPGwkUsM+CUe55bL/uX+1aBQsxZOaSK+3F7atATACkbiwZ09v++rbKa7F DaiU47PLRdMvqwux5xA41IwkgH35qyufqR6kNYbCvwInj+p94fG+ouyjutS+TsfAcdFz oy4QydlvJaUoVmoIA7wGWIwMfMDlgVWSr60DJbEs9n7/Gfzg5Z/W6kqkzo1PP4aklsmD 0gDg== X-Gm-Message-State: AOAM530E45MAa8ENwGmHTf2sgw1gIKWyJoNH0MpUn+MDkNCiIS18huoV G374wTNo3gAFP/CbFp+SQUQSJyBx35pPng== X-Google-Smtp-Source: ABdhPJwzbHxaqQt9BTGces0JIstCGmNxFmyMz+z++K7eA4yCXp5wzVgAC4r6ioNCvtLV1EoeBXzxCQ== X-Received: by 2002:a17:902:b68a:b029:e9:7643:6335 with SMTP id c10-20020a170902b68ab02900e976436335mr29124158pls.2.1618300232789; Tue, 13 Apr 2021 00:50:32 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:84f5:7981:dfbe:8f02]) by smtp.gmail.com with ESMTPSA id n25sm11525125pff.154.2021.04.13.00.50.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Apr 2021 00:50:32 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Tue, 13 Apr 2021 16:50:13 +0900 Message-Id: <20210413075013.3069213-6-hiroh@chromium.org> X-Mailer: git-send-email 2.31.1.295.g9ea45b61b8-goog In-Reply-To: <20210413075013.3069213-1-hiroh@chromium.org> References: <20210413075013.3069213-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH v2 5/5] libcamera: pipeline: ipu3: Report available sensor test pattern mode 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: , Cc: jmondi@jacopo.org Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" PipelineHandlerIPU3 gets available test pattern modes of the sensor device and reports them to a client. Signed-off-by: Hirokazu Honda --- src/libcamera/pipeline/ipu3/ipu3.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 519cad4f..bcef331c 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -891,6 +891,18 @@ int PipelineHandlerIPU3::initControls(IPU3CameraData *data) ControlInfoMap::Map controls = IPU3Controls; const ControlInfoMap &sensorControls = sensor->controls(); + if (!sensorInfo.availableTestPatternModes.empty()) { + std::vector values( + sensorInfo.availableTestPatternModes.size()); + for (size_t i = 0; i < values.size(); ++i) { + values[i] = ControlValue( + sensorInfo.availableTestPatternModes[i]); + } + + controls[&controls::draft::SensorTestPatternMode] = + ControlInfo(libcamera::Span(values)); + } + /* * Compute exposure time limits. *