From patchwork Mon Oct 10 13:17:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xavier Roumegue X-Patchwork-Id: 17569 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 14368C0DA4 for ; Mon, 10 Oct 2022 13:18:20 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B7ABF62D68; Mon, 10 Oct 2022 15:18:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1665407899; bh=xoUHWiByL5iR0r4lJHtd8J8dPJVxQbNtI/Jche+j+PI=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=yL7dfSnIlXfBwkOGv2KJfgjDJ2BIxVWh4MXvboDrkKRwQRAHX1NLm4UVEtwD4ZtPr fIHx2pZRY7L01cC2j8KFrOdBrU2gooNICcOUQYVYJ2nLZYWByXlILLOpeVkmJwHPRV cGP7FXCF7S4r+08NBUaPKd8K4cpxVI/ySgfdFaHOnpF4cpE6dEOOVO0LeDjVxSju1p 17FDCK1CFSSvcbZXxb2jGeKK/aLCV3Eq4IHl3fQIAEAWivnrTEZo/sa5qN2DA/yol6 VZ8EsSpQJ2rW4se1dNBFpEWFBMg/iVWINpWCAIp6ohvEe83ypOrDsimq8rnO9RaqE4 E/8vgeWA+78vw== Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2058.outbound.protection.outlook.com [40.107.21.58]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D69D362D5D for ; Mon, 10 Oct 2022 15:18:17 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.b="lhTaymqe"; dkim-atps=neutral ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lah+2ZnwM91XMKChrdhmGppRjPyvXwxX66c1FLNvX+5pjlkDE3CW3TlYMzIR1w/mXq38Fdo5kaeP7HPp68tsNzc9DCNAhL1IdclbXtLEtJimiD7IlmpBDveGR7xc6CSjMVAny6PU15y5GF6nBSHP0nTBJ2wY77UgfA0EnwdQMGP/Hhtc2IedjhTMODvpN3AfHwY1Oco5SHxacDUbpMRX9nEb4Q10J1SIS397CEKdlmxaq76XFddrWVt3fup/tr+UfBfGNfq3CHoM0rE83gnH0l7a8owNErqRsS1EwMa9bCsBlLlQgr4OCsTnZsX/CtBbEg75V9v6QM/2pDYxFpILiw== 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=HLrehMPuVvkFpk5mpBrx88HpMG3uRy31HqjWXXv+Ajg=; b=EkauyfngAEPuXrxg6Ep6A4BT3luJqj8IE4I3Qy3QC3YiaorJs5yjX/w8tlTXefGTTPrx2Y9XVI71lmy+mj3mX85xqj+wOkJiUzlpG+9pSSM2e7/2k+FuTBK9MbM+ytyM5HTBX2c8K/BwgTKDY8AJ1hDT4Vyc+vcLFtztk/EOgzunjT1zkqsnLA/1c2qxn6lHSx/c10Ue+/ejG3n2rnAZU2v5gr0lOlEwdAvdNC6jOon+lkl4xRyn0PmwHyzlxcQ2xR5JrrmxNBib2XoOp9Mx73WfHWX68HsmnPT5jPJe/Ti6vcCMOwg5NX3Xnz+5tnYwOShe+uKjzUnpyV0qn1swmw== 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=HLrehMPuVvkFpk5mpBrx88HpMG3uRy31HqjWXXv+Ajg=; b=lhTaymqe8wrvZw7FQBdxGPqOvPsy/55/lnnQsSzrn2xYpfRt+DuXHcHegkZjBt1oqTI+Kl8DGhc0hHdgRGYIsvDAVMjBg8iPENdasqqRl2fyMKhG4fBfYAkmNAsjvwJFTdPvJj61wqQtoEwdvZJy09SYMR3BTdQPsHAkSroCK8Y= 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 PA4PR04MB7933.eurprd04.prod.outlook.com (2603:10a6:102:b9::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.34; Mon, 10 Oct 2022 13:18:16 +0000 Received: from PAXPR04MB8703.eurprd04.prod.outlook.com ([fe80::4f72:a35a:8c60:63f1]) by PAXPR04MB8703.eurprd04.prod.outlook.com ([fe80::4f72:a35a:8c60:63f1%6]) with mapi id 15.20.5709.015; Mon, 10 Oct 2022 13:18:15 +0000 To: jacopo@jmondi.org, laurent.pinchart@ideasonboard.com, libcamera-devel@lists.libcamera.org Date: Mon, 10 Oct 2022 15:17:44 +0200 Message-Id: <20221010131744.513261-3-xavier.roumegue@oss.nxp.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221010131744.513261-1-xavier.roumegue@oss.nxp.com> References: <20221010131744.513261-1-xavier.roumegue@oss.nxp.com> X-ClientProxiedBy: BY5PR17CA0058.namprd17.prod.outlook.com (2603:10b6:a03:167::35) 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_|PA4PR04MB7933:EE_ X-MS-Office365-Filtering-Correlation-Id: 6979081e-4abe-4dc1-58a1-08daaac1e3d8 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: OEj1nURJQ1ciwoJj2buk0B8BH+JzQ1ynPSrHOdZFlqCfYKz8jvx0fOiqzzAXQY5z4mFyB0duLroRpqbh6mSS3KHHeb9OiFcPwZbL2hm/Nslx2MlEtkE6y8mFuolRm8kcSVZJ9dLteFGaMGsSeXfRWzcLpxpWrql1q4A1B9QQ6jM0uCzC7Vb+U0U2ZCHlT/GcJCtyPx/OG0c0MRWaRx1/KuE1CWbQiRxxjyAVGFH6zLejA3VB1pJiO1VNzS56mBRln47Gt1VO5P9tJL5eGgGtkusx7kY8iIdB7JpMEk34NSciOIIcd6OdE9V1sHNOplhUzGrHHMy61aYa4fP5ieCt2kLVm7Z3R848i603FbeSjZ36x6s/4rIsVf+aQTkFCoNxpoYHKWDHGJV/rNJ6NYv5oT2NdszMlKuJTMEm6mvqiActK8I4z7lenKhMiLEbrIv/460zGPhxTjzS1RucmxRPck3FlnEZYH2EaiFmYTXIjTJmv5r2Vle5n9OpNTALdR3ZFzWYwE3RSkedN1s9XJgQSIef7dru1pRhVWigDVH9BywsVVsslL4T7Q2NscUycb17/EvgfrIZiOYGGAbSGwZTxQg86H/V3j1Ln3bQ28/WaOG0+cKOO59A4zY7h0UeeTAqvnnWj/RY2i642sz975dayHwFSo6P7m3qPyuQ9UW8qNZAmwlH+yx1bxy1eF9A9AoCd+vc7JLbC5ju/qIO4S4JuP2aKef4f9w+6RSsC98uXhShzVQf655x6PKtkoSLG9OjLMtKhrtMlNeqPom4oeR4W2FWM+Io8RdhCovopmDf3yc= 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)(376002)(396003)(366004)(136003)(39860400002)(346002)(451199015)(55236004)(66476007)(8676002)(5660300002)(66556008)(4326008)(66946007)(316002)(38350700002)(38100700002)(41300700001)(8936002)(30864003)(2906002)(6486002)(478600001)(6666004)(1076003)(186003)(6512007)(26005)(52116002)(83380400001)(6506007)(86362001)(2616005)(41533002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MvLI3/sYN0JtKUZ3k9SOmQrMoRJKMXZNe/vaZviTCsTpLWBDsbRhaByzA7fSpomsP/MiYm6rGL21ZJ6KLtjCZEpwZluOJnOCd/44vnXqEjVia8IXrNAlbY8KoCpzQ5IGX2S+stgAYrrTwT0FYsFzLYgHuH6Z0vhGDTxEq098eHeWLH542R+5M5vaYNpdnqFyVjbEuk3cnZ0D0Vfj8EenvQelH1EYow/eAneYexJrFsyTy2baM2LD/tzqBkOQKxrQClLXhGtTESPak9Gi46eVmReYESIiQqXH8s9VtUHIa141wHwzjeFQCPhDDL2bjGrEwNKEDJLqXGTEHX20Uba8BwCSZr3iaPj6raMZ/LJ//nt98+IUJbYL6SRfZIwnETEvqzrCDn2mG0JGlnsAOMgCAbGQAhR67LXrh6l7ryPy520TX4UqUNLlTpHN0AJ9vIdJxpe0VgfPxPNulrJWJ/xtflZ6RN+uvyOcu7BQgVz+tdb7TrGLqWKsshUXwU2Euv0bIFtWb16QSStqdILUG2eBm37GWmKJ6U8me3/17gcrAcQ/ACqKonAwlL6GMFhY+kZG+T+/2k+CbeLIYZPN/DrYLtdb/IlrkR7pkQM+K9zWxg8TgAAQRAHhoEWrIE0hUxqHDz1Gls736hOv23j3mVHsXbuQR3gIV2MmAQbwTn4RxbXGH6w+grYKNBYsPsqQLV3xIujEnHU0gcrwKoNg14OiFTXMyz9xzjO4vEqkJxlMBQ3/iRvbjP6dyUM7VNY7RZxSNYtDTneRyRK7+vlhP2NMr9RuBlVxHHAF+foQzSBt0V0SjT6Pn2zdUYyxHSgxLd7cNVvPVMhUQKBzNXZFoh9i1h7GnPamYskDoZTBNSpG/E87S76dHZ3Af8sJ84e8+PUsl2+6/lkG/kuS0DILDjH546irQH+WQB1fxI1h2ah3epJOP/OLsqhQjye0dELcu8M4ERqnxiZ/Y/dFH5jz8OjzyutfA0+wCJXUj+K6ag2u90CO+bcLA5q7LdMFDx2I/7zwO1B9MxTgF0OJkD/3KA7S8nUKlM5Th4M1gzUyP3hGgRHN9Fz8a9QveWA2XpV4kDaZa8EyTN4zgSYu3AvzKnbwtly/h941uRaXWTJabbR6V6P5zz9tn6iWz+b8MMfLJbCxMp+CxJ4FeY3anDesOsAwfFfRcuWp+qB9WNVG/dRgaDp7xJC84jo0UBVN+Re7Y7il9C2ygrEbVAVBeLg/UGx5J78AlnvEXXTZDfGNc4QERyFM71stpejPwSgxlKvNS3bvCzSP7QhOaoxndkpia+uEEtvlBZA7+LO6oG0iB3/80MHk8fnu43Ip4bYPxxrg5f68VaX05HgG+4BRbxAPcK/4YsdR0OWU54Eej1z2S+HfrJFvzP9MV8vMuc0M+lOuhxFRpw6KAVfiXRrzQVaYHguwY+QoztW8fdYCt282+NTVBINfcu+QpBuzcnBhXN0YRiHzKcgO3LcDEQAUTXTN8ITHrZot2zPCq2s4s8vzgRkTPnvjHLhKUlIdJ2ZjKlEA+Sw8l9aps5Cs0CftMS0GG4g1lmzIb/fh/26AInuItnBETf4escpbDMaWv4oEPoNfQydUER+PbuDUtogdxVZExJCGQA== X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6979081e-4abe-4dc1-58a1-08daaac1e3d8 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8703.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2022 13:18:15.9064 (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: nvGnXfBdWkNGg3YT2NnI/Yhc2jAsQIwRskleHvlxR8mkLWf5e6rSOok39zYG772KBYbTqGeLJs/ee6xePfZ8ug== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB7933 Subject: [libcamera-devel] [PATCH 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 \(OSS\) via libcamera-devel" From: Xavier Roumegue Reply-To: "Xavier Roumegue \(OSS\)" Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Xavier Roumegue 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} | 149 +++++++++++------- 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, 119 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} (69%) 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 69% rename from src/libcamera/pipeline/simple/converter.cpp rename to src/libcamera/converter/converter_v4l2_m2m.cpp index acaaa64c..5af054be 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,32 @@ #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) + +/** + * \class V4L2M2MConverter + * \brief V4L2 M2M based converter + * + * The V4L2 M2M converter implements the converter interface based on V4L2 M2M device. + */ /* ----------------------------------------------------------------------------- - * 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 +54,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 +68,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 +90,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 +107,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 +140,7 @@ int SimpleConverter::Stream::start() return 0; } -void SimpleConverter::Stream::stop() +void V4L2M2MConverter::Stream::stop() { m2m_->capture()->streamOff(); m2m_->output()->streamOff(); @@ -136,8 +148,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 +161,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 +178,26 @@ void SimpleConverter::Stream::outputBufferReady(FrameBuffer *buffer) } } -void SimpleConverter::Stream::captureBufferReady(FrameBuffer *buffer) +void V4L2M2MConverter::Stream::captureBufferReady(FrameBuffer *buffer) { converter_->outputBufferReady.emit(buffer); } /* ----------------------------------------------------------------------------- - * SimpleConverter + * V4L2M2MConverter */ -SimpleConverter::SimpleConverter(MediaDevice *media) +/** + * \brief Construct a V4L2M2MConverter instance + * \param[in] media The media device implementing the converter + */ +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 +205,18 @@ SimpleConverter::SimpleConverter(MediaDevice *media) } } -std::vector SimpleConverter::formats(PixelFormat input) +/** + * \copydoc libcamera::Converter::loadConfiguration + */ + +/** + * \copydoc libcamera::Converter::isValid + */ + +/** + * \copydoc libcamera::Converter::formats + */ +std::vector V4L2M2MConverter::formats(PixelFormat input) { if (!m2m_) return {}; @@ -215,13 +231,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 +253,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 +271,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 +281,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 +291,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 +301,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 +319,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 +334,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 +353,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 +365,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 +383,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 +439,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 3a9fc31f..d2f75741 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 37b3e7ac..5cc6bc6a 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";