From patchwork Wed Dec 3 09:14:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 25344 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 9FE55C3260 for ; Wed, 3 Dec 2025 09:14:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0702E60F4C; Wed, 3 Dec 2025 10:14:45 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ArNq1o1M"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2FB5F60D39 for ; Wed, 3 Dec 2025 10:14:42 +0100 (CET) Received: from [192.168.1.104] (net-93-65-100-155.cust.vodafonedsl.it [93.65.100.155]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1AD2411D5; Wed, 3 Dec 2025 10:12:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1764753147; bh=ViwOVu9KPvO9NVPh7IlZCO2GIqUbssGWLqWxM7acVvc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ArNq1o1MJVLsBZpIt0t7rc9rB/BIWmpuKezPNjuN7Dz0CUHWpLnifCR2yzAeo7xNp wPplSIHEqDVV8cbWhmAqSXcJnyhUdNLl4ufYPZ/mFMsXZGALQkge/958uTjC0HQaUH 3Byr/PFFPsxDa0xYhFeODhiU4Bz5q/SfIHWLqNZc= From: Jacopo Mondi Date: Wed, 03 Dec 2025 10:14:21 +0100 Subject: [PATCH v3 1/4] libcamera: base: Wrap MIME-Version: 1.0 Message-Id: <20251203-rzv2h-pre-v3-1-1493e0638626@ideasonboard.com> References: <20251203-rzv2h-pre-v3-0-1493e0638626@ideasonboard.com> In-Reply-To: <20251203-rzv2h-pre-v3-0-1493e0638626@ideasonboard.com> To: Daniel Scally , libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi , Laurent Pinchart , Stefan Klug X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2493; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=S3CsftrNrQZfUspeiZ2HEbUMI6Klm6nwBgv+4OryKvA=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBpL/+AxWnje9mm74qDF6TJnObEOlhU/z/4qn2fO 3CzK5E6qXSJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaS//gAAKCRByNAaPFqFW PGOqD/0Qgz4FkpLjIbSukhS2egKZFzZVJWUPI0yxs0wFMBcUuJNxK037dETfQy+6pnt+Q6MADK8 ZW4ZditLQ/j216HnbZiqIpAhMsphVkpUNAzG0Z67R84QnoxITKO2nSz6nHkwxJv82Jo7TDVkaOy vR+l3HsksS7AO3aOsewmlZzQLDUwc4kqfHvoztHim9c0qXrrVQmN83h2lpVIuPP+2YxP108vbqO RtX59jj+Wif8rF+KIFd0vK+FijKKJhTG0X+xJfUdKl155ONLgHl+4Q6FWeROwQK9jHSU9AC0VD5 eMIPjXDaxne8W09vO6NUv60qgHY7Pc+lRia067n6q9I+mWDOb89EMI+Z9bLcfAYAUpHrqNN7U5F D1aZkU9FDCorEAnOiGgUi8/dLyeMH5WkSkAC9UvowrlXMG9hExvs00ufVFunIC6eDYerEU//24B 1ScYPJsoMCSbvRd8S2FbDjYYMO0/LW6j7J8X8BLFJjpPE4hAkAkh1ULHRwAXTx5w7ngIBxr2zCN f3NoZemQ9dnQM7Ie0BZpRieD3icXLLjvTYZ+4w4tAEfRCW5lMqr2awaT6b6PnnvcMowxJrbR0C+ Ue8LeTAmf1ui9MIKM1lEiaFmhABrfrCjEjqzekrJDG+F++gCX/W/hAnSNOBHaqagfD1DjmD5YYK 9KbgJzpkO4Ws99A== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B 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: Daniel Scally Provide a wrapper for regex.h to work around the false-positive compilation errors that crop up in some versions of gcc. Suggested-by: Laurent Pinchart Signed-off-by: Daniel Scally Reviewed-by: Laurent Pinchart Reviewed-by: Stefan Klug Signed-off-by: Jacopo Mondi --- include/libcamera/base/meson.build | 1 + include/libcamera/base/regex.h | 13 +++++++++++++ src/libcamera/v4l2_subdevice.cpp | 8 +------- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build index f28ae4d42a69c755710b51ffc92976bb6fb6a0d8..f84b514191949f625c3c70f116059ee70de464b5 100644 --- a/include/libcamera/base/meson.build +++ b/include/libcamera/base/meson.build @@ -24,6 +24,7 @@ libcamera_base_private_headers = files([ 'message.h', 'mutex.h', 'private.h', + 'regex.h', 'semaphore.h', 'thread.h', 'thread_annotations.h', diff --git a/include/libcamera/base/regex.h b/include/libcamera/base/regex.h new file mode 100644 index 0000000000000000000000000000000000000000..1ae21c1f971387da48282d9144827c75270cdcc6 --- /dev/null +++ b/include/libcamera/base/regex.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2025, Ideas on Board Oy + * + * std::regex wrapper for gcc + */ + +#pragma GCC diagnostic push +#if defined __SANITIZE_ADDRESS__ && defined __OPTIMIZE__ +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif +#include +#pragma GCC diagnostic pop diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 31a2ac72a7ee6f980b6110ba73919f74d3b7bbe2..b75edffe762155e428e039b4884bed3d469ba751 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -13,17 +13,11 @@ #include #include -#pragma GCC diagnostic push -#if defined __SANITIZE_ADDRESS__ && defined __OPTIMIZE__ -#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" -#endif -#include -#pragma GCC diagnostic pop - #include #include #include +#include #include #include From patchwork Wed Dec 3 09:14:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 25345 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 E0948BD80A for ; Wed, 3 Dec 2025 09:14:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F1EC660D39; Wed, 3 Dec 2025 10:14:45 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="W1rTEZaN"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6C0A6606A0 for ; Wed, 3 Dec 2025 10:14:42 +0100 (CET) Received: from [192.168.1.104] (net-93-65-100-155.cust.vodafonedsl.it [93.65.100.155]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6F8431574; Wed, 3 Dec 2025 10:12:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1764753147; bh=ga6BwroBLPac8/Chk0wzAVk1un0uWO+DSXQvAFxHmhU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=W1rTEZaNr9ngA7WErodwJLy+vWa4dgCVJfvxV8zqAerS2PKKSv5abOBipo7svJjcn gUWdO/tMQSS0u5khy2J/Bij/mLoy3ZElpzhlyuNfQDZ2DVa4wQ6Xe59c/plg8bNkLE lH5IFA6dh2ldhdPhQLkyQBaa1D+sIGGSNtw0hRQE= From: Jacopo Mondi Date: Wed, 03 Dec 2025 10:14:22 +0100 Subject: [PATCH v3 2/4] libcamera: device_enumerator: Support regex to match entity names MIME-Version: 1.0 Message-Id: <20251203-rzv2h-pre-v3-2-1493e0638626@ideasonboard.com> References: <20251203-rzv2h-pre-v3-0-1493e0638626@ideasonboard.com> In-Reply-To: <20251203-rzv2h-pre-v3-0-1493e0638626@ideasonboard.com> To: Daniel Scally , libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5163; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=PboEjt+8hFEbpw7D3On0uCQE59Q+aRwMemUVw2PRQ5g=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBpL/+AW0MuITsvieOHMSpOS7jxh5H/f6T7JJLGF KtBEusw4kiJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaS//gAAKCRByNAaPFqFW POZVD/95OLrShplfrDQBdkqUHXvglekOIDpt6L41183Pn07KmLQyMDkQ5dnN0oA/aDhdb8wNByU uDWre5qRvFqFBImPbgotnvu7YUcZY6wMtM2bKK3qNOGXrZv07KYZre/nlYgv6PVPOYpku/tD7Wc WG+imOY9HqOXvN1jqNLYHNjQPld1qjFvqXMHXN6KuV9UeIUtLmoZtCvkoIhJwvZ+bkCLzU7Nkza puZLdmTTH1Mh1dyZgZ2pGL6xIQj5UBSfL/ElE216u6iewdi6ocSvFzXq7w9abhMC4sdS7mImDFb 0gQmPkn5NLsSYXrl7rgrpaGB+Pe2BkMAw6nBQj2+s4ahAY9t2YIXyoGGQccmWmkc+Sg8LWCG/cv cgPgVJPid1R8DGpvoQyAtprRQ3x3HaiyUY44y3UWm+2vQ8ZQ6rlVocO6v1l6tcBGX6Bzvev8Vri wDiUVLm9/L0OmH9W0J9OR74DwbDCLmY6eP1u4vABiMGNpUsnk10AKyCKdtgQpOonS5m3lW8JgA1 1tOcVTU3fjJKXIOg/voQoe4vGLooaPrUZ44M/8Lvizbfg2K2urix6Pp/ubW+sdUdZhWjhX5czWx 6pg1VVpE4lhfC+lPLgbXatxTH05/JO/SuD1VAIPJUIa+sVuzx9nUbeDMgqrbqYh6iNUG5mlaZGb pxlbLmdotMdg3ZA== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B 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: Daniel Scally Some entities in a media graph have names that might differ from implementation to implementation; for example the Camera Receiver Unit and CSI-2 receiver on the RZ/V2H(P) SoC have entities with names that include their address, in the form "csi-16000400.csi2". Passing that entity name to DeviceMatch is too inflexible given it would only work if that specific CSI-2 receiver were the one being used. Add an overload for DeviceMatch::add() such that users can pass in a std::regex instead of a string. Update DeviceMatch::match() to check for entities that are matched by the regular expressions added with the new overload after checking for any exact matches from the vector of strings. This allows us to use regex to match on patterns like "csi-[0-9a-f]{8}.csi2". Signed-off-by: Daniel Scally Reviewed-by: Jacopo Mondi Signed-off-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- Changes in v3: - As suggested by Barnabas accept an std::regex in add() instead of a reference and move it into the entityRegexs_ vector - Exit early in DeviceMatch::match() for (const MediaEntity *entity : device->entities()) { if (!std::regex_search(entity->name(), nameRegex)) continue; if (found) { } } Compared to for (const MediaEntity *entity : device->entities()) { if (std::regex_search(entity->name(), nameRegex)) { if (found) { } } } - Invert the error logic when deviceNode is empty if (entity->deviceNode().empty()) { LOG(DeviceEnumerator, Debug) << "Skip " << entity->name() << ": no device node"; continue; } found = true; Compared to if (!entity->deviceNode().empty()) { found = true; } else { LOG(DeviceEnumerator, Debug) << "Skip " << entity->name() << ": no device node"; } Changes in v2: - Instead of replacing the existing ::add() function and matching process with regex, add an overload for ::add() that takes a regex and incorporate that into ::match() alongside the existing functionality. --- include/libcamera/internal/device_enumerator.h | 3 ++ src/libcamera/device_enumerator.cpp | 39 +++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/device_enumerator.h b/include/libcamera/internal/device_enumerator.h index db3532a9887af913ceee20cbba3f945e56e7b61d..fa8806b0c2a47ab89fdc74fe01ef77bf2e68abb1 100644 --- a/include/libcamera/internal/device_enumerator.h +++ b/include/libcamera/internal/device_enumerator.h @@ -11,6 +11,7 @@ #include #include +#include #include namespace libcamera { @@ -23,12 +24,14 @@ public: DeviceMatch(const std::string &driver); void add(const std::string &entity); + void add(const std::regex entity); bool match(const MediaDevice *device) const; private: std::string driver_; std::vector entities_; + std::vector entityRegexs_; }; class DeviceEnumerator diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp index ae17862f676310ef568e5331106ed661e84b5130..2911d5f0385f9765a2eafce2085d1fd627d94b95 100644 --- a/src/libcamera/device_enumerator.cpp +++ b/src/libcamera/device_enumerator.cpp @@ -53,7 +53,8 @@ LOG_DEFINE_CATEGORY(DeviceEnumerator) * * A DeviceMatch is created with a specific Linux device driver in mind, * therefore the name of the driver is a required property. One or more Entity - * names can be added as match criteria. + * names (or regular expressions designed to match an entity name) can be added + * as match criteria. * * Pipeline handlers are recommended to add entities to DeviceMatch as * appropriate to ensure that the media device they need can be uniquely @@ -81,6 +82,15 @@ void DeviceMatch::add(const std::string &entity) entities_.push_back(entity); } +/** + * \brief Add a regex to match a media entity name to the search pattern + * \param[in] entity The regex intended to match to an entity in the media graph + */ +void DeviceMatch::add(const std::regex entity) +{ + entityRegexs_.push_back(std::move(entity)); +} + /** * \brief Compare a search pattern with a media device * \param[in] device The media device @@ -116,6 +126,33 @@ bool DeviceMatch::match(const MediaDevice *device) const return false; } + for (const std::regex &nameRegex : entityRegexs_) { + bool found = false; + + for (const MediaEntity *entity : device->entities()) { + if (!std::regex_search(entity->name(), nameRegex)) + continue; + + if (found) { + LOG(DeviceEnumerator, Error) + << "Multiple entities match regex"; + return false; + } + + if (entity->deviceNode().empty()) { + LOG(DeviceEnumerator, Debug) + << "Skip " << entity->name() + << ": no device node"; + continue; + } + + found = true; + } + + if (!found) + return false; + } + return true; } From patchwork Wed Dec 3 09:14:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 25346 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 93E6AC326B for ; Wed, 3 Dec 2025 09:14:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 74DCF60F39; Wed, 3 Dec 2025 10:14:46 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="kMhQEbiY"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9E1BC60D3C for ; Wed, 3 Dec 2025 10:14:42 +0100 (CET) Received: from [192.168.1.104] (net-93-65-100-155.cust.vodafonedsl.it [93.65.100.155]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id AF545177D; Wed, 3 Dec 2025 10:12:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1764753147; bh=OK+fB7Vp6TOD7TO3OMr+jM9hUioqx6bIbfyn9i+eTAg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=kMhQEbiYelLcLY6dAPbkBIDfNzrBMzxyozv88yW5s6DOojaD7tMtXLUkn2Ck+VcGB 3ivrCPcXwardDKLIhYmtNwCWnpsMd+oC0eUCiUumCAzBvC9m7q1AXPoWpyseeOI/Nf +qXGP/gsXJlfHt2EBTYYV+oaKqAr9QXYLIH8/kos= From: Jacopo Mondi Date: Wed, 03 Dec 2025 10:14:23 +0100 Subject: [PATCH v3 3/4] libcamera: media_device: Get entity by regexp MIME-Version: 1.0 Message-Id: <20251203-rzv2h-pre-v3-3-1493e0638626@ideasonboard.com> References: <20251203-rzv2h-pre-v3-0-1493e0638626@ideasonboard.com> In-Reply-To: <20251203-rzv2h-pre-v3-0-1493e0638626@ideasonboard.com> To: Daniel Scally , libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi , Stefan Klug X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3756; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=kCWeRaEOu8rOmLYcRmGBXdnXFslSgWVGZBiXQNhQ29Q=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBpL/+ALyrPrjOhot48qcTBtH/l/EHlLK8tSadOa dK5c53krCCJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaS//gAAKCRByNAaPFqFW PLbKEAC5QeVe4bzansOu1RlNoNP7bA29tIRARTHUB2d98LlL2BeGrV4XHJ2S2l1Ica6a80PKWj0 bRF/Jx/nBBIIaG/9UBJjgm6rbAgYIr9qfDsqem1gmR9UnLWBUseqUu5mW1PPQOKvKCeCPaEQl/l erRSsLg3xB7B64U+VPNYA0Yb3l5SziO7M2wOtrUaL06L1qrQbs2976fDj+hWyj/F4K2x9l5aMTc Ihau/oo/d36jJ0fkWpct1G0x+ZPzoMqBelI1j4EZOrIZIb2zjVdYB56hucfj5Y2TD0OOffF/iIX Pn9J4hjOlCV7RkbzrJQBKQqCiMUtpJo2s+AQe1uOW3CQEmf0B6lGg635u3Q0JPh9lQEZW+KC741 ycEqHDWAB5bIeFSNdIiIntoy5/sehvo9L6/in66BGvgEryguH3lL2x+94wXoE+Hxv30HlG5VM2H JLgMz3q90RzCrn2KEmJQIrAfNNIF8G+X5JeOAq90af430/ZpBzzco7yR7h/zaZ6kPpc5+oOgqwQ aloDweBejW3Gvp8cVdyJYk0w1b2o/QPEq/ukKQuI0FZuzwKavj9W8HTYhWAHepFCWKr3hsNd8ex Vs4t74LXG7xlRFYQAQhpLS1f9FKpJUnCymj8VTzpnL3Ffzp3LOruOpcj6kGmsHBKx7yxQipP9zS v3+/zSNheSDVBhA== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B 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: Daniel Scally Some kernel drivers give their entities names that will differ from implementation to implementation; for example the drivers for the Camera Receiver Unit and CSI-2 receiver in the RZ/V2H(P) SoC give their entities names that include their memory address, in the format "csi-16000400.csi2". Passing that entity name to MediaDevice::getEntityByName() is too inflexible given it would only then work if that specific CSI-2 receiver were the one being used. Add an overload for MediaDevice::getEntityByName() that accepts a std::basic_regex instead of a string, and use std::regex_search() instead of a direct string comparison to find a matching entity. This allows us to search for entites using regex patterns like "csi-[0-9a-f]{8}.csi2". Signed-off-by: Daniel Scally Reviewed-by: Stefan Klug Reviewed-by: Jacopo Mondi Signed-off-by: Jacopo Mondi --- Changes in v3: - Exit early when searching regexp for (MediaEntity *e : entities_) { if (!std::regex_search(e->name(), name)) continue; if (entity) { } } compared to for (MediaEntity *e : entities_) { if (std::regex_search(e->name(), name)) { if (entity) { } } } Changes in v2: - Add an overload for ::getEntityByName() instead of replacing the existing functionality. The new overload takes a regex, but will return a nullptr in the event that the given regex matches multiple entities. --- include/libcamera/internal/media_device.h | 2 ++ src/libcamera/media_device.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h index 2eb3ad988b09fca304b71eb726cc724d301e7891..5c1f14b63823f31bcf70eeb3abb6efe9bc891f29 100644 --- a/include/libcamera/internal/media_device.h +++ b/include/libcamera/internal/media_device.h @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -47,6 +48,7 @@ public: const std::vector &entities() const { return entities_; } MediaEntity *getEntityByName(const std::string &name) const; + MediaEntity *getEntityByName(const std::regex &name) const; MediaLink *link(const std::string &sourceName, unsigned int sourceIdx, const std::string &sinkName, unsigned int sinkIdx); diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index 2a848ebed99894fff3e44fad63e1f17d0ba9d647..8c82a2b1488b4d72eb3e0930f04ff604395e9f92 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -342,6 +342,32 @@ MediaEntity *MediaDevice::getEntityByName(const std::string &name) const return nullptr; } +/** + * \brief Return the MediaEntity with name matching the regex \a name + * \param[in] name A regex to match the entity name + * \return The entity matching the regex \a name, or nullptr if no such entity + * is found or multiple entities match on \a name + */ +MediaEntity *MediaDevice::getEntityByName(const std::regex &name) const +{ + MediaEntity *entity = nullptr; + + for (MediaEntity *e : entities_) { + if (!std::regex_search(e->name(), name)) + continue; + + if (entity) { + LOG(MediaDevice, Error) + << "Multiple entities match given regex"; + return nullptr; + } + + entity = e; + } + + return entity; +} + /** * \brief Retrieve the MediaLink connecting two pads, identified by entity * names and pad indexes From patchwork Wed Dec 3 09:14:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 25347 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 F0ECFC32AF for ; Wed, 3 Dec 2025 09:14:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1511A60F4A; Wed, 3 Dec 2025 10:14:47 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="X69rBGA+"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AC6EC60D39 for ; Wed, 3 Dec 2025 10:14:42 +0100 (CET) Received: from [192.168.1.104] (net-93-65-100-155.cust.vodafonedsl.it [93.65.100.155]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id F2EC71787; Wed, 3 Dec 2025 10:12:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1764753148; bh=hjahXNah1RbuUiN7aDtizRrX6Ko4xbWUknSuL9r6v+8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=X69rBGA+WjyDyMzRgsncfA69F6ddE6XKC7Vve2XTjtA/yCdKnX7UhT1ivyitT2VmU VzOUR68lK64KdZyEjbvfW7O/V31TJpiQubQ6i93x4yUfe8KYXhF2Tq1VSebgbhnSek f9g0L/AIBijP9gt9DYCE7B5SNnn+HfrwHR6IUE44= From: Jacopo Mondi Date: Wed, 03 Dec 2025 10:14:24 +0100 Subject: [PATCH v3 4/4] libcamera: V4L2Subdevice: Get device by regexp MIME-Version: 1.0 Message-Id: <20251203-rzv2h-pre-v3-4-1493e0638626@ideasonboard.com> References: <20251203-rzv2h-pre-v3-0-1493e0638626@ideasonboard.com> In-Reply-To: <20251203-rzv2h-pre-v3-0-1493e0638626@ideasonboard.com> To: Daniel Scally , libcamera-devel@lists.libcamera.org Cc: Jacopo Mondi , Stefan Klug X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3442; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=af7m13ES9de6oF4m50q/afkIeXZbh+NVBRixZ9gOgRE=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBpL/+ACEUPXWu3eN5Kk0rj7Kzi4bh3LUhhBXyjr 8rLmGvias2JAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaS//gAAKCRByNAaPFqFW PKdoD/9j0IBsLPuGMzARAdbpzUapEyYt+ezgRqu0sL8CjSDcx8t6tH+OsyZCDKtmfxf/8FSwj5F A2EnZDnKfDsmfFKr+aTbF1Xwca96kVCEKDK6Do/6FeaW3RaY2tWPieIoCATTfEQWeejaIm1xrPv wSnxJ0J7nOkXrcwKj9F9dEnp/orp0cYWxcfDpGdf139fRsfwpoqKPw8MhijEa3UWSkCi+1FaTtS jHNVBxIA/AqADq29kivVFZxlHJEgTJ7VLhNwXCvf3vJwC0rtAFKVriW2tqgHciGNbmgg7WbXlbc 1wLwbVNN+VScJHtvUHc23mlxzlrLvbft2i3j+jsa4xIQhVzfArE6mXDmnz8z4NxrIuxpOCqL6lk xoK6YtcNWZGoxfkTd8k9ofvNTPrZZ5efAkCZlDSDR8h8eopwb4CNrVvqvN8bmEK++1ZxPdGKhAu sRNFnwnbhQC+RH4lji5FTXXG/ZsOc9IaPPv1+zZa5AZ6+gd2SJUG3y/Cs6OMbCdyUQNQSyIuxWw TQg55/5/I0rhn1TdGuhQWAuCF5yw5xJSL3pxQZ2iPRuNucbHBeKi2OXltMaJQ1PvqVglaAuBOkL t/rLJkVmhH5g6WM7VBYaWmWO1XCnlP3bf4I6ifjPajfYvMQbblapqt2AzeyumqHVbX8eRChvQ0V TXsewSDtzpJI9sg== X-Developer-Key: i=jacopo.mondi@ideasonboard.com; a=openpgp; fpr=72392EDC88144A65C701EA9BA5826A2587AD026B 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: Daniel Scally Some kernel drivers give their entities names that will differ from implementation to implementation; for example the drivers for the Camera Receiver Unit and CSI-2 receiver in the RZ/V2H(P) SoC give their entities names that include their memory address, in the format "csi-16000400.csi2". Passing that entity name to V4L2Subdevice::fromEntityName() is too inflexible given it would only then work if that specific CSI-2 receiver were the one being used. Add an overload for V4L2Subdevice::fromEntityName() to instead allow users to pass a std::basic_regex, and use std::regex_search() instead of a direct string comparison to find a matching entity. Ths allows us to form regular expressions like "csi-[0-9a-f]{8}.csi2" to find the entities. Signed-off-by: Daniel Scally Reviewed-by: Stefan Klug Reviewed-by: Jacopo Mondi Signed-off-by: Jacopo Mondi --- include/libcamera/internal/v4l2_subdevice.h | 3 +++ src/libcamera/v4l2_subdevice.cpp | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index c1cde1df2e369101eee7ff351f14f81098ec597b..c37a82afa881db9566fa7a0bd8dbdfb0e9f029e8 100644 --- a/include/libcamera/internal/v4l2_subdevice.h +++ b/include/libcamera/internal/v4l2_subdevice.h @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -163,6 +164,8 @@ public: static std::unique_ptr fromEntityName(const MediaDevice *media, const std::string &entity); + static std::unique_ptr + fromEntityName(const MediaDevice *media, const std::regex &entity); protected: std::string logPrefix() const override; diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index b75edffe762155e428e039b4884bed3d469ba751..199424600f582b918e7daa5b77fbec426c8b408c 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -1748,7 +1748,6 @@ const std::string &V4L2Subdevice::model() * \a media * \param[in] media The media device where the entity is registered * \param[in] entity The media entity name - * * \return A newly created V4L2Subdevice on success, nullptr otherwise */ std::unique_ptr @@ -1762,6 +1761,24 @@ V4L2Subdevice::fromEntityName(const MediaDevice *media, return std::make_unique(mediaEntity); } +/** + * \brief Create a new video subdevice instance from an entity in media device + * \a media + * \param[in] media The media device where the entity is registered + * \param[in] entity A regex that will match the media entity's name + * \return A newly created V4L2Subdevice on success, nullptr otherwise + */ +std::unique_ptr +V4L2Subdevice::fromEntityName(const MediaDevice *media, + const std::regex &entity) +{ + MediaEntity *mediaEntity = media->getEntityByName(entity); + if (!mediaEntity) + return nullptr; + + return std::make_unique(mediaEntity); +} + std::string V4L2Subdevice::logPrefix() const { return "'" + entity_->name() + "'";