[{"id":35474,"web_url":"https://patchwork.libcamera.org/comment/35474/","msgid":"<175551385409.2014387.4232632297553055522@localhost>","date":"2025-08-18T10:44:14","subject":"Re: [PATCH v2 4/4] libcamera: V4L2Subdevice: 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:53)\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> V4L2Subdevice::fromEntityName() 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 V4L2Subdevice::fromEntityName() to instead allow\n> users to pass a std::basic_regex, and use std::regex_search() instead\n> of a direct string comparison to find a matching entity. Ths allows\n> us to form regular expressions like \"csi-[0-9a-f]{8}.csi2\" to find\n> the entities.\n> \n> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n> ---\n> Changes in v2:\n> \n>         - New patch\n> \n>  include/libcamera/internal/v4l2_subdevice.h |  3 +++\n>  src/libcamera/v4l2_subdevice.cpp            | 19 +++++++++++++++++++\n>  2 files changed, 22 insertions(+)\n> \n> diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h\n> index fa2a4a21..192141be 100644\n> --- a/include/libcamera/internal/v4l2_subdevice.h\n> +++ b/include/libcamera/internal/v4l2_subdevice.h\n> @@ -18,6 +18,7 @@\n>  \n>  #include <libcamera/base/class.h>\n>  #include <libcamera/base/log.h>\n> +#include <libcamera/base/regex.h>\n>  \n>  #include <libcamera/color_space.h>\n>  #include <libcamera/geometry.h>\n> @@ -163,6 +164,8 @@ public:\n>  \n>         static std::unique_ptr<V4L2Subdevice>\n>         fromEntityName(const MediaDevice *media, const std::string &entity);\n> +       static std::unique_ptr<V4L2Subdevice>\n> +       fromEntityName(const MediaDevice *media, const std::regex &entity);\n\nIn this context the function name seems a tiny bit off to me.\nfromEntityNameMatching() or fromEntityMatching() come to mind but are\nalso not super smooth. So I'll leave that to you :-)\n\nReviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\nCheers,\nStefan\n\n>  \n>  protected:\n>         std::string logPrefix() const override;\n> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\n> index fd3b18c2..72fcf0d5 100644\n> --- a/src/libcamera/v4l2_subdevice.cpp\n> +++ b/src/libcamera/v4l2_subdevice.cpp\n> @@ -1760,6 +1760,25 @@ V4L2Subdevice::fromEntityName(const MediaDevice *media,\n>         return std::make_unique<V4L2Subdevice>(mediaEntity);\n>  }\n>  \n> +/**\n> + * \\brief Create a new video subdevice instance from an entity in media device\n> + * \\a media\n> + * \\param[in] media The media device where the entity is registered\n> + * \\param[in] entity A regex that will match the media entity's name\n> + *\n> + * \\return A newly created V4L2Subdevice on success, nullptr otherwise\n> + */\n> +std::unique_ptr<V4L2Subdevice>\n> +V4L2Subdevice::fromEntityName(const MediaDevice *media,\n> +                             const std::regex &entity)\n> +{\n> +       MediaEntity *mediaEntity = media->getEntityByName(entity);\n> +       if (!mediaEntity)\n> +               return nullptr;\n> +\n> +       return std::make_unique<V4L2Subdevice>(mediaEntity);\n> +}\n> +\n>  std::string V4L2Subdevice::logPrefix() const\n>  {\n>         return \"'\" + entity_->name() + \"'\";\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 16181BDCC1\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 18 Aug 2025 10:44:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3D14669259;\n\tMon, 18 Aug 2025 12:44:19 +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 9B13969257\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 18 Aug 2025 12:44:17 +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 5B98E2394; \n\tMon, 18 Aug 2025 12:43:20 +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=\"pmG4Fe3f\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1755513800;\n\tbh=etgKZOYx+o84d9oggDHLvkLuZOZyfqB21E+AcvGL9rA=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=pmG4Fe3fvqxkqcov2nAgYF9kDWzmqfuv71GlXPYAADh9UlzDNBJaxa4ZqmDXDUjKx\n\tLctI88Z0zG6TdPIx/Ne9WisDLtvl5FD5akcJDFZZFG3nWaGLlX4R7unHghlJ6jCjSs\n\txHo9wrHz8gBHojQuRqLGDtsf/MeidY3VrpbYyQ9o=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250717124853.2317191-5-dan.scally@ideasonboard.com>","References":"<20250717124853.2317191-1-dan.scally@ideasonboard.com>\n\t<20250717124853.2317191-5-dan.scally@ideasonboard.com>","Subject":"Re: [PATCH v2 4/4] libcamera: V4L2Subdevice: 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:44:14 +0200","Message-ID":"<175551385409.2014387.4232632297553055522@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":36524,"web_url":"https://patchwork.libcamera.org/comment/36524/","msgid":"<c3eocjinccnfma3ibh3ymmuslzxvotrzofl3swkujd5iyahxq3@hakxmvdlwwqa>","date":"2025-10-28T15:55:15","subject":"Re: [PATCH v2 4/4] libcamera: V4L2Subdevice: 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:53PM +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> V4L2Subdevice::fromEntityName() 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 V4L2Subdevice::fromEntityName() to instead allow\n> users to pass a std::basic_regex, and use std::regex_search() instead\n> of a direct string comparison to find a matching entity. Ths allows\n> us to form regular expressions like \"csi-[0-9a-f]{8}.csi2\" to find\n> the entities.\n>\n> Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>\n> ---\n> Changes in v2:\n>\n> \t- New patch\n>\n>  include/libcamera/internal/v4l2_subdevice.h |  3 +++\n>  src/libcamera/v4l2_subdevice.cpp            | 19 +++++++++++++++++++\n>  2 files changed, 22 insertions(+)\n>\n> diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h\n> index fa2a4a21..192141be 100644\n> --- a/include/libcamera/internal/v4l2_subdevice.h\n> +++ b/include/libcamera/internal/v4l2_subdevice.h\n> @@ -18,6 +18,7 @@\n>\n>  #include <libcamera/base/class.h>\n>  #include <libcamera/base/log.h>\n> +#include <libcamera/base/regex.h>\n>\n>  #include <libcamera/color_space.h>\n>  #include <libcamera/geometry.h>\n> @@ -163,6 +164,8 @@ public:\n>\n>  \tstatic std::unique_ptr<V4L2Subdevice>\n>  \tfromEntityName(const MediaDevice *media, const std::string &entity);\n> +\tstatic std::unique_ptr<V4L2Subdevice>\n> +\tfromEntityName(const MediaDevice *media, const std::regex &entity);\n>\n>  protected:\n>  \tstd::string logPrefix() const override;\n> diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp\n> index fd3b18c2..72fcf0d5 100644\n> --- a/src/libcamera/v4l2_subdevice.cpp\n> +++ b/src/libcamera/v4l2_subdevice.cpp\n> @@ -1760,6 +1760,25 @@ V4L2Subdevice::fromEntityName(const MediaDevice *media,\n>  \treturn std::make_unique<V4L2Subdevice>(mediaEntity);\n>  }\n>\n> +/**\n> + * \\brief Create a new video subdevice instance from an entity in media device\n> + * \\a media\n> + * \\param[in] media The media device where the entity is registered\n> + * \\param[in] entity A regex that will match the media entity's name\n> + *\n\nNo need for an empty line\n\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\nThanks\n  j\n\n> + * \\return A newly created V4L2Subdevice on success, nullptr otherwise\n> + */\n> +std::unique_ptr<V4L2Subdevice>\n> +V4L2Subdevice::fromEntityName(const MediaDevice *media,\n> +\t\t\t      const std::regex &entity)\n> +{\n> +\tMediaEntity *mediaEntity = media->getEntityByName(entity);\n> +\tif (!mediaEntity)\n> +\t\treturn nullptr;\n> +\n> +\treturn std::make_unique<V4L2Subdevice>(mediaEntity);\n> +}\n> +\n>  std::string V4L2Subdevice::logPrefix() const\n>  {\n>  \treturn \"'\" + entity_->name() + \"'\";\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 7C014BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 28 Oct 2025 15:55:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 380DC607DB;\n\tTue, 28 Oct 2025 16:55:20 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3C0A5606DE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 28 Oct 2025 16:55:19 +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 8095C446;\n\tTue, 28 Oct 2025 16:53:30 +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=\"n3IaJyZc\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1761666810;\n\tbh=vN4lEBFl0e/pboLAps8t013I10U9O5jo7X8u/q0LGhc=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=n3IaJyZcRI7TREXy3fj87GR+uFXhsOAXP7CIJuwDORqN84Az42oqXC29GzDHRBjAN\n\tbXsYa5yPT0Rf2OuQfCW9pethv6LP1xBZ9SXwRdcrRTDB48w+dPFQpGPIn1Rk6r2Tf4\n\t6gnpi3j65L20IvAmlf/+Y6jp4X+Ih9dk/gQ+0Dho=","Date":"Tue, 28 Oct 2025 16:55:15 +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 4/4] libcamera: V4L2Subdevice: Allow for a regex to\n\tmatch entity name","Message-ID":"<c3eocjinccnfma3ibh3ymmuslzxvotrzofl3swkujd5iyahxq3@hakxmvdlwwqa>","References":"<20250717124853.2317191-1-dan.scally@ideasonboard.com>\n\t<20250717124853.2317191-5-dan.scally@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20250717124853.2317191-5-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>"}}]