From patchwork Tue Sep 29 01:43: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: 9846 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 E1B43C3B5B for ; Tue, 29 Sep 2020 01:43:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BEAAB62140; Tue, 29 Sep 2020 03:43:50 +0200 (CEST) Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id F017B60365 for ; Tue, 29 Sep 2020 03:43:48 +0200 (CEST) X-Halon-ID: 34a557cf-01f5-11eb-b295-0050569116f7 Authorized-sender: niklas.soderlund@fsdn.se Received: from bismarck.berto.se (p54ac52a8.dip0.t-ipconnect.de [84.172.82.168]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 34a557cf-01f5-11eb-b295-0050569116f7; Tue, 29 Sep 2020 03:43:44 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 29 Sep 2020 03:43:28 +0200 Message-Id: <20200929014334.49719-2-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929014334.49719-1-niklas.soderlund@ragnatech.se> References: <20200929014334.49719-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 1/7] libcamera: pipeline: rkisp1: Breakout basic path handling to own class 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 self and main paths are very similar and the introduction of support for two simultaneous streams have made it clear their handling could be abstracted in a separate class. This is the first step to create such a class by breaking out the initialization and storage of the video and subdevices. There is no functional change in this patch. Signed-off-by: Niklas Söderlund Reviewed-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- * Changes since v3 - Fix spelling in commit message. - Rename rkisp1path.{cpp,h} -> rkisp1_path.{cpp,h} --- src/libcamera/pipeline/rkisp1/meson.build | 1 + src/libcamera/pipeline/rkisp1/rkisp1.cpp | 106 ++++++++---------- src/libcamera/pipeline/rkisp1/rkisp1_path.cpp | 53 +++++++++ src/libcamera/pipeline/rkisp1/rkisp1_path.h | 46 ++++++++ 4 files changed, 145 insertions(+), 61 deletions(-) create mode 100644 src/libcamera/pipeline/rkisp1/rkisp1_path.cpp create mode 100644 src/libcamera/pipeline/rkisp1/rkisp1_path.h diff --git a/src/libcamera/pipeline/rkisp1/meson.build b/src/libcamera/pipeline/rkisp1/meson.build index 1ab3964a6db190f0..5cd40d949d543fa9 100644 --- a/src/libcamera/pipeline/rkisp1/meson.build +++ b/src/libcamera/pipeline/rkisp1/meson.build @@ -2,5 +2,6 @@ libcamera_sources += files([ 'rkisp1.cpp', + 'rkisp1_path.cpp', 'timeline.cpp', ]) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index acd946d10b416654..84b5164bd040e617 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -33,6 +33,7 @@ #include "libcamera/internal/v4l2_subdevice.h" #include "libcamera/internal/v4l2_videodevice.h" +#include "rkisp1_path.h" #include "timeline.h" namespace libcamera { @@ -147,12 +148,11 @@ public: class RkISP1CameraData : public CameraData { public: - RkISP1CameraData(PipelineHandler *pipe, V4L2VideoDevice *mainPathVideo, - V4L2VideoDevice *selfPathVideo) + RkISP1CameraData(PipelineHandler *pipe, RkISP1MainPath *mainPath, + RkISP1SelfPath *selfPath) : CameraData(pipe), sensor_(nullptr), frame_(0), - frameInfo_(pipe), mainPathVideo_(mainPathVideo), - selfPathVideo_(selfPathVideo), mainPathActive_(false), - selfPathActive_(false) + frameInfo_(pipe), mainPath_(mainPath), selfPath_(selfPath), + mainPathActive_(false), selfPathActive_(false) { } @@ -171,8 +171,8 @@ public: RkISP1Frames frameInfo_; RkISP1Timeline timeline_; - V4L2VideoDevice *mainPathVideo_; - V4L2VideoDevice *selfPathVideo_; + RkISP1MainPath *mainPath_; + RkISP1SelfPath *selfPath_; bool mainPathActive_; bool selfPathActive_; @@ -259,13 +259,12 @@ private: MediaDevice *media_; V4L2Subdevice *isp_; - V4L2Subdevice *mainPathResizer_; - V4L2Subdevice *selfPathResizer_; - V4L2VideoDevice *mainPathVideo_; - V4L2VideoDevice *selfPathVideo_; V4L2VideoDevice *param_; V4L2VideoDevice *stat_; + RkISP1MainPath mainPath_; + RkISP1SelfPath selfPath_; + std::vector> paramBuffers_; std::vector> statBuffers_; std::queue availableParamBuffers_; @@ -441,10 +440,10 @@ protected: pipe_->stat_->queueBuffer(info->statBuffer); if (info->mainPathBuffer) - pipe_->mainPathVideo_->queueBuffer(info->mainPathBuffer); + pipe_->mainPath_.video_->queueBuffer(info->mainPathBuffer); if (info->selfPathBuffer) - pipe_->selfPathVideo_->queueBuffer(info->selfPathBuffer); + pipe_->selfPath_.video_->queueBuffer(info->selfPathBuffer); } private: @@ -554,13 +553,13 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validatePath( CameraConfiguration::Status RkISP1CameraConfiguration::validateMainPath(StreamConfiguration *cfg) { return validatePath(cfg, RKISP1_RSZ_MP_FORMATS, RKISP1_RSZ_MP_SRC_MIN, - RKISP1_RSZ_MP_SRC_MAX, data_->mainPathVideo_); + RKISP1_RSZ_MP_SRC_MAX, data_->mainPath_->video_); } CameraConfiguration::Status RkISP1CameraConfiguration::validateSelfPath(StreamConfiguration *cfg) { return validatePath(cfg, RKISP1_RSZ_SP_FORMATS, RKISP1_RSZ_SP_SRC_MIN, - RKISP1_RSZ_SP_SRC_MAX, data_->selfPathVideo_); + RKISP1_RSZ_SP_SRC_MAX, data_->selfPath_->video_); } bool RkISP1CameraConfiguration::fitsAllPaths(const StreamConfiguration &cfg) @@ -684,9 +683,8 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate() } PipelineHandlerRkISP1::PipelineHandlerRkISP1(CameraManager *manager) - : PipelineHandler(manager), isp_(nullptr), mainPathResizer_(nullptr), - selfPathResizer_(nullptr), mainPathVideo_(nullptr), - selfPathVideo_(nullptr), param_(nullptr), stat_(nullptr) + : PipelineHandler(manager), isp_(nullptr), param_(nullptr), + stat_(nullptr) { } @@ -694,10 +692,6 @@ PipelineHandlerRkISP1::~PipelineHandlerRkISP1() { delete param_; delete stat_; - delete mainPathVideo_; - delete selfPathVideo_; - delete mainPathResizer_; - delete selfPathResizer_; delete isp_; } @@ -823,12 +817,12 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c) V4L2VideoDevice *video; if (cfg.stream() == &data->mainPathStream_) { - resizer = mainPathResizer_; - video = mainPathVideo_; + resizer = mainPath_.resizer_; + video = mainPath_.video_; data->mainPathActive_ = true; } else { - resizer = selfPathResizer_; - video = selfPathVideo_; + resizer = selfPath_.resizer_; + video = selfPath_.video_; data->selfPathActive_ = true; } @@ -836,7 +830,7 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c) if (ret < 0) return ret; - const char *name = resizer == mainPathResizer_ ? "main" : "self"; + const char *name = resizer == mainPath_.resizer_ ? "main" : "self"; LOG(RkISP1, Debug) << "Configured " << name << " resizer input pad with " @@ -896,9 +890,9 @@ int PipelineHandlerRkISP1::exportFrameBuffers([[maybe_unused]] Camera *camera, S unsigned int count = stream->configuration().bufferCount; if (stream == &data->mainPathStream_) - return mainPathVideo_->exportBuffers(count, buffers); + return mainPath_.video_->exportBuffers(count, buffers); else if (stream == &data->selfPathStream_) - return selfPathVideo_->exportBuffers(count, buffers); + return selfPath_.video_->exportBuffers(count, buffers); return -EINVAL; } @@ -915,14 +909,14 @@ int PipelineHandlerRkISP1::allocateBuffers(Camera *camera) }); if (data->mainPathActive_) { - ret = mainPathVideo_->importBuffers( + ret = mainPath_.video_->importBuffers( data->mainPathStream_.configuration().bufferCount); if (ret < 0) goto error; } if (data->selfPathActive_) { - ret = selfPathVideo_->importBuffers( + ret = selfPath_.video_->importBuffers( data->selfPathStream_.configuration().bufferCount); if (ret < 0) goto error; @@ -957,8 +951,8 @@ int PipelineHandlerRkISP1::allocateBuffers(Camera *camera) error: paramBuffers_.clear(); statBuffers_.clear(); - mainPathVideo_->releaseBuffers(); - selfPathVideo_->releaseBuffers(); + mainPath_.video_->releaseBuffers(); + selfPath_.video_->releaseBuffers(); return ret; } @@ -989,10 +983,10 @@ int PipelineHandlerRkISP1::freeBuffers(Camera *camera) if (stat_->releaseBuffers()) LOG(RkISP1, Error) << "Failed to release stat buffers"; - if (mainPathVideo_->releaseBuffers()) + if (mainPath_.video_->releaseBuffers()) LOG(RkISP1, Error) << "Failed to release main path buffers"; - if (selfPathVideo_->releaseBuffers()) + if (selfPath_.video_->releaseBuffers()) LOG(RkISP1, Error) << "Failed to release self path buffers"; return 0; @@ -1040,7 +1034,7 @@ int PipelineHandlerRkISP1::start(Camera *camera) std::map streamConfig; if (data->mainPathActive_) { - ret = mainPathVideo_->streamOn(); + ret = mainPath_.video_->streamOn(); if (ret) { param_->streamOff(); stat_->streamOff(); @@ -1059,10 +1053,10 @@ int PipelineHandlerRkISP1::start(Camera *camera) } if (data->selfPathActive_) { - ret = selfPathVideo_->streamOn(); + ret = selfPath_.video_->streamOn(); if (ret) { if (data->mainPathActive_) - mainPathVideo_->streamOff(); + mainPath_.video_->streamOff(); param_->streamOff(); stat_->streamOff(); @@ -1108,7 +1102,7 @@ void PipelineHandlerRkISP1::stop(Camera *camera) int ret; if (data->selfPathActive_) { - ret = selfPathVideo_->streamOff(); + ret = selfPath_.video_->streamOff(); if (ret) LOG(RkISP1, Warning) << "Failed to stop self path for " @@ -1116,7 +1110,7 @@ void PipelineHandlerRkISP1::stop(Camera *camera) } if (data->mainPathActive_) { - ret = mainPathVideo_->streamOff(); + ret = mainPath_.video_->streamOff(); if (ret) LOG(RkISP1, Warning) << "Failed to stop main path for " @@ -1228,8 +1222,7 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor) int ret; std::unique_ptr data = - std::make_unique(this, mainPathVideo_, - selfPathVideo_); + std::make_unique(this, &mainPath_, &selfPath_); ControlInfoMap::Map ctrls; ctrls.emplace(std::piecewise_construct, @@ -1283,23 +1276,7 @@ bool PipelineHandlerRkISP1::match(DeviceEnumerator *enumerator) if (isp_->open() < 0) return false; - mainPathResizer_ = V4L2Subdevice::fromEntityName(media_, "rkisp1_resizer_mainpath"); - if (mainPathResizer_->open() < 0) - return false; - - selfPathResizer_ = V4L2Subdevice::fromEntityName(media_, "rkisp1_resizer_selfpath"); - if (selfPathResizer_->open() < 0) - return false; - - /* Locate and open the capture video node. */ - mainPathVideo_ = V4L2VideoDevice::fromEntityName(media_, "rkisp1_mainpath"); - if (mainPathVideo_->open() < 0) - return false; - - selfPathVideo_ = V4L2VideoDevice::fromEntityName(media_, "rkisp1_selfpath"); - if (selfPathVideo_->open() < 0) - return false; - + /* Locate and open the stats and params video nodes. */ stat_ = V4L2VideoDevice::fromEntityName(media_, "rkisp1_stats"); if (stat_->open() < 0) return false; @@ -1308,8 +1285,15 @@ bool PipelineHandlerRkISP1::match(DeviceEnumerator *enumerator) if (param_->open() < 0) return false; - mainPathVideo_->bufferReady.connect(this, &PipelineHandlerRkISP1::bufferReady); - selfPathVideo_->bufferReady.connect(this, &PipelineHandlerRkISP1::bufferReady); + /* Locate and open the ISP main and self paths. */ + if (!mainPath_.init(media_)) + return false; + + if (!selfPath_.init(media_)) + return false; + + mainPath_.video_->bufferReady.connect(this, &PipelineHandlerRkISP1::bufferReady); + selfPath_.video_->bufferReady.connect(this, &PipelineHandlerRkISP1::bufferReady); stat_->bufferReady.connect(this, &PipelineHandlerRkISP1::statReady); param_->bufferReady.connect(this, &PipelineHandlerRkISP1::paramReady); diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp new file mode 100644 index 0000000000000000..2eae42340c23783c --- /dev/null +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp @@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2020, Google Inc. + * + * rkisp1path.cpp - Rockchip ISP1 path helper + */ + +#include "rkisp1_path.h" + +#include "libcamera/internal/media_device.h" +#include "libcamera/internal/v4l2_subdevice.h" +#include "libcamera/internal/v4l2_videodevice.h" + +namespace libcamera { + +RkISP1Path::RkISP1Path(const char *name) + : resizer_(nullptr), video_(nullptr), name_(name) +{ +} + +RkISP1Path::~RkISP1Path() +{ + delete video_; + delete resizer_; +} + +bool RkISP1Path::init(MediaDevice *media) +{ + std::string resizer = std::string("rkisp1_resizer_") + name_ + "path"; + std::string video = std::string("rkisp1_") + name_ + "path"; + + resizer_ = V4L2Subdevice::fromEntityName(media, resizer); + if (resizer_->open() < 0) + return false; + + video_ = V4L2VideoDevice::fromEntityName(media, video); + if (video_->open() < 0) + return false; + + return true; +} + +RkISP1MainPath::RkISP1MainPath() + : RkISP1Path("main") +{ +} + +RkISP1SelfPath::RkISP1SelfPath() + : RkISP1Path("self") +{ +} + +} /* namespace libcamera */ diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.h b/src/libcamera/pipeline/rkisp1/rkisp1_path.h new file mode 100644 index 0000000000000000..d3172e228a3f67bf --- /dev/null +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.h @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2020, Google Inc. + * + * rkisp1path.h - Rockchip ISP1 path helper + */ +#ifndef __LIBCAMERA_PIPELINE_RKISP1_PATH_H__ +#define __LIBCAMERA_PIPELINE_RKISP1_PATH_H__ + +namespace libcamera { + +class MediaDevice; +class V4L2Subdevice; +class V4L2VideoDevice; + +class RkISP1Path +{ +public: + RkISP1Path(const char *name); + ~RkISP1Path(); + + bool init(MediaDevice *media); + + /* \todo Make resizer and video private. */ + V4L2Subdevice *resizer_; + V4L2VideoDevice *video_; + +private: + const char *name_; +}; + +class RkISP1MainPath : public RkISP1Path +{ +public: + RkISP1MainPath(); +}; + +class RkISP1SelfPath : public RkISP1Path +{ +public: + RkISP1SelfPath(); +}; + +} /* namespace libcamera */ + +#endif /* __LIBCAMERA_PIPELINE_RKISP1_PATH_H__ */ From patchwork Tue Sep 29 01:43: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: 9847 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 2FCD8C3B5B for ; Tue, 29 Sep 2020 01:43:53 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 09A4061FE5; Tue, 29 Sep 2020 03:43:53 +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 017056213B for ; Tue, 29 Sep 2020 03:43:50 +0200 (CEST) X-Halon-ID: 365502a1-01f5-11eb-b295-0050569116f7 Authorized-sender: niklas.soderlund@fsdn.se Received: from bismarck.berto.se (p54ac52a8.dip0.t-ipconnect.de [84.172.82.168]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 365502a1-01f5-11eb-b295-0050569116f7; Tue, 29 Sep 2020 03:43:47 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 29 Sep 2020 03:43:29 +0200 Message-Id: <20200929014334.49719-3-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929014334.49719-1-niklas.soderlund@ragnatech.se> References: <20200929014334.49719-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 2/7] libcamera: pipeline: rkisp1: Move path configuration to RkISP1Path 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" Move the path configuration to RkISP1Path to increase code reuse and make the V4L2 subdevice resizer private to the path. There is no functional change. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 55 ++----------------- src/libcamera/pipeline/rkisp1/rkisp1_path.cpp | 55 ++++++++++++++++++- src/libcamera/pipeline/rkisp1/rkisp1_path.h | 10 +++- 3 files changed, 68 insertions(+), 52 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 84b5164bd040e617..13e0666d80050b51 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -812,60 +812,17 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c) data->mainPathActive_ = false; data->selfPathActive_ = false; for (const StreamConfiguration &cfg : *config) { - V4L2SubdeviceFormat ispFormat = format; - V4L2Subdevice *resizer; - V4L2VideoDevice *video; - if (cfg.stream() == &data->mainPathStream_) { - resizer = mainPath_.resizer_; - video = mainPath_.video_; + ret = mainPath_.configure(cfg, format); + if (ret) + return ret; data->mainPathActive_ = true; } else { - resizer = selfPath_.resizer_; - video = selfPath_.video_; + ret = selfPath_.configure(cfg, format); + if (ret) + return ret; data->selfPathActive_ = true; } - - ret = resizer->setFormat(0, &ispFormat); - if (ret < 0) - return ret; - - const char *name = resizer == mainPath_.resizer_ ? "main" : "self"; - - LOG(RkISP1, Debug) - << "Configured " << name << " resizer input pad with " - << ispFormat.toString(); - - ispFormat.size = cfg.size; - - LOG(RkISP1, Debug) - << "Configuring " << name << " resizer output pad with " - << ispFormat.toString(); - - ret = resizer->setFormat(1, &ispFormat); - if (ret < 0) - return ret; - - LOG(RkISP1, Debug) - << "Configured " << name << " resizer output pad with " - << ispFormat.toString(); - - const PixelFormatInfo &info = PixelFormatInfo::info(cfg.pixelFormat); - V4L2DeviceFormat outputFormat = {}; - outputFormat.fourcc = video->toV4L2PixelFormat(cfg.pixelFormat); - outputFormat.size = cfg.size; - outputFormat.planesCount = info.numPlanes(); - - ret = video->setFormat(&outputFormat); - if (ret) - return ret; - - if (outputFormat.size != cfg.size || - outputFormat.fourcc != video->toV4L2PixelFormat(cfg.pixelFormat)) { - LOG(RkISP1, Error) - << "Unable to configure capture in " << cfg.toString(); - return -EINVAL; - } } V4L2DeviceFormat paramFormat = {}; diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp index 2eae42340c23783c..66b5eebdcb804e24 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp @@ -7,14 +7,18 @@ #include "rkisp1_path.h" +#include + #include "libcamera/internal/media_device.h" #include "libcamera/internal/v4l2_subdevice.h" #include "libcamera/internal/v4l2_videodevice.h" namespace libcamera { +LOG_DECLARE_CATEGORY(RkISP1) + RkISP1Path::RkISP1Path(const char *name) - : resizer_(nullptr), video_(nullptr), name_(name) + : video_(nullptr), name_(name), resizer_(nullptr) { } @@ -40,6 +44,55 @@ bool RkISP1Path::init(MediaDevice *media) return true; } +int RkISP1Path::configure(const StreamConfiguration &config, + const V4L2SubdeviceFormat &inputFormat) +{ + int ret; + + V4L2SubdeviceFormat ispFormat = inputFormat; + + ret = resizer_->setFormat(0, &ispFormat); + if (ret < 0) + return ret; + + LOG(RkISP1, Debug) + << "Configured " << name_ << " resizer input pad with " + << ispFormat.toString(); + + ispFormat.size = config.size; + + LOG(RkISP1, Debug) + << "Configuring " << name_ << " resizer output pad with " + << ispFormat.toString(); + + ret = resizer_->setFormat(1, &ispFormat); + if (ret < 0) + return ret; + + LOG(RkISP1, Debug) + << "Configured " << name_ << " resizer output pad with " + << ispFormat.toString(); + + const PixelFormatInfo &info = PixelFormatInfo::info(config.pixelFormat); + V4L2DeviceFormat outputFormat = {}; + outputFormat.fourcc = video_->toV4L2PixelFormat(config.pixelFormat); + outputFormat.size = config.size; + outputFormat.planesCount = info.numPlanes(); + + ret = video_->setFormat(&outputFormat); + if (ret) + return ret; + + if (outputFormat.size != config.size || + outputFormat.fourcc != video_->toV4L2PixelFormat(config.pixelFormat)) { + LOG(RkISP1, Error) + << "Unable to configure capture in " << config.toString(); + return -EINVAL; + } + + return 0; +} + RkISP1MainPath::RkISP1MainPath() : RkISP1Path("main") { diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.h b/src/libcamera/pipeline/rkisp1/rkisp1_path.h index d3172e228a3f67bf..6eb01529d2fddb1c 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.h +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.h @@ -12,6 +12,8 @@ namespace libcamera { class MediaDevice; class V4L2Subdevice; class V4L2VideoDevice; +struct StreamConfiguration; +struct V4L2SubdeviceFormat; class RkISP1Path { @@ -21,12 +23,16 @@ public: bool init(MediaDevice *media); - /* \todo Make resizer and video private. */ - V4L2Subdevice *resizer_; + int configure(const StreamConfiguration &config, + const V4L2SubdeviceFormat &inputFormat); + + /* \todo Make video private. */ V4L2VideoDevice *video_; private: const char *name_; + + V4L2Subdevice *resizer_; }; class RkISP1MainPath : public RkISP1Path From patchwork Tue Sep 29 01:43: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: 9848 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 B25D8C3B5B for ; Tue, 29 Sep 2020 01:43:54 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3DA6362140; Tue, 29 Sep 2020 03:43:54 +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 31C6D60BD4 for ; Tue, 29 Sep 2020 03:43:52 +0200 (CEST) X-Halon-ID: 37995844-01f5-11eb-b295-0050569116f7 Authorized-sender: niklas.soderlund@fsdn.se Received: from bismarck.berto.se (p54ac52a8.dip0.t-ipconnect.de [84.172.82.168]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 37995844-01f5-11eb-b295-0050569116f7; Tue, 29 Sep 2020 03:43:47 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 29 Sep 2020 03:43:30 +0200 Message-Id: <20200929014334.49719-4-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929014334.49719-1-niklas.soderlund@ragnatech.se> References: <20200929014334.49719-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 3/7] libcamera: pipeline: rkisp1: Move path configuration generation and validation to RkISP1Path 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" Move the path configuration generation and validation to RkISP1Path. This is done to increase code reuse and to encapsulate the main and self path differences inside the RkISP1Path class. There is no functional change. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- * Changes since v3 - Include headers instead of forward declare Size and PixelFormat. - Keep array of PixelFormats in Span. --- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 122 ++---------------- src/libcamera/pipeline/rkisp1/rkisp1_path.cpp | 94 +++++++++++++- src/libcamera/pipeline/rkisp1/rkisp1_path.h | 19 ++- 3 files changed, 119 insertions(+), 116 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 13e0666d80050b51..6c81faa818e2b11a 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include "libcamera/internal/camera_sensor.h" @@ -40,34 +39,6 @@ namespace libcamera { LOG_DEFINE_CATEGORY(RkISP1) -namespace { -constexpr Size RKISP1_RSZ_MP_SRC_MIN{ 32, 16 }; -constexpr Size RKISP1_RSZ_MP_SRC_MAX{ 4416, 3312 }; -constexpr std::array RKISP1_RSZ_MP_FORMATS{ - formats::YUYV, - formats::YVYU, - formats::VYUY, - formats::NV16, - formats::NV61, - formats::NV21, - formats::NV12, - /* \todo Add support for 8-bit greyscale to DRM formats */ -}; - -constexpr Size RKISP1_RSZ_SP_SRC_MIN{ 32, 16 }; -constexpr Size RKISP1_RSZ_SP_SRC_MAX{ 1920, 1920 }; -constexpr std::array RKISP1_RSZ_SP_FORMATS{ - formats::YUYV, - formats::YVYU, - formats::VYUY, - formats::NV16, - formats::NV61, - formats::NV21, - formats::NV12, - /* \todo Add support for BGR888 and RGB565 */ -}; -} /* namespace */ - class PipelineHandlerRkISP1; class RkISP1ActionQueueBuffers; class RkISP1CameraData; @@ -194,14 +165,6 @@ public: const V4L2SubdeviceFormat &sensorFormat() { return sensorFormat_; } private: - static constexpr unsigned int RKISP1_BUFFER_COUNT = 4; - - CameraConfiguration::Status validatePath(StreamConfiguration *cfg, - const Span &formats, - const Size &min, const Size &max, - V4L2VideoDevice *video); - CameraConfiguration::Status validateMainPath(StreamConfiguration *cfg); - CameraConfiguration::Status validateSelfPath(StreamConfiguration *cfg); bool fitsAllPaths(const StreamConfiguration &cfg); /* @@ -514,64 +477,16 @@ RkISP1CameraConfiguration::RkISP1CameraConfiguration(Camera *camera, data_ = data; } -CameraConfiguration::Status RkISP1CameraConfiguration::validatePath( - StreamConfiguration *cfg, const Span &formats, - const Size &min, const Size &max, V4L2VideoDevice *video) -{ - const StreamConfiguration reqCfg = *cfg; - Status status = Valid; - - if (std::find(formats.begin(), formats.end(), cfg->pixelFormat) == - formats.end()) - cfg->pixelFormat = formats::NV12; - - cfg->size.boundTo(max); - cfg->size.expandTo(min); - cfg->bufferCount = RKISP1_BUFFER_COUNT; - - V4L2DeviceFormat format = {}; - format.fourcc = video->toV4L2PixelFormat(cfg->pixelFormat); - format.size = cfg->size; - - int ret = video->tryFormat(&format); - if (ret) - return Invalid; - - cfg->stride = format.planes[0].bpl; - cfg->frameSize = format.planes[0].size; - - if (cfg->pixelFormat != reqCfg.pixelFormat || cfg->size != reqCfg.size) { - LOG(RkISP1, Debug) - << "Adjusting format from " << reqCfg.toString() - << " to " << cfg->toString(); - status = Adjusted; - } - - return status; -} - -CameraConfiguration::Status RkISP1CameraConfiguration::validateMainPath(StreamConfiguration *cfg) -{ - return validatePath(cfg, RKISP1_RSZ_MP_FORMATS, RKISP1_RSZ_MP_SRC_MIN, - RKISP1_RSZ_MP_SRC_MAX, data_->mainPath_->video_); -} - -CameraConfiguration::Status RkISP1CameraConfiguration::validateSelfPath(StreamConfiguration *cfg) -{ - return validatePath(cfg, RKISP1_RSZ_SP_FORMATS, RKISP1_RSZ_SP_SRC_MIN, - RKISP1_RSZ_SP_SRC_MAX, data_->selfPath_->video_); -} - bool RkISP1CameraConfiguration::fitsAllPaths(const StreamConfiguration &cfg) { StreamConfiguration config; config = cfg; - if (validateMainPath(&config) != Valid) + if (data_->mainPath_->validate(&config) != Valid) return false; config = cfg; - if (validateSelfPath(&config) != Valid) + if (data_->selfPath_->validate(&config) != Valid) return false; return true; @@ -611,7 +526,7 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate() /* Try to match stream without adjusting configuration. */ if (mainPathAvailable) { StreamConfiguration tryCfg = cfg; - if (validateMainPath(&tryCfg) == Valid) { + if (data_->mainPath_->validate(&tryCfg) == Valid) { mainPathAvailable = false; cfg = tryCfg; cfg.setStream(const_cast(&data_->mainPathStream_)); @@ -621,7 +536,7 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate() if (selfPathAvailable) { StreamConfiguration tryCfg = cfg; - if (validateSelfPath(&tryCfg) == Valid) { + if (data_->selfPath_->validate(&tryCfg) == Valid) { selfPathAvailable = false; cfg = tryCfg; cfg.setStream(const_cast(&data_->selfPathStream_)); @@ -632,7 +547,7 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate() /* Try to match stream allowing adjusting configuration. */ if (mainPathAvailable) { StreamConfiguration tryCfg = cfg; - if (validateMainPath(&tryCfg) == Adjusted) { + if (data_->mainPath_->validate(&tryCfg) == Adjusted) { mainPathAvailable = false; cfg = tryCfg; cfg.setStream(const_cast(&data_->mainPathStream_)); @@ -643,7 +558,7 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate() if (selfPathAvailable) { StreamConfiguration tryCfg = cfg; - if (validateSelfPath(&tryCfg) == Adjusted) { + if (data_->selfPath_->validate(&tryCfg) == Adjusted) { selfPathAvailable = false; cfg = tryCfg; cfg.setStream(const_cast(&data_->selfPathStream_)); @@ -729,32 +644,17 @@ CameraConfiguration *PipelineHandlerRkISP1::generateConfiguration(Camera *camera return nullptr; } - std::map> streamFormats; - Size maxResolution = data->sensor_->resolution(); + StreamConfiguration cfg; if (useMainPath) { + cfg = data->mainPath_->generateConfiguration( + data->sensor_->resolution()); mainPathAvailable = false; - maxResolution.boundTo(RKISP1_RSZ_MP_SRC_MAX); - for (const PixelFormat &format : RKISP1_RSZ_MP_FORMATS) - streamFormats[format] = { { - RKISP1_RSZ_MP_SRC_MIN, - maxResolution, - } }; } else { + cfg = data->selfPath_->generateConfiguration( + data->sensor_->resolution()); selfPathAvailable = false; - maxResolution.boundTo(RKISP1_RSZ_SP_SRC_MAX); - for (const PixelFormat &format : RKISP1_RSZ_SP_FORMATS) - streamFormats[format] = { { - RKISP1_RSZ_SP_SRC_MIN, - maxResolution, - } }; } - StreamFormats formats(streamFormats); - StreamConfiguration cfg(formats); - cfg.pixelFormat = formats::NV12; - cfg.size = maxResolution; - cfg.bufferCount = 4; - config->addConfiguration(cfg); } diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp index 66b5eebdcb804e24..96c18b352472a417 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp @@ -7,6 +7,7 @@ #include "rkisp1_path.h" +#include #include #include "libcamera/internal/media_device.h" @@ -17,8 +18,11 @@ namespace libcamera { LOG_DECLARE_CATEGORY(RkISP1) -RkISP1Path::RkISP1Path(const char *name) - : video_(nullptr), name_(name), resizer_(nullptr) +RkISP1Path::RkISP1Path(const char *name, const Span &formats, + const Size &minResolution, const Size &maxResolution) + : video_(nullptr), name_(name), formats_(formats), + minResolution_(minResolution), maxResolution_(maxResolution), + resizer_(nullptr) { } @@ -44,6 +48,58 @@ bool RkISP1Path::init(MediaDevice *media) return true; } +StreamConfiguration RkISP1Path::generateConfiguration(const Size &resolution) +{ + Size maxResolution = resolution; + maxResolution.boundTo(maxResolution_); + + std::map> streamFormats; + for (const PixelFormat &format : formats_) + streamFormats[format] = { { minResolution_, maxResolution } }; + + StreamFormats formats(streamFormats); + StreamConfiguration cfg(formats); + cfg.pixelFormat = formats::NV12; + cfg.size = maxResolution; + cfg.bufferCount = RKISP1_BUFFER_COUNT; + + return cfg; +} + +CameraConfiguration::Status RkISP1Path::validate(StreamConfiguration *cfg) +{ + const StreamConfiguration reqCfg = *cfg; + CameraConfiguration::Status status = CameraConfiguration::Valid; + + if (std::find(formats_.begin(), formats_.end(), cfg->pixelFormat) == + formats_.end()) + cfg->pixelFormat = formats::NV12; + + cfg->size.boundTo(maxResolution_); + cfg->size.expandTo(minResolution_); + cfg->bufferCount = RKISP1_BUFFER_COUNT; + + V4L2DeviceFormat format = {}; + format.fourcc = video_->toV4L2PixelFormat(cfg->pixelFormat); + format.size = cfg->size; + + int ret = video_->tryFormat(&format); + if (ret) + return CameraConfiguration::Invalid; + + cfg->stride = format.planes[0].bpl; + cfg->frameSize = format.planes[0].size; + + if (cfg->pixelFormat != reqCfg.pixelFormat || cfg->size != reqCfg.size) { + LOG(RkISP1, Debug) + << "Adjusting format from " << reqCfg.toString() + << " to " << cfg->toString(); + status = CameraConfiguration::Adjusted; + } + + return status; +} + int RkISP1Path::configure(const StreamConfiguration &config, const V4L2SubdeviceFormat &inputFormat) { @@ -93,13 +149,43 @@ int RkISP1Path::configure(const StreamConfiguration &config, return 0; } +namespace { +constexpr Size RKISP1_RSZ_MP_SRC_MIN{ 32, 16 }; +constexpr Size RKISP1_RSZ_MP_SRC_MAX{ 4416, 3312 }; +constexpr std::array RKISP1_RSZ_MP_FORMATS{ + formats::YUYV, + formats::YVYU, + formats::VYUY, + formats::NV16, + formats::NV61, + formats::NV21, + formats::NV12, + /* \todo Add support for 8-bit greyscale to DRM formats */ +}; + +constexpr Size RKISP1_RSZ_SP_SRC_MIN{ 32, 16 }; +constexpr Size RKISP1_RSZ_SP_SRC_MAX{ 1920, 1920 }; +constexpr std::array RKISP1_RSZ_SP_FORMATS{ + formats::YUYV, + formats::YVYU, + formats::VYUY, + formats::NV16, + formats::NV61, + formats::NV21, + formats::NV12, + /* \todo Add support for BGR888 and RGB565 */ +}; +} /* namespace */ + RkISP1MainPath::RkISP1MainPath() - : RkISP1Path("main") + : RkISP1Path("main", RKISP1_RSZ_MP_FORMATS, + RKISP1_RSZ_MP_SRC_MIN, RKISP1_RSZ_MP_SRC_MAX) { } RkISP1SelfPath::RkISP1SelfPath() - : RkISP1Path("self") + : RkISP1Path("self", RKISP1_RSZ_SP_FORMATS, + RKISP1_RSZ_SP_SRC_MIN, RKISP1_RSZ_SP_SRC_MAX) { } diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.h b/src/libcamera/pipeline/rkisp1/rkisp1_path.h index 6eb01529d2fddb1c..7433ad03387dce0b 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.h +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.h @@ -7,6 +7,13 @@ #ifndef __LIBCAMERA_PIPELINE_RKISP1_PATH_H__ #define __LIBCAMERA_PIPELINE_RKISP1_PATH_H__ +#include + +#include +#include +#include +#include + namespace libcamera { class MediaDevice; @@ -18,11 +25,15 @@ struct V4L2SubdeviceFormat; class RkISP1Path { public: - RkISP1Path(const char *name); + RkISP1Path(const char *name, const Span &formats, + const Size &minResolution, const Size &maxResolution); ~RkISP1Path(); bool init(MediaDevice *media); + StreamConfiguration generateConfiguration(const Size &resolution); + CameraConfiguration::Status validate(StreamConfiguration *cfg); + int configure(const StreamConfiguration &config, const V4L2SubdeviceFormat &inputFormat); @@ -30,8 +41,14 @@ public: V4L2VideoDevice *video_; private: + static constexpr unsigned int RKISP1_BUFFER_COUNT = 4; + const char *name_; + const Span formats_; + const Size minResolution_; + const Size maxResolution_; + V4L2Subdevice *resizer_; }; From patchwork Tue Sep 29 01:43: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: 9849 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 13988C3B5B for ; Tue, 29 Sep 2020 01:43:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E240062150; Tue, 29 Sep 2020 03:43:55 +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 EC0CD62033 for ; Tue, 29 Sep 2020 03:43:53 +0200 (CEST) X-Halon-ID: 38536656-01f5-11eb-b295-0050569116f7 Authorized-sender: niklas.soderlund@fsdn.se Received: from bismarck.berto.se (p54ac52a8.dip0.t-ipconnect.de [84.172.82.168]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 38536656-01f5-11eb-b295-0050569116f7; Tue, 29 Sep 2020 03:43:50 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 29 Sep 2020 03:43:31 +0200 Message-Id: <20200929014334.49719-5-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929014334.49719-1-niklas.soderlund@ragnatech.se> References: <20200929014334.49719-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 4/7] libcamera: pipeline: rkisp1: Add wrappers for accessing the path video device 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" As a step to be able to make RkISP1Path::video_ private add simple wrappers for buffer handling. There is no functional change. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- * Changes since v3 - Inline exportBuffers(). --- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 12 ++++++------ src/libcamera/pipeline/rkisp1/rkisp1_path.h | 13 ++++++++++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 6c81faa818e2b11a..7823fd91866a473a 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -403,10 +403,10 @@ protected: pipe_->stat_->queueBuffer(info->statBuffer); if (info->mainPathBuffer) - pipe_->mainPath_.video_->queueBuffer(info->mainPathBuffer); + pipe_->mainPath_.queueBuffer(info->mainPathBuffer); if (info->selfPathBuffer) - pipe_->selfPath_.video_->queueBuffer(info->selfPathBuffer); + pipe_->selfPath_.queueBuffer(info->selfPathBuffer); } private: @@ -747,9 +747,9 @@ int PipelineHandlerRkISP1::exportFrameBuffers([[maybe_unused]] Camera *camera, S unsigned int count = stream->configuration().bufferCount; if (stream == &data->mainPathStream_) - return mainPath_.video_->exportBuffers(count, buffers); + return mainPath_.exportBuffers(count, buffers); else if (stream == &data->selfPathStream_) - return selfPath_.video_->exportBuffers(count, buffers); + return selfPath_.exportBuffers(count, buffers); return -EINVAL; } @@ -1149,8 +1149,8 @@ bool PipelineHandlerRkISP1::match(DeviceEnumerator *enumerator) if (!selfPath_.init(media_)) return false; - mainPath_.video_->bufferReady.connect(this, &PipelineHandlerRkISP1::bufferReady); - selfPath_.video_->bufferReady.connect(this, &PipelineHandlerRkISP1::bufferReady); + mainPath_.bufferReady().connect(this, &PipelineHandlerRkISP1::bufferReady); + selfPath_.bufferReady().connect(this, &PipelineHandlerRkISP1::bufferReady); stat_->bufferReady.connect(this, &PipelineHandlerRkISP1::statReady); param_->bufferReady.connect(this, &PipelineHandlerRkISP1::paramReady); diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.h b/src/libcamera/pipeline/rkisp1/rkisp1_path.h index 7433ad03387dce0b..377772ca73877702 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.h +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.h @@ -12,13 +12,15 @@ #include #include #include +#include #include +#include "libcamera/internal/v4l2_videodevice.h" + namespace libcamera { class MediaDevice; class V4L2Subdevice; -class V4L2VideoDevice; struct StreamConfiguration; struct V4L2SubdeviceFormat; @@ -37,6 +39,15 @@ public: int configure(const StreamConfiguration &config, const V4L2SubdeviceFormat &inputFormat); + int exportBuffers(unsigned int bufferCount, + std::vector> *buffers) + { + return video_->exportBuffers(bufferCount, buffers); + } + + int queueBuffer(FrameBuffer *buffer) { return video_->queueBuffer(buffer); } + Signal &bufferReady() { return video_->bufferReady; } + /* \todo Make video private. */ V4L2VideoDevice *video_; From patchwork Tue Sep 29 01:43: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: 9850 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 8696AC3B5B for ; Tue, 29 Sep 2020 01:43:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 30F276215B; Tue, 29 Sep 2020 03:43:56 +0200 (CEST) Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B491D6213B for ; Tue, 29 Sep 2020 03:43:54 +0200 (CEST) X-Halon-ID: 3962f9f0-01f5-11eb-b295-0050569116f7 Authorized-sender: niklas.soderlund@fsdn.se Received: from bismarck.berto.se (p54ac52a8.dip0.t-ipconnect.de [84.172.82.168]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 3962f9f0-01f5-11eb-b295-0050569116f7; Tue, 29 Sep 2020 03:43:50 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 29 Sep 2020 03:43:32 +0200 Message-Id: <20200929014334.49719-6-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929014334.49719-1-niklas.soderlund@ragnatech.se> References: <20200929014334.49719-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 5/7] libcamera: pipeline: rkisp1: Move start and stop of path to RkISP1Path 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" Move the start and stop of a path to RkISP1Path. This allows the importing of buffers to be moved closer the path start/stop simplifying the code. Also by adding a simple running tracker the error logic in PipelineHandlerRkISP1 can be simplified as stop() can always be called. This also removes all external users of RkISP1Path::video_ so it can be made private. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- * Changes since v3 - Add missing space in Error message. --- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 53 ++----------------- src/libcamera/pipeline/rkisp1/rkisp1_path.cpp | 42 ++++++++++++++- src/libcamera/pipeline/rkisp1/rkisp1_path.h | 8 +-- 3 files changed, 50 insertions(+), 53 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 7823fd91866a473a..2eaf7b491d13397b 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -765,20 +765,6 @@ int PipelineHandlerRkISP1::allocateBuffers(Camera *camera) data->selfPathStream_.configuration().bufferCount, }); - if (data->mainPathActive_) { - ret = mainPath_.video_->importBuffers( - data->mainPathStream_.configuration().bufferCount); - if (ret < 0) - goto error; - } - - if (data->selfPathActive_) { - ret = selfPath_.video_->importBuffers( - data->selfPathStream_.configuration().bufferCount); - if (ret < 0) - goto error; - } - ret = param_->allocateBuffers(maxCount, ¶mBuffers_); if (ret < 0) goto error; @@ -808,8 +794,6 @@ int PipelineHandlerRkISP1::allocateBuffers(Camera *camera) error: paramBuffers_.clear(); statBuffers_.clear(); - mainPath_.video_->releaseBuffers(); - selfPath_.video_->releaseBuffers(); return ret; } @@ -840,12 +824,6 @@ int PipelineHandlerRkISP1::freeBuffers(Camera *camera) if (stat_->releaseBuffers()) LOG(RkISP1, Error) << "Failed to release stat buffers"; - if (mainPath_.video_->releaseBuffers()) - LOG(RkISP1, Error) << "Failed to release main path buffers"; - - if (selfPath_.video_->releaseBuffers()) - LOG(RkISP1, Error) << "Failed to release self path buffers"; - return 0; } @@ -891,15 +869,12 @@ int PipelineHandlerRkISP1::start(Camera *camera) std::map streamConfig; if (data->mainPathActive_) { - ret = mainPath_.video_->streamOn(); + ret = mainPath_.start(); if (ret) { param_->streamOff(); stat_->streamOff(); data->ipa_->stop(); freeBuffers(camera); - - LOG(RkISP1, Error) - << "Failed to start main path " << camera->id(); return ret; } @@ -910,18 +885,13 @@ int PipelineHandlerRkISP1::start(Camera *camera) } if (data->selfPathActive_) { - ret = selfPath_.video_->streamOn(); + ret = selfPath_.start(); if (ret) { - if (data->mainPathActive_) - mainPath_.video_->streamOff(); - + mainPath_.stop(); param_->streamOff(); stat_->streamOff(); data->ipa_->stop(); freeBuffers(camera); - - LOG(RkISP1, Error) - << "Failed to start self path " << camera->id(); return ret; } @@ -958,21 +928,8 @@ void PipelineHandlerRkISP1::stop(Camera *camera) RkISP1CameraData *data = cameraData(camera); int ret; - if (data->selfPathActive_) { - ret = selfPath_.video_->streamOff(); - if (ret) - LOG(RkISP1, Warning) - << "Failed to stop self path for " - << camera->id(); - } - - if (data->mainPathActive_) { - ret = mainPath_.video_->streamOff(); - if (ret) - LOG(RkISP1, Warning) - << "Failed to stop main path for " - << camera->id(); - } + selfPath_.stop(); + mainPath_.stop(); ret = stat_->streamOff(); if (ret) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp index 96c18b352472a417..9f1706c78f41465b 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp @@ -20,9 +20,9 @@ LOG_DECLARE_CATEGORY(RkISP1) RkISP1Path::RkISP1Path(const char *name, const Span &formats, const Size &minResolution, const Size &maxResolution) - : video_(nullptr), name_(name), formats_(formats), + : name_(name), running_(false), formats_(formats), minResolution_(minResolution), maxResolution_(maxResolution), - resizer_(nullptr) + resizer_(nullptr), video_(nullptr) { } @@ -149,6 +149,44 @@ int RkISP1Path::configure(const StreamConfiguration &config, return 0; } +int RkISP1Path::start() +{ + int ret; + + if (running_) + return -EBUSY; + + ret = video_->importBuffers(RKISP1_BUFFER_COUNT); + if (ret) + return ret; + + ret = video_->streamOn(); + if (ret) { + LOG(RkISP1, Error) + << "Failed to start " << name_ << " path"; + + video_->releaseBuffers(); + return ret; + } + + running_ = true; + + return 0; +} + +void RkISP1Path::stop() +{ + if (!running_) + return; + + if (video_->streamOff()) + LOG(RkISP1, Warning) << "Failed to stop " << name_ << " path"; + + video_->releaseBuffers(); + + running_ = false; +} + namespace { constexpr Size RKISP1_RSZ_MP_SRC_MIN{ 32, 16 }; constexpr Size RKISP1_RSZ_MP_SRC_MAX{ 4416, 3312 }; diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.h b/src/libcamera/pipeline/rkisp1/rkisp1_path.h index 377772ca73877702..e2eb1be9a445ba41 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.h +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.h @@ -45,22 +45,24 @@ public: return video_->exportBuffers(bufferCount, buffers); } + int start(); + void stop(); + int queueBuffer(FrameBuffer *buffer) { return video_->queueBuffer(buffer); } Signal &bufferReady() { return video_->bufferReady; } - /* \todo Make video private. */ - V4L2VideoDevice *video_; - private: static constexpr unsigned int RKISP1_BUFFER_COUNT = 4; const char *name_; + bool running_; const Span formats_; const Size minResolution_; const Size maxResolution_; V4L2Subdevice *resizer_; + V4L2VideoDevice *video_; }; class RkISP1MainPath : public RkISP1Path From patchwork Tue Sep 29 01:43:33 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: 9851 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 D8B18C3B5B for ; Tue, 29 Sep 2020 01:43:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B494862140; Tue, 29 Sep 2020 03:43: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 6D0E460BD4 for ; Tue, 29 Sep 2020 03:43:55 +0200 (CEST) X-Halon-ID: 39da3677-01f5-11eb-b295-0050569116f7 Authorized-sender: niklas.soderlund@fsdn.se Received: from bismarck.berto.se (p54ac52a8.dip0.t-ipconnect.de [84.172.82.168]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 39da3677-01f5-11eb-b295-0050569116f7; Tue, 29 Sep 2020 03:43:51 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 29 Sep 2020 03:43:33 +0200 Message-Id: <20200929014334.49719-7-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929014334.49719-1-niklas.soderlund@ragnatech.se> References: <20200929014334.49719-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 6/7] libcamera: pipeline: rkisp1: Move path link handling to RkISP1Path 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" Move the path link handling to RkISP1Path, there is no functional change. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- * Changes since v3 - Rename enable() to setEnabled(bool enable) to make it less confusing for users. --- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 11 ++--------- src/libcamera/pipeline/rkisp1/rkisp1_path.cpp | 6 +++++- src/libcamera/pipeline/rkisp1/rkisp1_path.h | 4 ++++ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 2eaf7b491d13397b..72593a06b0f502b0 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -1010,20 +1010,13 @@ int PipelineHandlerRkISP1::initLinks(const Camera *camera, } for (const StreamConfiguration &cfg : config) { - MediaLink *link; if (cfg.stream() == &data->mainPathStream_) - link = media_->link("rkisp1_isp", 2, - "rkisp1_resizer_mainpath", 0); + ret = data->mainPath_->setEnabled(true); else if (cfg.stream() == &data->selfPathStream_) - link = media_->link("rkisp1_isp", 2, - "rkisp1_resizer_selfpath", 0); + ret = data->selfPath_->setEnabled(true); else return -EINVAL; - if (!link) - return -ENODEV; - - ret = link->setEnabled(true); if (ret < 0) return ret; } diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp index 9f1706c78f41465b..0ce133dd04048cbb 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp @@ -22,7 +22,7 @@ RkISP1Path::RkISP1Path(const char *name, const Span &formats, const Size &minResolution, const Size &maxResolution) : name_(name), running_(false), formats_(formats), minResolution_(minResolution), maxResolution_(maxResolution), - resizer_(nullptr), video_(nullptr) + resizer_(nullptr), video_(nullptr), link_(nullptr) { } @@ -45,6 +45,10 @@ bool RkISP1Path::init(MediaDevice *media) if (video_->open() < 0) return false; + link_ = media->link("rkisp1_isp", 2, resizer, 0); + if (!link_) + return false; + return true; } diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.h b/src/libcamera/pipeline/rkisp1/rkisp1_path.h index e2eb1be9a445ba41..98863a2e693729be 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.h +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.h @@ -15,6 +15,7 @@ #include #include +#include "libcamera/internal/media_object.h" #include "libcamera/internal/v4l2_videodevice.h" namespace libcamera { @@ -33,6 +34,8 @@ public: bool init(MediaDevice *media); + int setEnabled(bool enable) { return link_->setEnabled(enable); } + StreamConfiguration generateConfiguration(const Size &resolution); CameraConfiguration::Status validate(StreamConfiguration *cfg); @@ -63,6 +66,7 @@ private: V4L2Subdevice *resizer_; V4L2VideoDevice *video_; + MediaLink *link_; }; class RkISP1MainPath : public RkISP1Path From patchwork Tue Sep 29 01:43:34 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: 9852 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 2CF2EC3B5E for ; Tue, 29 Sep 2020 01:43:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EE5C362146; Tue, 29 Sep 2020 03:43: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 39C6E62048 for ; Tue, 29 Sep 2020 03:43:56 +0200 (CEST) X-Halon-ID: 3a46364f-01f5-11eb-b295-0050569116f7 Authorized-sender: niklas.soderlund@fsdn.se Received: from bismarck.berto.se (p54ac52a8.dip0.t-ipconnect.de [84.172.82.168]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 3a46364f-01f5-11eb-b295-0050569116f7; Tue, 29 Sep 2020 03:43:52 +0200 (CEST) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Tue, 29 Sep 2020 03:43:34 +0200 Message-Id: <20200929014334.49719-8-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929014334.49719-1-niklas.soderlund@ragnatech.se> References: <20200929014334.49719-1-niklas.soderlund@ragnatech.se> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 7/7] libcamera: pipeline: rkisp1: Use the media link to track if a path is enabled 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 tracking if a path is enable or not use the media graph link status. There is no functional change. Signed-off-by: Niklas Söderlund Reviewed-by: Laurent Pinchart --- * Changes since v3 - Update spelling in commit message. - Do not check path status in RkISP1Path::start() instead keep check in pipeline start(). --- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 26 +++++++-------------- src/libcamera/pipeline/rkisp1/rkisp1_path.h | 1 + 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 72593a06b0f502b0..48d00970aba3beda 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -122,8 +122,7 @@ public: RkISP1CameraData(PipelineHandler *pipe, RkISP1MainPath *mainPath, RkISP1SelfPath *selfPath) : CameraData(pipe), sensor_(nullptr), frame_(0), - frameInfo_(pipe), mainPath_(mainPath), selfPath_(selfPath), - mainPathActive_(false), selfPathActive_(false) + frameInfo_(pipe), mainPath_(mainPath), selfPath_(selfPath) { } @@ -145,9 +144,6 @@ public: RkISP1MainPath *mainPath_; RkISP1SelfPath *selfPath_; - bool mainPathActive_; - bool selfPathActive_; - private: void queueFrameAction(unsigned int frame, const IPAOperationData &action); @@ -709,20 +705,14 @@ int PipelineHandlerRkISP1::configure(Camera *camera, CameraConfiguration *c) LOG(RkISP1, Debug) << "ISP output pad configured with " << format.toString(); - data->mainPathActive_ = false; - data->selfPathActive_ = false; for (const StreamConfiguration &cfg : *config) { - if (cfg.stream() == &data->mainPathStream_) { + if (cfg.stream() == &data->mainPathStream_) ret = mainPath_.configure(cfg, format); - if (ret) - return ret; - data->mainPathActive_ = true; - } else { + else ret = selfPath_.configure(cfg, format); - if (ret) - return ret; - data->selfPathActive_ = true; - } + + if (ret) + return ret; } V4L2DeviceFormat paramFormat = {}; @@ -868,7 +858,7 @@ int PipelineHandlerRkISP1::start(Camera *camera) std::map streamConfig; - if (data->mainPathActive_) { + if (data->mainPath_->isEnabled()) { ret = mainPath_.start(); if (ret) { param_->streamOff(); @@ -884,7 +874,7 @@ int PipelineHandlerRkISP1::start(Camera *camera) }; } - if (data->selfPathActive_) { + if (data->selfPath_->isEnabled()) { ret = selfPath_.start(); if (ret) { mainPath_.stop(); diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.h b/src/libcamera/pipeline/rkisp1/rkisp1_path.h index 98863a2e693729be..f34d6bacd49c8f02 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.h +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.h @@ -35,6 +35,7 @@ public: bool init(MediaDevice *media); int setEnabled(bool enable) { return link_->setEnabled(enable); } + bool isEnabled() { return link_->flags() & MEDIA_LNK_FL_ENABLED; } StreamConfiguration generateConfiguration(const Size &resolution); CameraConfiguration::Status validate(StreamConfiguration *cfg);