From patchwork Tue Aug 8 12:52:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 18928 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 C28E6C32A9 for ; Tue, 8 Aug 2023 12:52:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EF049627F0; Tue, 8 Aug 2023 14:52:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1691499169; bh=u/+aVEYmwldsZIs13/MxapmxB2C5bS5FSopQsWJA0vI=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=dlrpOgskQWJSaGK6xOGFTyjfCeoSVEOzKhPZQZCSTZlrEZFybLTZaUWVqk32KWzT3 hrP2Yl4KzJIgPZuac+sFfy/UnuiJvMFLhH+YO5fV0h2JEENCfKsSM4Qhi4qo/V1CgJ 69K3zzn/YUpafbVTnDeuprM8FuHHbILpouRgfY8D0v1j77NshWFLp65FKW8FL4Vo8w Ffo1niyK1m+hbT9rtCjINp29KNJ/yiGVeusJ/l+aJNAr2FC0fohLXTxUFlKlmNokVU 4z8jxCWIKUnDsGXFdxGX0e1dE5yvvLiWGtdrj29Q6CY037ENa+QCMdB1yZGO3SMEMU YlTkoxX44Qsnw== 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 ED43C60562 for ; Tue, 8 Aug 2023 14:52:46 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="BKAal0EP"; dkim-atps=neutral Received: from uno.localdomain (mob-5-90-60-22.net.vodafone.it [5.90.60.22]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0449138B3; Tue, 8 Aug 2023 14:51:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1691499099; bh=u/+aVEYmwldsZIs13/MxapmxB2C5bS5FSopQsWJA0vI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BKAal0EPG7HCbobfixm499uHdRWaglLnpMejXEyZnKbIEtwhGBanPww9O4LniPvOA 9++eAbW0zTYil/sIFGAQcrdmz4SM4Zg+Sx4ZW3hCMrzlWbVrwyjAsTaD5kWz7nJfII gDxceWGA9fqRHgY0J6KOZy/fl4LRApxvcaJpLr2w= To: libcamera-devel@lists.libcamera.org, Sophie Friedrich Date: Tue, 8 Aug 2023 14:52:20 +0200 Message-Id: <20230808125228.29043-2-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808125228.29043-1-jacopo.mondi@ideasonboard.com> References: <20230808125228.29043-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 1/9] libcamera: Break-out DeviceMatch 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: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The DeviceMatch class is defined inside the 'device_enumerator' file. Break it out to a dedicated file and header in order to expand it to support multiple matching criteria. Signed-off-by: Jacopo Mondi --- .../libcamera/internal/device_enumerator.h | 16 +--- include/libcamera/internal/device_match.h | 31 +++++++ include/libcamera/internal/meson.build | 1 + src/libcamera/device_enumerator.cpp | 73 --------------- src/libcamera/device_match.cpp | 92 +++++++++++++++++++ src/libcamera/meson.build | 1 + 6 files changed, 127 insertions(+), 87 deletions(-) create mode 100644 include/libcamera/internal/device_match.h create mode 100644 src/libcamera/device_match.cpp diff --git a/include/libcamera/internal/device_enumerator.h b/include/libcamera/internal/device_enumerator.h index 72ec9a60b19a..259a9e4621ea 100644 --- a/include/libcamera/internal/device_enumerator.h +++ b/include/libcamera/internal/device_enumerator.h @@ -13,24 +13,12 @@ #include +#include "libcamera/internal/device_match.h" + namespace libcamera { class MediaDevice; -class DeviceMatch -{ -public: - DeviceMatch(const std::string &driver); - - void add(const std::string &entity); - - bool match(const MediaDevice *device) const; - -private: - std::string driver_; - std::vector entities_; -}; - class DeviceEnumerator { public: diff --git a/include/libcamera/internal/device_match.h b/include/libcamera/internal/device_match.h new file mode 100644 index 000000000000..9f190f0c8a84 --- /dev/null +++ b/include/libcamera/internal/device_match.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2023, Ideas On Board Oy + * + * device_match.h - Match and identify devices to create cameras with + */ + +#pragma once + +#include +#include + +namespace libcamera { + +class MediaDevice; + +class DeviceMatch +{ +public: + DeviceMatch(const std::string &driver); + + void add(const std::string &entity); + + bool match(const MediaDevice *device) const; + +private: + std::string driver_; + std::vector entities_; +}; + +}; /* namespace libcamera */ diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build index 7f1f344014c4..169e06557106 100644 --- a/include/libcamera/internal/meson.build +++ b/include/libcamera/internal/meson.build @@ -25,6 +25,7 @@ libcamera_internal_headers = files([ 'device_enumerator.h', 'device_enumerator_sysfs.h', 'device_enumerator_udev.h', + 'device_match.h', 'formats.h', 'framebuffer.h', 'ipa_manager.h', diff --git a/src/libcamera/device_enumerator.cpp b/src/libcamera/device_enumerator.cpp index f2e055de6477..49afd7834db2 100644 --- a/src/libcamera/device_enumerator.cpp +++ b/src/libcamera/device_enumerator.cpp @@ -40,79 +40,6 @@ namespace libcamera { LOG_DEFINE_CATEGORY(DeviceEnumerator) -/** - * \class DeviceMatch - * \brief Description of a media device search pattern - * - * The DeviceMatch class describes a media device using properties from the - * Media Controller struct media_device_info, entity names in the media graph - * or other properties that can be used to identify a media device. - * - * The description is meant to be filled by pipeline managers and passed to a - * 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. - * - * Pipeline handlers are recommended to add entities to DeviceMatch as - * appropriare 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. - */ - -/** - * \brief Construct a media device search pattern - * \param[in] driver The Linux device driver name that created the media device - */ -DeviceMatch::DeviceMatch(const std::string &driver) - : driver_(driver) -{ -} - -/** - * \brief Add a media entity name to the search pattern - * \param[in] entity The name of the entity in the media graph - */ -void DeviceMatch::add(const std::string &entity) -{ - entities_.push_back(entity); -} - -/** - * \brief Compare a search pattern with a media device - * \param[in] device The media device - * - * Matching is performed on the Linux device driver name and entity names from - * the media graph. A match is found if both the driver name matches and the - * media device contains all the entities listed in the search pattern. - * - * \return true if the media device matches the search pattern, false otherwise - */ -bool DeviceMatch::match(const MediaDevice *device) const -{ - if (driver_ != device->driver()) - return false; - - for (const std::string &name : entities_) { - bool found = false; - - for (const MediaEntity *entity : device->entities()) { - if (name == entity->name()) { - found = true; - break; - } - } - - if (!found) - return false; - } - - return true; -} - /** * \class DeviceEnumerator * \brief Enumerate, store and search media devices diff --git a/src/libcamera/device_match.cpp b/src/libcamera/device_match.cpp new file mode 100644 index 000000000000..a51b9081d398 --- /dev/null +++ b/src/libcamera/device_match.cpp @@ -0,0 +1,92 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2023, Ideas On Board Oy + * + * device_match.cpp - Match and identify devices to create cameras with + */ + +#include "libcamera/internal/device_match.h" + +#include "libcamera/internal/media_device.h" + +/** + * \file device_match.h + * \brief Define types and functions to identify devices used to create cameras + */ + +namespace libcamera { + +/** + * \class DeviceMatch + * \brief Description of a media device search pattern + * + * The DeviceMatch class describes a media device using properties from the + * Media Controller struct media_device_info, entity names in the media graph + * or other properties that can be used to identify a media device. + * + * The description is meant to be filled by pipeline managers and passed to a + * 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. + * + * Pipeline handlers are recommended to add entities to DeviceMatch as + * appropriare 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. + */ + +/** + * \brief Construct a media device search pattern + * \param[in] driver The Linux device driver name that created the media device + */ +DeviceMatch::DeviceMatch(const std::string &driver) + : driver_(driver) +{ +} + +/** + * \brief Add a media entity name to the search pattern + * \param[in] entity The name of the entity in the media graph + */ +void DeviceMatch::add(const std::string &entity) +{ + entities_.push_back(entity); +} + +/** + * \brief Compare a search pattern with a media device + * \param[in] device The media device + * + * Matching is performed on the Linux device driver name and entity names from + * the media graph. A match is found if both the driver name matches and the + * media device contains all the entities listed in the search pattern. + * + * \return True if the media device matches the search pattern, false otherwise + */ +bool DeviceMatch::match(const MediaDevice *device) const +{ + if (driver_ != device->driver()) + return false; + + for (const std::string &name : entities_) { + bool found = false; + + for (const MediaEntity *entity : device->entities()) { + if (name == entity->name()) { + found = true; + break; + } + } + + if (!found) + return false; + } + + return true; +} + +} /* namespace libcamera */ diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index b24f82965764..d5562afc50c7 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -17,6 +17,7 @@ libcamera_sources = files([ 'delayed_controls.cpp', 'device_enumerator.cpp', 'device_enumerator_sysfs.cpp', + 'device_match.cpp', 'fence.cpp', 'formats.cpp', 'framebuffer.cpp',