{"id":14924,"url":"https://patchwork.libcamera.org/api/1.1/patches/14924/?format=json","web_url":"https://patchwork.libcamera.org/patch/14924/","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":"<20211130233634.34173-11-jacopo@jmondi.org>","date":"2021-11-30T23:36:33","name":"[libcamera-devel,v3,10/11] libcamera: pipeline_handler: Prepare Request","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"0c018b7eb15005f88b532cfe3c5e095f1cfd4f80","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/14924/mbox/","series":[{"id":2788,"url":"https://patchwork.libcamera.org/api/1.1/series/2788/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2788","date":"2021-11-30T23:36:23","name":"libcamera: Add support for Fence","version":3,"mbox":"https://patchwork.libcamera.org/series/2788/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/14924/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14924/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 B9338C324F\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 30 Nov 2021 23:35:59 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5CF3760725;\n\tWed,  1 Dec 2021 00:35:59 +0100 (CET)","from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net\n\t[217.70.183.201])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5F28860718\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  1 Dec 2021 00:35:58 +0100 (CET)","(Authenticated sender: jacopo@jmondi.org)\n\tby relay8-d.mail.gandi.net (Postfix) with ESMTPSA id A7E101BF206;\n\tTue, 30 Nov 2021 23:35:57 +0000 (UTC)"],"From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed,  1 Dec 2021 00:36:33 +0100","Message-Id":"<20211130233634.34173-11-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.33.1","In-Reply-To":"<20211130233634.34173-1-jacopo@jmondi.org>","References":"<20211130233634.34173-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v3 10/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 has completed its\npreparation phase and queue it to the device.\n\nSigned-off-by: Jacopo Mondi <jacopo@jmondi.org>\n---\n src/libcamera/pipeline_handler.cpp | 48 ++++++++++++++++++++++--------\n 1 file changed, 36 insertions(+), 12 deletions(-)","diff":"diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp\nindex 8f1f20e896b0..0a6a2e6ee983 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@@ -17,6 +18,7 @@\n #include <libcamera/framebuffer.h>\n \n #include \"libcamera/internal/camera.h\"\n+#include \"libcamera/internal/framebuffer.h\"\n #include \"libcamera/internal/device_enumerator.h\"\n #include \"libcamera/internal/media_device.h\"\n #include \"libcamera/internal/request.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,11 +349,20 @@ 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  * \\brief Queue one requests to the device\n+ *\n+ * If a Request has failed during the preparation phase it is cancelled.\n+ *\n+ * If queuing a Request to the pipeline handler fails, the Request is cancelled\n+ * as well.\n  */\n void PipelineHandler::doQueueRequest(Request *request)\n {\n@@ -355,6 +374,12 @@ void PipelineHandler::doQueueRequest(Request *request)\n \n \trequest->_d()->sequence_ = data->requestSequence_++;\n \n+\tif (request->_d()->cancelled_) {\n+\t\trequest->_d()->cancel();\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@@ -365,19 +390,18 @@ void PipelineHandler::doQueueRequest(Request *request)\n /**\n  * \\brief Queue requests to the device\n  *\n- * Iterate the lst of waiting requests and queue them to the hardware one\n- * by one.\n+ * Iterate the queue of waiting requests and queue them in order the hardware if\n+ * they have completed their preparation phase.\n  */\n void PipelineHandler::doQueueRequests()\n {\n-\twhile (true) {\n-\t\tif (waitingRequests_.empty())\n-\t\t\treturn;\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","v3","10/11"]}