{"id":17298,"url":"https://patchwork.libcamera.org/api/1.1/patches/17298/?format=json","web_url":"https://patchwork.libcamera.org/patch/17298/","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":"<20220905073956.7342-3-naush@raspberrypi.com>","date":"2022-09-05T07:39:51","name":"[libcamera-devel,v2,2/7] delayed_controls: Add user cookie to DelayedControls","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"5f175fbfd60f3ea772c2d75255b303124893b203","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/17298/mbox/","series":[{"id":3471,"url":"https://patchwork.libcamera.org/api/1.1/series/3471/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=3471","date":"2022-09-05T07:39:49","name":"Raspberry Pi AGC digial gain fixes","version":2,"mbox":"https://patchwork.libcamera.org/series/3471/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/17298/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/17298/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 63A9EC3272\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  5 Sep 2022 07:40:06 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 2066962061;\n\tMon,  5 Sep 2022 09:40:06 +0200 (CEST)","from mail-wm1-x332.google.com (mail-wm1-x332.google.com\n\t[IPv6:2a00:1450:4864:20::332])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 185CC6201C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  5 Sep 2022 09:40:04 +0200 (CEST)","by mail-wm1-x332.google.com with SMTP id\n\tz14-20020a7bc7ce000000b003a5db0388a8so6446870wmk.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 05 Sep 2022 00:40:04 -0700 (PDT)","from naush-laptop.localdomain ([93.93.133.154])\n\tby smtp.gmail.com with ESMTPSA id\n\tv16-20020a5d5910000000b00228a6ce17b4sm1342841wrd.37.2022.09.05.00.40.01\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tMon, 05 Sep 2022 00:40:02 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1662363606;\n\tbh=g+yojow+QSITK4eB7dyNWvdns/J7/9ZmNwJ1ghjHEIY=;\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=nm+P+hMKVg2aiuuprv1Cv4nyuBXFH3H9Uax6KL+xUf46ob+YgXNSQrbDKTBCeXvub\n\tXO3Yqe9zWncjlC5vDrbeo0+N5umlguTNJ37c5U3AfsRKG/dumOTy8OkOCnDRj2rGrm\n\tTPPv/HJGBEuGRI+4DsZMuuhEkGtkc9IrDgTao5QQLgl+VcZha55CgQeYOjvEDM0HPS\n\t4KpPkJoWWPAITclxmIRGnxtMmXUSGT/5wI7c7xqRZlJxMYsea8O4DFBFmu1njYlHM8\n\tMYu7UGEF75BBnovxJNAeoMXJrnHP4rfALncJYhZ2sEaNp9cw9BKvsh2KWxcJIsSG4X\n\tnZ0lM6wuULP4Q==","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=TLd3IVP2iO3I4bZNxOYJauQGUqiKFviOy3ElyLrY/78=;\n\tb=iPefwIYeatMCNizzzBR4qfU8y2g7kRZg+RSaix+K3Lz6uRqGdp4YuRSo4bxcoR58Hf\n\t55edx+nHo1lfb85uZIyF9BzgOxt3Cx4hkmCKID8MMFQwEtxWpOyiJ1tbJkc1mSHACVCj\n\tOnDGacOLXSIUKn/4P83xa9an34MhWJV3nyyq5FlE/x3Yhc/70+r3HR9PXBqXi8WjB/8q\n\tuGsdZMyxhgGURQ7PJRIkAgo7sfqq+X+gykENpeN5s2wm4i4mPqLiU4hqsdKVL9/oXB7e\n\tOytN+se/wXPIei+7UZZd22yANhHiQqxWYiNrqx0YuZjfAuWtZIMDmIGSkuWmhmWpd5hV\n\tEB3A=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"iPefwIYe\"; 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=TLd3IVP2iO3I4bZNxOYJauQGUqiKFviOy3ElyLrY/78=;\n\tb=7dBfI920RotyNOI+aQ7K7Cu4e9rgvsOl5xSPz0ont7FF3vj4X24GU3T1d86SGl2Zq6\n\twEkgD2X5hUjAaOj0gnPF3QceAEV+DWbSHvH4lXdcMkLKmSIo9H63U3Va/TqOxFMdO6eo\n\tzXJH5JkGWXRb59kfNTrw5wziGEE2YTi3nru0MUUe5UNzXbd9QR8tmHFRkTmD8sxvZ7jK\n\t042UXNCXAcBTbX+M1Ac12ku+42IH2O6AIpQt6lUAEdhdcSvYB4NSioNgXJtrsQzkxw4U\n\tGsSDZaUPKgZLooOlPrYtFbGB9B/Hs8vtUl8h8TXYnkBDvi50X8BYqNdMGx8DfZGLZAi8\n\tfo+g==","X-Gm-Message-State":"ACgBeo2UFb6PFORZXiXiD3NduLkROsd2ksMEU5TozkKDc2Q21446Pw+T\n\t7Q5QMQ+jyzBbngz2dc3KVCvrC3rbTQ2OkQ5b","X-Google-Smtp-Source":"AA6agR70xaqn+T2vtJo1y9nmESOLXLR6plPTHBnyCQzrl5RGH7GPtLikn7aikVTD5+mo6jWjFwxqug==","X-Received":"by 2002:a7b:c045:0:b0:3a5:ff4e:5528 with SMTP id\n\tu5-20020a7bc045000000b003a5ff4e5528mr10252712wmc.150.1662363603332; \n\tMon, 05 Sep 2022 00:40:03 -0700 (PDT)","To":"libcamera-devel@lists.libcamera.org","Date":"Mon,  5 Sep 2022 08:39:51 +0100","Message-Id":"<20220905073956.7342-3-naush@raspberrypi.com>","X-Mailer":"git-send-email 2.25.1","In-Reply-To":"<20220905073956.7342-1-naush@raspberrypi.com>","References":"<20220905073956.7342-1-naush@raspberrypi.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v2 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>\n---\n include/libcamera/internal/delayed_controls.h   |  8 +++++---\n src/libcamera/delayed_controls.cpp              | 17 +++++++++++------\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, 25 insertions(+), 16 deletions(-)","diff":"diff --git a/include/libcamera/internal/delayed_controls.h b/include/libcamera/internal/delayed_controls.h\nindex f6e622f1dfba..fa222bb17d23 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 *, ControlRingBuffer<Info>> values_;\n+\tControlRingBuffer<unsigned int> cookies_;\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/delayed_controls.cpp b/src/libcamera/delayed_controls.cpp\nindex 777441e8222a..c2198d0e8d77 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,14 @@ 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  *\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 +183,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 +202,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 +222,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 +281,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 b4094898ca6c..d34a906c3cea 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -1848,7 +1848,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 03bbe6b467ae..cec90810ff95 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -1159,8 +1159,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, cooke] = 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","v2","2/7"]}