{"id":23839,"url":"https://patchwork.libcamera.org/api/patches/23839/?format=json","web_url":"https://patchwork.libcamera.org/patch/23839/","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":"<20250717125931.2848300-2-stefan.klug@ideasonboard.com>","date":"2025-07-17T12:59:21","name":"[v3,1/5] libcamera: pipeline_handler: Move waitingRequests_ into camera class","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"40f06d5e154f2e42ef273a62cbd0895f893046ba","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/?format=json","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/23839/mbox/","series":[{"id":5294,"url":"https://patchwork.libcamera.org/api/series/5294/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5294","date":"2025-07-17T12:59:20","name":"rkisp1: Allow usage of more than 4 buffers","version":3,"mbox":"https://patchwork.libcamera.org/series/5294/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/23839/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/23839/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 5D9CCC3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 17 Jul 2025 12:59:42 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0970368F83;\n\tThu, 17 Jul 2025 14:59:42 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 29BD568F78\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 17 Jul 2025 14:59:39 +0200 (CEST)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:7b93:8acd:d82d:248d])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 0D1DE1FA4; \n\tThu, 17 Jul 2025 14:59:05 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"u2D+LuRk\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1752757145;\n\tbh=HVix85CEOalKqOQqPNte3u8ELZDK1U7M8WvxXbc1kKk=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=u2D+LuRk02B+4L7jlcTGs6/xxHqC/WdIP9OuRtwZTxZrlHc5if8rmLGQ6UMQiGQfL\n\tTJ/HYRdLY1xIN+tQApCSyBwuHAsGKjauxDlj+vVxLDQr5UwD7+YciV5yqoyVlfl5J3\n\tnBvlQzq5oE1HNQZMaS6Udqpefly/gclxn4GThOYs=","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tUmang Jain <uajain@igalia.com>, Kieran Bingham\n\t<kieran.bingham@ideasonboard.com>, =?utf-8?q?Sven_P=C3=BCschel?=\n\t<s.pueschel@pengutronix.de>","Subject":"[PATCH v3 1/5] libcamera: pipeline_handler: Move waitingRequests_\n\tinto camera class","Date":"Thu, 17 Jul 2025 14:59:21 +0200","Message-ID":"<20250717125931.2848300-2-stefan.klug@ideasonboard.com>","X-Mailer":"git-send-email 2.48.1","In-Reply-To":"<20250717125931.2848300-1-stefan.klug@ideasonboard.com>","References":"<20250717125931.2848300-1-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","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":"The waiting requests of one camera should not be able to influence\nqueuing to another camera. Currently a request that is in the\nwaitingQueue and waiting for preparation blocks all requests of other\ncameras even if they are already prepared. To fix that replace the\nsingle waitingRequests_ queue with one queue per camera.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\nReviewed-by: Umang Jain <uajain@igalia.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\nTested-By: Sven Püschel<s.pueschel@pengutronix.de>\n\n---\n\nChanges in v3:\n- Collected tag\n\nChanges in v2:\n- Fixed capturing on lambda expression\n- Added documentation for waitingRequests_\n- Improved commit message\n\nChanges in v1:\n- Added camera param to doQueueRequests() which allows to remove a loop\n---\n include/libcamera/internal/camera.h           |  2 ++\n include/libcamera/internal/pipeline_handler.h |  5 +---\n src/libcamera/camera.cpp                      |  9 +++++++\n src/libcamera/pipeline_handler.cpp            | 26 ++++++++++++-------\n 4 files changed, 28 insertions(+), 14 deletions(-)","diff":"diff --git a/include/libcamera/internal/camera.h b/include/libcamera/internal/camera.h\nindex 18f5c32a18e4..8a2e9ed5894d 100644\n--- a/include/libcamera/internal/camera.h\n+++ b/include/libcamera/internal/camera.h\n@@ -10,6 +10,7 @@\n #include <atomic>\n #include <list>\n #include <memory>\n+#include <queue>\n #include <set>\n #include <stdint.h>\n #include <string>\n@@ -36,6 +37,7 @@ public:\n \tconst PipelineHandler *pipe() const { return pipe_.get(); }\n \n \tstd::list<Request *> queuedRequests_;\n+\tstd::queue<Request *> waitingRequests_;\n \tControlInfoMap controlInfo_;\n \tControlList properties_;\n \ndiff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h\nindex 972a2fa65310..be017ad47219 100644\n--- a/include/libcamera/internal/pipeline_handler.h\n+++ b/include/libcamera/internal/pipeline_handler.h\n@@ -8,7 +8,6 @@\n #pragma once\n \n #include <memory>\n-#include <queue>\n #include <string>\n #include <sys/types.h>\n #include <vector>\n@@ -89,13 +88,11 @@ private:\n \tvirtual void disconnect();\n \n \tvoid doQueueRequest(Request *request);\n-\tvoid doQueueRequests();\n+\tvoid doQueueRequests(Camera *camera);\n \n \tstd::vector<std::shared_ptr<MediaDevice>> mediaDevices_;\n \tstd::vector<std::weak_ptr<Camera>> cameras_;\n \n-\tstd::queue<Request *> waitingRequests_;\n-\n \tconst char *name_;\n \tunsigned int useCount_;\n \ndiff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\nindex c180a5fdde93..2ae50eaeaa5a 100644\n--- a/src/libcamera/camera.cpp\n+++ b/src/libcamera/camera.cpp\n@@ -628,6 +628,15 @@ Camera::Private::~Private()\n  * PipelineHandler::completeRequest()\n  */\n \n+/**\n+ * \\var Camera::Private::waitingRequests_\n+ * \\brief The queue of waiting requests\n+ *\n+ * This queue tracks all requests that can not yet be queued to the device.\n+ * Either because they are not yet prepared or because the maximum number of\n+ * queued requests was reached.\n+ */\n+\n /**\n  * \\var Camera::Private::controlInfo_\n  * \\brief The set of controls supported by the camera\ndiff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp\nindex d84dff3c9f19..b50eda5e0f86 100644\n--- a/src/libcamera/pipeline_handler.cpp\n+++ b/src/libcamera/pipeline_handler.cpp\n@@ -363,15 +363,16 @@ void PipelineHandler::stop(Camera *camera)\n \t/* Stop the pipeline handler and let the queued requests complete. */\n \tstopDevice(camera);\n \n+\tCamera::Private *data = camera->_d();\n+\n \t/* Cancel and signal as complete all waiting requests. */\n-\twhile (!waitingRequests_.empty()) {\n-\t\tRequest *request = waitingRequests_.front();\n-\t\twaitingRequests_.pop();\n+\twhile (!data->waitingRequests_.empty()) {\n+\t\tRequest *request = data->waitingRequests_.front();\n+\t\tdata->waitingRequests_.pop();\n \t\tcancelRequest(request);\n \t}\n \n \t/* Make sure no requests are pending. */\n-\tCamera::Private *data = camera->_d();\n \tASSERT(data->queuedRequests_.empty());\n \n \tdata->requestSequence_ = 0;\n@@ -414,7 +415,9 @@ void PipelineHandler::registerRequest(Request *request)\n \t * Connect the request prepared signal to notify the pipeline handler\n \t * when a request is ready to be processed.\n \t */\n-\trequest->_d()->prepared.connect(this, &PipelineHandler::doQueueRequests);\n+\trequest->_d()->prepared.connect(this, [this, request]() {\n+\t\tdoQueueRequests(request->_d()->camera());\n+\t});\n }\n \n /**\n@@ -444,7 +447,9 @@ void PipelineHandler::queueRequest(Request *request)\n {\n \tLIBCAMERA_TRACEPOINT(request_queue, request);\n \n-\twaitingRequests_.push(request);\n+\tCamera *camera = request->_d()->camera();\n+\tCamera::Private *data = camera->_d();\n+\tdata->waitingRequests_.push(request);\n \n \trequest->_d()->prepare(300ms);\n }\n@@ -478,15 +483,16 @@ void PipelineHandler::doQueueRequest(Request *request)\n  * Iterate the list of waiting requests and queue them to the device one\n  * by one if they have been prepared.\n  */\n-void PipelineHandler::doQueueRequests()\n+void PipelineHandler::doQueueRequests(Camera *camera)\n {\n-\twhile (!waitingRequests_.empty()) {\n-\t\tRequest *request = waitingRequests_.front();\n+\tCamera::Private *data = camera->_d();\n+\twhile (!data->waitingRequests_.empty()) {\n+\t\tRequest *request = data->waitingRequests_.front();\n \t\tif (!request->_d()->prepared_)\n \t\t\tbreak;\n \n \t\tdoQueueRequest(request);\n-\t\twaitingRequests_.pop();\n+\t\tdata->waitingRequests_.pop();\n \t}\n }\n \n","prefixes":["v3","1/5"]}