{"id":12871,"url":"https://patchwork.libcamera.org/api/patches/12871/?format=json","web_url":"https://patchwork.libcamera.org/patch/12871/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/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":"<20210708213105.1485393-1-nfraprado@collabora.com>","date":"2021-07-08T21:31:05","name":"[libcamera-devel] libcamera: pipeline: rkisp1: Add internal request queue","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"9774f7ecd7fa346fcc0a26d471b9f09c36f6debb","submitter":{"id":84,"url":"https://patchwork.libcamera.org/api/people/84/?format=json","name":"Nícolas F. R. A. Prado","email":"nfraprado@collabora.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/12871/mbox/","series":[{"id":2219,"url":"https://patchwork.libcamera.org/api/series/2219/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2219","date":"2021-07-08T21:31:05","name":"[libcamera-devel] libcamera: pipeline: rkisp1: Add internal request queue","version":1,"mbox":"https://patchwork.libcamera.org/series/2219/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/12871/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/12871/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 A8B04C3224\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  8 Jul 2021 21:31:25 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 17ECE68513;\n\tThu,  8 Jul 2021 23:31:25 +0200 (CEST)","from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AB60168506\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  8 Jul 2021 23:31:23 +0200 (CEST)","from localhost.localdomain (unknown\n\t[IPv6:2804:14c:1a9:2434:6553:ad0c:9d2a:24db])\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 111B91F44064;\n\tThu,  8 Jul 2021 22:31:21 +0100 (BST)"],"From":"=?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= <nfraprado@collabora.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Thu,  8 Jul 2021 18:31:05 -0300","Message-Id":"<20210708213105.1485393-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: rkisp1: Add internal\n\trequest 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 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\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. And also to the patch I sent for the uvcvideo pipeline [1].\n\nI tested this with a new lc-compliance test from the series in [2]. The test\nfails without this patch, and passes with it applied.\n\n[1] https://lists.libcamera.org/pipermail/libcamera-devel/2021-July/022029.html\n[2] https://lists.libcamera.org/pipermail/libcamera-devel/2021-July/022098.html\n\n src/libcamera/pipeline/rkisp1/rkisp1.cpp | 72 +++++++++++++++++++-----\n 1 file changed, 58 insertions(+), 14 deletions(-)","diff":"diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex 00df4f0b3e6b..84abb4c2a462 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -87,6 +87,8 @@ public:\n \t}\n \n \tint loadIPA(unsigned int hwRevision);\n+\tvoid queuePendingRequests();\n+\tvoid cancelPendingRequests();\n \n \tStream mainPathStream_;\n \tStream selfPathStream_;\n@@ -101,6 +103,8 @@ public:\n \n \tstd::unique_ptr<ipa::rkisp1::IPAProxyRkISP1> ipa_;\n \n+\tstd::queue<Request *> pendingRequests_;\n+\n private:\n \tvoid queueFrameAction(unsigned int frame,\n \t\t\t      const ipa::rkisp1::RkISP1Action &action);\n@@ -198,13 +202,13 @@ RkISP1FrameInfo *RkISP1Frames::create(const RkISP1CameraData *data, Request *req\n \tunsigned int frame = data->frame_;\n \n \tif (pipe_->availableParamBuffers_.empty()) {\n-\t\tLOG(RkISP1, Error) << \"Parameters buffer underrun\";\n+\t\tLOG(RkISP1, Debug) << \"Parameters buffer underrun\";\n \t\treturn nullptr;\n \t}\n \tFrameBuffer *paramBuffer = pipe_->availableParamBuffers_.front();\n \n \tif (pipe_->availableStatBuffers_.empty()) {\n-\t\tLOG(RkISP1, Error) << \"Statisitc buffer underrun\";\n+\t\tLOG(RkISP1, Debug) << \"Statistic buffer underrun\";\n \t\treturn nullptr;\n \t}\n \tFrameBuffer *statBuffer = pipe_->availableStatBuffers_.front();\n@@ -831,6 +835,8 @@ void PipelineHandlerRkISP1::stop(Camera *camera)\n \n \tisp_->setFrameStartEnabled(false);\n \n+\tdata->cancelPendingRequests();\n+\n \tdata->ipa_->stop();\n \n \tselfPath_.stop();\n@@ -854,22 +860,58 @@ void PipelineHandlerRkISP1::stop(Camera *camera)\n \tactiveCamera_ = nullptr;\n }\n \n-int PipelineHandlerRkISP1::queueRequestDevice(Camera *camera, Request *request)\n+void RkISP1CameraData::cancelPendingRequests()\n {\n-\tRkISP1CameraData *data = cameraData(camera);\n+\twhile (!pendingRequests_.empty()) {\n+\t\tRequest *request = pendingRequests_.front();\n \n-\tRkISP1FrameInfo *info = data->frameInfo_.create(data, request);\n-\tif (!info)\n-\t\treturn -ENOENT;\n+\t\tfor (auto it : request->buffers()) {\n+\t\t\tFrameBuffer *buffer = it.second;\n+\t\t\tbuffer->cancel();\n+\t\t\tpipe_->completeBuffer(request, buffer);\n+\t\t}\n \n-\tipa::rkisp1::RkISP1Event ev;\n-\tev.op = ipa::rkisp1::EventQueueRequest;\n-\tev.frame = data->frame_;\n-\tev.bufferId = info->paramBuffer->cookie();\n-\tev.controls = request->controls();\n-\tdata->ipa_->processEvent(ev);\n+\t\tpipe_->completeRequest(request);\n+\n+\t\tpendingRequests_.pop();\n+\t}\n+}\n+\n+void RkISP1CameraData::queuePendingRequests()\n+{\n+\twhile (!pendingRequests_.empty()) {\n+\t\tRequest *request = pendingRequests_.front();\n+\n+\t\t/*\n+\t\t * If there aren't internal buffers available, we break and try\n+\t\t * again later. If there are, we're guaranteed to also have V4L2\n+\t\t * buffer slots available to queue the request, since we should\n+\t\t * always have more (or equal) buffer slots than internal\n+\t\t * buffers.\n+\t\t */\n+\t\tRkISP1FrameInfo *info = frameInfo_.create(this, request);\n+\t\tif (!info)\n+\t\t\tbreak;\n+\n+\t\tipa::rkisp1::RkISP1Event ev;\n+\t\tev.op = ipa::rkisp1::EventQueueRequest;\n+\t\tev.frame = frame_;\n+\t\tev.bufferId = info->paramBuffer->cookie();\n+\t\tev.controls = request->controls();\n+\t\tipa_->processEvent(ev);\n \n-\tdata->frame_++;\n+\t\tframe_++;\n+\n+\t\tpendingRequests_.pop();\n+\t}\n+}\n+\n+int PipelineHandlerRkISP1::queueRequestDevice(Camera *camera, Request *request)\n+{\n+\tRkISP1CameraData *data = cameraData(camera);\n+\n+\tdata->pendingRequests_.push(request);\n+\tdata->queuePendingRequests();\n \n \treturn 0;\n }\n@@ -1065,6 +1107,8 @@ void PipelineHandlerRkISP1::tryCompleteRequest(Request *request)\n \tdata->frameInfo_.destroy(info->frame);\n \n \tcompleteRequest(request);\n+\n+\tdata->queuePendingRequests();\n }\n \n void PipelineHandlerRkISP1::bufferReady(FrameBuffer *buffer)\n","prefixes":["libcamera-devel"]}