From patchwork Fri Aug 23 16:22:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-Hao Yang X-Patchwork-Id: 21007 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 48466BDE17 for ; Fri, 23 Aug 2024 16:33:07 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0844D633CB; Fri, 23 Aug 2024 18:33:05 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="LOKxGCJ3"; dkim-atps=neutral Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3749F63393 for ; Fri, 23 Aug 2024 18:33:02 +0200 (CEST) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-37196229343so1336807f8f.0 for ; Fri, 23 Aug 2024 09:33:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724430781; x=1725035581; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5GrXuGgAZeoER1lybbUNwH3VosMCgpgbhpPWheMcniI=; b=LOKxGCJ32QQlxPtw2C2srCAlEud3gJY4nW9AIQX6B06WChLQqW/fpzJbINH4iIXqXV EnXtn57MJWX3lXDbnOBqGzT5rzXaq/eK4ic//UUPWfOAwB1Cwn2ZwMQWc8LTTAi5n1vp Qk59Syxg+h6Hb32vTGaVD6IVpKE/jHpEIIn4c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724430781; x=1725035581; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5GrXuGgAZeoER1lybbUNwH3VosMCgpgbhpPWheMcniI=; b=vhuaiFQK3ABAzqfGB150PvBikSaqwvyuftsCo+z8/fZQzE/sCSnGtnPCZY+Ya99GXn RfCAOCT29ahBTdWpRz5doN2MuCwTn0Xs2MRoAqP0TVG7dCWw4wsyirfBzO07vSvYYcFR vDirfUA5jwF+vCXqYrCOM0jpQ5YB+TDk+12QtsF1mrIpwv7UdAScBTkft0VCrnws4imx tO+SdgFYlStunxaN27b/NQ3pujX1we9si3v8a0UN1WN4Zul2IQPjCYm46bSW+Ikvf6wt aA6rjw+q/3b2y1YXS5Awutx0TG1inIHotd4jtzviTCegsqWKc6I2tZoei4Hhcsx5wLvE nbVQ== X-Gm-Message-State: AOJu0YzFJ6FVme6cWtzRNilrYxAQyFZkoz4kENHCZVx6ykIF3D031Qix xkT4svgSs+dE+gZesbfzFhm84VZA5K9+DytEsxNyZGHEMGHMhIGn5plDxd2dHYf21LDIB4+VF7j eow== X-Google-Smtp-Source: AGHT+IG8J40frUkLqGCvSw/Yo8haQyjFMvheA3KBsUsWNraBjGUbaP/5Zvap5a/PTVyuQAcUSurElg== X-Received: by 2002:adf:f3c8:0:b0:371:7e19:b9c8 with SMTP id ffacd0b85a97d-373118eec09mr1949298f8f.58.1724430781141; Fri, 23 Aug 2024 09:33:01 -0700 (PDT) Received: from chenghaoyang-germany.c.googlers.com.com (161.126.77.34.bc.googleusercontent.com. [34.77.126.161]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3730826196bsm4482151f8f.102.2024.08.23.09.33.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 09:33:00 -0700 (PDT) From: Harvey Yang X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Cc: Han-Lin Chen , Harvey Yang Subject: [PATCH v1 1/1] libcamera: Camera: Add RequestCompletionMode to configure the completion order Date: Fri, 23 Aug 2024 16:22:45 +0000 Message-ID: <20240823163251.2979324-2-chenghaoyang@google.com> X-Mailer: git-send-email 2.46.0.295.g3b9ea8a38a-goog In-Reply-To: <20240823163251.2979324-1-chenghaoyang@google.com> References: <20240823163251.2979324-1-chenghaoyang@google.com> MIME-Version: 1.0 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" From: Han-Lin Chen Add enum RequestCompletionMode to Camera with two values: InSubmissionOrder andImmediately. The purpose is to allow the application to configure the order of signaling requestCompleted. The InSubmissionOrder mode is the default mode, which signals according to the request submission order. The Immediately mode allows the pipeline handler to signal as soon as a request is completed. Applications need to reconstruct the order by themselves. In the real use cases, it allows a camera app to continue the preview stream flowing, while certain ISPs/algorithms are still processing a complex flow like a still capture request, instead of being blocked by the still capture request. Signed-off-by: Han-Lin Chen Co-developed-by: Harvey Yang --- Documentation/guides/pipeline-handler.rst | 3 +- include/libcamera/camera.h | 8 ++++ include/libcamera/internal/camera.h | 1 + src/libcamera/camera.cpp | 50 +++++++++++++++++++++-- src/libcamera/pipeline_handler.cpp | 7 ++++ 5 files changed, 65 insertions(+), 4 deletions(-) diff --git a/Documentation/guides/pipeline-handler.rst b/Documentation/guides/pipeline-handler.rst index 26aea4334..f8e64e2f0 100644 --- a/Documentation/guides/pipeline-handler.rst +++ b/Documentation/guides/pipeline-handler.rst @@ -1453,7 +1453,8 @@ completion of that buffer to the Camera by using the PipelineHandler base class have been completed, the pipeline handler must again notify the ``Camera`` using the PipelineHandler base class ``completeRequest`` function. The PipelineHandler class implementation makes sure the request completion notifications are -delivered to applications in the same order as they have been submitted. +delivered to applications in the same order as they have been submitted, unless +the Camera's ``RequestCompletionMode`` is set to ``Immediately``. .. _connecting: https://libcamera.org/api-html/classlibcamera_1_1Signal.html#aa04db72d5b3091ffbb4920565aeed382 diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index 94cee7bd8..5226d94ef 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -116,6 +116,11 @@ class Camera final : public Object, public std::enable_shared_from_this, LIBCAMERA_DECLARE_PRIVATE() public: + enum RequestCompletionMode { + InSubmissionOrder, + Immediately, + }; + static std::shared_ptr create(std::unique_ptr d, const std::string &id, const std::set &streams); @@ -129,6 +134,9 @@ public: int acquire(); int release(); + int setRequestCompletionMode(RequestCompletionMode mode); + RequestCompletionMode requestCompletionMode() const; + const ControlInfoMap &controls() const; const ControlList &properties() const; diff --git a/include/libcamera/internal/camera.h b/include/libcamera/internal/camera.h index 0add0428b..cb3bbf4f6 100644 --- a/include/libcamera/internal/camera.h +++ b/include/libcamera/internal/camera.h @@ -68,6 +68,7 @@ private: bool disconnected_; std::atomic state_; + RequestCompletionMode requestCompletionMode_; std::unique_ptr validator_; }; diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 382a68f7b..02decc87e 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -5,7 +5,7 @@ * Camera device */ -#include +#include "libcamera/internal/camera.h" #include #include @@ -14,12 +14,12 @@ #include #include +#include #include #include #include #include -#include "libcamera/internal/camera.h" #include "libcamera/internal/camera_controls.h" #include "libcamera/internal/formats.h" #include "libcamera/internal/pipeline_handler.h" @@ -584,7 +584,8 @@ CameraConfiguration::Status CameraConfiguration::validateColorSpaces(ColorSpaceF */ Camera::Private::Private(PipelineHandler *pipe) : requestSequence_(0), pipe_(pipe->shared_from_this()), - disconnected_(false), state_(CameraAvailable) + disconnected_(false), state_(CameraAvailable), + requestCompletionMode_(Camera::InSubmissionOrder) { } @@ -858,6 +859,15 @@ std::shared_ptr Camera::create(std::unique_ptr d, return std::shared_ptr(camera, Deleter()); } +/** + * \enum Camera::RequestCompletionMode + * \brief The mode of request completion behavior + * \var libcamera::Camera::InSubmissionOrder + * \brief requestCompleted will be emited according to the request submission order + * \var libcamera::Camera::Immediately + * \brief requestCompleted will be emited immediately when a request is completed + */ + /** * \brief Retrieve the ID of the camera * @@ -1405,6 +1415,40 @@ int Camera::stop() return 0; } +/** + * \brief Set the request completion mode + * \param[in] mode The RequestCompletionMode + * + * This function sets the request completion mode. + * InSubmissionOrder is the default mode. + * + * \return 0 on success or a negative error code otherwise + * \retval -EACCES The camera is running so can't change the behavior + */ +int Camera::setRequestCompletionMode(RequestCompletionMode mode) +{ + Private *const d = _d(); + + int ret = d->isAccessAllowed(Private::CameraAvailable, + Private::CameraConfigured); + if (ret < 0) + return -EACCES; + + d->requestCompletionMode_ = mode; + + return 0; +} + +/** + * \brief Get the request completion mode + * + * \return The current RequestCompletionMode + */ +Camera::RequestCompletionMode Camera::requestCompletionMode() const +{ + return _d()->requestCompletionMode_; +} + /** * \brief Handle request completion and notify application * \param[in] request The request that has completed diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index 5a6de685b..767e224e9 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -525,6 +525,13 @@ void PipelineHandler::completeRequest(Request *request) Camera::Private *data = camera->_d(); + if (camera->requestCompletionMode() == Camera::Immediately) { + camera->requestComplete(request); + data->queuedRequests_.remove(request); + return; + } + + /* camera->requestCompletionMode() == Camera::InSubmissionOrder */ while (!data->queuedRequests_.empty()) { Request *req = data->queuedRequests_.front(); if (req->status() == Request::RequestPending)