From patchwork Thu Mar 31 16:30:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 15594 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 61A11C3256 for ; Thu, 31 Mar 2022 16:31:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 16A1365637; Thu, 31 Mar 2022 18:31:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648744275; bh=NeggrAJB3EVsMVFrePCbrSbv24Dlun6ZuJaPwTfjsWA=; 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=in5NHYetEM1fpj51sjRz+sqFI8qFELKX7AALcMZGIM3yHD6fBXNo6NYPZQkQ3xVZj 9pIp4NcEtoW/wAq9YzcWrDN4VkF6YEwc73LG0YgkvitpB/wAlNyJQrjOKxqH64v9yD 9c+ZWecinXNSslKLK3Zx9+60YEgC6qTbBsQuU9Pubzqp4wKDGsD6OwEuDqTq91TPN3 NSNmGazx+KfL9IOcp7JyFkg0VJC8BmXOt5TejeWBpA6fMkDSLOdc2lXBLsBz+gQXjp mDXAMLb6oOkC+fHrawijpaum94jTKPFNBNlXfiZF9ZZitISQqf+E12eAp9B4rvkl0r FYRgt+ODS6szQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C563265633 for ; Thu, 31 Mar 2022 18:31:13 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="snf3dis2"; dkim-atps=neutral Received: from perceval.ideasonboard.com (unknown [103.74.73.150]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1027E486; Thu, 31 Mar 2022 18:31:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1648744273; bh=NeggrAJB3EVsMVFrePCbrSbv24Dlun6ZuJaPwTfjsWA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=snf3dis2Z3GkSTcIS78PrqDqkok5GFD+6aQ+f7U7Y8DNcesEjwxF8lkecxU1dzbqB rCanVrLn3TbGPEgveed+88w0PcfrThEBWV4i1NWcapXrfSzmFXJkGU5uRTNmV3Kggx sLxY1GxQlSc7PUFaTPamPeiXosM6D4lTb81KkdfA= To: libcamera-devel@lists.libcamera.org Date: Thu, 31 Mar 2022 22:00:53 +0530 Message-Id: <20220331163058.171418-2-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220331163058.171418-1-umang.jain@ideasonboard.com> References: <20220331163058.171418-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 1/6] ipa: ipu3: Replace event-based ops with dedicated functions 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" The IPAIPU3 interface currently uses event-type based structures in order to communicate with the pipeline-handler (and vice-versa). Replace the event based structures with dedicated functions associated to each operation. The translated naming scheme of operations to dedicated functions: ActionSetSensorControls => setSensorControls ActionParamFilled => paramsBufferReady ActionMetadataReady => metadataReady EventProcessControls => queueRequest() EventStatReady => processStatsBuffer() EventFillParams => fillParamsBuffer() Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart --- include/libcamera/ipa/ipu3.mojom | 36 ++----- src/ipa/ipu3/ipu3-ipa-design-guide.rst | 27 ++--- src/ipa/ipu3/ipu3.cpp | 132 +++++++++++-------------- src/libcamera/pipeline/ipu3/ipu3.cpp | 122 ++++++++++------------- 4 files changed, 132 insertions(+), 185 deletions(-) diff --git a/include/libcamera/ipa/ipu3.mojom b/include/libcamera/ipa/ipu3.mojom index 18cdc744..b1e06e65 100644 --- a/include/libcamera/ipa/ipu3.mojom +++ b/include/libcamera/ipa/ipu3.mojom @@ -8,32 +8,6 @@ module ipa.ipu3; import "include/libcamera/ipa/core.mojom"; -enum IPU3Operations { - ActionSetSensorControls = 1, - ActionParamFilled = 2, - ActionMetadataReady = 3, - EventProcessControls = 4, - EventStatReady = 5, - EventFillParams = 6, -}; - -struct IPU3Event { - IPU3Operations op; - uint32 frame; - int64 frameTimestamp; - uint32 bufferId; - libcamera.ControlList controls; - libcamera.ControlList sensorControls; - libcamera.ControlList lensControls; -}; - -struct IPU3Action { - IPU3Operations op; - libcamera.ControlList controls; - libcamera.ControlList sensorControls; - libcamera.ControlList lensControls; -}; - struct IPAConfigInfo { libcamera.IPACameraSensorInfo sensorInfo; libcamera.ControlInfoMap sensorControls; @@ -56,9 +30,15 @@ interface IPAIPU3Interface { mapBuffers(array buffers); unmapBuffers(array ids); - [async] processEvent(IPU3Event ev); + [async] fillParamsBuffer(uint32 frame, uint32 bufferId); + [async] processStatsBuffer(uint32 frame, int64 frameTimestamp, + uint32 bufferId, libcamera.ControlList sensorControls); + [async] queueRequest(uint32 frame, libcamera.ControlList controls); }; interface IPAIPU3EventInterface { - queueFrameAction(uint32 frame, IPU3Action action); + setSensorControls(uint32 frame, libcamera.ControlList sensorControls, + libcamera.ControlList lensControls); + paramsBufferReady(uint32 frame); + metadataReady(uint32 frame, libcamera.ControlList metadata); }; diff --git a/src/ipa/ipu3/ipu3-ipa-design-guide.rst b/src/ipa/ipu3/ipu3-ipa-design-guide.rst index 89c71108..13682599 100644 --- a/src/ipa/ipu3/ipu3-ipa-design-guide.rst +++ b/src/ipa/ipu3/ipu3-ipa-design-guide.rst @@ -25,7 +25,8 @@ from applications, and managing events from the pipeline handler. └─┬───┬───┬──────┬────┬────┬────┬─┴────▼─┬──┘ 1: init() │ │ │ │ ▲ │ ▲ │ ▲ │ ▲ │ 2: configure() │1 │2 │3 │4│ │4│ │4│ │4│ │5 3: mapBuffers(), start() - ▼ ▼ ▼ ▼ │ ▼ │ ▼ │ ▼ │ ▼ 4: processEvent() + │ │ │ │ │ │ │ │ │ │ │ │ 4: (▼) queueRequest(), fillParamsBuffer(), processStatsBuffer() + ▼ ▼ ▼ ▼ │ ▼ │ ▼ │ ▼ │ ▼ (▲) setSensorControls, paramsBufferReady, metadataReady Signals ┌──────────────────┴────┴────┴────┴─────────┐ 5: stop(), unmapBuffers() │ IPU3 IPA │ │ ┌───────────────────────┐ │ @@ -100,8 +101,9 @@ There are three main interactions with the algorithms for the IPU3 IPA to operate when running: - configure() -- processEvent(``EventFillParams``) -- processEvent(``EventStatReady``) +- fillParamsBuffer() +- queueRequest() +- processStatsBuffer() The configuration phase allows the pipeline-handler to inform the IPA of the current stream configurations, which is then passed into each @@ -114,8 +116,8 @@ Pre-frame preparation When configured, the IPA is notified by the pipeline handler of the Camera ``start()`` event, after which incoming requests will be queued for processing, requiring a parameter buffer (``ipu3_uapi_params``) to -be populated for the ImgU. This is given to the IPA through the -``EventFillParams`` event, and then passed directly to each algorithm +be populated for the ImgU. This is given to the IPA through +``fillParamsBuffer()``, and then passed directly to each algorithm through the ``prepare()`` call allowing the ISP configuration to be updated for the needs of each component that the algorithm is responsible for. @@ -125,7 +127,7 @@ structure that it modifies, and it should take care to ensure that any structure set by a use flag is fully initialised to suitable values. The parameter buffer is returned to the pipeline handler through the -``ActionParamFilled`` event, and from there queued to the ImgU along +``paramsBufferReady`` signal, and from there queued to the ImgU along with a raw frame captured with the CIO2. Post-frame completion @@ -133,8 +135,8 @@ Post-frame completion When the capture of an image is completed, and successfully processed through the ImgU, the generated statistics buffer -(``ipu3_uapi_stats_3a``) is given to the IPA through the -``EventStatReady`` event. This provides the IPA with an opportunity to +(``ipu3_uapi_stats_3a``) is given to the IPA through +``processStatsBuffer()``. This provides the IPA with an opportunity to examine the results of the ISP and run the calculations required by each algorithm on the new data. The algorithms may require context from the operations of other algorithms, for example, the AWB might choose to use @@ -145,11 +147,14 @@ before they are needed. The ordering of the algorithm processing is determined by their placement in the ``IPU3::algorithms_`` ordered list. +Finally, the IPA metadata for the completed frame is returned back via +the ``metadataReady`` signal. + Sensor Controls ~~~~~~~~~~~~~~~ The AutoExposure and AutoGain (AGC) algorithm differs slightly from the others as it requires operating directly on the sensor, as opposed to -through the ImgU ISP. To support this, there is a dedicated action -`ActionSetSensorControls` to allow the IPA to request controls to be set -on the camera sensor through the pipeline handler. +through the ImgU ISP. To support this, there is a ``setSensorControls`` +signal to allow the IPA to request controls to be set on the camera +sensor through the pipeline handler. diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index 50b52d8b..7779ad58 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -65,8 +65,9 @@ namespace ipa::ipu3 { * The IPU3 Pipeline defines an IPU3-specific interface for communication * between the PipelineHandler and the IPA module. * - * We extend the IPAIPU3Interface to implement our algorithms and handle events - * from the IPU3 PipelineHandler to satisfy requests from the application. + * We extend the IPAIPU3Interface to implement our algorithms and handle + * calls from the IPU3 PipelineHandler to satisfy requests from the + * application. * * At initialisation time, a CameraSensorHelper is instantiated to support * camera-specific calculations, while the default controls are computed, and @@ -81,14 +82,14 @@ namespace ipa::ipu3 { * parameter buffer, and adapting the settings of the sensor attached to the * IPU3 CIO2 through sensor-specific V4L2 controls. * - * When the event \a EventFillParams occurs we populate the ImgU parameter - * buffer with settings to configure the device in preparation for handling the - * frame queued in the Request. + * In fillParamsBuffer(), we populate the ImgU parameter buffer with + * settings to configure the device in preparation for handling the frame + * queued in the Request. * * When the frame has completed processing, the ImgU will generate a statistics - * buffer which is given to the IPA as part of the \a EventStatReady event. At - * this event we run the algorithms to parse the statistics and cache any - * results for the next \a EventFillParams event. + * buffer which is given to the IPA with processStatsBuffer(). In this we run the + * algorithms to parse the statistics and cache any results for the next + * fillParamsBuffer() function. * * The individual algorithms are split into modular components that are called * iteratively to allow them to process statistics from the ImgU in a defined @@ -143,14 +144,19 @@ public: void mapBuffers(const std::vector &buffers) override; void unmapBuffers(const std::vector &ids) override; - void processEvent(const IPU3Event &event) override; + + void fillParamsBuffer(const uint32_t frame, const uint32_t bufferId) override; + void processStatsBuffer(const uint32_t frame, const int64_t frameTimestamp, + const uint32_t bufferId, + const ControlList &sensorControls) override; + void queueRequest(const uint32_t frame, const ControlList &controls) override; private: void updateControls(const IPACameraSensorInfo &sensorInfo, const ControlInfoMap &sensorControls, ControlInfoMap *ipaControls); void updateSessionConfiguration(const ControlInfoMap &sensorControls); - void processControls(unsigned int frame, const ControlList &controls); + void fillParams(unsigned int frame, ipu3_uapi_params *params); void parseStatistics(unsigned int frame, int64_t frameTimestamp, @@ -505,73 +511,61 @@ void IPAIPU3::unmapBuffers(const std::vector &ids) } /** - * \brief Process an event generated by the pipeline handler - * \param[in] event The event sent from pipeline handler - * - * The expected event handling over the lifetime of a Request has - * the following sequence: - * - * - EventProcessControls : Handle controls from a new Request - * - EventFillParams : Prepare the ISP to process the Request - * - EventStatReady : Process statistics after ISP completion + * \brief Fill and return a buffer with ISP processing parameters for a frame + * \param[in] frame The frame number + * \param[in] bufferId ID of the parameter buffer to fill */ -void IPAIPU3::processEvent(const IPU3Event &event) +void IPAIPU3::fillParamsBuffer(const uint32_t frame, const uint32_t bufferId) { - switch (event.op) { - case EventProcessControls: { - processControls(event.frame, event.controls); - break; + auto it = buffers_.find(bufferId); + if (it == buffers_.end()) { + LOG(IPAIPU3, Error) << "Could not find param buffer!"; + return; } - case EventFillParams: { - auto it = buffers_.find(event.bufferId); - if (it == buffers_.end()) { - LOG(IPAIPU3, Error) << "Could not find param buffer!"; - return; - } - Span mem = it->second.planes()[0]; - ipu3_uapi_params *params = - reinterpret_cast(mem.data()); + Span mem = it->second.planes()[0]; + ipu3_uapi_params *params = + reinterpret_cast(mem.data()); - fillParams(event.frame, params); - break; - } - case EventStatReady: { - auto it = buffers_.find(event.bufferId); - if (it == buffers_.end()) { - LOG(IPAIPU3, Error) << "Could not find stats buffer!"; - return; - } + fillParams(frame, params); +} - Span mem = it->second.planes()[0]; - const ipu3_uapi_stats_3a *stats = - reinterpret_cast(mem.data()); +/** + * \brief Process statistics after ISP completion + * \param[in] frame The frame number + * \param[in] frameTimestamp Timestamp of the frame + * \param[in] bufferId ID of the statistics buffer + * \param[in] sensorControls Sensor controls + */ +void IPAIPU3::processStatsBuffer(const uint32_t frame, const int64_t frameTimestamp, + const uint32_t bufferId, const ControlList &sensorControls) +{ + auto it = buffers_.find(bufferId); + if (it == buffers_.end()) { + LOG(IPAIPU3, Error) << "Could not find stats buffer!"; + return; + } - int32_t exposure = event.sensorControls.get(V4L2_CID_EXPOSURE).get(); - int32_t gain = event.sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get(); + Span mem = it->second.planes()[0]; + const ipu3_uapi_stats_3a *stats = + reinterpret_cast(mem.data()); - context_.frameContext.sensor.exposure = exposure; - context_.frameContext.sensor.gain = camHelper_->gain(gain); + context_.frameContext.sensor.exposure = sensorControls.get(V4L2_CID_EXPOSURE).get(); + context_.frameContext.sensor.gain = camHelper_->gain(sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get()); - parseStatistics(event.frame, event.frameTimestamp, stats); - break; - } - default: - LOG(IPAIPU3, Error) << "Unknown event " << event.op; - break; - } + parseStatistics(frame, frameTimestamp, stats); } /** - * \brief Process a control list for a request from the application + * \brief Queue a request and process the control list from the application * \param[in] frame The number of the frame which will be processed next * \param[in] controls The controls for the \a frame * * Parse the request to handle any IPA-managed controls that were set from the * application such as manual sensor settings. */ -void IPAIPU3::processControls([[maybe_unused]] unsigned int frame, - [[maybe_unused]] const ControlList &controls) +void IPAIPU3::queueRequest(const uint32_t frame, + [[maybe_unused]] const ControlList &controls) { /* \todo Start processing for 'frame' based on 'controls'. */ } @@ -600,10 +594,7 @@ void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params) for (auto const &algo : algorithms_) algo->prepare(context_, params); - IPU3Action op; - op.op = ActionParamFilled; - - queueFrameAction.emit(frame, op); + paramsBufferReady.emit(frame); } /** @@ -647,11 +638,7 @@ void IPAIPU3::parseStatistics(unsigned int frame, * likely want to avoid putting platform specific metadata in. */ - IPU3Action op; - op.op = ActionMetadataReady; - op.controls = ctrls; - - queueFrameAction.emit(frame, op); + metadataReady.emit(frame, ctrls); } /** @@ -663,23 +650,18 @@ void IPAIPU3::parseStatistics(unsigned int frame, */ void IPAIPU3::setControls(unsigned int frame) { - IPU3Action op; - op.op = ActionSetSensorControls; - int32_t exposure = context_.frameContext.agc.exposure; int32_t gain = camHelper_->gainCode(context_.frameContext.agc.gain); ControlList ctrls(sensorCtrls_); ctrls.set(V4L2_CID_EXPOSURE, exposure); ctrls.set(V4L2_CID_ANALOGUE_GAIN, gain); - op.sensorControls = ctrls; - ControlList lensCtrls(lensCtrls_); + ControlList lensCtrls(sensorCtrls_); lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE, static_cast(context_.frameContext.af.focus)); - op.lensControls = lensCtrls; - queueFrameAction.emit(frame, op); + setSensorControls.emit(frame, ctrls, lensCtrls); } } /* namespace ipa::ipu3 */ diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp index 60e01917..59d7e9c0 100644 --- a/src/libcamera/pipeline/ipu3/ipu3.cpp +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp @@ -86,8 +86,10 @@ public: ControlInfoMap ipaControls_; private: - void queueFrameAction(unsigned int id, - const ipa::ipu3::IPU3Action &action); + void metadataReady(unsigned int id, const ControlList &metadata); + void paramsFilled(unsigned int id); + void setSensorControls(unsigned int id, const ControlList &sensorControls, + const ControlList &lensControls); }; class IPU3CameraConfiguration : public CameraConfiguration @@ -871,11 +873,7 @@ void IPU3CameraData::queuePendingRequests() info->rawBuffer = rawBuffer; - ipa::ipu3::IPU3Event ev; - ev.op = ipa::ipu3::EventProcessControls; - ev.frame = info->id; - ev.controls = request->controls(); - ipa_->processEvent(ev); + ipa_->queueRequest(info->id, request->controls()); pendingRequests_.pop(); processingRequests_.push(request); @@ -1218,7 +1216,9 @@ int IPU3CameraData::loadIPA() if (!ipa_) return -ENOENT; - ipa_->queueFrameAction.connect(this, &IPU3CameraData::queueFrameAction); + ipa_->setSensorControls.connect(this, &IPU3CameraData::setSensorControls); + ipa_->paramsBufferReady.connect(this, &IPU3CameraData::paramsFilled); + ipa_->metadataReady.connect(this, &IPU3CameraData::metadataReady); /* * Pass the sensor info to the IPA to initialize controls. @@ -1253,69 +1253,58 @@ int IPU3CameraData::loadIPA() return 0; } -void IPU3CameraData::queueFrameAction(unsigned int id, - const ipa::ipu3::IPU3Action &action) +void IPU3CameraData::setSensorControls([[maybe_unused]] unsigned int id, + const ControlList &sensorControls, + const ControlList &lensControls) { - switch (action.op) { - case ipa::ipu3::ActionSetSensorControls: { - const ControlList &sensorControls = action.sensorControls; - delayedCtrls_->push(sensorControls); + delayedCtrls_->push(sensorControls); - CameraLens *focusLens = cio2_.sensor()->focusLens(); - if (!focusLens) - break; - - const ControlList lensControls = action.lensControls; - if (!lensControls.contains(V4L2_CID_FOCUS_ABSOLUTE)) - break; + CameraLens *focusLens = cio2_.sensor()->focusLens(); + if (!focusLens) + return; - const ControlValue &focusValue = - lensControls.get(V4L2_CID_FOCUS_ABSOLUTE); + if (!lensControls.contains(V4L2_CID_FOCUS_ABSOLUTE)) + return; - focusLens->setFocusPosition(focusValue.get()); + const ControlValue &focusValue = lensControls.get(V4L2_CID_FOCUS_ABSOLUTE); - break; - } - case ipa::ipu3::ActionParamFilled: { - IPU3Frames::Info *info = frameInfos_.find(id); - if (!info) - break; - - /* Queue all buffers from the request aimed for the ImgU. */ - for (auto it : info->request->buffers()) { - const Stream *stream = it.first; - FrameBuffer *outbuffer = it.second; + focusLens->setFocusPosition(focusValue.get()); +} - if (stream == &outStream_) - imgu_->output_->queueBuffer(outbuffer); - else if (stream == &vfStream_) - imgu_->viewfinder_->queueBuffer(outbuffer); - } +void IPU3CameraData::paramsFilled(unsigned int id) +{ + IPU3Frames::Info *info = frameInfos_.find(id); + if (!info) + return; - imgu_->param_->queueBuffer(info->paramBuffer); - imgu_->stat_->queueBuffer(info->statBuffer); - imgu_->input_->queueBuffer(info->rawBuffer); + /* Queue all buffers from the request aimed for the ImgU. */ + for (auto it : info->request->buffers()) { + const Stream *stream = it.first; + FrameBuffer *outbuffer = it.second; - break; + if (stream == &outStream_) + imgu_->output_->queueBuffer(outbuffer); + else if (stream == &vfStream_) + imgu_->viewfinder_->queueBuffer(outbuffer); } - case ipa::ipu3::ActionMetadataReady: { - IPU3Frames::Info *info = frameInfos_.find(id); - if (!info) - break; - Request *request = info->request; - request->metadata().merge(action.controls); + imgu_->param_->queueBuffer(info->paramBuffer); + imgu_->stat_->queueBuffer(info->statBuffer); + imgu_->input_->queueBuffer(info->rawBuffer); +} - info->metadataProcessed = true; - if (frameInfos_.tryComplete(info)) - pipe()->completeRequest(request); +void IPU3CameraData::metadataReady(unsigned int id, const ControlList &metadata) +{ + IPU3Frames::Info *info = frameInfos_.find(id); + if (!info) + return; - break; - } - default: - LOG(IPU3, Error) << "Unknown action " << action.op; - break; - } + Request *request = info->request; + request->metadata().merge(metadata); + + info->metadataProcessed = true; + if (frameInfos_.tryComplete(info)) + pipe()->completeRequest(request); } /* ----------------------------------------------------------------------------- @@ -1390,11 +1379,7 @@ void IPU3CameraData::cio2BufferReady(FrameBuffer *buffer) if (request->findBuffer(&rawStream_)) pipe()->completeBuffer(request, buffer); - ipa::ipu3::IPU3Event ev; - ev.op = ipa::ipu3::EventFillParams; - ev.frame = info->id; - ev.bufferId = info->paramBuffer->cookie(); - ipa_->processEvent(ev); + ipa_->fillParamsBuffer(info->id, info->paramBuffer->cookie()); } void IPU3CameraData::paramBufferReady(FrameBuffer *buffer) @@ -1438,13 +1423,8 @@ void IPU3CameraData::statBufferReady(FrameBuffer *buffer) return; } - ipa::ipu3::IPU3Event ev; - ev.op = ipa::ipu3::EventStatReady; - ev.frame = info->id; - ev.bufferId = info->statBuffer->cookie(); - ev.frameTimestamp = request->metadata().get(controls::SensorTimestamp); - ev.sensorControls = info->effectiveSensorControls; - ipa_->processEvent(ev); + ipa_->processStatsBuffer(info->id, request->metadata().get(controls::SensorTimestamp), + info->statBuffer->cookie(), info->effectiveSensorControls); } /* From patchwork Thu Mar 31 16:30:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 15595 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 69D19C3256 for ; Thu, 31 Mar 2022 16:31:19 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 12B826563A; Thu, 31 Mar 2022 18:31:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648744279; bh=loseBciBXbXDa57acsv32QPhI9u/TYHzc6qK45tZQlY=; 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=ckqr9p+zenZo757u7ge8havhT7yzY2HUwaAb9enbB8nnokFOP5YsXY2vp7Szadu8i 88y1JX118N/LAMnLHv9VSfqgaLk16oKG4r63dEbmUncxzbc0cg5mpxAjdW9RIecW8U yN6Obkm5urWJim/RNiyO2/9Xsp/CnuVPWx86FXfeaDohWb7Rtt8RYj+m8E66HYttGb wMVQ87pDZGwg+k2BBObcyGqRfPhXizH1W6DuhCojPBP4Jrs6eI5O5SPSmBikC5x+Ka xHOgEzc4ZaC8/WTvnr0tzL916rqgHdTg0zK9ffPgunsQ9dnIbc8OcQmeFHwq03D+I/ 7/A0UDhaqH0iA== 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 A1E646563D for ; Thu, 31 Mar 2022 18:31:17 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="f1L1N9kp"; dkim-atps=neutral Received: from perceval.ideasonboard.com (unknown [103.74.73.150]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5D838486; Thu, 31 Mar 2022 18:31:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1648744277; bh=loseBciBXbXDa57acsv32QPhI9u/TYHzc6qK45tZQlY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f1L1N9kpo/1QiBj5JEao3Pvnk9pM59v+2LHwAVVOu5GAmLv/NpDiTdK2tPtho+yPT N8mX6+Umb5w9VAVYJ1w8vF7EPUxx+qsyKq0cqw6EgFo8sYzbguv+UNzVKrsLEhtUWy zCahd2eprsTRFBwA+fyZJzu5E6sDEHMBo49R/1qI= To: libcamera-devel@lists.libcamera.org Date: Thu, 31 Mar 2022 22:00:54 +0530 Message-Id: <20220331163058.171418-3-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220331163058.171418-1-umang.jain@ideasonboard.com> References: <20220331163058.171418-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 2/6] ipa: ipu3: Inlink fillParams() in fillParamsBuffer() 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" Since we have moved away from switch/case on the operation ID, there's little reason to split the operation in two functions. Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart --- src/ipa/ipu3/ipu3.cpp | 47 +++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index 7779ad58..23a9033e 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -157,7 +157,6 @@ private: ControlInfoMap *ipaControls); void updateSessionConfiguration(const ControlInfoMap &sensorControls); - void fillParams(unsigned int frame, ipu3_uapi_params *params); void parseStatistics(unsigned int frame, int64_t frameTimestamp, const ipu3_uapi_stats_3a *stats); @@ -514,6 +513,9 @@ void IPAIPU3::unmapBuffers(const std::vector &ids) * \brief Fill and return a buffer with ISP processing parameters for a frame * \param[in] frame The frame number * \param[in] bufferId ID of the parameter buffer to fill + * + * Algorithms are expected to fill the IPU3 parameter buffer for the next + * frame given their most recent processing of the ImgU statistics. */ void IPAIPU3::fillParamsBuffer(const uint32_t frame, const uint32_t bufferId) { @@ -527,7 +529,21 @@ void IPAIPU3::fillParamsBuffer(const uint32_t frame, const uint32_t bufferId) ipu3_uapi_params *params = reinterpret_cast(mem.data()); - fillParams(frame, params); + /* + * The incoming params buffer may contain uninitialised data, or the + * parameters of previously queued frames. Clearing the entire buffer + * may be an expensive operation, and the kernel will only read from + * structures which have their associated use-flag set. + * + * It is the responsibility of the algorithms to set the use flags + * accordingly for any data structure they update during prepare(). + */ + params->use = {}; + + for (auto const &algo : algorithms_) + algo->prepare(context_, params); + + paramsBufferReady.emit(frame); } /** @@ -570,33 +586,6 @@ void IPAIPU3::queueRequest(const uint32_t frame, /* \todo Start processing for 'frame' based on 'controls'. */ } -/** - * \brief Fill the ImgU parameter buffer for the next frame - * \param[in] frame The number of the latest frame processed - * \param[out] params The parameter buffer to fill - * - * Algorithms are expected to fill the IPU3 parameter buffer for the next - * frame given their most recent processing of the ImgU statistics. - */ -void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params) -{ - /* - * The incoming params buffer may contain uninitialised data, or the - * parameters of previously queued frames. Clearing the entire buffer - * may be an expensive operation, and the kernel will only read from - * structures which have their associated use-flag set. - * - * It is the responsibility of the algorithms to set the use flags - * accordingly for any data structure they update during prepare(). - */ - params->use = {}; - - for (auto const &algo : algorithms_) - algo->prepare(context_, params); - - paramsBufferReady.emit(frame); -} - /** * \brief Process the statistics generated by the ImgU * \param[in] frame The number of the latest frame processed From patchwork Thu Mar 31 16:30:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 15596 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 F1E02C3256 for ; Thu, 31 Mar 2022 16:31:23 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A96CD65635; Thu, 31 Mar 2022 18:31:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648744283; bh=woaICZpi4vBYwSHNgQg1gJUb3iznCV2EVIobAILwSUI=; 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=UoswSlTzITyyrVtFq4q3nOJ4Wayu3MfQ5+teQKMnTSQ/8Z8yAqqvIqdT0EuiYR5r/ XwXi/IGOuYDv0yVZhxvfnG1GfcVrq6tT4ViUhkUMmlF2BceiIEMTXp0A7TDDyHhXn4 mWC0jm2xjvamJXRwTCiDUd6azlVLC2zZy7Woc8szqCX61+EozmFnH9Oi9w8SKCu/Y+ GAWJXWJpe8mGWzfEWGWktIj1KhmgvtXR9B1/94ITT9gIF6E/TtarMic9SNdIaD3AOC E73idVOwG4StqwnOJPwRswDjW8DHNk8f2PumSKY+b9xb5Z/+WMnyv7fT0EakBDx1CV vOyj8tP1F5vZg== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 87F016563E for ; Thu, 31 Mar 2022 18:31:21 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="No02faHa"; dkim-atps=neutral Received: from perceval.ideasonboard.com (unknown [103.74.73.150]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7DD54486; Thu, 31 Mar 2022 18:31:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1648744281; bh=woaICZpi4vBYwSHNgQg1gJUb3iznCV2EVIobAILwSUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=No02faHa8FgioXIT0FhUlV8+HTqWYXW7zL0Yhbf3H4cAnqjdxLV8+s1dR2lUGdL54 YzFyOQXjn6tQQsdElCoJl/5pPllUCzOM1XG0AVrmuzhYncPUicH14ev200Xgr9gOxA zInjQFRotJNUcxHV61yZHQORvF3AECdh0282rlGU= To: libcamera-devel@lists.libcamera.org Date: Thu, 31 Mar 2022 22:00:55 +0530 Message-Id: <20220331163058.171418-4-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220331163058.171418-1-umang.jain@ideasonboard.com> References: <20220331163058.171418-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 3/6] ipa: ipu3: Inlink parseStatistics() into processStatsBuffer() 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" Since we have moved away from switch/case on the operation ID, there's little reason to split the operation in two functions. Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart --- src/ipa/ipu3/ipu3.cpp | 54 +++++++++++++++---------------------------- 1 file changed, 19 insertions(+), 35 deletions(-) diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp index 23a9033e..605ca9a5 100644 --- a/src/ipa/ipu3/ipu3.cpp +++ b/src/ipa/ipu3/ipu3.cpp @@ -157,9 +157,6 @@ private: ControlInfoMap *ipaControls); void updateSessionConfiguration(const ControlInfoMap &sensorControls); - void parseStatistics(unsigned int frame, - int64_t frameTimestamp, - const ipu3_uapi_stats_3a *stats); bool validateSensorControls(); void setControls(unsigned int frame); @@ -547,11 +544,15 @@ void IPAIPU3::fillParamsBuffer(const uint32_t frame, const uint32_t bufferId) } /** - * \brief Process statistics after ISP completion + * \brief Process the statistics generated by the ImgU * \param[in] frame The frame number * \param[in] frameTimestamp Timestamp of the frame * \param[in] bufferId ID of the statistics buffer * \param[in] sensorControls Sensor controls + * + * Parse the most recently processed image statistics from the ImgU. The + * statistics are passed to each algorithm module to run their calculations and + * update their state accordingly. */ void IPAIPU3::processStatsBuffer(const uint32_t frame, const int64_t frameTimestamp, const uint32_t bufferId, const ControlList &sensorControls) @@ -569,37 +570,6 @@ void IPAIPU3::processStatsBuffer(const uint32_t frame, const int64_t frameTimest context_.frameContext.sensor.exposure = sensorControls.get(V4L2_CID_EXPOSURE).get(); context_.frameContext.sensor.gain = camHelper_->gain(sensorControls.get(V4L2_CID_ANALOGUE_GAIN).get()); - parseStatistics(frame, frameTimestamp, stats); -} - -/** - * \brief Queue a request and process the control list from the application - * \param[in] frame The number of the frame which will be processed next - * \param[in] controls The controls for the \a frame - * - * Parse the request to handle any IPA-managed controls that were set from the - * application such as manual sensor settings. - */ -void IPAIPU3::queueRequest(const uint32_t frame, - [[maybe_unused]] const ControlList &controls) -{ - /* \todo Start processing for 'frame' based on 'controls'. */ -} - -/** - * \brief Process the statistics generated by the ImgU - * \param[in] frame The number of the latest frame processed - * \param[in] frameTimestamp The current frame timestamp - * \param[in] stats The IPU3 statistics and ISP results - * - * Parse the most recently processed image statistics from the ImgU. The - * statistics are passed to each algorithm module to run their calculations and - * update their state accordingly. - */ -void IPAIPU3::parseStatistics(unsigned int frame, - [[maybe_unused]] int64_t frameTimestamp, - const ipu3_uapi_stats_3a *stats) -{ double lineDuration = context_.configuration.sensor.lineDuration.get(); int32_t vBlank = context_.configuration.sensor.defVBlank; ControlList ctrls(controls::controls); @@ -630,6 +600,20 @@ void IPAIPU3::parseStatistics(unsigned int frame, metadataReady.emit(frame, ctrls); } +/** + * \brief Queue a request and process the control list from the application + * \param[in] frame The number of the frame which will be processed next + * \param[in] controls The controls for the \a frame + * + * Parse the request to handle any IPA-managed controls that were set from the + * application such as manual sensor settings. + */ +void IPAIPU3::queueRequest(const uint32_t frame, + [[maybe_unused]] const ControlList &controls) +{ + /* \todo Start processing for 'frame' based on 'controls'. */ +} + /** * \brief Handle sensor controls for a given \a frame number * \param[in] frame The frame on which the sensor controls should be set From patchwork Thu Mar 31 16:30: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: 15597 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 60C0BC3256 for ; Thu, 31 Mar 2022 16:31:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 13F6465635; Thu, 31 Mar 2022 18:31:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648744289; bh=iQP5eAvRsUy/OgVVjshQKc/QqGsiL4OgAA5JP8Gyv2o=; 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=edhIS1d3E2soGBZl8SPzIkyAC+qjBYIb3YXOx/YvObZvlz4l4HPem7pxaM+sXve6E objcr2GmEyBn8DsQlk1G48tFUJiHeffYu1EcklTzqCgqmA+e7kUyMrUjJIJJg2wgkR MZ4OVM/PXD2DRlvryXd/ocgBHJHtv2NieupTke/kSNaMkYrL2yYXh4jwxisFx65//D 5U9u7oN3z/X47Ime9ThvlL4cJRyqARzcVB4pQFq5yYqZQry5w4+WhGRIb0oetar4zP 8ge6ew4YQfr4J//0mKOpMpwUrjW21yp3kYnEC2zLM80G4fKU47GHj91RnuvgmDHtku hMtHhJvwae0rw== 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 B3A0265634 for ; Thu, 31 Mar 2022 18:31:27 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ZoBBunwb"; dkim-atps=neutral Received: from perceval.ideasonboard.com (unknown [103.74.73.150]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D9277486; Thu, 31 Mar 2022 18:31:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1648744287; bh=iQP5eAvRsUy/OgVVjshQKc/QqGsiL4OgAA5JP8Gyv2o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZoBBunwbb9rlNRjPtc7zHS6svIQUre9uKK1K2WiHZy9qZ7j6o3H/rRtANRnit+7qh 9ONCIps8L8BZpkLHdOH0iXJu2G7m1Z1DcuMI0wJPTEulvksxwLa8ovRSU/SP9vL8bK Ix4ZpbyCmwbg1U5MUQQmFhgbdaz89K/zasBnBSyM= To: libcamera-devel@lists.libcamera.org Date: Thu, 31 Mar 2022 22:00:56 +0530 Message-Id: <20220331163058.171418-5-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220331163058.171418-1-umang.jain@ideasonboard.com> References: <20220331163058.171418-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [IPAIPU3 PATCH v4 4/6] ipu3: Use the new IPAIPU3 interface 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" Use the new IPAIPU3 interface that migrates the event-based ops to dedication functions. Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart --- ipu3.cpp | 102 ++++++++++++++++++++++--------------------------------- 1 file changed, 41 insertions(+), 61 deletions(-) diff --git a/ipu3.cpp b/ipu3.cpp index 6ab86e0..289cc77 100644 --- a/ipu3.cpp +++ b/ipu3.cpp @@ -49,13 +49,17 @@ public: void mapBuffers(const std::vector &buffers) override; void unmapBuffers(const std::vector &ids) override; - void processEvent(const IPU3Event &event) override; + + void fillParamsBuffer(const uint32_t frame, const uint32_t bufferId) override; + void processStatsBuffer(const uint32_t frame, const int64_t frameTimestamp, + const uint32_t bufferId, + const ControlList &sensorControls) override; + void queueRequest(const uint32_t frame, const ControlList &controls) override; private: void updateControls(const IPACameraSensorInfo &sensorInfo, const ControlInfoMap &sensorControls, ControlInfoMap *ipaControls); - void processControls(unsigned int frame, const ControlList &metadata); void runAiq(unsigned int frame); void fillParams(unsigned int frame, ipu3_uapi_params *params); void parseStatistics(unsigned int frame, @@ -321,54 +325,41 @@ void IPAIPU3::unmapBuffers(const std::vector &ids) } } -void IPAIPU3::processEvent(const IPU3Event &event) +void IPAIPU3::queueRequest([[maybe_unused]] unsigned int frame, + [[maybe_unused]] const ControlList &controls) { - switch (event.op) { - case EventProcessControls: { - processControls(event.frame, event.controls); - break; - } - case EventStatReady: { - auto it = buffers_.find(event.bufferId); - if (it == buffers_.end()) { - LOG(IPAIPU3, Error) << "Could not find stats buffer!"; - return; - } - - Span mem = it->second.maps()[0]; - const ipu3_uapi_stats_3a *stats = - reinterpret_cast(mem.data()); - - parseStatistics(event.frame, - event.frameTimestamp, - stats, - event.sensorControls); - break; - } - case EventFillParams: { - auto it = buffers_.find(event.bufferId); - if (it == buffers_.end()) { - LOG(IPAIPU3, Error) << "Could not find param buffer!"; - return; - } - - Span mem = it->second.maps()[0]; - ipu3_uapi_params *params = - reinterpret_cast(mem.data()); - - fillParams(event.frame, params); - break; - } - default: - LOG(IPAIPU3, Error) << "Unknown event " << event.op; - break; + /* \todo Start processing for 'frame' based on 'controls'. */ +} + +void IPAIPU3::fillParamsBuffer(const uint32_t frame, const uint32_t bufferId) +{ + auto it = buffers_.find(bufferId); + if (it == buffers_.end()) { + LOG(IPAIPU3, Error) << "Could not find params buffer"; + return; } + + Span mem = it->second.maps()[0]; + ipu3_uapi_params *params = + reinterpret_cast(mem.data()); + + fillParams(frame, params); } -void IPAIPU3::processControls([[maybe_unused]] unsigned int frame, - [[maybe_unused]] const ControlList &controls) +void IPAIPU3::processStatsBuffer(const uint32_t frame, const int64_t frameTimestamp, + const uint32_t bufferId, const ControlList &sensorControls) { - /* \todo Start processing for 'frame' based on 'controls'. */ + auto it = buffers_.find(bufferId); + if (it == buffers_.end()) { + LOG(IPAIPU3, Error) << "Could not find stats buffer"; + return; + } + + Span mem = it->second.maps()[0]; + const ipu3_uapi_stats_3a *stats = + reinterpret_cast(mem.data()); + + parseStatistics(frame, frameTimestamp, stats, sensorControls); } void IPAIPU3::runAiq([[maybe_unused]] unsigned int frame) @@ -424,10 +415,7 @@ void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params) setControls(frame); - IPU3Action op; - op.op = ActionParamFilled; - - queueFrameAction.emit(frame, op); + paramsBufferReady.emit(frame); } void IPAIPU3::parseStatistics(unsigned int frame, @@ -488,27 +476,19 @@ void IPAIPU3::parseStatistics(unsigned int frame, (sensorInfo_.pixelRate / 1e6); ctrls.set(controls::FrameDuration, frameDuration); - IPU3Action op; - op.op = ActionMetadataReady; - op.controls = ctrls; - - queueFrameAction.emit(frame, op); + metadataReady.emit(frame, ctrls); } void IPAIPU3::setControls(unsigned int frame) { - IPU3Action op; - op.op = ActionSetSensorControls; - ControlList sensorCtrls(ctrls_); sensorCtrls.set(V4L2_CID_EXPOSURE, static_cast(exposure_)); sensorCtrls.set(V4L2_CID_ANALOGUE_GAIN, static_cast(gain_)); - op.sensorControls = sensorCtrls; - - op.lensControls.set(V4L2_CID_FOCUS_ABSOLUTE, lensPosition_); + ControlList lensCtrls(ctrls_); + lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE, lensPosition_); - queueFrameAction.emit(frame, op); + setSensorControls.emit(frame, sensorCtrls, lensCtrls); } } /* namespace ipa::ipu3 */ From patchwork Thu Mar 31 16:30:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 15598 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 014B0C3256 for ; Thu, 31 Mar 2022 16:31:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 9F57765635; Thu, 31 Mar 2022 18:31:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648744292; bh=318j58jnW0FN0U3MPLLoDqOwjks2juifiTrB65Chbg4=; 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=Gd7Qt024iplmelwpp1xxTtg0feCJT8+jCQ0wUCm1csAyGcHsOCO760nfTmCKSeQKi tD/QSjdorOfFtbi81tOazT9zhejm+Pr+nXFaRa2qJZumWtQc2J2r8JvF1lQr+ZajUM ynPr+FwsIsn8+72ejT4sWPH1IG+MqKH+4qoYZeLve+TFIApVpOvj4Y4bW48SC6DYUB G4IMUgIo7Es6oImhDQ/cKU4j4RTbORvX0b4lbqduSCkhYzYWan2s1b7/fOkLrsXBgp eX00apxGPvTy0xGpXh0zhig9Zj645QIcUOIknAJmD3USgIoDzStgWQmN7zP0tngSeP GOqtk5zcZUAWw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C63BA65637 for ; Thu, 31 Mar 2022 18:31:30 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="bpGXidsU"; dkim-atps=neutral Received: from perceval.ideasonboard.com (unknown [103.74.73.150]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id EAC86486; Thu, 31 Mar 2022 18:31:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1648744290; bh=318j58jnW0FN0U3MPLLoDqOwjks2juifiTrB65Chbg4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bpGXidsUyotORzYwkkkSDSWAY/e2L2GPWphpwUyaA1K8qIkxE/4ky3fZEBo3hCVSk c+u8myERQr1/LZzO/fJd2TmcK7NE9dF94UIiVp2Bw4rTVq4C7BFxvbO2OrKu4Nq0Zv HdriUBda9w9v9OUt/DLoFh/1nehFeFJwUGm74pyM= To: libcamera-devel@lists.libcamera.org Date: Thu, 31 Mar 2022 22:00:57 +0530 Message-Id: <20220331163058.171418-6-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220331163058.171418-1-umang.jain@ideasonboard.com> References: <20220331163058.171418-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [IPAIPU3 PATCH v4 5/6] ipu3: Inlink fillParams() in fillParamsBuffer() 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" Since we have moved away from switch/case on the operation ID, there's little reason to split the operation in two functions. Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart --- ipu3.cpp | 52 +++++++++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/ipu3.cpp b/ipu3.cpp index 289cc77..a435005 100644 --- a/ipu3.cpp +++ b/ipu3.cpp @@ -61,7 +61,6 @@ private: const ControlInfoMap &sensorControls, ControlInfoMap *ipaControls); void runAiq(unsigned int frame); - void fillParams(unsigned int frame, ipu3_uapi_params *params); void parseStatistics(unsigned int frame, int64_t frameTimestamp, const ipu3_uapi_stats_3a *stats, @@ -343,7 +342,29 @@ void IPAIPU3::fillParamsBuffer(const uint32_t frame, const uint32_t bufferId) ipu3_uapi_params *params = reinterpret_cast(mem.data()); - fillParams(frame, params); + /* Prepare parameters buffer. */ + memset(params, 0, sizeof(*params)); + + /* + * Call into the AIQ object, and set up the library with any requested + * controls or settings from the incoming request. + * + * (statistics are fed into the library as a separate event + * when available) + * + * - Run algorithms + * + * - Fill params buffer with the results of the algorithms. + */ + runAiq(frame); + + aiq::AiqResults& latestResults = resultsHistory_.latest(); + aic_.updateRuntimeParams(latestResults); + aic_.run(params); + + setControls(frame); + + paramsBufferReady.emit(frame); } void IPAIPU3::processStatsBuffer(const uint32_t frame, const int64_t frameTimestamp, @@ -391,33 +412,6 @@ void IPAIPU3::runAiq([[maybe_unused]] unsigned int frame) lensPosition_ = latestResults.af()->next_lens_position; } -void IPAIPU3::fillParams(unsigned int frame, ipu3_uapi_params *params) -{ - /* Prepare parameters buffer. */ - memset(params, 0, sizeof(*params)); - - /* - * Call into the AIQ object, and set up the library with any requested - * controls or settings from the incoming request. - * - * (statistics are fed into the library as a separate event - * when available) - * - * - Run algorithms - * - * - Fill params buffer with the results of the algorithms. - */ - runAiq(frame); - - aiq::AiqResults& latestResults = resultsHistory_.latest(); - aic_.updateRuntimeParams(latestResults); - aic_.run(params); - - setControls(frame); - - paramsBufferReady.emit(frame); -} - void IPAIPU3::parseStatistics(unsigned int frame, int64_t frameTimestamp, const ipu3_uapi_stats_3a *stats, From patchwork Thu Mar 31 16:30:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 15599 X-Patchwork-Delegate: umang.jain@ideasonboard.com 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 88D96C3256 for ; Thu, 31 Mar 2022 16:31:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3C49C6563F; Thu, 31 Mar 2022 18:31:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1648744298; bh=3ccGD3IjTda+w4Gj9Sb9LbL0gb50X1i1BGLRk7TpEqg=; 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=FZwIlDVIxTGnukZPeYdyvfDJXDX9y2Fzmd5utw9GNlvzuBZMwdKDyN3Wfi9FbyzhQ nTa+W2fm0O/gI8fhgFd6DB1+GBiZWPQE9vqPvpJ0I/LF0PWwNZ+2ryfL+xZ3Q2RU2d 2JvmGYaL80tlQe1e0gt/+wiqthUOoe69fw4mc19oBxIQ/r2QjKv6RoSX5X9Q9JFpQG Pd3Rekk5WkBYvW98JPqq6UTHwCjbboRh1r+fzpJahRWFKFDm1zLZx59sZjRcWmTXF0 KR6MgfjeqyY+F4Q40RKc2+tWNmKwt5YNf5K6FN3tinxcAYR2p4H0e6rMiO/XjgdFhc 6Y8B7p7MPgN3g== 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 7927C65637 for ; Thu, 31 Mar 2022 18:31:36 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="knkiCqQd"; dkim-atps=neutral Received: from perceval.ideasonboard.com (unknown [103.74.73.150]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8AD118E6; Thu, 31 Mar 2022 18:31:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1648744296; bh=3ccGD3IjTda+w4Gj9Sb9LbL0gb50X1i1BGLRk7TpEqg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=knkiCqQdSEUWwDMty3CyNX+eRtK9f8Js0wgkZe3+PDTg+0Dfl6fkDrYh7/teJImiR ZJ+f7Mnre44BQGFQSYe9K6B1u26T0gsH6YxI/NzY7PuO3UcF2O+YWpnmuMVpK5fEBN f5UC+l9R+W8cEfWdN5i8xCblYktafrY7/KACHN1g= To: libcamera-devel@lists.libcamera.org Date: Thu, 31 Mar 2022 22:00:58 +0530 Message-Id: <20220331163058.171418-7-umang.jain@ideasonboard.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220331163058.171418-1-umang.jain@ideasonboard.com> References: <20220331163058.171418-1-umang.jain@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [IPAIPU3 PATCH v4 6/6] ipa: ipu3: Inlink parseStatistics() into processStatsBuffer() 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" Since we have moved away from switch/case on the operation ID, there's little reason to split the operation in two functions. Signed-off-by: Umang Jain Reviewed-by: Laurent Pinchart --- ipu3.cpp | 74 ++++++++++++++++++++++++-------------------------------- 1 file changed, 31 insertions(+), 43 deletions(-) diff --git a/ipu3.cpp b/ipu3.cpp index a435005..9063d7e 100644 --- a/ipu3.cpp +++ b/ipu3.cpp @@ -61,10 +61,6 @@ private: const ControlInfoMap &sensorControls, ControlInfoMap *ipaControls); void runAiq(unsigned int frame); - void parseStatistics(unsigned int frame, - int64_t frameTimestamp, - const ipu3_uapi_stats_3a *stats, - const ControlList& sensorCtrls); void setControls(unsigned int frame); @@ -380,43 +376,6 @@ void IPAIPU3::processStatsBuffer(const uint32_t frame, const int64_t frameTimest const ipu3_uapi_stats_3a *stats = reinterpret_cast(mem.data()); - parseStatistics(frame, frameTimestamp, stats, sensorControls); -} - -void IPAIPU3::runAiq([[maybe_unused]] unsigned int frame) -{ - /* Run algorithms into/using this context structure */ - resultsHistory_.extendOne(); - aiq::AiqResults& latestResults = resultsHistory_.latest(); - - /* Todo: Refactor AiqInputParameters interface to set following parameters. */ - aiqInputParams_.afParams.lens_position = lensPosition_; - aiqInputParams_.afParams.lens_movement_start_timestamp = lensMovementStartTime_; - - aiq_.run2a(frame, aiqInputParams_, latestResults); - - exposure_ = latestResults.ae()->exposures[0].sensor_exposure->coarse_integration_time; - gain_ = latestResults.ae()->exposures[0].sensor_exposure->analog_gain_code_global; - - /* - * Af algorithm compares the timestamp of start of the lens movement and - * that of the statistics generated to estimate whether next lens - * position should be produced. - * \todo use the lens movement start time reported by the pipeline handler. - */ - if (lensPosition_ != latestResults.af()->next_lens_position) { - utils::time_point time = utils::clock::now(); - uint64_t usecs = std::chrono::duration_cast(time.time_since_epoch()).count(); - lensMovementStartTime_ = usecs; - } - lensPosition_ = latestResults.af()->next_lens_position; -} - -void IPAIPU3::parseStatistics(unsigned int frame, - int64_t frameTimestamp, - const ipu3_uapi_stats_3a *stats, - const ControlList& sensorCtrls) -{ ControlList ctrls(controls::controls); /* \todo React to statistics and update internal state machine. */ @@ -439,11 +398,11 @@ void IPAIPU3::parseStatistics(unsigned int frame, int32_t effectiveGain = 0; ControlValue ctrlValue; - ctrlValue = sensorCtrls.get(V4L2_CID_EXPOSURE); + ctrlValue = sensorControls.get(V4L2_CID_EXPOSURE); if (!ctrlValue.isNone()) effectiveExpo = ctrlValue.get(); - ctrlValue = sensorCtrls.get(V4L2_CID_ANALOGUE_GAIN); + ctrlValue = sensorControls.get(V4L2_CID_ANALOGUE_GAIN); if (!ctrlValue.isNone()) effectiveGain = ctrlValue.get(); @@ -473,6 +432,35 @@ void IPAIPU3::parseStatistics(unsigned int frame, metadataReady.emit(frame, ctrls); } +void IPAIPU3::runAiq([[maybe_unused]] unsigned int frame) +{ + /* Run algorithms into/using this context structure */ + resultsHistory_.extendOne(); + aiq::AiqResults& latestResults = resultsHistory_.latest(); + + /* Todo: Refactor AiqInputParameters interface to set following parameters. */ + aiqInputParams_.afParams.lens_position = lensPosition_; + aiqInputParams_.afParams.lens_movement_start_timestamp = lensMovementStartTime_; + + aiq_.run2a(frame, aiqInputParams_, latestResults); + + exposure_ = latestResults.ae()->exposures[0].sensor_exposure->coarse_integration_time; + gain_ = latestResults.ae()->exposures[0].sensor_exposure->analog_gain_code_global; + + /* + * Af algorithm compares the timestamp of start of the lens movement and + * that of the statistics generated to estimate whether next lens + * position should be produced. + * \todo use the lens movement start time reported by the pipeline handler. + */ + if (lensPosition_ != latestResults.af()->next_lens_position) { + utils::time_point time = utils::clock::now(); + uint64_t usecs = std::chrono::duration_cast(time.time_since_epoch()).count(); + lensMovementStartTime_ = usecs; + } + lensPosition_ = latestResults.af()->next_lens_position; +} + void IPAIPU3::setControls(unsigned int frame) { ControlList sensorCtrls(ctrls_);