From patchwork Mon Feb 12 15:35:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Scally X-Patchwork-Id: 19478 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 B38A5C3257 for ; Mon, 12 Feb 2024 15:35:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B24E562808; Mon, 12 Feb 2024 16:35:45 +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="sSBdrBfQ"; 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 B31A1627FE for ; Mon, 12 Feb 2024 16:35:43 +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 ED648B53; Mon, 12 Feb 2024 16:35:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1707752142; bh=DxJqQex+DsTsuM3bNz0S4N1NOuMFev5rQoljL/VGl8o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sSBdrBfQOfZh62TGh6e2BOok2XFKTvG84S0tnctUTA8J3+7mYh41JhEogYFS1ayzM QLJtMCybi4g0qQsob/3paXMKVNRaO76pzaeuK77v44ZDf6xoTVD0tbEEVvdQh/Wyuh e8JGTCXxVJnUkVAsDMcbltpyZpp1ve2vbgvQUnJ4= From: Daniel Scally To: libcamera-devel@lists.libcamera.org Subject: [PATCH 1/5] libcamera: rkisp1: Make tryCompleteRequest() params agnostic Date: Mon, 12 Feb 2024 15:35:28 +0000 Message-Id: <20240212153532.179283-2-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() doesn't actually need to know the status of the parameters buffer to decide whether it's ok to complete the Request or not - remove the check. Since setting the paramsDequeued flag is all that the paramsReady slot actually does, that can be removed too. Signed-off-by: Daniel Scally --- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 586b46d6..5460dc11 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -60,7 +60,6 @@ struct RkISP1FrameInfo { FrameBuffer *mainPathBuffer; FrameBuffer *selfPathBuffer; - bool paramDequeued; bool metadataProcessed; }; @@ -177,7 +176,6 @@ private: int createCamera(MediaEntity *sensor); void tryCompleteRequest(RkISP1FrameInfo *info); void bufferReady(FrameBuffer *buffer); - void paramReady(FrameBuffer *buffer); void statReady(FrameBuffer *buffer); void frameStart(uint32_t sequence); @@ -248,7 +246,6 @@ RkISP1FrameInfo *RkISP1Frames::create(const RkISP1CameraData *data, Request *req info->mainPathBuffer = mainPathBuffer; info->selfPathBuffer = selfPathBuffer; info->statBuffer = statBuffer; - info->paramDequeued = false; info->metadataProcessed = false; frameInfo_[frame] = info; @@ -1213,7 +1210,6 @@ bool PipelineHandlerRkISP1::match(DeviceEnumerator *enumerator) if (hasSelfPath_) selfPath_.bufferReady().connect(this, &PipelineHandlerRkISP1::bufferReady); stat_->bufferReady.connect(this, &PipelineHandlerRkISP1::statReady); - param_->bufferReady.connect(this, &PipelineHandlerRkISP1::paramReady); /* * Enumerate all sensors connected to the ISP and create one @@ -1243,9 +1239,6 @@ void PipelineHandlerRkISP1::tryCompleteRequest(RkISP1FrameInfo *info) if (!info->metadataProcessed) return; - if (!isRaw_ && !info->paramDequeued) - return; - data->frameInfo_.destroy(info->frame); completeRequest(request); @@ -1287,19 +1280,6 @@ void PipelineHandlerRkISP1::bufferReady(FrameBuffer *buffer) tryCompleteRequest(info); } -void PipelineHandlerRkISP1::paramReady(FrameBuffer *buffer) -{ - ASSERT(activeCamera_); - RkISP1CameraData *data = cameraData(activeCamera_); - - RkISP1FrameInfo *info = data->frameInfo_.find(buffer); - if (!info) - return; - - info->paramDequeued = true; - tryCompleteRequest(info); -} - void PipelineHandlerRkISP1::statReady(FrameBuffer *buffer) { ASSERT(activeCamera_); From patchwork Mon Feb 12 15:35:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Scally X-Patchwork-Id: 19479 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 C7C2EBDE17 for ; Mon, 12 Feb 2024 15:35:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5F04662812; Mon, 12 Feb 2024 16:35:46 +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="TeH0KGyT"; 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 E2C2A61CB6 for ; Mon, 12 Feb 2024 16:35:43 +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 38C7E2D8; 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=urcbygLaPvl5pQyS4StU6jBzQQkXgldSc3sRRNYbzaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TeH0KGyTgHupZP+NKwxts3n1uyduLcXw0sUtJD8yH7AW6Kuu4sv3TdtxOI07ST0vL X5q8zLIOsrNkd2cVqciTLyr6D7MbrBOvDHekSTch1ZcYKsTKW6UgozJVQRNSWm/9k6 OuzLYX12vH1q3EAoOn8BmqpojvPqc7B02IvsWUCE= From: Daniel Scally To: libcamera-devel@lists.libcamera.org Subject: [PATCH 2/5] libcamera: rkisp1: Standardise frame number tracking Date: Mon, 12 Feb 2024 15:35:29 +0000 Message-Id: <20240212153532.179283-3-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" The rkisp1 driver uses a couple of different methods of tracking the number of the frame - standardise them on request->sequence() and remove the frame_ member of RkISP1CameraData which was being used to do the job. Signed-off-by: Daniel Scally Reviewed-by: Jacopo Mondi --- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 25 ++++++++++-------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 5460dc11..22e553fe 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -87,7 +87,7 @@ class RkISP1CameraData : public Camera::Private public: RkISP1CameraData(PipelineHandler *pipe, RkISP1MainPath *mainPath, RkISP1SelfPath *selfPath) - : Camera::Private(pipe), frame_(0), frameInfo_(pipe), + : Camera::Private(pipe), frameInfo_(pipe), mainPath_(mainPath), selfPath_(selfPath) { } @@ -99,7 +99,6 @@ public: Stream selfPathStream_; std::unique_ptr sensor_; std::unique_ptr delayedCtrls_; - unsigned int frame_; std::vector ipaBuffers_; RkISP1Frames frameInfo_; @@ -212,7 +211,7 @@ RkISP1Frames::RkISP1Frames(PipelineHandler *pipe) RkISP1FrameInfo *RkISP1Frames::create(const RkISP1CameraData *data, Request *request, bool isRaw) { - unsigned int frame = data->frame_; + unsigned int frame = request->sequence(); FrameBuffer *paramBuffer = nullptr; FrameBuffer *statBuffer = nullptr; @@ -233,6 +232,7 @@ RkISP1FrameInfo *RkISP1Frames::create(const RkISP1CameraData *data, Request *req statBuffer = pipe_->availableStatBuffers_.front(); pipe_->availableStatBuffers_.pop(); + statBuffer->_d()->setRequest(request); } FrameBuffer *mainPathBuffer = request->findBuffer(&data->mainPathStream_); @@ -932,8 +932,6 @@ int PipelineHandlerRkISP1::start(Camera *camera, [[maybe_unused]] const ControlL return ret; } - data->frame_ = 0; - if (!isRaw_) { ret = param_->streamOn(); if (ret) { @@ -1025,7 +1023,7 @@ int PipelineHandlerRkISP1::queueRequestDevice(Camera *camera, Request *request) if (!info) return -ENOENT; - data->ipa_->queueRequest(data->frame_, request->controls()); + data->ipa_->queueRequest(request->sequence(), request->controls()); if (isRaw_) { if (info->mainPathBuffer) data->mainPath_->queueBuffer(info->mainPathBuffer); @@ -1033,12 +1031,10 @@ int PipelineHandlerRkISP1::queueRequestDevice(Camera *camera, Request *request) if (data->selfPath_ && info->selfPathBuffer) data->selfPath_->queueBuffer(info->selfPathBuffer); } else { - data->ipa_->fillParamsBuffer(data->frame_, + data->ipa_->fillParamsBuffer(request->sequence(), info->paramBuffer->cookie()); } - data->frame_++; - return 0; } @@ -1269,7 +1265,8 @@ void PipelineHandlerRkISP1::bufferReady(FrameBuffer *buffer) if (isRaw_) { const ControlList &ctrls = data->delayedCtrls_->get(metadata.sequence); - data->ipa_->processStatsBuffer(info->frame, 0, ctrls); + data->ipa_->processStatsBuffer(request->sequence(), + 0, ctrls); } } else { if (isRaw_) @@ -1284,6 +1281,7 @@ void PipelineHandlerRkISP1::statReady(FrameBuffer *buffer) { ASSERT(activeCamera_); RkISP1CameraData *data = cameraData(activeCamera_); + Request *request = buffer->request(); RkISP1FrameInfo *info = data->frameInfo_.find(buffer); if (!info) @@ -1295,11 +1293,8 @@ void PipelineHandlerRkISP1::statReady(FrameBuffer *buffer) return; } - if (data->frame_ <= buffer->metadata().sequence) - data->frame_ = buffer->metadata().sequence + 1; - - data->ipa_->processStatsBuffer(info->frame, info->statBuffer->cookie(), - data->delayedCtrls_->get(buffer->metadata().sequence)); + data->ipa_->processStatsBuffer(request->sequence(), info->statBuffer->cookie(), + data->delayedCtrls_->get(request->sequence())); } REGISTER_PIPELINE_HANDLER(PipelineHandlerRkISP1) From patchwork Mon Feb 12 15:35:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Scally X-Patchwork-Id: 19480 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 308C7C32C3 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 DB79A62814; Mon, 12 Feb 2024 16:35:46 +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="FBa8t7yv"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2CF67627FE 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 7A64FB53; 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=lrEgDEFU1TFHgIie2eGmD3DqpVXJ2+sJDe+Wy4+dkd8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FBa8t7yvb+ZQ9fM0qrhdt9hRVsp8QVZ5GIzrmYQu+MgTWIIWeMgMwYoCm3CGz5lzF D5UVMm9H+E2JNXygqLEKHoy4CPVNte8NpZ8Z26svvWVH9lXIwxevua/SJGgyXiql2V dvfcEmCPkh462FJnNtfB3v5Hi3U55JQTaSUes7UY= From: Daniel Scally To: libcamera-devel@lists.libcamera.org Subject: [PATCH 3/5] libcamera: rkisp1: Switch IPA slots to use bufferId not frame Date: Mon, 12 Feb 2024 15:35:30 +0000 Message-Id: <20240212153532.179283-4-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" In preparation for removing the RkISP1FrameInfo class we need the RkISP1 IPA to emit bufferIds rather than frame numbers for its slots so that the pipeline handler can find the correct buffer properly. Switch the slots; reconfigure the pipeline handler to obtain the correct buffer first before passing it to RkISP1FrameInfo::find() as before; one of its overloads already works with FrameBuffer *. Signed-off-by: Daniel Scally --- include/libcamera/ipa/rkisp1.mojom | 4 +- src/ipa/rkisp1/rkisp1.cpp | 4 +- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 59 ++++++++++++++++-------- 3 files changed, 44 insertions(+), 23 deletions(-) diff --git a/include/libcamera/ipa/rkisp1.mojom b/include/libcamera/ipa/rkisp1.mojom index 1009e970..4c097622 100644 --- a/include/libcamera/ipa/rkisp1.mojom +++ b/include/libcamera/ipa/rkisp1.mojom @@ -36,7 +36,7 @@ interface IPARkISP1Interface { }; interface IPARkISP1EventInterface { - paramsBufferReady(uint32 frame); + paramsBufferReady(uint32 bufferId); setSensorControls(uint32 frame, libcamera.ControlList sensorControls); - metadataReady(uint32 frame, libcamera.ControlList metadata); + metadataReady(uint32 bufferId, libcamera.ControlList metadata); }; diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 6544c925..7e01a04d 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -337,7 +337,7 @@ void IPARkISP1::fillParamsBuffer(const uint32_t frame, const uint32_t bufferId) for (auto const &algo : algorithms()) algo->prepare(context_, frame, frameContext, params); - paramsBufferReady.emit(frame); + paramsBufferReady.emit(bufferId); } void IPARkISP1::processStatsBuffer(const uint32_t frame, const uint32_t bufferId, @@ -370,7 +370,7 @@ void IPARkISP1::processStatsBuffer(const uint32_t frame, const uint32_t bufferId setControls(frame); - metadataReady.emit(frame, metadata); + metadataReady.emit(bufferId, metadata); } void IPARkISP1::updateControls(const IPACameraSensorInfo &sensorInfo, diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 22e553fe..d4ed38a4 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -376,23 +376,34 @@ int RkISP1CameraData::loadIPA(unsigned int hwRevision) return 0; } -void RkISP1CameraData::paramFilled(unsigned int frame) +void RkISP1CameraData::paramFilled(unsigned int bufferId) { PipelineHandlerRkISP1 *pipe = RkISP1CameraData::pipe(); - RkISP1FrameInfo *info = frameInfo_.find(frame); - if (!info) - return; - info->paramBuffer->_d()->metadata().planes()[0].bytesused = - sizeof(struct rkisp1_params_cfg); - pipe->param_->queueBuffer(info->paramBuffer); - pipe->stat_->queueBuffer(info->statBuffer); + for (std::unique_ptr ¶mBuffer : pipe->paramBuffers_) { + if (paramBuffer->cookie() != bufferId) + continue; + + RkISP1FrameInfo *info = frameInfo_.find(paramBuffer.get()); + if (!info) + return; + + info->paramBuffer->_d()->metadata().planes()[0].bytesused = + sizeof(struct rkisp1_params_cfg); + pipe->param_->queueBuffer(info->paramBuffer); + pipe->stat_->queueBuffer(info->statBuffer); - if (info->mainPathBuffer) - mainPath_->queueBuffer(info->mainPathBuffer); + if (info->mainPathBuffer) + mainPath_->queueBuffer(info->mainPathBuffer); + + if (selfPath_ && info->selfPathBuffer) + selfPath_->queueBuffer(info->selfPathBuffer); + + return; + } - if (selfPath_ && info->selfPathBuffer) - selfPath_->queueBuffer(info->selfPathBuffer); + LOG(RkISP1, Fatal) << "Can't locate buffer from bufferId"; + return; } void RkISP1CameraData::setSensorControls([[maybe_unused]] unsigned int frame, @@ -401,16 +412,26 @@ void RkISP1CameraData::setSensorControls([[maybe_unused]] unsigned int frame, delayedCtrls_->push(sensorControls); } -void RkISP1CameraData::metadataReady(unsigned int frame, const ControlList &metadata) +void RkISP1CameraData::metadataReady(unsigned int bufferId, + const ControlList &metadata) { - RkISP1FrameInfo *info = frameInfo_.find(frame); - if (!info) - return; + for (std::unique_ptr &statBuffer : pipe()->statBuffers_) { + if (statBuffer->cookie() != bufferId) + continue; + + RkISP1FrameInfo *info = frameInfo_.find(statBuffer.get()); + if (!info) + return; - info->request->metadata().merge(metadata); - info->metadataProcessed = true; + info->request->metadata().merge(metadata); + info->metadataProcessed = true; + + pipe()->tryCompleteRequest(info); + return; + } - pipe()->tryCompleteRequest(info); + LOG(RkISP1, Fatal) << "Can't locate buffer from bufferId"; + return; } /* ----------------------------------------------------------------------------- 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; } From patchwork Mon Feb 12 15:35:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Scally X-Patchwork-Id: 19482 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 ABD96C32C5 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 169F462818; Mon, 12 Feb 2024 16:35:48 +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="SZZuWdeC"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B02436280A 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 09429B53; Mon, 12 Feb 2024 16:35:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1707752143; bh=iMCHnAmh9fML1gMTs9rm1CXUcGfrZwEBEWtDh+beB/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SZZuWdeCleFXmtXzOau2GEOk5haDzyAkh/SXATTINrMpsn0wpqJiOC/WaD+e3MiAV iyYYMwpsYqeVdXW3nq9pBNKSxoCV/iKbHkd8XrS8k3u2k4qUVRiZjCgvtVRxfOvGo/ ukxqBVs8Cp17OLw+lH99rIKeWoeeK5xpqLzlsrxI= From: Daniel Scally To: libcamera-devel@lists.libcamera.org Subject: [PATCH 5/5] libcamera: rkisp1: Remove RkISP1FrameInfo Date: Mon, 12 Feb 2024 15:35:32 +0000 Message-Id: <20240212153532.179283-6-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" The RkISP1FrameInfo class existed to hold varying bits of info to help guarantee that a Request is not completed until all of the image buffers are returned to userspace and the metadata has been filled by the IPA module. Now that we're no longer using it for that function it can be removed. Remove the class and refactor its code out to the rest of the Pipeline Handler. Signed-off-by: Daniel Scally --- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 252 +++++------------------ 1 file changed, 46 insertions(+), 206 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index d8f27e96..f6dfd1cb 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -52,44 +52,13 @@ LOG_DEFINE_CATEGORY(RkISP1) class PipelineHandlerRkISP1; class RkISP1CameraData; -struct RkISP1FrameInfo { - unsigned int frame; - Request *request; - - FrameBuffer *paramBuffer; - FrameBuffer *statBuffer; - FrameBuffer *mainPathBuffer; - FrameBuffer *selfPathBuffer; - - bool metadataProcessed; -}; - -class RkISP1Frames -{ -public: - RkISP1Frames(PipelineHandler *pipe); - - RkISP1FrameInfo *create(const RkISP1CameraData *data, Request *request, - bool isRaw); - int destroy(unsigned int frame); - void clear(); - - RkISP1FrameInfo *find(unsigned int frame); - RkISP1FrameInfo *find(FrameBuffer *buffer); - RkISP1FrameInfo *find(Request *request); - -private: - PipelineHandlerRkISP1 *pipe_; - std::map frameInfo_; -}; - class RkISP1CameraData : public Camera::Private { public: RkISP1CameraData(PipelineHandler *pipe, RkISP1MainPath *mainPath, RkISP1SelfPath *selfPath) - : Camera::Private(pipe), frameInfo_(pipe), - mainPath_(mainPath), selfPath_(selfPath) + : Camera::Private(pipe), mainPath_(mainPath), + selfPath_(selfPath) { } @@ -101,7 +70,6 @@ public: std::unique_ptr sensor_; std::unique_ptr delayedCtrls_; std::vector ipaBuffers_; - RkISP1Frames frameInfo_; RkISP1MainPath *mainPath_; RkISP1SelfPath *selfPath_; @@ -169,7 +137,6 @@ private: } friend RkISP1CameraData; - friend RkISP1Frames; int initLinks(Camera *camera, const CameraSensor *sensor, const RkISP1CameraConfiguration &config); @@ -205,130 +172,6 @@ private: const MediaPad *ispSink_; }; -RkISP1Frames::RkISP1Frames(PipelineHandler *pipe) - : pipe_(static_cast(pipe)) -{ -} - -RkISP1FrameInfo *RkISP1Frames::create(const RkISP1CameraData *data, Request *request, - bool isRaw) -{ - unsigned int frame = request->sequence(); - - FrameBuffer *paramBuffer = nullptr; - FrameBuffer *statBuffer = nullptr; - - if (!isRaw) { - if (pipe_->availableParamBuffers_.empty()) { - LOG(RkISP1, Error) << "Parameters buffer underrun"; - return nullptr; - } - - if (pipe_->availableStatBuffers_.empty()) { - LOG(RkISP1, Error) << "Statistic buffer underrun"; - return nullptr; - } - - paramBuffer = pipe_->availableParamBuffers_.front(); - pipe_->availableParamBuffers_.pop(); - paramBuffer->_d()->setRequest(request); - - statBuffer = pipe_->availableStatBuffers_.front(); - pipe_->availableStatBuffers_.pop(); - statBuffer->_d()->setRequest(request); - } - - FrameBuffer *mainPathBuffer = request->findBuffer(&data->mainPathStream_); - FrameBuffer *selfPathBuffer = request->findBuffer(&data->selfPathStream_); - - RkISP1FrameInfo *info = new RkISP1FrameInfo; - - info->frame = frame; - info->request = request; - info->paramBuffer = paramBuffer; - info->mainPathBuffer = mainPathBuffer; - info->selfPathBuffer = selfPathBuffer; - info->statBuffer = statBuffer; - info->metadataProcessed = false; - - frameInfo_[frame] = info; - - return info; -} - -int RkISP1Frames::destroy(unsigned int frame) -{ - RkISP1FrameInfo *info = find(frame); - if (!info) - return -ENOENT; - - pipe_->availableParamBuffers_.push(info->paramBuffer); - pipe_->availableStatBuffers_.push(info->statBuffer); - - frameInfo_.erase(info->frame); - - delete info; - - return 0; -} - -void RkISP1Frames::clear() -{ - for (const auto &entry : frameInfo_) { - RkISP1FrameInfo *info = entry.second; - - pipe_->availableParamBuffers_.push(info->paramBuffer); - pipe_->availableStatBuffers_.push(info->statBuffer); - - delete info; - } - - frameInfo_.clear(); -} - -RkISP1FrameInfo *RkISP1Frames::find(unsigned int frame) -{ - auto itInfo = frameInfo_.find(frame); - - if (itInfo != frameInfo_.end()) - return itInfo->second; - - LOG(RkISP1, Fatal) << "Can't locate info from frame"; - - return nullptr; -} - -RkISP1FrameInfo *RkISP1Frames::find(FrameBuffer *buffer) -{ - for (auto &itInfo : frameInfo_) { - RkISP1FrameInfo *info = itInfo.second; - - if (info->paramBuffer == buffer || - info->statBuffer == buffer || - info->mainPathBuffer == buffer || - info->selfPathBuffer == buffer) - return info; - } - - LOG(RkISP1, Fatal) << "Can't locate info from buffer"; - - return nullptr; -} - -RkISP1FrameInfo *RkISP1Frames::find(Request *request) -{ - for (auto &itInfo : frameInfo_) { - RkISP1FrameInfo *info = itInfo.second; - - if (info->request == request) - return info; - } - - LOG(RkISP1, Fatal) << "Can't locate info from request"; - - return nullptr; -} - PipelineHandlerRkISP1 *RkISP1CameraData::pipe() { return static_cast(Camera::Private::pipe()); @@ -387,20 +230,30 @@ void RkISP1CameraData::paramFilled(unsigned int bufferId) if (paramBuffer->cookie() != bufferId) continue; - RkISP1FrameInfo *info = frameInfo_.find(paramBuffer.get()); - if (!info) + Request *request = paramBuffer->request(); + FrameBuffer *mainPathBuffer = request->findBuffer(&mainPathStream_); + FrameBuffer *selfPathBuffer = request->findBuffer(&selfPathStream_); + + if (pipe->availableStatBuffers_.empty()) { + LOG(RkISP1, Fatal) << "Parameters buffer underrun"; return; + } + + FrameBuffer *statBuffer = pipe->availableStatBuffers_.front(); + pipe->availableStatBuffers_.pop(); + pipe->inFlightStatBuffers_[request->sequence()] = statBuffer; + statBuffer->_d()->setRequest(request); - info->paramBuffer->_d()->metadata().planes()[0].bytesused = + paramBuffer->_d()->metadata().planes()[0].bytesused = sizeof(struct rkisp1_params_cfg); - pipe->param_->queueBuffer(info->paramBuffer); - pipe->stat_->queueBuffer(info->statBuffer); + pipe->param_->queueBuffer(paramBuffer.get()); + pipe->stat_->queueBuffer(statBuffer); - if (info->mainPathBuffer) - mainPath_->queueBuffer(info->mainPathBuffer); + if (mainPathBuffer) + mainPath_->queueBuffer(mainPathBuffer); - if (selfPath_ && info->selfPathBuffer) - selfPath_->queueBuffer(info->selfPathBuffer); + if (selfPath_ && selfPathBuffer) + selfPath_->queueBuffer(selfPathBuffer); return; } @@ -422,15 +275,13 @@ void RkISP1CameraData::metadataReady(unsigned int bufferId, if (statBuffer->cookie() != bufferId) continue; - RkISP1FrameInfo *info = frameInfo_.find(statBuffer.get()); - if (!info) - return; + Request *request = statBuffer->request(); - info->request->metadata().merge(metadata); - info->metadataProcessed = true; - pipe()->inFlightStatBuffers_.erase(info->request->sequence()); + request->metadata().merge(metadata); + pipe()->inFlightStatBuffers_.erase(request->sequence()); + pipe()->availableStatBuffers_.push(statBuffer.get()); + pipe()->tryCompleteRequest(request); - pipe()->tryCompleteRequest(statBuffer->request()); return; } @@ -1033,7 +884,6 @@ void PipelineHandlerRkISP1::stopDevice(Camera *camera) } ASSERT(data->queuedRequests_.empty()); - data->frameInfo_.clear(); freeBuffers(camera); @@ -1043,23 +893,32 @@ void PipelineHandlerRkISP1::stopDevice(Camera *camera) int PipelineHandlerRkISP1::queueRequestDevice(Camera *camera, Request *request) { RkISP1CameraData *data = cameraData(camera); + FrameBuffer *paramBuffer = nullptr; - RkISP1FrameInfo *info = data->frameInfo_.create(data, request, isRaw_); - if (!info) - return -ENOENT; + if (!isRaw_) { + if (availableParamBuffers_.empty()) { + LOG(RkISP1, Error) << "Parameters buffer underrun"; + return -ENOENT; + } - inFlightStatBuffers_[request->sequence()] = info->statBuffer; + paramBuffer = availableParamBuffers_.front(); + availableParamBuffers_.pop(); + paramBuffer->_d()->setRequest(request); + } data->ipa_->queueRequest(request->sequence(), request->controls()); if (isRaw_) { - if (info->mainPathBuffer) - data->mainPath_->queueBuffer(info->mainPathBuffer); + FrameBuffer *mainPathBuffer = request->findBuffer(&data->mainPathStream_); + FrameBuffer *selfPathBuffer = request->findBuffer(&data->selfPathStream_); + + if (mainPathBuffer) + data->mainPath_->queueBuffer(mainPathBuffer); - if (data->selfPath_ && info->selfPathBuffer) - data->selfPath_->queueBuffer(info->selfPathBuffer); + if (data->selfPath_ && selfPathBuffer) + data->selfPath_->queueBuffer(selfPathBuffer); } else { data->ipa_->fillParamsBuffer(request->sequence(), - info->paramBuffer->cookie()); + paramBuffer->cookie()); } return 0; @@ -1253,12 +1112,6 @@ bool PipelineHandlerRkISP1::match(DeviceEnumerator *enumerator) void PipelineHandlerRkISP1::tryCompleteRequest(Request *request) { - RkISP1CameraData *data = cameraData(activeCamera_); - - RkISP1FrameInfo *info = data->frameInfo_.find(request); - if (!info) - return; - if (request->hasPendingBuffers()) return; @@ -1266,8 +1119,6 @@ void PipelineHandlerRkISP1::tryCompleteRequest(Request *request) inFlightStatBuffers_.end()) return; - data->frameInfo_.destroy(info->frame); - completeRequest(request); } @@ -1275,11 +1126,6 @@ void PipelineHandlerRkISP1::bufferReady(FrameBuffer *buffer) { ASSERT(activeCamera_); RkISP1CameraData *data = cameraData(activeCamera_); - - RkISP1FrameInfo *info = data->frameInfo_.find(buffer); - if (!info) - return; - const FrameMetadata &metadata = buffer->metadata(); Request *request = buffer->request(); @@ -1299,9 +1145,6 @@ void PipelineHandlerRkISP1::bufferReady(FrameBuffer *buffer) data->ipa_->processStatsBuffer(request->sequence(), 0, ctrls); } - } else { - if (isRaw_) - info->metadataProcessed = true; } completeBuffer(request, buffer); @@ -1314,18 +1157,15 @@ void PipelineHandlerRkISP1::statReady(FrameBuffer *buffer) RkISP1CameraData *data = cameraData(activeCamera_); Request *request = buffer->request(); - RkISP1FrameInfo *info = data->frameInfo_.find(buffer); - if (!info) - return; if (buffer->metadata().status == FrameMetadata::FrameCancelled) { - info->metadataProcessed = true; inFlightStatBuffers_.erase(request->sequence()); + availableStatBuffers_.push(buffer); tryCompleteRequest(request); return; } - data->ipa_->processStatsBuffer(request->sequence(), info->statBuffer->cookie(), + data->ipa_->processStatsBuffer(request->sequence(), buffer->cookie(), data->delayedCtrls_->get(request->sequence())); }