{"id":10664,"url":"https://patchwork.libcamera.org/api/patches/10664/?format=json","web_url":"https://patchwork.libcamera.org/patch/10664/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20201215004811.602429-4-niklas.soderlund@ragnatech.se>","date":"2020-12-15T00:48:06","name":"[libcamera-devel,v4,3/8] libcamera: raspberrypi: Switch to DelayedControls","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"c2f3290dc0495f9481207bbec26e5837ee2d62ac","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":{"id":16,"url":"https://patchwork.libcamera.org/api/users/16/?format=json","username":"neg","first_name":"Niklas","last_name":"Söderlund","email":"niklas.soderlund@ragnatech.se"},"mbox":"https://patchwork.libcamera.org/patch/10664/mbox/","series":[{"id":1533,"url":"https://patchwork.libcamera.org/api/series/1533/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1533","date":"2020-12-15T00:48:03","name":"libcamera: Add helper for controls that take effect with a delay","version":4,"mbox":"https://patchwork.libcamera.org/series/1533/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/10664/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/10664/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 05EADBD80A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 15 Dec 2020 00:48:26 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 90736615AC;\n\tTue, 15 Dec 2020 01:48:25 +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 C618B61590\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 15 Dec 2020 01:48:23 +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 3b713277-3e6f-11eb-a076-005056917f90;\n\tTue, 15 Dec 2020 01:48:22 +0100 (CET)"],"X-Halon-ID":"3b713277-3e6f-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":"Tue, 15 Dec 2020 01:48:06 +0100","Message-Id":"<20201215004811.602429-4-niklas.soderlund@ragnatech.se>","X-Mailer":"git-send-email 2.29.2","In-Reply-To":"<20201215004811.602429-1-niklas.soderlund@ragnatech.se>","References":"<20201215004811.602429-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v4 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      | 54 +++++++++----------\n 1 file changed, 24 insertions(+), 30 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex 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","prefixes":["libcamera-devel","v4","3/8"]}