From patchwork Fri Aug 12 09:08:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hanlin Chen X-Patchwork-Id: 17087 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 A8700C3272 for ; Fri, 12 Aug 2022 09:08:51 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5C3E463328; Fri, 12 Aug 2022 11:08:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1660295331; bh=dgT2f5xmNTCegEs3xgGu28WwhPYhRhb8x2LyxCNaXZg=; 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=wOGs1j1pisSi9G6ildhOGegPCoAnp+dGUJ5qv9d3IUZPVJkyqDf2S4/noPa/FtvDT gHYUh19Sj9rjfn6DaYxxRCEsGWKigshwsYlwmE7XEYNVjRplRuesioIshhX+g6V8O5 SbC2El0DxinESckz42roqNCx5o7xclkKLlMZntfBpurvWx+f+4SwOtx62kFbEBhwag 1gzLZc2qnkkkDjopNYqIF9qkcfEcz8ooGyayShLc0HKW469DFQ7Mu7W4AS0+Oi0W5I bRwcnQrDIICyVxjufRsWwZ0p+mAwV6jHGiG4yEPU54Nlf8OhJMb6FS22pg6vfzlPOV Xm/W3qzKromAw== Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BC04463326 for ; Fri, 12 Aug 2022 11:08:49 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="a+uPj3Ai"; dkim-atps=neutral Received: by mail-pf1-x42d.google.com with SMTP id f28so443676pfk.1 for ; Fri, 12 Aug 2022 02:08:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=S1Ep1tF4EF/a5ouUHjKr/XM2U9J6mN0Ei5b1dI1AzoM=; b=a+uPj3AiIxIOgcUGGQ1+HDsGMkcVKOjTJDTw22K7a568gsu+BMutTIm/yRw2rd1wW+ nSiVOLp6myXg8PZLROEwnv/jBUy0/N3av4VVFBqpGPnqJSdjWdL88K6BmLPAuvYSWSSH E1i6Q9hkMt3sE1qTY+oTKviAKa3QBfm+iS1BI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=S1Ep1tF4EF/a5ouUHjKr/XM2U9J6mN0Ei5b1dI1AzoM=; b=hUjkyYEC+463khwKJAp+NQXoHbDQ7kF8sZ8q1v+RvQCEc7F0CyA1gy/qZkDcAiMVqW C0hyJyqejto9r1htky+GqTlMVKX0iYp6NsR1t3kuaos1PhTudzjn8sK2S6Vysipjmh7x zVdcXIj15+dVU4PZYHSmdaZpQEuk4LpcH/Pk47XlgxChlNRwvG16/UgAz9iM4MdZSsrH VaQ8JDiKKPfaWIkT5V3tILXbsZ4BYMe2dzH6H76rXARm2cy2i0WzSNuyDoXKRy9Dyjh8 atyogAXsZi6jU+2shqAwn5dmQ977EyLC8T2aJsfHiSxZOnIkVJQcxrE7FNx8fgrRTsvm zp0w== X-Gm-Message-State: ACgBeo3pL4NL3DTEIm4Yg0vGzyfVAAl69uhu97DFHS5ynEU3SxUgdLD3 9pgvlngqZCHTodXazDbvpzT25xdncT7R8g== X-Google-Smtp-Source: AA6agR6vSqlU4fLgd+Uw7toluSwzV3Uvw5zlxg6I+qUKthflswoyYxtEXUPYYUBBr8F7+z+fRPecSw== X-Received: by 2002:a05:6a00:d74:b0:52f:575c:2d69 with SMTP id n52-20020a056a000d7400b0052f575c2d69mr2977935pfv.77.1660295328103; Fri, 12 Aug 2022 02:08:48 -0700 (PDT) Received: from localhost ([2401:fa00:1:17:1705:d284:d114:2e24]) by smtp.gmail.com with UTF8SMTPSA id b72-20020a621b4b000000b0052d3d08cd96sm1100372pfb.67.2022.08.12.02.08.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Aug 2022 02:08:47 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Fri, 12 Aug 2022 17:08:32 +0800 Message-Id: <20220812090838.1784703-2-hanlinchen@chromium.org> X-Mailer: git-send-email 2.37.1.595.g718a3a8f04-goog In-Reply-To: <20220812090838.1784703-1-hanlinchen@chromium.org> References: <20220812090838.1784703-1-hanlinchen@chromium.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 1/7] 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++; } }