From patchwork Thu Jul 17 12:48:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 23834 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 01532BE175 for ; Thu, 17 Jul 2025 12:49:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9D3A168F7A; Thu, 17 Jul 2025 14:49:04 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="pbZqq2UX"; 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 2A31868F55 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 174521E74; 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=kE0lel7rEFmQFpgrewRogEtlBHDm3vRoU017l0LwWgY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pbZqq2UXCmUx+L6WXRG0hy/JkQkBZFlCRVYPwXS+KUv/ERxRl8pNmjx2SYtclibsB PteGghTIyKuJNVdRa8gpa0YGQwbeNHDM7FM+SGL2hykGm9aWU62Z7zwgXSEH8EYIP5 D4krJpKkE8vNWUV/K7rdF+0MVBGw9CghIIn0LjIs= From: Daniel Scally To: libcamera-devel@lists.libcamera.org Cc: Daniel Scally , Laurent Pinchart Subject: [PATCH v2 1/4] libcamera: base: Wrap Date: Thu, 17 Jul 2025 13:48:50 +0100 Message-Id: <20250717124853.2317191-2-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" Provide a wrapper for regex.h to work around the false-positive compilation errors that crop up in some versions of gcc. Suggested-by: Laurent Pinchart Signed-off-by: Daniel Scally --- Changes in v2: - New patch include/libcamera/base/meson.build | 1 + include/libcamera/base/regex.h | 13 +++++++++++++ src/libcamera/v4l2_subdevice.cpp | 8 +------- 3 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 include/libcamera/base/regex.h diff --git a/include/libcamera/base/meson.build b/include/libcamera/base/meson.build index f28ae4d4..f84b5141 100644 --- a/include/libcamera/base/meson.build +++ b/include/libcamera/base/meson.build @@ -24,6 +24,7 @@ libcamera_base_private_headers = files([ 'message.h', 'mutex.h', 'private.h', + 'regex.h', 'semaphore.h', 'thread.h', 'thread_annotations.h', diff --git a/include/libcamera/base/regex.h b/include/libcamera/base/regex.h new file mode 100644 index 00000000..1ae21c1f --- /dev/null +++ b/include/libcamera/base/regex.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2025, Ideas on Board Oy + * + * std::regex wrapper for gcc + */ + +#pragma GCC diagnostic push +#if defined __SANITIZE_ADDRESS__ && defined __OPTIMIZE__ +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif +#include +#pragma GCC diagnostic pop diff --git a/src/libcamera/v4l2_subdevice.cpp b/src/libcamera/v4l2_subdevice.cpp index 33279654..fd3b18c2 100644 --- a/src/libcamera/v4l2_subdevice.cpp +++ b/src/libcamera/v4l2_subdevice.cpp @@ -13,17 +13,11 @@ #include #include -#pragma GCC diagnostic push -#if defined __SANITIZE_ADDRESS__ && defined __OPTIMIZE__ -#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" -#endif -#include -#pragma GCC diagnostic pop - #include #include #include +#include #include #include From patchwork Thu Jul 17 12:48:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 23835 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 34A78C32C8 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 249B268F7F; 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="mQmdBjjz"; 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 79F3661517 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 640631FA4; 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=AVd9Ab55yqR0mQI/Pk2d8gA9rqaX4VV6i7I8u0PGQoM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mQmdBjjzwYDV45YAVoStsF8NymreqXv3Jd/tcUJjuGwvRsUqpP832yU+H5QJG8t9v 1ynrUe22ZDXMa+omt8mOXR6rAefpEB5HrJbJplih+4DNJ9EGa2Sn1dwisKxp/SYAfz i9OnAN+GqAamHWslhEMlYB7nhXYaTSDIEnWgfrCk= From: Daniel Scally To: libcamera-devel@lists.libcamera.org Cc: Daniel Scally Subject: [PATCH v2 2/4] libcamera: device_enumerator: Support regex to match entity names Date: Thu, 17 Jul 2025 13:48:51 +0100 Message-Id: <20250717124853.2317191-3-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 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. Add an overload for DeviceMatch::add() such that users can pass in a std::regex instead of a string. Update DeviceMatch::match() to check for entities that are matched by the regular expressions added with the new overload after checking for any exact matches from the vector of strings. This allows us to use regex to match on patterns like "csi-[0-9a-f]{8}.csi2". Signed-off-by: Daniel Scally --- Changes in v2: - Instead of replacing the existing ::add() function and matching process with regex, add an overload for ::add() that takes a regex and incorporate that into ::match() alongside the existing functionality. .../libcamera/internal/device_enumerator.h | 4 +- src/libcamera/device_enumerator.cpp | 37 ++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/include/libcamera/internal/device_enumerator.h b/include/libcamera/internal/device_enumerator.h index db3532a9..4e55e172 100644 --- a/include/libcamera/internal/device_enumerator.h +++ b/include/libcamera/internal/device_enumerator.h @@ -11,6 +11,7 @@ #include #include +#include #include namespace libcamera { @@ -23,12 +24,13 @@ public: DeviceMatch(const std::string &driver); void add(const std::string &entity); - + void add(const std::regex &entity); bool match(const MediaDevice *device) const; private: std::string driver_; std::vector entities_; + std::vector entityRegexs_; }; class DeviceEnumerator diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp index ae17862f..191758ca 100644 --- a/src/libcamera/device_enumerator.cpp +++ b/src/libcamera/device_enumerator.cpp @@ -53,7 +53,8 @@ LOG_DEFINE_CATEGORY(DeviceEnumerator) * * 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. + * names (or regular expressions designed to match an entity name) 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 @@ -81,6 +82,15 @@ void DeviceMatch::add(const std::string &entity) entities_.push_back(entity); } +/** + * \brief Add a regex to match a media entity name to the search pattern + * \param[in] entity The regex intended to match to an entity in the media graph + */ +void DeviceMatch::add(const std::regex &entity) +{ + entityRegexs_.push_back(entity); +} + /** * \brief Compare a search pattern with a media device * \param[in] device The media device @@ -116,6 +126,31 @@ bool DeviceMatch::match(const MediaDevice *device) const return false; } + for (const std::regex &nameRegex : entityRegexs_) { + bool found = false; + + for (const MediaEntity *entity : device->entities()) { + if (std::regex_search(entity->name(), nameRegex)) { + if (found) { + LOG(DeviceEnumerator, Error) + << "Multiple entities match regex"; + return false; + } + + if (!entity->deviceNode().empty()) { + found = true; + } else { + LOG(DeviceEnumerator, Debug) + << "Skip " << entity->name() + << ": no device node"; + } + } + } + + if (!found) + return false; + } + return true; } 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 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() + "'";