[{"id":14261,"web_url":"https://patchwork.libcamera.org/comment/14261/","msgid":"<20201217141805.ptn24utghjg6cgia@uno.localdomain>","date":"2020-12-17T14:18:05","subject":"Re: [libcamera-devel] [PATCH v4 6/8] libcamera: pipeline: rkisp1:\n\tUse delayed controls","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Niklas,\n\nOn Tue, Dec 15, 2020 at 01:48:09AM +0100, Niklas Söderlund wrote:\n> Instead of setting controls using the RkISP1 local Timeline helper use\n> the DelayedControls. The result is the same, the controls are applied\n> with a delay.\n>\n> The values of the delays are however different between the two methods.\n> The values used in the Timeline solution were chosen after some\n> experimentation and the values used in DelayedControls are taken from a\n> generic sensor. None of the two are a perfect match as the delays can be\n> different for different sensors used with the pipeline.\n>\n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks\n  j\n> ---\n> * Changes since v3\n> - Rewrite to not use CameraSensor.\n> ---\n>  src/libcamera/pipeline/rkisp1/rkisp1.cpp | 43 +++++++++++++-----------\n>  1 file changed, 23 insertions(+), 20 deletions(-)\n>\n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> index 4d98c9027f42c759..513a60b04e5f2e21 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> @@ -23,6 +23,7 @@\n>  #include <libcamera/stream.h>\n>\n>  #include \"libcamera/internal/camera_sensor.h\"\n> +#include \"libcamera/internal/delayed_controls.h\"\n>  #include \"libcamera/internal/device_enumerator.h\"\n>  #include \"libcamera/internal/ipa_manager.h\"\n>  #include \"libcamera/internal/log.h\"\n> @@ -136,6 +137,7 @@ public:\n>  \tStream mainPathStream_;\n>  \tStream selfPathStream_;\n>  \tCameraSensor *sensor_;\n> +\tstd::unique_ptr<DelayedControls> delayedCtrls_;\n>  \tunsigned int frame_;\n>  \tstd::vector<IPABuffer> ipaBuffers_;\n>  \tRkISP1Frames frameInfo_;\n> @@ -345,23 +347,6 @@ RkISP1FrameInfo *RkISP1Frames::find(Request *request)\n>  \treturn nullptr;\n>  }\n>\n> -class RkISP1ActionSetSensor : public FrameAction\n> -{\n> -public:\n> -\tRkISP1ActionSetSensor(unsigned int frame, CameraSensor *sensor, const ControlList &controls)\n> -\t\t: FrameAction(frame, SetSensor), sensor_(sensor), controls_(controls) {}\n> -\n> -protected:\n> -\tvoid run() override\n> -\t{\n> -\t\tsensor_->setControls(&controls_);\n> -\t}\n> -\n> -private:\n> -\tCameraSensor *sensor_;\n> -\tControlList controls_;\n> -};\n> -\n>  class RkISP1ActionQueueBuffers : public FrameAction\n>  {\n>  public:\n> @@ -429,9 +414,7 @@ void RkISP1CameraData::queueFrameAction(unsigned int frame,\n>  \tswitch (action.operation) {\n>  \tcase RKISP1_IPA_ACTION_V4L2_SET: {\n>  \t\tconst ControlList &controls = action.controls[0];\n> -\t\ttimeline_.scheduleAction(std::make_unique<RkISP1ActionSetSensor>(frame,\n> -\t\t\t\t\t\t\t\t\t\t sensor_,\n> -\t\t\t\t\t\t\t\t\t\t controls));\n> +\t\tdelayedCtrls_->push(controls);\n>  \t\tbreak;\n>  \t}\n>  \tcase RKISP1_IPA_ACTION_PARAM_FILLED: {\n> @@ -898,6 +881,8 @@ int PipelineHandlerRkISP1::start(Camera *camera, [[maybe_unused]] ControlList *c\n>  \t\t};\n>  \t}\n>\n> +\tisp_->setFrameStartEnabled(true);\n> +\n>  \tactiveCamera_ = camera;\n>\n>  \t/* Inform IPA of stream configuration and sensor controls. */\n> @@ -925,6 +910,8 @@ void PipelineHandlerRkISP1::stop(Camera *camera)\n>  \tRkISP1CameraData *data = cameraData(camera);\n>  \tint ret;\n>\n> +\tisp_->setFrameStartEnabled(false);\n> +\n>  \tselfPath_.stop();\n>  \tmainPath_.stop();\n>\n> @@ -1043,6 +1030,22 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor)\n>  \t/* Initialize the camera properties. */\n>  \tdata->properties_ = data->sensor_->properties();\n>\n> +\t/*\n> +\t * \\todo Read dealy values from the sensor itself or from a\n> +\t * a sensor database. For now use generic values taken from\n> +\t * the Raspberry Pi and listed as generic values.\n> +\t */\n> +\tstd::unordered_map<uint32_t, unsigned int> delays = {\n> +\t\t{ V4L2_CID_ANALOGUE_GAIN, 1 },\n> +\t\t{ V4L2_CID_EXPOSURE, 2 },\n> +\t};\n> +\n> +\tdata->delayedCtrls_ =\n> +\t\tstd::make_unique<DelayedControls>(data->sensor_->device(),\n> +\t\t\t\t\t\t  delays);\n> +\tisp_->frameStart.connect(data->delayedCtrls_.get(),\n> +\t\t\t\t &DelayedControls::applyControls);\n> +\n>  \tret = data->loadIPA();\n>  \tif (ret)\n>  \t\treturn ret;\n> --\n> 2.29.2\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","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 41653C0F1A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 17 Dec 2020 14:17:57 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C7ED561593;\n\tThu, 17 Dec 2020 15:17:56 +0100 (CET)","from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net\n\t[217.70.183.200])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EDFE861591\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 17 Dec 2020 15:17:54 +0100 (CET)","from uno.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 2E48320012;\n\tThu, 17 Dec 2020 14:17:53 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","Date":"Thu, 17 Dec 2020 15:18:05 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Message-ID":"<20201217141805.ptn24utghjg6cgia@uno.localdomain>","References":"<20201215004811.602429-1-niklas.soderlund@ragnatech.se>\n\t<20201215004811.602429-7-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20201215004811.602429-7-niklas.soderlund@ragnatech.se>","Subject":"Re: [libcamera-devel] [PATCH v4 6/8] libcamera: pipeline: rkisp1:\n\tUse delayed controls","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>"}},{"id":14491,"web_url":"https://patchwork.libcamera.org/comment/14491/","msgid":"<X/sKD618HaimVHMF@pendragon.ideasonboard.com>","date":"2021-01-10T14:07:11","subject":"Re: [libcamera-devel] [PATCH v4 6/8] libcamera: pipeline: rkisp1:\n\tUse delayed controls","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, Dec 15, 2020 at 01:48:09AM +0100, Niklas Söderlund wrote:\n> Instead of setting controls using the RkISP1 local Timeline helper use\n> the DelayedControls. The result is the same, the controls are applied\n> with a delay.\n> \n> The values of the delays are however different between the two methods.\n> The values used in the Timeline solution were chosen after some\n> experimentation and the values used in DelayedControls are taken from a\n> generic sensor. None of the two are a perfect match as the delays can be\n> different for different sensors used with the pipeline.\n> \n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> ---\n> * Changes since v3\n> - Rewrite to not use CameraSensor.\n> ---\n>  src/libcamera/pipeline/rkisp1/rkisp1.cpp | 43 +++++++++++++-----------\n>  1 file changed, 23 insertions(+), 20 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> index 4d98c9027f42c759..513a60b04e5f2e21 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> @@ -23,6 +23,7 @@\n>  #include <libcamera/stream.h>\n>  \n>  #include \"libcamera/internal/camera_sensor.h\"\n> +#include \"libcamera/internal/delayed_controls.h\"\n>  #include \"libcamera/internal/device_enumerator.h\"\n>  #include \"libcamera/internal/ipa_manager.h\"\n>  #include \"libcamera/internal/log.h\"\n> @@ -136,6 +137,7 @@ public:\n>  \tStream mainPathStream_;\n>  \tStream selfPathStream_;\n>  \tCameraSensor *sensor_;\n> +\tstd::unique_ptr<DelayedControls> delayedCtrls_;\n>  \tunsigned int frame_;\n>  \tstd::vector<IPABuffer> ipaBuffers_;\n>  \tRkISP1Frames frameInfo_;\n> @@ -345,23 +347,6 @@ RkISP1FrameInfo *RkISP1Frames::find(Request *request)\n>  \treturn nullptr;\n>  }\n>  \n> -class RkISP1ActionSetSensor : public FrameAction\n> -{\n> -public:\n> -\tRkISP1ActionSetSensor(unsigned int frame, CameraSensor *sensor, const ControlList &controls)\n> -\t\t: FrameAction(frame, SetSensor), sensor_(sensor), controls_(controls) {}\n> -\n> -protected:\n> -\tvoid run() override\n> -\t{\n> -\t\tsensor_->setControls(&controls_);\n> -\t}\n> -\n> -private:\n> -\tCameraSensor *sensor_;\n> -\tControlList controls_;\n> -};\n> -\n>  class RkISP1ActionQueueBuffers : public FrameAction\n>  {\n>  public:\n> @@ -429,9 +414,7 @@ void RkISP1CameraData::queueFrameAction(unsigned int frame,\n>  \tswitch (action.operation) {\n>  \tcase RKISP1_IPA_ACTION_V4L2_SET: {\n>  \t\tconst ControlList &controls = action.controls[0];\n> -\t\ttimeline_.scheduleAction(std::make_unique<RkISP1ActionSetSensor>(frame,\n> -\t\t\t\t\t\t\t\t\t\t sensor_,\n> -\t\t\t\t\t\t\t\t\t\t controls));\n> +\t\tdelayedCtrls_->push(controls);\n>  \t\tbreak;\n>  \t}\n>  \tcase RKISP1_IPA_ACTION_PARAM_FILLED: {\n> @@ -898,6 +881,8 @@ int PipelineHandlerRkISP1::start(Camera *camera, [[maybe_unused]] ControlList *c\n>  \t\t};\n>  \t}\n>  \n> +\tisp_->setFrameStartEnabled(true);\n> +\n>  \tactiveCamera_ = camera;\n>  \n>  \t/* Inform IPA of stream configuration and sensor controls. */\n> @@ -925,6 +910,8 @@ void PipelineHandlerRkISP1::stop(Camera *camera)\n>  \tRkISP1CameraData *data = cameraData(camera);\n>  \tint ret;\n>  \n> +\tisp_->setFrameStartEnabled(false);\n> +\n>  \tselfPath_.stop();\n>  \tmainPath_.stop();\n>  \n> @@ -1043,6 +1030,22 @@ int PipelineHandlerRkISP1::createCamera(MediaEntity *sensor)\n>  \t/* Initialize the camera properties. */\n>  \tdata->properties_ = data->sensor_->properties();\n>  \n> +\t/*\n> +\t * \\todo Read dealy values from the sensor itself or from a\n> +\t * a sensor database. For now use generic values taken from\n> +\t * the Raspberry Pi and listed as generic values.\n> +\t */\n> +\tstd::unordered_map<uint32_t, unsigned int> delays = {\n> +\t\t{ V4L2_CID_ANALOGUE_GAIN, 1 },\n> +\t\t{ V4L2_CID_EXPOSURE, 2 },\n> +\t};\n> +\n> +\tdata->delayedCtrls_ =\n> +\t\tstd::make_unique<DelayedControls>(data->sensor_->device(),\n> +\t\t\t\t\t\t  delays);\n> +\tisp_->frameStart.connect(data->delayedCtrls_.get(),\n> +\t\t\t\t &DelayedControls::applyControls);\n> +\n>  \tret = data->loadIPA();\n>  \tif (ret)\n>  \t\treturn ret;","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 AC16BBD80C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 10 Jan 2021 14:07:26 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2B85268066;\n\tSun, 10 Jan 2021 15:07:26 +0100 (CET)","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 3357860523\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 10 Jan 2021 15:07:25 +0100 (CET)","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 AAABDDA;\n\tSun, 10 Jan 2021 15:07:24 +0100 (CET)"],"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=\"emZhS/iD\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1610287644;\n\tbh=EU2SAZlbfwrIEQTjoz8ohpXwC4ah7SKaeYl32GLwclI=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=emZhS/iDCl/t0/ttXmp8kifNgQgNoaw9Xb3nuiB4tYRC/ryZ0XB0BehcyNvjKwzUD\n\t2LbIZfkh0Pt9MmBq0fEOb4+yVT8jYPRr2GC0niWi9N2mhjOnP7jaY8VBZCPxYDbq75\n\tJpNRV1aUAbQY0pYbh83AN6a1O4VLAyykxArqVjh0=","Date":"Sun, 10 Jan 2021 16:07:11 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Message-ID":"<X/sKD618HaimVHMF@pendragon.ideasonboard.com>","References":"<20201215004811.602429-1-niklas.soderlund@ragnatech.se>\n\t<20201215004811.602429-7-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20201215004811.602429-7-niklas.soderlund@ragnatech.se>","Subject":"Re: [libcamera-devel] [PATCH v4 6/8] libcamera: pipeline: rkisp1:\n\tUse delayed controls","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>"}}]