From patchwork Thu Oct 28 11:15:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 14402 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id DFE89BF415 for ; Thu, 28 Oct 2021 11:14:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 78FF260159; Thu, 28 Oct 2021 13:14:49 +0200 (CEST) Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 49F39600BA for ; Thu, 28 Oct 2021 13:14:41 +0200 (CEST) Received: (Authenticated sender: jacopo@jmondi.org) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id D74E7FF804; Thu, 28 Oct 2021 11:14:40 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Thu, 28 Oct 2021 13:15:17 +0200 Message-Id: <20211028111520.256612-8-jacopo@jmondi.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211028111520.256612-1-jacopo@jmondi.org> References: <20211028111520.256612-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 07/10] libcamera: pipeline_handler: Split request queueing X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" In order to prepare to handle synchronization fences at Request queueing time, split the PipelineHandler::queueRequest() function in two, by creating a list of waiting requests and introducing a new doQueueDevice() function that queues Requests to the device in the order the pipeline has received them. Signed-off-by: Jacopo Mondi --- include/libcamera/internal/pipeline_handler.h | 7 ++++ src/libcamera/pipeline_handler.cpp | 35 +++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index 41cba44d990f..afb7990ea21b 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -7,7 +7,9 @@ #ifndef __LIBCAMERA_INTERNAL_PIPELINE_HANDLER_H__ #define __LIBCAMERA_INTERNAL_PIPELINE_HANDLER_H__ +#include #include +#include #include #include #include @@ -76,9 +78,14 @@ private: void mediaDeviceDisconnected(MediaDevice *media); virtual void disconnect(); + void doQueueRequest(); + std::vector> mediaDevices_; std::vector> cameras_; + std::mutex waitingRequestsMutex_; + std::list waitingRequests_; + const char *name_; friend class PipelineHandlerFactory; diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index cada864687ff..38edd00cebad 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -312,17 +313,45 @@ void PipelineHandler::queueRequest(Request *request) { LIBCAMERA_TRACEPOINT(request_queue, request); + { + MutexLocker lock(waitingRequestsMutex_); + waitingRequests_.push_back(request); + } + + doQueueRequest(); +} + +/** + * \brief Queue a request to the device + */ +void PipelineHandler::doQueueRequest() +{ + Request *request = nullptr; + { + MutexLocker lock(waitingRequestsMutex_); + + if (!waitingRequests_.size()) + return; + + request = waitingRequests_.front(); + waitingRequests_.pop_front(); + } + + /* Queue Request to the pipeline handler. */ Camera *camera = request->_d()->camera(); - Camera::Private *data = camera->_d(); - data->queuedRequests_.push_back(request); + Camera::Private *camData = camera->_d(); - request->sequence_ = data->requestSequence_++; + request->sequence_ = camData->requestSequence_++; + camData->queuedRequests_.push_back(request); int ret = queueRequestDevice(camera, request); if (ret) { request->cancel(); completeRequest(request); } + + /* Try to queue the next Request in the queue, if ready. */ + doQueueRequest(); } /**