{"id":24722,"url":"https://patchwork.libcamera.org/api/1.1/patches/24722/?format=json","web_url":"https://patchwork.libcamera.org/patch/24722/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20251023105651.78395-2-isaac.scott@ideasonboard.com>","date":"2025-10-23T10:56:48","name":"[1/4] libcamera: v4l2: Support string control payloads","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"150a1b57f039c2f1b7f24bb258d56dd3e5224424","submitter":{"id":215,"url":"https://patchwork.libcamera.org/api/1.1/people/215/?format=json","name":"Isaac Scott","email":"isaac.scott@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/24722/mbox/","series":[{"id":5518,"url":"https://patchwork.libcamera.org/api/1.1/series/5518/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5518","date":"2025-10-23T10:56:47","name":"libcamera: controls: Add support for camera module identifiers","version":1,"mbox":"https://patchwork.libcamera.org/series/5518/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/24722/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/24722/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id DB9D4C32CE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 23 Oct 2025 10:57:06 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 64629607D5;\n\tThu, 23 Oct 2025 12:57:06 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2CB4F607BC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Oct 2025 12:57:04 +0200 (CEST)","from isaac-ThinkPad-T16-Gen-2.infra.iob\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 57177591;\n\tThu, 23 Oct 2025 12:55:19 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"TWS941Ht\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1761216919;\n\tbh=yn7F384ag+1v3liHRDp6OQRFEvqPutdA8ucEtWoMLZI=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=TWS941HtrxBIVOwMDmyvr8PVuouTcz5r3LmSjHc3R7NR8tnVHPwNm4THa8gt6Qu0G\n\tlDIHh9IsyveEIQqCSVVhGk4LRlCJjTDGVIhRMtL4Ot7bThsX0zLkXpPZj8mUEu5jFJ\n\twDHcA5SqAr4WmHpIyeC2o+unG2s+/vcWX/RwzlJE=","From":"Isaac Scott <isaac.scott@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Isaac Scott <isaac.scott@ideasonboard.com>","Subject":"[PATCH 1/4] libcamera: v4l2: Support string control payloads","Date":"Thu, 23 Oct 2025 11:56:48 +0100","Message-ID":"<20251023105651.78395-2-isaac.scott@ideasonboard.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20251023105651.78395-1-isaac.scott@ideasonboard.com>","References":"<20251023105651.78395-1-isaac.scott@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"v4l2 controls can be configured to store a string. This is stored in the\nv4l2_ctrl_ext when the union within it points to a string as its\npayload.\n\nThis can be read similarly to int control payloadsm instead using the\nmaximum length of the string, represented by info.maximum.\n\nThis pointer can then be reinterpreted as a char *.\n\nN.B. It is possible that if the string is less than the maximum length,\nthe data after the string is populated with garbage. This isn't a\nproblem when using the string later, as the std::string will only use up\nto the null character in the string.\n\nSigned-off-by: Isaac Scott <isaac.scott@ideasonboard.com>\n---\n include/libcamera/controls.h  |  3 ++-\n src/libcamera/controls.cpp    | 11 ++++++++---\n src/libcamera/v4l2_device.cpp | 28 ++++++++++++++++++++++++++++\n 3 files changed, 38 insertions(+), 4 deletions(-)","diff":"diff --git a/include/libcamera/controls.h b/include/libcamera/controls.h\nindex c970e4b7b..59b666f16 100644\n--- a/include/libcamera/controls.h\n+++ b/include/libcamera/controls.h\n@@ -201,7 +201,8 @@ public:\n \tT get() const\n \t{\n \t\tassert(type_ == details::control_type<std::remove_cv_t<T>>::value);\n-\t\tassert(isArray_);\n+\t\tif (type_ != ControlTypeString)\n+\t\t\tassert(isArray_);\n \n \t\tusing V = typename T::value_type;\n \t\tconst V *value = reinterpret_cast<const V *>(data().data());\ndiff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp\nindex 1e1b49e6b..f82c4f777 100644\n--- a/src/libcamera/controls.cpp\n+++ b/src/libcamera/controls.cpp\n@@ -276,8 +276,12 @@ std::string ControlValue::toString() const\n \t\t\tstr += value->toString();\n \t\t\tbreak;\n \t\t}\n+\t\tcase ControlTypeString: {\n+\t\t\tconst std::string *value = reinterpret_cast<const std::string *>(data);\n+\t\t\tstr += *value;\n+\t\t\tbreak;\n+\t\t}\n \t\tcase ControlTypeNone:\n-\t\tcase ControlTypeString:\n \t\t\tbreak;\n \t\t}\n \n@@ -353,7 +357,8 @@ bool ControlValue::operator==(const ControlValue &other) const\n void ControlValue::set(ControlType type, bool isArray, const void *data,\n \t\t       std::size_t numElements, std::size_t elementSize)\n {\n-\tASSERT(elementSize == ControlValueSize[type]);\n+\tif (type != ControlTypeString)\n+\t\tASSERT(elementSize == ControlValueSize[type]);\n \n \treserve(type, isArray, numElements);\n \n@@ -375,7 +380,7 @@ void ControlValue::set(ControlType type, bool isArray, const void *data,\n  */\n void ControlValue::reserve(ControlType type, bool isArray, std::size_t numElements)\n {\n-\tif (!isArray)\n+\tif (!isArray && type != ControlTypeString)\n \t\tnumElements = 1;\n \n \tstd::size_t oldSize = numElements_ * ControlValueSize[type_];\ndiff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex 8c78b8c42..641ea4981 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -12,6 +12,7 @@\n #include <stdint.h>\n #include <stdlib.h>\n #include <string.h>\n+#include <string_view>\n #include <sys/ioctl.h>\n #include <sys/syscall.h>\n #include <unistd.h>\n@@ -25,6 +26,8 @@\n \n #include \"libcamera/internal/formats.h\"\n #include \"libcamera/internal/sysfs.h\"\n+#include \"libcamera/controls.h\"\n+#include \"linux/videodev2.h\"\n \n /**\n  * \\file v4l2_device.h\n@@ -230,6 +233,13 @@ ControlList V4L2Device::getControls(Span<const uint32_t> ids)\n \t\t\t\tv4l2Ctrl.p_u32 = reinterpret_cast<uint32_t *>(data.data());\n \t\t\t\tbreak;\n \n+\t\t\tcase V4L2_CTRL_TYPE_STRING:\n+\t\t\t\ttype = ControlTypeString;\n+\t\t\t\tvalue.reserve(type, false, info.maximum + 1);\n+\t\t\t\tdata = value.data();\n+\t\t\t\tv4l2Ctrl.string = reinterpret_cast<char *>(data.data());\n+\t\t\t\tbreak;\n+\n \t\t\tdefault:\n \t\t\t\tLOG(V4L2, Error)\n \t\t\t\t\t<< \"Unsupported payload control type \"\n@@ -570,6 +580,8 @@ ControlType V4L2Device::v4l2CtrlType(uint32_t ctrlType)\n \t\t * integer type.\n \t\t */\n \t\treturn ControlTypeInteger32;\n+\tcase V4L2_CTRL_TYPE_STRING:\n+\t\treturn ControlTypeString;\n \n \tdefault:\n \t\treturn ControlTypeNone;\n@@ -709,6 +721,7 @@ void V4L2Device::listControls()\n \t\tcase V4L2_CTRL_TYPE_U8:\n \t\tcase V4L2_CTRL_TYPE_U16:\n \t\tcase V4L2_CTRL_TYPE_U32:\n+\t\tcase V4L2_CTRL_TYPE_STRING:\n \t\t\tbreak;\n \t\t/* \\todo Support other control types. */\n \t\tdefault:\n@@ -808,6 +821,21 @@ void V4L2Device::updateControls(ControlList *ctrls,\n \t\t\tvalue.set<int64_t>(v4l2Ctrl.value64);\n \t\t\tbreak;\n \n+\t\tcase ControlTypeString:\n+\t\t\t/*\n+\t\t\t * The ControlValue contains storage for the  maximum\n+\t\t\t * length of the string, and its size matches that. After\n+\t\t\t * the data is retrieved, it must be resized so ControlValue::numElements()\n+\t\t\t * is correct.\n+\t\t\t*\n+\t\t\t * VIDIOC_G_EXT_CTRLS does not return the length of the string,\n+\t\t\t * so we must reassign and let the std::string_view constructor\n+\t\t\t * calculate the true length. Because value is a copy, there will be\n+\t\t\t * no use-after-free issues.\n+\t\t\t */\n+\t\t\tvalue.set<std::string_view>(v4l2Ctrl.string);\n+\t\t\tbreak;\n+\n \t\tdefault:\n \t\t\t/*\n \t\t\t * Note: this catches the ControlTypeInteger32 case.\n","prefixes":["1/4"]}