[{"id":34799,"web_url":"https://patchwork.libcamera.org/comment/34799/","msgid":"<175188634445.2340557.8045107898266709266@ping.linuxembedded.co.uk>","date":"2025-07-07T11:05:44","subject":"Re: [PATCH v2 1/5] libcamera: pipeline_handler: Move\n\twaitingRequests_ into camera class","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Stefan Klug (2025-07-07 08:53:35)\n> The waiting requests of one camera should not be able to influence\n> queuing to another camera. Currently a request that is in the\n> waitingQUeue and waiting for preparation blocks all requests of other\n\ns/waitingQUeue/waitingQueue/\n\n> cameras even if they are already prepared. To fix that replace the\n> single waitingRequests_ queue with one queue per camera.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> Reviewed-by: Umang Jain <uajain@igalia.com>\n> \n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n> \n> Changes in v2:\n> - Fixed capturing on lambda expression\n> - Added documentation for waitingRequests_\n> - Improved commit message\n> \n> Changes 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(-)\n> \n> diff --git a/include/libcamera/internal/camera.h b/include/libcamera/internal/camera.h\n> index 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>         const PipelineHandler *pipe() const { return pipe_.get(); }\n>  \n>         std::list<Request *> queuedRequests_;\n> +       std::queue<Request *> waitingRequests_;\n>         ControlInfoMap controlInfo_;\n>         ControlList properties_;\n>  \n> diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h\n> index 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>         virtual void disconnect();\n>  \n>         void doQueueRequest(Request *request);\n> -       void doQueueRequests();\n> +       void doQueueRequests(Camera *camera);\n>  \n>         std::vector<std::shared_ptr<MediaDevice>> mediaDevices_;\n>         std::vector<std::weak_ptr<Camera>> cameras_;\n>  \n> -       std::queue<Request *> waitingRequests_;\n> -\n>         const char *name_;\n>         unsigned int useCount_;\n>  \n> diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp\n> index 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\n> diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp\n> index 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>         /* Stop the pipeline handler and let the queued requests complete. */\n>         stopDevice(camera);\n>  \n> +       Camera::Private *data = camera->_d();\n> +\n>         /* Cancel and signal as complete all waiting requests. */\n> -       while (!waitingRequests_.empty()) {\n> -               Request *request = waitingRequests_.front();\n> -               waitingRequests_.pop();\n> +       while (!data->waitingRequests_.empty()) {\n> +               Request *request = data->waitingRequests_.front();\n> +               data->waitingRequests_.pop();\n>                 cancelRequest(request);\n>         }\n>  \n>         /* Make sure no requests are pending. */\n> -       Camera::Private *data = camera->_d();\n>         ASSERT(data->queuedRequests_.empty());\n>  \n>         data->requestSequence_ = 0;\n> @@ -414,7 +415,9 @@ void PipelineHandler::registerRequest(Request *request)\n>          * Connect the request prepared signal to notify the pipeline handler\n>          * when a request is ready to be processed.\n>          */\n> -       request->_d()->prepared.connect(this, &PipelineHandler::doQueueRequests);\n> +       request->_d()->prepared.connect(this, [this, request]() {\n> +               doQueueRequests(request->_d()->camera());\n> +       });\n>  }\n>  \n>  /**\n> @@ -444,7 +447,9 @@ void PipelineHandler::queueRequest(Request *request)\n>  {\n>         LIBCAMERA_TRACEPOINT(request_queue, request);\n>  \n> -       waitingRequests_.push(request);\n> +       Camera *camera = request->_d()->camera();\n> +       Camera::Private *data = camera->_d();\n> +       data->waitingRequests_.push(request);\n>  \n>         request->_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> -       while (!waitingRequests_.empty()) {\n> -               Request *request = waitingRequests_.front();\n> +       Camera::Private *data = camera->_d();\n> +       while (!data->waitingRequests_.empty()) {\n> +               Request *request = data->waitingRequests_.front();\n>                 if (!request->_d()->prepared_)\n>                         break;\n>  \n>                 doQueueRequest(request);\n> -               waitingRequests_.pop();\n> +               data->waitingRequests_.pop();\n>         }\n>  }\n>  \n> -- \n> 2.48.1\n>","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 06671C0DA4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  7 Jul 2025 11:05:52 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EE46668EA4;\n\tMon,  7 Jul 2025 13:05:50 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 40BEA68E92\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  7 Jul 2025 13:05:48 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id A4847524;\n\tMon,  7 Jul 2025 13:05:20 +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=\"Nz6EcjbZ\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1751886320;\n\tbh=9YHrR+TkJS9cpGt8PaocqZnR+K2mEssZcymhmIMN+5I=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=Nz6EcjbZLsCvgLzpCls5ejljM0CPT2KX7T7DZH3kDyvo6KhqxWRKrQGw5lUJw0o73\n\t7XSCoiWFBsOicgl3Y+N5ymS3mq0f6No1oMSaAK7cEXjZR+8jVV+dLb/f4Qg9tdVEKE\n\t4vJoNr41ki946kvPt4l6w9bw3EStBPsFJZqUm8q8=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250707075400.9079-2-stefan.klug@ideasonboard.com>","References":"<20250707075400.9079-1-stefan.klug@ideasonboard.com>\n\t<20250707075400.9079-2-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v2 1/5] libcamera: pipeline_handler: Move\n\twaitingRequests_ into camera class","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tUmang Jain <uajain@igalia.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 07 Jul 2025 12:05:44 +0100","Message-ID":"<175188634445.2340557.8045107898266709266@ping.linuxembedded.co.uk>","User-Agent":"alot/0.9.1","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>"}}]