From patchwork Tue Jul 26 18:24:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 16802 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 DE37EBE173 for ; Tue, 26 Jul 2022 18:25:30 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A7A1563315; Tue, 26 Jul 2022 20:25:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1658859930; bh=ltpFuCAuihvbOmL8Fyz176w5YjlXklIGUIsQYWVnMoM=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=LCuH9XH5VrCbNoSAotXoqMajbAsX1wCaLVjhvHR9PNh+HOuo7agItAIk/HBZtamdn ty/lXoXG02Pwf/oc3/h6505Nc3qwAQ/G2bmI/9ffqVwyHOoUrLvBeYFX/8RJD+RlGR xOdIuxAfEiaz3pDqmt0TJthzxSE0/8K1mLIpJnEboxW0j1I8J9sFa7JfG93HR2OBGT QzD4m3P1HFUcSf15lgDfQd+j4BlHWE4w8j8Jw5d6RWJobfLlVvb/X0n/0WND/CPlsl duXP1sTMDe0KM7lIbx8zwR3HNJEk/WQvXTmXaiaxKKOIIoGwqRHxxqIWPBIeH8neP0 LtSP/tjDZVfwQ== Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C819360487 for ; Tue, 26 Jul 2022 20:25:28 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="jwUXHmJ2"; dkim-atps=neutral Received: by mail-pl1-x62b.google.com with SMTP id x1so12319610plb.3 for ; Tue, 26 Jul 2022 11:25:28 -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=uIpXw/38Bee1gJ74s8fAiVV6faeIlVK6IkLgUHBeyLs=; b=jwUXHmJ2UgLxCtpqOwO2/WU3Q1UZDl3KLugBHcXPf8L1ssySEkpZf5Lg5GcOonEgIF N9e4SJZEYhBdjLP51Dnb5pYw1XiWXBX4WaKtjmEbOt/s/RXCIOag58Gm79/kgBgcaQCj vZ+UDLe+NtkzjRYWmi2biB1wL9MlbvuaUCNho= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uIpXw/38Bee1gJ74s8fAiVV6faeIlVK6IkLgUHBeyLs=; b=nH41PQ9o3rjV2LDZszWh9fnV2Xx8ha+wi6R1oAyFZfrjq63Cqf865WRJr2f/NYnVBR GxOdliSZmyXQScP1CLrDBaskG8gGDz4HySOkDLY2WO1UE0EgXmhm2qpkxNZ5remeHeZE TvTrkZb1J6z2rYhS2qjY7KweibIF+lYs/3I8R1Dt7xp3MDaHOFD/0PqsBPcYdE/A9Pk3 ATJmLYLPrq8pqzEiB+2DLGYY7ltY/EBwrzErhlSVfawjD7B6KAoF1vpjypZEhdgoILwR 7LAaOCXA7ZDCkVCu//xUaNquZkD7SLgIkmqINWLzaI8n6bW70cywTouLDWx/+Bj5k/UO pC9g== X-Gm-Message-State: AJIora/plJKZxpOKztTHUvWf9Z/mFo05E4ONJzquAtYbpf+MZJU8d3ye 4p+QupQ1JLZlTYt16YIp5vVSAHt6y3dlMw== X-Google-Smtp-Source: AGRyM1tuukfknGyAQ7pxixW71f0OyFJdX2DWXPSOk2eWB28Gr3Z+31ESTv4EFRqfqZVMR6AuX6XO0g== X-Received: by 2002:a17:902:eb8f:b0:16d:4215:5f23 with SMTP id q15-20020a170902eb8f00b0016d42155f23mr18258091plg.70.1658859927170; Tue, 26 Jul 2022 11:25:27 -0700 (PDT) Received: from localhost ([2401:fa00:1:17:739:6574:4032:5911]) by smtp.gmail.com with UTF8SMTPSA id y14-20020a17090a644e00b001f217ec21efsm13470920pjm.13.2022.07.26.11.25.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 26 Jul 2022 11:25:26 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Wed, 27 Jul 2022 02:24:55 +0800 Message-Id: <20220726182500.425182-2-hanlinchen@chromium.org> X-Mailer: git-send-email 2.37.1.359.gd136c6c3e2-goog In-Reply-To: <20220726182500.425182-1-hanlinchen@chromium.org> References: <20220726182500.425182-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/6] libcamera: Camera: Add RequestCompletionMode to configure the completion order 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: , X-Patchwork-Original-From: Han-Lin Chen via libcamera-devel From: Hanlin Chen Reply-To: Han-Lin Chen Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add enum RequestCompletionMode to Camera with two value: InSubmissionOrder and Immediately. The purpose is to allow the application 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 self. Signed-off-by: Han-Lin Chen --- include/libcamera/camera.h | 8 ++++ include/libcamera/internal/camera.h | 4 ++ src/libcamera/camera.cpp | 68 ++++++++++++++++++++++++++++- src/libcamera/pipeline_handler.cpp | 20 ++++++--- 4 files changed, 92 insertions(+), 8 deletions(-) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index 5bb06584..5aa4bf69 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -88,6 +88,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); @@ -101,6 +106,9 @@ public: int acquire(); int release(); + int setRequestCompletionMode(RequestCompletionMode order); + 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 597426a6..68e8d952 100644 --- a/include/libcamera/internal/camera.h +++ b/include/libcamera/internal/camera.h @@ -33,6 +33,9 @@ public: PipelineHandler *pipe() { return pipe_.get(); } + void setRequestCompletionMode(RequestCompletionMode mode); + RequestCompletionMode requestCompletionMode() const; + std::list queuedRequests_; ControlInfoMap controlInfo_; ControlList properties_; @@ -67,6 +70,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 2a8ef60e..4d3523e2 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -435,7 +435,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) { } @@ -573,6 +574,28 @@ void Camera::Private::setState(State state) state_.store(state, std::memory_order_release); } +/** + * \brief Set the request completion mode + * \param[in] mode The RequestCompletionMode + * + * This function set the request completion mode. + * InSubmissionOrder is the default mode. + */ +void Camera::Private::setRequestCompletionMode(RequestCompletionMode mode) +{ + requestCompletionMode_ = mode; +} + +/** + * \brief Get the request completion mode + * + * \return The current RequestCompletionMode. + */ +Camera::RequestCompletionMode Camera::Private::requestCompletionMode() const +{ + return requestCompletionMode_; +} + /** * \class Camera * \brief Camera device @@ -702,6 +725,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 Camera::RequestCompletionMode::InSubmissionOrder + * \brief requestCompleted will be emited according to the request submission order + * \var Camera::RequestCompletionMode::Immediately + * \brief requestCompleted will be emited immediately when a request is completed. + */ + /** * \brief Retrieve the ID of the camera * @@ -1237,6 +1269,40 @@ int Camera::stop() return 0; } +/** + * \brief Set the request completion mode + * \param[in] mode The RequestCompletionMode + * + * This function set 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->setRequestCompletionMode(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 67540533..7c180a8e 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -494,14 +494,20 @@ void PipelineHandler::completeRequest(Request *request) Camera::Private *data = camera->_d(); - while (!data->queuedRequests_.empty()) { - Request *req = data->queuedRequests_.front(); - if (req->status() == Request::RequestPending) - break; + auto iter = data->queuedRequests_.begin(); + while (iter != data->queuedRequests_.end()) { + if ((*iter)->status() != Request::RequestPending) { + ASSERT(!(*iter)->hasPendingBuffers()); + camera->requestComplete((*iter)); + iter = data->queuedRequests_.erase(iter); + continue; + } - ASSERT(!req->hasPendingBuffers()); - data->queuedRequests_.pop_front(); - camera->requestComplete(req); + /* Break at the pending result to reflect the submission order */ + if (camera->requestCompletionMode() == Camera::InSubmissionOrder) { + break; + } + iter++; } }