{"id":17399,"url":"https://patchwork.libcamera.org/api/1.1/patches/17399/?format=json","web_url":"https://patchwork.libcamera.org/patch/17399/","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":"<20220926095737.30506-3-naush@raspberrypi.com>","date":"2022-09-26T09:57:32","name":"[libcamera-devel,v3,2/7] delayed_controls: Add user cookie to DelayedControls","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"68c8bc825b3224c91d21f34f48ffbe732a1e6c22","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/1.1/people/34/?format=json","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/17399/mbox/","series":[{"id":3503,"url":"https://patchwork.libcamera.org/api/1.1/series/3503/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3503","date":"2022-09-26T09:57:30","name":"Raspberry Pi AGC digital gain fixes","version":3,"mbox":"https://patchwork.libcamera.org/series/3503/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17399/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17399/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 63A55BD16B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 26 Sep 2022 09:57:53 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 12E8262257;\n\tMon, 26 Sep 2022 11:57:53 +0200 (CEST)","from mail-wr1-x430.google.com (mail-wr1-x430.google.com\n\t[IPv6:2a00:1450:4864:20::430])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4EF4962253\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 26 Sep 2022 11:57:51 +0200 (CEST)","by mail-wr1-x430.google.com with SMTP id y5so9372501wrh.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 26 Sep 2022 02:57:51 -0700 (PDT)","from naush-laptop.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tp22-20020a05600c419600b003a4efb794d7sm10160671wmh.36.2022.09.26.02.57.49\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 26 Sep 2022 02:57:49 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1664186273;\n\tbh=IQ11zrL8V8CcGgD8ZYN8HRBUrVWQ+jswWC4R4SNfUE4=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=OYMomx2DeBq9YXRjsxmF7G0a989QwoWbtxDBIwlU7nRaxSiGZGOmrrTeMUQWRO3hA\n\ti7YbqZUyWt71cJVTIl8ZyPIFpwFK+HTG/nCZdU+k2EPYCrAVvGvUvdiaxt8JtktvcX\n\t4+9Dt2cut8COat1AZFU8oqz9A4t/1HfhV1MVMTqzXHjtK29URDpdk+Sa9wdTceK1L3\n\tKfIDhjebR4kXvrjw8ICVEN9X+Ga8l7Ro+210CXY32Clet46s/kYzoqQzJJ/YBLWh18\n\tnVyzq40x2iiCCtTy3/cvOSzgTsmtf7rl+79IpTKufoUmDJY1VZHKXHc8zeHih0mQN7\n\tJf4h3yZJSTYpA==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date;\n\tbh=Cw53K/DDEYku/Ke9JjEC7XgUkQg4Iac6pUiLiZMSKJI=;\n\tb=UhHUhNoTf9sru2w0ahF3BFSPLvdU63qyG+jbrGNErDxBoJxPB4uZ1OIt1CmdTmhKh5\n\tGOt0zCFW0SpK0ZRwS5BLe6HZURrIPzB6QqTPcPeo1+wxtIXF0RimvK5vDnn1oyvCfKXx\n\tWGaDYShbIuRHdhZJrWiOPleh35vLb0VuOUJs48UNxoTpl6/0p7BEp4r7OPVN5R1AKt+r\n\tDdQUvm7IcumeZAuAOqM4OCUEqqzU9xODiIf9Qfu/BFlKy4lQv7tL8b35IxsfmEBque23\n\tEvn1edD9BcebbNiF52oREQS+8FrjsOtQ9caVQqnLqepj39QozNPM7oASiwJN6opdo9+F\n\t2DaA=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"UhHUhNoT\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date;\n\tbh=Cw53K/DDEYku/Ke9JjEC7XgUkQg4Iac6pUiLiZMSKJI=;\n\tb=l4HyZxbNa3hYHcngwCjGObd1n3M18LYCIju681dQ914K+Avfio/q+snunlEFUDfY9a\n\tBWBqNpIviuRvYO1kgoh/yCztot3m22r3liQGy9H5/UwpLn2OKVd2vrjvxByiw3HAWLNa\n\t+DbmpOt0khOYImZaRNRgrPeChUYBBMsx2ISUB3pydxASbyn4+a6/lIUfoukroKGBY5ut\n\tPmfB5ymwWEpiCxSgUU1U2G3eCWMMxMdAQULjMnOpUs+/FjdqCG+Ri4isMtvmam7edxcv\n\tGLSbPe/nW5lqX5l7AuigW16FSIw20ccuqOj2HSDEi2v1X8hGgmlLo0yTcN061KKwZ5v6\n\tWnVQ==","X-Gm-Message-State":"ACrzQf0AdR7a/o7z+6nRa4Ctom2rb8t06qRgPsLQyvfraqeysVNmEkVU\n\totOkxrHJGnD6BJOnZ/vZpgc6JqFjagrNJM+F","X-Google-Smtp-Source":"AMsMyM7e9llJTcZAI1J50oNh+tscb1FNOiQSVOUC9bHCxZOc3tQWB9P5tV2z/wZVUeRago+2fvsSyw==","X-Received":"by 2002:a5d:5110:0:b0:22b:214:38e4 with SMTP id\n\ts16-20020a5d5110000000b0022b021438e4mr12901016wrt.219.1664186270819; \n\tMon, 26 Sep 2022 02:57:50 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 26 Sep 2022 10:57:32 +0100","Message-Id":"<20220926095737.30506-3-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20220926095737.30506-1-naush@raspberrypi.com>","References":"<20220926095737.30506-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 2/7] delayed_controls: Add user cookie\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>","From":"Naushir Patuck via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Naushir Patuck <naush@raspberrypi.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Allow the caller to provide a cookie value to DelayedControls::reset and\nDelayedControls::push. This cookie value is returned from DelayedControls::get\nfor the frame that has the control values applied to it.\n\nThe cookie value is useful in tracking when a set of controls has been applied\nto a frame. In a subsequent commit, it will be used by the Raspberry Pi IPA to\ntrack the IPA context used when setting the control values.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: David Plowman <david.plowman@raspberrypi.com>\nTested-by: David Plowman <david.plowman@raspberrypi.com>\n---\n include/libcamera/internal/delayed_controls.h |  8 +++++---\n src/libcamera/delayed_controls.cpp            | 20 ++++++++++++-------\n src/libcamera/pipeline/ipu3/ipu3.cpp          |  3 ++-\n .../pipeline/raspberrypi/raspberrypi.cpp      |  2 +-\n src/libcamera/pipeline/rkisp1/rkisp1.cpp      |  3 ++-\n test/delayed_controls.cpp                     |  8 ++++----\n 6 files changed, 27 insertions(+), 17 deletions(-)","diff":"diff --git a/include/libcamera/internal/delayed_controls.h b/include/libcamera/internal/delayed_controls.h\nindex de8026e3e4f0..c7e79150afb8 100644\n--- a/include/libcamera/internal/delayed_controls.h\n+++ b/include/libcamera/internal/delayed_controls.h\n@@ -9,6 +9,7 @@\n \n #include <stdint.h>\n #include <unordered_map>\n+#include <utility>\n \n #include <libcamera/controls.h>\n \n@@ -27,10 +28,10 @@ public:\n \tDelayedControls(V4L2Device *device,\n \t\t\tconst std::unordered_map<uint32_t, ControlParams> &controlParams);\n \n-\tvoid reset();\n+\tvoid reset(unsigned int cookie = 0);\n \n-\tbool push(const ControlList &controls);\n-\tControlList get(uint32_t sequence);\n+\tbool push(const ControlList &controls, unsigned int cookie = 0);\n+\tstd::pair<ControlList, unsigned int> get(uint32_t sequence);\n \n \tvoid applyControls(uint32_t sequence);\n \n@@ -77,6 +78,7 @@ private:\n \tuint32_t writeCount_;\n \t/* \\todo Evaluate if we should index on ControlId * or unsigned int */\n \tstd::unordered_map<const ControlId *, RingBuffer<Info>> values_;\n+\tRingBuffer<unsigned int> cookies_;\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/delayed_controls.cpp b/src/libcamera/delayed_controls.cpp\nindex 777441e8222a..3e7f60f9c421 100644\n--- a/src/libcamera/delayed_controls.cpp\n+++ b/src/libcamera/delayed_controls.cpp\n@@ -109,14 +109,16 @@ DelayedControls::DelayedControls(V4L2Device *device,\n \n /**\n  * \\brief Reset state machine\n+ * \\param[in] cookie User supplied reset cookie value\n  *\n  * Resets the state machine to a starting position based on control values\n  * retrieved from the device.\n  */\n-void DelayedControls::reset()\n+void DelayedControls::reset(unsigned int cookie)\n {\n \tqueueCount_ = 1;\n \twriteCount_ = 0;\n+\tcookies_[0] = cookie;\n \n \t/* Retrieve control as reported by the device. */\n \tstd::vector<uint32_t> ids;\n@@ -140,13 +142,15 @@ void DelayedControls::reset()\n /**\n  * \\brief Push a set of controls on the queue\n  * \\param[in] controls List of controls to add to the device queue\n+ * \\param[in] cookie User supplied cookie value for \\a controls\n  *\n  * Push a set of controls to the control queue. This increases the control queue\n- * depth by one.\n+ * depth by one. The \\a cookie value will be subsequently returned from\n+ * \\a get() for the frame with all controls applied.\n  *\n  * \\returns true if \\a controls are accepted, or false otherwise\n  */\n-bool DelayedControls::push(const ControlList &controls)\n+bool DelayedControls::push(const ControlList &controls, const unsigned int cookie)\n {\n \t/* Copy state from previous frame. */\n \tfor (auto &ctrl : values_) {\n@@ -180,6 +184,7 @@ bool DelayedControls::push(const ControlList &controls)\n \t\t\t<< \" at index \" << queueCount_;\n \t}\n \n+\tcookies_[queueCount_] = cookie;\n \tqueueCount_++;\n \n \treturn true;\n@@ -198,9 +203,10 @@ bool DelayedControls::push(const ControlList &controls)\n  * push(). The max history from the current sequence number that yields valid\n  * values are thus 16 minus number of controls pushed.\n  *\n- * \\return The controls at \\a sequence number\n+ * \\return The controls at \\a sequence number and associated user supplied\n+ * cookie value.\n  */\n-ControlList DelayedControls::get(uint32_t sequence)\n+std::pair<ControlList, unsigned int> DelayedControls::get(uint32_t sequence)\n {\n \tunsigned int index = std::max<int>(0, sequence - maxDelay_);\n \n@@ -217,7 +223,7 @@ ControlList DelayedControls::get(uint32_t sequence)\n \t\t\t<< \" at index \" << index;\n \t}\n \n-\treturn out;\n+\treturn { out, cookies_[index] };\n }\n \n /**\n@@ -276,7 +282,7 @@ void DelayedControls::applyControls(uint32_t sequence)\n \twhile (writeCount_ > queueCount_) {\n \t\tLOG(DelayedControls, Debug)\n \t\t\t<< \"Queue is empty, auto queue no-op.\";\n-\t\tpush({});\n+\t\tpush({}, cookies_[queueCount_ - 1]);\n \t}\n \n \tdevice_->setControls(&out);\ndiff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex 93219a6c1134..b0f0b22c5298 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -1385,7 +1385,8 @@ void IPU3CameraData::cio2BufferReady(FrameBuffer *buffer)\n \trequest->metadata().set(controls::SensorTimestamp,\n \t\t\t\tbuffer->metadata().timestamp);\n \n-\tinfo->effectiveSensorControls = delayedCtrls_->get(buffer->metadata().sequence);\n+\tauto [controls, cookie] = delayedCtrls_->get(buffer->metadata().sequence);\n+\tinfo->effectiveSensorControls = std::move(controls);\n \n \tif (request->findBuffer(&rawStream_))\n \t\tpipe()->completeBuffer(request, buffer);\ndiff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex dcd81650c32d..39e69d748693 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -1864,7 +1864,7 @@ void RPiCameraData::unicamBufferDequeue(FrameBuffer *buffer)\n \t\t * Lookup the sensor controls used for this frame sequence from\n \t\t * DelayedControl and queue them along with the frame buffer.\n \t\t */\n-\t\tControlList ctrl = delayedCtrls_->get(buffer->metadata().sequence);\n+\t\tauto [ctrl, cookie] = delayedCtrls_->get(buffer->metadata().sequence);\n \t\t/*\n \t\t * Add the frame timestamp to the ControlList for the IPA to use\n \t\t * as it does not receive the FrameBuffer object.\ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex 25fbf9f1a0a9..97df33ceece4 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -1187,8 +1187,9 @@ void PipelineHandlerRkISP1::statReady(FrameBuffer *buffer)\n \tif (data->frame_ <= buffer->metadata().sequence)\n \t\tdata->frame_ = buffer->metadata().sequence + 1;\n \n+\tauto [controls, cookie] = data->delayedCtrls_->get(buffer->metadata().sequence);\n \tdata->ipa_->processStatsBuffer(info->frame, info->statBuffer->cookie(),\n-\t\t\t\t       data->delayedCtrls_->get(buffer->metadata().sequence));\n+\t\t\t\t       controls);\n }\n \n REGISTER_PIPELINE_HANDLER(PipelineHandlerRkISP1)\ndiff --git a/test/delayed_controls.cpp b/test/delayed_controls.cpp\nindex a8ce9828d73d..322c545998b2 100644\n--- a/test/delayed_controls.cpp\n+++ b/test/delayed_controls.cpp\n@@ -96,7 +96,7 @@ protected:\n \n \t\t\tdelayed->applyControls(i);\n \n-\t\t\tControlList result = delayed->get(i);\n+\t\t\tauto [result, cookie] = delayed->get(i);\n \t\t\tint32_t brightness = result.get(V4L2_CID_BRIGHTNESS).get<int32_t>();\n \t\t\tif (brightness != value) {\n \t\t\t\tcerr << \"Failed single control without delay\"\n@@ -138,7 +138,7 @@ protected:\n \n \t\t\tdelayed->applyControls(i);\n \n-\t\t\tControlList result = delayed->get(i);\n+\t\t\tauto [result, cookie] = delayed->get(i);\n \t\t\tint32_t brightness = result.get(V4L2_CID_BRIGHTNESS).get<int32_t>();\n \t\t\tif (brightness != expected) {\n \t\t\t\tcerr << \"Failed single control with delay\"\n@@ -187,7 +187,7 @@ protected:\n \n \t\t\tdelayed->applyControls(i);\n \n-\t\t\tControlList result = delayed->get(i);\n+\t\t\tauto [result, cookie] = delayed->get(i);\n \t\t\tint32_t brightness = result.get(V4L2_CID_BRIGHTNESS).get<int32_t>();\n \t\t\tint32_t contrast = result.get(V4L2_CID_CONTRAST).get<int32_t>();\n \t\t\tif (brightness != expected || contrast != expected + 1) {\n@@ -247,7 +247,7 @@ protected:\n \n \t\t\tdelayed->applyControls(i);\n \n-\t\t\tControlList result = delayed->get(i);\n+\t\t\tauto [result, cookie] = delayed->get(i);\n \n \t\t\tint32_t brightness = result.get(V4L2_CID_BRIGHTNESS).get<int32_t>();\n \t\t\tint32_t contrast = result.get(V4L2_CID_CONTRAST).get<int32_t>();\n","prefixes":["libcamera-devel","v3","2/7"]}