From patchwork Fri Jun 3 13:22:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 16138 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 AA7E2C3256 for ; Fri, 3 Jun 2022 13:23:08 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F019F65639; Fri, 3 Jun 2022 15:23:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1654262588; bh=vzOxlCkU1d8zf16gF6O0d6hz2qGWA70wddX4Y8mdK54=; 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=F3wYiOx5ukRq2GAVfcJtxUJ8uxWvXYuye+DgyqvFwzL7ZnXiNROyFDlOcWTupXQ4H oExrW+t5JuvmHh/vwEI7kqO6D9Sedpv9DQicDZWdazI0yW1zcd2mweHroVzNI2DlQM dbo7KPwyBFeXkigMcKq0HJkff+UaM4Vo6cXYarKb+nT0hdWl5dRFK9SYw4HLjhCXSw Ah/cb7OY8ZCvV8EhBiNdIfMvVLQKzqcgbS5zNlzfi6MDy/1lfcrmbKzt3Kr4Wvqd+B Ie5ttIXoR7Ik3Wiu1lHdiTAe14pWERO7q6AC21vwqJvDyj/yY65fNhv2gWtB/S8E03 scScmKmn/2l3g== 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 4368360105 for ; Fri, 3 Jun 2022 15:23:05 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="vk9bYQvw"; dkim-atps=neutral Received: from perceval.ideasonboard.com (static-127-186-62-95.ipcom.comunitel.net [95.62.186.127]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id C750710DD; Fri, 3 Jun 2022 15:23:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1654262585; bh=vzOxlCkU1d8zf16gF6O0d6hz2qGWA70wddX4Y8mdK54=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vk9bYQvwRvqvlOok8v2WiYH+VSNbjmY5zo6ZqX3/z8JdQ/k8714uhNEytZJf2gmac t76f+fL15REQqEJkbb0fZ38L/2RGgNafWAPcQoGBP92N2wuoeeJ4eZPMLUSubPP/Cg qh1DF7De6qAwb0PkXT0wym7guukZ8zapSd9QKcko= To: libcamera-devel@lists.libcamera.org Date: Fri, 3 Jun 2022 15:22:56 +0200 Message-Id: <20220603132259.188845-2-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220603132259.188845-1-umang.jain@ideasonboard.com> References: <20220603132259.188845-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 1/4] ipa: ipu3: Separate out frame context queue as a distinct class 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: Umang Jain via libcamera-devel From: Umang Jain Reply-To: Umang Jain Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" There are cases where we need more checks and balance to be carried out by the frame context queue class. For that, separate it out as a distinct class on which we can build upon. For now, a minimialistic implementation is provided with .get(frame) helper which returns a IPAFrameContext pointer for the required frame. Going ahead more such helpers can be provided to access/modify the frame context queue. Signed-off-by: Umang Jain Reviewed-by: Paul Elder Reviewed-by: Jean-Michel Hautbois --- src/ipa/ipu3/ipa_context.cpp | 57 ++++++++++++++++++++++++++++++++++-- src/ipa/ipu3/ipa_context.h | 11 ++++++- src/ipa/ipu3/ipu3.cpp | 18 ++++++------ 3 files changed, 74 insertions(+), 12 deletions(-) diff --git a/src/ipa/ipu3/ipa_context.cpp b/src/ipa/ipu3/ipa_context.cpp index 13cdb835..9f95a61c 100644 --- a/src/ipa/ipu3/ipa_context.cpp +++ b/src/ipa/ipu3/ipa_context.cpp @@ -7,12 +7,18 @@ #include "ipa_context.h" +#include + /** * \file ipa_context.h * \brief Context and state information shared between the algorithms */ -namespace libcamera::ipa::ipu3 { +namespace libcamera { + +LOG_DECLARE_CATEGORY(IPAIPU3) + +namespace ipa::ipu3 { /** * \struct IPASessionConfiguration @@ -211,4 +217,51 @@ IPAFrameContext::IPAFrameContext(uint32_t id, const ControlList &reqControls) * \brief Analogue gain multiplier */ -} /* namespace libcamera::ipa::ipu3 */ +/** + * \class FCQueue + * \brief A FIFO circular queue holding IPAFrameContext(s) + * + * FCQueue holds all the IPAFrameContext(s) related to frames required + * to be processed by the IPA at a given point. + */ + +/** + * \brief FCQueue constructor + */ +FCQueue::FCQueue() +{ + clear(); +} + +/** + * \brief Retrieve the IPAFrameContext for the frame + * \param[in] frame Frame number for which the IPAFrameContext needs to + * retrieved + * + * \return Pointer to the IPAFrameContext + */ +IPAFrameContext *FCQueue::get(uint32_t frame) +{ + IPAFrameContext &frameContext = this->at(frame % kMaxFrameContexts); + + if (frame != frameContext.frame) { + LOG(IPAIPU3, Warning) + << "Got wrong frame context for frame" << frame + << " or frame context doesn't exist yet"; + } + + return &frameContext; +} + +/** + * \brief Clear the FCQueue by resetting all the entries in the ring-buffer + */ +void FCQueue::clear() +{ + IPAFrameContext initFrameContext; + this->fill(initFrameContext); +} + +} /* namespace ipa::ipu3 */ + +} /* namespace libcamera */ diff --git a/src/ipa/ipu3/ipa_context.h b/src/ipa/ipu3/ipa_context.h index 42e11141..56d281f6 100644 --- a/src/ipa/ipu3/ipa_context.h +++ b/src/ipa/ipu3/ipa_context.h @@ -89,11 +89,20 @@ struct IPAFrameContext { ControlList frameControls; }; +class FCQueue : public std::array +{ +public: + FCQueue(); + + void clear(); + IPAFrameContext *get(uint32_t frame); +}; + struct IPAContext { IPASessionConfiguration configuration; IPAActiveState activeState; - std::array frameContexts; + FCQueue frameContexts; }; } /* namespace ipa::ipu3 */ diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index 2f6bb672..0843d882 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -456,8 +456,8 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo, /* Clean IPAActiveState at each reconfiguration. */ context_.activeState = {}; - IPAFrameContext initFrameContext; - context_.frameContexts.fill(initFrameContext); + context_.frameContexts.clear(); + if (!validateSensorControls()) { LOG(IPAIPU3, Error) << "Sensor control validation failed."; @@ -569,20 +569,20 @@ void IPAIPU3::processStatsBuffer(const uint32_t frame, const ipu3_uapi_stats_3a *stats = reinterpret_cast(mem.data()); - IPAFrameContext &frameContext = context_.frameContexts[frame % kMaxFrameContexts]; + IPAFrameContext *frameContext = context_.frameContexts.get(frame); - if (frameContext.frame != frame) + if (frameContext->frame != frame) LOG(IPAIPU3, Warning) << "Frame " << frame << " does not match its frame context"; - frameContext.sensor.exposure = sensorControls.get(V4L2_CID_EXPOSURE).get(); - frameContext.sensor.gain = camHelper_->gain(sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get()); + frameContext->sensor.exposure = sensorControls.get(V4L2_CID_EXPOSURE).get(); + frameContext->sensor.gain = camHelper_->gain(sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get()); double lineDuration = context_.configuration.sensor.lineDuration.get(); int32_t vBlank = context_.configuration.sensor.defVBlank; ControlList ctrls(controls::controls); for (auto const &algo : algorithms_) - algo->process(context_, &frameContext, stats); + algo->process(context_, frameContext, stats); setControls(frame); @@ -590,11 +590,11 @@ void IPAIPU3::processStatsBuffer(const uint32_t frame, int64_t frameDuration = (vBlank + sensorInfo_.outputSize.height) * lineDuration; ctrls.set(controls::FrameDuration, frameDuration); - ctrls.set(controls::AnalogueGain, frameContext.sensor.gain); + ctrls.set(controls::AnalogueGain, frameContext->sensor.gain); ctrls.set(controls::ColourTemperature, context_.activeState.awb.temperatureK); - ctrls.set(controls::ExposureTime, frameContext.sensor.exposure * lineDuration); + ctrls.set(controls::ExposureTime, frameContext->sensor.exposure * lineDuration); /* * \todo The Metadata provides a path to getting extended data