From patchwork Sun Jun 28 00:15:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 8458 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 CD0A7C2E69 for ; Sun, 28 Jun 2020 00:15:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 66D59609E1; Sun, 28 Jun 2020 02:15:48 +0200 (CEST) Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D534A609C5 for ; Sun, 28 Jun 2020 02:15:45 +0200 (CEST) X-Halon-ID: 6e36aaf3-b8d4-11ea-86ee-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 6e36aaf3-b8d4-11ea-86ee-0050569116f7; Sun, 28 Jun 2020 02:15:11 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sun, 28 Jun 2020 02:15:20 +0200 Message-Id: <20200628001532.2685967-2-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> References: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 01/13] libcamera: ipu3: Remove unused name_ filed from IPU3Stream 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The field is never used, remove it. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/ipu3/ipu3.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 6c43169eb0915965..fba45935741e0e4e 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -109,7 +109,6 @@ public: bool active_; bool raw_; - std::string name_; ImgUDevice::ImgUOutput *device_; }; @@ -867,11 +866,8 @@ int PipelineHandlerIPU3::registerCameras() */ data->imgu_ = numCameras ? &imgu1_ : &imgu0_; data->outStream_.device_ = &data->imgu_->output_; - data->outStream_.name_ = "output"; data->vfStream_.device_ = &data->imgu_->viewfinder_; - data->vfStream_.name_ = "viewfinder"; data->rawStream_.raw_ = true; - data->rawStream_.name_ = "raw"; /* * Connect video devices' 'bufferReady' signals to their From patchwork Sun Jun 28 00:15:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 8459 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 597A1C2E69 for ; Sun, 28 Jun 2020 00:15:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0FC3B60AF4; Sun, 28 Jun 2020 02:15:49 +0200 (CEST) Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6CC90609C5 for ; Sun, 28 Jun 2020 02:15:46 +0200 (CEST) X-Halon-ID: 6e959b43-b8d4-11ea-86ee-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 6e959b43-b8d4-11ea-86ee-0050569116f7; Sun, 28 Jun 2020 02:15:11 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sun, 28 Jun 2020 02:15:21 +0200 Message-Id: <20200628001532.2685967-3-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> References: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 02/13] libcamera: ipu3: Import instead of allocate statistic buffers 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Statistics buffers are not yet used by the IPU3 pipeline, they are never queued to the video device or in any other way consumed. The kernel driver will however not allow video streaming to start if buffers are not either allocated or imported on the video device. Instead of allocating the buffers wasting memory that is never used import buffers. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/ipu3/ipu3.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index fba45935741e0e4e..405550b1302fb370 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -1135,11 +1135,13 @@ int ImgUDevice::allocateBuffers(IPU3CameraData *data, unsigned int bufferCount) } /* - * Use for the stat's internal pool the same number of buffers as for - * the input pool. + * The kernel fails to start if buffers are not either imported or + * allocated for the statisitcs video device. As statistics buffers are + * not yet used by the pipeline import buffers to save memory. + * * \todo To be revised when we'll actually use the stat node. */ - ret = stat_.dev->allocateBuffers(bufferCount, &stat_.buffers); + ret = stat_.dev->importBuffers(bufferCount); if (ret < 0) { LOG(IPU3, Error) << "Failed to allocate ImgU stat buffers"; goto error; From patchwork Sun Jun 28 00:15:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 8460 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 B353CC2E6A for ; Sun, 28 Jun 2020 00:15:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8EDC660AFD; Sun, 28 Jun 2020 02:15:50 +0200 (CEST) Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0F8E0609C8 for ; Sun, 28 Jun 2020 02:15:47 +0200 (CEST) X-Halon-ID: 6eec9ef4-b8d4-11ea-86ee-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 6eec9ef4-b8d4-11ea-86ee-0050569116f7; Sun, 28 Jun 2020 02:15:12 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sun, 28 Jun 2020 02:15:22 +0200 Message-Id: <20200628001532.2685967-4-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> References: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 03/13] libcamera: ipu3: Always import buffers for ImgU sinks 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When the IPU3 pipeline was first developed sinks of the ImgU that where not active still needed to have buffers allocated to allow streaming to start. This is no longer true, it's enough that the sinks have imported buffers to allow streaming to start. As we already need to import buffers for stream that are active we can align the two cases and always import buffers. With this there is no longer a reason to store the allocated FrameBuffers to keep them alive and the vector tracking them can be removed. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- * Changes since v1 - Add comment - Update commit message --- src/libcamera/pipeline/ipu3/ipu3.cpp | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 405550b1302fb370..f35672f4761659f4 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -49,7 +49,6 @@ public: V4L2VideoDevice *dev; unsigned int pad; std::string name; - std::vector> buffers; }; ImgUDevice() @@ -1124,9 +1123,6 @@ int ImgUDevice::configureOutput(ImgUOutput *output, */ int ImgUDevice::allocateBuffers(IPU3CameraData *data, unsigned int bufferCount) { - IPU3Stream *outStream = &data->outStream_; - IPU3Stream *vfStream = &data->vfStream_; - /* Share buffers between CIO2 output and ImgU input. */ int ret = input_->importBuffers(bufferCount); if (ret) { @@ -1148,27 +1144,19 @@ int ImgUDevice::allocateBuffers(IPU3CameraData *data, unsigned int bufferCount) } /* - * Allocate buffers for both outputs. If an output is active, prepare - * for buffer import, otherwise allocate internal buffers. Use the same - * number of buffers in either case. + * Import buffers for all outputs, regardless of whether the + * corresponding stream is active or inactive, as the driver needs + * buffers to be requested on the V4L2 devices in order to operate. */ - if (outStream->active_) - ret = output_.dev->importBuffers(bufferCount); - else - ret = output_.dev->allocateBuffers(bufferCount, - &output_.buffers); + ret = output_.dev->importBuffers(bufferCount); if (ret < 0) { - LOG(IPU3, Error) << "Failed to allocate ImgU output buffers"; + LOG(IPU3, Error) << "Failed to import ImgU output buffers"; goto error; } - if (vfStream->active_) - ret = viewfinder_.dev->importBuffers(bufferCount); - else - ret = viewfinder_.dev->allocateBuffers(bufferCount, - &viewfinder_.buffers); + ret = viewfinder_.dev->importBuffers(bufferCount); if (ret < 0) { - LOG(IPU3, Error) << "Failed to allocate ImgU viewfinder buffers"; + LOG(IPU3, Error) << "Failed to import ImgU viewfinder buffers"; goto error; } From patchwork Sun Jun 28 00:15:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 8461 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 13172C2E69 for ; Sun, 28 Jun 2020 00:15:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AE54560B00; Sun, 28 Jun 2020 02:15:50 +0200 (CEST) Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AE2F8609C8 for ; Sun, 28 Jun 2020 02:15:47 +0200 (CEST) X-Halon-ID: 6f4f62be-b8d4-11ea-86ee-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 6f4f62be-b8d4-11ea-86ee-0050569116f7; Sun, 28 Jun 2020 02:15:13 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sun, 28 Jun 2020 02:15:23 +0200 Message-Id: <20200628001532.2685967-5-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> References: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 04/13] libcamera: ipu3: Remove usage of IPU3CameraData from ImgUDevice 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The IPU3CameraData argument to allocateBuffers() and freeBuffers() is no longer used and can be removed. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/ipu3/ipu3.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index f35672f4761659f4..fd2725c7bd0c144b 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -34,8 +34,6 @@ namespace libcamera { LOG_DEFINE_CATEGORY(IPU3) -class IPU3CameraData; - class ImgUDevice { public: @@ -75,8 +73,8 @@ public: const StreamConfiguration &cfg, V4L2DeviceFormat *outputFormat); - int allocateBuffers(IPU3CameraData *data, unsigned int bufferCount); - void freeBuffers(IPU3CameraData *data); + int allocateBuffers(unsigned int bufferCount); + void freeBuffers(); int start(); int stop(); @@ -665,7 +663,7 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera) data->rawStream_.configuration().bufferCount, }); - ret = imgu->allocateBuffers(data, bufferCount); + ret = imgu->allocateBuffers(bufferCount); if (ret < 0) return ret; @@ -676,7 +674,7 @@ int PipelineHandlerIPU3::freeBuffers(Camera *camera) { IPU3CameraData *data = cameraData(camera); - data->imgu_->freeBuffers(data); + data->imgu_->freeBuffers(); return 0; } @@ -1121,7 +1119,7 @@ int ImgUDevice::configureOutput(ImgUOutput *output, /** * \brief Allocate buffers for all the ImgU video devices */ -int ImgUDevice::allocateBuffers(IPU3CameraData *data, unsigned int bufferCount) +int ImgUDevice::allocateBuffers(unsigned int bufferCount) { /* Share buffers between CIO2 output and ImgU input. */ int ret = input_->importBuffers(bufferCount); @@ -1163,7 +1161,7 @@ int ImgUDevice::allocateBuffers(IPU3CameraData *data, unsigned int bufferCount) return 0; error: - freeBuffers(data); + freeBuffers(); return ret; } @@ -1171,7 +1169,7 @@ error: /** * \brief Release buffers for all the ImgU video devices */ -void ImgUDevice::freeBuffers(IPU3CameraData *data) +void ImgUDevice::freeBuffers() { int ret; From patchwork Sun Jun 28 00:15:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 8462 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 2BB41C2E69 for ; Sun, 28 Jun 2020 00:15:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 02FD0609E1; Sun, 28 Jun 2020 02:15:54 +0200 (CEST) Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6FE1560AF6 for ; Sun, 28 Jun 2020 02:15:49 +0200 (CEST) X-Halon-ID: 6fb232ed-b8d4-11ea-86ee-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 6fb232ed-b8d4-11ea-86ee-0050569116f7; Sun, 28 Jun 2020 02:15:13 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sun, 28 Jun 2020 02:15:24 +0200 Message-Id: <20200628001532.2685967-6-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> References: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 05/13] libcamera: ipu3: imgu: Move the ImgUDevice class to separate files 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" In preparation of refactoring the IPU3 pipeline handler breakout the ImgUDevice into its own .cpp and .h file, no functional change. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- * Changes since v1 - Remove stray newline --- src/libcamera/pipeline/ipu3/imgu.cpp | 355 +++++++++++++++++++++ src/libcamera/pipeline/ipu3/imgu.h | 86 +++++ src/libcamera/pipeline/ipu3/ipu3.cpp | 404 +----------------------- src/libcamera/pipeline/ipu3/meson.build | 1 + 4 files changed, 443 insertions(+), 403 deletions(-) create mode 100644 src/libcamera/pipeline/ipu3/imgu.cpp create mode 100644 src/libcamera/pipeline/ipu3/imgu.h diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp new file mode 100644 index 0000000000000000..8965a51c5d26f8ae --- /dev/null +++ b/src/libcamera/pipeline/ipu3/imgu.cpp @@ -0,0 +1,355 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * imgu.cpp - Intel IPU3 ImgU + */ + +#include "imgu.h" + +#include + +#include +#include + +#include "libcamera/internal/log.h" +#include "libcamera/internal/media_device.h" + +namespace libcamera { + +LOG_DECLARE_CATEGORY(IPU3) + +/** + * \brief Initialize components of the ImgU instance + * \param[in] mediaDevice The ImgU instance media device + * \param[in] index The ImgU instance index + * + * Create and open the V4L2 devices and subdevices of the ImgU instance + * with \a index. + * + * In case of errors the created V4L2VideoDevice and V4L2Subdevice instances + * are destroyed at pipeline handler delete time. + * + * \return 0 on success or a negative error code otherwise + */ +int ImgUDevice::init(MediaDevice *media, unsigned int index) +{ + int ret; + + index_ = index; + name_ = "ipu3-imgu " + std::to_string(index_); + media_ = media; + + /* + * The media entities presence in the media device has been verified + * by the match() function: no need to check for newly created + * video devices and subdevice validity here. + */ + imgu_ = V4L2Subdevice::fromEntityName(media, name_); + ret = imgu_->open(); + if (ret) + return ret; + + input_ = V4L2VideoDevice::fromEntityName(media, name_ + " input"); + ret = input_->open(); + if (ret) + return ret; + + output_.dev = V4L2VideoDevice::fromEntityName(media, name_ + " output"); + ret = output_.dev->open(); + if (ret) + return ret; + + output_.pad = PAD_OUTPUT; + output_.name = "output"; + + viewfinder_.dev = V4L2VideoDevice::fromEntityName(media, + name_ + " viewfinder"); + ret = viewfinder_.dev->open(); + if (ret) + return ret; + + viewfinder_.pad = PAD_VF; + viewfinder_.name = "viewfinder"; + + stat_.dev = V4L2VideoDevice::fromEntityName(media, name_ + " 3a stat"); + ret = stat_.dev->open(); + if (ret) + return ret; + + stat_.pad = PAD_STAT; + stat_.name = "stat"; + + return 0; +} + +/** + * \brief Configure the ImgU unit input + * \param[in] size The ImgU input frame size + * \param[in] inputFormat The format to be applied to ImgU input + * \return 0 on success or a negative error code otherwise + */ +int ImgUDevice::configureInput(const Size &size, + V4L2DeviceFormat *inputFormat) +{ + /* Configure the ImgU input video device with the requested sizes. */ + int ret = input_->setFormat(inputFormat); + if (ret) + return ret; + + LOG(IPU3, Debug) << "ImgU input format = " << inputFormat->toString(); + + /* + * \todo The IPU3 driver implementation shall be changed to use the + * input sizes as 'ImgU Input' subdevice sizes, and use the desired + * GDC output sizes to configure the crop/compose rectangles. + * + * The current IPU3 driver implementation uses GDC sizes as the + * 'ImgU Input' subdevice sizes, and the input video device sizes + * to configure the crop/compose rectangles, contradicting the + * V4L2 specification. + */ + Rectangle rect = { + .x = 0, + .y = 0, + .width = inputFormat->size.width, + .height = inputFormat->size.height, + }; + ret = imgu_->setSelection(PAD_INPUT, V4L2_SEL_TGT_CROP, &rect); + if (ret) + return ret; + + ret = imgu_->setSelection(PAD_INPUT, V4L2_SEL_TGT_COMPOSE, &rect); + if (ret) + return ret; + + LOG(IPU3, Debug) << "ImgU input feeder and BDS rectangle = " + << rect.toString(); + + V4L2SubdeviceFormat imguFormat = {}; + imguFormat.mbus_code = MEDIA_BUS_FMT_FIXED; + imguFormat.size = size; + + ret = imgu_->setFormat(PAD_INPUT, &imguFormat); + if (ret) + return ret; + + LOG(IPU3, Debug) << "ImgU GDC format = " << imguFormat.toString(); + + return 0; +} + +/** + * \brief Configure the ImgU unit \a id video output + * \param[in] output The ImgU output device to configure + * \param[in] cfg The requested configuration + * \return 0 on success or a negative error code otherwise + */ +int ImgUDevice::configureOutput(ImgUOutput *output, + const StreamConfiguration &cfg, + V4L2DeviceFormat *outputFormat) +{ + V4L2VideoDevice *dev = output->dev; + unsigned int pad = output->pad; + + V4L2SubdeviceFormat imguFormat = {}; + imguFormat.mbus_code = MEDIA_BUS_FMT_FIXED; + imguFormat.size = cfg.size; + + int ret = imgu_->setFormat(pad, &imguFormat); + if (ret) + return ret; + + /* No need to apply format to the stat node. */ + if (output == &stat_) + return 0; + + *outputFormat = {}; + outputFormat->fourcc = dev->toV4L2PixelFormat(formats::NV12); + outputFormat->size = cfg.size; + outputFormat->planesCount = 2; + + ret = dev->setFormat(outputFormat); + if (ret) + return ret; + + LOG(IPU3, Debug) << "ImgU " << output->name << " format = " + << outputFormat->toString(); + + return 0; +} + +/** + * \brief Allocate buffers for all the ImgU video devices + */ +int ImgUDevice::allocateBuffers(unsigned int bufferCount) +{ + /* Share buffers between CIO2 output and ImgU input. */ + int ret = input_->importBuffers(bufferCount); + if (ret) { + LOG(IPU3, Error) << "Failed to import ImgU input buffers"; + return ret; + } + + /* + * The kernel fails to start if buffers are not either imported or + * allocated for the statisitcs video device. As statistics buffers are + * not yet used by the pipeline import buffers to save memory. + * + * \todo To be revised when we'll actually use the stat node. + */ + ret = stat_.dev->importBuffers(bufferCount); + if (ret < 0) { + LOG(IPU3, Error) << "Failed to allocate ImgU stat buffers"; + goto error; + } + + /* + * Import buffers for all outputs, regardless of whether the + * corresponding stream is active or inactive, as the driver needs + * buffers to be requested on the V4L2 devices in order to operate. + */ + ret = output_.dev->importBuffers(bufferCount); + if (ret < 0) { + LOG(IPU3, Error) << "Failed to import ImgU output buffers"; + goto error; + } + + ret = viewfinder_.dev->importBuffers(bufferCount); + if (ret < 0) { + LOG(IPU3, Error) << "Failed to import ImgU viewfinder buffers"; + goto error; + } + + return 0; + +error: + freeBuffers(); + + return ret; +} + +/** + * \brief Release buffers for all the ImgU video devices + */ +void ImgUDevice::freeBuffers() +{ + int ret; + + ret = output_.dev->releaseBuffers(); + if (ret) + LOG(IPU3, Error) << "Failed to release ImgU output buffers"; + + ret = stat_.dev->releaseBuffers(); + if (ret) + LOG(IPU3, Error) << "Failed to release ImgU stat buffers"; + + ret = viewfinder_.dev->releaseBuffers(); + if (ret) + LOG(IPU3, Error) << "Failed to release ImgU viewfinder buffers"; + + ret = input_->releaseBuffers(); + if (ret) + LOG(IPU3, Error) << "Failed to release ImgU input buffers"; +} + +int ImgUDevice::start() +{ + int ret; + + /* Start the ImgU video devices. */ + ret = output_.dev->streamOn(); + if (ret) { + LOG(IPU3, Error) << "Failed to start ImgU output"; + return ret; + } + + ret = viewfinder_.dev->streamOn(); + if (ret) { + LOG(IPU3, Error) << "Failed to start ImgU viewfinder"; + return ret; + } + + ret = stat_.dev->streamOn(); + if (ret) { + LOG(IPU3, Error) << "Failed to start ImgU stat"; + return ret; + } + + ret = input_->streamOn(); + if (ret) { + LOG(IPU3, Error) << "Failed to start ImgU input"; + return ret; + } + + return 0; +} + +int ImgUDevice::stop() +{ + int ret; + + ret = output_.dev->streamOff(); + ret |= viewfinder_.dev->streamOff(); + ret |= stat_.dev->streamOff(); + ret |= input_->streamOff(); + + return ret; +} + +/** + * \brief Enable or disable a single link on the ImgU instance + * + * This method assumes the media device associated with the ImgU instance + * is open. + * + * \return 0 on success or a negative error code otherwise + */ +int ImgUDevice::linkSetup(const std::string &source, unsigned int sourcePad, + const std::string &sink, unsigned int sinkPad, + bool enable) +{ + MediaLink *link = media_->link(source, sourcePad, sink, sinkPad); + if (!link) { + LOG(IPU3, Error) + << "Failed to get link: '" << source << "':" + << sourcePad << " -> '" << sink << "':" << sinkPad; + return -ENODEV; + } + + return link->setEnabled(enable); +} + +/** + * \brief Enable or disable all media links in the ImgU instance to prepare + * for capture operations + * + * \todo This method will probably be removed or changed once links will be + * enabled or disabled selectively. + * + * \return 0 on success or a negative error code otherwise + */ +int ImgUDevice::enableLinks(bool enable) +{ + std::string viewfinderName = name_ + " viewfinder"; + std::string outputName = name_ + " output"; + std::string statName = name_ + " 3a stat"; + std::string inputName = name_ + " input"; + int ret; + + ret = linkSetup(inputName, 0, name_, PAD_INPUT, enable); + if (ret) + return ret; + + ret = linkSetup(name_, PAD_OUTPUT, outputName, 0, enable); + if (ret) + return ret; + + ret = linkSetup(name_, PAD_VF, viewfinderName, 0, enable); + if (ret) + return ret; + + return linkSetup(name_, PAD_STAT, statName, 0, enable); +} + +} /* namespace libcamera */ diff --git a/src/libcamera/pipeline/ipu3/imgu.h b/src/libcamera/pipeline/ipu3/imgu.h new file mode 100644 index 0000000000000000..9bb1b88e2ca8ea2d --- /dev/null +++ b/src/libcamera/pipeline/ipu3/imgu.h @@ -0,0 +1,86 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * imgu.h - Intel IPU3 ImgU + */ +#ifndef __LIBCAMERA_PIPELINE_IPU3_IMGU_H__ +#define __LIBCAMERA_PIPELINE_IPU3_IMGU_H__ + +#include +#include +#include + +#include "libcamera/internal/v4l2_subdevice.h" +#include "libcamera/internal/v4l2_videodevice.h" + +namespace libcamera { + +class FrameBuffer; +class MediaDevice; +struct Size; +struct StreamConfiguration; + +class ImgUDevice +{ +public: + static constexpr unsigned int PAD_INPUT = 0; + static constexpr unsigned int PAD_OUTPUT = 2; + static constexpr unsigned int PAD_VF = 3; + static constexpr unsigned int PAD_STAT = 4; + + /* ImgU output descriptor: group data specific to an ImgU output. */ + struct ImgUOutput { + V4L2VideoDevice *dev; + unsigned int pad; + std::string name; + }; + + ImgUDevice() + : imgu_(nullptr), input_(nullptr) + { + output_.dev = nullptr; + viewfinder_.dev = nullptr; + stat_.dev = nullptr; + } + + ~ImgUDevice() + { + delete imgu_; + delete input_; + delete output_.dev; + delete viewfinder_.dev; + delete stat_.dev; + } + + int init(MediaDevice *media, unsigned int index); + int configureInput(const Size &size, V4L2DeviceFormat *inputFormat); + int configureOutput(ImgUOutput *output, const StreamConfiguration &cfg, + V4L2DeviceFormat *outputFormat); + + int allocateBuffers(unsigned int bufferCount); + void freeBuffers(); + + int start(); + int stop(); + + int linkSetup(const std::string &source, unsigned int sourcePad, + const std::string &sink, unsigned int sinkPad, + bool enable); + int enableLinks(bool enable); + + unsigned int index_; + std::string name_; + MediaDevice *media_; + + V4L2Subdevice *imgu_; + V4L2VideoDevice *input_; + ImgUOutput output_; + ImgUOutput viewfinder_; + ImgUOutput stat_; + /* \todo Add param video device for 3A tuning */ +}; + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_PIPELINE_IPU3_IMGU_H__ */ diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index fd2725c7bd0c144b..b41a789e8dc2a7b2 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -11,8 +11,6 @@ #include #include -#include - #include #include #include @@ -25,77 +23,14 @@ #include "libcamera/internal/pipeline_handler.h" #include "libcamera/internal/utils.h" #include "libcamera/internal/v4l2_controls.h" -#include "libcamera/internal/v4l2_subdevice.h" -#include "libcamera/internal/v4l2_videodevice.h" #include "cio2.h" +#include "imgu.h" namespace libcamera { LOG_DEFINE_CATEGORY(IPU3) -class ImgUDevice -{ -public: - static constexpr unsigned int PAD_INPUT = 0; - static constexpr unsigned int PAD_OUTPUT = 2; - static constexpr unsigned int PAD_VF = 3; - static constexpr unsigned int PAD_STAT = 4; - - /* ImgU output descriptor: group data specific to an ImgU output. */ - struct ImgUOutput { - V4L2VideoDevice *dev; - unsigned int pad; - std::string name; - }; - - ImgUDevice() - : imgu_(nullptr), input_(nullptr) - { - output_.dev = nullptr; - viewfinder_.dev = nullptr; - stat_.dev = nullptr; - } - - ~ImgUDevice() - { - delete imgu_; - delete input_; - delete output_.dev; - delete viewfinder_.dev; - delete stat_.dev; - } - - int init(MediaDevice *media, unsigned int index); - int configureInput(const Size &size, - V4L2DeviceFormat *inputFormat); - int configureOutput(ImgUOutput *output, - const StreamConfiguration &cfg, - V4L2DeviceFormat *outputFormat); - - int allocateBuffers(unsigned int bufferCount); - void freeBuffers(); - - int start(); - int stop(); - - int linkSetup(const std::string &source, unsigned int sourcePad, - const std::string &sink, unsigned int sinkPad, - bool enable); - int enableLinks(bool enable); - - unsigned int index_; - std::string name_; - MediaDevice *media_; - - V4L2Subdevice *imgu_; - V4L2VideoDevice *input_; - ImgUOutput output_; - ImgUOutput viewfinder_; - ImgUOutput stat_; - /* \todo Add param video device for 3A tuning */ -}; - class IPU3Stream : public Stream { public: @@ -952,343 +887,6 @@ void IPU3CameraData::cio2BufferReady(FrameBuffer *buffer) imgu_->input_->queueBuffer(buffer); } -/* ----------------------------------------------------------------------------- - * ImgU Device - */ - -/** - * \brief Initialize components of the ImgU instance - * \param[in] mediaDevice The ImgU instance media device - * \param[in] index The ImgU instance index - * - * Create and open the V4L2 devices and subdevices of the ImgU instance - * with \a index. - * - * In case of errors the created V4L2VideoDevice and V4L2Subdevice instances - * are destroyed at pipeline handler delete time. - * - * \return 0 on success or a negative error code otherwise - */ -int ImgUDevice::init(MediaDevice *media, unsigned int index) -{ - int ret; - - index_ = index; - name_ = "ipu3-imgu " + std::to_string(index_); - media_ = media; - - /* - * The media entities presence in the media device has been verified - * by the match() function: no need to check for newly created - * video devices and subdevice validity here. - */ - imgu_ = V4L2Subdevice::fromEntityName(media, name_); - ret = imgu_->open(); - if (ret) - return ret; - - input_ = V4L2VideoDevice::fromEntityName(media, name_ + " input"); - ret = input_->open(); - if (ret) - return ret; - - output_.dev = V4L2VideoDevice::fromEntityName(media, name_ + " output"); - ret = output_.dev->open(); - if (ret) - return ret; - - output_.pad = PAD_OUTPUT; - output_.name = "output"; - - viewfinder_.dev = V4L2VideoDevice::fromEntityName(media, - name_ + " viewfinder"); - ret = viewfinder_.dev->open(); - if (ret) - return ret; - - viewfinder_.pad = PAD_VF; - viewfinder_.name = "viewfinder"; - - stat_.dev = V4L2VideoDevice::fromEntityName(media, name_ + " 3a stat"); - ret = stat_.dev->open(); - if (ret) - return ret; - - stat_.pad = PAD_STAT; - stat_.name = "stat"; - - return 0; -} - -/** - * \brief Configure the ImgU unit input - * \param[in] size The ImgU input frame size - * \param[in] inputFormat The format to be applied to ImgU input - * \return 0 on success or a negative error code otherwise - */ -int ImgUDevice::configureInput(const Size &size, - V4L2DeviceFormat *inputFormat) -{ - /* Configure the ImgU input video device with the requested sizes. */ - int ret = input_->setFormat(inputFormat); - if (ret) - return ret; - - LOG(IPU3, Debug) << "ImgU input format = " << inputFormat->toString(); - - /* - * \todo The IPU3 driver implementation shall be changed to use the - * input sizes as 'ImgU Input' subdevice sizes, and use the desired - * GDC output sizes to configure the crop/compose rectangles. - * - * The current IPU3 driver implementation uses GDC sizes as the - * 'ImgU Input' subdevice sizes, and the input video device sizes - * to configure the crop/compose rectangles, contradicting the - * V4L2 specification. - */ - Rectangle rect = { - .x = 0, - .y = 0, - .width = inputFormat->size.width, - .height = inputFormat->size.height, - }; - ret = imgu_->setSelection(PAD_INPUT, V4L2_SEL_TGT_CROP, &rect); - if (ret) - return ret; - - ret = imgu_->setSelection(PAD_INPUT, V4L2_SEL_TGT_COMPOSE, &rect); - if (ret) - return ret; - - LOG(IPU3, Debug) << "ImgU input feeder and BDS rectangle = " - << rect.toString(); - - V4L2SubdeviceFormat imguFormat = {}; - imguFormat.mbus_code = MEDIA_BUS_FMT_FIXED; - imguFormat.size = size; - - ret = imgu_->setFormat(PAD_INPUT, &imguFormat); - if (ret) - return ret; - - LOG(IPU3, Debug) << "ImgU GDC format = " << imguFormat.toString(); - - return 0; -} - -/** - * \brief Configure the ImgU unit \a id video output - * \param[in] output The ImgU output device to configure - * \param[in] cfg The requested configuration - * \return 0 on success or a negative error code otherwise - */ -int ImgUDevice::configureOutput(ImgUOutput *output, - const StreamConfiguration &cfg, - V4L2DeviceFormat *outputFormat) -{ - V4L2VideoDevice *dev = output->dev; - unsigned int pad = output->pad; - - V4L2SubdeviceFormat imguFormat = {}; - imguFormat.mbus_code = MEDIA_BUS_FMT_FIXED; - imguFormat.size = cfg.size; - - int ret = imgu_->setFormat(pad, &imguFormat); - if (ret) - return ret; - - /* No need to apply format to the stat node. */ - if (output == &stat_) - return 0; - - *outputFormat = {}; - outputFormat->fourcc = dev->toV4L2PixelFormat(formats::NV12); - outputFormat->size = cfg.size; - outputFormat->planesCount = 2; - - ret = dev->setFormat(outputFormat); - if (ret) - return ret; - - LOG(IPU3, Debug) << "ImgU " << output->name << " format = " - << outputFormat->toString(); - - return 0; -} - -/** - * \brief Allocate buffers for all the ImgU video devices - */ -int ImgUDevice::allocateBuffers(unsigned int bufferCount) -{ - /* Share buffers between CIO2 output and ImgU input. */ - int ret = input_->importBuffers(bufferCount); - if (ret) { - LOG(IPU3, Error) << "Failed to import ImgU input buffers"; - return ret; - } - - /* - * The kernel fails to start if buffers are not either imported or - * allocated for the statisitcs video device. As statistics buffers are - * not yet used by the pipeline import buffers to save memory. - * - * \todo To be revised when we'll actually use the stat node. - */ - ret = stat_.dev->importBuffers(bufferCount); - if (ret < 0) { - LOG(IPU3, Error) << "Failed to allocate ImgU stat buffers"; - goto error; - } - - /* - * Import buffers for all outputs, regardless of whether the - * corresponding stream is active or inactive, as the driver needs - * buffers to be requested on the V4L2 devices in order to operate. - */ - ret = output_.dev->importBuffers(bufferCount); - if (ret < 0) { - LOG(IPU3, Error) << "Failed to import ImgU output buffers"; - goto error; - } - - ret = viewfinder_.dev->importBuffers(bufferCount); - if (ret < 0) { - LOG(IPU3, Error) << "Failed to import ImgU viewfinder buffers"; - goto error; - } - - return 0; - -error: - freeBuffers(); - - return ret; -} - -/** - * \brief Release buffers for all the ImgU video devices - */ -void ImgUDevice::freeBuffers() -{ - int ret; - - ret = output_.dev->releaseBuffers(); - if (ret) - LOG(IPU3, Error) << "Failed to release ImgU output buffers"; - - ret = stat_.dev->releaseBuffers(); - if (ret) - LOG(IPU3, Error) << "Failed to release ImgU stat buffers"; - - ret = viewfinder_.dev->releaseBuffers(); - if (ret) - LOG(IPU3, Error) << "Failed to release ImgU viewfinder buffers"; - - ret = input_->releaseBuffers(); - if (ret) - LOG(IPU3, Error) << "Failed to release ImgU input buffers"; -} - -int ImgUDevice::start() -{ - int ret; - - /* Start the ImgU video devices. */ - ret = output_.dev->streamOn(); - if (ret) { - LOG(IPU3, Error) << "Failed to start ImgU output"; - return ret; - } - - ret = viewfinder_.dev->streamOn(); - if (ret) { - LOG(IPU3, Error) << "Failed to start ImgU viewfinder"; - return ret; - } - - ret = stat_.dev->streamOn(); - if (ret) { - LOG(IPU3, Error) << "Failed to start ImgU stat"; - return ret; - } - - ret = input_->streamOn(); - if (ret) { - LOG(IPU3, Error) << "Failed to start ImgU input"; - return ret; - } - - return 0; -} - -int ImgUDevice::stop() -{ - int ret; - - ret = output_.dev->streamOff(); - ret |= viewfinder_.dev->streamOff(); - ret |= stat_.dev->streamOff(); - ret |= input_->streamOff(); - - return ret; -} - -/** - * \brief Enable or disable a single link on the ImgU instance - * - * This method assumes the media device associated with the ImgU instance - * is open. - * - * \return 0 on success or a negative error code otherwise - */ -int ImgUDevice::linkSetup(const std::string &source, unsigned int sourcePad, - const std::string &sink, unsigned int sinkPad, - bool enable) -{ - MediaLink *link = media_->link(source, sourcePad, sink, sinkPad); - if (!link) { - LOG(IPU3, Error) - << "Failed to get link: '" << source << "':" - << sourcePad << " -> '" << sink << "':" << sinkPad; - return -ENODEV; - } - - return link->setEnabled(enable); -} - -/** - * \brief Enable or disable all media links in the ImgU instance to prepare - * for capture operations - * - * \todo This method will probably be removed or changed once links will be - * enabled or disabled selectively. - * - * \return 0 on success or a negative error code otherwise - */ -int ImgUDevice::enableLinks(bool enable) -{ - std::string viewfinderName = name_ + " viewfinder"; - std::string outputName = name_ + " output"; - std::string statName = name_ + " 3a stat"; - std::string inputName = name_ + " input"; - int ret; - - ret = linkSetup(inputName, 0, name_, PAD_INPUT, enable); - if (ret) - return ret; - - ret = linkSetup(name_, PAD_OUTPUT, outputName, 0, enable); - if (ret) - return ret; - - ret = linkSetup(name_, PAD_VF, viewfinderName, 0, enable); - if (ret) - return ret; - - return linkSetup(name_, PAD_STAT, statName, 0, enable); -} - REGISTER_PIPELINE_HANDLER(PipelineHandlerIPU3); } /* namespace libcamera */ diff --git a/src/libcamera/pipeline/ipu3/meson.build b/src/libcamera/pipeline/ipu3/meson.build index b2602d30123f908d..d60e07ae6ccac2bc 100644 --- a/src/libcamera/pipeline/ipu3/meson.build +++ b/src/libcamera/pipeline/ipu3/meson.build @@ -2,5 +2,6 @@ libcamera_sources += files([ 'cio2.cpp', + 'imgu.cpp', 'ipu3.cpp', ]) From patchwork Sun Jun 28 00:15:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 8463 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 80586C2E6A for ; Sun, 28 Jun 2020 00:15:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4985260B05; Sun, 28 Jun 2020 02:15:54 +0200 (CEST) Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 37406609D6 for ; Sun, 28 Jun 2020 02:15:50 +0200 (CEST) X-Halon-ID: 70b1f390-b8d4-11ea-86ee-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 70b1f390-b8d4-11ea-86ee-0050569116f7; Sun, 28 Jun 2020 02:15:15 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sun, 28 Jun 2020 02:15:25 +0200 Message-Id: <20200628001532.2685967-7-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> References: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 06/13] libcamera: ipu3: imgu: Do not cache index 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The numerical index of the imgu is only used to create its name in string form. There is no need to keep it around after that, remove it. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/ipu3/imgu.cpp | 3 +-- src/libcamera/pipeline/ipu3/imgu.h | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp index 8965a51c5d26f8ae..46d56a5d18dc3687 100644 --- a/src/libcamera/pipeline/ipu3/imgu.cpp +++ b/src/libcamera/pipeline/ipu3/imgu.cpp @@ -36,8 +36,7 @@ int ImgUDevice::init(MediaDevice *media, unsigned int index) { int ret; - index_ = index; - name_ = "ipu3-imgu " + std::to_string(index_); + name_ = "ipu3-imgu " + std::to_string(index); media_ = media; /* diff --git a/src/libcamera/pipeline/ipu3/imgu.h b/src/libcamera/pipeline/ipu3/imgu.h index 9bb1b88e2ca8ea2d..ad5aabf134e2099d 100644 --- a/src/libcamera/pipeline/ipu3/imgu.h +++ b/src/libcamera/pipeline/ipu3/imgu.h @@ -69,7 +69,6 @@ public: bool enable); int enableLinks(bool enable); - unsigned int index_; std::string name_; MediaDevice *media_; From patchwork Sun Jun 28 00:15:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 8464 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 01A39C2E69 for ; Sun, 28 Jun 2020 00:15:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id CE98260AF9; Sun, 28 Jun 2020 02:15:56 +0200 (CEST) Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 47AD2609DD for ; Sun, 28 Jun 2020 02:15:51 +0200 (CEST) X-Halon-ID: 71350f88-b8d4-11ea-86ee-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 71350f88-b8d4-11ea-86ee-0050569116f7; Sun, 28 Jun 2020 02:15:16 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sun, 28 Jun 2020 02:15:26 +0200 Message-Id: <20200628001532.2685967-8-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> References: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 07/13] libcamera: ipu3: imgu: Mark things that are internal as private 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Mark all variables and functions that are only used internally as private. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/ipu3/imgu.h | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/imgu.h b/src/libcamera/pipeline/ipu3/imgu.h index ad5aabf134e2099d..b6b08b4fef2d3a9d 100644 --- a/src/libcamera/pipeline/ipu3/imgu.h +++ b/src/libcamera/pipeline/ipu3/imgu.h @@ -24,11 +24,6 @@ struct StreamConfiguration; class ImgUDevice { public: - static constexpr unsigned int PAD_INPUT = 0; - static constexpr unsigned int PAD_OUTPUT = 2; - static constexpr unsigned int PAD_VF = 3; - static constexpr unsigned int PAD_STAT = 4; - /* ImgU output descriptor: group data specific to an ImgU output. */ struct ImgUOutput { V4L2VideoDevice *dev; @@ -64,20 +59,27 @@ public: int start(); int stop(); - int linkSetup(const std::string &source, unsigned int sourcePad, - const std::string &sink, unsigned int sinkPad, - bool enable); int enableLinks(bool enable); - std::string name_; - MediaDevice *media_; - V4L2Subdevice *imgu_; V4L2VideoDevice *input_; ImgUOutput output_; ImgUOutput viewfinder_; ImgUOutput stat_; /* \todo Add param video device for 3A tuning */ + +private: + static constexpr unsigned int PAD_INPUT = 0; + static constexpr unsigned int PAD_OUTPUT = 2; + static constexpr unsigned int PAD_VF = 3; + static constexpr unsigned int PAD_STAT = 4; + + int linkSetup(const std::string &source, unsigned int sourcePad, + const std::string &sink, unsigned int sinkPad, + bool enable); + + std::string name_; + MediaDevice *media_; }; } /* namespace libcamera */ From patchwork Sun Jun 28 00:15:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 8465 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 29076C2E6A for ; Sun, 28 Jun 2020 00:15:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0208960BDC; Sun, 28 Jun 2020 02:15:57 +0200 (CEST) Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1EA1D609C8 for ; Sun, 28 Jun 2020 02:15:52 +0200 (CEST) X-Halon-ID: 71d348a9-b8d4-11ea-86ee-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 71d348a9-b8d4-11ea-86ee-0050569116f7; Sun, 28 Jun 2020 02:15:17 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sun, 28 Jun 2020 02:15:27 +0200 Message-Id: <20200628001532.2685967-9-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> References: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 08/13] libcamera: ipu3: imgu: Use specific functions to configure each sink 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" When the IPU3 pipeline only provided streams to applications that came from the ImgU it made sense to have a generic function to configure all the different outputs. With the addition of the RAW stream this begins to be cumbersome to read and make sense of in the PipelineHandlerIPU3 code. Replace the generic function that takes a specific argument for which sink to configure with a specific function for each sink. This makes the code easier to follow as it's always clear which of the ImgU sinks are being configured without knowing the content of a generically named variable. It also paves way for future improvements. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- * Changes since v1 - s/sens/sense/ - Retain comment for configureVideoDevice() - Inline the accessors for configureVideoDevice() in the .h file - Update comment in PipelineHandlerIPU3::configure() --- src/libcamera/pipeline/ipu3/imgu.cpp | 20 +++++++-------- src/libcamera/pipeline/ipu3/imgu.h | 28 ++++++++++++++++++-- src/libcamera/pipeline/ipu3/ipu3.cpp | 38 +++++++++++++++------------- 3 files changed, 57 insertions(+), 29 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp index 46d56a5d18dc3687..981239cba975f92e 100644 --- a/src/libcamera/pipeline/ipu3/imgu.cpp +++ b/src/libcamera/pipeline/ipu3/imgu.cpp @@ -139,18 +139,17 @@ int ImgUDevice::configureInput(const Size &size, } /** - * \brief Configure the ImgU unit \a id video output - * \param[in] output The ImgU output device to configure + * \brief Configure a video device on the ImgU + * \param[in] dev The video device to configure + * \param[in] pad The pad of the ImgU subdevice * \param[in] cfg The requested configuration + * \param[out] outputFormat The format set on the video device * \return 0 on success or a negative error code otherwise */ -int ImgUDevice::configureOutput(ImgUOutput *output, - const StreamConfiguration &cfg, - V4L2DeviceFormat *outputFormat) +int ImgUDevice::configureVideoDevice(V4L2VideoDevice *dev, unsigned int pad, + const StreamConfiguration &cfg, + V4L2DeviceFormat *outputFormat) { - V4L2VideoDevice *dev = output->dev; - unsigned int pad = output->pad; - V4L2SubdeviceFormat imguFormat = {}; imguFormat.mbus_code = MEDIA_BUS_FMT_FIXED; imguFormat.size = cfg.size; @@ -160,7 +159,7 @@ int ImgUDevice::configureOutput(ImgUOutput *output, return ret; /* No need to apply format to the stat node. */ - if (output == &stat_) + if (dev == stat_.dev) return 0; *outputFormat = {}; @@ -172,7 +171,8 @@ int ImgUDevice::configureOutput(ImgUOutput *output, if (ret) return ret; - LOG(IPU3, Debug) << "ImgU " << output->name << " format = " + const char *name = dev == output_.dev ? "output" : "viewfinder"; + LOG(IPU3, Debug) << "ImgU " << name << " format = " << outputFormat->toString(); return 0; diff --git a/src/libcamera/pipeline/ipu3/imgu.h b/src/libcamera/pipeline/ipu3/imgu.h index b6b08b4fef2d3a9d..5f1dbfd8f45f7924 100644 --- a/src/libcamera/pipeline/ipu3/imgu.h +++ b/src/libcamera/pipeline/ipu3/imgu.h @@ -49,9 +49,29 @@ public: } int init(MediaDevice *media, unsigned int index); + int configureInput(const Size &size, V4L2DeviceFormat *inputFormat); - int configureOutput(ImgUOutput *output, const StreamConfiguration &cfg, - V4L2DeviceFormat *outputFormat); + + int configureOutput(const StreamConfiguration &cfg, + V4L2DeviceFormat *outputFormat) + { + return configureVideoDevice(output_.dev, PAD_OUTPUT, cfg, + outputFormat); + } + + int configureViewfinder(const StreamConfiguration &cfg, + V4L2DeviceFormat *outputFormat) + { + return configureVideoDevice(viewfinder_.dev, PAD_VF, cfg, + outputFormat); + } + + int configureStat(const StreamConfiguration &cfg, + V4L2DeviceFormat *outputFormat) + { + return configureVideoDevice(stat_.dev, PAD_STAT, cfg, + outputFormat); + } int allocateBuffers(unsigned int bufferCount); void freeBuffers(); @@ -78,6 +98,10 @@ private: const std::string &sink, unsigned int sinkPad, bool enable); + int configureVideoDevice(V4L2VideoDevice *dev, unsigned int pad, + const StreamConfiguration &cfg, + V4L2DeviceFormat *outputFormat); + std::string name_; MediaDevice *media_; }; diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index b41a789e8dc2a7b2..e817f842f1216a7f 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -504,19 +504,25 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) stream->active_ = true; cfg.setStream(stream); - /* - * The RAW still capture stream just copies buffers from the - * internal queue and doesn't need any specific configuration. - */ - if (stream->raw_) { + if (stream == outStream) { + ret = imgu->configureOutput(cfg, &outputFormat); + if (ret) + return ret; + + cfg.stride = outputFormat.planes[0].bpl; + } else if (stream == vfStream) { + ret = imgu->configureViewfinder(cfg, &outputFormat); + if (ret) + return ret; + + cfg.stride = outputFormat.planes[0].bpl; + } else { + /* + * The RAW still capture stream only uses en externel + * for the already configured CIO2 sink and doesn't need + * any specific configuration of the ImgU. + */ cfg.stride = cio2Format.planes[0].bpl; - } else { - ret = imgu->configureOutput(stream->device_, cfg, - &outputFormat); - if (ret) - return ret; - - cfg.stride = outputFormat.planes[0].bpl; } } @@ -526,15 +532,13 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) * be at least one active stream in the configuration request). */ if (!outStream->active_) { - ret = imgu->configureOutput(outStream->device_, config->at(0), - &outputFormat); + ret = imgu->configureOutput(config->at(0), &outputFormat); if (ret) return ret; } if (!vfStream->active_) { - ret = imgu->configureOutput(vfStream->device_, config->at(0), - &outputFormat); + ret = imgu->configureViewfinder(config->at(0), &outputFormat); if (ret) return ret; } @@ -546,7 +550,7 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) StreamConfiguration statCfg = {}; statCfg.size = cio2Format.size; - ret = imgu->configureOutput(&imgu->stat_, statCfg, &outputFormat); + ret = imgu->configureStat(statCfg, &outputFormat); if (ret) return ret; From patchwork Sun Jun 28 00:15:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 8466 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 A1D09C2E69 for ; Sun, 28 Jun 2020 00:15:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 66B7B60AF5; Sun, 28 Jun 2020 02:15:57 +0200 (CEST) Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D4018609E1 for ; Sun, 28 Jun 2020 02:15:52 +0200 (CEST) X-Halon-ID: 724f18b7-b8d4-11ea-86ee-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 724f18b7-b8d4-11ea-86ee-0050569116f7; Sun, 28 Jun 2020 02:15:18 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sun, 28 Jun 2020 02:15:28 +0200 Message-Id: <20200628001532.2685967-10-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> References: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 09/13] libcamera: ipu3: Do not duplicate data in IPU3Stream 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Do not keep the duplicated ImgUDevice::ImgUOutput information in both the stream and camera data classes. Remove it from the stream and only access it from the camera data class. Which stream is which can instead be checked by comparing it to the known streams in camera data. This match how streams are checked in other parts of the code making the pipeline more coherent. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- * Changes since v1 - s/driver/pipeline/ in commit message. - Reorder if ; if else ; else statement in PipelineHandlerIPU3::queueRequestDevice() --- src/libcamera/pipeline/ipu3/ipu3.cpp | 32 ++++++++++++++++------------ 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index e817f842f1216a7f..c1520ec40fe7b57c 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -35,13 +35,11 @@ class IPU3Stream : public Stream { public: IPU3Stream() - : active_(false), raw_(false), device_(nullptr) + : active_(false) { } bool active_; - bool raw_; - ImgUDevice::ImgUOutput *device_; }; class IPU3CameraData : public CameraData @@ -276,7 +274,7 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate() const StreamConfiguration oldCfg = cfg; const IPU3Stream *stream = streams_[i]; - if (stream->raw_) { + if (stream == &data_->rawStream_) { cfg = cio2Configuration_; } else { bool scale = stream == &data_->vfStream_; @@ -572,13 +570,16 @@ int PipelineHandlerIPU3::exportFrameBuffers(Camera *camera, Stream *stream, std::vector> *buffers) { IPU3CameraData *data = cameraData(camera); - IPU3Stream *ipu3stream = static_cast(stream); unsigned int count = stream->configuration().bufferCount; - if (ipu3stream->raw_) + if (stream == &data->outStream_) + return data->imgu_->output_.dev->exportBuffers(count, buffers); + else if (stream == &data->vfStream_) + return data->imgu_->viewfinder_.dev->exportBuffers(count, buffers); + else if (stream == &data->rawStream_) return data->cio2_.exportBuffers(count, buffers); - return ipu3stream->device_->dev->exportBuffers(count, buffers); + return -EINVAL; } /** @@ -685,11 +686,17 @@ int PipelineHandlerIPU3::queueRequestDevice(Camera *camera, Request *request) /* Queue all buffers from the request aimed for the ImgU. */ for (auto it : request->buffers()) { IPU3Stream *stream = static_cast(it.first); - if (stream->raw_) - continue; - FrameBuffer *buffer = it.second; - int ret = stream->device_->dev->queueBuffer(buffer); + + if (stream == &data->rawStream_) + continue; + + int ret = 0; + if (stream == &data->outStream_) + ret = data->imgu_->output_.dev->queueBuffer(buffer); + else if (stream == &data->vfStream_) + ret = data->imgu_->viewfinder_.dev->queueBuffer(buffer); + if (ret < 0) error = ret; } @@ -801,9 +808,6 @@ int PipelineHandlerIPU3::registerCameras() * second. */ data->imgu_ = numCameras ? &imgu1_ : &imgu0_; - data->outStream_.device_ = &data->imgu_->output_; - data->vfStream_.device_ = &data->imgu_->viewfinder_; - data->rawStream_.raw_ = true; /* * Connect video devices' 'bufferReady' signals to their From patchwork Sun Jun 28 00:15:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 8468 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 BB1C5C2E69 for ; Sun, 28 Jun 2020 00:15:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7D35B60B02; Sun, 28 Jun 2020 02:15:58 +0200 (CEST) Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8C35B60B08 for ; Sun, 28 Jun 2020 02:15:54 +0200 (CEST) X-Halon-ID: 72bc0497-b8d4-11ea-86ee-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 72bc0497-b8d4-11ea-86ee-0050569116f7; Sun, 28 Jun 2020 02:15:18 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sun, 28 Jun 2020 02:15:29 +0200 Message-Id: <20200628001532.2685967-11-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> References: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 10/13] libcamera: ipu3: Remove the active flag from IPU3Stream 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The active_ flag is only used inside one function, remove the global flag and handle it inside the single function. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi --- src/libcamera/pipeline/ipu3/ipu3.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index c1520ec40fe7b57c..332cbbded52497f7 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -33,13 +33,6 @@ LOG_DEFINE_CATEGORY(IPU3) class IPU3Stream : public Stream { -public: - IPU3Stream() - : active_(false) - { - } - - bool active_; }; class IPU3CameraData : public CameraData @@ -486,8 +479,8 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) return ret; /* Apply the format to the configured streams output devices. */ - outStream->active_ = false; - vfStream->active_ = false; + bool outActive = false; + bool vfActive = false; for (unsigned int i = 0; i < config->size(); ++i) { /* @@ -499,7 +492,6 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) IPU3Stream *stream = const_cast(config->streams()[i]); StreamConfiguration &cfg = (*config)[i]; - stream->active_ = true; cfg.setStream(stream); if (stream == outStream) { @@ -508,12 +500,14 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) return ret; cfg.stride = outputFormat.planes[0].bpl; + outActive = true; } else if (stream == vfStream) { ret = imgu->configureViewfinder(cfg, &outputFormat); if (ret) return ret; cfg.stride = outputFormat.planes[0].bpl; + vfActive = true; } else { /* * The RAW still capture stream only uses en externel @@ -529,13 +523,13 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) * the configuration of the active one for that purpose (there should * be at least one active stream in the configuration request). */ - if (!outStream->active_) { + if (!outActive) { ret = imgu->configureOutput(config->at(0), &outputFormat); if (ret) return ret; } - if (!vfStream->active_) { + if (!vfActive) { ret = imgu->configureViewfinder(config->at(0), &outputFormat); if (ret) return ret; @@ -555,7 +549,7 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) /* Apply the "pipe_mode" control to the ImgU subdevice. */ ControlList ctrls(imgu->imgu_->controls()); ctrls.set(V4L2_CID_IPU3_PIPE_MODE, - static_cast(vfStream->active_ ? IPU3PipeModeVideo : + static_cast(vfActive ? IPU3PipeModeVideo : IPU3PipeModeStillCapture)); ret = imgu->imgu_->setControls(&ctrls); if (ret) { From patchwork Sun Jun 28 00:15:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 8467 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 33687C2E6A for ; Sun, 28 Jun 2020 00:15:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E4BCC60AF7; Sun, 28 Jun 2020 02:15:57 +0200 (CEST) Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4238E60AF6 for ; Sun, 28 Jun 2020 02:15:54 +0200 (CEST) X-Halon-ID: 731e49d7-b8d4-11ea-86ee-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 731e49d7-b8d4-11ea-86ee-0050569116f7; Sun, 28 Jun 2020 02:15:19 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sun, 28 Jun 2020 02:15:30 +0200 Message-Id: <20200628001532.2685967-12-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> References: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 11/13] libcamera: ipu3: Remove IPU3Stream 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The pipeline specific subclass of the pipeline is empty, remove it. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/ipu3/ipu3.cpp | 32 ++++++++++++---------------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 332cbbded52497f7..4e997c529153662c 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -31,10 +31,6 @@ namespace libcamera { LOG_DEFINE_CATEGORY(IPU3) -class IPU3Stream : public Stream -{ -}; - class IPU3CameraData : public CameraData { public: @@ -49,9 +45,9 @@ public: CIO2Device cio2_; ImgUDevice *imgu_; - IPU3Stream outStream_; - IPU3Stream vfStream_; - IPU3Stream rawStream_; + Stream outStream_; + Stream vfStream_; + Stream rawStream_; }; class IPU3CameraConfiguration : public CameraConfiguration @@ -62,7 +58,7 @@ public: Status validate() override; const StreamConfiguration &cio2Format() const { return cio2Configuration_; }; - const std::vector &streams() { return streams_; } + const std::vector &streams() { return streams_; } private: static constexpr unsigned int IPU3_BUFFER_COUNT = 4; @@ -80,7 +76,7 @@ private: const IPU3CameraData *data_; StreamConfiguration cio2Configuration_; - std::vector streams_; + std::vector streams_; }; class PipelineHandlerIPU3 : public PipelineHandler @@ -144,7 +140,7 @@ void IPU3CameraConfiguration::assignStreams() * resolution is equal to the sensor resolution, and the viewfinder * stream otherwise. */ - std::set availableStreams = { + std::set availableStreams = { &data_->outStream_, &data_->vfStream_, &data_->rawStream_, @@ -162,7 +158,7 @@ void IPU3CameraConfiguration::assignStreams() for (const StreamConfiguration &cfg : config_) { const PixelFormatInfo &info = PixelFormatInfo::info(cfg.pixelFormat); - const IPU3Stream *stream; + const Stream *stream; if (info.colourEncoding == PixelFormatInfo::ColourEncodingRAW) stream = &data_->rawStream_; @@ -265,7 +261,7 @@ CameraConfiguration::Status IPU3CameraConfiguration::validate() for (unsigned int i = 0; i < config_.size(); ++i) { StreamConfiguration &cfg = config_[i]; const StreamConfiguration oldCfg = cfg; - const IPU3Stream *stream = streams_[i]; + const Stream *stream = streams_[i]; if (stream == &data_->rawStream_) { cfg = cio2Configuration_; @@ -297,7 +293,7 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera, { IPU3CameraData *data = cameraData(camera); IPU3CameraConfiguration *config; - std::set streams = { + std::set streams = { &data->outStream_, &data->vfStream_, &data->rawStream_, @@ -307,7 +303,7 @@ CameraConfiguration *PipelineHandlerIPU3::generateConfiguration(Camera *camera, for (const StreamRole role : roles) { StreamConfiguration cfg = {}; - IPU3Stream *stream = nullptr; + Stream *stream = nullptr; cfg.pixelFormat = formats::NV12; @@ -415,8 +411,8 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) IPU3CameraConfiguration *config = static_cast(c); IPU3CameraData *data = cameraData(camera); - IPU3Stream *outStream = &data->outStream_; - IPU3Stream *vfStream = &data->vfStream_; + Stream *outStream = &data->outStream_; + Stream *vfStream = &data->vfStream_; CIO2Device *cio2 = &data->cio2_; ImgUDevice *imgu = data->imgu_; V4L2DeviceFormat outputFormat; @@ -489,7 +485,7 @@ int PipelineHandlerIPU3::configure(Camera *camera, CameraConfiguration *c) * unwanted modifications of camera data in the configuration * validate() implementation. */ - IPU3Stream *stream = const_cast(config->streams()[i]); + Stream *stream = const_cast(config->streams()[i]); StreamConfiguration &cfg = (*config)[i]; cfg.setStream(stream); @@ -679,7 +675,7 @@ int PipelineHandlerIPU3::queueRequestDevice(Camera *camera, Request *request) /* Queue all buffers from the request aimed for the ImgU. */ for (auto it : request->buffers()) { - IPU3Stream *stream = static_cast(it.first); + Stream *stream = static_cast(it.first); FrameBuffer *buffer = it.second; if (stream == &data->rawStream_) From patchwork Sun Jun 28 00:15:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 8469 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 4B8DBC2E69 for ; Sun, 28 Jun 2020 00:15:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0EDEF60B09; Sun, 28 Jun 2020 02:15:59 +0200 (CEST) Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 49621609C7 for ; Sun, 28 Jun 2020 02:15:55 +0200 (CEST) X-Halon-ID: 739cfaf2-b8d4-11ea-86ee-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 739cfaf2-b8d4-11ea-86ee-0050569116f7; Sun, 28 Jun 2020 02:15:20 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sun, 28 Jun 2020 02:15:31 +0200 Message-Id: <20200628001532.2685967-13-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> References: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 12/13] libcamera: ipu3: imgu: Remove ImgUOutput 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The struct ImgUOutput now only contains one member that is in use, the video device. Remove the struct and use the video device directly instead. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- * Changes since v1 - Fix indentation --- src/libcamera/pipeline/ipu3/imgu.cpp | 51 ++++++++++++---------------- src/libcamera/pipeline/ipu3/imgu.h | 32 ++++++----------- src/libcamera/pipeline/ipu3/ipu3.cpp | 12 +++---- 3 files changed, 38 insertions(+), 57 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp index 981239cba975f92e..6a721d47cdacf3d6 100644 --- a/src/libcamera/pipeline/ipu3/imgu.cpp +++ b/src/libcamera/pipeline/ipu3/imgu.cpp @@ -54,31 +54,22 @@ int ImgUDevice::init(MediaDevice *media, unsigned int index) if (ret) return ret; - output_.dev = V4L2VideoDevice::fromEntityName(media, name_ + " output"); - ret = output_.dev->open(); + output_ = V4L2VideoDevice::fromEntityName(media, name_ + " output"); + ret = output_->open(); if (ret) return ret; - output_.pad = PAD_OUTPUT; - output_.name = "output"; - - viewfinder_.dev = V4L2VideoDevice::fromEntityName(media, - name_ + " viewfinder"); - ret = viewfinder_.dev->open(); + viewfinder_ = V4L2VideoDevice::fromEntityName(media, + name_ + " viewfinder"); + ret = viewfinder_->open(); if (ret) return ret; - viewfinder_.pad = PAD_VF; - viewfinder_.name = "viewfinder"; - - stat_.dev = V4L2VideoDevice::fromEntityName(media, name_ + " 3a stat"); - ret = stat_.dev->open(); + stat_ = V4L2VideoDevice::fromEntityName(media, name_ + " 3a stat"); + ret = stat_->open(); if (ret) return ret; - stat_.pad = PAD_STAT; - stat_.name = "stat"; - return 0; } @@ -159,7 +150,7 @@ int ImgUDevice::configureVideoDevice(V4L2VideoDevice *dev, unsigned int pad, return ret; /* No need to apply format to the stat node. */ - if (dev == stat_.dev) + if (dev == stat_) return 0; *outputFormat = {}; @@ -171,7 +162,7 @@ int ImgUDevice::configureVideoDevice(V4L2VideoDevice *dev, unsigned int pad, if (ret) return ret; - const char *name = dev == output_.dev ? "output" : "viewfinder"; + const char *name = dev == output_ ? "output" : "viewfinder"; LOG(IPU3, Debug) << "ImgU " << name << " format = " << outputFormat->toString(); @@ -197,7 +188,7 @@ int ImgUDevice::allocateBuffers(unsigned int bufferCount) * * \todo To be revised when we'll actually use the stat node. */ - ret = stat_.dev->importBuffers(bufferCount); + ret = stat_->importBuffers(bufferCount); if (ret < 0) { LOG(IPU3, Error) << "Failed to allocate ImgU stat buffers"; goto error; @@ -208,13 +199,13 @@ int ImgUDevice::allocateBuffers(unsigned int bufferCount) * corresponding stream is active or inactive, as the driver needs * buffers to be requested on the V4L2 devices in order to operate. */ - ret = output_.dev->importBuffers(bufferCount); + ret = output_->importBuffers(bufferCount); if (ret < 0) { LOG(IPU3, Error) << "Failed to import ImgU output buffers"; goto error; } - ret = viewfinder_.dev->importBuffers(bufferCount); + ret = viewfinder_->importBuffers(bufferCount); if (ret < 0) { LOG(IPU3, Error) << "Failed to import ImgU viewfinder buffers"; goto error; @@ -235,15 +226,15 @@ void ImgUDevice::freeBuffers() { int ret; - ret = output_.dev->releaseBuffers(); + ret = output_->releaseBuffers(); if (ret) LOG(IPU3, Error) << "Failed to release ImgU output buffers"; - ret = stat_.dev->releaseBuffers(); + ret = stat_->releaseBuffers(); if (ret) LOG(IPU3, Error) << "Failed to release ImgU stat buffers"; - ret = viewfinder_.dev->releaseBuffers(); + ret = viewfinder_->releaseBuffers(); if (ret) LOG(IPU3, Error) << "Failed to release ImgU viewfinder buffers"; @@ -257,19 +248,19 @@ int ImgUDevice::start() int ret; /* Start the ImgU video devices. */ - ret = output_.dev->streamOn(); + ret = output_->streamOn(); if (ret) { LOG(IPU3, Error) << "Failed to start ImgU output"; return ret; } - ret = viewfinder_.dev->streamOn(); + ret = viewfinder_->streamOn(); if (ret) { LOG(IPU3, Error) << "Failed to start ImgU viewfinder"; return ret; } - ret = stat_.dev->streamOn(); + ret = stat_->streamOn(); if (ret) { LOG(IPU3, Error) << "Failed to start ImgU stat"; return ret; @@ -288,9 +279,9 @@ int ImgUDevice::stop() { int ret; - ret = output_.dev->streamOff(); - ret |= viewfinder_.dev->streamOff(); - ret |= stat_.dev->streamOff(); + ret = output_->streamOff(); + ret |= viewfinder_->streamOff(); + ret |= stat_->streamOff(); ret |= input_->streamOff(); return ret; diff --git a/src/libcamera/pipeline/ipu3/imgu.h b/src/libcamera/pipeline/ipu3/imgu.h index 5f1dbfd8f45f7924..7be25e40957fcb03 100644 --- a/src/libcamera/pipeline/ipu3/imgu.h +++ b/src/libcamera/pipeline/ipu3/imgu.h @@ -24,28 +24,19 @@ struct StreamConfiguration; class ImgUDevice { public: - /* ImgU output descriptor: group data specific to an ImgU output. */ - struct ImgUOutput { - V4L2VideoDevice *dev; - unsigned int pad; - std::string name; - }; - ImgUDevice() - : imgu_(nullptr), input_(nullptr) + : imgu_(nullptr), input_(nullptr), output_(nullptr), + viewfinder_(nullptr), stat_(nullptr) { - output_.dev = nullptr; - viewfinder_.dev = nullptr; - stat_.dev = nullptr; } ~ImgUDevice() { delete imgu_; delete input_; - delete output_.dev; - delete viewfinder_.dev; - delete stat_.dev; + delete output_; + delete viewfinder_; + delete stat_; } int init(MediaDevice *media, unsigned int index); @@ -55,22 +46,21 @@ public: int configureOutput(const StreamConfiguration &cfg, V4L2DeviceFormat *outputFormat) { - return configureVideoDevice(output_.dev, PAD_OUTPUT, cfg, + return configureVideoDevice(output_, PAD_OUTPUT, cfg, outputFormat); } int configureViewfinder(const StreamConfiguration &cfg, V4L2DeviceFormat *outputFormat) { - return configureVideoDevice(viewfinder_.dev, PAD_VF, cfg, + return configureVideoDevice(viewfinder_, PAD_VF, cfg, outputFormat); } int configureStat(const StreamConfiguration &cfg, V4L2DeviceFormat *outputFormat) { - return configureVideoDevice(stat_.dev, PAD_STAT, cfg, - outputFormat); + return configureVideoDevice(stat_, PAD_STAT, cfg, outputFormat); } int allocateBuffers(unsigned int bufferCount); @@ -83,9 +73,9 @@ public: V4L2Subdevice *imgu_; V4L2VideoDevice *input_; - ImgUOutput output_; - ImgUOutput viewfinder_; - ImgUOutput stat_; + V4L2VideoDevice *output_; + V4L2VideoDevice *viewfinder_; + V4L2VideoDevice *stat_; /* \todo Add param video device for 3A tuning */ private: diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 4e997c529153662c..7d9fca320d608a0e 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -563,9 +563,9 @@ int PipelineHandlerIPU3::exportFrameBuffers(Camera *camera, Stream *stream, unsigned int count = stream->configuration().bufferCount; if (stream == &data->outStream_) - return data->imgu_->output_.dev->exportBuffers(count, buffers); + return data->imgu_->output_->exportBuffers(count, buffers); else if (stream == &data->vfStream_) - return data->imgu_->viewfinder_.dev->exportBuffers(count, buffers); + return data->imgu_->viewfinder_->exportBuffers(count, buffers); else if (stream == &data->rawStream_) return data->cio2_.exportBuffers(count, buffers); @@ -683,9 +683,9 @@ int PipelineHandlerIPU3::queueRequestDevice(Camera *camera, Request *request) int ret = 0; if (stream == &data->outStream_) - ret = data->imgu_->output_.dev->queueBuffer(buffer); + ret = data->imgu_->output_->queueBuffer(buffer); else if (stream == &data->vfStream_) - ret = data->imgu_->viewfinder_.dev->queueBuffer(buffer); + ret = data->imgu_->viewfinder_->queueBuffer(buffer); if (ret < 0) error = ret; @@ -811,9 +811,9 @@ int PipelineHandlerIPU3::registerCameras() &IPU3CameraData::cio2BufferReady); data->imgu_->input_->bufferReady.connect(&data->cio2_, &CIO2Device::tryReturnBuffer); - data->imgu_->output_.dev->bufferReady.connect(data.get(), + data->imgu_->output_->bufferReady.connect(data.get(), &IPU3CameraData::imguOutputBufferReady); - data->imgu_->viewfinder_.dev->bufferReady.connect(data.get(), + data->imgu_->viewfinder_->bufferReady.connect(data.get(), &IPU3CameraData::imguOutputBufferReady); /* Create and register the Camera instance. */ From patchwork Sun Jun 28 00:15:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 8470 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 13785C2E69 for ; Sun, 28 Jun 2020 00:16:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E23C1609C8; Sun, 28 Jun 2020 02:16:04 +0200 (CEST) Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0C17160AF7 for ; Sun, 28 Jun 2020 02:15:56 +0200 (CEST) X-Halon-ID: 7437b4bc-b8d4-11ea-86ee-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de [79.202.46.202]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 7437b4bc-b8d4-11ea-86ee-0050569116f7; Sun, 28 Jun 2020 02:15:21 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sun, 28 Jun 2020 02:15:32 +0200 Message-Id: <20200628001532.2685967-14-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> References: <20200628001532.2685967-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 13/13] libcamera: ipu3: imgu: Use unique_ptr for video and subdevices 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Instead of manually deleting the video and subdevices in the destructor use std::unique_ptr. Suggested-by: Laurent Pinchart Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/ipu3/imgu.cpp | 24 ++++++++++++++------- src/libcamera/pipeline/ipu3/imgu.h | 32 ++++++++-------------------- 2 files changed, 25 insertions(+), 31 deletions(-) diff --git a/src/libcamera/pipeline/ipu3/imgu.cpp b/src/libcamera/pipeline/ipu3/imgu.cpp index 6a721d47cdacf3d6..4f11dc0dbb5fe94a 100644 --- a/src/libcamera/pipeline/ipu3/imgu.cpp +++ b/src/libcamera/pipeline/ipu3/imgu.cpp @@ -44,28 +44,36 @@ int ImgUDevice::init(MediaDevice *media, unsigned int index) * by the match() function: no need to check for newly created * video devices and subdevice validity here. */ - imgu_ = V4L2Subdevice::fromEntityName(media, name_); + imgu_ = std::unique_ptr( + V4L2Subdevice::fromEntityName(media, name_)); ret = imgu_->open(); if (ret) return ret; - input_ = V4L2VideoDevice::fromEntityName(media, name_ + " input"); + input_ = std::unique_ptr( + V4L2VideoDevice::fromEntityName(media, + name_ + " input")); ret = input_->open(); if (ret) return ret; - output_ = V4L2VideoDevice::fromEntityName(media, name_ + " output"); + output_ = std::unique_ptr( + V4L2VideoDevice::fromEntityName(media, + name_ + " output")); ret = output_->open(); if (ret) return ret; - viewfinder_ = V4L2VideoDevice::fromEntityName(media, - name_ + " viewfinder"); + viewfinder_ = std::unique_ptr( + V4L2VideoDevice::fromEntityName(media, + name_ + " viewfinder")); ret = viewfinder_->open(); if (ret) return ret; - stat_ = V4L2VideoDevice::fromEntityName(media, name_ + " 3a stat"); + stat_ = std::unique_ptr( + V4L2VideoDevice::fromEntityName(media, + name_ + " 3a stat")); ret = stat_->open(); if (ret) return ret; @@ -150,7 +158,7 @@ int ImgUDevice::configureVideoDevice(V4L2VideoDevice *dev, unsigned int pad, return ret; /* No need to apply format to the stat node. */ - if (dev == stat_) + if (dev == stat_.get()) return 0; *outputFormat = {}; @@ -162,7 +170,7 @@ int ImgUDevice::configureVideoDevice(V4L2VideoDevice *dev, unsigned int pad, if (ret) return ret; - const char *name = dev == output_ ? "output" : "viewfinder"; + const char *name = dev == output_.get() ? "output" : "viewfinder"; LOG(IPU3, Debug) << "ImgU " << name << " format = " << outputFormat->toString(); diff --git a/src/libcamera/pipeline/ipu3/imgu.h b/src/libcamera/pipeline/ipu3/imgu.h index 7be25e40957fcb03..308bf26ee56e4e82 100644 --- a/src/libcamera/pipeline/ipu3/imgu.h +++ b/src/libcamera/pipeline/ipu3/imgu.h @@ -24,21 +24,6 @@ struct StreamConfiguration; class ImgUDevice { public: - ImgUDevice() - : imgu_(nullptr), input_(nullptr), output_(nullptr), - viewfinder_(nullptr), stat_(nullptr) - { - } - - ~ImgUDevice() - { - delete imgu_; - delete input_; - delete output_; - delete viewfinder_; - delete stat_; - } - int init(MediaDevice *media, unsigned int index); int configureInput(const Size &size, V4L2DeviceFormat *inputFormat); @@ -46,21 +31,22 @@ public: int configureOutput(const StreamConfiguration &cfg, V4L2DeviceFormat *outputFormat) { - return configureVideoDevice(output_, PAD_OUTPUT, cfg, + return configureVideoDevice(output_.get(), PAD_OUTPUT, cfg, outputFormat); } int configureViewfinder(const StreamConfiguration &cfg, V4L2DeviceFormat *outputFormat) { - return configureVideoDevice(viewfinder_, PAD_VF, cfg, + return configureVideoDevice(viewfinder_.get(), PAD_VF, cfg, outputFormat); } int configureStat(const StreamConfiguration &cfg, V4L2DeviceFormat *outputFormat) { - return configureVideoDevice(stat_, PAD_STAT, cfg, outputFormat); + return configureVideoDevice(stat_.get(), PAD_STAT, cfg, + outputFormat); } int allocateBuffers(unsigned int bufferCount); @@ -71,11 +57,11 @@ public: int enableLinks(bool enable); - V4L2Subdevice *imgu_; - V4L2VideoDevice *input_; - V4L2VideoDevice *output_; - V4L2VideoDevice *viewfinder_; - V4L2VideoDevice *stat_; + std::unique_ptr imgu_; + std::unique_ptr input_; + std::unique_ptr output_; + std::unique_ptr viewfinder_; + std::unique_ptr stat_; /* \todo Add param video device for 3A tuning */ private: