[{"id":14259,"web_url":"https://patchwork.libcamera.org/comment/14259/","msgid":"<20201217140928.5kz4qdohznfyx6tb@uno.localdomain>","date":"2020-12-17T14:09:28","subject":"Re: [libcamera-devel] [PATCH v4 3/8] libcamera: raspberrypi: Switch\n\tto DelayedControls","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:06AM +0100, Niklas Söderlund wrote:\n> Use the libcamera core helper DelayedControls instead of the local\n> StaggeredCtrl. The new helper is modeled after the StaggeredCtrl\n> implementation and behaves the same.\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> ---\n>  .../pipeline/raspberrypi/raspberrypi.cpp      | 54 +++++++++----------\n>  1 file changed, 24 insertions(+), 30 deletions(-)\n>\n> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> index 7a5f5881b9b30129..a0186bee9926f945 100644\n> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> @@ -27,6 +27,7 @@\n>  #include \"libcamera/internal/bayer_format.h\"\n>  #include \"libcamera/internal/buffer.h\"\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/media_device.h\"\n> @@ -37,7 +38,6 @@\n>\n>  #include \"dma_heaps.h\"\n>  #include \"rpi_stream.h\"\n> -#include \"staggered_ctrl.h\"\n>\n>  namespace libcamera {\n>\n> @@ -178,8 +178,7 @@ public:\n>  \tRPi::DmaHeap dmaHeap_;\n>  \tFileDescriptor lsTable_;\n>\n> -\tRPi::StaggeredCtrl staggeredCtrl_;\n> -\tuint32_t expectedSequence_;\n> +\tstd::unique_ptr<DelayedControls> delayedCtrls_;\n>  \tbool sensorMetadata_;\n>\n>  \t/*\n> @@ -766,11 +765,9 @@ int PipelineHandlerRPi::start(Camera *camera, [[maybe_unused]] ControlList *cont\n>  \t}\n>\n>  \t/* Apply any gain/exposure settings that the IPA may have passed back. */\n> -\tASSERT(data->staggeredCtrl_);\n>  \tif (result.operation & RPi::IPA_CONFIG_SENSOR) {\n> -\t\tconst ControlList &ctrls = result.controls[0];\n> -\t\tif (!data->staggeredCtrl_.set(ctrls))\n> -\t\t\tLOG(RPI, Error) << \"V4L2 staggered set failed\";\n> +\t\tControlList ctrls = result.controls[0];\n> +\t\tdata->unicam_[Unicam::Image].dev()->setControls(&ctrls);\n>  \t}\n>\n>  \tif (result.operation & RPi::IPA_CONFIG_DROP_FRAMES) {\n> @@ -802,13 +799,10 @@ int PipelineHandlerRPi::start(Camera *camera, [[maybe_unused]] ControlList *cont\n>  \tdata->unicam_[Unicam::Image].dev()->setFrameStartEnabled(true);\n>\n>  \t/*\n> -\t * Write the last set of gain and exposure values to the camera before\n> -\t * starting. First check that the staggered ctrl has been initialised\n> -\t * by configure().\n> +\t * Reset the delayed controls with the  gain and exposure values set by\n> +\t * the IPA.\n>  \t */\n> -\tdata->staggeredCtrl_.reset();\n> -\tdata->staggeredCtrl_.write();\n> -\tdata->expectedSequence_ = 0;\n> +\tdata->delayedCtrls_->reset();\n>\n>  \tdata->state_ = RPiCameraData::State::Idle;\n>\n> @@ -1147,7 +1141,7 @@ void RPiCameraData::frameStarted(uint32_t sequence)\n>  \tLOG(RPI, Debug) << \"frame start \" << sequence;\n>\n>  \t/* Write any controls for the next frame as soon as we can. */\n> -\tstaggeredCtrl_.write();\n> +\tdelayedCtrls_->applyControls(sequence);\n>  }\n>\n>  int RPiCameraData::loadIPA()\n> @@ -1230,18 +1224,22 @@ int RPiCameraData::configureIPA(const CameraConfiguration *config)\n>  \t\t * Setup our staggered control writer with the sensor default\n>  \t\t * gain and exposure delays.\n>  \t\t */\n> -\t\tif (!staggeredCtrl_) {\n> -\t\t\tstaggeredCtrl_.init(unicam_[Unicam::Image].dev(),\n> -\t\t\t\t\t    { { V4L2_CID_ANALOGUE_GAIN, result.data[resultIdx++] },\n> -\t\t\t\t\t      { V4L2_CID_EXPOSURE, result.data[resultIdx++] } });\n> +\n> +\t\tif (!delayedCtrls_) {\n> +\t\t\tstd::unordered_map<uint32_t, unsigned int> delays = {\n> +\t\t\t\t{ V4L2_CID_ANALOGUE_GAIN, result.data[resultIdx++] },\n> +\t\t\t\t{ V4L2_CID_EXPOSURE, result.data[resultIdx++] }\n> +\t\t\t};\n> +\n> +\t\t\tdelayedCtrls_ = std::make_unique<DelayedControls>(unicam_[Unicam::Image].dev(), delays);\n> +\n>  \t\t\tsensorMetadata_ = result.data[resultIdx++];\n>  \t\t}\n>  \t}\n>\n>  \tif (result.operation & RPi::IPA_CONFIG_SENSOR) {\n> -\t\tconst ControlList &ctrls = result.controls[0];\n> -\t\tif (!staggeredCtrl_.set(ctrls))\n> -\t\t\tLOG(RPI, Error) << \"V4L2 staggered set failed\";\n> +\t\tControlList ctrls = result.controls[0];\n> +\t\tunicam_[Unicam::Image].dev()->setControls(&ctrls);\n>  \t}\n>\n>  \t/*\n> @@ -1270,8 +1268,8 @@ void RPiCameraData::queueFrameAction([[maybe_unused]] unsigned int frame,\n>  \tswitch (action.operation) {\n>  \tcase RPi::IPA_ACTION_V4L2_SET_STAGGERED: {\n>  \t\tconst ControlList &controls = action.controls[0];\n> -\t\tif (!staggeredCtrl_.set(controls))\n> -\t\t\tLOG(RPI, Error) << \"V4L2 staggered set failed\";\n> +\t\tif (!delayedCtrls_->push(controls))\n> +\t\t\tLOG(RPI, Error) << \"V4L2 delay set failed\";\n>  \t\tgoto done;\n>  \t}\n>\n> @@ -1375,11 +1373,7 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer)\n>  \t} else {\n>  \t\tembeddedQueue_.push(buffer);\n>\n> -\t\tstd::unordered_map<uint32_t, int32_t> ctrl;\n> -\t\tint offset = buffer->metadata().sequence - expectedSequence_;\n> -\t\tstaggeredCtrl_.get(ctrl, offset);\n> -\n> -\t\texpectedSequence_ = buffer->metadata().sequence + 1;\n> +\t\tControlList ctrl = delayedCtrls_->get(buffer->metadata().sequence);\n>\n>  \t\t/*\n>  \t\t * Sensor metadata is unavailable, so put the expected ctrl\n> @@ -1391,8 +1385,8 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer)\n>  \t\t\tauto it = mappedEmbeddedBuffers_.find(bufferId);\n>  \t\t\tif (it != mappedEmbeddedBuffers_.end()) {\n>  \t\t\t\tuint32_t *mem = reinterpret_cast<uint32_t *>(it->second.maps()[0].data());\n> -\t\t\t\tmem[0] = ctrl[V4L2_CID_EXPOSURE];\n> -\t\t\t\tmem[1] = ctrl[V4L2_CID_ANALOGUE_GAIN];\n> +\t\t\t\tmem[0] = ctrl.get(V4L2_CID_EXPOSURE).get<int32_t>();\n> +\t\t\t\tmem[1] = ctrl.get(V4L2_CID_ANALOGUE_GAIN).get<int32_t>();\n>  \t\t\t} else {\n>  \t\t\t\tLOG(RPI, Warning) << \"Failed to find embedded buffer \"\n>  \t\t\t\t\t\t  << bufferId;\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 8E664C0F1A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 17 Dec 2020 14:09:19 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6A43D61595;\n\tThu, 17 Dec 2020 15:09:19 +0100 (CET)","from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net\n\t[217.70.183.197])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4843761591\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 17 Dec 2020 15:09:18 +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 relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 6EDA31C0003;\n\tThu, 17 Dec 2020 14:09:17 +0000 (UTC)"],"X-Originating-IP":"2.224.242.101","Date":"Thu, 17 Dec 2020 15:09:28 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Message-ID":"<20201217140928.5kz4qdohznfyx6tb@uno.localdomain>","References":"<20201215004811.602429-1-niklas.soderlund@ragnatech.se>\n\t<20201215004811.602429-4-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20201215004811.602429-4-niklas.soderlund@ragnatech.se>","Subject":"Re: [libcamera-devel] [PATCH v4 3/8] libcamera: raspberrypi: Switch\n\tto DelayedControls","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":14481,"web_url":"https://patchwork.libcamera.org/comment/14481/","msgid":"<CAEmqJPrSkMdDP0Gr7jtYmbdkyuZ2O7LBLmf4N-aqQJEYBrx+5Q@mail.gmail.com>","date":"2021-01-08T15:43:30","subject":"Re: [libcamera-devel] [PATCH v4 3/8] libcamera: raspberrypi: Switch\n\tto DelayedControls","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi Niklas,\n\nThank you for your patch.\n\nOn Tue, 15 Dec 2020 at 00:48, Niklas Söderlund <\nniklas.soderlund@ragnatech.se> wrote:\n\n> Use the libcamera core helper DelayedControls instead of the local\n> StaggeredCtrl. The new helper is modeled after the StaggeredCtrl\n> implementation and behaves the same.\n>\n> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> ---\n>  .../pipeline/raspberrypi/raspberrypi.cpp      | 54 +++++++++----------\n>  1 file changed, 24 insertions(+), 30 deletions(-)\n>\n> diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> index 7a5f5881b9b30129..a0186bee9926f945 100644\n> --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> @@ -27,6 +27,7 @@\n>  #include \"libcamera/internal/bayer_format.h\"\n>  #include \"libcamera/internal/buffer.h\"\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/media_device.h\"\n> @@ -37,7 +38,6 @@\n>\n>  #include \"dma_heaps.h\"\n>  #include \"rpi_stream.h\"\n> -#include \"staggered_ctrl.h\"\n>\n>  namespace libcamera {\n>\n> @@ -178,8 +178,7 @@ public:\n>         RPi::DmaHeap dmaHeap_;\n>         FileDescriptor lsTable_;\n>\n> -       RPi::StaggeredCtrl staggeredCtrl_;\n> -       uint32_t expectedSequence_;\n> +       std::unique_ptr<DelayedControls> delayedCtrls_;\n>         bool sensorMetadata_;\n>\n>         /*\n> @@ -766,11 +765,9 @@ int PipelineHandlerRPi::start(Camera *camera,\n> [[maybe_unused]] ControlList *cont\n>         }\n>\n>         /* Apply any gain/exposure settings that the IPA may have passed\n> back. */\n> -       ASSERT(data->staggeredCtrl_);\n>         if (result.operation & RPi::IPA_CONFIG_SENSOR) {\n> -               const ControlList &ctrls = result.controls[0];\n> -               if (!data->staggeredCtrl_.set(ctrls))\n> -                       LOG(RPI, Error) << \"V4L2 staggered set failed\";\n> +               ControlList ctrls = result.controls[0];\n> +               data->unicam_[Unicam::Image].dev()->setControls(&ctrls);\n>\n\nCould we optimise the copy to ctrls out here?  Not sure if the compiler\nwill do this for us or not...\n\n\n>         }\n>\n>         if (result.operation & RPi::IPA_CONFIG_DROP_FRAMES) {\n> @@ -802,13 +799,10 @@ int PipelineHandlerRPi::start(Camera *camera,\n> [[maybe_unused]] ControlList *cont\n>         data->unicam_[Unicam::Image].dev()->setFrameStartEnabled(true);\n>\n>         /*\n> -        * Write the last set of gain and exposure values to the camera\n> before\n> -        * starting. First check that the staggered ctrl has been\n> initialised\n> -        * by configure().\n> +        * Reset the delayed controls with the  gain and exposure values\n> set by\n> +        * the IPA.\n>          */\n> -       data->staggeredCtrl_.reset();\n> -       data->staggeredCtrl_.write();\n> -       data->expectedSequence_ = 0;\n> +       data->delayedCtrls_->reset();\n>\n>         data->state_ = RPiCameraData::State::Idle;\n>\n> @@ -1147,7 +1141,7 @@ void RPiCameraData::frameStarted(uint32_t sequence)\n>         LOG(RPI, Debug) << \"frame start \" << sequence;\n>\n>         /* Write any controls for the next frame as soon as we can. */\n> -       staggeredCtrl_.write();\n> +       delayedCtrls_->applyControls(sequence);\n>  }\n>\n>  int RPiCameraData::loadIPA()\n> @@ -1230,18 +1224,22 @@ int RPiCameraData::configureIPA(const\n> CameraConfiguration *config)\n>                  * Setup our staggered control writer with the sensor\n> default\n>                  * gain and exposure delays.\n>                  */\n> -               if (!staggeredCtrl_) {\n> -                       staggeredCtrl_.init(unicam_[Unicam::Image].dev(),\n> -                                           { { V4L2_CID_ANALOGUE_GAIN,\n> result.data[resultIdx++] },\n> -                                             { V4L2_CID_EXPOSURE,\n> result.data[resultIdx++] } });\n> +\n> +               if (!delayedCtrls_) {\n> +                       std::unordered_map<uint32_t, unsigned int> delays\n> = {\n> +                               { V4L2_CID_ANALOGUE_GAIN,\n> result.data[resultIdx++] },\n> +                               { V4L2_CID_EXPOSURE,\n> result.data[resultIdx++] }\n> +                       };\n> +\n> +                       delayedCtrls_ =\n> std::make_unique<DelayedControls>(unicam_[Unicam::Image].dev(), delays);\n> +\n>                         sensorMetadata_ = result.data[resultIdx++];\n>                 }\n>         }\n>\n>         if (result.operation & RPi::IPA_CONFIG_SENSOR) {\n> -               const ControlList &ctrls = result.controls[0];\n> -               if (!staggeredCtrl_.set(ctrls))\n> -                       LOG(RPI, Error) << \"V4L2 staggered set failed\";\n> +               ControlList ctrls = result.controls[0];\n> +               unicam_[Unicam::Image].dev()->setControls(&ctrls);\n>         }\n>\n>         /*\n> @@ -1270,8 +1268,8 @@ void\n> RPiCameraData::queueFrameAction([[maybe_unused]] unsigned int frame,\n>         switch (action.operation) {\n>         case RPi::IPA_ACTION_V4L2_SET_STAGGERED: {\n>\n\nThis label probably wants to change to SET_DELAYED_CTRLS or similar to be\nconsistent.\n\n\n>                 const ControlList &controls = action.controls[0];\n> -               if (!staggeredCtrl_.set(controls))\n> -                       LOG(RPI, Error) << \"V4L2 staggered set failed\";\n> +               if (!delayedCtrls_->push(controls))\n> +                       LOG(RPI, Error) << \"V4L2 delay set failed\";\n>                 goto done;\n>         }\n>\n> @@ -1375,11 +1373,7 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer\n> *buffer)\n>         } else {\n>                 embeddedQueue_.push(buffer);\n>\n> -               std::unordered_map<uint32_t, int32_t> ctrl;\n> -               int offset = buffer->metadata().sequence -\n> expectedSequence_;\n> -               staggeredCtrl_.get(ctrl, offset);\n> -\n> -               expectedSequence_ = buffer->metadata().sequence + 1;\n> +               ControlList ctrl =\n> delayedCtrls_->get(buffer->metadata().sequence);\n>\n>                 /*\n>                  * Sensor metadata is unavailable, so put the expected ctrl\n> @@ -1391,8 +1385,8 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer\n> *buffer)\n>                         auto it = mappedEmbeddedBuffers_.find(bufferId);\n>                         if (it != mappedEmbeddedBuffers_.end()) {\n>                                 uint32_t *mem = reinterpret_cast<uint32_t\n> *>(it->second.maps()[0].data());\n> -                               mem[0] = ctrl[V4L2_CID_EXPOSURE];\n> -                               mem[1] = ctrl[V4L2_CID_ANALOGUE_GAIN];\n> +                               mem[0] =\n> ctrl.get(V4L2_CID_EXPOSURE).get<int32_t>();\n> +                               mem[1] =\n> ctrl.get(V4L2_CID_ANALOGUE_GAIN).get<int32_t>();\n>                         } else {\n>                                 LOG(RPI, Warning) << \"Failed to find\n> embedded buffer \"\n>                                                   << bufferId;\n>\n\nApart from the minors,\n\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n\n\n> --\n> 2.29.2\n>\n>","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 A61B9C0F1A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  8 Jan 2021 15:43:49 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2F94168056;\n\tFri,  8 Jan 2021 16:43:49 +0100 (CET)","from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com\n\t[IPv6:2a00:1450:4864:20::12f])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0F86267F2D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  8 Jan 2021 16:43:47 +0100 (CET)","by mail-lf1-x12f.google.com with SMTP id u25so3157553lfc.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 08 Jan 2021 07:43:46 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"eCZXGmRO\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=jfhCL3OfVrwseZnvPjfZatTFvAdNeJESBaho0+k11Ts=;\n\tb=eCZXGmROCr5HHApz4zRFEE/JG4VBxhkWXFDf6AEx/8cnfLSg0vEpqomEbD3Ocz98F+\n\tfEkRmiy0ukOUE31zqtDhZLJGXze0EnybxGCyi7TzBs+zOx/qHhhU54Nm54aHcQ5IgNJJ\n\tD4WZt6G8RcQONqGbM90KPUsnlRsOEnW1w4grZhVeNmwgJf7RWn5+NVtOwpWIO8quI63T\n\tPC9osNe5iew2lvXKTu+RpBG6n2+eKTYW6DUkj8hIRiWePAgg4C1oHJU70b//H7A2wCpf\n\tPbJKV9+qEwe/eS0L4JJIx8OVztKl0mjSvg0mz3Z76iVtKW7vtF0u9l6idY+bF7rXyMvM\n\t1RwQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=jfhCL3OfVrwseZnvPjfZatTFvAdNeJESBaho0+k11Ts=;\n\tb=iErkG5+8/QlLP7LVBwCplU17JC/zrsnunWMCxKvSsrP6eC2DP8yjQmxUsy+s3Cw3IM\n\tLF1zqn72GXJmr4nDwI06XHFym3QDMGOFzNtSNg+kLfdOdvOkrSjfS5xFwGnu92fXiir3\n\traxZjKbVUm6umwEDGjxwVIf9nLWghobGQXV+FL8CsowisiVqOK2hkg43MYlC0g/mtdxH\n\tSDqnvwj0IoJZk/I6Tyo7C6yZYksmUJvrqDoGejbt2GLNFpdv9zVIYBn4D4JgKauLRB7+\n\tCotcXPfpVrN0h6mvjuB/Wu+o7TaM9YykOBzl1GmhgIffnJhs8Q6yuQJgQgV9zfdhemdP\n\t7hsA==","X-Gm-Message-State":"AOAM5332wyYIXCczvg4VTq2E4yHg65Hcl3qREERW2/vf7Z/leAcwBzU+\n\toB93ia0bA8rQStn1kJmP2Swee57/Q/BgFybpMFYUyNMG7+PlCg==","X-Google-Smtp-Source":"ABdhPJxA50VK2A5OiYUJqLsFn1plY+wnwBXuipg/iZ/E0+pPy7rZFQ3HvA5DUiEx4AT6dNNfPDBMGp3sQhExJK3jNvg=","X-Received":"by 2002:a05:6512:247:: with SMTP id\n\tb7mr1755114lfo.171.1610120626449; \n\tFri, 08 Jan 2021 07:43:46 -0800 (PST)","MIME-Version":"1.0","References":"<20201215004811.602429-1-niklas.soderlund@ragnatech.se>\n\t<20201215004811.602429-4-niklas.soderlund@ragnatech.se>","In-Reply-To":"<20201215004811.602429-4-niklas.soderlund@ragnatech.se>","From":"Naushir Patuck <naush@raspberrypi.com>","Date":"Fri, 8 Jan 2021 15:43:30 +0000","Message-ID":"<CAEmqJPrSkMdDP0Gr7jtYmbdkyuZ2O7LBLmf4N-aqQJEYBrx+5Q@mail.gmail.com>","To":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Subject":"Re: [libcamera-devel] [PATCH v4 3/8] libcamera: raspberrypi: Switch\n\tto DelayedControls","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 <libcamera-devel@lists.libcamera.org>","Content-Type":"multipart/mixed;\n\tboundary=\"===============3041769671664707666==\"","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":14482,"web_url":"https://patchwork.libcamera.org/comment/14482/","msgid":"<X/iDDr3P98DGs+G5@oden.dyn.berto.se>","date":"2021-01-08T16:06:38","subject":"Re: [libcamera-devel] [PATCH v4 3/8] libcamera: raspberrypi: Switch\n\tto DelayedControls","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"content":"Hi Naushir,\n\nThanks for your feedback.\n\nOn 2021-01-08 15:43:30 +0000, Naushir Patuck wrote:\n> Hi Niklas,\n> \n> Thank you for your patch.\n> \n> On Tue, 15 Dec 2020 at 00:48, Niklas Söderlund <\n> niklas.soderlund@ragnatech.se> wrote:\n> \n> > Use the libcamera core helper DelayedControls instead of the local\n> > StaggeredCtrl. The new helper is modeled after the StaggeredCtrl\n> > implementation and behaves the same.\n> >\n> > Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> > ---\n> >  .../pipeline/raspberrypi/raspberrypi.cpp      | 54 +++++++++----------\n> >  1 file changed, 24 insertions(+), 30 deletions(-)\n> >\n> > diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > index 7a5f5881b9b30129..a0186bee9926f945 100644\n> > --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > @@ -27,6 +27,7 @@\n> >  #include \"libcamera/internal/bayer_format.h\"\n> >  #include \"libcamera/internal/buffer.h\"\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/media_device.h\"\n> > @@ -37,7 +38,6 @@\n> >\n> >  #include \"dma_heaps.h\"\n> >  #include \"rpi_stream.h\"\n> > -#include \"staggered_ctrl.h\"\n> >\n> >  namespace libcamera {\n> >\n> > @@ -178,8 +178,7 @@ public:\n> >         RPi::DmaHeap dmaHeap_;\n> >         FileDescriptor lsTable_;\n> >\n> > -       RPi::StaggeredCtrl staggeredCtrl_;\n> > -       uint32_t expectedSequence_;\n> > +       std::unique_ptr<DelayedControls> delayedCtrls_;\n> >         bool sensorMetadata_;\n> >\n> >         /*\n> > @@ -766,11 +765,9 @@ int PipelineHandlerRPi::start(Camera *camera,\n> > [[maybe_unused]] ControlList *cont\n> >         }\n> >\n> >         /* Apply any gain/exposure settings that the IPA may have passed\n> > back. */\n> > -       ASSERT(data->staggeredCtrl_);\n> >         if (result.operation & RPi::IPA_CONFIG_SENSOR) {\n> > -               const ControlList &ctrls = result.controls[0];\n> > -               if (!data->staggeredCtrl_.set(ctrls))\n> > -                       LOG(RPI, Error) << \"V4L2 staggered set failed\";\n> > +               ControlList ctrls = result.controls[0];\n> > +               data->unicam_[Unicam::Image].dev()->setControls(&ctrls);\n> >\n> \n> Could we optimise the copy to ctrls out here?  Not sure if the compiler\n> will do this for us or not...\n\nGood catch. I will fix this for next version.\n\n> \n> \n> >         }\n> >\n> >         if (result.operation & RPi::IPA_CONFIG_DROP_FRAMES) {\n> > @@ -802,13 +799,10 @@ int PipelineHandlerRPi::start(Camera *camera,\n> > [[maybe_unused]] ControlList *cont\n> >         data->unicam_[Unicam::Image].dev()->setFrameStartEnabled(true);\n> >\n> >         /*\n> > -        * Write the last set of gain and exposure values to the camera\n> > before\n> > -        * starting. First check that the staggered ctrl has been\n> > initialised\n> > -        * by configure().\n> > +        * Reset the delayed controls with the  gain and exposure values\n> > set by\n> > +        * the IPA.\n> >          */\n> > -       data->staggeredCtrl_.reset();\n> > -       data->staggeredCtrl_.write();\n> > -       data->expectedSequence_ = 0;\n> > +       data->delayedCtrls_->reset();\n> >\n> >         data->state_ = RPiCameraData::State::Idle;\n> >\n> > @@ -1147,7 +1141,7 @@ void RPiCameraData::frameStarted(uint32_t sequence)\n> >         LOG(RPI, Debug) << \"frame start \" << sequence;\n> >\n> >         /* Write any controls for the next frame as soon as we can. */\n> > -       staggeredCtrl_.write();\n> > +       delayedCtrls_->applyControls(sequence);\n> >  }\n> >\n> >  int RPiCameraData::loadIPA()\n> > @@ -1230,18 +1224,22 @@ int RPiCameraData::configureIPA(const\n> > CameraConfiguration *config)\n> >                  * Setup our staggered control writer with the sensor\n> > default\n> >                  * gain and exposure delays.\n> >                  */\n> > -               if (!staggeredCtrl_) {\n> > -                       staggeredCtrl_.init(unicam_[Unicam::Image].dev(),\n> > -                                           { { V4L2_CID_ANALOGUE_GAIN,\n> > result.data[resultIdx++] },\n> > -                                             { V4L2_CID_EXPOSURE,\n> > result.data[resultIdx++] } });\n> > +\n> > +               if (!delayedCtrls_) {\n> > +                       std::unordered_map<uint32_t, unsigned int> delays\n> > = {\n> > +                               { V4L2_CID_ANALOGUE_GAIN,\n> > result.data[resultIdx++] },\n> > +                               { V4L2_CID_EXPOSURE,\n> > result.data[resultIdx++] }\n> > +                       };\n> > +\n> > +                       delayedCtrls_ =\n> > std::make_unique<DelayedControls>(unicam_[Unicam::Image].dev(), delays);\n> > +\n> >                         sensorMetadata_ = result.data[resultIdx++];\n> >                 }\n> >         }\n> >\n> >         if (result.operation & RPi::IPA_CONFIG_SENSOR) {\n> > -               const ControlList &ctrls = result.controls[0];\n> > -               if (!staggeredCtrl_.set(ctrls))\n> > -                       LOG(RPI, Error) << \"V4L2 staggered set failed\";\n> > +               ControlList ctrls = result.controls[0];\n> > +               unicam_[Unicam::Image].dev()->setControls(&ctrls);\n> >         }\n> >\n> >         /*\n> > @@ -1270,8 +1268,8 @@ void\n> > RPiCameraData::queueFrameAction([[maybe_unused]] unsigned int frame,\n> >         switch (action.operation) {\n> >         case RPi::IPA_ACTION_V4L2_SET_STAGGERED: {\n> >\n> \n> This label probably wants to change to SET_DELAYED_CTRLS or similar to be\n> consistent.\n\nAgreed will be done for next version.\n\n> \n> \n> >                 const ControlList &controls = action.controls[0];\n> > -               if (!staggeredCtrl_.set(controls))\n> > -                       LOG(RPI, Error) << \"V4L2 staggered set failed\";\n> > +               if (!delayedCtrls_->push(controls))\n> > +                       LOG(RPI, Error) << \"V4L2 delay set failed\";\n> >                 goto done;\n> >         }\n> >\n> > @@ -1375,11 +1373,7 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer\n> > *buffer)\n> >         } else {\n> >                 embeddedQueue_.push(buffer);\n> >\n> > -               std::unordered_map<uint32_t, int32_t> ctrl;\n> > -               int offset = buffer->metadata().sequence -\n> > expectedSequence_;\n> > -               staggeredCtrl_.get(ctrl, offset);\n> > -\n> > -               expectedSequence_ = buffer->metadata().sequence + 1;\n> > +               ControlList ctrl =\n> > delayedCtrls_->get(buffer->metadata().sequence);\n> >\n> >                 /*\n> >                  * Sensor metadata is unavailable, so put the expected ctrl\n> > @@ -1391,8 +1385,8 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer\n> > *buffer)\n> >                         auto it = mappedEmbeddedBuffers_.find(bufferId);\n> >                         if (it != mappedEmbeddedBuffers_.end()) {\n> >                                 uint32_t *mem = reinterpret_cast<uint32_t\n> > *>(it->second.maps()[0].data());\n> > -                               mem[0] = ctrl[V4L2_CID_EXPOSURE];\n> > -                               mem[1] = ctrl[V4L2_CID_ANALOGUE_GAIN];\n> > +                               mem[0] =\n> > ctrl.get(V4L2_CID_EXPOSURE).get<int32_t>();\n> > +                               mem[1] =\n> > ctrl.get(V4L2_CID_ANALOGUE_GAIN).get<int32_t>();\n> >                         } else {\n> >                                 LOG(RPI, Warning) << \"Failed to find\n> > embedded buffer \"\n> >                                                   << bufferId;\n> >\n> \n> Apart from the minors,\n> \n> Reviewed-by: Naushir Patuck <naush@raspberrypi.com>\n\nThanks!\n\n> \n> \n> > --\n> > 2.29.2\n> >\n> >","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 AF0F7C3256\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  8 Jan 2021 16:06:42 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3A1A068061;\n\tFri,  8 Jan 2021 17:06:42 +0100 (CET)","from mail-lf1-x129.google.com (mail-lf1-x129.google.com\n\t[IPv6:2a00:1450:4864:20::129])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 259C867F2D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  8 Jan 2021 17:06:41 +0100 (CET)","by mail-lf1-x129.google.com with SMTP id 23so24027712lfg.10\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 08 Jan 2021 08:06:41 -0800 (PST)","from localhost (h-209-203.A463.priv.bahnhof.se. [155.4.209.203])\n\tby smtp.gmail.com with ESMTPSA id\n\tk8sm2054463lfk.187.2021.01.08.08.06.39\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 08 Jan 2021 08:06:39 -0800 (PST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=ragnatech-se.20150623.gappssmtp.com\n\theader.i=@ragnatech-se.20150623.gappssmtp.com\n\theader.b=\"wgjLvS7R\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=ragnatech-se.20150623.gappssmtp.com; s=20150623;\n\th=date:from:to:cc:subject:message-id:references:mime-version\n\t:content-disposition:content-transfer-encoding:in-reply-to;\n\tbh=Xc2WVeRjrpVzUbKZ9KeogHAwSf1FHWualAj1526clqU=;\n\tb=wgjLvS7Rv2q4D9znBDm0HpUbByNoetLOqAu4xRc7PE3Rli2rHPNwp+DWXvFV6cR99O\n\tQx2JBG1uy8gbHt4JEYfnJK1aN63QvkxqhhJSWAp45byKzHXpzGb4cooFE8yvAa8bcAGc\n\tS3TSKoJAHo+L8r4ZZdgxpZhxd0TI326eIyWi5UZgi+bxLrtScMlay7UCFMpN7IYbRP6c\n\tGzrHgRy81OPfdikqv3fHyjwDZIPRtyrCTnvCx+D/1UDzopeWB/4lundByCUWhZNCWy2X\n\tOoD4B6PEZO4QBBEujk+oYZl6iPwJVXFyoMkb5V5KUteYWCRvQDsv3J0VoIZYFncPaZYi\n\tWOyw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:date:from:to:cc:subject:message-id:references\n\t:mime-version:content-disposition:content-transfer-encoding\n\t:in-reply-to;\n\tbh=Xc2WVeRjrpVzUbKZ9KeogHAwSf1FHWualAj1526clqU=;\n\tb=aKFtbNBzqgc04muzmoVWYujCDssFcrvLrpVrcH7StN7PgaKwBQpRJSSY9osIrAG4Nm\n\tCW/4xyn8iuaLolQP0ZbIKrwdB76naqHac0vRC26y4ACdSfEMXOLZsxlAQILqpwEjW0jK\n\tAkYMl22tVijFpidiiQlSlnXJ31bL/EGbZgwlSHi3zS2yM+CdGe4eArWU9BAP+sPqPGoz\n\tI4cwpLG5ipbkJIA0fed8hZbN+QKDVFla+JdnSVrsWI2JfEh0H9nERaLHJB+NqlL/4bcD\n\tg50FU8KISft82LfL8JlNo4bS89Ao3gmLErTg9qTRgurfxTO5Beo8cXOSGEkW+imJc/QF\n\tKwGw==","X-Gm-Message-State":"AOAM5323P6Y8bBEJvqU66OeDpGdrk8m4/Jj3bPaPX4py1P+lfJSG013D\n\tc4uN7g/nOfhb+4YRifTOQlflEA==","X-Google-Smtp-Source":"ABdhPJy+EyaKF2wkA1lHzbslqorr2DueCbvWnw1rmou/RvOkEsGoM6J37bRi4ASjBYLTAQsNb/Rpmg==","X-Received":"by 2002:a19:a40a:: with SMTP id q10mr1815255lfc.39.1610122000445;\n\tFri, 08 Jan 2021 08:06:40 -0800 (PST)","Date":"Fri, 8 Jan 2021 17:06:38 +0100","From":"Niklas =?iso-8859-1?q?S=F6derlund?= <niklas.soderlund@ragnatech.se>","To":"Naushir Patuck <naush@raspberrypi.com>","Message-ID":"<X/iDDr3P98DGs+G5@oden.dyn.berto.se>","References":"<20201215004811.602429-1-niklas.soderlund@ragnatech.se>\n\t<20201215004811.602429-4-niklas.soderlund@ragnatech.se>\n\t<CAEmqJPrSkMdDP0Gr7jtYmbdkyuZ2O7LBLmf4N-aqQJEYBrx+5Q@mail.gmail.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<CAEmqJPrSkMdDP0Gr7jtYmbdkyuZ2O7LBLmf4N-aqQJEYBrx+5Q@mail.gmail.com>","Subject":"Re: [libcamera-devel] [PATCH v4 3/8] libcamera: raspberrypi: Switch\n\tto DelayedControls","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 <libcamera-devel@lists.libcamera.org>","Content-Type":"text/plain; charset=\"iso-8859-1\"","Content-Transfer-Encoding":"quoted-printable","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":14493,"web_url":"https://patchwork.libcamera.org/comment/14493/","msgid":"<X/sPL+izK5zZ5yIQ@pendragon.ideasonboard.com>","date":"2021-01-10T14:29:03","subject":"Re: [libcamera-devel] [PATCH v4 3/8] libcamera: raspberrypi: Switch\n\tto DelayedControls","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 Fri, Jan 08, 2021 at 05:06:38PM +0100, Niklas Söderlund wrote:\n> On 2021-01-08 15:43:30 +0000, Naushir Patuck wrote:\n> > On Tue, 15 Dec 2020 at 00:48, Niklas Söderlund wrote:\n> > \n> > > Use the libcamera core helper DelayedControls instead of the local\n> > > StaggeredCtrl. The new helper is modeled after the StaggeredCtrl\n> > > implementation and behaves the same.\n> > >\n> > > Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n> > > ---\n> > >  .../pipeline/raspberrypi/raspberrypi.cpp      | 54 +++++++++----------\n> > >  1 file changed, 24 insertions(+), 30 deletions(-)\n> > >\n> > > diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > > b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > > index 7a5f5881b9b30129..a0186bee9926f945 100644\n> > > --- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > > +++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n> > > @@ -27,6 +27,7 @@\n> > >  #include \"libcamera/internal/bayer_format.h\"\n> > >  #include \"libcamera/internal/buffer.h\"\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/media_device.h\"\n> > > @@ -37,7 +38,6 @@\n> > >\n> > >  #include \"dma_heaps.h\"\n> > >  #include \"rpi_stream.h\"\n> > > -#include \"staggered_ctrl.h\"\n> > >\n> > >  namespace libcamera {\n> > >\n> > > @@ -178,8 +178,7 @@ public:\n> > >         RPi::DmaHeap dmaHeap_;\n> > >         FileDescriptor lsTable_;\n> > >\n> > > -       RPi::StaggeredCtrl staggeredCtrl_;\n> > > -       uint32_t expectedSequence_;\n> > > +       std::unique_ptr<DelayedControls> delayedCtrls_;\n> > >         bool sensorMetadata_;\n> > >\n> > >         /*\n> > > @@ -766,11 +765,9 @@ int PipelineHandlerRPi::start(Camera *camera, [[maybe_unused]] ControlList *cont\n> > >         }\n> > >\n> > >         /* Apply any gain/exposure settings that the IPA may have passed back. */\n> > > -       ASSERT(data->staggeredCtrl_);\n> > >         if (result.operation & RPi::IPA_CONFIG_SENSOR) {\n> > > -               const ControlList &ctrls = result.controls[0];\n> > > -               if (!data->staggeredCtrl_.set(ctrls))\n> > > -                       LOG(RPI, Error) << \"V4L2 staggered set failed\";\n> > > +               ControlList ctrls = result.controls[0];\n> > > +               data->unicam_[Unicam::Image].dev()->setControls(&ctrls);\n> > >\n> > \n> > Could we optimise the copy to ctrls out here?  Not sure if the compiler\n> > will do this for us or not...\n> \n> Good catch. I will fix this for next version.\n> \n> > >         }\n> > >\n> > >         if (result.operation & RPi::IPA_CONFIG_DROP_FRAMES) {\n> > > @@ -802,13 +799,10 @@ int PipelineHandlerRPi::start(Camera *camera, [[maybe_unused]] ControlList *cont\n> > >         data->unicam_[Unicam::Image].dev()->setFrameStartEnabled(true);\n> > >\n> > >         /*\n> > > -        * Write the last set of gain and exposure values to the camera before\n> > > -        * starting. First check that the staggered ctrl has been initialised\n> > > -        * by configure().\n> > > +        * Reset the delayed controls with the  gain and exposure values set by\n\ns/the  gain/the gain/\n\n> > > +        * the IPA.\n> > >          */\n> > > -       data->staggeredCtrl_.reset();\n> > > -       data->staggeredCtrl_.write();\n> > > -       data->expectedSequence_ = 0;\n> > > +       data->delayedCtrls_->reset();\n> > >\n> > >         data->state_ = RPiCameraData::State::Idle;\n> > >\n> > > @@ -1147,7 +1141,7 @@ void RPiCameraData::frameStarted(uint32_t sequence)\n> > >         LOG(RPI, Debug) << \"frame start \" << sequence;\n> > >\n> > >         /* Write any controls for the next frame as soon as we can. */\n> > > -       staggeredCtrl_.write();\n> > > +       delayedCtrls_->applyControls(sequence);\n> > >  }\n> > >\n> > >  int RPiCameraData::loadIPA()\n> > > @@ -1230,18 +1224,22 @@ int RPiCameraData::configureIPA(const CameraConfiguration *config)\n> > >                  * Setup our staggered control writer with the sensor default\n\ns/staggered/delayed/ ?\n\n> > >                  * gain and exposure delays.\n> > >                  */\n> > > -               if (!staggeredCtrl_) {\n> > > -                       staggeredCtrl_.init(unicam_[Unicam::Image].dev(),\n> > > -                                           { { V4L2_CID_ANALOGUE_GAIN, result.data[resultIdx++] },\n> > > -                                             { V4L2_CID_EXPOSURE, result.data[resultIdx++] } });\n> > > +\n\nExtra blank line.\n\n> > > +               if (!delayedCtrls_) {\n> > > +                       std::unordered_map<uint32_t, unsigned int> delays = {\n> > > +                               { V4L2_CID_ANALOGUE_GAIN, result.data[resultIdx++] },\n> > > +                               { V4L2_CID_EXPOSURE, result.data[resultIdx++] }\n> > > +                       };\n> > > +\n> > > +                       delayedCtrls_ = std::make_unique<DelayedControls>(unicam_[Unicam::Image].dev(), delays);\n> > > +\n> > >                         sensorMetadata_ = result.data[resultIdx++];\n> > >                 }\n> > >         }\n> > >\n> > >         if (result.operation & RPi::IPA_CONFIG_SENSOR) {\n> > > -               const ControlList &ctrls = result.controls[0];\n> > > -               if (!staggeredCtrl_.set(ctrls))\n> > > -                       LOG(RPI, Error) << \"V4L2 staggered set failed\";\n> > > +               ControlList ctrls = result.controls[0];\n> > > +               unicam_[Unicam::Image].dev()->setControls(&ctrls);\n\nThis copy should be avoided too.\n\n> > >         }\n> > >\n> > >         /*\n> > > @@ -1270,8 +1268,8 @@ void\n> > > RPiCameraData::queueFrameAction([[maybe_unused]] unsigned int frame,\n> > >         switch (action.operation) {\n> > >         case RPi::IPA_ACTION_V4L2_SET_STAGGERED: {\n> > \n> > This label probably wants to change to SET_DELAYED_CTRLS or similar to be\n> > consistent.\n> \n> Agreed will be done for next version.\n> \n> > >                 const ControlList &controls = action.controls[0];\n> > > -               if (!staggeredCtrl_.set(controls))\n> > > -                       LOG(RPI, Error) << \"V4L2 staggered set failed\";\n> > > +               if (!delayedCtrls_->push(controls))\n> > > +                       LOG(RPI, Error) << \"V4L2 delay set failed\";\n\n\"Failed to set delayed controls\" ?\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> > >                 goto done;\n> > >         }\n> > >\n> > > @@ -1375,11 +1373,7 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer)\n> > >         } else {\n> > >                 embeddedQueue_.push(buffer);\n> > >\n> > > -               std::unordered_map<uint32_t, int32_t> ctrl;\n> > > -               int offset = buffer->metadata().sequence - expectedSequence_;\n> > > -               staggeredCtrl_.get(ctrl, offset);\n> > > -\n> > > -               expectedSequence_ = buffer->metadata().sequence + 1;\n> > > +               ControlList ctrl = delayedCtrls_->get(buffer->metadata().sequence);\n> > >\n> > >                 /*\n> > >                  * Sensor metadata is unavailable, so put the expected ctrl\n> > > @@ -1391,8 +1385,8 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer)\n> > >                         auto it = mappedEmbeddedBuffers_.find(bufferId);\n> > >                         if (it != mappedEmbeddedBuffers_.end()) {\n> > >                                 uint32_t *mem = reinterpret_cast<uint32_t *>(it->second.maps()[0].data());\n> > > -                               mem[0] = ctrl[V4L2_CID_EXPOSURE];\n> > > -                               mem[1] = ctrl[V4L2_CID_ANALOGUE_GAIN];\n> > > +                               mem[0] = ctrl.get(V4L2_CID_EXPOSURE).get<int32_t>();\n> > > +                               mem[1] = ctrl.get(V4L2_CID_ANALOGUE_GAIN).get<int32_t>();\n> > >                         } else {\n> > >                                 LOG(RPI, Warning) << \"Failed to find embedded buffer \"\n> > >                                                   << bufferId;\n> > \n> > Apart from the minors,\n> > \n> > Reviewed-by: Naushir Patuck <naush@raspberrypi.com>","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 45686BD80C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 10 Jan 2021 14:29:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B83856806C;\n\tSun, 10 Jan 2021 15:29:19 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 35E6D60523\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 10 Jan 2021 15:29:18 +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 9CEDFDA;\n\tSun, 10 Jan 2021 15:29:17 +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=\"Ih7TI5R/\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1610288957;\n\tbh=jvkR5GEV+ZnKVnbyeCQkcHgjoG7mwBR9/5VhQhkN7Ns=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=Ih7TI5R/VYr+fl3B8ff+vu3Z6uFAx87T42cnCL0POc6HJzYYJ/xwZS/qxlhBQSX4O\n\tmGVDFcc7+hnQnsXHLOvckU1ztkhZixH+ZTmLqngFiiY4R6gCYXlLx1r9uPsUwLl55b\n\tVlCgotAD5htdrsk4qWM19eeLL0bK2scmg0NUWZqI=","Date":"Sun, 10 Jan 2021 16:29:03 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Niklas =?utf-8?q?S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","Message-ID":"<X/sPL+izK5zZ5yIQ@pendragon.ideasonboard.com>","References":"<20201215004811.602429-1-niklas.soderlund@ragnatech.se>\n\t<20201215004811.602429-4-niklas.soderlund@ragnatech.se>\n\t<CAEmqJPrSkMdDP0Gr7jtYmbdkyuZ2O7LBLmf4N-aqQJEYBrx+5Q@mail.gmail.com>\n\t<X/iDDr3P98DGs+G5@oden.dyn.berto.se>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<X/iDDr3P98DGs+G5@oden.dyn.berto.se>","Subject":"Re: [libcamera-devel] [PATCH v4 3/8] libcamera: raspberrypi: Switch\n\tto DelayedControls","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 <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>"}}]