{"id":10402,"url":"https://patchwork.libcamera.org/api/1.1/patches/10402/?format=json","web_url":"https://patchwork.libcamera.org/patch/10402/","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":"<20201110002710.3233696-4-niklas.soderlund@ragnatech.se>","date":"2020-11-10T00:27:05","name":"[libcamera-devel,v2,3/8] libcamera: raspberrypi: Switch to DelayedControls","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"d0d5bb05b9f0d6ead4a4724d5c99bb17d86a45d3","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":null,"mbox":"https://patchwork.libcamera.org/patch/10402/mbox/","series":[{"id":1454,"url":"https://patchwork.libcamera.org/api/1.1/series/1454/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1454","date":"2020-11-10T00:27:02","name":"Add helper for controls that take effect with a delay","version":2,"mbox":"https://patchwork.libcamera.org/series/1454/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/10402/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/10402/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 B23C0BE085\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 10 Nov 2020 00:28:00 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 57480630C7;\n\tTue, 10 Nov 2020 01:28:00 +0100 (CET)","from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net\n\t[195.74.38.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 18BDC630BC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 10 Nov 2020 01:27:59 +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 c4f2b2f3-22ea-11eb-bcc0-005056917f90;\n\tTue, 10 Nov 2020 01:22:08 +0100 (CET)"],"X-Halon-ID":"c4f2b2f3-22ea-11eb-bcc0-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, 10 Nov 2020 01:27:05 +0100","Message-Id":"<20201110002710.3233696-4-niklas.soderlund@ragnatech.se>","X-Mailer":"git-send-email 2.29.2","In-Reply-To":"<20201110002710.3233696-1-niklas.soderlund@ragnatech.se>","References":"<20201110002710.3233696-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v2 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 7ad66f21ffa37842..f3ab257cec62f995 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -25,6 +25,7 @@\n \n #include \"libcamera/internal/bayer_format.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@@ -35,7 +36,6 @@\n \n #include \"dma_heaps.h\"\n #include \"rpi_stream.h\"\n-#include \"staggered_ctrl.h\"\n \n namespace libcamera {\n \n@@ -169,8 +169,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@@ -775,10 +774,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@@ -1109,7 +1105,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@@ -1187,18 +1183,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@@ -1232,8 +1232,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@@ -1337,11 +1337,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@@ -1354,8 +1350,8 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer)\n \t\t\t\t\t\t\t\t       PROT_READ | PROT_WRITE,\n \t\t\t\t\t\t\t\t       MAP_SHARED,\n \t\t\t\t\t\t\t\t       fb.planes()[0].fd.fd(), 0));\n-\t\t\tmem[0] = ctrl[V4L2_CID_EXPOSURE];\n-\t\t\tmem[1] = ctrl[V4L2_CID_ANALOGUE_GAIN];\n+\t\t\tmem[0] = ctrl.get(V4L2_CID_EXPOSURE).get<int32_t>();\n+\t\t\tmem[1] = ctrl.get(V4L2_CID_ANALOGUE_GAIN).get<int32_t>();\n \t\t\tmunmap(mem, fb.planes()[0].length);\n \t\t}\n \t}\n","prefixes":["libcamera-devel","v2","3/8"]}