{"id":11756,"url":"https://patchwork.libcamera.org/api/patches/11756/?format=json","web_url":"https://patchwork.libcamera.org/patch/11756/","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":"<20210329022604.110201-3-hiroh@chromium.org>","date":"2021-03-29T02:26:04","name":"[libcamera-devel,RFC,2/2] libcamera: PipelineHandler: Retry queuing a capture request","commit_ref":null,"pull_url":null,"state":"changes-requested","archived":false,"hash":"079c41b1cede6f94eb5b0943b4f8552de82768e4","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/people/63/?format=json","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/11756/mbox/","series":[{"id":1857,"url":"https://patchwork.libcamera.org/api/series/1857/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1857","date":"2021-03-29T02:26:02","name":"Enable handling a number of capture requests","version":1,"mbox":"https://patchwork.libcamera.org/series/1857/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/11756/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/11756/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 5137CC32EA\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 29 Mar 2021 02:26:18 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A2BB668783;\n\tMon, 29 Mar 2021 04:26:17 +0200 (CEST)","from mail-pf1-x429.google.com (mail-pf1-x429.google.com\n\t[IPv6:2607:f8b0:4864:20::429])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DBCCC6878A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 29 Mar 2021 04:26:15 +0200 (CEST)","by mail-pf1-x429.google.com with SMTP id q5so8892261pfh.10\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 28 Mar 2021 19:26:15 -0700 (PDT)","from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:2:1db7:ae60:9288:b906])\n\tby smtp.gmail.com with ESMTPSA id\n\ta26sm10537879pff.149.2021.03.28.19.26.13\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tSun, 28 Mar 2021 19:26:13 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"DIRwffu2\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=from:to:cc:subject:date:message-id:in-reply-to:references\n\t:mime-version:content-transfer-encoding;\n\tbh=czhyYhwGY0WqEmRQMGMI68MXU+M6I3wju8GAZE5G6s0=;\n\tb=DIRwffu27DYOXUGhe11D3xAtCk3Shq9yHXS3BPaFmsEvm9TNHnFUekQqtg9IcoI3/j\n\tWLLBzajBxG1AG8UtElAYRmyYdG4q63hobuNqjX4GQZJ6AtCnTzCn31mlYInFa3TG6r61\n\t0SzSxGgDT50hasp8719DSRWkqgBRDuV0NfYMg=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references:mime-version:content-transfer-encoding;\n\tbh=czhyYhwGY0WqEmRQMGMI68MXU+M6I3wju8GAZE5G6s0=;\n\tb=U82zYi1hsiCCmy1Rl1AmjdHGbeHKka1gnnBa1WQGpQouEnU/u7lpshZDK0Gkp5eNR/\n\tIy9udN2Ynr6Kx7s/rmwVUJugnlcemkwN2Dl83Gpny5xwjW5zcntyy7PB09a7PCH4yPSo\n\t1KdrnAueemUWDcEumueem/o4X8Akeb6KBSzhqJAblWOBzMoBgG7s55RAcQb2dQCQjGQP\n\trvaSLRoyZ01ZdQjvSlPr/6/OyqQ1ExXKb0FPPo2eaTrE66ZQW2tY8I43a++vf+kT7/Wp\n\txl+MaQWXxhAMPlq8qb2Mr14iG/zye6xm9YbsZtdRrj/fKTfSQ3ZcUvc53zM6kfhyvtcY\n\tG2bg==","X-Gm-Message-State":"AOAM533cgWP8HKCa4yC0f+eH1QLeUmMtJ8YYqRPIi4LOE94Gr2owrO/Q\n\tE8V5N1+bnUHdlli7DIlA6hd6oM/9suODiA==","X-Google-Smtp-Source":"ABdhPJwKIAnJ6UUsCUgzkM+25rH9e3rxfToPSnNlvVadtwboosj2Crry4eFF7qog1OJpAEDUh+9X3Q==","X-Received":"by 2002:a62:76c5:0:b029:1f2:e6af:e2ab with SMTP id\n\tr188-20020a6276c50000b02901f2e6afe2abmr23853841pfc.10.1616984774131; \n\tSun, 28 Mar 2021 19:26:14 -0700 (PDT)","From":"Hirokazu Honda <hiroh@chromium.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Mon, 29 Mar 2021 11:26:04 +0900","Message-Id":"<20210329022604.110201-3-hiroh@chromium.org>","X-Mailer":"git-send-email 2.31.0.291.g576ba9dcdaf-goog","In-Reply-To":"<20210329022604.110201-1-hiroh@chromium.org>","References":"<20210329022604.110201-1-hiroh@chromium.org>","MIME-Version":"1.0","Subject":"[libcamera-devel] [RFC PATCH 2/2] libcamera: PipelineHandler: Retry\n\tqueuing a capture request","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=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"PipelineHandler::queueRequestDevice() fails due to a buffer\nshortage. We should retry queuing a capture request later in the\ncase.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n include/libcamera/internal/pipeline_handler.h |  2 +\n src/libcamera/pipeline_handler.cpp            | 57 +++++++++++++++++--\n 2 files changed, 54 insertions(+), 5 deletions(-)","diff":"diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h\nindex 763da63e..e6f771a6 100644\n--- a/include/libcamera/internal/pipeline_handler.h\n+++ b/include/libcamera/internal/pipeline_handler.h\n@@ -44,6 +44,7 @@ public:\n \tvirtual ~CameraData() = default;\n \n \tPipelineHandler *pipe_;\n+\tstd::queue<Request *> waitedRequests_;\n \tstd::deque<Request *> queuedRequests_;\n \tControlInfoMap controlInfo_;\n \tControlList properties_;\n@@ -99,6 +100,7 @@ protected:\n \tCameraManager *manager_;\n \n private:\n+\tvoid tryQueueRequests(CameraData *data);\n \tvoid mediaDeviceDisconnected(MediaDevice *media);\n \tvirtual void disconnect();\n \ndiff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp\nindex 4cb58084..18952a1b 100644\n--- a/src/libcamera/pipeline_handler.cpp\n+++ b/src/libcamera/pipeline_handler.cpp\n@@ -70,6 +70,16 @@ LOG_DEFINE_CATEGORY(Pipeline)\n  * and remains valid until the instance is destroyed.\n  */\n \n+/**\n+ * \\var CameraData::waitedRequests_\n+ * \\brief The queue of not yet queued request\n+ *\n+ * The queue of not yet queued request is used to track requests that are not\n+ * queued in order to retry queueing them when a pipeline is ready to accept.\n+ *\n+ * \\sa PipelineHandler::queueRequest(), PipelineHandler::tryQueueRequests().\n+ */\n+\n /**\n  * \\var CameraData::queuedRequests_\n  * \\brief The queue of queued and not yet completed request\n@@ -378,12 +388,44 @@ void PipelineHandler::queueRequest(Request *request)\n \n \tCamera *camera = request->camera_;\n \tCameraData *data = cameraData(camera);\n-\tdata->queuedRequests_.push_back(request);\n+\tdata->waitedRequests_.push(request);\n+\n+\ttryQueueRequests(data);\n+}\n+\n+/**\n+ * \\fn PipelineHandler::tryQueueRequests()\n+ * \\brief Queue requests that are not yet queued.\n+ * \\param[in] data The camera data whose waited requests are tried to queue.\n+ *\n+ * This tries to queue as many requests as possible in order of the\n+ * waitedRequests_ in data. If queuing fails due to a buffer shortage, this\n+ * method stops and the next call of this method starts from the request that\n+ * fails in the previous call. On any other failures, the request is marked as\n+ * complete and proceed the successive requests.\n+ *\n+ * \\context This function shall be called from the CameraManager thread.\n+ */\n+void PipelineHandler::tryQueueRequests(CameraData *data)\n+{\n+\twhile (!data->waitedRequests_.empty()) {\n+\t\tRequest *request = data->waitedRequests_.front();\n+\t\tCamera *camera = request->camera_;\n+\t\tASSERT(data == cameraData(camera));\n+\n+\t\tdata->queuedRequests_.push_back(request);\n+\t\tint ret = queueRequestDevice(camera, request);\n+\t\tif (ret == -ENOBUFS || ret == -ENOMEM) {\n+\t\t\tdata->queuedRequests_.pop_back();\n+\t\t\tbreak;\n+\t\t}\n \n-\tint ret = queueRequestDevice(camera, request);\n-\tif (ret) {\n-\t\trequest->result_ = ret;\n-\t\tcompleteRequest(request);\n+\t\tdata->waitedRequests_.pop();\n+\t\tif (ret) {\n+\t\t\trequest->result_ = ret;\n+\t\t\tcompleteRequest(request);\n+\t\t\tbreak;\n+\t\t}\n \t}\n }\n \n@@ -440,6 +482,9 @@ bool PipelineHandler::completeBuffer(Request *request, FrameBuffer *buffer)\n  * submission order, the pipeline handler may call it on any complete request\n  * without any ordering constraint.\n  *\n+ * There might be requests that are waiting to be queued, this triggers\n+ * tryQueueRequests().\n+ *\n  * \\context This function shall be called from the CameraManager thread.\n  */\n void PipelineHandler::completeRequest(Request *request)\n@@ -459,6 +504,8 @@ void PipelineHandler::completeRequest(Request *request)\n \t\tdata->queuedRequests_.pop_front();\n \t\tcamera->requestComplete(req);\n \t}\n+\n+\ttryQueueRequests(data);\n }\n \n /**\n","prefixes":["libcamera-devel","RFC","2/2"]}