From patchwork Mon Mar 29 02:26:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11756 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 5137CC32EA for ; Mon, 29 Mar 2021 02:26:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A2BB668783; Mon, 29 Mar 2021 04:26:17 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="DIRwffu2"; dkim-atps=neutral Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DBCCC6878A for ; Mon, 29 Mar 2021 04:26:15 +0200 (CEST) Received: by mail-pf1-x429.google.com with SMTP id q5so8892261pfh.10 for ; Sun, 28 Mar 2021 19:26:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=czhyYhwGY0WqEmRQMGMI68MXU+M6I3wju8GAZE5G6s0=; b=DIRwffu27DYOXUGhe11D3xAtCk3Shq9yHXS3BPaFmsEvm9TNHnFUekQqtg9IcoI3/j WLLBzajBxG1AG8UtElAYRmyYdG4q63hobuNqjX4GQZJ6AtCnTzCn31mlYInFa3TG6r61 0SzSxGgDT50hasp8719DSRWkqgBRDuV0NfYMg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=czhyYhwGY0WqEmRQMGMI68MXU+M6I3wju8GAZE5G6s0=; b=U82zYi1hsiCCmy1Rl1AmjdHGbeHKka1gnnBa1WQGpQouEnU/u7lpshZDK0Gkp5eNR/ Iy9udN2Ynr6Kx7s/rmwVUJugnlcemkwN2Dl83Gpny5xwjW5zcntyy7PB09a7PCH4yPSo 1KdrnAueemUWDcEumueem/o4X8Akeb6KBSzhqJAblWOBzMoBgG7s55RAcQb2dQCQjGQP rvaSLRoyZ01ZdQjvSlPr/6/OyqQ1ExXKb0FPPo2eaTrE66ZQW2tY8I43a++vf+kT7/Wp xl+MaQWXxhAMPlq8qb2Mr14iG/zye6xm9YbsZtdRrj/fKTfSQ3ZcUvc53zM6kfhyvtcY G2bg== X-Gm-Message-State: AOAM533cgWP8HKCa4yC0f+eH1QLeUmMtJ8YYqRPIi4LOE94Gr2owrO/Q E8V5N1+bnUHdlli7DIlA6hd6oM/9suODiA== X-Google-Smtp-Source: ABdhPJwKIAnJ6UUsCUgzkM+25rH9e3rxfToPSnNlvVadtwboosj2Crry4eFF7qog1OJpAEDUh+9X3Q== X-Received: by 2002:a62:76c5:0:b029:1f2:e6af:e2ab with SMTP id r188-20020a6276c50000b02901f2e6afe2abmr23853841pfc.10.1616984774131; Sun, 28 Mar 2021 19:26:14 -0700 (PDT) Received: from hiroh2.tok.corp.google.com ([2401:fa00:8f:2:1db7:ae60:9288:b906]) by smtp.gmail.com with ESMTPSA id a26sm10537879pff.149.2021.03.28.19.26.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Mar 2021 19:26:13 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Mar 2021 11:26:04 +0900 Message-Id: <20210329022604.110201-3-hiroh@chromium.org> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog In-Reply-To: <20210329022604.110201-1-hiroh@chromium.org> References: <20210329022604.110201-1-hiroh@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC PATCH 2/2] libcamera: PipelineHandler: Retry queuing a capture request 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" PipelineHandler::queueRequestDevice() fails due to a buffer shortage. We should retry queuing a capture request later in the case. Signed-off-by: Hirokazu Honda --- include/libcamera/internal/pipeline_handler.h | 2 + src/libcamera/pipeline_handler.cpp | 57 +++++++++++++++++-- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index 763da63e..e6f771a6 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -44,6 +44,7 @@ public: virtual ~CameraData() = default; PipelineHandler *pipe_; + std::queue waitedRequests_; std::deque queuedRequests_; ControlInfoMap controlInfo_; ControlList properties_; @@ -99,6 +100,7 @@ protected: CameraManager *manager_; private: + void tryQueueRequests(CameraData *data); void mediaDeviceDisconnected(MediaDevice *media); virtual void disconnect(); diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 4cb58084..18952a1b 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -70,6 +70,16 @@ LOG_DEFINE_CATEGORY(Pipeline) * and remains valid until the instance is destroyed. */ +/** + * \var CameraData::waitedRequests_ + * \brief The queue of not yet queued request + * + * The queue of not yet queued request is used to track requests that are not + * queued in order to retry queueing them when a pipeline is ready to accept. + * + * \sa PipelineHandler::queueRequest(), PipelineHandler::tryQueueRequests(). + */ + /** * \var CameraData::queuedRequests_ * \brief The queue of queued and not yet completed request @@ -378,12 +388,44 @@ void PipelineHandler::queueRequest(Request *request) Camera *camera = request->camera_; CameraData *data = cameraData(camera); - data->queuedRequests_.push_back(request); + data->waitedRequests_.push(request); + + tryQueueRequests(data); +} + +/** + * \fn PipelineHandler::tryQueueRequests() + * \brief Queue requests that are not yet queued. + * \param[in] data The camera data whose waited requests are tried to queue. + * + * This tries to queue as many requests as possible in order of the + * waitedRequests_ in data. If queuing fails due to a buffer shortage, this + * method stops and the next call of this method starts from the request that + * fails in the previous call. On any other failures, the request is marked as + * complete and proceed the successive requests. + * + * \context This function shall be called from the CameraManager thread. + */ +void PipelineHandler::tryQueueRequests(CameraData *data) +{ + while (!data->waitedRequests_.empty()) { + Request *request = data->waitedRequests_.front(); + Camera *camera = request->camera_; + ASSERT(data == cameraData(camera)); + + data->queuedRequests_.push_back(request); + int ret = queueRequestDevice(camera, request); + if (ret == -ENOBUFS || ret == -ENOMEM) { + data->queuedRequests_.pop_back(); + break; + } - int ret = queueRequestDevice(camera, request); - if (ret) { - request->result_ = ret; - completeRequest(request); + data->waitedRequests_.pop(); + if (ret) { + request->result_ = ret; + completeRequest(request); + break; + } } } @@ -440,6 +482,9 @@ bool PipelineHandler::completeBuffer(Request *request, FrameBuffer *buffer) * submission order, the pipeline handler may call it on any complete request * without any ordering constraint. * + * There might be requests that are waiting to be queued, this triggers + * tryQueueRequests(). + * * \context This function shall be called from the CameraManager thread. */ void PipelineHandler::completeRequest(Request *request) @@ -459,6 +504,8 @@ void PipelineHandler::completeRequest(Request *request) data->queuedRequests_.pop_front(); camera->requestComplete(req); } + + tryQueueRequests(data); } /**