Show a patch.

GET /api/patches/10877/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 10877,
    "url": "https://patchwork.libcamera.org/api/patches/10877/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/10877/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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": "<20210116114805.905397-4-niklas.soderlund@ragnatech.se>",
    "date": "2021-01-16T11:48:00",
    "name": "[libcamera-devel,v5,3/8] libcamera: raspberrypi: Switch to DelayedControls",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "77ead1d784a025f9aa0b9b0678ae24d10ce871d5",
    "submitter": {
        "id": 5,
        "url": "https://patchwork.libcamera.org/api/people/5/?format=api",
        "name": "Niklas Söderlund",
        "email": "niklas.soderlund@ragnatech.se"
    },
    "delegate": {
        "id": 16,
        "url": "https://patchwork.libcamera.org/api/users/16/?format=api",
        "username": "neg",
        "first_name": "Niklas",
        "last_name": "Söderlund",
        "email": "niklas.soderlund@ragnatech.se"
    },
    "mbox": "https://patchwork.libcamera.org/patch/10877/mbox/",
    "series": [
        {
            "id": 1579,
            "url": "https://patchwork.libcamera.org/api/series/1579/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1579",
            "date": "2021-01-16T11:47:57",
            "name": "libcamera: Add helper for controls that take effect with a delay",
            "version": 5,
            "mbox": "https://patchwork.libcamera.org/series/1579/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/10877/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/10877/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 E06B4BD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 16 Jan 2021 11:48:20 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 585106811A;\n\tSat, 16 Jan 2021 12:48:20 +0100 (CET)",
            "from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net\n\t[195.74.38.229])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5182960109\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 16 Jan 2021 12:48:19 +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 b93207ca-57f0-11eb-a076-005056917f90;\n\tSat, 16 Jan 2021 12:48:18 +0100 (CET)"
        ],
        "X-Halon-ID": "b93207ca-57f0-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",
        "Date": "Sat, 16 Jan 2021 12:48:00 +0100",
        "Message-Id": "<20210116114805.905397-4-niklas.soderlund@ragnatech.se>",
        "X-Mailer": "git-send-email 2.30.0",
        "In-Reply-To": "<20210116114805.905397-1-niklas.soderlund@ragnatech.se>",
        "References": "<20210116114805.905397-1-niklas.soderlund@ragnatech.se>",
        "MIME-Version": "1.0",
        "Subject": "[libcamera-devel] [PATCH v5 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>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n* Changes since v4\n- Rename IPA_ACTION_V4L2_SET_STAGGERED to IPA_ACTION_SET_DELAYED_CTRLS.\n- Optimize copy of controls in PipelineHandlerRPi::start().\n- Update comments and an error message.\n---\n include/libcamera/ipa/raspberrypi.h           |  2 +-\n src/ipa/raspberrypi/raspberrypi.cpp           |  2 +-\n .../pipeline/raspberrypi/raspberrypi.cpp      | 57 ++++++++-----------\n 3 files changed, 27 insertions(+), 34 deletions(-)",
    "diff": "diff --git a/include/libcamera/ipa/raspberrypi.h b/include/libcamera/ipa/raspberrypi.h\nindex 01fe5abce9a6072c..c0516cbe786a1636 100644\n--- a/include/libcamera/ipa/raspberrypi.h\n+++ b/include/libcamera/ipa/raspberrypi.h\n@@ -26,7 +26,7 @@ enum ConfigParameters {\n };\n \n enum Operations {\n-\tIPA_ACTION_V4L2_SET_STAGGERED = 1,\n+\tIPA_ACTION_SET_DELAYED_CTRLS = 1,\n \tIPA_ACTION_V4L2_SET_ISP,\n \tIPA_ACTION_STATS_METADATA_COMPLETE,\n \tIPA_ACTION_RUN_ISP,\ndiff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp\nindex 8af3d603a3ff64b9..2d8fd793654e402c 100644\n--- a/src/ipa/raspberrypi/raspberrypi.cpp\n+++ b/src/ipa/raspberrypi/raspberrypi.cpp\n@@ -944,7 +944,7 @@ void IPARPi::processStats(unsigned int bufferId)\n \t\tapplyAGC(&agcStatus, ctrls);\n \n \t\tIPAOperationData op;\n-\t\top.operation = RPi::IPA_ACTION_V4L2_SET_STAGGERED;\n+\t\top.operation = RPi::IPA_ACTION_SET_DELAYED_CTRLS;\n \t\top.controls.emplace_back(ctrls);\n \t\tqueueFrameAction.emit(0, op);\n \t}\ndiff --git a/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp b/src/libcamera/pipeline/raspberrypi/raspberrypi.cpp\nindex f121328ee9a9b6f2..3613671aded0a8fd 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@@ -1227,21 +1221,24 @@ int RPiCameraData::configureIPA(const CameraConfiguration *config)\n \tunsigned int resultIdx = 0;\n \tif (result.operation & RPi::IPA_CONFIG_STAGGERED_WRITE) {\n \t\t/*\n-\t\t * Setup our staggered control writer with the sensor default\n+\t\t * Setup our delayed 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+\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@@ -1268,10 +1265,10 @@ void RPiCameraData::queueFrameAction([[maybe_unused]] unsigned int frame,\n \t * a stopped state.\n \t */\n \tswitch (action.operation) {\n-\tcase RPi::IPA_ACTION_V4L2_SET_STAGGERED: {\n+\tcase RPi::IPA_ACTION_SET_DELAYED_CTRLS: {\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) << \"Failed to set delayed controls\";\n \t\tgoto done;\n \t}\n \n@@ -1375,11 +1372,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 +1384,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",
        "v5",
        "3/8"
    ]
}