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