{"id":25346,"url":"https://patchwork.libcamera.org/api/patches/25346/?format=json","web_url":"https://patchwork.libcamera.org/patch/25346/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20251203-rzv2h-pre-v3-3-1493e0638626@ideasonboard.com>","date":"2025-12-03T09:14:23","name":"[v3,3/4] libcamera: media_device: Get entity by regexp","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"47e77609938feb2dbe8b95a57332adfa4b4a3006","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/?format=json","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/25346/mbox/","series":[{"id":5634,"url":"https://patchwork.libcamera.org/api/series/5634/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5634","date":"2025-12-03T09:14:20","name":"Use regular expressions for entity name matching","version":3,"mbox":"https://patchwork.libcamera.org/series/5634/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/25346/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/25346/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 93E6AC326B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  3 Dec 2025 09:14:48 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 74DCF60F39;\n\tWed,  3 Dec 2025 10:14:46 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9E1BC60D3C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  3 Dec 2025 10:14:42 +0100 (CET)","from [192.168.1.104] (net-93-65-100-155.cust.vodafonedsl.it\n\t[93.65.100.155])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id AF545177D;\n\tWed,  3 Dec 2025 10:12:27 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"kMhQEbiY\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1764753147;\n\tbh=OK+fB7Vp6TOD7TO3OMr+jM9hUioqx6bIbfyn9i+eTAg=;\n\th=From:Date:Subject:References:In-Reply-To:To:Cc:From;\n\tb=kMhQEbiYelLcLY6dAPbkBIDfNzrBMzxyozv88yW5s6DOojaD7tMtXLUkn2Ck+VcGB\n\t3ivrCPcXwardDKLIhYmtNwCWnpsMd+oC0eUCiUumCAzBvC9m7q1AXPoWpyseeOI/Nf\n\t+qXGP/gsXJlfHt2EBTYYV+oaKqAr9QXYLIH8/kos=","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","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","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"7bit","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 <dan.scally@ideasonboard.com>, \n\tlibcamera-devel@lists.libcamera.org","Cc":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>, \n\tStefan Klug <stefan.klug@ideasonboard.com>","X-Mailer":"b4 0.14.2","X-Developer-Signature":"v=1; a=openpgp-sha256; l=3756;\n\ti=jacopo.mondi@ideasonboard.com; h=from:subject:message-id;\n\tbh=kCWeRaEOu8rOmLYcRmGBXdnXFslSgWVGZBiXQNhQ29Q=;\n\tb=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBpL/+ALyrPrjOhot48qcTBtH/l/EHlLK8tSadOa\n\tdK5c53krCCJAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaS//gAAKCRByNAaPFqFW\n\tPLbKEAC5QeVe4bzansOu1RlNoNP7bA29tIRARTHUB2d98LlL2BeGrV4XHJ2S2l1Ica6a80PKWj0\n\tbRF/Jx/nBBIIaG/9UBJjgm6rbAgYIr9qfDsqem1gmR9UnLWBUseqUu5mW1PPQOKvKCeCPaEQl/l\n\terRSsLg3xB7B64U+VPNYA0Yb3l5SziO7M2wOtrUaL06L1qrQbs2976fDj+hWyj/F4K2x9l5aMTc\n\tIhau/oo/d36jJ0fkWpct1G0x+ZPzoMqBelI1j4EZOrIZIb2zjVdYB56hucfj5Y2TD0OOffF/iIX\n\tPn9J4hjOlCV7RkbzrJQBKQqCiMUtpJo2s+AQe1uOW3CQEmf0B6lGg635u3Q0JPh9lQEZW+KC741\n\tycEqHDWAB5bIeFSNdIiIntoy5/sehvo9L6/in66BGvgEryguH3lL2x+94wXoE+Hxv30HlG5VM2H\n\tJLgMz3q90RzCrn2KEmJQIrAfNNIF8G+X5JeOAq90af430/ZpBzzco7yR7h/zaZ6kPpc5+oOgqwQ\n\taloDweBejW3Gvp8cVdyJYk0w1b2o/QPEq/ukKQuI0FZuzwKavj9W8HTYhWAHepFCWKr3hsNd8ex\n\tVs4t74LXG7xlRFYQAQhpLS1f9FKpJUnCymj8VTzpnL3Ffzp3LOruOpcj6kGmsHBKx7yxQipP9zS\n\tv3+/zSNheSDVBhA==","X-Developer-Key":"i=jacopo.mondi@ideasonboard.com; a=openpgp;\n\tfpr=72392EDC88144A65C701EA9BA5826A2587AD026B","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":"From: Daniel Scally <dan.scally@ideasonboard.com>\n\nSome kernel drivers give their entities names that will differ from\nimplementation to implementation; for example the drivers for the\nCamera Receiver Unit and CSI-2 receiver in the RZ/V2H(P) SoC give their\nentities names that include their memory address, in the format\n\"csi-16000400.csi2\". Passing that entity name to\nMediaDevice::getEntityByName() is too inflexible given it would only\nthen work if that specific CSI-2 receiver were the one being used.\n\nAdd an overload for MediaDevice::getEntityByName() that accepts a\nstd::basic_regex instead of a string, and use std::regex_search()\ninstead of a direct string comparison to find a matching entity. This\nallows us to search for entites using regex patterns like\n\"csi-[0-9a-f]{8}.csi2\".\n\nSigned-off-by: Daniel Scally <dan.scally@ideasonboard.com>\nReviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\nSigned-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\n---\nChanges in v3:\n- Exit early when searching regexp\n\n\tfor (MediaEntity *e : entities_) {\n\t      \tif (!std::regex_search(e->name(), name))\n\t\t\tcontinue;\n\n\t\tif (entity) {\n\n\t\t}\n\t}\n\n  compared to\n\n\tfor (MediaEntity *e : entities_) {\n\t      \tif (std::regex_search(e->name(), name)) {\n\t\t\tif (entity) {\n\n\t\t\t}\n\t\t}\n\t}\n\nChanges in v2:\n\n- Add an overload for ::getEntityByName() instead of replacing the\n  existing functionality. The new overload takes a regex, but will\n  return a nullptr in the event that the given regex matches multiple\n  entities.\n---\n include/libcamera/internal/media_device.h |  2 ++\n src/libcamera/media_device.cpp            | 26 ++++++++++++++++++++++++++\n 2 files changed, 28 insertions(+)","diff":"diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h\nindex 2eb3ad988b09fca304b71eb726cc724d301e7891..5c1f14b63823f31bcf70eeb3abb6efe9bc891f29 100644\n--- a/include/libcamera/internal/media_device.h\n+++ b/include/libcamera/internal/media_device.h\n@@ -15,6 +15,7 @@\n #include <linux/media.h>\n \n #include <libcamera/base/log.h>\n+#include <libcamera/base/regex.h>\n #include <libcamera/base/signal.h>\n #include <libcamera/base/unique_fd.h>\n \n@@ -47,6 +48,7 @@ public:\n \n \tconst std::vector<MediaEntity *> &entities() const { return entities_; }\n \tMediaEntity *getEntityByName(const std::string &name) const;\n+\tMediaEntity *getEntityByName(const std::regex &name) const;\n \n \tMediaLink *link(const std::string &sourceName, unsigned int sourceIdx,\n \t\t\tconst std::string &sinkName, unsigned int sinkIdx);\ndiff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\nindex 2a848ebed99894fff3e44fad63e1f17d0ba9d647..8c82a2b1488b4d72eb3e0930f04ff604395e9f92 100644\n--- a/src/libcamera/media_device.cpp\n+++ b/src/libcamera/media_device.cpp\n@@ -342,6 +342,32 @@ MediaEntity *MediaDevice::getEntityByName(const std::string &name) const\n \treturn nullptr;\n }\n \n+/**\n+ * \\brief Return the MediaEntity with name matching the regex \\a name\n+ * \\param[in] name A regex to match the entity name\n+ * \\return The entity matching the regex \\a name, or nullptr if no such entity\n+ * is found or multiple entities match on \\a name\n+ */\n+MediaEntity *MediaDevice::getEntityByName(const std::regex &name) const\n+{\n+\tMediaEntity *entity = nullptr;\n+\n+\tfor (MediaEntity *e : entities_) {\n+\t\tif (!std::regex_search(e->name(), name))\n+\t\t\tcontinue;\n+\n+\t\tif (entity) {\n+\t\t\tLOG(MediaDevice, Error)\n+\t\t\t\t<< \"Multiple entities match given regex\";\n+\t\t\treturn nullptr;\n+\t\t}\n+\n+\t\tentity = e;\n+\t}\n+\n+\treturn entity;\n+}\n+\n /**\n  * \\brief Retrieve the MediaLink connecting two pads, identified by entity\n  * names and pad indexes\n","prefixes":["v3","3/4"]}