{"id":11070,"url":"https://patchwork.libcamera.org/api/1.1/patches/11070/?format=json","web_url":"https://patchwork.libcamera.org/patch/11070/","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":"<20210130001915.489703-3-niklas.soderlund@ragnatech.se>","date":"2021-01-30T00:19:15","name":"[libcamera-devel,v3,2/2] cam: Only queue the exact number of requests asked for","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"5e46a5845ea4060d05edbf5fac66252d7dd53d4a","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/1.1/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/11070/mbox/","series":[{"id":1629,"url":"https://patchwork.libcamera.org/api/1.1/series/1629/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1629","date":"2021-01-30T00:19:13","name":"cam: Fix races in event loop and long request processing times","version":3,"mbox":"https://patchwork.libcamera.org/series/1629/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/11070/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/11070/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 80566BD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 30 Jan 2021 00:19:41 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 78167683CE;\n\tSat, 30 Jan 2021 01:19:39 +0100 (CET)","from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net\n\t[195.74.38.229])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D08AE6030A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 30 Jan 2021 01:19:38 +0100 (CET)","from bismarck.berto.se (p4fca2458.dip0.t-ipconnect.de\n\t[79.202.36.88])\n\tby bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA\n\tid d687d398-6290-11eb-b73f-0050569116f7;\n\tSat, 30 Jan 2021 01:19:38 +0100 (CET)"],"X-Halon-ID":"d687d398-6290-11eb-b73f-0050569116f7","Authorized-sender":"niklas.soderlund@fsdn.se","From":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","To":"libcamera-devel@lists.libcamera.org","Date":"Sat, 30 Jan 2021 01:19:15 +0100","Message-Id":"<20210130001915.489703-3-niklas.soderlund@ragnatech.se>","X-Mailer":"git-send-email 2.30.0","In-Reply-To":"<20210130001915.489703-1-niklas.soderlund@ragnatech.se>","References":"<20210130001915.489703-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v3 2/2] cam: Only queue the exact number\n\tof requests asked for","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>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"The cam option --capture=N is suppose to only capture N requests. But if\nthe processing done for each request is large (such as writing it to a\nslow disk) the current implementation could queue more then N requests\nbefore the exit condition is detected and capturing stopped.\n\nSolve this by only queueing N requests while still waiting for N\nrequests to complete before exiting.\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n src/cam/capture.cpp | 16 +++++++++++++---\n src/cam/capture.h   |  2 ++\n 2 files changed, 15 insertions(+), 3 deletions(-)","diff":"diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp\nindex 113ea49d50046e5b..e498b562826b8794 100644\n--- a/src/cam/capture.cpp\n+++ b/src/cam/capture.cpp\n@@ -18,7 +18,7 @@ using namespace libcamera;\n Capture::Capture(std::shared_ptr<Camera> camera, CameraConfiguration *config,\n \t\t EventLoop *loop)\n \t: camera_(camera), config_(config), writer_(nullptr), last_(0), loop_(loop),\n-\t  captureCount_(0), captureLimit_(0)\n+\t  queueCount_(0), captureCount_(0), captureLimit_(0)\n {\n }\n \n@@ -26,6 +26,7 @@ int Capture::run(const OptionsParser::Options &options)\n {\n \tint ret;\n \n+\tqueueCount_ = 0;\n \tcaptureCount_ = 0;\n \tcaptureLimit_ = options[OptCapture].toInteger();\n \n@@ -128,7 +129,7 @@ int Capture::capture(FrameBufferAllocator *allocator)\n \t}\n \n \tfor (std::unique_ptr<Request> &request : requests_) {\n-\t\tret = camera_->queueRequest(request.get());\n+\t\tret = queueRequest(request.get());\n \t\tif (ret < 0) {\n \t\t\tstd::cerr << \"Can't queue request\" << std::endl;\n \t\t\tcamera_->stop();\n@@ -152,6 +153,15 @@ int Capture::capture(FrameBufferAllocator *allocator)\n \treturn ret;\n }\n \n+int Capture::queueRequest(Request *request)\n+{\n+\tqueueCount_++;\n+\tif (captureLimit_ && queueCount_ > captureLimit_)\n+\t\treturn 0;\n+\n+\treturn camera_->queueRequest(request);\n+}\n+\n void Capture::requestComplete(Request *request)\n {\n \tif (request->status() == Request::RequestCancelled)\n@@ -213,5 +223,5 @@ void Capture::processRequest(Request *request)\n \t}\n \n \trequest->reuse(Request::ReuseBuffers);\n-\tcamera_->queueRequest(request);\n+\tqueueRequest(request);\n }\ndiff --git a/src/cam/capture.h b/src/cam/capture.h\nindex d21c95a26ce7d83a..c7c9dc00d30f06d6 100644\n--- a/src/cam/capture.h\n+++ b/src/cam/capture.h\n@@ -32,6 +32,7 @@ public:\n private:\n \tint capture(libcamera::FrameBufferAllocator *allocator);\n \n+\tint queueRequest(libcamera::Request *request);\n \tvoid requestComplete(libcamera::Request *request);\n \tvoid processRequest(libcamera::Request *request);\n \n@@ -43,6 +44,7 @@ private:\n \tuint64_t last_;\n \n \tEventLoop *loop_;\n+\tunsigned int queueCount_;\n \tunsigned int captureCount_;\n \tunsigned int captureLimit_;\n \n","prefixes":["libcamera-devel","v3","2/2"]}