{"id":14970,"url":"https://patchwork.libcamera.org/api/1.1/patches/14970/?format=json","web_url":"https://patchwork.libcamera.org/patch/14970/","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":"<20211201142936.107405-11-jacopo@jmondi.org>","date":"2021-12-01T14:29:35","name":"[libcamera-devel,v4,10/11] libcamera: pipeline_handler: Prepare Request","commit_ref":null,"pull_url":null,"state":"superseded","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":{"id":15,"url":"https://patchwork.libcamera.org/api/1.1/users/15/?format=json","username":"jmondi","first_name":"Jacopo","last_name":"Mondi","email":"jacopo@jmondi.org"},"mbox":"https://patchwork.libcamera.org/patch/14970/mbox/","series":[{"id":2795,"url":"https://patchwork.libcamera.org/api/1.1/series/2795/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=2795","date":"2021-12-01T14:29:25","name":"libcamera: Add support for Fence","version":4,"mbox":"https://patchwork.libcamera.org/series/2795/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/14970/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/14970/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 5BD94BDB13\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed,  1 Dec 2021 14:29:01 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1E97660741;\n\tWed,  1 Dec 2021 15:29:01 +0100 (CET)","from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net\n\t[217.70.183.198])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DA6B360732\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed,  1 Dec 2021 15:28:59 +0100 (CET)","(Authenticated sender: jacopo@jmondi.org)\n\tby relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 9A1B9C0008;\n\tWed,  1 Dec 2021 14:28:58 +0000 (UTC)"],"From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed,  1 Dec 2021 15:29:35 +0100","Message-Id":"<20211201142936.107405-11-jacopo@jmondi.org>","X-Mailer":"git-send-email 2.33.1","In-Reply-To":"<20211201142936.107405-1-jacopo@jmondi.org>","References":"<20211201142936.107405-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH v4 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 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 863d206a7ddd..5b5cb9c18dad 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","v4","10/11"]}