From patchwork Wed Jun 25 15:53:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Scally X-Patchwork-Id: 23653 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 19990C3237 for ; Wed, 25 Jun 2025 15:53:33 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0E29268DD0; 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="j9/RUtbq"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1E7A968DD0 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 C879F982; Wed, 25 Jun 2025 17:53:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1750866788; bh=EMQQg7VR7g0025K3LsIPdudZTjOd6jQRXSK9BFGVgN8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j9/RUtbqxhkz0WlzD1+sEhPIxLss2OEBEBkq65K5CUDoAJftQkDB5k8mKhP1a+5cE gqn7tEeuU9o5G6OzapDXYrhiU23C3bHLUeS4w1TlZsRIxSVd1gMlCsX9M6O8t+AbVL uIqJyAIrfJNINGiYlQWVAH8bM1FyfRdn1/zV+heo= From: Daniel Scally To: libcamera-devel@lists.libcamera.org Cc: Daniel Scally Subject: [PATCH v1 1/2] libcamera: device_enumerator: Use regex to match entity names Date: Wed, 25 Jun 2025 16:53:07 +0100 Message-Id: <20250625155308.2325438-2-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 entities in a media graph have names that might differ from implementation to implementation; for example the Camera Receiver Unit and CSI-2 receiver on the KakiP board have entities with names that include their address, in the form "csi-16000400.csi2". Passing that entity name to DeviceMatch is too inflexible given it would only work if that specific CSI-2 receiver were the one being used. Update DeviceMatch.add() 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 in DeviceMatch::match(). This allows us to pass a string that will form a regex expression to match to the entity instead, for example "csi-[0-9]{8}.csi2". Signed-off-by: Daniel Scally --- .../libcamera/internal/device_enumerator.h | 3 ++- src/libcamera/device_enumerator.cpp | 27 ++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/include/libcamera/internal/device_enumerator.h b/include/libcamera/internal/device_enumerator.h index db3532a9..fce7f0ea 100644 --- a/include/libcamera/internal/device_enumerator.h +++ b/include/libcamera/internal/device_enumerator.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include #include @@ -28,7 +29,7 @@ public: private: std::string driver_; - std::vector entities_; + std::vector entities_; }; class DeviceEnumerator diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp index ae17862f..e22d2822 100644 --- a/src/libcamera/device_enumerator.cpp +++ b/src/libcamera/device_enumerator.cpp @@ -52,15 +52,15 @@ LOG_DEFINE_CATEGORY(DeviceEnumerator) * device enumerator to find matching media devices. * * A DeviceMatch is created with a specific Linux device driver in mind, - * therefore the name of the driver is a required property. One or more Entity - * names can be added as match criteria. + * therefore the name of the driver is a required property. Regex expressions to + * match one or more Entity names can be added as match criteria. * - * Pipeline handlers are recommended to add entities to DeviceMatch as - * appropriate to ensure that the media device they need can be uniquely - * identified. This is useful when the corresponding kernel driver can produce - * different graphs, for instance as a result of different driver versions or - * hardware configurations, and not all those graphs are suitable for a pipeline - * handler. + * Pipeline handlers are recommended to add regex expressions for entities to + * DeviceMatch as appropriate to ensure that the media device they need can be + * uniquely identified. This is useful when the corresponding kernel driver can + * produce different graphs, for instance as a result of different driver + * versions or hardware configurations, and not all those graphs are suitable + * for a pipeline handler. */ /** @@ -73,12 +73,13 @@ DeviceMatch::DeviceMatch(const std::string &driver) } /** - * \brief Add a media entity name to the search pattern - * \param[in] entity The name of the entity in the media graph + * \brief Add a media entity regex string to the search pattern + * \param[in] entity A regex string to match the entity in the media graph */ void DeviceMatch::add(const std::string &entity) { - entities_.push_back(entity); + std::regex entity_regex(entity); + entities_.push_back(entity_regex); } /** @@ -96,11 +97,11 @@ bool DeviceMatch::match(const MediaDevice *device) const if (driver_ != device->driver()) return false; - for (const std::string &name : entities_) { + for (const std::regex &name_regex : entities_) { bool found = false; for (const MediaEntity *entity : device->entities()) { - if (name == entity->name()) { + if (std::regex_search(entity->name(), name_regex)) { if (!entity->deviceNode().empty()) { found = true; break; 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 */