From patchwork Tue Nov 15 12:59:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier Roumegue X-Patchwork-Id: 17801 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 B782ABD16B for ; Tue, 15 Nov 2022 13:00:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 13D8063086; Tue, 15 Nov 2022 14:00:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1668517211; bh=/WVow3498+Nj673oVlopp4e9a8ryFuB7GI6EdvEMAco=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=NSrIkvE8ErKKTweExoKaVapttGGDvlOlHhvwtgYRdIuFrFuDkWADPVjAIScBrhQjW eUy8gb1XCqIoEfDsnjd5V8xzMqMEG9BDhpkIWsJ0x72aweLC1ZcQJ/0MNZMDY86ROt /kYbfdKowDgzhkeoAKhQs7szntFfOvou9jUvzvhGMhpTMskhbZqjmKRRPdA7Pv4LCh 1XFKbwYRoqBqEVmX45HbjJYTw6HM2ZGXfVRcnwPW36hOEnkdO7kcDVpfEbChuXYDjJ Qp8dKMZHqIjxfTnIS99l7rSm+6UJEKSKMPY74QJMzYs5zadXAjow6NvCo/svsLhKl0 fhpmyM+yXtpig== Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on0613.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0d::613]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C929163079 for ; Tue, 15 Nov 2022 14:00:08 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="QZpP1y+y"; dkim-atps=neutral ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NjHg8uLyaDznz81y6o7nH72GaMunAV3rtG7D5jdO8B2K/S5SBp3EMd7RgT4roxpvjSk7iZL27+OKoZ+yk4/ZU8OCMhpFGDU+zRZMhgLIiKbgHAXZ+NQt5u/rZ66udngWw9Zui7j08TMMaSC4MyYo5qYhscp5TJGfo5ZtlO1ll6iL3L7ICCJuAMzEvkKYV7wJuPu3lDcFXUuxvn7NouicMFZkptC5dNJVhbht/5sLPWZn4vlWlbB+k9EGlVZ43ykqQATEBMnxk74Dyr6VrUADsjgpvhaB2S+LmzzDzoxO7PqRTwgtQVuwOaDrx9NwoPnyFz71mAj7A9rLueKZxq2cFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+JG9bH+uWZ7efH+Ajyo3jHXN9C5F+E1Wtsg6GwBsV+c=; b=i/M2qbdwwU7ouDOpbvxgRmKFCSWE2Jv0E0EMaWdnhPj2tzhZuQoNooB1AXx4QmmmLu/aRC+DPWAYCR9vDOblXG/8AAt4sPpgNiLjWX052Drm9Mik7MF+ZtktyNhsqNXpZO5LGRb67eIYuLp4rqMehbbe/T/3Q/ZgdWbEtwS3I5PhtkaPOZzc5cYNKttrm36wlx1RvWZ9U4H+Za+L9FhbJoITChQCeLZCiW7L+S13tie1y1mvBRXJlOOeP+VBS3EGbxgomrk7n/3PGGQuf/FRu5Bl7mLJl74IEtYQjgsoJKufEmz2Y5rJo7vQs5J0tU0IhtF5+PCKkhTq70ETKdR3SQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+JG9bH+uWZ7efH+Ajyo3jHXN9C5F+E1Wtsg6GwBsV+c=; b=QZpP1y+ykF7GDkj3v8l357Mlx4tyJ6qQG/tgw/t6E1+SseHZtCTQgNeR9Of1rTDb86T+ahhvWUQcyWNl4OfzgKvCNPT7zVeQ39u9s84hljFSWe47f+qAdceBZJ05+z3HqRxQtB1zoKTophL6Ysp11GjzzMrge0zJvKd7pcxzDWM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from PAXPR04MB8703.eurprd04.prod.outlook.com (2603:10a6:102:21e::22) by PAXPR04MB8639.eurprd04.prod.outlook.com (2603:10a6:102:21e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.13; Tue, 15 Nov 2022 13:00:06 +0000 Received: from PAXPR04MB8703.eurprd04.prod.outlook.com ([fe80::14d3:8e4:cf07:810d]) by PAXPR04MB8703.eurprd04.prod.outlook.com ([fe80::14d3:8e4:cf07:810d%3]) with mapi id 15.20.5813.018; Tue, 15 Nov 2022 13:00:05 +0000 To: jacopo@jmondi.org, laurent.pinchart@ideasonboard.com Date: Tue, 15 Nov 2022 13:59:33 +0100 Message-Id: <20221115125935.1196138-1-xavier.roumegue@oss.nxp.com> X-Mailer: git-send-email 2.38.1 X-ClientProxiedBy: PR3P189CA0080.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::25) To PAXPR04MB8703.eurprd04.prod.outlook.com (2603:10a6:102:21e::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8703:EE_|PAXPR04MB8639:EE_ X-MS-Office365-Filtering-Correlation-Id: 35f8d541-040c-4355-03ba-08dac70950f0 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8nOK2EFcdUJVEFJLRitMotVs9UBkYN0m1O4hiUR8205Abk5XjFMlg9sWW8Ko195r7Z8ZZWZ/OSkZWLqzJuMl6DB3pTcX4/9xRENJ5Q5xwBgmOm6wmQB8aGhnfrHzo5ehRYFsShf0u1mnhkVrFKa6F3f8IFFgevvNo+Vc1jagGSwJYuiuFpJdYvF5SOurs8wjudGELRZsGRO066wCMsz4dWw8NvYmMxcUWPnzdQRmIV3xIg9VO7rYd9I5BgaOa91GoeXshiC+8n9pXpBCm4LdbWeXrZ2Ihaqt+ksIumkZ5CDIYcUKou6GZ5aTwPmokXr+WN0Aa4Ul6ul+404mJNKG4+eTq1b+WVW4ibcPsV9phCiutl/bRsc8nhhnfL+isFPmVlotwKjkS+LWShaAk3iJOJ5JFMmkVQ2PmoKGTaRJ1rYo7UXIdBzAX/uoUZz6b+YhkZTAFGGdOrxrzAI37W25rELwmWH79E9CdUli2vO0GGoA0B5eIwJC+99h+nwta4UzZnoZudRjML9OtZsGRVK/agrLpeVD4wxvk9O6545hW2duNOJZQMybD6E8D539yDKSWA7QflGrjhkkO3UWFt70CxlWIf4xlXi48AWUNcqQmoVsbdeoHKd+mXv/X1htS3hy0crOo83d8Pgr2l8/a7daMwJYhC+85McKlMobxAth52WrYdqar3fuYG2qXhDivatfqgQgWD0ads1fE//J+BaHqCV4EkcOwPQdVoAgs1oBxb6MiG1dmuoCKvTAn/txhPks X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAXPR04MB8703.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(136003)(396003)(366004)(376002)(39860400002)(346002)(451199015)(6512007)(86362001)(316002)(38100700002)(52116002)(83380400001)(44832011)(2906002)(41300700001)(8676002)(4326008)(66946007)(8936002)(66556008)(1076003)(66476007)(186003)(30864003)(5660300002)(2616005)(6486002)(66899015)(6506007)(478600001)(6666004)(41533002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WrkIjT/I7q65m2d5FQ1GEYweg0Qw+/Koo2A2HxSQuqWADI13LLvAUWcD70fv5WaXELIbyoYyDZP7VEom+14D4R/Qb/ILZ6rh2ojOqH98C3XxgQJFbs66YVnifcNK50N9N5DTCCnYIQoCeopO2NeP9SBxNswFve04UCV8rsQd0wz5UlucnHxCl+3Ci7eAStp6yEUOosXXZ7EffTJhhFfLKH+a/B9LYdbvwNQ27l9GiJz5L1SfOX9K6bCJjxj2bFvgOInf3fpjtbiba6aIaCRvv+4921qRJwr1OhO7vO7NwGqLkI9cL0khtbVaFsIgRSJRd7Yu4jSMnZj5wBybYZkPuj+IavOCFT3vzIrrvb5f3vJJWOf4Z6lq0+GxtFBaJ3EnipmBwTj9JpqWd0Ddz0zamnI8uo3tEPGAKmcsLSuyuxqL+D2g3kI4HL5xohyAxtEOMMJGUKsc2vAaTHEviSlf1mOFYrk7eqjUjZ7O/wpt9aNVL6NoomwJ17bFMvEdrAw/MVKwlkS3bnl+279f0XA/t0DYhvXvz6i1Bqp7/DkGBLoZA0g9HU5fy9wWMU5jDRo9DCXES/QPhUe05jtqmT+4ioWz4Xs0qcKivolj6VEHj3heK/7i0Xa/2bkYYcrgkXghm21UTEOQxasd/X6Q3g5mXiLyU5JTJLtRtEcssqFwEmF1c7xWBvwY+ZJmXjTPy+LCk5OFqRiYnTjG9ahUtSVw7e+rH+wjLI/yjdlWFWGrOltQ871t4l1sTiFwPTiEiLi10XvrpSSv9lmuME0RK1Hk3Etka2o+Akcq3EAS2bnMeFJRMtY8mySQ3BOL9XutJBl2fvtCwgXGnPac3lihct+zF2OBkZS3N752eidUNwaaqrZAYmm5CfkmXi71/QP4CMmGev0p6MX5CibjbwQbgdCWrq/kzf5iGlBHSJOaV0g1qJqLfE6r/zOlLpDaFyrPWlCWiHnP3IFeEtHtnGMlDJDjNtdw3dSXYFcyM+vKk6sc+9vJFyyVRhQ5+xU9WaTMnQWcljT1FtLMjDlYOoP9ZHrwPuw1LikoqjenoATP/fMaEm5ocZQ4JeU3F4fvIMWD2gHXN5SUQjQZOV/wDQwhUyM+omapKEDnnb4k+Cevk4DW+UyfCzkG8Asc3Je4wN8lCB28zCcreiQPLc3g0QvsRxE6mlO5lsmz+Ce0r7Tg4miGZh6lEyxSRTvrW3AP/Nyu+Pk9maw+RAsbF803x6rWPYUPxJ1m1juv9dRTYtKmCgNfOX1Z5fzWK6pkvQawClGyhFdakeeEYEFErLhHCQH8tSxF3T21i4Z7Vk1Sh2OlxKL/RIw+PtS+pF1fkGz4Ip7tLmMoxRUEfgK0MqeDRJY8RrsB/gPNMQWdUkpdSAgNLBT7ngzC4knc+EIV7JPWBGpoodE4g93NZMUzf5mkS/YYo0j3Zeo/Rv2/IsJ9EsD2No3E9IFvqgCeHyBhvJZqJskxzRjybEPHKWXfFzMJOXkExuDyU7p047+OyjIggQCrb2In1P66MlSLX2Fy+Cn2pTVyrp2bN1+XZrCmhxc8zKvwVnCAh1ymQZmb6AAjFs5nQ2bcjbWtu8NWwiykP4pfGGW1PkoqGzrFaeBletWqaM8GzenMxd9xIb33r4ISWkHXqi/JMcdKyAvzfBWmbpBW3SJhHzeQP1wygCRCbChmYIxuH3FXbA== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 35f8d541-040c-4355-03ba-08dac70950f0 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8703.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Nov 2022 13:00:05.8666 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: tBhPfzpDRZwZLQrJwDHl1kn5jrfxLibxErVD2fMYEQ8yYmCqfSV0xLQyZb8ga6BGEsBldE9lx0ALGWoTNtgp8g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8639 Subject: [libcamera-devel] [PATCH v2 1/2] libcamera: Declare generic converter interface 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: Xavier Roumegue via libcamera-devel From: Xavier Roumegue Reply-To: Xavier Roumegue Cc: libcamera-devel@lists.libcamera.org Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Declare a converter Abstract Base Class intended to provide generic interfaces to hardware offering size and format conversion services on streams. This is mainly based on the public interfaces of the current converter class implementation found in the simple pipeline handler. The main change is the introduction of loadConfiguration() function which can be used by the concrete implementation to load hardware specific runtime parameters defined by the application. Signed-off-by: Xavier Roumegue Reviewed-by: Jacopo Mondi --- include/libcamera/internal/converter.h | 109 ++++++++ include/libcamera/internal/meson.build | 1 + src/libcamera/converter.cpp | 331 +++++++++++++++++++++++++ src/libcamera/meson.build | 1 + 4 files changed, 442 insertions(+) create mode 100644 include/libcamera/internal/converter.h create mode 100644 src/libcamera/converter.cpp diff --git a/include/libcamera/internal/converter.h b/include/libcamera/internal/converter.h new file mode 100644 index 00000000..19e8c7c5 --- /dev/null +++ b/include/libcamera/internal/converter.h @@ -0,0 +1,109 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2020, Laurent Pinchart + * Copyright 2022 NXP + * + * converter.h - Generic stream converter interface + */ + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +namespace libcamera { + +class FrameBuffer; +class MediaDevice; +class Size; +class SizeRange; +struct StreamConfiguration; + +class Converter +{ +public: + Converter(MediaDevice *media); + virtual ~Converter(); + + virtual int loadConfiguration(const std::string &filename) = 0; + + virtual bool isValid() const = 0; + + virtual std::vector formats(PixelFormat input) = 0; + virtual SizeRange sizes(const Size &input) = 0; + + virtual std::tuple + strideAndFrameSize(const PixelFormat &pixelFormat, const Size &size) = 0; + + virtual int configure(const StreamConfiguration &inputCfg, + const std::vector> &outputCfgs) = 0; + virtual int exportBuffers(unsigned int output, unsigned int count, + std::vector> *buffers) = 0; + + virtual int start() = 0; + virtual void stop() = 0; + + virtual int queueBuffers(FrameBuffer *input, + const std::map &outputs) = 0; + + Signal inputBufferReady; + Signal outputBufferReady; + + const std::string &deviceNode() const { return deviceNode_; }; + +private: + std::string deviceNode_; +}; + +class ConverterFactoryBase +{ +public: + ConverterFactoryBase(const std::string name, std::initializer_list aliases); + virtual ~ConverterFactoryBase() = default; + + const std::vector &aliases() const { return aliases_; } + + static std::unique_ptr create(MediaDevice *media); + static std::vector &factories(); + static std::vector names(); + +private: + LIBCAMERA_DISABLE_COPY_AND_MOVE(ConverterFactoryBase) + + static void registerType(ConverterFactoryBase *factory); + + virtual std::unique_ptr createInstance(MediaDevice *media) const = 0; + + std::string name_; + std::vector aliases_; +}; + +template +class ConverterFactory : public ConverterFactoryBase +{ +public: + ConverterFactory(const char *name, std::initializer_list aliases) + : ConverterFactoryBase(name, aliases) + { + } + + std::unique_ptr createInstance(MediaDevice *media) const override + { + return std::make_unique<_Converter>(media); + } +}; + +#define REGISTER_CONVERTER(name, converter, ...) \ + static ConverterFactory global_##converter##Factory(name, { __VA_ARGS__ }); + +} /* namespace libcamera */ diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build index 7a780d48..8f50d755 100644 --- a/include/libcamera/internal/meson.build +++ b/include/libcamera/internal/meson.build @@ -19,6 +19,7 @@ libcamera_internal_headers = files([ 'camera_sensor_properties.h', 'control_serializer.h', 'control_validator.h', + 'converter.h', 'delayed_controls.h', 'device_enumerator.h', 'device_enumerator_sysfs.h', diff --git a/src/libcamera/converter.cpp b/src/libcamera/converter.cpp new file mode 100644 index 00000000..e370038f --- /dev/null +++ b/src/libcamera/converter.cpp @@ -0,0 +1,331 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright 2022 NXP + * + * converter.cpp - Generic Format converter interface + */ + +#include "libcamera/internal/converter.h" + +#include + +#include + +#include "libcamera/internal/media_device.h" + +/** + * \file internal/converter.h + * \brief Abstract converter + */ + +namespace libcamera { + +LOG_DEFINE_CATEGORY(Converter) + +/** + * \class Converter + * \brief Abstract Base Class for converter + * + * The Converter class is an Abstract Base Class defining the interfaces of + * converter implementations. + * + * Converters offer scaling and pixel format conversion services on a input + * stream. The converter can output multiple streams with individual conversion + * parameters from the same input stream. + */ + +/** + * \brief Construct a Converter instance + * \param[in] media The media device implementing the converter + * + * This seeks for the entity implementing data streaming function in the media + * graph entities and use its device node as 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; + } + + deviceNode_ = (*it)->deviceNode(); +} + +Converter::~Converter() +{ +} + +/** + * \fn Converter::loadConfiguration() + * \brief Load converter configuration from file + * \param[in] filename The file name path + * + * Load converter dependent configuration parameters to apply on the hardware. + * + * \return 0 on success or a negative error code otherwise + */ + +/** + * \fn Converter::isValid() + * \brief Check if the converter configuration is valid + * \return True is the converter is valid, false otherwise + */ + +/** + * \fn Converter::formats() + * \brief Retrieve the list of supported pixel formats for an input pixel format + * \param[in] input Input pixel format to retrieve output pixel format list for + * \return The list of supported output pixel formats + */ + +/** + * \fn Converter::sizes() + * \brief Retrieve the range of minimum and maximum output sizes for an input size + * \param[in] input Input stream size to retrieve range for + * \return A range of output image sizes + */ + +/** + * \fn Converter::strideAndFrameSize() + * \brief Retrieve the output stride and frame size for an input configutation + * \param[in] pixelFormat Input stream pixel format + * \param[in] size Input stream size + * \return A tuple indicating the stride and frame size or an empty tuple on error + */ + +/** + * \fn Converter::configure() + * \brief Configure a set of output stream conversion from an input stream + * \param[in] inputCfg Input stream configuration + * \param[out] outputCfgs A list of output stream configurations + * \return 0 on success or a negative error code otherwise + */ + +/** + * \fn Converter::exportBuffers() + * \brief Export buffers from the converter device + * \param[in] output Output stream index exporting the buffers + * \param[in] count Number of buffers to allocate + * \param[out] buffers Vector to store allocated buffers + * + * This function operates similarly as V4L2VideoDevice::exportBuffers() on the + * output stream indicated by the \a output index. + * + * \return The number of allocated buffers on success or a negative error code + * otherwise + */ + +/** + * \fn Converter::start() + * \brief Start the converter streaming operation + * \return 0 on success or a negative error code otherwise + */ + +/** + * \fn Converter::stop() + * \brief Stop the converter streaming operation + */ + +/** + * \fn Converter::queueBuffers() + * \brief Queue buffers to converter device + * \param[in] input The frame buffer to apply the conversion + * \param[out] outputs The container holding the output stream indexes and + * their respective frame buffer outputs. + * + * This function queues the \a input frame buffer on the output streams of the + * \a outputs map key and retrieve the output frame buffer indicated by the + * buffer map value. + * + * \return 0 on success or a negative error code otherwise + */ + +/** + * \var Converter::inputBufferReady + * \brief A signal emitted when the input frame buffer completes + */ + +/** + * \var Converter::outputBufferReady + * \brief A signal emitted when the output frame buffer completes + */ + +/** + * \fn Converter::deviceNode() + * \brief The converter device node attribute accessor + * \return The converter device node string + */ + +/** + * \class ConverterFactoryBase + * \brief Base class for converter factories + * + * The ConverterFactoryBase class is the base of all specializations of the + * ConverterFactory class template. It implements the factory registration, + * maintains a registry of factories, and provides access to the registered + * factories. + */ + +/** + * \brief Construct a converter factory base + * \param[in] name Name of the converter class + * \param[in] aliases Name aliases of the converter class + * + * Creating an instance of the factory base registers it with the global list of + * factories, accessible through the factories() function. + * + * The factory \a name is used as unique identifier. If the converter + * implementation fully relies on a generic framework, the name should be the + * same as the framework. Otherwise, if the implementation is specialized, the + * factory name should match the driver name implementing the function. + * + * The factory \a aliases holds a list of driver names implementing a generic + * subsystem without any personalizations. + */ +ConverterFactoryBase::ConverterFactoryBase(const std::string name, std::initializer_list aliases) + : name_(name), aliases_(aliases) +{ + registerType(this); +} + +/** + * \fn ConverterFactoryBase::aliases() + * \return The names aliases + */ + +/** + * \brief Create an instance of the converter corresponding to a named factory + * \param[in] media Name of the factory + * + * \return A unique pointer to a new instance of the converter subclass + * corresponding to the named factory or one of its alias. Otherwise a null + * pointer if no such factory exists + */ +std::unique_ptr ConverterFactoryBase::create(MediaDevice *media) +{ + const std::vector &factories = + ConverterFactoryBase::factories(); + + for (const ConverterFactoryBase *factory : factories) { + const std::vector &aliases = factory->aliases(); + auto it = std::find(aliases.begin(), aliases.end(), media->driver()); + + if (it == aliases.end() && media->driver() != factory->name_) + continue; + + LOG(Converter, Debug) + << "Creating converter from " + << factory->name_ << " factory with " + << (it == aliases.end() ? "no" : media->driver()) << " alias."; + + return factory->createInstance(media); + } + + return nullptr; +} + +/** + * \brief Add a converter class to the registry + * \param[in] factory Factory to use to construct the converter class + * + * The caller is responsible to guarantee the uniqueness of the converter name. + */ +void ConverterFactoryBase::registerType(ConverterFactoryBase *factory) +{ + std::vector &factories = + ConverterFactoryBase::factories(); + + factories.push_back(factory); +} + +/** + * \brief Retrieve the list of all converter factory names + * \return The list of all converter factory names + */ +std::vector ConverterFactoryBase::names() +{ + std::vector list; + + std::vector &factories = + ConverterFactoryBase::factories(); + + for (ConverterFactoryBase *factory : factories) { + list.push_back(factory->name_); + for (auto alias : factory->aliases()) + list.push_back(alias); + } + + return list; +} + +/** + * \brief Retrieve the list of all converter factories + * \return The list of converter factories + */ +std::vector &ConverterFactoryBase::factories() +{ + /* + * The static factories map is defined inside the function to ensure + * it gets initialized on first use, without any dependency on link + * order. + */ + static std::vector factories; + return factories; +} + +/** + * \var ConverterFactoryBase::name_ + * \brief The name of the factory + */ + +/** + * \var ConverterFactoryBase::aliases_ + * \brief The list holding the factory aliases + */ + +/** + * \class ConverterFactory + * \brief Registration of ConverterFactory classes and creation of instances + * \param _Converter The converter class type for this factory + * + * To facilitate discovery and instantiation of Converter classes, the + * ConverterFactory class implements auto-registration of converter helpers. + * Each Converter subclass shall register itself using the REGISTER_CONVERTER() + * macro, which will create a corresponding instance of a ConverterFactory + * subclass and register it with the static list of factories. + */ + +/** + * \fn ConverterFactory::ConverterFactory(const char *name, std::initializer_list aliases) + * \brief Construct a converter factory + * \details \copydetails ConverterFactoryBase::ConverterFactoryBase + * + */ + +/** + * \fn ConverterFactory::createInstance() const + * \brief Create an instance of the Converter corresponding to the factory + * \param[in] media Media device pointer + * \return A unique pointer to a newly constructed instance of the Converter + * subclass corresponding to the factory + */ + +/** + * \def REGISTER_CONVERTER + * \brief Register a converter with the Converter factory + * \param[in] name Converter name used to register the class + * \param[in] converter Class name of Converter derived class to register + * \param[in] ... Optional list of alias names + * + * Register a Converter subclass with the factory and make it available to try + * and match converters. + */ + +} /* namespace libcamera */ diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index 0494e808..e9d0324e 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -13,6 +13,7 @@ libcamera_sources = files([ 'controls.cpp', 'control_serializer.cpp', 'control_validator.cpp', + 'converter.cpp', 'delayed_controls.cpp', 'device_enumerator.cpp', 'device_enumerator_sysfs.cpp', From patchwork Tue Nov 15 12:59:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier Roumegue X-Patchwork-Id: 17802 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 99887C3285 for ; Tue, 15 Nov 2022 13:00:12 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8B2EB63091; Tue, 15 Nov 2022 14:00:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1668517211; bh=NNRm5ysaW9aOkU/3+UmSo4hHHR9ERYJho/lw0z0JnQs=; 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=djZ6Q/PixYCnvczjhDCesDs1U8v/Gny/KFXYCKPXSS0LA6Ke1QgCupyy60UKNz7eq RVBLr0c1NrE4pBMUwzalzTIu9Grehm4eH75/jKhaf7WnSUOZs8b27TWbcHEmmX7WsS ygbF9JoegLjvxRueOIYg1PEQnSLVB8CsSCanNwEP315wYsUAPPU/atsd4g2JBWTaQS vdBjxlSwQFlIPrBkzUaJHuFEUZz3geZSOP0z7kxjw443IwqPgUvuWRHWecxAeZGkKV M4DJ0jooJFdv1q27d2l6+kkRAtEmriV4jhm/DcIQUW+2Ck6dOMoGtVmUPhAGbRXxq/ 9LEDC+4DsY5UA== Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on0613.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0d::613]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 363FC63086 for ; Tue, 15 Nov 2022 14:00:09 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="XIXh4v0A"; dkim-atps=neutral ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d2ij4oGkyk01ifuebutlSUqop2ykWvifeKOkyS/672GXPE03SHBZropnC2GTRb/DtGYePPEMn9NnLrlTM8Ih1JaMKG6TczG/03AzBVmXCTUt7868Me1KJzbn/eEjvFR3GJwOZ97dszv4rQDEqb0CISWNXC6lhEuR1OmtizduLcyHXchkIzvSjCMU9YQ/BHj2Zp3NpVI0doecPj7jVn9fZFPpRgKy/vrKWngrgFIvibLsu3P3Cve3RHZ/jkrY2hsNMdPgHN9jwTw2fV0lBg5Z1bPO57xeQ7kiQTVb9zNCo4moFrD5NU7sFvbcwOFRRPUFn2DHb/79dvM+MQHIK8THRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=KAUDWq3MJRyC2i5jOYmMmBF+MtZu4kl74ng2Y39O4pI=; b=NA/FRiWlvjCjkC5zDota7hqEhnqE6fZK6PbxxOePVXkC23bPK277zpaO1/FmYgIgKSL16FeziFNpMnCfEJ/gXyZ2IgYPLsU9TouD2srj8EaNzxJnDy6AebZdaUO/OraB1BcJ0PmqWgePwuGx248wivZyjaLBO2QCtyf3BCe1E2lBg1E+u3fWlHVri/heV40ODfuCIqvD2WuyIQp8J/MtxQF9GZGuy7MSNqgeSraLsOZPhi5SR4BxLIAOmE2F7v+Zh86+Zs+D/sdUQ32BjbpL34zgV0KLCaON+2s4GlsGXtX0c+9rgRcvTWiq2ronlSAM7wo/iCs5gfz2VBzwRQrrNQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KAUDWq3MJRyC2i5jOYmMmBF+MtZu4kl74ng2Y39O4pI=; b=XIXh4v0A7Y6jDwC09KY3qsV0ddO78EFm4uqSwhwPh+EX1G+Mnbr1m1bNL1Rk2Gbl0xJpSFQEj+K6dl1ZXafzlkFaXFMVpOwA+8n5hKi8V0ElSut65bkC+6AocJN72uDrEKkO75caZtafSd+oi+nMAoW9DuX0kJAccf2sVnrt+kM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from PAXPR04MB8703.eurprd04.prod.outlook.com (2603:10a6:102:21e::22) by PAXPR04MB8639.eurprd04.prod.outlook.com (2603:10a6:102:21e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5813.13; Tue, 15 Nov 2022 13:00:06 +0000 Received: from PAXPR04MB8703.eurprd04.prod.outlook.com ([fe80::14d3:8e4:cf07:810d]) by PAXPR04MB8703.eurprd04.prod.outlook.com ([fe80::14d3:8e4:cf07:810d%3]) with mapi id 15.20.5813.018; Tue, 15 Nov 2022 13:00:06 +0000 To: jacopo@jmondi.org, laurent.pinchart@ideasonboard.com Date: Tue, 15 Nov 2022 13:59:34 +0100 Message-Id: <20221115125935.1196138-2-xavier.roumegue@oss.nxp.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221115125935.1196138-1-xavier.roumegue@oss.nxp.com> References: <20221115125935.1196138-1-xavier.roumegue@oss.nxp.com> X-ClientProxiedBy: PR3P189CA0080.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::25) To PAXPR04MB8703.eurprd04.prod.outlook.com (2603:10a6:102:21e::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8703:EE_|PAXPR04MB8639:EE_ X-MS-Office365-Filtering-Correlation-Id: 30763b04-1832-4458-5e60-08dac70951a5 X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PpfY3H6wuzEAoN4m4u4/Qelxw/ODJ5a6f1eg83ToNh8Cmwf6FTPAzymymzkmFoO61HKO5Jl0DPdFiLEyqP9lZobKbZBYC5zRV3l2QlZYJbDmcoIj/PZjw4b7ruDdLj+K0OlbRiHeZgQSu+nC5VK/lw7sqpzvNCyYX/7irykx5wj2MEyz4dI1Zi+qRTexzEfeTQXf6fx4LvkiqmF3/z8f56vBk1ZCqMetS/5LaC2FVNdgUtfwkGTK/NWW6e444Tr/9+zhr7/mE35uGu9X+UBr6+IvhgHMHKEFK4k5BiPKZCHnG0gWxoCj4Gz5fx9PrM+gPD1lZ3oey+dm62srzWUNiqIjdrWT8IXxfIoWEUdnWc8IESjCKWDk+IuOVW+nU9q3UdBUN/XT9DZCfEseaeyx5WXUcHuqUIb2yLEWk/4Yt1fjuEzlaY/DGUP80KqfpE9TWSxDsS/Nw1ZlI7NS8wxBtU7jHu8QpV2gMHMxkuKTF08JnujtiE2SynJrlWZ5iz3xn4VTpYiPhjAsrL58jpd70WN9zJ/R69ubRRqs4/moO1t2pGPsp1lkrRXTFCtrVoIT8pI/RX2lUnGteIFZobkOj0O0EIonGqQ5STG8kNluW81sC3+Sm7zxUI2wM/fvSa56ze8RNmmbrCNjSJM5sYHph2/swxR6c/x0dWJLnu+gpYHkKj/xdKjc2x2jlDw52lkkoTGPGKblld4VV0d89m1dqnxCha9iXev3b2rqgqsEhE8daALYRyQ6z/zZgNh/sn4L X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PAXPR04MB8703.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(136003)(396003)(366004)(376002)(39860400002)(346002)(451199015)(6512007)(86362001)(316002)(38100700002)(52116002)(83380400001)(44832011)(2906002)(41300700001)(8676002)(4326008)(66946007)(8936002)(66556008)(1076003)(66476007)(186003)(30864003)(5660300002)(2616005)(6486002)(6506007)(478600001)(6666004)(41533002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wY1bj1gMk2IbyYyKSvToFS6S9m3oGxsZ9CQULwOHwwYDYRymfnPXDe3TTmxFtKFkpVAJBEmBSlLuEkd12UNJonbMMqk5MmmBPQ4fftBprKNdXmDgyadcDZbM5mDPqCBLG7PH9Zmk9jobbKN+mgn38KW7Nbg4oK+MIh63p3nkS28qyzLuhRpvCddSBItwffiPshb9EhUzzO4Rg+arGTGhYGqmrtaDpR5/jwUuW7eDSrUOpWrl6hVqgrplfgLEGoeX+qNSNzFTDbJZnZHHLmDSLnces9Lb3q0U0r4NigFMgBcnyl41dJUCIrdMFUqkyclu3c9RuGtJyK9mWa9hfMGNhxhQMG/f55dV9uhWwWhZhPW6jFNu/KrN68RNIUy73sFnpvE1CZZQeHTlhQJRC6ioF8rMk2/Af/e6gXSxEPSznlmimBnV7tAHqylErDAlAoJRomjsuGEypo138PqDcaR22ydb4GHmqOEV3ThNjUBOVouv/9VjBBGLAqWAmMIoP1D00fXOgtKvfL0MigZYo5ZDbmU6/LkwsqQO9eSeaFL/GoUMaxeaqKW29mxSD7XixHuxkQmwTwaV95KC9j+nSRB87awkFGaqzcFvSGaSK/U+ToQOKblmSH91zLq+XmZjLoRxeVB2k4CZPVwlsbFUek45V9qrEGnS3O0attRYWMwx2qfd4DstNRV5htxNVLb44jTO3LFD5jkx5esuV4Y392vRy5knIlowxk05wthjDjUOqcBEVCrUeDX6+9VDeGwAQwbzXjaT0QWDPurX35ncT9AHVSDs3UHCrwWxNaz1MCmkQBTK8jIWiAPx7IPspslMVlLL5wXxo1CIBmHQev4ieDP3H+L9NXKaAEkMb93KEUWmjKEP12ueWUafd93kQfCj3yA3HUsD7GomV/WjlEbE0x7cwVgLJNwU1FmZKj0Lk2WMIwWtFNo0jwpSnTqXoadrrCwcU26TBrOZGDsg8TrAoY7yMwfte/wSQXoIGnwN2qjoXh/+i98HT7oilpaqYB/YoandcWfxqD4VYg2J+IicKXwIUVXX7jlAsl3d8KoxsMPtIkHBRvD/vGr02wdYMW/b3qDPsoqLW729Z5X2ykHnCtUxyq8XEfgSqSYQ+iqPAlmXcMqcO3TO6L1fX3ODn9zaOxFxAF704Y4XPggtLEef8ZKHqTvRUEDQg4/Dfzgv+IJL98pGdo382kNjhx9hRhOB0OEHVAMrD0IYYdOCsFt/hMsg0+hmdTT3mh5Winw47FeQ2nfza+jTFLn52WCtSwa5Pq7HdY/X6w4DjleU3OmRLjrB+OU8wN4B0He5EkCQtiOA6aqjPjUrjM/Wfdl3ZYRfs+4JQegdK0u9yY/CirPoAoI/8j5c3yO8GlJH7vp4GEtkuK/IRsts9N9PJ27yNmiqjBeuClGAHANtcROmXmfLbz7U8fB9IkRgkeuterYJLkbbjOXBwx+e1eFRho2T0lM3ptYmdSFj8+KTgCNVNsoWC/R6iUC8y2Mt4tppRxhj5YmQTwTXRj6he9/EoBoB+yEj0ppDsuRDig6ePpk6XRg2yMyvuEsvp7IsC2xqWRRQ+1dOK3AXyPtMsE3X++gIH+qw2l709xTBibo+06Os9ILHnw6uQqhk6cXC0Z3lJIAOEPMO6XSYblCBEGTZHiwU2vddUuaS6oOS4CVpBTqyZNVvOOC6gA== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 30763b04-1832-4458-5e60-08dac70951a5 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8703.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Nov 2022 13:00:06.7896 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: EVzmsturS0DK5pDgwvc7l8vQWYsHuOfrk99xCWKSsIvfn/bk1GKcTV54Wuls4olohaFVrEV+Wk8NAuMkYQDtUg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8639 Subject: [libcamera-devel] [PATCH v2 2/2] libcamera: pipeline: simple: converter: Use generic converter interface 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: Xavier Roumegue via libcamera-devel From: Xavier Roumegue Reply-To: Xavier Roumegue Cc: libcamera-devel@lists.libcamera.org Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Move the simple converter implementation to a generic V4L2 M2M class derived from the converter interface. This latter could be used by other pipeline implementations and as base class for customized V4L2 M2M converters. Signed-off-by: Xavier Roumegue Reviewed-by: Jacopo Mondi --- .../internal/converter/converter_v4l2_m2m.h | 18 +-- .../libcamera/internal/converter/meson.build | 5 + include/libcamera/internal/meson.build | 2 + .../converter_v4l2_m2m.cpp} | 153 +++++++++++------- src/libcamera/converter/meson.build | 5 + src/libcamera/meson.build | 1 + src/libcamera/pipeline/simple/meson.build | 1 - src/libcamera/pipeline/simple/simple.cpp | 6 +- 8 files changed, 123 insertions(+), 68 deletions(-) rename src/libcamera/pipeline/simple/converter.h => include/libcamera/internal/converter/converter_v4l2_m2m.h (83%) create mode 100644 include/libcamera/internal/converter/meson.build rename src/libcamera/{pipeline/simple/converter.cpp => converter/converter_v4l2_m2m.cpp} (68%) create mode 100644 src/libcamera/converter/meson.build diff --git a/src/libcamera/pipeline/simple/converter.h b/include/libcamera/internal/converter/converter_v4l2_m2m.h similarity index 83% rename from src/libcamera/pipeline/simple/converter.h rename to include/libcamera/internal/converter/converter_v4l2_m2m.h index f0ebe2e0..ef31eeba 100644 --- a/src/libcamera/pipeline/simple/converter.h +++ b/include/libcamera/internal/converter/converter_v4l2_m2m.h @@ -1,8 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2020, Laurent Pinchart + * Copyright 2022 NXP * - * converter.h - Format converter for simple pipeline handler + * converter_v4l2_m2m.h - V4l2 M2M Format converter interface */ #pragma once @@ -19,6 +20,8 @@ #include #include +#include "libcamera/internal/converter.h" + namespace libcamera { class FrameBuffer; @@ -28,11 +31,12 @@ class SizeRange; struct StreamConfiguration; class V4L2M2MDevice; -class SimpleConverter +class V4L2M2MConverter : public Converter { public: - SimpleConverter(MediaDevice *media); + V4L2M2MConverter(MediaDevice *media); + int loadConfiguration([[maybe_unused]] const std::string &filename) { return 0; } bool isValid() const { return m2m_ != nullptr; } std::vector formats(PixelFormat input); @@ -52,14 +56,11 @@ public: int queueBuffers(FrameBuffer *input, const std::map &outputs); - Signal inputBufferReady; - Signal outputBufferReady; - private: class Stream : protected Loggable { public: - Stream(SimpleConverter *converter, unsigned int index); + Stream(V4L2M2MConverter *converter, unsigned int index); bool isValid() const { return m2m_ != nullptr; } @@ -80,7 +81,7 @@ private: void captureBufferReady(FrameBuffer *buffer); void outputBufferReady(FrameBuffer *buffer); - SimpleConverter *converter_; + V4L2M2MConverter *converter_; unsigned int index_; std::unique_ptr m2m_; @@ -88,7 +89,6 @@ private: unsigned int outputBufferCount_; }; - std::string deviceNode_; std::unique_ptr m2m_; std::vector streams_; diff --git a/include/libcamera/internal/converter/meson.build b/include/libcamera/internal/converter/meson.build new file mode 100644 index 00000000..891e79e7 --- /dev/null +++ b/include/libcamera/internal/converter/meson.build @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: CC0-1.0 + +libcamera_internal_headers += files([ + 'converter_v4l2_m2m.h', +]) diff --git a/include/libcamera/internal/meson.build b/include/libcamera/internal/meson.build index 8f50d755..b9db5a8c 100644 --- a/include/libcamera/internal/meson.build +++ b/include/libcamera/internal/meson.build @@ -45,3 +45,5 @@ libcamera_internal_headers = files([ 'v4l2_videodevice.h', 'yaml_parser.h', ]) + +subdir('converter') diff --git a/src/libcamera/pipeline/simple/converter.cpp b/src/libcamera/converter/converter_v4l2_m2m.cpp similarity index 68% rename from src/libcamera/pipeline/simple/converter.cpp rename to src/libcamera/converter/converter_v4l2_m2m.cpp index acaaa64c..31acb048 100644 --- a/src/libcamera/pipeline/simple/converter.cpp +++ b/src/libcamera/converter/converter_v4l2_m2m.cpp @@ -1,12 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ /* * Copyright (C) 2020, Laurent Pinchart + * Copyright 2022 NXP * - * converter.cpp - Format converter for simple pipeline handler + * converter_v4l2_m2m.cpp - V4L2 M2M Format converter */ -#include "converter.h" - #include #include @@ -20,19 +19,25 @@ #include "libcamera/internal/media_device.h" #include "libcamera/internal/v4l2_videodevice.h" +#include "libcamera/internal/converter/converter_v4l2_m2m.h" + +/** + * \file internal/converter/converter_v4l2_m2m.h + * \brief V4L2 M2M based converter + */ namespace libcamera { -LOG_DECLARE_CATEGORY(SimplePipeline) +LOG_DECLARE_CATEGORY(Converter) /* ----------------------------------------------------------------------------- - * SimpleConverter::Stream + * V4L2M2MConverter::Stream */ -SimpleConverter::Stream::Stream(SimpleConverter *converter, unsigned int index) +V4L2M2MConverter::Stream::Stream(V4L2M2MConverter *converter, unsigned int index) : converter_(converter), index_(index) { - m2m_ = std::make_unique(converter->deviceNode_); + m2m_ = std::make_unique(converter->deviceNode()); m2m_->output()->bufferReady.connect(this, &Stream::outputBufferReady); m2m_->capture()->bufferReady.connect(this, &Stream::captureBufferReady); @@ -42,8 +47,8 @@ SimpleConverter::Stream::Stream(SimpleConverter *converter, unsigned int index) m2m_.reset(); } -int SimpleConverter::Stream::configure(const StreamConfiguration &inputCfg, - const StreamConfiguration &outputCfg) +int V4L2M2MConverter::Stream::configure(const StreamConfiguration &inputCfg, + const StreamConfiguration &outputCfg) { V4L2PixelFormat videoFormat = m2m_->output()->toV4L2PixelFormat(inputCfg.pixelFormat); @@ -56,14 +61,14 @@ int SimpleConverter::Stream::configure(const StreamConfiguration &inputCfg, int ret = m2m_->output()->setFormat(&format); if (ret < 0) { - LOG(SimplePipeline, Error) + LOG(Converter, Error) << "Failed to set input format: " << strerror(-ret); return ret; } if (format.fourcc != videoFormat || format.size != inputCfg.size || format.planes[0].bpl != inputCfg.stride) { - LOG(SimplePipeline, Error) + LOG(Converter, Error) << "Input format not supported (requested " << inputCfg.size << "-" << videoFormat << ", got " << format << ")"; @@ -78,13 +83,13 @@ int SimpleConverter::Stream::configure(const StreamConfiguration &inputCfg, ret = m2m_->capture()->setFormat(&format); if (ret < 0) { - LOG(SimplePipeline, Error) + LOG(Converter, Error) << "Failed to set output format: " << strerror(-ret); return ret; } if (format.fourcc != videoFormat || format.size != outputCfg.size) { - LOG(SimplePipeline, Error) + LOG(Converter, Error) << "Output format not supported"; return -EINVAL; } @@ -95,13 +100,13 @@ int SimpleConverter::Stream::configure(const StreamConfiguration &inputCfg, return 0; } -int SimpleConverter::Stream::exportBuffers(unsigned int count, - std::vector> *buffers) +int V4L2M2MConverter::Stream::exportBuffers(unsigned int count, + std::vector> *buffers) { return m2m_->capture()->exportBuffers(count, buffers); } -int SimpleConverter::Stream::start() +int V4L2M2MConverter::Stream::start() { int ret = m2m_->output()->importBuffers(inputBufferCount_); if (ret < 0) @@ -128,7 +133,7 @@ int SimpleConverter::Stream::start() return 0; } -void SimpleConverter::Stream::stop() +void V4L2M2MConverter::Stream::stop() { m2m_->capture()->streamOff(); m2m_->output()->streamOff(); @@ -136,8 +141,7 @@ void SimpleConverter::Stream::stop() m2m_->output()->releaseBuffers(); } -int SimpleConverter::Stream::queueBuffers(FrameBuffer *input, - FrameBuffer *output) +int V4L2M2MConverter::Stream::queueBuffers(FrameBuffer *input, FrameBuffer *output) { int ret = m2m_->output()->queueBuffer(input); if (ret < 0) @@ -150,12 +154,12 @@ int SimpleConverter::Stream::queueBuffers(FrameBuffer *input, return 0; } -std::string SimpleConverter::Stream::logPrefix() const +std::string V4L2M2MConverter::Stream::logPrefix() const { return "stream" + std::to_string(index_); } -void SimpleConverter::Stream::outputBufferReady(FrameBuffer *buffer) +void V4L2M2MConverter::Stream::outputBufferReady(FrameBuffer *buffer) { auto it = converter_->queue_.find(buffer); if (it == converter_->queue_.end()) @@ -167,32 +171,34 @@ void SimpleConverter::Stream::outputBufferReady(FrameBuffer *buffer) } } -void SimpleConverter::Stream::captureBufferReady(FrameBuffer *buffer) +void V4L2M2MConverter::Stream::captureBufferReady(FrameBuffer *buffer) { converter_->outputBufferReady.emit(buffer); } /* ----------------------------------------------------------------------------- - * SimpleConverter + * V4L2M2MConverter + */ + +/** + * \class libcamera::V4L2M2MConverter + * \brief The V4L2 M2M converter implements the converter interface based on + * V4L2 M2M device. +*/ + +/** + * \fn V4L2M2MConverter::V4L2M2MConverter + * \brief Construct a V4L2M2MConverter instance + * \param[in] media The media device implementing the converter */ -SimpleConverter::SimpleConverter(MediaDevice *media) +V4L2M2MConverter::V4L2M2MConverter(MediaDevice *media) + : Converter(media) { - /* - * Locate the video node. There's no need to validate the pipeline - * further, the caller guarantees that this is a V4L2 mem2mem device. - */ - 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()) + if (deviceNode().empty()) return; - deviceNode_ = (*it)->deviceNode(); - - m2m_ = std::make_unique(deviceNode_); + m2m_ = std::make_unique(deviceNode()); int ret = m2m_->open(); if (ret < 0) { m2m_.reset(); @@ -200,7 +206,21 @@ SimpleConverter::SimpleConverter(MediaDevice *media) } } -std::vector SimpleConverter::formats(PixelFormat input) +/** + * \fn libcamera::V4L2M2MConverter::loadConfiguration + * \details \copydetails libcamera::Converter::loadConfiguration + */ + +/** + * \fn libcamera::V4L2M2MConverter::isValid + * \details \copydetails libcamera::Converter::isValid + */ + +/** + * \fn libcamera::V4L2M2MConverter::formats + * \details \copydetails libcamera::Converter::formats + */ +std::vector V4L2M2MConverter::formats(PixelFormat input) { if (!m2m_) return {}; @@ -215,13 +235,13 @@ std::vector SimpleConverter::formats(PixelFormat input) int ret = m2m_->output()->setFormat(&v4l2Format); if (ret < 0) { - LOG(SimplePipeline, Error) + LOG(Converter, Error) << "Failed to set format: " << strerror(-ret); return {}; } if (v4l2Format.fourcc != m2m_->output()->toV4L2PixelFormat(input)) { - LOG(SimplePipeline, Debug) + LOG(Converter, Debug) << "Input format " << input << " not supported."; return {}; } @@ -237,7 +257,10 @@ std::vector SimpleConverter::formats(PixelFormat input) return pixelFormats; } -SizeRange SimpleConverter::sizes(const Size &input) +/** + * \copydoc libcamera::Converter::sizes + */ +SizeRange V4L2M2MConverter::sizes(const Size &input) { if (!m2m_) return {}; @@ -252,7 +275,7 @@ SizeRange SimpleConverter::sizes(const Size &input) int ret = m2m_->output()->setFormat(&format); if (ret < 0) { - LOG(SimplePipeline, Error) + LOG(Converter, Error) << "Failed to set format: " << strerror(-ret); return {}; } @@ -262,7 +285,7 @@ SizeRange SimpleConverter::sizes(const Size &input) format.size = { 1, 1 }; ret = m2m_->capture()->setFormat(&format); if (ret < 0) { - LOG(SimplePipeline, Error) + LOG(Converter, Error) << "Failed to set format: " << strerror(-ret); return {}; } @@ -272,7 +295,7 @@ SizeRange SimpleConverter::sizes(const Size &input) format.size = { UINT_MAX, UINT_MAX }; ret = m2m_->capture()->setFormat(&format); if (ret < 0) { - LOG(SimplePipeline, Error) + LOG(Converter, Error) << "Failed to set format: " << strerror(-ret); return {}; } @@ -282,9 +305,12 @@ SizeRange SimpleConverter::sizes(const Size &input) return sizes; } +/** + * \copydoc libcamera::Converter::strideAndFrameSize + */ std::tuple -SimpleConverter::strideAndFrameSize(const PixelFormat &pixelFormat, - const Size &size) +V4L2M2MConverter::strideAndFrameSize(const PixelFormat &pixelFormat, + const Size &size) { V4L2DeviceFormat format; format.fourcc = m2m_->capture()->toV4L2PixelFormat(pixelFormat); @@ -297,8 +323,11 @@ SimpleConverter::strideAndFrameSize(const PixelFormat &pixelFormat, return std::make_tuple(format.planes[0].bpl, format.planes[0].size); } -int SimpleConverter::configure(const StreamConfiguration &inputCfg, - const std::vector> &outputCfgs) +/** + * \copydoc libcamera::Converter::configure + */ +int V4L2M2MConverter::configure(const StreamConfiguration &inputCfg, + const std::vector> &outputCfgs) { int ret = 0; @@ -309,7 +338,7 @@ int SimpleConverter::configure(const StreamConfiguration &inputCfg, Stream &stream = streams_.emplace_back(this, i); if (!stream.isValid()) { - LOG(SimplePipeline, Error) + LOG(Converter, Error) << "Failed to create stream " << i; ret = -EINVAL; break; @@ -328,8 +357,11 @@ int SimpleConverter::configure(const StreamConfiguration &inputCfg, return 0; } -int SimpleConverter::exportBuffers(unsigned int output, unsigned int count, - std::vector> *buffers) +/** + * \copydoc libcamera::Converter::exportBuffers + */ +int V4L2M2MConverter::exportBuffers(unsigned int output, unsigned int count, + std::vector> *buffers) { if (output >= streams_.size()) return -EINVAL; @@ -337,7 +369,10 @@ int SimpleConverter::exportBuffers(unsigned int output, unsigned int count, return streams_[output].exportBuffers(count, buffers); } -int SimpleConverter::start() +/** + * \copydoc libcamera::Converter::start + */ +int V4L2M2MConverter::start() { int ret; @@ -352,14 +387,20 @@ int SimpleConverter::start() return 0; } -void SimpleConverter::stop() +/** + * \copydoc libcamera::Converter::stop + */ +void V4L2M2MConverter::stop() { for (Stream &stream : utils::reverse(streams_)) stream.stop(); } -int SimpleConverter::queueBuffers(FrameBuffer *input, - const std::map &outputs) +/** + * \copydoc libcamera::Converter::queueBuffers + */ +int V4L2M2MConverter::queueBuffers(FrameBuffer *input, + const std::map &outputs) { unsigned int mask = 0; int ret; @@ -402,4 +443,6 @@ int SimpleConverter::queueBuffers(FrameBuffer *input, return 0; } +REGISTER_CONVERTER("v4l2_m2m", V4L2M2MConverter, "pxp") + } /* namespace libcamera */ diff --git a/src/libcamera/converter/meson.build b/src/libcamera/converter/meson.build new file mode 100644 index 00000000..2aa72fe4 --- /dev/null +++ b/src/libcamera/converter/meson.build @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: CC0-1.0 + +libcamera_sources += files([ + 'converter_v4l2_m2m.cpp' +]) diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build index e9d0324e..ffc294f3 100644 --- a/src/libcamera/meson.build +++ b/src/libcamera/meson.build @@ -62,6 +62,7 @@ libatomic = cc.find_library('atomic', required : false) libthreads = dependency('threads') subdir('base') +subdir('converter') subdir('ipa') subdir('pipeline') subdir('proxy') diff --git a/src/libcamera/pipeline/simple/meson.build b/src/libcamera/pipeline/simple/meson.build index 9c99b32f..42b0896d 100644 --- a/src/libcamera/pipeline/simple/meson.build +++ b/src/libcamera/pipeline/simple/meson.build @@ -1,6 +1,5 @@ # SPDX-License-Identifier: CC0-1.0 libcamera_sources += files([ - 'converter.cpp', 'simple.cpp', ]) diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index a32de7f3..24ded4db 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -30,13 +30,13 @@ #include "libcamera/internal/camera.h" #include "libcamera/internal/camera_sensor.h" +#include "libcamera/internal/converter.h" #include "libcamera/internal/device_enumerator.h" #include "libcamera/internal/media_device.h" #include "libcamera/internal/pipeline_handler.h" #include "libcamera/internal/v4l2_subdevice.h" #include "libcamera/internal/v4l2_videodevice.h" -#include "converter.h" namespace libcamera { @@ -266,7 +266,7 @@ public: std::vector configs_; std::map> formats_; - std::unique_ptr converter_; + std::unique_ptr converter_; std::vector> converterBuffers_; bool useConverter_; std::queue> converterQueue_; @@ -492,7 +492,7 @@ int SimpleCameraData::init() /* Open the converter, if any. */ MediaDevice *converter = pipe->converter(); if (converter) { - converter_ = std::make_unique(converter); + converter_ = ConverterFactoryBase::create(converter); if (!converter_->isValid()) { LOG(SimplePipeline, Warning) << "Failed to create converter, disabling format conversion";