From patchwork Thu Sep 28 18:55:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 19096 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 48F46C0F2A for ; Thu, 28 Sep 2023 18:57:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 035DC62964; Thu, 28 Sep 2023 20:57:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1695927428; bh=uXauu6ouhtLjZWNP5XLgaZ9jTggEIKauHcBLGkaqxEg=; 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=gIdAGRB73oQ7mxGuGl4sgkEIlVT7OK0/+mKkZPeOugeRkA29hu62vyRtRtzrgHxbs gb8pQy8daWxx7sChwNFXRZ15hYRN37BGViWiWg0r0n0LBpHj/9mGUDSBW3S/VYK1nJ KBbpD2h3pm8Yi94PJ398dzMPNPFjbfcm6rUG/WN0TmwUrcHM13szTLL8akAk7mvpIe zulQTsDXjiztrQl+TZk5DgsGurtQRrsfkRVf1LxVfpPHdXSOT3UOP9xjXxjXzh3Z36 Jzp6uqSObwa3veAq4ZS8nRoUaMzvxYDI5s6QisUivjBnlY+F9z+kVeqh7sxG/Kjrdb dhSZ31cNwT3/g== Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1F68F61DE4 for ; Thu, 28 Sep 2023 20:57:06 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="obCZG18P"; dkim-atps=neutral Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-4053c6f0db8so127753205e9.3 for ; Thu, 28 Sep 2023 11:57:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695927426; x=1696532226; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=OI2VKm75pLdX9VEIRplvrxvoZJu4os9OOVGF8JqDQLs=; b=obCZG18Pn03mD+IZsxqPiocC6b5ZxUVdVZRyeLnw7NDAIdivwBBN27YfItr0WK4zXH DVKZjivsIZW00x8ZMFlkHUkaBBp7Pr5P258ITZ3g3S0J1funs27TRq6OaVQ+QU1U81jH sMyiyPHV3NechlKumqeCgxMO+jVl6YlKDvFiIdsRXIXtIgwxlQWFlkdMsoUdQausHnqE FBZzNK21t9xbi/8OZ7s4OiyB6I3uEcn5d07GJ0wlasDBEYWu9Hqd32DfSVfnTpLB4yBJ ERSLgyfimLHwQkiF0k/yS8y2ak1FXpeHCEfeSr45D1I7iwoDIUNE91Ka+SnS8plisJOv hqBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695927426; x=1696532226; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OI2VKm75pLdX9VEIRplvrxvoZJu4os9OOVGF8JqDQLs=; b=qEvmZDBfH1JvA+Fvhwa9h2ezZ67KCKXWMXJfF0Bq1SiNLoLp/TjGmFZ2qebPU49+3N pQxiydAqmKZNj2Jd2fNsPvrY40eOo8ahZ12vPx4IXfpQVX+WTwkKq/Pc44/KH9WA1neH 1h01n6SU2Mk8/KzlUOh/6uW7SenMECS9acVs1oR5YCCq/xu4gj6V5cmSUTWQMhPL3l0M Tks+N6UKlwXdMrCmV40GPMHqkyqB2SvD1sDqdHXK2QDO5vXNYI75yixyDSJaUVvXr96j 9JwBa9tzYjGahCs22OFgkhqMPBsXWYM0a1ewyQ8/bET0ZOJT5a+ZgRaA2CiMFdRyVlx9 enfQ== X-Gm-Message-State: AOJu0YwbTgBWoFLKP00GHg1xACqJy/2HPKtEi36jV90nmi0cjQ9rm7uy LiLjacEk7naxvnWZIJbdSB5d+gWbzcnLb/5+eds= X-Google-Smtp-Source: AGHT+IGYx3+YrFp7aVlrfHrSPnkd6eNYVE62jov0aEMuObOwddr266S8uoBS/0YrPNIy+5t6ZE1QxQ== X-Received: by 2002:a05:6000:136a:b0:317:1b08:b317 with SMTP id q10-20020a056000136a00b003171b08b317mr1929996wrz.6.1695927425719; Thu, 28 Sep 2023 11:57:05 -0700 (PDT) Received: from Lat-5310.. ([87.116.164.210]) by smtp.gmail.com with ESMTPSA id u1-20020adfed41000000b003247d3e5d99sm890842wro.55.2023.09.28.11.57.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 11:57:05 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Sep 2023 21:55:35 +0300 Message-Id: <20230928185537.20178-4-andrey.konovalov@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230928185537.20178-1-andrey.konovalov@linaro.org> References: <20230928185537.20178-1-andrey.konovalov@linaro.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 3/5] libcamera: converter: make using MediaDevice optional for the Converter 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: Andrey Konovalov via libcamera-devel From: Andrey Konovalov Reply-To: Andrey Konovalov Cc: jacopo.mondi@ideasonboard.com, bryan.odonoghue@linaro.org, srinivas.kandagatla@linaro.org Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Make Converter a bit more generic by making pointer to MediaDevice an optional argument for Converter::Converter(), ConverterFactoryBase::create(), ConverterFactoryBase::createInstance(), and ConverterFactory::createInstance() functions to prepare for adding support for coverters not backed by a media device. Instead of the MediaDevice driver name, use a generic string to match against the converter factory name and its compatibles list. For MediaDevice based converters this string will be the MediaDevice driver name as before. Signed-off-by: Andrey Konovalov Reviewed-by: Mattijs Korpershoek --- include/libcamera/internal/converter.h | 9 +++--- src/libcamera/converter.cpp | 40 +++++++++++++++--------- src/libcamera/pipeline/simple/simple.cpp | 39 ++++++++++++++++------- 3 files changed, 58 insertions(+), 30 deletions(-) diff --git a/include/libcamera/internal/converter.h b/include/libcamera/internal/converter.h index 834ec5ab..d0c70296 100644 --- a/include/libcamera/internal/converter.h +++ b/include/libcamera/internal/converter.h @@ -2,6 +2,7 @@ /* * Copyright (C) 2020, Laurent Pinchart * Copyright 2022 NXP + * Copyright 2023, Linaro Ltd * * converter.h - Generic format converter interface */ @@ -31,7 +32,7 @@ struct StreamConfiguration; class Converter { public: - Converter(MediaDevice *media); + Converter(MediaDevice *media = nullptr); virtual ~Converter(); virtual int loadConfiguration(const std::string &filename) = 0; @@ -72,7 +73,7 @@ public: const std::vector &compatibles() const { return compatibles_; } - static std::unique_ptr create(MediaDevice *media); + static std::unique_ptr create(std::string name, MediaDevice *media = nullptr); static std::vector &factories(); static std::vector names(); @@ -81,7 +82,7 @@ private: static void registerType(ConverterFactoryBase *factory); - virtual std::unique_ptr createInstance(MediaDevice *media) const = 0; + virtual std::unique_ptr createInstance(MediaDevice *media = nullptr) const = 0; std::string name_; std::vector compatibles_; @@ -96,7 +97,7 @@ public: { } - std::unique_ptr createInstance(MediaDevice *media) const override + std::unique_ptr createInstance(MediaDevice *media = nullptr) const override { return std::make_unique<_Converter>(media); } diff --git a/src/libcamera/converter.cpp b/src/libcamera/converter.cpp index aca4fbc7..fe073bf2 100644 --- a/src/libcamera/converter.cpp +++ b/src/libcamera/converter.cpp @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright 2022 NXP + * Copyright 2023 Linaro Ltd * * converter.cpp - Generic format converter interface */ @@ -36,13 +37,16 @@ LOG_DEFINE_CATEGORY(Converter) /** * \brief Construct a Converter instance - * \param[in] media The media device implementing the converter + * \param[in] media The media device implementing the converter (optional) * * This searches for the entity implementing the data streaming function in the * media graph entities and use its device node as the converter device node. */ Converter::Converter(MediaDevice *media) { + if (!media) + return; + const std::vector &entities = media->entities(); auto it = std::find_if(entities.begin(), entities.end(), [](MediaEntity *entity) { @@ -160,7 +164,8 @@ Converter::~Converter() /** * \fn Converter::deviceNode() * \brief The converter device node attribute accessor - * \return The converter device node string + * \return The converter device node string. If there is no device node for + * the converter returns an empty string. */ /** @@ -201,32 +206,37 @@ ConverterFactoryBase::ConverterFactoryBase(const std::string name, std::initiali */ /** - * \brief Create an instance of the converter corresponding to the media device - * \param[in] media The media device to create the converter for + * \brief Create an instance of the converter corresponding to the converter + * name + * \param[in] name The name of the converter to create + * \param[in] media The media device to create the converter for (optional) + * + * The converter \a name must match the name of the converter factory, or one + * of its compatibles. For media device based converters the converter \a name + * is the media device driver name. + * + * \return A unique pointer to a new instance of the converter subclass. + * The converter is created by matching the factory name or any of its + * compatible aliases with the converter name. * - * \return A unique pointer to a new instance of the converter subclass - * corresponding to the media device. The converter is created by matching - * the factory name or any of its compatible aliases with the media device - * driver name. - * If the media device driver name doesn't match anything a null pointer is - * returned. + * If the converter name doesn't match anything a null pointer is returned. */ -std::unique_ptr ConverterFactoryBase::create(MediaDevice *media) +std::unique_ptr ConverterFactoryBase::create(std::string name, MediaDevice *media) { const std::vector &factories = ConverterFactoryBase::factories(); for (const ConverterFactoryBase *factory : factories) { const std::vector &compatibles = factory->compatibles(); - auto it = std::find(compatibles.begin(), compatibles.end(), media->driver()); + auto it = std::find(compatibles.begin(), compatibles.end(), name); - if (it == compatibles.end() && media->driver() != factory->name_) + if (it == compatibles.end() && name != factory->name_) continue; LOG(Converter, Debug) << "Creating converter from " << factory->name_ << " factory with " - << (it == compatibles.end() ? "no" : media->driver()) << " alias."; + << (it == compatibles.end() ? "no" : name) << " alias."; std::unique_ptr converter = factory->createInstance(media); if (converter->isValid()) @@ -317,7 +327,7 @@ std::vector &ConverterFactoryBase::factories() /** * \fn ConverterFactory::createInstance() const * \brief Create an instance of the Converter corresponding to the factory - * \param[in] media Media device pointer + * \param[in] media Media device pointer (optional) * \return A unique pointer to a newly constructed instance of the Converter * subclass corresponding to the factory */ diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index 05ba76bc..c7da700b 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -178,20 +178,26 @@ LOG_DEFINE_CATEGORY(SimplePipeline) class SimplePipelineHandler; +enum class ConverterFlag { + NoFlag = 0, + MediaDevice = (1 << 0), +}; +using ConverterFlags = Flags; + struct SimplePipelineInfo { const char *driver; /* * Each converter in the list contains the name * and the number of streams it supports. */ - std::vector> converters; + std::vector> converters; }; namespace { static const SimplePipelineInfo supportedDevices[] = { { "dcmipp", {} }, - { "imx7-csi", { { "pxp", 1 } } }, + { "imx7-csi", { { ConverterFlag::MediaDevice, "pxp", 1 } } }, { "j721e-csi2rx", {} }, { "mxc-isi", {} }, { "qcom-camss", {} }, @@ -330,6 +336,7 @@ public: V4L2VideoDevice *video(const MediaEntity *entity); V4L2Subdevice *subdev(const MediaEntity *entity); + const char *converterName() { return converterName_; } MediaDevice *converter() { return converter_; } protected: @@ -358,6 +365,7 @@ private: MediaDevice *media_; std::map entities_; + const char *converterName_; MediaDevice *converter_; }; @@ -495,9 +503,10 @@ int SimpleCameraData::init() int ret; /* Open the converter, if any. */ - MediaDevice *converter = pipe->converter(); - if (converter) { - converter_ = ConverterFactoryBase::create(converter); + const char *converterName = pipe->converterName(); + if (converterName) { + LOG(SimplePipeline, Info) << "Creating converter '" << converterName << "'"; + converter_ = ConverterFactoryBase::create(std::string(converterName), pipe->converter()); if (!converter_) { LOG(SimplePipeline, Warning) << "Failed to create converter, disabling format conversion"; @@ -1409,13 +1418,21 @@ bool SimplePipelineHandler::match(DeviceEnumerator *enumerator) if (!media_) return false; - for (const auto &[name, streams] : info->converters) { - DeviceMatch converterMatch(name); - converter_ = acquireMediaDevice(enumerator, converterMatch); - if (converter_) { - numStreams = streams; - break; + for (const auto &[flags, name, streams] : info->converters) { + if (flags & ConverterFlag::MediaDevice) { + DeviceMatch converterMatch(name); + converter_ = acquireMediaDevice(enumerator, converterMatch); + if (!converter_) { + LOG(SimplePipeline, Debug) + << "Failed to acquire converter media device '" + << name << "'"; + continue; + } } + + converterName_ = name; + numStreams = streams; + break; } /* Locate the sensors. */