{"id":12760,"url":"https://patchwork.libcamera.org/api/1.1/patches/12760/?format=json","web_url":"https://patchwork.libcamera.org/patch/12760/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20210701192951.662584-1-nfraprado@collabora.com>","date":"2021-07-01T19:29:51","name":"[libcamera-devel] libcamera: pipeline: uvcvideo: Add internal request queue","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"bebbcce86a607478f20032d5496813853c9ff08f","submitter":{"id":84,"url":"https://patchwork.libcamera.org/api/1.1/people/84/?format=json","name":"Nícolas F. R. A. Prado","email":"nfraprado@collabora.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/12760/mbox/","series":[{"id":2197,"url":"https://patchwork.libcamera.org/api/1.1/series/2197/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2197","date":"2021-07-01T19:29:51","name":"[libcamera-devel] libcamera: pipeline: uvcvideo: Add internal request queue","version":1,"mbox":"https://patchwork.libcamera.org/series/2197/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/12760/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/12760/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 68DF2C3222\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  1 Jul 2021 19:30:11 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7ABFA684E7;\n\tThu,  1 Jul 2021 21:30:10 +0200 (CEST)","from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 86E8E60289\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  1 Jul 2021 21:30:08 +0200 (CEST)","from localhost.localdomain (unknown\n\t[IPv6:2804:14c:1a9:2434:bd70:78a1:919c:f01a])\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 F387C1F445A3;\n\tThu,  1 Jul 2021 20:30:06 +0100 (BST)"],"From":"=?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= <nfraprado@collabora.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu,  1 Jul 2021 16:29:51 -0300","Message-Id":"<20210701192951.662584-1-nfraprado@collabora.com>","X-Mailer":"git-send-email 2.32.0","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH] 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\nThis is very similar to what 5a9d19210fad (\"libcamera: pipeline: ipu3: Try\nqueuing pending requests if a buffer is available\") and 89dae5844964\n(\"libcamera: pipeline: ipu3: Store requests in the case a buffer shortage\") did\nfor IPU3.\n\nI tested this with a new lc-compliance test from [1] which is a rebased version\nof the series in [2]. I'll resend this series after the googletest refactor\nseries [3] is merged. But this patch for uvcvideo doesn't depend on that.\n\n[1] https://gitlab.collabora.com/nfraprado/libcamera/-/tree/lcc-lots-requests-v5\n[2] https://lists.libcamera.org/pipermail/libcamera-devel/2021-May/020150.html\n[3] https://lists.libcamera.org/pipermail/libcamera-devel/2021-June/021891.html\n\n src/libcamera/pipeline/uvcvideo/uvcvideo.cpp | 64 +++++++++++++++++---\n 1 file changed, 54 insertions(+), 10 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp b/src/libcamera/pipeline/uvcvideo/uvcvideo.cpp\nindex 0f634b8da609..a51131dce8e0 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,6 +46,11 @@ public:\n \t\t\tControlInfoMap::Map *ctrls);\n \tvoid bufferReady(FrameBuffer *buffer);\n \n+\tvoid queuePendingRequests();\n+\tvoid cancelPendingRequests();\n+\n+\tstd::queue<Request *> pendingRequests_;\n+\n \tstd::unique_ptr<V4L2VideoDevice> video_;\n \tStream stream_;\n };\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@@ -363,24 +370,59 @@ int PipelineHandlerUVC::processControls(UVCCameraData *data, Request *request)\n \treturn ret;\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+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+\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 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@@ -668,6 +710,8 @@ void UVCCameraData::bufferReady(FrameBuffer *buffer)\n \n \tpipe_->completeBuffer(request, buffer);\n \tpipe_->completeRequest(request);\n+\n+\tqueuePendingRequests();\n }\n \n REGISTER_PIPELINE_HANDLER(PipelineHandlerUVC)\n","prefixes":["libcamera-devel"]}