From patchwork Tue Feb 20 16:43:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Scally X-Patchwork-Id: 19515 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 A3622C3257 for ; Tue, 20 Feb 2024 16:43:37 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5FB6061CAA; Tue, 20 Feb 2024 17:43:37 +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="WHnbW8Ti"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4A30261CAA for ; Tue, 20 Feb 2024 17:43:25 +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 E18E213AC; Tue, 20 Feb 2024 17:43:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1708447398; bh=+D0mqjYPqvZZVsEoTqPXJlIeJLBcXF9uANQXv72rSsg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WHnbW8TiO6g8AdxYnhSJdyuOPQmMw1KQcsYj4xdP5SNuupZDo/305LEh34tXCn27C fiaUpyNJwaBgWC3K5SyoTq4iDupRc2QvqpsEEJ3W4nKRVKjAz9+1Jqb1nsm9PAPMEv ibZDNJOHOETLCWUdj2ugp6lqwMFAr2cJmyPX+SSk= From: Daniel Scally To: libcamera-devel@lists.libcamera.org Subject: [PATCH v2 4/7] libcamera: rkisp1: Switch tryCompleteRequest() to use Request * Date: Tue, 20 Feb 2024 16:43:14 +0000 Message-Id: <20240220164317.998477-5-dan.scally@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240220164317.998477-1-dan.scally@ideasonboard.com> References: <20240220164317.998477-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 - ultimately what is being tracked is whether or not the buffers in question have been handled by the pipeline handler, and a Request already tracks that for the image buffers. The internal buffers can be tracked in the same way using the new concept of internal buffers for a Request. Re-factor the tryCompleteRequest() function to take a Request * and simply check hasPendingBuffers(request). Use the relatively new Request::Private::addInternalBuffer() to link the stats and parameters buffers to the request on each queueRequestDevice(). Signed-off-by: Daniel Scally --- Changes in v2: - Use the new internal buffers for Requests to track status rather than the inFlightStatsBuffers_ map. src/libcamera/pipeline/rkisp1/rkisp1.cpp | 28 ++++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index d926c83c..43e9d98b 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -39,6 +39,7 @@ #include "libcamera/internal/ipa_manager.h" #include "libcamera/internal/media_device.h" #include "libcamera/internal/pipeline_handler.h" +#include "libcamera/internal/request.h" #include "libcamera/internal/v4l2_subdevice.h" #include "libcamera/internal/v4l2_videodevice.h" @@ -48,6 +49,8 @@ namespace libcamera { LOG_DEFINE_CATEGORY(RkISP1) +using InternalStream = Request::Private::InternalStream; + class PipelineHandlerRkISP1; class RkISP1CameraData; @@ -174,7 +177,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 paramReady(FrameBuffer *buffer); void statReady(FrameBuffer *buffer); @@ -231,6 +234,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(); @@ -413,7 +417,8 @@ void RkISP1CameraData::metadataReady(unsigned int frame, const ControlList &meta info->request->metadata().merge(metadata); info->metadataProcessed = true; - pipe()->tryCompleteRequest(info); + pipe()->completeBuffer(info->request, info->statBuffer); + pipe()->tryCompleteRequest(info->request); } /* ----------------------------------------------------------------------------- @@ -1026,6 +1031,9 @@ int PipelineHandlerRkISP1::queueRequestDevice(Camera *camera, Request *request) if (!info) return -ENOENT; + request->_d()->addInternalBuffer(InternalStream::Statistics, info->statBuffer); + request->_d()->addInternalBuffer(InternalStream::Parameters, info->paramBuffer); + data->ipa_->queueRequest(request->sequence(), request->controls()); if (isRaw_) { if (info->mainPathBuffer) @@ -1228,15 +1236,15 @@ 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; - if (request->hasPendingBuffers()) + RkISP1FrameInfo *info = data->frameInfo_.find(request); + if (!info) return; - if (!info->metadataProcessed) + if (request->hasPendingBuffers()) return; if (!isRaw_ && !info->paramDequeued) @@ -1281,7 +1289,7 @@ void PipelineHandlerRkISP1::bufferReady(FrameBuffer *buffer) } completeBuffer(request, buffer); - tryCompleteRequest(info); + tryCompleteRequest(request); } void PipelineHandlerRkISP1::paramReady(FrameBuffer *buffer) @@ -1294,7 +1302,8 @@ void PipelineHandlerRkISP1::paramReady(FrameBuffer *buffer) return; info->paramDequeued = true; - tryCompleteRequest(info); + completeBuffer(info->request, buffer); + tryCompleteRequest(info->request); } void PipelineHandlerRkISP1::statReady(FrameBuffer *buffer) @@ -1309,7 +1318,8 @@ void PipelineHandlerRkISP1::statReady(FrameBuffer *buffer) if (buffer->metadata().status == FrameMetadata::FrameCancelled) { info->metadataProcessed = true; - tryCompleteRequest(info); + completeBuffer(info->request, buffer); + tryCompleteRequest(info->request); return; }