From patchwork Mon Feb 12 15:35:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Scally X-Patchwork-Id: 19481 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 72A0FC32C4 for ; Mon, 12 Feb 2024 15:35:49 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 71FF062817; Mon, 12 Feb 2024 16:35:47 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="k+EreKkh"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6F60362807 for ; Mon, 12 Feb 2024 16:35:44 +0100 (CET) Received: from mail.ideasonboard.com (cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net [86.13.91.161]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B8B8D2D8; Mon, 12 Feb 2024 16:35:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1707752142; bh=xruQDwl4uQuAn9+wiqUFgjgX5aj25sHp22fgs/3FZfw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k+EreKkhZd6PkrMqJmgs12vtfssUqMFsvCR8buXq5WPPMxo1Dn2b5gC7fKBI+Ulri /goBCXT8ZgrXdmMazjk/pXJm32+0b+jl2O8cy/j9T0EUIGNKSpu7EQQkzWLn/D00Oo 4xKdBeUZdTo3tOlP0ShvoCm34iFuDpUqCd2q2CoU= From: Daniel Scally To: libcamera-devel@lists.libcamera.org Subject: [PATCH 4/5] libcamera: rkisp1: Switch tryCompleteRequest() to use Request * Date: Mon, 12 Feb 2024 15:35:31 +0000 Message-Id: <20240212153532.179283-5-dan.scally@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240212153532.179283-1-dan.scally@ideasonboard.com> References: <20240212153532.179283-1-dan.scally@ideasonboard.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" tryCompleteRequest() is used to delay completeRequest() until all the image buffers have been returned to userspace and the Request's metadata has been filled with control values by the IPA. To do that the pipeline handler has a struct which holds various pieces of info that allow the tryCompleteRequest() function to decide whether it's ok to complete the request yet or not. This is quite a heavy way of doing things - most of the information is tracked internally in the Request already (status of the image buffers), some doesn't actually factor into the decision (whether the next param buffer is dequeued) and the final piece (the status of the statistics buffer) can be tracked more simply with a map. Re-factor the tryCompleteRequest() function to take a Request * and simply check hasPendingBuffers(request) and a new map flagging stats buffers as in-flight to decide whether or not to complete. Signed-off-by: Daniel Scally --- As an alternative to the inFlightStatBuffers_ map we could instead extend Request with a concept of internal-only buffers, probably in Request::Private, that wouldn't be exposed to the application but which could be added with an analogue of addBuffer() and checked with an analogue of hasPendingBuffers(). src/libcamera/pipeline/rkisp1/rkisp1.cpp | 25 +++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index d4ed38a4..d8f27e96 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -173,7 +174,7 @@ private: int initLinks(Camera *camera, const CameraSensor *sensor, const RkISP1CameraConfiguration &config); int createCamera(MediaEntity *sensor); - void tryCompleteRequest(RkISP1FrameInfo *info); + void tryCompleteRequest(Request *request); void bufferReady(FrameBuffer *buffer); void statReady(FrameBuffer *buffer); void frameStart(uint32_t sequence); @@ -197,6 +198,7 @@ private: std::vector> statBuffers_; std::queue availableParamBuffers_; std::queue availableStatBuffers_; + std::map inFlightStatBuffers_; Camera *activeCamera_; @@ -229,6 +231,7 @@ RkISP1FrameInfo *RkISP1Frames::create(const RkISP1CameraData *data, Request *req paramBuffer = pipe_->availableParamBuffers_.front(); pipe_->availableParamBuffers_.pop(); + paramBuffer->_d()->setRequest(request); statBuffer = pipe_->availableStatBuffers_.front(); pipe_->availableStatBuffers_.pop(); @@ -425,8 +428,9 @@ void RkISP1CameraData::metadataReady(unsigned int bufferId, info->request->metadata().merge(metadata); info->metadataProcessed = true; + pipe()->inFlightStatBuffers_.erase(info->request->sequence()); - pipe()->tryCompleteRequest(info); + pipe()->tryCompleteRequest(statBuffer->request()); return; } @@ -1044,6 +1048,8 @@ int PipelineHandlerRkISP1::queueRequestDevice(Camera *camera, Request *request) if (!info) return -ENOENT; + inFlightStatBuffers_[request->sequence()] = info->statBuffer; + data->ipa_->queueRequest(request->sequence(), request->controls()); if (isRaw_) { if (info->mainPathBuffer) @@ -1245,15 +1251,19 @@ bool PipelineHandlerRkISP1::match(DeviceEnumerator *enumerator) * Buffer Handling */ -void PipelineHandlerRkISP1::tryCompleteRequest(RkISP1FrameInfo *info) +void PipelineHandlerRkISP1::tryCompleteRequest(Request *request) { RkISP1CameraData *data = cameraData(activeCamera_); - Request *request = info->request; + + RkISP1FrameInfo *info = data->frameInfo_.find(request); + if (!info) + return; if (request->hasPendingBuffers()) return; - if (!info->metadataProcessed) + if (inFlightStatBuffers_.find(request->sequence()) != + inFlightStatBuffers_.end()) return; data->frameInfo_.destroy(info->frame); @@ -1295,7 +1305,7 @@ void PipelineHandlerRkISP1::bufferReady(FrameBuffer *buffer) } completeBuffer(request, buffer); - tryCompleteRequest(info); + tryCompleteRequest(request); } void PipelineHandlerRkISP1::statReady(FrameBuffer *buffer) @@ -1310,7 +1320,8 @@ void PipelineHandlerRkISP1::statReady(FrameBuffer *buffer) if (buffer->metadata().status == FrameMetadata::FrameCancelled) { info->metadataProcessed = true; - tryCompleteRequest(info); + inFlightStatBuffers_.erase(request->sequence()); + tryCompleteRequest(request); return; }