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