From patchwork Wed Jun 25 15:53:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Scally X-Patchwork-Id: 23654 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 2E5DCC3237 for ; Wed, 25 Jun 2025 15:53:34 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A7C7868DF8; Wed, 25 Jun 2025 17:53:31 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Tl93aaI7"; 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 4D65A68DE6 for ; Wed, 25 Jun 2025 17:53:27 +0200 (CEST) Received: from mail.ideasonboard.com (cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 13DF9D77; Wed, 25 Jun 2025 17:53:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1750866789; bh=aDYSWJisyufDScRZiZkGRKzIogrFovDgOxs6196AWcM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tl93aaI7VMGdchPKXPjpcMbizzzC+sWCEp1OTksiLMVZlTu2lHou9C7vvdtbstPRI /GCGwjMV2jg1CrhZ3JJxGUYdvsSACPxSXm+D7cxEvlwV3wQdpUMxwbtCB5ctrFH2dB 2g3z218ytGPfjbtseoXb4wb3LJIMkYXVMRl+/VD0= From: Daniel Scally To: libcamera-devel@lists.libcamera.org Cc: Daniel Scally Subject: [PATCH v1 2/2] libcamera: media_device: Use a regex to match entity name Date: Wed, 25 Jun 2025 16:53:08 +0100 Message-Id: <20250625155308.2325438-3-dan.scally@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250625155308.2325438-1-dan.scally@ideasonboard.com> References: <20250625155308.2325438-1-dan.scally@ideasonboard.com> MIME-Version: 1.0 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" 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 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. Update MediaDevice::getEntityByName() such that the string passed to it is used to create a std::basic_regex, and use std::regex_search() instead of a direct string comparison to find a matching entity. This allows us to pass a string that will form a regex to match to the entity instead, for example "csi-[0-9]{8}.csi2". Signed-off-by: Daniel Scally --- src/libcamera/media_device.cpp | 12 ++++++++---- src/libcamera/v4l2_subdevice.cpp | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index 353f34a8..27180ca5 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -328,14 +329,17 @@ done: */ /** - * \brief Return the MediaEntity with name \a name - * \param[in] name The entity name - * \return The entity with \a name, or nullptr if no such entity is found + * \brief Return the MediaEntity with name matching the regex \a name + * \param[in] name Regex to match against the entity name + * \return The entity with name matching \a name, or nullptr if no such entity + * is found */ MediaEntity *MediaDevice::getEntityByName(const std::string &name) const { + std::regex name_regex(name); + for (MediaEntity *e : entities_) - if (e->name() == name) + if (std::regex_search(e->name(), name_regex)) return e; return nullptr; diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 33279654..4868785d 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -1748,10 +1748,10 @@ const std::string &V4L2Subdevice::model() */ /** - * \brief Create a new video subdevice instance from \a entity in media device + * \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 The media entity name + * \param[in] entity A regex that will match media entity name * * \return A newly created V4L2Subdevice on success, nullptr otherwise */