Patch Detail
Show a patch.
GET /api/1.1/patches/11042/?format=api
{ "id": 11042, "url": "https://patchwork.libcamera.org/api/1.1/patches/11042/?format=api", "web_url": "https://patchwork.libcamera.org/patch/11042/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20210128091050.881815-6-naush@raspberrypi.com>", "date": "2021-01-28T09:10:50", "name": "[libcamera-devel,v3,5/5] pipeline: raspberrypi: Add notion of priority write to StaggeredCtrl", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "565ce372e2965ccd84ef7dd857f2e03d4ec03200", "submitter": { "id": 34, "url": "https://patchwork.libcamera.org/api/1.1/people/34/?format=api", "name": "Naushir Patuck", "email": "naush@raspberrypi.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/11042/mbox/", "series": [ { "id": 1619, "url": "https://patchwork.libcamera.org/api/1.1/series/1619/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1619", "date": "2021-01-28T09:10:45", "name": "Raspberry Pi: FrameDurations control refinements", "version": 3, "mbox": "https://patchwork.libcamera.org/series/1619/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/11042/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/11042/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 1BBB5BD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 28 Jan 2021 09:11:03 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CC0DC68394;\n\tThu, 28 Jan 2021 10:11:02 +0100 (CET)", "from mail-wm1-x330.google.com (mail-wm1-x330.google.com\n\t[IPv6:2a00:1450:4864:20::330])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5D3686838C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 28 Jan 2021 10:10:59 +0100 (CET)", "by mail-wm1-x330.google.com with SMTP id s24so4731209wmj.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 28 Jan 2021 01:10:59 -0800 (PST)", "from naushir-VirtualBox.patuck.local ([88.97.76.4])\n\tby smtp.gmail.com with ESMTPSA id\n\tf17sm6517056wrv.0.2021.01.28.01.10.57\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 28 Jan 2021 01:10:58 -0800 (PST)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"g6F7+v0X\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=G0NLRn1CkpdPEZDB7Iv8jjTSZZtCx6D+TwurDlEp7/Q=;\n\tb=g6F7+v0X37O/dMM0MaCfp8n9H0b4UbP93PHovoOc83cFGf/kN0nzuxsqY7lWRe4R45\n\tc0DGGMSOnOH47sDVaea3TJyXdelskP+ShPuVnjzP9m2d7zJA6OnN6OJ506PhGaEQAOzW\n\tSGvK06c2nM3t6q/NZNacf7acdur39UUZo1fKDxnjv86NWjBPS3JQI4uUuqkv+UKsrWgW\n\tZCEefLuC278UP8Pa0lrgpMiLfUgB5ov4I00AAvxtUd1QRhOrFJkI+WXIENUZj2lTxuBV\n\tgOqt0BS+jOAkktcrmeM7FRbeU7EP63V78VUZnevsFfKb9u9chUW9RORIqq4I8+ogw4/V\n\tqaCQ==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=G0NLRn1CkpdPEZDB7Iv8jjTSZZtCx6D+TwurDlEp7/Q=;\n\tb=Ruk5/Kpe8z5/uXAd1NeIkWCQZSSvB06nptPduzQUWdCz/dN0y9QMhcpzdmFpadMQnm\n\t2Hm+nu5zpTkEiqXyyGP1eWJmfDOZIqMDm0zcOzMUR8YRMjO3fXFqnSrZbx1LJoIxCl72\n\tn8RXN0BYw3JlNcsfw6VTafKFmfZM424iRV303mfJDLEIyMYTO9RSzL3POc/8eZnisPdo\n\trQ4x/bPoGWNvlAP6JAk8tLM6ImmIceOeqXTATps5ZMGob/4KlXs6JSBZp0xaIoz8YHul\n\taOu7my7J2y8rBIHe5odj1RCRhfuH73vziV3qFNLWQgy7X6tZ9efB2kgHQxzk6W9y63kp\n\t6etA==", "X-Gm-Message-State": "AOAM530R8Vtv+1PriRtn/seTa0NIbSEyYCA7Mebj+Y+ZXJnDwpcs+bp/\n\t1UP5oygweZ6hsJxIX5aAdBwGWig4WkzONGPv", "X-Google-Smtp-Source": "ABdhPJwt2z/bX7K9JNOVOcfJYj1V61DkT5V6pvnBkw7TqEgQO0sbkOoI1dSZ6yFDa6bkn+xDaOF7yw==", "X-Received": "by 2002:a05:600c:215:: with SMTP id\n\t21mr7749851wmi.54.1611825058593; \n\tThu, 28 Jan 2021 01:10:58 -0800 (PST)", "From": "Naushir Patuck <naush@raspberrypi.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Thu, 28 Jan 2021 09:10:50 +0000", "Message-Id": "<20210128091050.881815-6-naush@raspberrypi.com>", "X-Mailer": "git-send-email 2.25.1", "In-Reply-To": "<20210128091050.881815-1-naush@raspberrypi.com>", "References": "<20210128091050.881815-1-naush@raspberrypi.com>", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH v3 5/5] pipeline: raspberrypi: Add notion\n\tof priority write to StaggeredCtrl", "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=\"us-ascii\"", "Content-Transfer-Encoding": "7bit", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "If an exposure time change adjusts the vblanking limits, and we write\nboth VBLANK and EXPOSURE controls as a set, the latter may fail if the\nvalue is outside of the limits calculated by the old VBLANK value. This\nis a limitation in V4L2 and cannot be fixed by writing VBLANK before\nEXPOSURE.\n\nThe workaround here is to have the StaggeredCtrl mark the\nVBLANK control as \"priority write\", which then write VBLANK separately\nfrom (and ahead of) any other controls. This way, the sensor driver will\nupdate the EXPOSURE control with new limits before the new values is\npresented, and will thus be seen as valid.\n\nIn addition to this, the following changes have also been made to\nthe module:\n\n- The initializer list passed into init() now uses a structure type\n instead of a std::pair.\n- Use unsigned int to store control delays to avoid unnecessary casts.\n\nStaggeredCtrl is due to be deprecated and replaced by DelayedCtrl, so\nthis change serves more a working proof-of-concept on the workaround,\nand not much care has been taken to provide a nice new API for applying\nthis \"priority write\" flag to the control. A similar workaround must be\navailable to DelayedCtrl eventually.\n\nSigned-off-by: Naushir Patuck <naush@raspberrypi.com>\n---\n src/ipa/raspberrypi/raspberrypi.cpp | 5 ++-\n .../pipeline/raspberrypi/raspberrypi.cpp | 12 ++++--\n .../pipeline/raspberrypi/staggered_ctrl.cpp | 41 +++++++++++++------\n .../pipeline/raspberrypi/staggered_ctrl.h | 17 ++++++--\n 4 files changed, 54 insertions(+), 21 deletions(-)", "diff": "diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex 8c0e699184f6..2ad7b7dabb3e 100644\n--- a/src/ipa/raspberrypi/raspberrypi.cpp\n+++ b/src/ipa/raspberrypi/raspberrypi.cpp\n@@ -1038,8 +1038,9 @@ void IPARPi::applyAGC(const struct AgcStatus *agcStatus, ControlList &ctrls)\n \n \t/*\n \t * Due to the behavior of V4L2, the current value of VBLANK could clip the\n-\t * exposure time without us knowing. The next time though this function should\n-\t * clip exposure correctly.\n+\t * exposure time without us knowing. We get around this by ensuring the\n+\t * staggered write component submits VBLANK separately from, and before the\n+\t * EXPOSURE control.\n \t */\n \tctrls.set(V4L2_CID_VBLANK, vblanking);\n \tctrls.set(V4L2_CID_EXPOSURE, exposureLines);\ndiff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex 524cc960dd37..2118f2e72486 100644\n--- a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\n@@ -1229,12 +1229,18 @@ int RPiCameraData::configureIPA(const CameraConfiguration *config)\n \t\t/*\n \t\t * Setup our staggered control writer with the sensor default\n \t\t * gain and exposure delays.\n+\t\t *\n+\t\t * VBLANK must be flagged as \"priority write\" to allow it to\n+\t\t * be set ahead of (and separate from) all other controls that\n+\t\t * are batched together. This is needed so that any update to the\n+\t\t * EXPOSURE control will be validated based on the new VBLANK\n+\t\t * control value.\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-\t\t\t\t\t { V4L2_CID_VBLANK, result.data[resultIdx++] } });\n+\t\t\t\t\t { { V4L2_CID_ANALOGUE_GAIN, result.data[resultIdx++], false },\n+\t\t\t\t\t { V4L2_CID_EXPOSURE, result.data[resultIdx++], false },\n+\t\t\t\t\t { V4L2_CID_VBLANK, result.data[resultIdx++], true } });\n \t\t\tsensorMetadata_ = result.data[resultIdx++];\n \t\t}\n \t}\ndiff --git a/src/libcamera/pipeline/raspberrypi/staggered_ctrl.cpp b/src/libcamera/pipeline/raspberrypi/staggered_ctrl.cpp\nindex 62605c0fceee..498cd65b4cb6 100644\n--- a/src/libcamera/pipeline/raspberrypi/staggered_ctrl.cpp\n+++ b/src/libcamera/pipeline/raspberrypi/staggered_ctrl.cpp\n@@ -22,21 +22,23 @@ LOG_DEFINE_CATEGORY(RPI_S_W)\n namespace RPi {\n \n void StaggeredCtrl::init(V4L2VideoDevice *dev,\n-\t std::initializer_list<std::pair<const uint32_t, uint8_t>> delayList)\n+\t\t\t std::initializer_list<CtrlInitParams> ctrlList)\n {\n \tstd::lock_guard<std::mutex> lock(lock_);\n \n \tdev_ = dev;\n-\tdelay_ = delayList;\n+\tctrlParams_.clear();\n \tctrl_.clear();\n \n-\t/* Find the largest delay across all controls. */\n \tmaxDelay_ = 0;\n-\tfor (auto const &p : delay_) {\n+\tfor (auto const &c : ctrlList) {\n \t\tLOG(RPI_S_W, Info) << \"Init ctrl \"\n-\t\t\t\t << utils::hex(p.first) << \" with delay \"\n-\t\t\t\t << static_cast<int>(p.second);\n-\t\tmaxDelay_ = std::max(maxDelay_, p.second);\n+\t\t\t\t << utils::hex(c.id) << \" with delay \"\n+\t\t\t\t << static_cast<int>(c.delay);\n+\n+\t\tctrlParams_[c.id] = { c.delay, c.priorityWrite };\n+\t\t/* Find the largest delay across all controls. */\n+\t\tmaxDelay_ = std::max(maxDelay_, c.delay);\n \t}\n \n \tinit_ = true;\n@@ -67,7 +69,7 @@ bool StaggeredCtrl::set(uint32_t ctrl, int32_t value)\n \tstd::lock_guard<std::mutex> lock(lock_);\n \n \t/* Can we find this ctrl as one that is registered? */\n-\tif (delay_.find(ctrl) == delay_.end())\n+\tif (ctrlParams_.find(ctrl) == ctrlParams_.end())\n \t\treturn false;\n \n \tctrl_[ctrl][setCount_].value = value;\n@@ -82,7 +84,7 @@ bool StaggeredCtrl::set(std::initializer_list<std::pair<const uint32_t, int32_t>\n \n \tfor (auto const &p : ctrlList) {\n \t\t/* Can we find this ctrl? */\n-\t\tif (delay_.find(p.first) == delay_.end())\n+\t\tif (ctrlParams_.find(p.first) == ctrlParams_.end())\n \t\t\treturn false;\n \n \t\tctrl_[p.first][setCount_] = CtrlInfo(p.second);\n@@ -97,7 +99,7 @@ bool StaggeredCtrl::set(const ControlList &controls)\n \n \tfor (auto const &p : controls) {\n \t\t/* Can we find this ctrl? */\n-\t\tif (delay_.find(p.first) == delay_.end())\n+\t\tif (ctrlParams_.find(p.first) == ctrlParams_.end())\n \t\t\treturn false;\n \n \t\tctrl_[p.first][setCount_] = CtrlInfo(p.second.get<int32_t>());\n@@ -117,12 +119,25 @@ int StaggeredCtrl::write()\n \tControlList controls(dev_->controls());\n \n \tfor (auto &p : ctrl_) {\n-\t\tint delayDiff = maxDelay_ - delay_[p.first];\n+\t\tint delayDiff = maxDelay_ - ctrlParams_[p.first].delay;\n \t\tint index = std::max<int>(0, setCount_ - delayDiff);\n \n \t\tif (p.second[index].updated) {\n-\t\t\t/* We need to write this value out. */\n-\t\t\tcontrols.set(p.first, p.second[index].value);\n+\t\t\tif (ctrlParams_[p.first].priorityWrite) {\n+\t\t\t\t/*\n+\t\t\t\t * This control must be written now, it could\n+\t\t\t\t * affect validity of the other controls.\n+\t\t\t\t */\n+\t\t\t\tControlList immediate(dev_->controls());\n+\t\t\t\timmediate.set(p.first, p.second[index].value);\n+\t\t\t\tdev_->setControls(&immediate);\n+\t\t\t} else {\n+\t\t\t\t/*\n+\t\t\t\t * Batch up the list of controls and write them\n+\t\t\t\t * at the end of the function.\n+\t\t\t\t */\n+\t\t\t\tcontrols.set(p.first, p.second[index].value);\n+\t\t\t}\n \t\t\tp.second[index].updated = false;\n \t\t\tLOG(RPI_S_W, Debug) << \"Writing ctrl \"\n \t\t\t\t\t << utils::hex(p.first) << \" to \"\ndiff --git a/src/libcamera/pipeline/raspberrypi/staggered_ctrl.h b/src/libcamera/pipeline/raspberrypi/staggered_ctrl.h\nindex 382fa31a6853..637629c0d9a8 100644\n--- a/src/libcamera/pipeline/raspberrypi/staggered_ctrl.h\n+++ b/src/libcamera/pipeline/raspberrypi/staggered_ctrl.h\n@@ -23,6 +23,12 @@ namespace RPi {\n class StaggeredCtrl\n {\n public:\n+\tstruct CtrlInitParams {\n+\t\tunsigned int id;\n+\t\tunsigned int delay;\n+\t\tbool priorityWrite;\n+\t};\n+\n \tStaggeredCtrl()\n \t\t: init_(false), setCount_(0), getCount_(0), maxDelay_(0)\n \t{\n@@ -34,7 +40,7 @@ public:\n \t}\n \n \tvoid init(V4L2VideoDevice *dev,\n-\t\t std::initializer_list<std::pair<const uint32_t, uint8_t>> delayList);\n+\t\t std::initializer_list<CtrlInitParams> ctrlList);\n \tvoid reset();\n \n \tvoid get(std::unordered_map<uint32_t, int32_t> &ctrl, uint8_t offset = 0);\n@@ -79,12 +85,17 @@ private:\n \t\t}\n \t};\n \n+\tstruct CtrlParams {\n+\t\tunsigned int delay;\n+\t\tbool priorityWrite;\n+\t};\n+\n \tbool init_;\n \tuint32_t setCount_;\n \tuint32_t getCount_;\n-\tuint8_t maxDelay_;\n+\tunsigned int maxDelay_;\n \tV4L2VideoDevice *dev_;\n-\tstd::unordered_map<uint32_t, uint8_t> delay_;\n+\tstd::unordered_map<uint32_t, CtrlParams> ctrlParams_;\n \tstd::unordered_map<uint32_t, CircularArray> ctrl_;\n \tstd::mutex lock_;\n };\n", "prefixes": [ "libcamera-devel", "v3", "5/5" ] }