From patchwork Wed Dec 3 09:14:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 25347 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 F0ECFC32AF 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 1511A60F4A; Wed, 3 Dec 2025 10:14:47 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="X69rBGA+"; 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 AC6EC60D39 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 F2EC71787; 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=1764753148; bh=hjahXNah1RbuUiN7aDtizRrX6Ko4xbWUknSuL9r6v+8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=X69rBGA+WjyDyMzRgsncfA69F6ddE6XKC7Vve2XTjtA/yCdKnX7UhT1ivyitT2VmU VzOUR68lK64KdZyEjbvfW7O/V31TJpiQubQ6i93x4yUfe8KYXhF2Tq1VSebgbhnSek f9g0L/AIBijP9gt9DYCE7B5SNnn+HfrwHR6IUE44= From: Jacopo Mondi Date: Wed, 03 Dec 2025 10:14:24 +0100 Subject: [PATCH v3 4/4] libcamera: V4L2Subdevice: Get device by regexp MIME-Version: 1.0 Message-Id: <20251203-rzv2h-pre-v3-4-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=3442; i=jacopo.mondi@ideasonboard.com; h=from:subject:message-id; bh=af7m13ES9de6oF4m50q/afkIeXZbh+NVBRixZ9gOgRE=; b=owEBbQKS/ZANAwAKAXI0Bo8WoVY8AcsmYgBpL/+ACEUPXWu3eN5Kk0rj7Kzi4bh3LUhhBXyjr 8rLmGvias2JAjMEAAEKAB0WIQS1xD1IgJogio9YOMByNAaPFqFWPAUCaS//gAAKCRByNAaPFqFW PKdoD/9j0IBsLPuGMzARAdbpzUapEyYt+ezgRqu0sL8CjSDcx8t6tH+OsyZCDKtmfxf/8FSwj5F A2EnZDnKfDsmfFKr+aTbF1Xwca96kVCEKDK6Do/6FeaW3RaY2tWPieIoCATTfEQWeejaIm1xrPv wSnxJ0J7nOkXrcwKj9F9dEnp/orp0cYWxcfDpGdf139fRsfwpoqKPw8MhijEa3UWSkCi+1FaTtS jHNVBxIA/AqADq29kivVFZxlHJEgTJ7VLhNwXCvf3vJwC0rtAFKVriW2tqgHciGNbmgg7WbXlbc 1wLwbVNN+VScJHtvUHc23mlxzlrLvbft2i3j+jsa4xIQhVzfArE6mXDmnz8z4NxrIuxpOCqL6lk xoK6YtcNWZGoxfkTd8k9ofvNTPrZZ5efAkCZlDSDR8h8eopwb4CNrVvqvN8bmEK++1ZxPdGKhAu sRNFnwnbhQC+RH4lji5FTXXG/ZsOc9IaPPv1+zZa5AZ6+gd2SJUG3y/Cs6OMbCdyUQNQSyIuxWw TQg55/5/I0rhn1TdGuhQWAuCF5yw5xJSL3pxQZ2iPRuNucbHBeKi2OXltMaJQ1PvqVglaAuBOkL t/rLJkVmhH5g6WM7VBYaWmWO1XCnlP3bf4I6ifjPajfYvMQbblapqt2AzeyumqHVbX8eRChvQ0V TXsewSDtzpJI9sg== 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 V4L2Subdevice::fromEntityName() is too inflexible given it would only then work if that specific CSI-2 receiver were the one being used. Add an overload for V4L2Subdevice::fromEntityName() to instead allow users to pass a std::basic_regex, and use std::regex_search() instead of a direct string comparison to find a matching entity. Ths allows us to form regular expressions like "csi-[0-9a-f]{8}.csi2" to find the entities. Signed-off-by: Daniel Scally Reviewed-by: Stefan Klug Reviewed-by: Jacopo Mondi Signed-off-by: Jacopo Mondi --- include/libcamera/internal/v4l2_subdevice.h | 3 +++ src/libcamera/v4l2_subdevice.cpp | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index c1cde1df2e369101eee7ff351f14f81098ec597b..c37a82afa881db9566fa7a0bd8dbdfb0e9f029e8 100644 --- a/include/libcamera/internal/v4l2_subdevice.h +++ b/include/libcamera/internal/v4l2_subdevice.h @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -163,6 +164,8 @@ public: static std::unique_ptr fromEntityName(const MediaDevice *media, const std::string &entity); + static std::unique_ptr + fromEntityName(const MediaDevice *media, const std::regex &entity); protected: std::string logPrefix() const override; diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index b75edffe762155e428e039b4884bed3d469ba751..199424600f582b918e7daa5b77fbec426c8b408c 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -1748,7 +1748,6 @@ const std::string &V4L2Subdevice::model() * \a media * \param[in] media The media device where the entity is registered * \param[in] entity The media entity name - * * \return A newly created V4L2Subdevice on success, nullptr otherwise */ std::unique_ptr @@ -1762,6 +1761,24 @@ V4L2Subdevice::fromEntityName(const MediaDevice *media, return std::make_unique(mediaEntity); } +/** + * \brief Create a new video subdevice instance from an entity in media device + * \a media + * \param[in] media The media device where the entity is registered + * \param[in] entity A regex that will match the media entity's name + * \return A newly created V4L2Subdevice on success, nullptr otherwise + */ +std::unique_ptr +V4L2Subdevice::fromEntityName(const MediaDevice *media, + const std::regex &entity) +{ + MediaEntity *mediaEntity = media->getEntityByName(entity); + if (!mediaEntity) + return nullptr; + + return std::make_unique(mediaEntity); +} + std::string V4L2Subdevice::logPrefix() const { return "'" + entity_->name() + "'";