From patchwork Thu Jul 17 12:48:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 23836 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 CE92DBE175 for ; Thu, 17 Jul 2025 12:49:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BF7E168F86; Thu, 17 Jul 2025 14:49:06 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="jG/DSCM+"; 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 A24CE68F78 for ; Thu, 17 Jul 2025 14:49:02 +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 A4DC721F5; Thu, 17 Jul 2025 14:48:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1752756508; bh=dyllA6vhOpHDbyQVyysv4Hgk9JcCjOP6QWTZDbX9hW8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jG/DSCM+kOm4OaT6kQJpt5A58WcwzJROPUA1L5u3jBTUdwD7LuRxo2ejuhHyaNwWV +2AM2296th0teqQpYul4f9kat3O80GivELT5gLOxRy/U6fnva3XemnL1D0bRF1q3yN 1gGwTqDCrcIVA6pRG4Z4Y43fFOkjOrjgVcbuGkbA= From: Daniel Scally To: libcamera-devel@lists.libcamera.org Cc: Daniel Scally Subject: [PATCH v2 3/4] libcamera: media_device: Allow for a regex to match entity name Date: Thu, 17 Jul 2025 13:48:52 +0100 Message-Id: <20250717124853.2317191-4-dan.scally@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250717124853.2317191-1-dan.scally@ideasonboard.com> References: <20250717124853.2317191-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. Add an overload for MediaDevice::getEntityByName() that accepts a std::basic_regex instead of a string, and use std::regex_search() instead of a direct string comparison to find a matching entity. This allows us to search for entites using regex patterns like "csi-[0-9a-f]{8}.csi2". Signed-off-by: Daniel Scally --- Changes in v2: - Add an overload for ::getEntityByName() instead of replacing the existing functionality. The new overload takes a regex, but will return a nullptr in the event that the given regex matches multiple entities. include/libcamera/internal/media_device.h | 2 ++ src/libcamera/media_device.cpp | 25 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/libcamera/internal/media_device.h b/include/libcamera/internal/media_device.h index b3a48b98..3f28793f 100644 --- a/include/libcamera/internal/media_device.h +++ b/include/libcamera/internal/media_device.h @@ -14,6 +14,7 @@ #include #include +#include #include #include @@ -45,6 +46,7 @@ public: const std::vector &entities() const { return entities_; } MediaEntity *getEntityByName(const std::string &name) const; + MediaEntity *getEntityByName(const std::regex &name) const; MediaLink *link(const std::string &sourceName, unsigned int sourceIdx, const std::string &sinkName, unsigned int sinkIdx); diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index 353f34a8..a0c0df86 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -341,6 +341,31 @@ MediaEntity *MediaDevice::getEntityByName(const std::string &name) const return nullptr; } +/** + * \brief Return the MediaEntity with name matching the regex \a name + * \param[in] name A regex to match the entity name + * \return The entity with name matching the regex \a name, or nullptr if no + * such entity is found + */ +MediaEntity *MediaDevice::getEntityByName(const std::regex &name) const +{ + MediaEntity *entity = nullptr; + + for (MediaEntity *e : entities_) { + if (std::regex_search(e->name(), name)) { + if (entity) { + LOG(MediaDevice, Error) + << "Multiple entities match given regex"; + return nullptr; + } + + entity = e; + } + } + + return entity; +} + /** * \brief Retrieve the MediaLink connecting two pads, identified by entity * names and pad indexes