[{"id":35473,"web_url":"https://patchwork.libcamera.org/comment/35473/","msgid":"<175551361843.2014387.15734102575462794481@localhost>","date":"2025-08-18T10:40:18","subject":"Re: [PATCH v2 3/4] libcamera: media_device: Allow for a regex to\n\tmatch entity name","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"content":"Hi Dan,\n\nThank you for the patch.\n\nQuoting Daniel Scally (2025-07-17 14:48:52)\n> Some kernel drivers give their entities names that will differ from\n> implementation to implementation; for example the drivers for the\n> Camera Receiver Unit and CSI-2 receiver in the RZ/V2H SoC give their\n> entities names that include their memory address, in the format\n> \"csi-16000400.csi2\". Passing that entity name to\n> MediaDevice::getEntityByName() is too inflexible given it would only\n> then work if that specific CSI-2 receiver were the one being used.\n> \n> Add an overload for MediaDevice::getEntityByName() that accepts a\n> std::basic_regex instead of a string, and use std::regex_search()\n> instead of a direct string comparison to find a matching entity. This\n> allows us to search for entites using regex patterns like\n> \"csi-[0-9a-f]{8}.csi2\".\n> \n> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n> ---\n> Changes in v2:\n> \n>         - Add an overload for ::getEntityByName() instead of\n>         replacing the existing functionality. The new overload\n>         takes a regex, but will return a nullptr in the event\n>         that the given regex matches multiple entities.\n> \n>  include/libcamera/internal/media_device.h |  2 ++\n>  src/libcamera/media_device.cpp            | 25 +++++++++++++++++++++++\n>  2 files changed, 27 insertions(+)\n> \n> diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h\n> index b3a48b98..3f28793f 100644\n> --- a/include/libcamera/internal/media_device.h\n> +++ b/include/libcamera/internal/media_device.h\n> @@ -14,6 +14,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> @@ -45,6 +46,7 @@ public:\n>  \n>         const std::vector<MediaEntity *> &entities() const { return entities_; }\n>         MediaEntity *getEntityByName(const std::string &name) const;\n> +       MediaEntity *getEntityByName(const std::regex &name) const;\n>  \n>         MediaLink *link(const std::string &sourceName, unsigned int sourceIdx,\n>                         const std::string &sinkName, unsigned int sinkIdx);\n> diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\n> index 353f34a8..a0c0df86 100644\n> --- a/src/libcamera/media_device.cpp\n> +++ b/src/libcamera/media_device.cpp\n> @@ -341,6 +341,31 @@ MediaEntity *MediaDevice::getEntityByName(const std::string &name) const\n>         return 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 with name matching the regex \\a name, or nullptr if no\n> + * such entity is found\n> + */\n> +MediaEntity *MediaDevice::getEntityByName(const std::regex &name) const\n> +{\n> +       MediaEntity *entity = nullptr;\n> +\n> +       for (MediaEntity *e : entities_) {\n> +               if (std::regex_search(e->name(), name)) {\n\nI far as my planning goes I'll need a\nMediaEntinty::matchesName(std::regex) function. But that can also be\nadded on top. So\n\nReviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\nRegards,\nStefan\n\n> +                       if (entity) {\n> +                               LOG(MediaDevice, Error)\n> +                                       << \"Multiple entities match given regex\";\n> +                               return nullptr;\n> +                       }\n> +\n> +                       entity = e;\n> +               }\n> +       }\n> +\n> +       return entity;\n> +}\n> +\n>  /**\n>   * \\brief Retrieve the MediaLink connecting two pads, identified by entity\n>   * names and pad indexes\n> -- \n> 2.34.1\n>","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 1C67BBEFBE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 18 Aug 2025 10:40:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 69DBF69257;\n\tMon, 18 Aug 2025 12:40:22 +0200 (CEST)","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 1794269257\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 18 Aug 2025 12:40:21 +0200 (CEST)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:766d:a405:f64e:fe3a])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id DCA6A2394; \n\tMon, 18 Aug 2025 12:39:23 +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=\"IZiw/UTL\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1755513564;\n\tbh=l+QZyQD14z2UrlaUvwIlrOu2GzFRsxKTal1aTuxWBIs=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=IZiw/UTLFLlcksJqaiAyN+671lF7eyfDvBxZmmeXAdKz1tGe5rdxfZOIz4ahw37/p\n\thNuY0Gc2pkqM8XmaoVT/Aesc16YqDLexEMP1wAR8iKahawngKSCzwH6HsPhyBlmTt/\n\tBsyJILhWkIp6ymL+txvXk2BaHxu5OF2x3y8rIgSo=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250717124853.2317191-4-dan.scally@ideasonboard.com>","References":"<20250717124853.2317191-1-dan.scally@ideasonboard.com>\n\t<20250717124853.2317191-4-dan.scally@ideasonboard.com>","Subject":"Re: [PATCH v2 3/4] libcamera: media_device: Allow for a regex to\n\tmatch entity name","From":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"Daniel Scally <dan.scally@ideasonboard.com>","To":"Daniel Scally <dan.scally@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 18 Aug 2025 12:40:18 +0200","Message-ID":"<175551361843.2014387.15734102575462794481@localhost>","User-Agent":"alot/0.12.dev8+g2c003385c862.d20250602","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>"}},{"id":36523,"web_url":"https://patchwork.libcamera.org/comment/36523/","msgid":"<ltrniwtocsku5ou755ej7o3ajxzsrj57d2brfx4ektaffqazmi@x2yfjfevd5vi>","date":"2025-10-28T15:54:07","subject":"Re: [PATCH v2 3/4] libcamera: media_device: Allow for a regex to\n\tmatch entity name","submitter":{"id":143,"url":"https://patchwork.libcamera.org/api/people/143/","name":"Jacopo Mondi","email":"jacopo.mondi@ideasonboard.com"},"content":"Hi Dan\n\nOn Thu, Jul 17, 2025 at 01:48:52PM +0100, Daniel Scally wrote:\n> Some kernel drivers give their entities names that will differ from\n> implementation to implementation; for example the drivers for the\n> Camera Receiver Unit and CSI-2 receiver in the RZ/V2H SoC give their\n> entities names that include their memory address, in the format\n> \"csi-16000400.csi2\". Passing that entity name to\n> MediaDevice::getEntityByName() is too inflexible given it would only\n> then work if that specific CSI-2 receiver were the one being used.\n>\n> Add an overload for MediaDevice::getEntityByName() that accepts a\n> std::basic_regex instead of a string, and use std::regex_search()\n> instead of a direct string comparison to find a matching entity. This\n> allows us to search for entites using regex patterns like\n> \"csi-[0-9a-f]{8}.csi2\".\n>\n> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n> ---\n> Changes in v2:\n>\n> \t- Add an overload for ::getEntityByName() instead of\n> \treplacing the existing functionality. The new overload\n> \ttakes a regex, but will return a nullptr in the event\n> \tthat the given regex matches multiple entities.\n>\n>  include/libcamera/internal/media_device.h |  2 ++\n>  src/libcamera/media_device.cpp            | 25 +++++++++++++++++++++++\n>  2 files changed, 27 insertions(+)\n>\n> diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h\n> index b3a48b98..3f28793f 100644\n> --- a/include/libcamera/internal/media_device.h\n> +++ b/include/libcamera/internal/media_device.h\n> @@ -14,6 +14,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> @@ -45,6 +46,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);\n> diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\n> index 353f34a8..a0c0df86 100644\n> --- a/src/libcamera/media_device.cpp\n> +++ b/src/libcamera/media_device.cpp\n> @@ -341,6 +341,31 @@ 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 with name matching the regex \\a name, or nullptr if no\n> + * such entity is found\n      such entity is found or multiple entities match on \\a regexp\n\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\tif (entity) {\n> +\t\t\t\tLOG(MediaDevice, Error)\n> +\t\t\t\t\t<< \"Multiple entities match given regex\";\n> +\t\t\t\treturn nullptr;\n> +\t\t\t}\n> +\n> +\t\t\tentity = e;\n> +\t\t}\n> +\t}\n> +\n> +\treturn entity;\n> +}\n> +\n\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\nThanks\n  j\n\n>  /**\n>   * \\brief Retrieve the MediaLink connecting two pads, identified by entity\n>   * names and pad indexes\n> --\n> 2.34.1\n>","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 2FBB5BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 28 Oct 2025 15:54:13 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4E62D607E2;\n\tTue, 28 Oct 2025 16:54:12 +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 71A66606DE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 28 Oct 2025 16:54:10 +0100 (CET)","from ideasonboard.com (mob-5-90-58-13.net.vodafone.it [5.90.58.13])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 9CA90446;\n\tTue, 28 Oct 2025 16:52:21 +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=\"q8chub4L\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1761666741;\n\tbh=7QF29qtW/4kpDXxBMTa2f4oXJ7Ef7zddwMyRK/odfOQ=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=q8chub4L5f33K1OFTgnnpYd4Z+R1rccDpvoP7e2Sb0bNh8QLwddp+0d6jTXLLtvFv\n\tlYPFpM3Z9xItj8DNg+pQoCPAxw83ac5Yubl2WV0DGXveOr3Erf5u2s9xnmX1y37RRz\n\tcaBIWHJtKN1c4wH3jdKq8Hjza89GW6cysjGdkrTM=","Date":"Tue, 28 Oct 2025 16:54:07 +0100","From":"Jacopo Mondi <jacopo.mondi@ideasonboard.com>","To":"Daniel Scally <dan.scally@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH v2 3/4] libcamera: media_device: Allow for a regex to\n\tmatch entity name","Message-ID":"<ltrniwtocsku5ou755ej7o3ajxzsrj57d2brfx4ektaffqazmi@x2yfjfevd5vi>","References":"<20250717124853.2317191-1-dan.scally@ideasonboard.com>\n\t<20250717124853.2317191-4-dan.scally@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20250717124853.2317191-4-dan.scally@ideasonboard.com>","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>"}}]