From patchwork Thu Sep 12 04:52:48 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: 21244 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 CDBFBC324C for ; Thu, 12 Sep 2024 04:57:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6C4F7634FF; Thu, 12 Sep 2024 06:57:16 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="f6nt8X2z"; dkim-atps=neutral Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3D5C8634FB for ; Thu, 12 Sep 2024 06:57:12 +0200 (CEST) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-205659dc63aso6515705ad.1 for ; Wed, 11 Sep 2024 21:57:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1726117030; x=1726721830; 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=BJ0z8FK6KSwDQUsR4EdR1clLIHZLI81svcaWeS6aSpY=; b=f6nt8X2zfUHg+0QHbQgoD9Re8DkWtn2oZzYPRV1d6Mh1/hgSsKedZ8VRY9Jnu+wOFj wdIWkch6y0It5ypbgkUZv1IskB1Ubnb3KP6gi1SbhKIRqwSKScGvAz54pSg3CyNqzVNM mNSGzJKv5e/eg8g4OQecH2EgNARjfa5TSZrqg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726117030; x=1726721830; 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=BJ0z8FK6KSwDQUsR4EdR1clLIHZLI81svcaWeS6aSpY=; b=nmbQO3z43B6rHNDqpwL4Jb4etG/b3PH9JTvIVRpfFLyeXstmMAySqsMeDWJ3woebgq P40WVV9mLKQEW84qZ9bPTYMk2VP6L5BsTOpnIRYAq9uRjWj5VWaAkmZK3/OSVzzIKyNx HnjA9Aiv5QX3DqfmDs1L1fyg0qQhgg3MXiRHv4ImhMbR0mcep81sV2b/YkuR0iu9hvWX /AqygJVe//oGnlf/suTxxj2nOZfK1ksg4F3rnsUEiSc01ggRBdaAkh+CMuhy9Z3vgzfE 8+mfVvBOkVw+yO1rZSL/QbR/zVUixV3MFe791xh7WWgwSwUONd2PeWIC7EFE0Ojve7hs VS7w== X-Gm-Message-State: AOJu0Yy2xWT+j+zUAVa3SXuQ+6855BOk1d5q7AcF9jhIW1CsozleiHwy 7jy5l7KlEf2kQVZLQ+tZ0DmFvsWLJ/iIItU6jsP7UvF9fgTOvL6VgGtJtCl/0bwMiOlAxBYaEAI = X-Google-Smtp-Source: AGHT+IF93NYxFqCx/9qIsabJejnWEvCqc8M/NmR3sKwkALi2wEPViQabBVRNuhKTEpnS3HJ+H16dBQ== X-Received: by 2002:a17:903:2281:b0:201:f8b4:3e3c with SMTP id d9443c01a7336-2076e36c158mr28888005ad.12.1726117029686; Wed, 11 Sep 2024 21:57:09 -0700 (PDT) Received: from chenghaoyang-low.c.googlers.com.com (0.223.81.34.bc.googleusercontent.com. [34.81.223.0]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2076b01af1esm7048155ad.293.2024.09.11.21.57.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 21:57:09 -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 1/1] libcamera: Camera: Add signals for completion of metadata as a partial result Date: Thu, 12 Sep 2024 04:52:48 +0000 Message-ID: <20240912045703.3446748-2-chenghaoyang@google.com> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240912045703.3446748-1-chenghaoyang@google.com> References: <20240912045703.3446748-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 Allows pipeline handler to signal metadata completion by adding the following signals to Camera: Signal metadataCompleted; Together with the bufferCompleted signal, the pipeline handler is allowed to return buffers and partial metadata at any stage of processing. Signed-off-by: Han-Lin Chen Co-developed-by: Harvey Yang --- include/libcamera/camera.h | 1 + include/libcamera/internal/pipeline_handler.h | 1 + include/libcamera/request.h | 5 +++ src/libcamera/camera.cpp | 6 +++ src/libcamera/pipeline_handler.cpp | 37 +++++++++++++++++++ src/libcamera/request.cpp | 20 ++++++++++ 6 files changed, 70 insertions(+) diff --git a/include/libcamera/camera.h b/include/libcamera/camera.h index 94cee7bd..08c5c58c 100644 --- a/include/libcamera/camera.h +++ b/include/libcamera/camera.h @@ -122,6 +122,7 @@ public: const std::string &id() const; + Signal metadataCompleted; Signal bufferCompleted; Signal requestCompleted; Signal<> disconnected; diff --git a/include/libcamera/internal/pipeline_handler.h b/include/libcamera/internal/pipeline_handler.h index 0d380803..1af63a23 100644 --- a/include/libcamera/internal/pipeline_handler.h +++ b/include/libcamera/internal/pipeline_handler.h @@ -58,6 +58,7 @@ public: void registerRequest(Request *request); void queueRequest(Request *request); + void completeMetadata(Request *request, const ControlList &metadata); bool completeBuffer(Request *request, FrameBuffer *buffer); void completeRequest(Request *request); diff --git a/include/libcamera/request.h b/include/libcamera/request.h index e214a9d1..0200f4a1 100644 --- a/include/libcamera/request.h +++ b/include/libcamera/request.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -64,6 +65,8 @@ public: std::string toString() const; + ControlList addCompletedMetadata(const ControlList &metadata); + private: LIBCAMERA_DISABLE_COPY(Request) @@ -73,6 +76,8 @@ private: const uint64_t cookie_; Status status_; + + std::unordered_set completedMetadata_; }; std::ostream &operator<<(std::ostream &out, const Request &r); diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index a86f552a..5ffae23e 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -892,6 +892,12 @@ const std::string &Camera::id() const * completed */ +/** + * \var Camera::metadataCompleted + * \brief Signal emitted when some metadata for a request is completed as a + * partial result + */ + /** * \var Camera::requestCompleted * \brief Signal emitted when a request queued to the camera has completed diff --git a/src/libcamera/pipeline_handler.cpp b/src/libcamera/pipeline_handler.cpp index e5940469..5d2999cb 100644 --- a/src/libcamera/pipeline_handler.cpp +++ b/src/libcamera/pipeline_handler.cpp @@ -535,6 +535,28 @@ bool PipelineHandler::completeBuffer(Request *request, FrameBuffer *buffer) return request->_d()->completeBuffer(buffer); } +/** + * \brief Complete part of metadata for a request + * \param[in] request The request the buffer belongs to + * \param[in] metadata The partial metadata that has completed + * + * This function could be called by pipeline handlers to signal completion of + * the \a metadata part of the \a request. It notifies applications of metadata + * completion. + * + * \context This function shall be called from the CameraManager thread. + */ +void PipelineHandler::completeMetadata(Request *request, const ControlList &metadata) +{ + const ControlList &validMetadata = request->addCompletedMetadata(metadata); + if (!validMetadata.empty()) { + request->metadata().merge(validMetadata); + + Camera *camera = request->_d()->camera(); + camera->metadataCompleted.emit(request, validMetadata); + } +} + /** * \brief Signal request completion * \param[in] request The request that has completed @@ -557,6 +579,21 @@ void PipelineHandler::completeRequest(Request *request) Camera::Private *data = camera->_d(); + /* + * Collect metadata which is not yet completed by the Camera, and + * create one partial result to cover the missing metadata before + * completing the whole request. This guarantees the aggregation of + * metadata in completed partial results equals to the global metadata + * in the request. + * + * \todo: Forbid merging metadata into request.metadata() directly and + * force calling completeMetadata() to report metadata. + */ + const ControlList &validMetadata = request->addCompletedMetadata( + request->metadata()); + if (!validMetadata.empty()) + camera->metadataCompleted.emit(request, validMetadata); + while (!data->queuedRequests_.empty()) { Request *req = data->queuedRequests_.front(); if (req->status() == Request::RequestPending) diff --git a/src/libcamera/request.cpp b/src/libcamera/request.cpp index 8c56ed30..3ce23a8e 100644 --- a/src/libcamera/request.cpp +++ b/src/libcamera/request.cpp @@ -598,6 +598,26 @@ std::string Request::toString() const return ss.str(); } +/** + * \brief Add completed metadata, as a partial result + * \param[in] metadata The metadata completed + * + * Request will record the entries that has been sent to the application, to + * prevent duplicated controls. + * + * \return ControlList that hasn't been completed before + */ +ControlList Request::addCompletedMetadata(const ControlList &metadata) +{ + ControlList resultMetadata; + for (auto &[id, value] : metadata) { + if (!completedMetadata_.count(id)) + resultMetadata.set(id, value); + } + + return resultMetadata; +} + /** * \brief Insert a text representation of a Request into an output stream * \param[in] out The output stream