From patchwork Wed Sep 20 15:19:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 19062 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 97E5BBE080 for ; Wed, 20 Sep 2023 15:19:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 42E3F6294A; Wed, 20 Sep 2023 17:19:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1695223191; bh=2Njc0O7Ob11wQMCP+v1HytL2/9nJoKyaxnVb/jvHmfg=; 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=QhzD/HGig1H/Cf7vGHYBf6br3hIaqoRINKnqsHhWd7TxSUwPHgRkn30ijiOBtTise sIiljWKF3ZFYlF50msUqv83LA7SZVE1L2Jzyn1WCpav/CnlFaDUXzUNQVKo1/G/GFh 9yYT5mvT/nMdZgGEWL+hapD/UkzE0mTPypXF+ZHcuoIu+YgPouan3JhUFpDXKYDZ/t jhK5iZeBUZdGVn2CqRCB4xRc63Jbxkf/rFCAe0+ytVajl6KkpD5usjHWtR8soAS57C i9YWbO0jzEzQ9e5aW55zFMv5K4g8nbm0G9EcBJCyxCxouf4YRVndevJY9Hm3veUw/y +SWuq0qDWznWw== Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8B4B160388 for ; Wed, 20 Sep 2023 17:19:49 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="FueLl9o+"; dkim-atps=neutral Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-9ae2cc4d17eso253302166b.1 for ; Wed, 20 Sep 2023 08:19:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695223189; x=1695827989; 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=G2NSitUIDldnJJ4gfjSXMsL6xctreIOQIZGGhC40Bg8=; b=FueLl9o+/N1flf2eAKoPGKyzUWRF3ZhgaTMh+5nN4RsoDU80mkpIEffmOqZFjnGl0Z SRGfZfpaniO3s64jy8xh2QaUh/lmedrFRlxR2iqfeytQoYFwIgG232WCIEIQedlwa2Zr ScANqUg7bGgzpblkb5rNDVL1/hYWM5qPg06QslqaWayLmTTlvQ0x4yQzsi8wpiXBu+3W rcfPyoJ70cgT8WOalvwjYVjhkN5KfAPu0reihdBwLIkEsNlsy9Jkjlx0ykZDP2pyk688 EOGsBmdYevfcySMl5D0PmkULgtdeG5EEB36mGntAU0sWjBiVXhAkNkoHdGdTUjJMwivQ rFrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695223189; x=1695827989; 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=G2NSitUIDldnJJ4gfjSXMsL6xctreIOQIZGGhC40Bg8=; b=KY1hnmdAVyjy5g4B/tFqqzZU3mZAEnaGRg1CaOZzZnlJL/KfqsmVEw7XF7pyXen6lX j6+CKKLFXzwyUI200uofpx0nrSEe9zKyKYje0Tvvwy+LmxpElQJuk/gq93j1os2O7KTi Zmxa+W21ppy0WBrdgHZdQZ1BbWivFlqZwDOVzpb5HKnF8LlptJeu6C7sIqXVzl/V+wV9 0N8Y6bTwygDvkMYfAT1LXge88w9E1VHW4IqCBG3FDCHG6IPN1jLnJNSNDhuP10lPXEnm FF4/EutpRkJXfcQOyzk4W5s+RRru1nE2NUAO/Da8DkMUr46OpZKcm+kw8x8Z5yw/Y3qf dqIQ== X-Gm-Message-State: AOJu0YzWJIbC7N99KgB0r9x4n2RggYa4bDcWd4xBZztbbyHx8jECL778 H6WUdyal3gjbcnVP4wgBzjf/MXoej2qE6JnT0YI= X-Google-Smtp-Source: AGHT+IE2yHFzE7K0dLQIlqXKpFP1T9/giIIdTYwlTsnZp4hiB06RWm2LyfhVb1R2RSvGiil0w3GdqA== X-Received: by 2002:a17:906:1d2:b0:9a1:cbe4:d029 with SMTP id 18-20020a17090601d200b009a1cbe4d029mr2283360ejj.74.1695223189052; Wed, 20 Sep 2023 08:19:49 -0700 (PDT) Received: from Lat-5310.. ([87.116.162.81]) by smtp.gmail.com with ESMTPSA id h24-20020a170906829800b009ae0042e48bsm5376736ejx.5.2023.09.20.08.19.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 08:19:48 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 20 Sep 2023 18:19:19 +0300 Message-Id: <20230920151921.31273-3-andrey.konovalov@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230920151921.31273-1-andrey.konovalov@linaro.org> References: <20230920151921.31273-1-andrey.konovalov@linaro.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 2/4] 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. Instead of the MediaDevice driver name, use a generic string to match against the convertor 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 --- include/libcamera/internal/converter.h | 9 ++-- src/libcamera/converter.cpp | 53 ++++++++++++++---------- src/libcamera/pipeline/simple/simple.cpp | 33 +++++++++++---- 3 files changed, 60 insertions(+), 35 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 466f8421..5070eabc 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 */ @@ -13,8 +14,6 @@ #include "libcamera/internal/media_device.h" -#include "linux/media.h" - /** * \file internal/converter.h * \brief Abstract converter @@ -38,26 +37,28 @@ 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) { - const std::vector &entities = media->entities(); - auto it = std::find_if(entities.begin(), entities.end(), - [](MediaEntity *entity) { - return entity->function() == MEDIA_ENT_F_IO_V4L; - }); - if (it == entities.end()) { - LOG(Converter, Error) - << "No entity suitable for implementing a converter in " - << media->driver() << " entities list."; - return; + if (media) { + const std::vector &entities = media->entities(); + auto it = std::find_if(entities.begin(), entities.end(), + [](MediaEntity *entity) { + return entity->function() == MEDIA_ENT_F_IO_V4L; + }); + if (it == entities.end()) { + LOG(Converter, Error) + << "No entity suitable for implementing a converter in " + << media->driver() << " entities list."; + return; + } + + deviceNode_ = (*it)->deviceNode(); } - - deviceNode_ = (*it)->deviceNode(); } Converter::~Converter() @@ -162,7 +163,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 returnes an empty string. */ /** @@ -203,8 +205,13 @@ 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. * * \return A unique pointer to a new instance of the converter subclass * corresponding to the media device. The converter is created by the factory @@ -212,22 +219,22 @@ ConverterFactoryBase::ConverterFactoryBase(const std::string name, std::initiali * If the media device driver 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()) @@ -318,7 +325,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..3f1b523a 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_; }; @@ -496,8 +504,10 @@ int SimpleCameraData::init() /* 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), converter); if (!converter_) { LOG(SimplePipeline, Warning) << "Failed to create converter, disabling format conversion"; @@ -1409,10 +1419,17 @@ 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_) { + for (const auto &[flags, name, streams] : info->converters) { + if (flags & ConverterFlag::MediaDevice) { + DeviceMatch converterMatch(name); + converter_ = acquireMediaDevice(enumerator, converterMatch); + if (converter_) { + converterName_ = name; + numStreams = streams; + break; + } + } else { + converterName_ = name; numStreams = streams; break; }