{"id":15144,"url":"https://patchwork.libcamera.org/api/1.1/patches/15144/?format=json","web_url":"https://patchwork.libcamera.org/patch/15144/","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":"<20211211165714.23067-10-jacopo@jmondi.org>","date":"2021-12-11T16:57:12","name":"[libcamera-devel,v6,09/11] libcamera: pipeline_handler: Prepare Request","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"2b723685e46d446f1eba9bb6b3cc592021984094","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/1.1/people/3/?format=json","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/15144/mbox/","series":[{"id":2838,"url":"https://patchwork.libcamera.org/api/1.1/series/2838/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2838","date":"2021-12-11T16:57:03","name":"libcamera: Add Fence support","version":6,"mbox":"https://patchwork.libcamera.org/series/2838/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/15144/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/15144/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 D21A7BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 11 Dec 2021 16:56:38 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 736DB608A5;\n\tSat, 11 Dec 2021 17:56:38 +0100 (CET)","from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net\n\t[217.70.183.200])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id F001A608A4\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 11 Dec 2021 17:56:31 +0100 (CET)","(Authenticated sender: jacopo@jmondi.org)\n\tby relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 530D720004;\n\tSat, 11 Dec 2021 16:56:31 +0000 (UTC)"],"From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Sat, 11 Dec 2021 17:57:12 +0100","Message-Id":"<20211211165714.23067-10-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.33.1","In-Reply-To":"<20211211165714.23067-1-jacopo@jmondi.org>","References":"<20211211165714.23067-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v6 09/11] libcamera: pipeline_handler:\n\tPrepare 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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Before queueing a request to the device, any synchronization fence from\nthe Request framebuffers has to be waited on.\n\nConnect the Request::Private::prepared signal to the function that\nqueues requests to the hardware and call Request::Private::prepare().\n\nWhen the waiting request queue is inspected, verify if it has completed its\npreparation phase and queue it to the device.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/libcamera/pipeline_handler.cpp | 37 +++++++++++++++++++++++-------\n 1 file changed, 29 insertions(+), 8 deletions(-)","diff":"diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp\nindex 92b5e3ab07d8..0bc0e341b9e7 100644\n--- a/src/libcamera/pipeline_handler.cpp\n+++ b/src/libcamera/pipeline_handler.cpp\n@@ -7,6 +7,7 @@\n \n #include \"libcamera/internal/pipeline_handler.h\"\n \n+#include <chrono>\n #include <sys/sysmacros.h>\n \n #include <libcamera/base/log.h>\n@@ -18,6 +19,7 @@\n \n #include \"libcamera/internal/camera.h\"\n #include \"libcamera/internal/device_enumerator.h\"\n+#include \"libcamera/internal/framebuffer.h\"\n #include \"libcamera/internal/media_device.h\"\n #include \"libcamera/internal/request.h\"\n #include \"libcamera/internal/tracepoints.h\"\n@@ -36,6 +38,8 @@\n  * the REGISTER_PIPELINE_HANDLER() macro.\n  */\n \n+using namespace std::chrono_literals;\n+\n namespace libcamera {\n \n LOG_DEFINE_CATEGORY(Pipeline)\n@@ -323,10 +327,16 @@ bool PipelineHandler::hasPendingRequests(const Camera *camera) const\n  * \\param[in] request The request to queue\n  *\n  * This function queues a capture request to the pipeline handler for\n- * processing. The request is first added to the internal list of queued\n- * requests, and then passed to the pipeline handler with a call to\n- * queueRequestDevice(). If the pipeline handler fails in queuing the request\n- * to the hardware the request is cancelled.\n+ * processing. The request is first added to the internal list of waiting\n+ * requests which have to be prepared to make sure they are ready for being\n+ * queued to the pipeline handler.\n+ *\n+ * The queue of waiting requests is iterated and all prepared requests are\n+ * passed to the pipeline handler in the same order they have been queued by\n+ * calling this function.\n+ *\n+ * If a Request fails during the preparation phase or if the pipeline handler\n+ * fails in queuing the request to the hardware the request is cancelled.\n  *\n  * Keeping track of queued requests ensures automatic completion of all requests\n  * when the pipeline handler is stopped with stop(). Request completion shall be\n@@ -339,7 +349,11 @@ void PipelineHandler::queueRequest(Request *request)\n \tLIBCAMERA_TRACEPOINT(request_queue, request);\n \n \twaitingRequests_.push(request);\n-\tdoQueueRequests();\n+\n+\trequest->_d()->prepared.connect(this, [this]() {\n+\t\t\t\t\t\tdoQueueRequests();\n+\t\t\t\t\t});\n+\trequest->_d()->prepare(300ms);\n }\n \n /**\n@@ -355,6 +369,11 @@ void PipelineHandler::doQueueRequest(Request *request)\n \n \trequest->_d()->sequence_ = data->requestSequence_++;\n \n+\tif (request->_d()->cancelled_) {\n+\t\tcompleteRequest(request);\n+\t\treturn;\n+\t}\n+\n \tint ret = queueRequestDevice(camera, request);\n \tif (ret) {\n \t\trequest->_d()->cancel();\n@@ -363,18 +382,20 @@ void PipelineHandler::doQueueRequest(Request *request)\n }\n \n /**\n- * \\brief Queue requests to the device\n+ * \\brief Queue prepared requests to the device\n  *\n  * Iterate the list of waiting requests and queue them to the device one\n- * by one.\n+ * by one if they have been prepared.\n  */\n void PipelineHandler::doQueueRequests()\n {\n \twhile (!waitingRequests_.empty()) {\n \t\tRequest *request = waitingRequests_.front();\n-\t\twaitingRequests_.pop();\n+\t\tif (!request->_d()->prepared_)\n+\t\t\tbreak;\n \n \t\tdoQueueRequest(request);\n+\t\twaitingRequests_.pop();\n \t}\n }\n \n","prefixes":["libcamera-devel","v6","09/11"]}