From patchwork Fri Oct 25 05:30:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-Hao Yang X-Patchwork-Id: 21752 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 AF5D6C3220 for ; Fri, 25 Oct 2024 05:31:24 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 514CA65397; Fri, 25 Oct 2024 07:31:24 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="duNGtrI5"; dkim-atps=neutral Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6B27B6538A for ; Fri, 25 Oct 2024 07:31:20 +0200 (CEST) Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-7163489149eso1145935a12.1 for ; Thu, 24 Oct 2024 22:31:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1729834278; x=1730439078; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hoj5EptvhU9pg9aZA081Vuc/pCfYDXASJLvTcNEnh6U=; b=duNGtrI5pF3w01DIci2rjgrt7gM8O6iy4Ek70TEXm672Yfje4wly15XhVP+y13i/qz 346nSX9lYebL7IcajZG5bijhBTuhjgs+6R3+x0yYz8YyvGJSzdfPTa22CTkwhCmZsQMX p5UEHXD8A0lhoA6Kwe47TUIeqrN87kJGctcKw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729834278; x=1730439078; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hoj5EptvhU9pg9aZA081Vuc/pCfYDXASJLvTcNEnh6U=; b=mma1qZDPGdGpVDjJs1EMmt7LRliCHu8zU89PlbElYg+fxjjHHC83xdnagOdDtn+qdb eHoFJJT+S9qsBen679HA7kXSAoZwcWNqnYTywSchF4ei0l2D3UhZJxMcKn+be9dPcLhg /yTNMVTmyJkpI2lT87b3CNNxC4N1qUHzWU0Z4jp0/HBcYg3Ox5YUba/Mqm3Ij3I8osap OkWvBQWoCoFEd2IWIJr1pyIYqQoPDTcAJVtl9Jcmv5cRovFbzhXWYmf5nJpsxSo3c0fm Ue2kIl2/OycQeEMPQlVLd9OxFmJbSD9TMli5VoEwMyr0ZSzQXHhBNkwjWzW4n8xHQCqh RNXQ== X-Gm-Message-State: AOJu0YwKhnKjWBpbV5CoUmJomy6Rbixx/qvieSGPyOebN2jZAQaPm4m+ RNzMcd0CTwI5NUF+TksRstxEEnZYwmBpUf7jKjcICNh4HVE+XV0H32hA2+miE64LJCgXYmxO39M = X-Google-Smtp-Source: AGHT+IF/y1kftz2nRgIdOTATuTtj7rDB4A6oX5vy5qbbfsupDGQqY9qnJ6NcVTVYqO7zw88z+YTk/w== X-Received: by 2002:a05:6a20:3813:b0:1d9:975e:2bce with SMTP id adf61e73a8af0-1d9975e2d71mr2135718637.38.1729834278146; Thu, 24 Oct 2024 22:31:18 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (199.211.81.34.bc.googleusercontent.com. [34.81.211.199]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72057a1fe53sm317992b3a.162.2024.10.24.22.31.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 22:31:17 -0700 (PDT) From: Harvey Yang To: libcamera-devel@lists.libcamera.org Cc: Yudhistira Erlandinata , Harvey Yang Subject: [PATCH v3 1/2] libcamera: Extend u32 control type Date: Fri, 25 Oct 2024 05:30:13 +0000 Message-ID: <20241025053111.519449-2-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog In-Reply-To: <20241025053111.519449-1-chenghaoyang@chromium.org> References: <20241025053111.519449-1-chenghaoyang@chromium.org> MIME-Version: 1.0 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" From: Yudhistira Erlandinata V4L2 Controls support a wide variety of types not yet supported by the ControlValue type system. Extend the libcamera ControlValue types to support an explicit 32 bit unsigned integer type, and map that to the corresponding V4L2_CTRL_TYPE_U32 type within the v4l2_device support class. Signed-off-by: Yudhistira Erlandinata Co-developed-by: Harvey Yang Signed-off-by: Harvey Yang --- include/libcamera/controls.h | 7 ++++++ src/libcamera/controls.cpp | 12 ++++++++-- src/libcamera/v4l2_device.cpp | 13 +++++++++++ test/controls/control_value.cpp | 40 +++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 2 deletions(-) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index ca60bbaca..6da8ad2c3 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -29,6 +29,7 @@ enum ControlType { ControlTypeNone, ControlTypeBool, ControlTypeByte, + ControlTypeUnsigned32, ControlTypeInteger32, ControlTypeInteger64, ControlTypeFloat, @@ -62,6 +63,12 @@ struct control_type { static constexpr std::size_t size = 0; }; +template<> +struct control_type { + static constexpr ControlType value = ControlTypeUnsigned32; + static constexpr std::size_t size = 0; +}; + template<> struct control_type { static constexpr ControlType value = ControlTypeInteger32; diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index 62185d643..8ae295191 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -54,6 +54,7 @@ static constexpr size_t ControlValueSize[] = { [ControlTypeNone] = 0, [ControlTypeBool] = sizeof(bool), [ControlTypeByte] = sizeof(uint8_t), + [ControlTypeUnsigned32] = sizeof(uint32_t), [ControlTypeInteger32] = sizeof(int32_t), [ControlTypeInteger64] = sizeof(int64_t), [ControlTypeFloat] = sizeof(float), @@ -74,10 +75,12 @@ static constexpr size_t ControlValueSize[] = { * The control stores a boolean value * \var ControlTypeByte * The control stores a byte value as an unsigned 8-bit integer + * \var ControlTypeUnsigned32 + * The control stores an unsigned 32-bit integer value * \var ControlTypeInteger32 - * The control stores a 32-bit integer value + * The control stores a signed 32-bit integer value * \var ControlTypeInteger64 - * The control stores a 64-bit integer value + * The control stores a signed 64-bit integer value * \var ControlTypeFloat * The control stores a 32-bit floating point value * \var ControlTypeString @@ -230,6 +233,11 @@ std::string ControlValue::toString() const str += std::to_string(*value); break; } + case ControlTypeUnsigned32: { + const uint32_t *value = reinterpret_cast(data); + str += std::to_string(*value); + break; + } case ControlTypeInteger32: { const int32_t *value = reinterpret_cast(data); str += std::to_string(*value); diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 68add4f2e..0ba8dcfa0 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -17,11 +18,14 @@ #include #include +#include #include #include #include +#include + #include "libcamera/internal/formats.h" #include "libcamera/internal/sysfs.h" @@ -488,6 +492,9 @@ ControlType V4L2Device::v4l2CtrlType(uint32_t ctrlType) case V4L2_CTRL_TYPE_BOOLEAN: return ControlTypeBool; + case V4L2_CTRL_TYPE_U32: + return ControlTypeUnsigned32; + case V4L2_CTRL_TYPE_INTEGER: return ControlTypeInteger32; @@ -536,6 +543,11 @@ std::optional V4L2Device::v4l2ControlInfo(const v4l2_query_ext_ctrl static_cast(ctrl.maximum), static_cast(ctrl.default_value)); + case V4L2_CTRL_TYPE_U32: + return ControlInfo(static_cast(ctrl.minimum), + static_cast(ctrl.maximum), + static_cast(ctrl.default_value)); + case V4L2_CTRL_TYPE_BOOLEAN: return ControlInfo(static_cast(ctrl.minimum), static_cast(ctrl.maximum), @@ -622,6 +634,7 @@ void V4L2Device::listControls() case V4L2_CTRL_TYPE_BITMASK: case V4L2_CTRL_TYPE_INTEGER_MENU: case V4L2_CTRL_TYPE_U8: + case V4L2_CTRL_TYPE_U32: break; /* \todo Support other control types. */ default: diff --git a/test/controls/control_value.cpp b/test/controls/control_value.cpp index 344107fae..6ca85b739 100644 --- a/test/controls/control_value.cpp +++ b/test/controls/control_value.cpp @@ -109,6 +109,46 @@ protected: return TestFail; } + /* + * Unsigned Integer32 type. + */ + value.set(static_cast(42)); + if (value.isNone() || value.isArray() || + value.type() != ControlTypeUnsigned32) { + cerr << "Control type mismatch after setting to uint32_t" << endl; + return TestFail; + } + + if (value.get() != 42) { + cerr << "Control value mismatch after setting to uint32_t" << endl; + return TestFail; + } + + if (value.toString() != "42") { + cerr << "Control string mismatch after setting to uint32_t" << endl; + return TestFail; + } + + std::array uint32s{ 3, 14, 15, 9 }; + value.set(Span(uint32s)); + if (value.isNone() || !value.isArray() || + value.type() != ControlTypeUnsigned32) { + cerr << "Control type mismatch after setting to uint32_t array" << endl; + return TestFail; + } + + Span uint32sResult = value.get>(); + if (uint32s.size() != uint32sResult.size() || + !std::equal(uint32s.begin(), uint32s.end(), uint32sResult.begin())) { + cerr << "Control value mismatch after setting to uint32_t array" << endl; + return TestFail; + } + + if (value.toString() != "[ 3, 14, 15, 9 ]") { + cerr << "Control string mismatch after setting to uint32_t array" << endl; + return TestFail; + } + /* * Integer32 type. */ From patchwork Fri Oct 25 05:30:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-Hao Yang X-Patchwork-Id: 21753 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 4C024C32A2 for ; Fri, 25 Oct 2024 05:31:27 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BE79F65397; Fri, 25 Oct 2024 07:31:26 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="nySzdu+s"; dkim-atps=neutral Received: from mail-pg1-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8980765391 for ; Fri, 25 Oct 2024 07:31:22 +0200 (CEST) Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-7d4f85766f0so1092238a12.2 for ; Thu, 24 Oct 2024 22:31:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1729834280; x=1730439080; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=r386/93w3W3Hz+QYkzYzNrZ6/8Zqa0TUG2MyR6Zo87s=; b=nySzdu+sCUbHR8+6FUhKmLoiPW8A7RDcdmHJHDjq9z4vkF9HzK/FJ/T7JAJiB88pyq awQZY80fXAxy/HsMRe/F+pEbRQK4IJTJHZHuLGqsWuIzEOG+X3WobHBQvfbXXCAw0rJl b9CKlXG20iEwo40PjiyRFxJmO9UOsdYYyN6FU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729834280; x=1730439080; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r386/93w3W3Hz+QYkzYzNrZ6/8Zqa0TUG2MyR6Zo87s=; b=Gc2QdBNzUnigxi2WJ7q5Qd91ukFh3zwxlMzAFulDN6BN7xReW0vhdb89lxwrmZRTNg DVLfJoxInovv5tUqidnpWIM/XW2vSqXfJ1Sr1YOYsFzMDIdgtAsAfpmJFgz+WOi2ZAu8 dxrDQWMtexnuwlwqzzWrCauESAAXvfU42XCMS0Nk9nYNd5dwRpXbcwGQJsZk9KhVFo8q tTGRVIP1dTRts8rTDKmmwv+rVZ4HXmBP1ydMdN99nRAo5NjuuS6vsuYqdfdOfryryzaw pdQXkMYoPPzIG8vRq9krgI/x68F/RaUmcq8Xi6fmFyVRUNpBh9xXfGwdY+1yl5LMFdBK veMQ== X-Gm-Message-State: AOJu0YwTEfOJAgroly7BXanWs8V36X+yCTiqpy6bUi3fXPB2YSjguSLv NV26IjGqwpBqBuOQDKM4H5ThnVYQUITKAd3HbY2bHpnKThZTFYSw0rLW6TL1tEXmPbc5PnvRCG0 = X-Google-Smtp-Source: AGHT+IGJ4khaXO3q28jAkRhpeMtAWzgeEPumM/wzJDO5p1OC7DJ1BRwEQpnyMBacniJgGFCQusaDAg== X-Received: by 2002:a05:6a21:3941:b0:1d9:18e2:e09d with SMTP id adf61e73a8af0-1d978bb2bb7mr10219899637.44.1729834280191; Thu, 24 Oct 2024 22:31:20 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (199.211.81.34.bc.googleusercontent.com. [34.81.211.199]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72057a1fe53sm317992b3a.162.2024.10.24.22.31.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2024 22:31:19 -0700 (PDT) From: Harvey Yang To: libcamera-devel@lists.libcamera.org Cc: Yudhistira Erlandinata , Harvey Yang Subject: [PATCH v3 2/2] libcamera: Add Unsigned 16-bits Control Type Date: Fri, 25 Oct 2024 05:30:14 +0000 Message-ID: <20241025053111.519449-3-chenghaoyang@chromium.org> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog In-Reply-To: <20241025053111.519449-1-chenghaoyang@chromium.org> References: <20241025053111.519449-1-chenghaoyang@chromium.org> MIME-Version: 1.0 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" From: Yudhistira Erlandinata V4L2 Controls support a wide variety of types not yet supported by the ControlValue type system. Extend the libcamera ControlValue types to support an explicit 16 bit unsigned integer type, and map that to the corresponding V4L2_CTRL_TYPE_U16 type within the v4l2_device support class. It's used on some camera metadata that is of length 16-bits, for example JPEG metadata headers. Signed-off-by: Yudhistira Erlandinata Co-developed-by: Harvey Yang Signed-off-by: Harvey Yang --- include/libcamera/controls.h | 7 ++++++ src/libcamera/controls.cpp | 8 +++++++ src/libcamera/v4l2_device.cpp | 9 ++++++++ test/controls/control_value.cpp | 40 +++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+) diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h index 6da8ad2c3..162115bb5 100644 --- a/include/libcamera/controls.h +++ b/include/libcamera/controls.h @@ -29,6 +29,7 @@ enum ControlType { ControlTypeNone, ControlTypeBool, ControlTypeByte, + ControlTypeUnsigned16, ControlTypeUnsigned32, ControlTypeInteger32, ControlTypeInteger64, @@ -63,6 +64,12 @@ struct control_type { static constexpr std::size_t size = 0; }; +template<> +struct control_type { + static constexpr ControlType value = ControlTypeUnsigned16; + static constexpr std::size_t size = 0; +}; + template<> struct control_type { static constexpr ControlType value = ControlTypeUnsigned32; diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index 8ae295191..3a840bb22 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -54,6 +54,7 @@ static constexpr size_t ControlValueSize[] = { [ControlTypeNone] = 0, [ControlTypeBool] = sizeof(bool), [ControlTypeByte] = sizeof(uint8_t), + [ControlTypeUnsigned16] = sizeof(uint16_t), [ControlTypeUnsigned32] = sizeof(uint32_t), [ControlTypeInteger32] = sizeof(int32_t), [ControlTypeInteger64] = sizeof(int64_t), @@ -75,6 +76,8 @@ static constexpr size_t ControlValueSize[] = { * The control stores a boolean value * \var ControlTypeByte * The control stores a byte value as an unsigned 8-bit integer + * \var ControlTypeUnsigned16 + * The control stores an unsigned 16-bit integer value * \var ControlTypeUnsigned32 * The control stores an unsigned 32-bit integer value * \var ControlTypeInteger32 @@ -233,6 +236,11 @@ std::string ControlValue::toString() const str += std::to_string(*value); break; } + case ControlTypeUnsigned16: { + const uint16_t *value = reinterpret_cast(data); + str += std::to_string(*value); + break; + } case ControlTypeUnsigned32: { const uint32_t *value = reinterpret_cast(data); str += std::to_string(*value); diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp index 0ba8dcfa0..f1b5a25a0 100644 --- a/src/libcamera/v4l2_device.cpp +++ b/src/libcamera/v4l2_device.cpp @@ -492,6 +492,9 @@ ControlType V4L2Device::v4l2CtrlType(uint32_t ctrlType) case V4L2_CTRL_TYPE_BOOLEAN: return ControlTypeBool; + case V4L2_CTRL_TYPE_U16: + return ControlTypeUnsigned16; + case V4L2_CTRL_TYPE_U32: return ControlTypeUnsigned32; @@ -543,6 +546,11 @@ std::optional V4L2Device::v4l2ControlInfo(const v4l2_query_ext_ctrl static_cast(ctrl.maximum), static_cast(ctrl.default_value)); + case V4L2_CTRL_TYPE_U16: + return ControlInfo(static_cast(ctrl.minimum), + static_cast(ctrl.maximum), + static_cast(ctrl.default_value)); + case V4L2_CTRL_TYPE_U32: return ControlInfo(static_cast(ctrl.minimum), static_cast(ctrl.maximum), @@ -634,6 +642,7 @@ void V4L2Device::listControls() case V4L2_CTRL_TYPE_BITMASK: case V4L2_CTRL_TYPE_INTEGER_MENU: case V4L2_CTRL_TYPE_U8: + case V4L2_CTRL_TYPE_U16: case V4L2_CTRL_TYPE_U32: break; /* \todo Support other control types. */ diff --git a/test/controls/control_value.cpp b/test/controls/control_value.cpp index 6ca85b739..5084fd0cf 100644 --- a/test/controls/control_value.cpp +++ b/test/controls/control_value.cpp @@ -109,6 +109,46 @@ protected: return TestFail; } + /* + * Unsigned Integer16 type. + */ + value.set(static_cast(42)); + if (value.isNone() || value.isArray() || + value.type() != ControlTypeUnsigned16) { + cerr << "Control type mismatch after setting to uint16_t" << endl; + return TestFail; + } + + if (value.get() != 42) { + cerr << "Control value mismatch after setting to uint16_t" << endl; + return TestFail; + } + + if (value.toString() != "42") { + cerr << "Control string mismatch after setting to uint16_t" << endl; + return TestFail; + } + + std::array uint16s{ 3, 14, 15, 9 }; + value.set(Span(uint16s)); + if (value.isNone() || !value.isArray() || + value.type() != ControlTypeUnsigned16) { + cerr << "Control type mismatch after setting to uint16_t array" << endl; + return TestFail; + } + + Span uint16sResult = value.get>(); + if (uint16s.size() != uint16sResult.size() || + !std::equal(uint16s.begin(), uint16s.end(), uint16sResult.begin())) { + cerr << "Control value mismatch after setting to uint16_t array" << endl; + return TestFail; + } + + if (value.toString() != "[ 3, 14, 15, 9 ]") { + cerr << "Control string mismatch after setting to uint16_t array" << endl; + return TestFail; + } + /* * Unsigned Integer32 type. */