Show a patch.

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

{
    "id": 23010,
    "url": "https://patchwork.libcamera.org/api/patches/23010/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/23010/",
    "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": "<20210831223705.1928000-5-nfraprado@collabora.com>",
    "date": "2021-08-31T22:37:04",
    "name": "[libcamera-devel,v2,4/5] libcamera: pipeline: simple: Add internal request queue",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "98a350dfa9b121e583724b29eae6c84c1d689a91",
    "submitter": {
        "id": 84,
        "url": "https://patchwork.libcamera.org/api/people/84/?format=api",
        "name": "Nícolas F. R. A. Prado",
        "email": "nfraprado@collabora.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/23010/mbox/",
    "series": [
        {
            "id": 2431,
            "url": "https://patchwork.libcamera.org/api/series/2431/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2431",
            "date": "2021-08-31T22:37:00",
            "name": "libcamera: pipeline: Add internal request queue",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/2431/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/23010/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/23010/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<kieran.bingham@ideasonboard.com>",
        "X-Original-To": "parsemail@patchwork.libcamera.org",
        "Delivered-To": [
            "parsemail@patchwork.libcamera.org",
            "kbingham@ideasonboard.com"
        ],
        "Received": [
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id B7D95C0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 24 Mar 2025 17:12:47 +0000 (UTC)",
            "from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net\n\t[86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 40F6CA8F\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 24 Mar 2025 18:11:01 +0100 (CET)",
            "from perceval.ideasonboard.com\n\tby perceval.ideasonboard.com with LMTP id 2NvwBTuvLmFucAAA4E0KoQ\n\t(envelope-from <libcamera-devel-bounces@lists.libcamera.org>)\n\tfor <kbingham@ideasonboard.com>; Wed, 01 Sep 2021 00:37:47 +0200",
            "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\tby perceval.ideasonboard.com (Postfix) with ESMTPS\n\tid 07BAC8F;\tWed,  1 Sep 2021 00:37:47 +0200 (CEST)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9BB6069183;\n\tWed,  1 Sep 2021 00:37:46 +0200 (CEST)",
            "from bhuna.collabora.co.uk (bhuna.collabora.co.uk\n\t[IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 81E6B69166\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  1 Sep 2021 00:37:38 +0200 (CEST)",
            "from localhost.localdomain (unknown\n\t[IPv6:2804:14c:1a9:2434:b693:c9:5cb6:b688])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128\n\tbits))\n\t(No client certificate requested) (Authenticated sender: nfraprado)\n\tby bhuna.collabora.co.uk (Postfix) with ESMTPSA id 8E51C1F4396E;\n\tTue, 31 Aug 2021 23:37:36 +0100 (BST)"
        ],
        "From": "=?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= <nfraprado@collabora.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue, 31 Aug 2021 19:37:04 -0300",
        "Message-Id": "<20210831223705.1928000-5-nfraprado@collabora.com>",
        "X-Mailer": "git-send-email 2.33.0",
        "In-Reply-To": "<20210831223705.1928000-1-nfraprado@collabora.com>",
        "References": "<20210831223705.1928000-1-nfraprado@collabora.com>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=\"utf-8\"",
        "Content-Transfer-Encoding": "quoted-printable",
        "Subject": "[libcamera-devel] [PATCH v2 4/5] libcamera: pipeline: simple: Add\n\tinternal request queue",
        "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>",
        "Cc": "kernel@collabora.com, =?utf-8?q?Andr=C3=A9_Almeida?=\n\t<andrealmeid@collabora.com>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>",
        "X-TUID": "mPWV82qDk+0V",
        "Resent-From": "Kieran Bingham <kieran.bingham@ideasonboard.com>",
        "Resent-To": "parsemail@patchwork.libcamera.org"
    },
    "content": "Add an internal queue that stores requests until there are internal\nbuffers and V4L2 buffer slots available. This avoids the need to cancel\nrequests when there is a shortage of said buffers.\n\nSigned-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>\n\n---\nI wasn't able to test this patch as I don't have any of the target\nhardware.\n\nChanges in v2:\n- New\n\n src/libcamera/pipeline/simple/simple.cpp | 101 ++++++++++++++++++-----\n 1 file changed, 81 insertions(+), 20 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp\nindex 6deba5d7dd61..e9abe5e291f4 100644\n--- a/src/libcamera/pipeline/simple/simple.cpp\n+++ b/src/libcamera/pipeline/simple/simple.cpp\n@@ -167,6 +167,9 @@ public:\n \tint setupFormats(V4L2SubdeviceFormat *format,\n \t\t\t V4L2Subdevice::Whence whence);\n \n+\tvoid queuePendingRequests();\n+\tvoid cancelPendingRequests();\n+\n \tunsigned int streamIndex(const Stream *stream) const\n \t{\n \t\treturn stream - &streams_.front();\n@@ -198,6 +201,10 @@ public:\n \tstd::queue<std::map<unsigned int, FrameBuffer *>> converterQueue_;\n \n \tconst SimplePipelineInfo *deviceInfo;\n+\n+\tstd::queue<Request *> pendingRequests_;\n+\n+\tunsigned int avaliableBufferSlotCount_;\n };\n \n class SimpleCameraConfiguration : public CameraConfiguration\n@@ -546,6 +553,66 @@ int SimpleCameraData::setupFormats(V4L2SubdeviceFormat *format,\n \treturn 0;\n }\n \n+void SimpleCameraData::queuePendingRequests()\n+{\n+\twhile (!pendingRequests_.empty() && avaliableBufferSlotCount_) {\n+\t\tRequest *request = pendingRequests_.front();\n+\n+\t\tif (useConverter_) {\n+\t\t\t/*\n+\t\t\t * If conversion is needed, push the buffer(s) to the\n+\t\t\t * converter queue, it will be handed to the converter\n+\t\t\t * in the capture completion handler.\n+\t\t\t */\n+\t\t\tstd::map<unsigned int, FrameBuffer *> buffers;\n+\n+\t\t\tfor (auto &[stream, buffer] : request->buffers())\n+\t\t\t\tbuffers.emplace(streamIndex(stream), buffer);\n+\n+\t\t\tconverterQueue_.push(std::move(buffers));\n+\t\t} else {\n+\t\t\t/*\n+\t\t\t * Since we're not using a converter we can assume\n+\t\t\t * there's a single stream.\n+\t\t\t */\n+\t\t\tFrameBuffer *buffer = request->buffers().at(0);\n+\n+\t\t\tint ret = video_->queueBuffer(buffer);\n+\t\t\tif (ret < 0) {\n+\t\t\t\tLOG(SimplePipeline, Error)\n+\t\t\t\t\t<< \"Failed to queue buffer with error \"\n+\t\t\t\t\t<< ret << \". Cancelling buffer.\";\n+\t\t\t\tbuffer->cancel();\n+\t\t\t\tpipe()->completeBuffer(request, buffer);\n+\t\t\t\tpipe()->completeRequest(request);\n+\t\t\t\tpendingRequests_.pop();\n+\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\t\t}\n+\n+\t\tavaliableBufferSlotCount_--;\n+\n+\t\tpendingRequests_.pop();\n+\t}\n+}\n+\n+void SimpleCameraData::cancelPendingRequests()\n+{\n+\twhile (!pendingRequests_.empty()) {\n+\t\tRequest *request = pendingRequests_.front();\n+\n+\t\tfor (auto const &it : request->buffers()) {\n+\t\t\tit.second->cancel();\n+\t\t\tpipe()->completeBuffer(request, it.second);\n+\t\t}\n+\n+\t\tpipe()->completeRequest(request);\n+\n+\t\tpendingRequests_.pop();\n+\t}\n+}\n+\n /* -----------------------------------------------------------------------------\n  * Camera Configuration\n  */\n@@ -852,6 +919,8 @@ int SimplePipelineHandler::start(Camera *camera, [[maybe_unused]] const ControlL\n \tif (ret < 0)\n \t\treturn ret;\n \n+\tdata->avaliableBufferSlotCount_ = kSimpleBufferSlotCount;\n+\n \tret = video->streamOn();\n \tif (ret < 0) {\n \t\tstop(camera);\n@@ -885,6 +954,7 @@ void SimplePipelineHandler::stop(Camera *camera)\n \t\tconverter_->stop();\n \n \tvideo->streamOff();\n+\tdata->cancelPendingRequests();\n \tvideo->releaseBuffers();\n \n \tdata->converterBuffers_.clear();\n@@ -894,27 +964,9 @@ void SimplePipelineHandler::stop(Camera *camera)\n int SimplePipelineHandler::queueRequestDevice(Camera *camera, Request *request)\n {\n \tSimpleCameraData *data = cameraData(camera);\n-\tint ret;\n-\n-\tstd::map<unsigned int, FrameBuffer *> buffers;\n-\n-\tfor (auto &[stream, buffer] : request->buffers()) {\n-\t\t/*\n-\t\t * If conversion is needed, push the buffer to the converter\n-\t\t * queue, it will be handed to the converter in the capture\n-\t\t * completion handler.\n-\t\t */\n-\t\tif (data->useConverter_) {\n-\t\t\tbuffers.emplace(data->streamIndex(stream), buffer);\n-\t\t} else {\n-\t\t\tret = data->video_->queueBuffer(buffer);\n-\t\t\tif (ret < 0)\n-\t\t\t\treturn ret;\n-\t\t}\n-\t}\n \n-\tif (data->useConverter_)\n-\t\tdata->converterQueue_.push(std::move(buffers));\n+\tdata->pendingRequests_.push(request);\n+\tdata->queuePendingRequests();\n \n \treturn 0;\n }\n@@ -1151,6 +1203,8 @@ void SimplePipelineHandler::bufferReady(FrameBuffer *buffer)\n \t\t\tRequest *request = buffer->request();\n \t\t\tcompleteBuffer(request, buffer);\n \t\t\tcompleteRequest(request);\n+\t\t\tdata->avaliableBufferSlotCount_++;\n+\t\t\tdata->queuePendingRequests();\n \t\t\treturn;\n \t\t}\n \n@@ -1221,6 +1275,9 @@ void SimplePipelineHandler::bufferReady(FrameBuffer *buffer)\n \t/* Otherwise simply complete the request. */\n \tcompleteBuffer(request, buffer);\n \tcompleteRequest(request);\n+\n+\tdata->avaliableBufferSlotCount_++;\n+\tdata->queuePendingRequests();\n }\n \n void SimplePipelineHandler::converterInputDone(FrameBuffer *buffer)\n@@ -1235,11 +1292,15 @@ void SimplePipelineHandler::converterInputDone(FrameBuffer *buffer)\n void SimplePipelineHandler::converterOutputDone(FrameBuffer *buffer)\n {\n \tASSERT(activeCamera_);\n+\tSimpleCameraData *data = cameraData(activeCamera_);\n \n \t/* Complete the buffer and the request. */\n \tRequest *request = buffer->request();\n \tif (completeBuffer(request, buffer))\n \t\tcompleteRequest(request);\n+\n+\tdata->avaliableBufferSlotCount_++;\n+\tdata->queuePendingRequests();\n }\n \n REGISTER_PIPELINE_HANDLER(SimplePipelineHandler)\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "4/5"
    ]
}