{"id":10483,"url":"https://patchwork.libcamera.org/api/1.1/patches/10483/?format=json","web_url":"https://patchwork.libcamera.org/patch/10483/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20201123221234.485933-4-niklas.soderlund@ragnatech.se>","date":"2020-11-23T22:12:29","name":"[libcamera-devel,v3,3/8] libcamera: raspberrypi: Switch to DelayedControls","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"5e789baf93ee8a9ad9f761733bad4b9876dd1594","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/1.1/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":{"id":16,"url":"https://patchwork.libcamera.org/api/1.1/users/16/?format=json","username":"neg","first_name":"Niklas","last_name":"Söderlund","email":"niklas.soderlund@ragnatech.se"},"mbox":"https://patchwork.libcamera.org/patch/10483/mbox/","series":[{"id":1478,"url":"https://patchwork.libcamera.org/api/1.1/series/1478/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1478","date":"2020-11-23T22:12:26","name":"libcamera: Add helper for controls that take effect with a delay","version":3,"mbox":"https://patchwork.libcamera.org/series/1478/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/10483/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/10483/checks/","tags":{},"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 5BDD1BE177\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 23 Nov 2020 22:12:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1DBA8633FC;\n\tMon, 23 Nov 2020 23:12:52 +0100 (CET)","from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net\n\t[195.74.38.228])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 24021633F9\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 23 Nov 2020 23:12:49 +0100 (CET)","from bismarck.berto.se (p4fca2458.dip0.t-ipconnect.de\n\t[79.202.36.88])\n\tby bin-vsp-out-02.atm.binero.net (Halon) with ESMTPA\n\tid 26edcb38-2dd8-11eb-a076-005056917f90;\n\tMon, 23 Nov 2020 23:06:35 +0100 (CET)"],"X-Halon-ID":"26edcb38-2dd8-11eb-a076-005056917f90","Authorized-sender":"niklas.soderlund@fsdn.se","From":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","To":"libcamera-devel@lists.libcamera.org,\n\tnaush@raspberrypi.com","Date":"Mon, 23 Nov 2020 23:12:29 +0100","Message-Id":"<20201123221234.485933-4-niklas.soderlund@ragnatech.se>","X-Mailer":"git-send-email 2.29.2","In-Reply-To":"<20201123221234.485933-1-niklas.soderlund@ragnatech.se>","References":"<20201123221234.485933-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v3 3/8] libcamera: raspberrypi: Switch to\n\tDelayedControls","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>","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>"},"content":"Use the libcamera core helper DelayedControls instead of the local\nStaggeredCtrl. The new helper is modeled after the StaggeredCtrl\nimplementation and behaves the same.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n .../pipeline/raspberrypi/raspberrypi.cpp      | 44 +++++++++----------\n 1 file changed, 20 insertions(+), 24 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex 66b483f73e2d6625..43bb4c2ecabd1f15 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -26,6 +26,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@@ -36,7 +37,6 @@\n \n #include \"dma_heaps.h\"\n #include \"rpi_stream.h\"\n-#include \"staggered_ctrl.h\"\n \n namespace libcamera {\n \n@@ -176,8 +176,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@@ -780,10 +779,7 @@ int PipelineHandlerRPi::start(Camera *camera)\n \t * starting. First check that the staggered ctrl has been initialised\n \t * by configure().\n \t */\n-\tASSERT(data->staggeredCtrl_);\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@@ -1122,7 +1118,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_->frameStart(sequence);\n }\n \n int RPiCameraData::loadIPA()\n@@ -1200,18 +1196,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\tdelayedCtrls_->reset(&ctrls);\n \t}\n \n \tif (result.operation & RPi::IPA_CONFIG_DROP_FRAMES) {\n@@ -1245,8 +1245,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@@ -1350,11 +1350,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@@ -1366,8 +1362,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","prefixes":["libcamera-devel","v3","3/8"]}