Patch Detail
Show a patch.
GET /api/1.1/patches/23009/?format=api
{ "id": 23009, "url": "https://patchwork.libcamera.org/api/1.1/patches/23009/?format=api", "web_url": "https://patchwork.libcamera.org/patch/23009/", "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": "<20210831223705.1928000-3-nfraprado@collabora.com>", "date": "2021-08-31T22:37:02", "name": "[libcamera-devel,v2,2/5] libcamera: pipeline: uvcvideo: Add internal request queue", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "cc83279df6aea5ae40c347fc029f9aedd3483a74", "submitter": { "id": 84, "url": "https://patchwork.libcamera.org/api/1.1/people/84/?format=api", "name": "Nícolas F. R. A. Prado", "email": "nfraprado@collabora.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/23009/mbox/", "series": [ { "id": 2431, "url": "https://patchwork.libcamera.org/api/1.1/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/23009/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/23009/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 CAAEEC0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 24 Mar 2025 17:12:39 +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 522C8455\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 24 Mar 2025 18:10:53 +0100 (CET)", "from perceval.ideasonboard.com\n\tby perceval.ideasonboard.com with LMTP id yBcMHjqvLmFtcAAA4E0KoQ\n\t(envelope-from <libcamera-devel-bounces@lists.libcamera.org>)\n\tfor <kbingham@ideasonboard.com>; Wed, 01 Sep 2021 00:37:46 +0200", "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\tby perceval.ideasonboard.com (Postfix) with ESMTPS\n\tid 6D8DC8F;\tWed, 1 Sep 2021 00:37:46 +0200 (CEST)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1302F6917E;\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 BAB6760258\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 1 Sep 2021 00:37:33 +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 D32D61F43866;\n\tTue, 31 Aug 2021 23:37:31 +0100 (BST)" ], "From": "=?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= <nfraprado@collabora.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Tue, 31 Aug 2021 19:37:02 -0300", "Message-Id": "<20210831223705.1928000-3-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 2/5] 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>", "X-TUID": "4UL7mSPzsoKm", "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 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---\n\nChanges in v2:\n- Added a counter to keep track of the number of available buffer slots\n- Moved cancellation of pending requests to after video devices stop\n- Added error log on failure to process controls\n\n src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 98 ++++++++++++++++----\n 1 file changed, 81 insertions(+), 17 deletions(-)", "diff": "diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\nindex 5977312a795d..5e73a8e682dd 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@@ -46,8 +47,22 @@ public:\n \t\t\tControlInfoMap::Map *ctrls);\n \tvoid bufferReady(FrameBuffer *buffer);\n \n+\tvoid queuePendingRequests();\n+\tvoid cancelPendingRequests();\n+\n+\tvoid setAvailableBufferSlotCount(unsigned int count) { availableBufferSlotCount_ = count; }\n+\n \tstd::unique_ptr<V4L2VideoDevice> video_;\n \tStream stream_;\n+\n+\tstd::queue<Request *> pendingRequests_;\n+\n+private:\n+\tint processControls(Request *request);\n+\tint processControl(ControlList *controls, unsigned int id,\n+\t\t\t const ControlValue &value);\n+\n+\tunsigned int availableBufferSlotCount_;\n };\n \n class UVCCameraConfiguration : public CameraConfiguration\n@@ -83,10 +98,6 @@ public:\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(Camera *camera)\n \t{\n \t\treturn static_cast<UVCCameraData *>(camera->_d());\n@@ -240,6 +251,8 @@ int PipelineHandlerUVC::start(Camera *camera, [[maybe_unused]] const ControlList\n \tif (ret < 0)\n \t\treturn ret;\n \n+\tdata->setAvailableBufferSlotCount(kUVCBufferSlotCount);\n+\n \tret = data->video_->streamOn();\n \tif (ret < 0) {\n \t\tdata->video_->releaseBuffers();\n@@ -253,10 +266,11 @@ void PipelineHandlerUVC::stop(Camera *camera)\n {\n \tUVCCameraData *data = cameraData(camera);\n \tdata->video_->streamOff();\n+\tdata->cancelPendingRequests();\n \tdata->video_->releaseBuffers();\n }\n \n-int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id,\n+int UVCCameraData::processControl(ControlList *controls, unsigned int id,\n \t\t\t\t const ControlValue &value)\n {\n \tuint32_t cid;\n@@ -337,9 +351,9 @@ int PipelineHandlerUVC::processControl(ControlList *controls, unsigned int id,\n \treturn 0;\n }\n \n-int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request)\n+int UVCCameraData::processControls(Request *request)\n {\n-\tControlList controls(data->video_->controls());\n+\tControlList controls(video_->controls());\n \n \tfor (auto it : request->controls()) {\n \t\tunsigned int id = it.first;\n@@ -353,7 +367,7 @@ int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request)\n \t\t\t<< \"Setting control \" << utils::hex(ctrl.first)\n \t\t\t<< \" to \" << ctrl.second.toString();\n \n-\tint ret = data->video_->setControls(&controls);\n+\tint ret = video_->setControls(&controls);\n \tif (ret) {\n \t\tLOG(UVC, Error) << \"Failed to set controls: \" << ret;\n \t\treturn ret < 0 ? ret : -EINVAL;\n@@ -365,21 +379,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@@ -670,6 +679,61 @@ void UVCCameraData::bufferReady(FrameBuffer *buffer)\n \n \tpipe()->completeBuffer(request, buffer);\n \tpipe()->completeRequest(request);\n+\n+\tavailableBufferSlotCount_++;\n+\n+\tqueuePendingRequests();\n+}\n+\n+void UVCCameraData::queuePendingRequests()\n+{\n+\twhile (!pendingRequests_.empty() && availableBufferSlotCount_) {\n+\t\tRequest *request = pendingRequests_.front();\n+\t\tFrameBuffer *buffer = request->findBuffer(&stream_);\n+\n+\t\tint ret = processControls(request);\n+\t\tif (ret < 0) {\n+\t\t\tLOG(UVC, Error) << \"Failed to process controls with\"\n+\t\t\t\t\t<< \" error \" << ret << \". Cancelling\"\n+\t\t\t\t\t<< \" buffer.\";\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\tret = video_->queueBuffer(buffer);\n+\t\tif (ret < 0) {\n+\t\t\tLOG(UVC, Error) << \"Failed to queue buffer with error \"\n+\t\t\t\t\t<< ret << \". Cancelling buffer.\";\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\tavailableBufferSlotCount_--;\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", "v2", "2/5" ] }