From patchwork Wed Dec 14 10:34:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier Roumegue X-Patchwork-Id: 18010 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 C0623C328E for ; Wed, 14 Dec 2022 10:35:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 54A4463367; Wed, 14 Dec 2022 11:35:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1671014112; bh=XIRfq6ilxcjqOj832v1cuzGV+LCBeioHVYVkX75ycd8=; 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=znsaxYDDFRTwIdzSYzBFx+JR+5iSS9yo2DBu88Fk96JxlTxkb6b83csZp9xyLo0v/ 7Lv+1DcpZDyOWoLzPGoMtRre0nGXOXT5BbXDmU/Z5HNGHsbXePMG2KOtT5hPQ57bf4 0FDeIQkQODVHsAfKfuwli6bXYZwvXHmelkGNDxU1C+v3851EqRPVQVA62+TW9MrS/o AVwg+MEUEeTLoEoiE/FBplBvCxGJL2CND89/BEBc+rCe7Xc1ie0Hcq7+8iuBnEMZHh SK97rZ9r/taG9mvxQOEFl8txZ3rUo9wXVWjYj2qZvui/9CoSSVEcZuSBYo5qGEHvvX jx/OwQn4iRB9w== Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2084.outbound.protection.outlook.com [40.107.105.84]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 74D5663354 for ; Wed, 14 Dec 2022 11:35:10 +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="PqByhl5J"; dkim-atps=neutral ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f2jWB6xDfr2eE+Mb2PmHtAngbR9YBGs9GhmnZUjoZM0/M7yNkaPeT38PRl424NjnACgFr5F3uc8nPDClQ2zJn+YRUeMyx2s5ohhvY3ehwE9ePGtzeWtQ7puCVcd6a/Ru2+F2kTLSqrG1sSE15f1oD/NFYALBDuZV7HBwOPQY2LswQ6EZ2YljrCDrvxZkyP+3bTETrNoel10yDNRj7EPOHBF6DAQEmQFZFywMdWCkKjd7/vecX6U8lG0pMSjoXUAfI3DU/4mABPnQqCekj8EAU9oJebZHll8vhVxwo96VW+9Uxh1xz3qnTUGNtA3Dby38XKHBxjiGT1KhaqNzxYnCBw== 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=gassHcAXdxUcu30UNhi04Xa+JxjUBKc9xwj20+B3twY=; b=f6vqfQVP+koElrdffUuPIpeJ3ou0CvaUOa/ieQW+fgNITV2KDSGzPG4+jV99fRJ7KdbbFklClel9Bb0Ff+RLEriKKxdCEjxEyb0CcvoX+iruL7loeHQ9rZq87pGFI3MWkKh1KBDzfQ6RPjymqQ8zJo0GFG2eUomLWa/pA9UsCvTtbbWrN34ymf8YCZ3nMbx9j/spu0I0nGiz76xsOXrGuqyKzLibxW22/AYfyA2EohI3rRKyJr5iZhGQ1CxvbvjbuuoemDmVFuIcGAejwn+8l9bKRzhwKDfxVNKLVVBQB1mAp0mvOCRHQG8wqNOV3WETX1EVLwPEX+8pxzy0Vp4i+w== 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=gassHcAXdxUcu30UNhi04Xa+JxjUBKc9xwj20+B3twY=; b=PqByhl5JRXCvoUSqQB/cEkTOLd+Yup5N4f426F198mQw4MW35raLqwqF/VW1BYeQ/BecFno7Mho9v/mRGTAkA003HHh8FPOUIWpmQ8eTBQDwxsXsuuDGVRxHL8YDVvoNhkz1VPYEcmQspjFA7wA3+UDwbpywpNiYtn5IzMeiWo8= 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 DB8PR04MB7177.eurprd04.prod.outlook.com (2603:10a6:10:127::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.10; Wed, 14 Dec 2022 10:35:07 +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.5880.019; Wed, 14 Dec 2022 10:35:07 +0000 To: jacopo@jmondi.org, laurent.pinchart@ideasonboard.com, kieran.bingham@ideasonboard.com Date: Wed, 14 Dec 2022 11:34:43 +0100 Message-Id: <20221214103443.236973-2-xavier.roumegue@oss.nxp.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221214103443.236973-1-xavier.roumegue@oss.nxp.com> References: <20221214103443.236973-1-xavier.roumegue@oss.nxp.com> X-ClientProxiedBy: PR0P264CA0179.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:1c::23) 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_|DB8PR04MB7177:EE_ X-MS-Office365-Filtering-Correlation-Id: 495c06e8-4411-45dc-8731-08daddbede8d 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: pmpxgqTHF6CljvmPEWIK/nMneTk3uvEArWLv5KMpCKL+oxa7cWycvgFTudik1Gdopl+/qZ6RFAMlfwD0tF0Qw5/ntS8Q1PLeCBKyoXMBBg2zN/QFjGRWYh3HAzd+48rbP2DtwAn8M0RQ7eLPXf2tOt6w4XA5mcVHy2ieNF2gZPffuSMZuLeZ0dgsOsZiiGJnWfXVwWPdvvYogbBYvYrrMlXCSSZ5hy9Po/d0vF3phlMz2Z7bESmlJx/0RgzSwyGXPc1byBjPg9GjasKZVLlYZikiUcOQ1132eFvT1WelNmptcHX6i6XZslMDk39U7wJu8PT1Tlqe2kmeqEds68cd2r/ZqiLUhqBImgbEmsSeqq8upqQvPBeTA//QBHEdVhsIf/re3iP8d+pA/IBDkmzNPjCQw6dicS4yToQh9nLfA7X2XdznHH0U1rwaYwyHi2BrPeDse9Y+saX0A6gxEHOTJoYrxtaxUPXIQ4EWzQeb0zY7WK/lHLx5qyu6b/dHlneZevHIYrCDMMCw1uO2afHYPl+NWfEZAzUqpUo7WPFyoB0VPIoItkC3IQfop2YXi8xeE+fnI1FqWOBx9AFrkIDsMdBfCBGvj7d/I+z6BdbfOlK3lcq3kqDrEKEViSxgOdJ0/vnKDVCndtoCyLBAP+lBy4xbGxmGbZx9W232CgYw4cQtrqkI1EPs2hXBPv6qO67R 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)(366004)(39860400002)(396003)(346002)(376002)(136003)(451199015)(8936002)(44832011)(478600001)(5660300002)(83380400001)(86362001)(66476007)(38100700002)(2906002)(4326008)(66946007)(66556008)(8676002)(30864003)(41300700001)(2616005)(6666004)(6512007)(52116002)(6506007)(186003)(316002)(6486002)(1076003)(41533002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JCX61QCl5fuJGBHswCwS3YbMhf+6wwPTXep+H1Cz4/f5cQljLyY0qSRzvLJ/YnArcQ+fBNu3+W38O601nMl3b4CrYu99MxI2g8vfaT1wmV34qFITIAoXxA4YCrX26H+PH7UY8dQp3+crPw5Vzsv24E4T22WMb5Gbg8RjiBDbLNLhNjCtvpGpuVpuWFA519sgaEnH3YmCdao0Ff2bK6EM0q82Kmqxn4hlXL2iPsfP1ZOD3AHrfTPID6nNeTnJMZ1ct47JaWqXnpbalafa4ZTE3OWRDMo1lLLdVOU/12Ni16a9jd8kz0wvggzHDIbjstMUvqCi2qiHaltfupSnhCDmUhs3ndjKBcELlF0lhMuQF/TeyBgCD3fgG4vW1rCv4YA4O41mxKZUNVPXDjcDPmsUjlM6OQiRzOUr67ZSdoGyBcV3idSRM/ED07bZ3IQQ8dCZFVpKjX7kxBxMjR9koZ7AnJXhCMKVnDssEsX4Tm5CWjUhjkfj/8FFProzdUVyJl6rkyRvgLBU9D2192MMfi/lr2u/jDMVvZe7GcbzBvHZEAH7j3wau8OmJdB8dKN/IZEpXGmikSsQCL/BaI/qTs2gZwJJX67hjTFABYpQdasDM8oljNFo2qPNOf/6bmG+fhyOsBQpNOpkbnIAVRYaccazLaT14OW1L/q4MbIH/S2+C4BEomkIhOUFRwoxljvCTy8RDdyZe7kK3Q5bjLVVXnjiSx9q8Qb1c8mMDjX7HmWNguUEDVukrqRjdZIBxdffga2S7mVoBJFJ77CQStfARZ05Z3ApWUEsQiu5HMJ665VLzD34PbbonuTwgrvGBnjDbh5txUUmCwLmGpRkTn4dHEIAcezoNsfoZE7tZxx86rQ+Q04gBdtrAL5HEgoJW5IvWnUpz4i7YA+G7DeOZLP/uT2sEAF9X4jZRr6bYhTsDZwmSR9ij7jF7k3ylnxgjc+dYPMC6xAndZoEgCopepT+uTcCC+/9hlWm/bPQPC5zSRnxnZnB/e9EFDePztWsu+Kloy6fgMGXMFjpeGK31loflw3eKV5YA0b8wVyc2NCCEMldEk6WkkfP/N9chA1y3mTyaAFvi4KQr02Yb48wHITwg25h//1LutQ9gAxcCQEo4aSUF6sEwH+TcQGggmtdK6S313Hn4vcIAHL0ODYFdeH7MqbFgIWYJ/tS6JMwXlyo3x25eVYubklOuzfGmV3RPl3gfoAnoSSzLdKYuPFt+GG9sRkZ5Fa6/1rNGdZETo3GVIkaeB8EmSPBxRLRyWk4NT8AgQG8xqx5B8qqb8uVmV4r26ZynISos3GRZYhR7U8uulVgvjhjf101cPe3Sb5P7CIqYyvBQPSTD92TQfTf6vyBQL/qOnCp7rYe+bV2P5JbS0+An1uJoY/PjfqyPBi5zRkhlfI/GBYehIOG1zvk9G1jtyMwG+BfBThldWRtIt4u6ZqeOiH1amjfim+Ggzm5KPjlqpChP9it/kr3UvAqtcQ8bB8wV1Tu8psGIw173X/orbXxyzqibZp38AflMA0UHB6by1VUFB9vkdmcbUIGtDi30QkSwggq/iNV5DMUvtu+iEngLXnFv50KrPiX/swX1FMNIHR/ZVWdy+bbbtYyxcj8pMnFUGu2/OwEaGHAKFwH/s0ducf495uSHqYIeg/nphOxZOH9CTRoZF8uRRBlwJpWXSJ26A== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 495c06e8-4411-45dc-8731-08daddbede8d X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8703.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Dec 2022 10:35:07.6031 (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: YWNt8vTOYDlZt1z+bhUk61bOohmofaXWPgVLrZFNqmVQ2sqMo1hzSRZmPXgXdc0EC+B9nLQiu15KpGB8ziwIqw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR04MB7177 Subject: [libcamera-devel] [PATCH v4 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 Reviewed-by: Kieran Bingham --- .../internal/converter/converter_v4l2_m2m.h | 18 +- .../libcamera/internal/converter/meson.build | 5 + include/libcamera/internal/meson.build | 2 + .../converter_v4l2_m2m.cpp} | 157 ++++++++++++------ 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, 127 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} (67%) 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 341af8a2..d7508805 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 67% rename from src/libcamera/pipeline/simple/converter.cpp rename to src/libcamera/converter/converter_v4l2_m2m.cpp index acaaa64c..5995d406 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,10 @@ int SimpleConverter::queueBuffers(FrameBuffer *input, return 0; } +static std::initializer_list compatibles = { + "pxp", +}; + +REGISTER_CONVERTER("v4l2_m2m", V4L2M2MConverter, compatibles) + } /* 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";