Patch Detail
Show a patch.
GET /api/1.1/patches/3972/?format=api
{ "id": 3972, "url": "https://patchwork.libcamera.org/api/1.1/patches/3972/?format=api", "web_url": "https://patchwork.libcamera.org/patch/3972/", "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": "<20200606150436.1851700-11-niklas.soderlund@ragnatech.se>", "date": "2020-06-06T15:04:36", "name": "[libcamera-devel,v2,10/10] libcamera: ipu3: Allow zero-copy RAW stream capture", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "1235f2430aa4a72edf2bc59cc52785093e3d3b52", "submitter": { "id": 5, "url": "https://patchwork.libcamera.org/api/1.1/people/5/?format=api", "name": "Niklas Söderlund", "email": "niklas.soderlund@ragnatech.se" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/3972/mbox/", "series": [ { "id": 964, "url": "https://patchwork.libcamera.org/api/1.1/series/964/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=964", "date": "2020-06-06T15:04:26", "name": "libcamera: ipu3: Allow zero-copy RAW stream", "version": 2, "mbox": "https://patchwork.libcamera.org/series/964/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/3972/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/3972/checks/", "tags": {}, "headers": { "Return-Path": "<niklas.soderlund@ragnatech.se>", "Received": [ "from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net\n\t[195.74.38.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2F40563C29\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 6 Jun 2020 17:05:00 +0200 (CEST)", "from bismarck.berto.se (p4fca2eca.dip0.t-ipconnect.de\n\t[79.202.46.202]) by bin-vsp-out-01.atm.binero.net (Halon) with ESMTPA\n\tid 159edbb3-a807-11ea-933e-005056917a89;\n\tSat, 06 Jun 2020 17:04:57 +0200 (CEST)" ], "X-Halon-ID": "159edbb3-a807-11ea-933e-005056917a89", "Authorized-sender": "niklas@soderlund.pp.se", "From": "=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Sat, 6 Jun 2020 17:04:36 +0200", "Message-Id": "<20200606150436.1851700-11-niklas.soderlund@ragnatech.se>", "X-Mailer": "git-send-email 2.26.2", "In-Reply-To": "<20200606150436.1851700-1-niklas.soderlund@ragnatech.se>", "References": "<20200606150436.1851700-1-niklas.soderlund@ragnatech.se>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "Subject": "[libcamera-devel] [PATCH v2 10/10] libcamera: ipu3: Allow zero-copy\n\tRAW stream capture", "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>", "X-List-Received-Date": "Sat, 06 Jun 2020 15:05:01 -0000" }, "content": "With the refactored CIO2 interface it's now easy to add zero-copy for\nbuffers in the RAW stream. Use the internally allocated buffers inside\nthe CIO2Device if no buffer for the RAW stream is provided by the\napplication, or use the application-provided buffer if any.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n* Changes since v1\n- Update comments.\n- Use Request::findBuffer() instead of own logic.\n---\n src/libcamera/pipeline/ipu3/cio2.cpp | 52 ++++++++++++---------\n src/libcamera/pipeline/ipu3/cio2.h | 7 ++-\n src/libcamera/pipeline/ipu3/ipu3.cpp | 69 +++++++++-------------------\n 3 files changed, 55 insertions(+), 73 deletions(-)", "diff": "diff --git a/src/libcamera/pipeline/ipu3/cio2.cpp b/src/libcamera/pipeline/ipu3/cio2.cpp\nindex 9298f10d8d8c07f7..753f20fb615f6748 100644\n--- a/src/libcamera/pipeline/ipu3/cio2.cpp\n+++ b/src/libcamera/pipeline/ipu3/cio2.cpp\n@@ -235,31 +235,16 @@ int CIO2Device::exportBuffers(unsigned int count,\n \treturn output_->exportBuffers(count, buffers);\n }\n \n-FrameBuffer *CIO2Device::getBuffer()\n-{\n-\tif (availableBuffers_.empty()) {\n-\t\tLOG(IPU3, Error) << \"CIO2 buffer underrun\";\n-\t\treturn nullptr;\n-\t}\n-\n-\tFrameBuffer *buffer = availableBuffers_.front();\n-\n-\tavailableBuffers_.pop();\n-\n-\treturn buffer;\n-}\n-\n-void CIO2Device::putBuffer(FrameBuffer *buffer)\n-{\n-\tavailableBuffers_.push(buffer);\n-}\n-\n int CIO2Device::start()\n {\n-\tint ret = output_->allocateBuffers(CIO2_BUFFER_COUNT, &buffers_);\n+\tint ret = output_->exportBuffers(CIO2_BUFFER_COUNT, &buffers_);\n \tif (ret < 0)\n \t\treturn ret;\n \n+\tret = output_->importBuffers(CIO2_BUFFER_COUNT);\n+\tif (ret)\n+\t\tLOG(IPU3, Error) << \"Failed to import CIO2 buffers\";\n+\n \tfor (std::unique_ptr<FrameBuffer> &buffer : buffers_)\n \t\tavailableBuffers_.push(buffer.get());\n \n@@ -291,11 +276,36 @@ int CIO2Device::stop()\n \treturn ret;\n }\n \n-int CIO2Device::queueBuffer(FrameBuffer *buffer)\n+int CIO2Device::queueBuffer(Request *request, FrameBuffer *rawBuffer)\n {\n+\tFrameBuffer *buffer = rawBuffer;\n+\n+\t/* If no buffer is provided in the request, use an internal one. */\n+\tif (!buffer) {\n+\t\tif (availableBuffers_.empty()) {\n+\t\t\tLOG(IPU3, Error) << \"CIO2 buffer underrun\";\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tbuffer = availableBuffers_.front();\n+\t\tavailableBuffers_.pop();\n+\t}\n+\n+\tbuffer->setRequest(request);\n+\n \treturn output_->queueBuffer(buffer);\n }\n \n+void CIO2Device::tryReturnBuffer(FrameBuffer *buffer)\n+{\n+\tfor (const std::unique_ptr<FrameBuffer> &buf : buffers_) {\n+\t\tif (buf.get() == buffer) {\n+\t\t\tavailableBuffers_.push(buffer);\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+}\n+\n void CIO2Device::cio2BufferReady(FrameBuffer *buffer)\n {\n \tbufferReady.emit(buffer);\ndiff --git a/src/libcamera/pipeline/ipu3/cio2.h b/src/libcamera/pipeline/ipu3/cio2.h\nindex ffb401da6b576556..9bc01b8aa92446b0 100644\n--- a/src/libcamera/pipeline/ipu3/cio2.h\n+++ b/src/libcamera/pipeline/ipu3/cio2.h\n@@ -20,6 +20,7 @@ namespace libcamera {\n class CameraSensor;\n class FrameBuffer;\n class MediaDevice;\n+class Request;\n class V4L2DeviceFormat;\n class V4L2Subdevice;\n class V4L2VideoDevice;\n@@ -42,15 +43,13 @@ public:\n \tint exportBuffers(unsigned int count,\n \t\t\t std::vector<std::unique_ptr<FrameBuffer>> *buffers);\n \n-\tFrameBuffer *getBuffer();\n-\tvoid putBuffer(FrameBuffer *buffer);\n-\n \tint start();\n \tint stop();\n \n \tCameraSensor *sensor() { return sensor_; }\n \n-\tint queueBuffer(FrameBuffer *buffer);\n+\tint queueBuffer(Request *request, FrameBuffer *rawBuffer);\n+\tvoid tryReturnBuffer(FrameBuffer *buffer);\n \tSignal<FrameBuffer *> bufferReady;\n \n private:\ndiff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp\nindex c95c1bfbce914801..f183ec54daed6f57 100644\n--- a/src/libcamera/pipeline/ipu3/ipu3.cpp\n+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp\n@@ -121,7 +121,6 @@ public:\n \t}\n \n \tvoid imguOutputBufferReady(FrameBuffer *buffer);\n-\tvoid imguInputBufferReady(FrameBuffer *buffer);\n \tvoid cio2BufferReady(FrameBuffer *buffer);\n \n \tCIO2Device cio2_;\n@@ -725,25 +724,24 @@ void PipelineHandlerIPU3::stop(Camera *camera)\n int PipelineHandlerIPU3::queueRequestDevice(Camera *camera, Request *request)\n {\n \tIPU3CameraData *data = cameraData(camera);\n-\tFrameBuffer *buffer;\n \tint error = 0;\n \n-\t/* Get a CIO2 buffer, associate it with the request and queue it. */\n-\tbuffer = data->cio2_.getBuffer();\n-\tif (!buffer)\n-\t\treturn -EINVAL;\n-\n-\tbuffer->setRequest(request);\n-\tdata->cio2_.queueBuffer(buffer);\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+\t */\n+\tFrameBuffer *rawBuffer = request->findBuffer(&data->rawStream_);\n+\terror = data->cio2_.queueBuffer(request, rawBuffer);\n+\tif (error)\n+\t\treturn error;\n \n+\t/* Queue all buffers from the request aimed for the ImgU. */\n \tfor (auto it : request->buffers()) {\n \t\tIPU3Stream *stream = static_cast<IPU3Stream *>(it.first);\n-\t\tbuffer = it.second;\n-\n-\t\t/* Skip raw streams, they are copied from the CIO2 buffer. */\n \t\tif (stream->raw_)\n \t\t\tcontinue;\n \n+\t\tFrameBuffer *buffer = it.second;\n \t\tint ret = stream->device_->dev->queueBuffer(buffer);\n \t\tif (ret < 0)\n \t\t\terror = ret;\n@@ -873,8 +871,8 @@ int PipelineHandlerIPU3::registerCameras()\n \t\t */\n \t\tdata->cio2_.bufferReady.connect(data.get(),\n \t\t\t\t\t&IPU3CameraData::cio2BufferReady);\n-\t\tdata->imgu_->input_->bufferReady.connect(data.get(),\n-\t\t\t\t\t&IPU3CameraData::imguInputBufferReady);\n+\t\tdata->imgu_->input_->bufferReady.connect(&data->cio2_,\n+\t\t\t\t\t&CIO2Device::tryReturnBuffer);\n \t\tdata->imgu_->output_.dev->bufferReady.connect(data.get(),\n \t\t\t\t\t&IPU3CameraData::imguOutputBufferReady);\n \t\tdata->imgu_->viewfinder_.dev->bufferReady.connect(data.get(),\n@@ -903,22 +901,6 @@ int PipelineHandlerIPU3::registerCameras()\n * Buffer Ready slots\n */\n \n-/**\n- * \\brief Handle buffers completion at the ImgU input\n- * \\param[in] buffer The completed buffer\n- *\n- * Buffers completed from the ImgU input are immediately queued back to the\n- * CIO2 unit to continue frame capture.\n- */\n-void IPU3CameraData::imguInputBufferReady(FrameBuffer *buffer)\n-{\n-\t/* \\todo Handle buffer failures when state is set to BufferError. */\n-\tif (buffer->metadata().status == FrameMetadata::FrameCancelled)\n-\t\treturn;\n-\n-\tcio2_.putBuffer(buffer);\n-}\n-\n /**\n * \\brief Handle buffers completion at the ImgU output\n * \\param[in] buffer The completed buffer\n@@ -951,27 +933,18 @@ void IPU3CameraData::cio2BufferReady(FrameBuffer *buffer)\n \t\treturn;\n \n \tRequest *request = buffer->request();\n-\tFrameBuffer *raw = request->findBuffer(&rawStream_);\n \n-\tif (!raw) {\n-\t\t/* No RAW buffers present, just queue to IMGU. */\n-\t\timgu_->input_->queueBuffer(buffer);\n-\t\treturn;\n-\t}\n-\n-\t/* RAW buffers present, special care is needed. */\n-\tif (request->buffers().size() > 1)\n-\t\timgu_->input_->queueBuffer(buffer);\n-\n-\tif (raw->copyFrom(buffer))\n-\t\tLOG(IPU3, Debug) << \"Copy of FrameBuffer failed\";\n-\n-\tpipe_->completeBuffer(camera_, request, raw);\n-\n-\tif (request->buffers().size() == 1) {\n-\t\tcio2_.putBuffer(buffer);\n+\t/*\n+\t * If the request contains a buffer for the RAW stream only, complete it\n+\t * now as there's no need for ImgU processing.\n+\t */\n+\tif (request->findBuffer(&rawStream_) &&\n+\t pipe_->completeBuffer(camera_, request, buffer)) {\n \t\tpipe_->completeRequest(camera_, request);\n+\t\treturn;\n \t}\n+\n+\timgu_->input_->queueBuffer(buffer);\n }\n \n /* -----------------------------------------------------------------------------\n", "prefixes": [ "libcamera-devel", "v2", "10/10" ] }