Show a patch.

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

{
    "id": 13046,
    "url": "https://patchwork.libcamera.org/api/patches/13046/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/13046/",
    "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": "<20210719191438.189046-3-nfraprado@collabora.com>",
    "date": "2021-07-19T19:14:37",
    "name": "[libcamera-devel,2/3] libcamera: pipeline: uvcvideo: Add internal request queue",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "b4d1b08b5576936584c3faedd0b626b8915dfd8e",
    "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/13046/mbox/",
    "series": [
        {
            "id": 2256,
            "url": "https://patchwork.libcamera.org/api/series/2256/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=2256",
            "date": "2021-07-19T19:14:35",
            "name": "libcamera: pipeline: Add internal request queue",
            "version": 1,
            "mbox": "https://patchwork.libcamera.org/series/2256/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/13046/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/13046/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 857D4C322B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 19 Jul 2021 19:15:01 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4315D6853F;\n\tMon, 19 Jul 2021 21:15:01 +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 5AB6868538\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 19 Jul 2021 21:14:59 +0200 (CEST)",
            "from localhost.localdomain (unknown\n\t[IPv6:2804:14c:1a9:2434:2e2f:cb19:fca8:1dff])\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 993381F42E0E;\n\tMon, 19 Jul 2021 20:14:57 +0100 (BST)"
        ],
        "From": "=?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= <nfraprado@collabora.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Mon, 19 Jul 2021 16:14:37 -0300",
        "Message-Id": "<20210719191438.189046-3-nfraprado@collabora.com>",
        "X-Mailer": "git-send-email 2.32.0",
        "In-Reply-To": "<20210719191438.189046-1-nfraprado@collabora.com>",
        "References": "<20210719191438.189046-1-nfraprado@collabora.com>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=UTF-8",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH 2/3] libcamera: pipeline: uvcvideo: 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>"
    },
    "content": "Add an internal queue that stores requests until there are V4L2 buffer\nslots available. This avoids the need to cancel requests when there is a\nshortage of said buffers.\n\nSigned-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>\n---\n src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 66 +++++++++++++++++---\n 1 file changed, 56 insertions(+), 10 deletions(-)",
    "diff": "diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\nindex 32482300f09a..a5b593473cb3 100644\n--- a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n+++ b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\n@@ -10,6 +10,7 @@\n #include <iomanip>\n #include <math.h>\n #include <memory>\n+#include <queue>\n #include <tuple>\n \n #include <libcamera/base/log.h>\n@@ -45,8 +46,13 @@ public:\n \t\t\tControlInfoMap::Map *ctrls);\n \tvoid bufferReady(FrameBuffer *buffer);\n \n+\tvoid queuePendingRequests();\n+\tvoid cancelPendingRequests();\n+\n \tstd::unique_ptr<V4L2VideoDevice> video_;\n \tStream stream_;\n+\n+\tstd::queue<Request *> pendingRequests_;\n };\n \n class UVCCameraConfiguration : public CameraConfiguration\n@@ -79,12 +85,13 @@ public:\n \n \tbool match(DeviceEnumerator *enumerator) override;\n \n+\tint processControls(UVCCameraData *data, Request *request);\n+\n private:\n \tstd::string generateId(const UVCCameraData *data);\n \n \tint processControl(ControlList *controls, unsigned int id,\n \t\t\t   const ControlValue &value);\n-\tint processControls(UVCCameraData *data, Request *request);\n \n \tUVCCameraData *cameraData(const Camera *camera)\n \t{\n@@ -252,6 +259,7 @@ int PipelineHandlerUVC::start(Camera *camera, [[maybe_unused]] const ControlList\n void PipelineHandlerUVC::stop(Camera *camera)\n {\n \tUVCCameraData *data = cameraData(camera);\n+\tdata->cancelPendingRequests();\n \tdata->video_->streamOff();\n \tdata->video_->releaseBuffers();\n }\n@@ -365,21 +373,16 @@ int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request)\n int PipelineHandlerUVC::queueRequestDevice(Camera *camera, Request *request)\n {\n \tUVCCameraData *data = cameraData(camera);\n-\tFrameBuffer *buffer = request->findBuffer(&data->stream_);\n-\tif (!buffer) {\n+\n+\tif (!request->findBuffer(&data->stream_)) {\n \t\tLOG(UVC, Error)\n \t\t\t<< \"Attempt to queue request with invalid stream\";\n \n \t\treturn -ENOENT;\n \t}\n \n-\tint ret = processControls(data, request);\n-\tif (ret < 0)\n-\t\treturn ret;\n-\n-\tret = data->video_->queueBuffer(buffer);\n-\tif (ret < 0)\n-\t\treturn ret;\n+\tdata->pendingRequests_.push(request);\n+\tdata->queuePendingRequests();\n \n \treturn 0;\n }\n@@ -669,6 +672,49 @@ void UVCCameraData::bufferReady(FrameBuffer *buffer)\n \n \tpipe_->completeBuffer(request, buffer);\n \tpipe_->completeRequest(request);\n+\n+\tqueuePendingRequests();\n+}\n+\n+void UVCCameraData::queuePendingRequests()\n+{\n+\tPipelineHandlerUVC *pipe = static_cast<PipelineHandlerUVC *>(pipe_);\n+\n+\twhile (!pendingRequests_.empty()) {\n+\t\tRequest *request = pendingRequests_.front();\n+\t\tFrameBuffer *buffer = request->findBuffer(&stream_);\n+\n+\t\tint ret = pipe->processControls(this, request);\n+\t\tif (ret < 0) {\n+\t\t\tbuffer->cancel();\n+\t\t\tpipe_->completeBuffer(request, buffer);\n+\t\t\tpipe_->completeRequest(request);\n+\t\t\tpendingRequests_.pop();\n+\n+\t\t\tcontinue;\n+\t\t}\n+\n+\t\t/* If we're missing V4L2 buffer slots, try again later */\n+\t\tret = video_->queueBuffer(buffer);\n+\t\tif (ret < 0)\n+\t\t\tbreak;\n+\n+\t\tpendingRequests_.pop();\n+\t}\n+}\n+\n+void UVCCameraData::cancelPendingRequests()\n+{\n+\twhile (!pendingRequests_.empty()) {\n+\t\tRequest *request = pendingRequests_.front();\n+\t\tFrameBuffer *buffer = request->findBuffer(&stream_);\n+\n+\t\tbuffer->cancel();\n+\t\tpipe_->completeBuffer(request, buffer);\n+\t\tpipe_->completeRequest(request);\n+\n+\t\tpendingRequests_.pop();\n+\t}\n }\n \n REGISTER_PIPELINE_HANDLER(PipelineHandlerUVC)\n",
    "prefixes": [
        "libcamera-devel",
        "2/3"
    ]
}