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; }