From patchwork Mon Mar 29 02:26:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hirokazu Honda X-Patchwork-Id: 11755 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 8D4E8C32EA for ; Mon, 29 Mar 2021 02:26:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F35776878B; Mon, 29 Mar 2021 04:26:15 +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="Z8y8BpUk"; dkim-atps=neutral Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CE000602D7 for ; Mon, 29 Mar 2021 04:26:14 +0200 (CEST) Received: by mail-pj1-x1030.google.com with SMTP id ot17-20020a17090b3b51b0290109c9ac3c34so6980010pjb.4 for ; Sun, 28 Mar 2021 19:26:14 -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=OnvULsl0p2IJPoR9+i18brD7WO6K1ll5UjoYcmuDwXs=; b=Z8y8BpUkKzIv+sqz8CN6uZ9uraAljWdiwmmjE0VEHlLtN82R+ioNSgTBjdWzfMuuyj gBVjWgtIO+POAiSewL6nk3d49BrHdYpH5mcnV5C4/dFLN6jj+HZ/xz1iUg8f6naJayW2 NolMROJw1EOcfhD5q97bqya61/uRwqX9MOr5E= 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=OnvULsl0p2IJPoR9+i18brD7WO6K1ll5UjoYcmuDwXs=; b=UqJsP4gUp+vBJyrrrr6sZjd6Soi81nYIKB7ce+iySiphsNtxwoN3Hd8qkoYz6SAIIv NvAvzIRsQ2/8A/GryYpjzdMEWwwZlsY1BZLSp0BC39CZlEH6zrwDMQEGXsOG8I84ByzT rY5fv+wq6WqTDPSV1EUN0EzuQICsfKE6ioBPyWoZsuUrmPXt4v9S/JgemrVBxxAxO4fv fRIcSnj2nwVENhOdIbLCATQ5tL6HBbEth3ODedZqMQhtACdPE8BXk/FvEIIlmpirXuDW wncykhq6jhUuUnRiX/lEZmFzcFJJ3OWYvE+I9jfxb1kNygR3ETyS2VklnKxx+n92Gi/x 7nsQ== X-Gm-Message-State: AOAM533bWFvZboqM5GzO99g1Sy8lR3IH+T/EGr7mshkC7Wd/cNinM6bN 7ZASKbtjp7PpCGGvHsMK8kHzBN7sE+kvhw== X-Google-Smtp-Source: ABdhPJw6Db1qTNYKRDc6Ef9xYYphXR9zHDk9cpZw3C2mdv2FGrMXN1I06k5v+Msyq3ISqbN3ftt6LA== X-Received: by 2002:a17:90a:be09:: with SMTP id a9mr24098028pjs.219.1616984772724; Sun, 28 Mar 2021 19:26:12 -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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Mar 2021 19:26:12 -0700 (PDT) From: Hirokazu Honda To: libcamera-devel@lists.libcamera.org Date: Mon, 29 Mar 2021 11:26:03 +0900 Message-Id: <20210329022604.110201-2-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 1/2] libcamera: CameraData: Change queuedRequests_ type to std::dequeue 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" The type of CameraData::queuedRequests_ is std::list. The more appropriate type is std::dequeue as the requests is reported as complete in the order of queuing and are needed to be removed in the first and last ones. Signed-off-by: Hirokazu Honda Reviewed-by: Sebastian Fricke --- include/libcamera/internal/pipeline_handler.h | 4 ++-- src/libcamera/pipeline_handler.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index 093b94c6..763da63e 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -7,9 +7,9 @@ #ifndef __LIBCAMERA_INTERNAL_PIPELINE_HANDLER_H__ #define __LIBCAMERA_INTERNAL_PIPELINE_HANDLER_H__ -#include #include #include +#include #include #include #include @@ -44,7 +44,7 @@ public: virtual ~CameraData() = default; PipelineHandler *pipe_; - std::list queuedRequests_; + std::deque queuedRequests_; ControlInfoMap controlInfo_; ControlList properties_; diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 0228d7b2..4cb58084 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -72,9 +72,9 @@ LOG_DEFINE_CATEGORY(Pipeline) /** * \var CameraData::queuedRequests_ - * \brief The list of queued and not yet completed request + * \brief The queue of queued and not yet completed request * - * The list of queued request is used to track requests queued in order to + * The queue of queued request is used to track requests queued in order to * ensure completion of all requests when the pipeline handler is stopped. * * \sa PipelineHandler::queueRequest(), PipelineHandler::stop(), 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); } /**