{"id":10348,"url":"https://patchwork.libcamera.org/api/patches/10348/?format=json","web_url":"https://patchwork.libcamera.org/patch/10348/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20201105001546.1690179-12-niklas.soderlund@ragnatech.se>","date":"2020-11-05T00:15:46","name":"[libcamera-devel,11/11] libcamera: ipu3: Share parameter and statistic buffers with IPA","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"0f0d7d1be2f05199f87c46ef64dfd63d674994e4","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":{"id":16,"url":"https://patchwork.libcamera.org/api/users/16/?format=json","username":"neg","first_name":"Niklas","last_name":"Söderlund","email":"niklas.soderlund@ragnatech.se"},"mbox":"https://patchwork.libcamera.org/patch/10348/mbox/","series":[{"id":1447,"url":"https://patchwork.libcamera.org/api/series/1447/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1447","date":"2020-11-05T00:15:35","name":"libcamera: ipu3: Attach to an skeleton IPA","version":1,"mbox":"https://patchwork.libcamera.org/series/1447/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/10348/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/10348/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 ADB92BDB89\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  5 Nov 2020 00:16:25 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8032B62CCB;\n\tThu,  5 Nov 2020 01:16:25 +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 2F44862C7D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  5 Nov 2020 01:16:23 +0100 (CET)","from bismarck.berto.se (p4fca2458.dip0.t-ipconnect.de\n\t[79.202.36.88])\n\tby bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA\n\tid 6f8c5417-1efa-11eb-8a9c-005056917a89;\n\tThu, 05 Nov 2020 01:04:12 +0100 (CET)"],"X-Halon-ID":"6f8c5417-1efa-11eb-8a9c-005056917a89","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":"Thu,  5 Nov 2020 01:15:46 +0100","Message-Id":"<20201105001546.1690179-12-niklas.soderlund@ragnatech.se>","X-Mailer":"git-send-email 2.29.2","In-Reply-To":"<20201105001546.1690179-1-niklas.soderlund@ragnatech.se>","References":"<20201105001546.1690179-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH 11/11] libcamera: ipu3: Share parameter\n\tand statistic buffers with IPA","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 IPU3Frames helper to share parameter and statistic buffers with\nthe IPA. Track which parameter and statistic buffer is used for witch\nrequest and make sure the parameter buffers is filled in by the IPA\nbefore it's needed and that the statistic buffer is consumed and meta\ndata generated before completing the request.\n\nWith this change the IPU3 pipeline is prepared to fully operate with an\nIPA component.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/libcamera/pipeline/ipu3/ipu3.cpp | 106 +++++++++++++++++++++++++--\n 1 file changed, 100 insertions(+), 6 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex d161c2e68c0db0f2..58f8feaba4e87c54 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -28,6 +28,7 @@\n #include \"libcamera/internal/v4l2_controls.h\"\n \n #include \"cio2.h\"\n+#include \"frames.h\"\n #include \"imgu.h\"\n \n namespace libcamera {\n@@ -59,6 +60,8 @@ public:\n \n \tvoid imguOutputBufferReady(FrameBuffer *buffer);\n \tvoid cio2BufferReady(FrameBuffer *buffer);\n+\tvoid paramBufferReady(FrameBuffer *buffer);\n+\tvoid statBufferReady(FrameBuffer *buffer);\n \n \tCIO2Device cio2_;\n \tImgUDevice *imgu_;\n@@ -68,6 +71,7 @@ public:\n \tStream rawStream_;\n \n \tDelayedControls *delayedCtrls_;\n+\tstd::unique_ptr<IPU3Frames> frameInfo_;\n \n private:\n \tvoid actOnIpa(unsigned int id, const IPAOperationData &op);\n@@ -582,6 +586,8 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera)\n \tif (ret < 0)\n \t\treturn ret;\n \n+\tdata->frameInfo_->mapBuffers(imgu->paramBuffers_, imgu->statBuffers_);\n+\n \treturn 0;\n }\n \n@@ -589,6 +595,8 @@ int PipelineHandlerIPU3::freeBuffers(Camera *camera)\n {\n \tIPU3CameraData *data = cameraData(camera);\n \n+\tdata->frameInfo_->unmapBuffers();\n+\n \tdata->imgu_->freeBuffers();\n \n \treturn 0;\n@@ -684,6 +692,10 @@ int PipelineHandlerIPU3::queueRequestDevice(Camera *camera, Request *request)\n \tIPU3CameraData *data = cameraData(camera);\n \tint error = 0;\n \n+\tIPU3Frames::Info *info = data->frameInfo_->create(request);\n+\tif (!info)\n+\t\treturn -ENOENT;\n+\n \t/*\n \t * Queue a buffer on the CIO2, using the raw stream buffer provided in\n \t * the request, if any, or a CIO2 internal buffer otherwise.\n@@ -693,7 +705,10 @@ int PipelineHandlerIPU3::queueRequestDevice(Camera *camera, Request *request)\n \tif (!rawBuffer)\n \t\treturn -ENOMEM;\n \n+\tinfo->rawBuffer = rawBuffer;\n+\n \t/* Queue all buffers from the request aimed for the ImgU. */\n+\tbool onlyRaw = true;\n \tfor (auto it : request->buffers()) {\n \t\tconst Stream *stream = it.first;\n \t\tFrameBuffer *buffer = it.second;\n@@ -708,6 +723,23 @@ int PipelineHandlerIPU3::queueRequestDevice(Camera *camera, Request *request)\n \n \t\tif (ret < 0)\n \t\t\terror = ret;\n+\n+\t\tonlyRaw = false;\n+\t}\n+\n+\t/* If request only contains a raw buffer do not involve IPA. */\n+\tif (onlyRaw) {\n+\t\tinfo->paramDequeued = true;\n+\t\tinfo->metadataProcessed = true;\n+\t} else {\n+\t\tIPAOperationData op;\n+\t\top.operation = IPU3_IPA_EVENT_FILL_PARAMS;\n+\t\top.data = { info->id, info->paramBuffer->cookie() };\n+\t\top.controls = { request->controls() };\n+\t\tdata->ipa_->processEvent(op);\n+\n+\t\tdata->imgu_->param_->queueBuffer(info->paramBuffer);\n+\t\tdata->imgu_->stat_->queueBuffer(info->statBuffer);\n \t}\n \n \treturn error;\n@@ -845,6 +877,10 @@ int PipelineHandlerIPU3::registerCameras()\n \t\t\t\t\t&IPU3CameraData::imguOutputBufferReady);\n \t\tdata->imgu_->viewfinder_->bufferReady.connect(data.get(),\n \t\t\t\t\t&IPU3CameraData::imguOutputBufferReady);\n+\t\tdata->imgu_->param_->bufferReady.connect(data.get(),\n+\t\t\t\t\t&IPU3CameraData::paramBufferReady);\n+\t\tdata->imgu_->stat_->bufferReady.connect(data.get(),\n+\t\t\t\t\t&IPU3CameraData::statBufferReady);\n \n \t\t/* Create and register the Camera instance. */\n \t\tstd::string cameraId = cio2->sensor()->id();\n@@ -874,10 +910,12 @@ int IPU3CameraData::loadIPA()\n \n \tipa_->init(IPASettings{});\n \n+\tframeInfo_ = std::make_unique<IPU3Frames>(pipe_, ipa_.get());\n+\n \treturn 0;\n }\n \n-void IPU3CameraData::actOnIpa([[maybe_unused]] unsigned int id,\n+void IPU3CameraData::actOnIpa(unsigned int id,\n \t\t\t      const IPAOperationData &action)\n {\n \tswitch (action.operation) {\n@@ -886,6 +924,24 @@ void IPU3CameraData::actOnIpa([[maybe_unused]] unsigned int id,\n \t\tdelayedCtrls_->push(controls);\n \t\tbreak;\n \t}\n+\tcase IPU3_IPA_ACTION_PARAM_FILLED: {\n+\t\tIPU3Frames::Info *info = frameInfo_->find(id);\n+\t\tif (!info)\n+\t\t\tbreak;\n+\n+\t\tinfo->paramFilled = true;\n+\t\tbreak;\n+\t}\n+\tcase IPU3_IPA_ACTION_METADATA_READY: {\n+\t\tIPU3Frames::Info *info = frameInfo_->find(id);\n+\t\tif (!info)\n+\t\t\tbreak;\n+\n+\t\tinfo->request->metadata() = action.controls[0];\n+\t\tinfo->metadataProcessed = true;\n+\t\tframeInfo_->tryComplete(info);\n+\t\tbreak;\n+\t}\n \tdefault:\n \t\tLOG(IPU3, Error) << \"Unknown action \" << action.operation;\n \t\tbreak;\n@@ -906,13 +962,15 @@ void IPU3CameraData::imguOutputBufferReady(FrameBuffer *buffer)\n {\n \tRequest *request = buffer->request();\n \n-\tif (!pipe_->completeBuffer(request, buffer))\n-\t\t/* Request not completed yet, return here. */\n+\tpipe_->completeBuffer(request, buffer);\n+\n+\tIPU3Frames::Info *info = frameInfo_->find(buffer);\n+\tif (!info)\n \t\treturn;\n \n-\t/* Mark the request as complete. */\n \trequest->metadata().set(controls::draft::PipelineDepth, 3);\n-\tpipe_->completeRequest(request);\n+\n+\tframeInfo_->tryComplete(info);\n }\n \n /**\n@@ -928,6 +986,10 @@ void IPU3CameraData::cio2BufferReady(FrameBuffer *buffer)\n \tif (buffer->metadata().status == FrameMetadata::FrameCancelled)\n \t\treturn;\n \n+\tIPU3Frames::Info *info = frameInfo_->find(buffer);\n+\tif (!info)\n+\t\treturn;\n+\n \tRequest *request = buffer->request();\n \n \t/*\n@@ -938,14 +1000,46 @@ void IPU3CameraData::cio2BufferReady(FrameBuffer *buffer)\n \t\tbool isComplete = pipe_->completeBuffer(request, buffer);\n \t\tif (isComplete) {\n \t\t\trequest->metadata().set(controls::draft::PipelineDepth, 2);\n-\t\t\tpipe_->completeRequest(request);\n+\t\t\tframeInfo_->tryComplete(info);\n \t\t\treturn;\n \t\t}\n \t}\n \n+\tif (!info->paramFilled)\n+\t\tLOG(IPU3, Info)\n+\t\t\t<< \"Parameters not ready on time for id \" << info->id;\n+\n \timgu_->input_->queueBuffer(buffer);\n }\n \n+void IPU3CameraData::paramBufferReady(FrameBuffer *buffer)\n+{\n+\tif (buffer->metadata().status == FrameMetadata::FrameCancelled)\n+\t\treturn;\n+\n+\tIPU3Frames::Info *info = frameInfo_->find(buffer);\n+\tif (!info)\n+\t\treturn;\n+\n+\tinfo->paramDequeued = true;\n+\tframeInfo_->tryComplete(info);\n+}\n+\n+void IPU3CameraData::statBufferReady(FrameBuffer *buffer)\n+{\n+\tif (buffer->metadata().status == FrameMetadata::FrameCancelled)\n+\t\treturn;\n+\n+\tIPU3Frames::Info *info = frameInfo_->find(buffer);\n+\tif (!info)\n+\t\treturn;\n+\n+\tIPAOperationData op;\n+\top.operation = IPU3_IPA_EVENT_PARSE_STAT;\n+\top.data = { info->id, info->statBuffer->cookie() };\n+\tipa_->processEvent(op);\n+}\n+\n REGISTER_PIPELINE_HANDLER(PipelineHandlerIPU3)\n \n } /* namespace libcamera */\n","prefixes":["libcamera-devel","11/11"]}