[{"id":12852,"web_url":"https://patchwork.libcamera.org/comment/12852/","msgid":"<20200929020010.GP14614@pendragon.ideasonboard.com>","date":"2020-09-29T02:00:10","subject":"Re: [libcamera-devel] [PATCH v4 5/7] libcamera: pipeline: rkisp1:\n\tMove start and stop of path to RkISP1Path","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Niklas,\n\nThank you for the patch.\n\nOn Tue, Sep 29, 2020 at 03:43:32AM +0200, Niklas Söderlund wrote:\n> Move the start and stop of a path to RkISP1Path. This allows the\n> importing of buffers to be moved closer the path start/stop simplifying\n> the code. Also by adding a simple running tracker the error logic in\n> PipelineHandlerRkISP1 can be simplified as stop() can always be called.\n> \n> This also removes all external users of RkISP1Path::video_ so it can be\n> made private.\n> \n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n> * Changes since v3\n> - Add missing space in Error message.\n> ---\n>  src/libcamera/pipeline/rkisp1/rkisp1.cpp      | 53 ++-----------------\n>  src/libcamera/pipeline/rkisp1/rkisp1_path.cpp | 42 ++++++++++++++-\n>  src/libcamera/pipeline/rkisp1/rkisp1_path.h   |  8 +--\n>  3 files changed, 50 insertions(+), 53 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> index 7823fd91866a473a..2eaf7b491d13397b 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> @@ -765,20 +765,6 @@ int PipelineHandlerRkISP1::allocateBuffers(Camera *camera)\n>  \t\tdata->selfPathStream_.configuration().bufferCount,\n>  \t});\n>  \n> -\tif (data->mainPathActive_) {\n> -\t\tret = mainPath_.video_->importBuffers(\n> -\t\t\tdata->mainPathStream_.configuration().bufferCount);\n> -\t\tif (ret < 0)\n> -\t\t\tgoto error;\n> -\t}\n> -\n> -\tif (data->selfPathActive_) {\n> -\t\tret = selfPath_.video_->importBuffers(\n> -\t\t\tdata->selfPathStream_.configuration().bufferCount);\n> -\t\tif (ret < 0)\n> -\t\t\tgoto error;\n> -\t}\n> -\n>  \tret = param_->allocateBuffers(maxCount, &paramBuffers_);\n>  \tif (ret < 0)\n>  \t\tgoto error;\n> @@ -808,8 +794,6 @@ int PipelineHandlerRkISP1::allocateBuffers(Camera *camera)\n>  error:\n>  \tparamBuffers_.clear();\n>  \tstatBuffers_.clear();\n> -\tmainPath_.video_->releaseBuffers();\n> -\tselfPath_.video_->releaseBuffers();\n>  \n>  \treturn ret;\n>  }\n> @@ -840,12 +824,6 @@ int PipelineHandlerRkISP1::freeBuffers(Camera *camera)\n>  \tif (stat_->releaseBuffers())\n>  \t\tLOG(RkISP1, Error) << \"Failed to release stat buffers\";\n>  \n> -\tif (mainPath_.video_->releaseBuffers())\n> -\t\tLOG(RkISP1, Error) << \"Failed to release main path buffers\";\n> -\n> -\tif (selfPath_.video_->releaseBuffers())\n> -\t\tLOG(RkISP1, Error) << \"Failed to release self path buffers\";\n> -\n>  \treturn 0;\n>  }\n>  \n> @@ -891,15 +869,12 @@ int PipelineHandlerRkISP1::start(Camera *camera)\n>  \tstd::map<unsigned int, IPAStream> streamConfig;\n>  \n>  \tif (data->mainPathActive_) {\n> -\t\tret = mainPath_.video_->streamOn();\n> +\t\tret = mainPath_.start();\n>  \t\tif (ret) {\n>  \t\t\tparam_->streamOff();\n>  \t\t\tstat_->streamOff();\n>  \t\t\tdata->ipa_->stop();\n>  \t\t\tfreeBuffers(camera);\n> -\n> -\t\t\tLOG(RkISP1, Error)\n> -\t\t\t\t<< \"Failed to start main path \" << camera->id();\n>  \t\t\treturn ret;\n>  \t\t}\n>  \n> @@ -910,18 +885,13 @@ int PipelineHandlerRkISP1::start(Camera *camera)\n>  \t}\n>  \n>  \tif (data->selfPathActive_) {\n> -\t\tret = selfPath_.video_->streamOn();\n> +\t\tret = selfPath_.start();\n>  \t\tif (ret) {\n> -\t\t\tif (data->mainPathActive_)\n> -\t\t\t\tmainPath_.video_->streamOff();\n> -\n> +\t\t\tmainPath_.stop();\n>  \t\t\tparam_->streamOff();\n>  \t\t\tstat_->streamOff();\n>  \t\t\tdata->ipa_->stop();\n>  \t\t\tfreeBuffers(camera);\n> -\n> -\t\t\tLOG(RkISP1, Error)\n> -\t\t\t\t<< \"Failed to start self path \" << camera->id();\n>  \t\t\treturn ret;\n>  \t\t}\n>  \n> @@ -958,21 +928,8 @@ void PipelineHandlerRkISP1::stop(Camera *camera)\n>  \tRkISP1CameraData *data = cameraData(camera);\n>  \tint ret;\n>  \n> -\tif (data->selfPathActive_) {\n> -\t\tret = selfPath_.video_->streamOff();\n> -\t\tif (ret)\n> -\t\t\tLOG(RkISP1, Warning)\n> -\t\t\t\t<< \"Failed to stop self path for \"\n> -\t\t\t\t<< camera->id();\n> -\t}\n> -\n> -\tif (data->mainPathActive_) {\n> -\t\tret = mainPath_.video_->streamOff();\n> -\t\tif (ret)\n> -\t\t\tLOG(RkISP1, Warning)\n> -\t\t\t\t<< \"Failed to stop main path for \"\n> -\t\t\t\t<< camera->id();\n> -\t}\n> +\tselfPath_.stop();\n> +\tmainPath_.stop();\n>  \n>  \tret = stat_->streamOff();\n>  \tif (ret)\n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\n> index 96c18b352472a417..9f1706c78f41465b 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.cpp\n> @@ -20,9 +20,9 @@ LOG_DECLARE_CATEGORY(RkISP1)\n>  \n>  RkISP1Path::RkISP1Path(const char *name, const Span<const PixelFormat> &formats,\n>  \t\t       const Size &minResolution, const Size &maxResolution)\n> -\t: video_(nullptr), name_(name), formats_(formats),\n> +\t: name_(name), running_(false), formats_(formats),\n>  \t  minResolution_(minResolution), maxResolution_(maxResolution),\n> -\t  resizer_(nullptr)\n> +\t  resizer_(nullptr), video_(nullptr)\n>  {\n>  }\n>  \n> @@ -149,6 +149,44 @@ int RkISP1Path::configure(const StreamConfiguration &config,\n>  \treturn 0;\n>  }\n>  \n> +int RkISP1Path::start()\n> +{\n> +\tint ret;\n> +\n> +\tif (running_)\n> +\t\treturn -EBUSY;\n> +\n> +\tret = video_->importBuffers(RKISP1_BUFFER_COUNT);\n\nCould you add a todo comment to track making the buffer count\nconfigurable ? With that,\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\tif (ret)\n> +\t\treturn ret;\n> +\n> +\tret = video_->streamOn();\n> +\tif (ret) {\n> +\t\tLOG(RkISP1, Error)\n> +\t\t\t<< \"Failed to start \" << name_ << \" path\";\n> +\n> +\t\tvideo_->releaseBuffers();\n> +\t\treturn ret;\n> +\t}\n> +\n> +\trunning_ = true;\n> +\n> +\treturn 0;\n> +}\n> +\n> +void RkISP1Path::stop()\n> +{\n> +\tif (!running_)\n> +\t\treturn;\n> +\n> +\tif (video_->streamOff())\n> +\t\tLOG(RkISP1, Warning) << \"Failed to stop \" << name_ << \" path\";\n> +\n> +\tvideo_->releaseBuffers();\n> +\n> +\trunning_ = false;\n> +}\n> +\n>  namespace {\n>  constexpr Size RKISP1_RSZ_MP_SRC_MIN{ 32, 16 };\n>  constexpr Size RKISP1_RSZ_MP_SRC_MAX{ 4416, 3312 };\n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1_path.h b/src/libcamera/pipeline/rkisp1/rkisp1_path.h\n> index 377772ca73877702..e2eb1be9a445ba41 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1_path.h\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1_path.h\n> @@ -45,22 +45,24 @@ public:\n>  \t\treturn video_->exportBuffers(bufferCount, buffers);\n>  \t}\n>  \n> +\tint start();\n> +\tvoid stop();\n> +\n>  \tint queueBuffer(FrameBuffer *buffer) { return video_->queueBuffer(buffer); }\n>  \tSignal<FrameBuffer *> &bufferReady() { return video_->bufferReady; }\n>  \n> -\t/* \\todo Make video private. */\n> -\tV4L2VideoDevice *video_;\n> -\n>  private:\n>  \tstatic constexpr unsigned int RKISP1_BUFFER_COUNT = 4;\n>  \n>  \tconst char *name_;\n> +\tbool running_;\n>  \n>  \tconst Span<const PixelFormat> formats_;\n>  \tconst Size minResolution_;\n>  \tconst Size maxResolution_;\n>  \n>  \tV4L2Subdevice *resizer_;\n> +\tV4L2VideoDevice *video_;\n>  };\n>  \n>  class RkISP1MainPath : public RkISP1Path","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 55A70C3B5C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 29 Sep 2020 02:00:48 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B036E61FE5;\n\tTue, 29 Sep 2020 04:00:47 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6433D60365\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 29 Sep 2020 04:00:46 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 51885540;\n\tTue, 29 Sep 2020 04:00:45 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"agAKhN5y\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1601344845;\n\tbh=wQp7HCvMTAX+9aJg3mxoQRabmhe7aBry+SawBxBtJ8Y=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=agAKhN5ysFTCG7OZdAErOFKvc0W3/U0oF6s4GP4FAIK0ubhcpG24s1UnZfQ2N04XC\n\tD12RRBJAIwMDiJi50ZVNASLaNUWEF5O7wXOd29yqIJOHnuEuLFy9aTQ8p27Gr5hx1C\n\tZ8nq8za0icFvETwL8xiGuORieE2RskN3cPwSHIOA=","Date":"Tue, 29 Sep 2020 05:00:10 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Message-ID":"<20200929020010.GP14614@pendragon.ideasonboard.com>","References":"<20200929014334.49719-1-niklas.soderlund@ragnatech.se>\n\t<20200929014334.49719-6-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20200929014334.49719-6-niklas.soderlund@ragnatech.se>","Subject":"Re: [libcamera-devel] [PATCH v4 5/7] libcamera: pipeline: rkisp1:\n\tMove start and stop of path to RkISP1Path","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]