From patchwork Thu Jul 17 12:48:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 23837 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 6696CC3324 for ; Thu, 17 Jul 2025 12:49:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id ADEFB68F91; Thu, 17 Jul 2025 14:49:07 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="taoerm3l"; 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 E322E68F7A 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 E85331AE2; 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=1752756509; bh=rnk40mK7wmRbsHbj3DM31FOCqnJVNInWCrJmlSaVjtE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=taoerm3lVpni/dubokTYxtwXaOVOwqKAkRkGOXvIjYv/n61hDRBAZKeQpcgSfrBHp 9wmwxMB/kzitFFkZnNnBX2A7vjGg7/EZ4q4sv7m9Jt47Fe3VV4cbiWmHG68w64xnuc zy9ecLt1Y3068wjZrBuDIoCfJXGrCSz89z0bmrDs= From: Daniel Scally To: libcamera-devel@lists.libcamera.org Cc: Daniel Scally Subject: [PATCH v2 4/4] libcamera: V4L2Subdevice: Allow for a regex to match entity name Date: Thu, 17 Jul 2025 13:48:53 +0100 Message-Id: <20250717124853.2317191-5-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 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 --- Changes in v2: - New patch include/libcamera/internal/v4l2_subdevice.h | 3 +++ src/libcamera/v4l2_subdevice.cpp | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/libcamera/internal/v4l2_subdevice.h b/include/libcamera/internal/v4l2_subdevice.h index fa2a4a21..192141be 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 fd3b18c2..72fcf0d5 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -1760,6 +1760,25 @@ 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() + "'";