[libcamera-devel,v4,12/14] ipa: ipu3: Cache line duration at configure call
diff mbox series

Message ID 20211111140928.136111-13-jeanmichel.hautbois@ideasonboard.com
State Accepted
Headers show
Series
  • IPA: IPU3: Introduce per-frame controls
Related show

Commit Message

Jean-Michel Hautbois Nov. 11, 2021, 2:09 p.m. UTC
We use the line duration several times in the IPAIPU3. Instead of
recalculating it each time, cache the value as a utils::Duration. When
the value is needed, cast it to a std::micro value.

As sensorInfo is no longer used in updateSessionConfiguration remove the
reference to it.

Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 src/ipa/ipu3/ipu3.cpp | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)

Comments

Umang Jain Nov. 12, 2021, 12:36 p.m. UTC | #1
Hi JM,

On 11/11/21 7:39 PM, Jean-Michel Hautbois wrote:
> We use the line duration several times in the IPAIPU3. Instead of
> recalculating it each time, cache the value as a utils::Duration. When
> the value is needed, cast it to a std::micro value.
>
> As sensorInfo is no longer used in updateSessionConfiguration remove the
> reference to it.
>
> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>


Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>

> ---
>   src/ipa/ipu3/ipu3.cpp | 29 +++++++++++++----------------
>   1 file changed, 13 insertions(+), 16 deletions(-)
>
> diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp
> index d3195de6..f1597f78 100644
> --- a/src/ipa/ipu3/ipu3.cpp
> +++ b/src/ipa/ipu3/ipu3.cpp
> @@ -148,8 +148,7 @@ private:
>   	void updateControls(const IPACameraSensorInfo &sensorInfo,
>   			    const ControlInfoMap &sensorControls,
>   			    ControlInfoMap *ipaControls);
> -	void updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,
> -					const ControlInfoMap &sensorControls);
> +	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,
> @@ -174,6 +173,8 @@ private:
>   	uint32_t minGain_;
>   	uint32_t maxGain_;
>   
> +	utils::Duration lineDuration_;
> +
>   	/* Interface to the Camera Helper */
>   	std::unique_ptr<CameraSensorHelper> camHelper_;
>   
> @@ -188,16 +189,12 @@ private:
>    * \brief Compute IPASessionConfiguration using the sensor information and the
>    * sensor V4L2 controls
>    */
> -void IPAIPU3::updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,
> -					 const ControlInfoMap &sensorControls)
> +void IPAIPU3::updateSessionConfiguration(const ControlInfoMap &sensorControls)
>   {
>   	const ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;
>   	int32_t minExposure = v4l2Exposure.min().get<int32_t>();
>   	int32_t maxExposure = v4l2Exposure.max().get<int32_t>();
>   
> -	utils::Duration lineDuration = sensorInfo.lineLength * 1.0s
> -				     / sensorInfo.pixelRate;
> -
>   	const ControlInfo &v4l2Gain = sensorControls.find(V4L2_CID_ANALOGUE_GAIN)->second;
>   	int32_t minGain = v4l2Gain.min().get<int32_t>();
>   	int32_t maxGain = v4l2Gain.max().get<int32_t>();
> @@ -209,8 +206,8 @@ void IPAIPU3::updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,
>   	 *
>   	 * \todo take VBLANK into account for maximum shutter speed
>   	 */
> -	context_.configuration.agc.minShutterSpeed = minExposure * lineDuration;
> -	context_.configuration.agc.maxShutterSpeed = maxExposure * lineDuration;
> +	context_.configuration.agc.minShutterSpeed = minExposure * lineDuration_;
> +	context_.configuration.agc.maxShutterSpeed = maxExposure * lineDuration_;
>   	context_.configuration.agc.minAnalogueGain = camHelper_->gain(minGain);
>   	context_.configuration.agc.maxAnalogueGain = camHelper_->gain(maxGain);
>   }
> @@ -239,11 +236,10 @@ void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo,
>   	 * exposure min, max and default and convert it from lines to
>   	 * microseconds.
>   	 */
> -	double lineDuration = sensorInfo.lineLength / (sensorInfo.pixelRate / 1e6);
>   	const ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;
> -	int32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration;
> -	int32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration;
> -	int32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration;
> +	int32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration_.get<std::micro>();
> +	int32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration_.get<std::micro>();
> +	int32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration_.get<std::micro>();
>   	controls[&controls::ExposureTime] = ControlInfo(minExposure, maxExposure,
>   							defExposure);
>   
> @@ -463,11 +459,13 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo,
>   
>   	calculateBdsGrid(configInfo.bdsOutputSize);
>   
> +	lineDuration_ = sensorInfo_.lineLength * 1.0s / sensorInfo_.pixelRate;
> +
>   	/* Update the camera controls using the new sensor settings. */
>   	updateControls(sensorInfo_, ctrls_, ipaControls);
>   
>   	/* Update the IPASessionConfiguration using the sensor settings. */
> -	updateSessionConfiguration(sensorInfo_, ctrls_);
> +	updateSessionConfiguration(ctrls_);
>   
>   	for (auto const &algo : algorithms_) {
>   		int ret = algo->configure(context_, configInfo);
> @@ -627,8 +625,7 @@ void IPAIPU3::parseStatistics(unsigned int frame,
>   	setControls(frame);
>   
>   	/* \todo Use VBlank value calculated from each frame exposure. */
> -	int64_t frameDuration = sensorInfo_.lineLength * (defVBlank_ + sensorInfo_.outputSize.height) /
> -				(sensorInfo_.pixelRate / 1e6);
> +	int64_t frameDuration = (defVBlank_ + sensorInfo_.outputSize.height) * lineDuration_.get<std::micro>();
>   	ctrls.set(controls::FrameDuration, frameDuration);
>   
>   	ctrls.set(controls::ColourTemperature, context_.frameContext.awb.temperatureK);
Kieran Bingham Nov. 12, 2021, 1:21 p.m. UTC | #2
Quoting Umang Jain (2021-11-12 12:36:21)
> Hi JM,
> 
> On 11/11/21 7:39 PM, Jean-Michel Hautbois wrote:
> > We use the line duration several times in the IPAIPU3. Instead of
> > recalculating it each time, cache the value as a utils::Duration. When
> > the value is needed, cast it to a std::micro value.

Aren't values always 'needed' when they're obtained? This isn't quite
helping improve the clarity.

Why is it needed in micros, vs other usages?


> >
> > As sensorInfo is no longer used in updateSessionConfiguration remove the
> > reference to it.
> >
> > Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
> > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> 
> 
> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
> 
> > ---
> >   src/ipa/ipu3/ipu3.cpp | 29 +++++++++++++----------------
> >   1 file changed, 13 insertions(+), 16 deletions(-)
> >
> > diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp
> > index d3195de6..f1597f78 100644
> > --- a/src/ipa/ipu3/ipu3.cpp
> > +++ b/src/ipa/ipu3/ipu3.cpp
> > @@ -148,8 +148,7 @@ private:
> >       void updateControls(const IPACameraSensorInfo &sensorInfo,
> >                           const ControlInfoMap &sensorControls,
> >                           ControlInfoMap *ipaControls);
> > -     void updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,
> > -                                     const ControlInfoMap &sensorControls);
> > +     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,
> > @@ -174,6 +173,8 @@ private:
> >       uint32_t minGain_;
> >       uint32_t maxGain_;
> >   
> > +     utils::Duration lineDuration_;
> > +
> >       /* Interface to the Camera Helper */
> >       std::unique_ptr<CameraSensorHelper> camHelper_;
> >   
> > @@ -188,16 +189,12 @@ private:
> >    * \brief Compute IPASessionConfiguration using the sensor information and the
> >    * sensor V4L2 controls
> >    */
> > -void IPAIPU3::updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,
> > -                                      const ControlInfoMap &sensorControls)
> > +void IPAIPU3::updateSessionConfiguration(const ControlInfoMap &sensorControls)
> >   {
> >       const ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;
> >       int32_t minExposure = v4l2Exposure.min().get<int32_t>();
> >       int32_t maxExposure = v4l2Exposure.max().get<int32_t>();
> >   
> > -     utils::Duration lineDuration = sensorInfo.lineLength * 1.0s
> > -                                  / sensorInfo.pixelRate;
> > -
> >       const ControlInfo &v4l2Gain = sensorControls.find(V4L2_CID_ANALOGUE_GAIN)->second;
> >       int32_t minGain = v4l2Gain.min().get<int32_t>();
> >       int32_t maxGain = v4l2Gain.max().get<int32_t>();
> > @@ -209,8 +206,8 @@ void IPAIPU3::updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,
> >        *
> >        * \todo take VBLANK into account for maximum shutter speed
> >        */
> > -     context_.configuration.agc.minShutterSpeed = minExposure * lineDuration;
> > -     context_.configuration.agc.maxShutterSpeed = maxExposure * lineDuration;
> > +     context_.configuration.agc.minShutterSpeed = minExposure * lineDuration_;
> > +     context_.configuration.agc.maxShutterSpeed = maxExposure * lineDuration_;
> >       context_.configuration.agc.minAnalogueGain = camHelper_->gain(minGain);
> >       context_.configuration.agc.maxAnalogueGain = camHelper_->gain(maxGain);
> >   }
> > @@ -239,11 +236,10 @@ void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo,
> >        * exposure min, max and default and convert it from lines to
> >        * microseconds.
> >        */
> > -     double lineDuration = sensorInfo.lineLength / (sensorInfo.pixelRate / 1e6);
> >       const ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;
> > -     int32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration;
> > -     int32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration;
> > -     int32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration;
> > +     int32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration_.get<std::micro>();
> > +     int32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration_.get<std::micro>();
> > +     int32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration_.get<std::micro>();
> >       controls[&controls::ExposureTime] = ControlInfo(minExposure, maxExposure,
> >                                                       defExposure);
> >   
> > @@ -463,11 +459,13 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo,
> >   
> >       calculateBdsGrid(configInfo.bdsOutputSize);
> >   
> > +     lineDuration_ = sensorInfo_.lineLength * 1.0s / sensorInfo_.pixelRate;
> > +
> >       /* Update the camera controls using the new sensor settings. */
> >       updateControls(sensorInfo_, ctrls_, ipaControls);
> >   
> >       /* Update the IPASessionConfiguration using the sensor settings. */
> > -     updateSessionConfiguration(sensorInfo_, ctrls_);
> > +     updateSessionConfiguration(ctrls_);
> >   
> >       for (auto const &algo : algorithms_) {
> >               int ret = algo->configure(context_, configInfo);
> > @@ -627,8 +625,7 @@ void IPAIPU3::parseStatistics(unsigned int frame,
> >       setControls(frame);
> >   
> >       /* \todo Use VBlank value calculated from each frame exposure. */
> > -     int64_t frameDuration = sensorInfo_.lineLength * (defVBlank_ + sensorInfo_.outputSize.height) /
> > -                             (sensorInfo_.pixelRate / 1e6);
> > +     int64_t frameDuration = (defVBlank_ + sensorInfo_.outputSize.height) * lineDuration_.get<std::micro>();
> >       ctrls.set(controls::FrameDuration, frameDuration);
> >   
> >       ctrls.set(controls::ColourTemperature, context_.frameContext.awb.temperatureK);
Jean-Michel Hautbois Nov. 12, 2021, 4:03 p.m. UTC | #3
Hi Kieran,

On 12/11/2021 14:21, Kieran Bingham wrote:
> Quoting Umang Jain (2021-11-12 12:36:21)
>> Hi JM,
>>
>> On 11/11/21 7:39 PM, Jean-Michel Hautbois wrote:
>>> We use the line duration several times in the IPAIPU3. Instead of
>>> recalculating it each time, cache the value as a utils::Duration. When
>>> the value is needed, cast it to a std::micro value.
> 
> Aren't values always 'needed' when they're obtained? This isn't quite
> helping improve the clarity.
> 
> Why is it needed in micros, vs other usages?

OK, I may have to specify it is documented in 
src/libcamera/control_ids.yaml ?

'''
- ExposureTime:
     type: int32_t
     description: |
Exposure time (shutter speed) for the frame applied in the sensor 
device. This value is specified in micro-seconds.
'''

How can I reference this file in the commit message ?
> 
> 
>>>
>>> As sensorInfo is no longer used in updateSessionConfiguration remove the
>>> reference to it.
>>>
>>> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
>>> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>>
>>
>> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
>>
>>> ---
>>>    src/ipa/ipu3/ipu3.cpp | 29 +++++++++++++----------------
>>>    1 file changed, 13 insertions(+), 16 deletions(-)
>>>
>>> diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp
>>> index d3195de6..f1597f78 100644
>>> --- a/src/ipa/ipu3/ipu3.cpp
>>> +++ b/src/ipa/ipu3/ipu3.cpp
>>> @@ -148,8 +148,7 @@ private:
>>>        void updateControls(const IPACameraSensorInfo &sensorInfo,
>>>                            const ControlInfoMap &sensorControls,
>>>                            ControlInfoMap *ipaControls);
>>> -     void updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,
>>> -                                     const ControlInfoMap &sensorControls);
>>> +     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,
>>> @@ -174,6 +173,8 @@ private:
>>>        uint32_t minGain_;
>>>        uint32_t maxGain_;
>>>    
>>> +     utils::Duration lineDuration_;
>>> +
>>>        /* Interface to the Camera Helper */
>>>        std::unique_ptr<CameraSensorHelper> camHelper_;
>>>    
>>> @@ -188,16 +189,12 @@ private:
>>>     * \brief Compute IPASessionConfiguration using the sensor information and the
>>>     * sensor V4L2 controls
>>>     */
>>> -void IPAIPU3::updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,
>>> -                                      const ControlInfoMap &sensorControls)
>>> +void IPAIPU3::updateSessionConfiguration(const ControlInfoMap &sensorControls)
>>>    {
>>>        const ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;
>>>        int32_t minExposure = v4l2Exposure.min().get<int32_t>();
>>>        int32_t maxExposure = v4l2Exposure.max().get<int32_t>();
>>>    
>>> -     utils::Duration lineDuration = sensorInfo.lineLength * 1.0s
>>> -                                  / sensorInfo.pixelRate;
>>> -
>>>        const ControlInfo &v4l2Gain = sensorControls.find(V4L2_CID_ANALOGUE_GAIN)->second;
>>>        int32_t minGain = v4l2Gain.min().get<int32_t>();
>>>        int32_t maxGain = v4l2Gain.max().get<int32_t>();
>>> @@ -209,8 +206,8 @@ void IPAIPU3::updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,
>>>         *
>>>         * \todo take VBLANK into account for maximum shutter speed
>>>         */
>>> -     context_.configuration.agc.minShutterSpeed = minExposure * lineDuration;
>>> -     context_.configuration.agc.maxShutterSpeed = maxExposure * lineDuration;
>>> +     context_.configuration.agc.minShutterSpeed = minExposure * lineDuration_;
>>> +     context_.configuration.agc.maxShutterSpeed = maxExposure * lineDuration_;
>>>        context_.configuration.agc.minAnalogueGain = camHelper_->gain(minGain);
>>>        context_.configuration.agc.maxAnalogueGain = camHelper_->gain(maxGain);
>>>    }
>>> @@ -239,11 +236,10 @@ void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo,
>>>         * exposure min, max and default and convert it from lines to
>>>         * microseconds.
>>>         */
>>> -     double lineDuration = sensorInfo.lineLength / (sensorInfo.pixelRate / 1e6);
>>>        const ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;
>>> -     int32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration;
>>> -     int32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration;
>>> -     int32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration;
>>> +     int32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration_.get<std::micro>();
>>> +     int32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration_.get<std::micro>();
>>> +     int32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration_.get<std::micro>();
>>>        controls[&controls::ExposureTime] = ControlInfo(minExposure, maxExposure,
>>>                                                        defExposure);
>>>    
>>> @@ -463,11 +459,13 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo,
>>>    
>>>        calculateBdsGrid(configInfo.bdsOutputSize);
>>>    
>>> +     lineDuration_ = sensorInfo_.lineLength * 1.0s / sensorInfo_.pixelRate;
>>> +
>>>        /* Update the camera controls using the new sensor settings. */
>>>        updateControls(sensorInfo_, ctrls_, ipaControls);
>>>    
>>>        /* Update the IPASessionConfiguration using the sensor settings. */
>>> -     updateSessionConfiguration(sensorInfo_, ctrls_);
>>> +     updateSessionConfiguration(ctrls_);
>>>    
>>>        for (auto const &algo : algorithms_) {
>>>                int ret = algo->configure(context_, configInfo);
>>> @@ -627,8 +625,7 @@ void IPAIPU3::parseStatistics(unsigned int frame,
>>>        setControls(frame);
>>>    
>>>        /* \todo Use VBlank value calculated from each frame exposure. */
>>> -     int64_t frameDuration = sensorInfo_.lineLength * (defVBlank_ + sensorInfo_.outputSize.height) /
>>> -                             (sensorInfo_.pixelRate / 1e6);
>>> +     int64_t frameDuration = (defVBlank_ + sensorInfo_.outputSize.height) * lineDuration_.get<std::micro>();
>>>        ctrls.set(controls::FrameDuration, frameDuration);
>>>    
>>>        ctrls.set(controls::ColourTemperature, context_.frameContext.awb.temperatureK);
Kieran Bingham Nov. 12, 2021, 4:19 p.m. UTC | #4
Quoting Jean-Michel Hautbois (2021-11-12 16:03:53)
> Hi Kieran,
> 
> On 12/11/2021 14:21, Kieran Bingham wrote:
> > Quoting Umang Jain (2021-11-12 12:36:21)
> >> Hi JM,
> >>
> >> On 11/11/21 7:39 PM, Jean-Michel Hautbois wrote:
> >>> We use the line duration several times in the IPAIPU3. Instead of
> >>> recalculating it each time, cache the value as a utils::Duration. When
> >>> the value is needed, cast it to a std::micro value.
> > 
> > Aren't values always 'needed' when they're obtained? This isn't quite
> > helping improve the clarity.
> > 
> > Why is it needed in micros, vs other usages?
> 
> OK, I may have to specify it is documented in 
> src/libcamera/control_ids.yaml ?
> 
> '''
> - ExposureTime:
>      type: int32_t
>      description: |
> Exposure time (shutter speed) for the frame applied in the sensor 
> device. This value is specified in micro-seconds.
> '''
> 
> How can I reference this file in the commit message ?

I don't think you need to reference the file, just the fact that
ExposureTime and FrameDuration units are in micro-seconds, and so the
Duration is cast accordingly.



> >>> As sensorInfo is no longer used in updateSessionConfiguration remove the
> >>> reference to it.
> >>>
> >>> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
> >>> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> >>
> >>
> >> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
> >>
> >>> ---
> >>>    src/ipa/ipu3/ipu3.cpp | 29 +++++++++++++----------------
> >>>    1 file changed, 13 insertions(+), 16 deletions(-)
> >>>
> >>> diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp
> >>> index d3195de6..f1597f78 100644
> >>> --- a/src/ipa/ipu3/ipu3.cpp
> >>> +++ b/src/ipa/ipu3/ipu3.cpp
> >>> @@ -148,8 +148,7 @@ private:
> >>>        void updateControls(const IPACameraSensorInfo &sensorInfo,
> >>>                            const ControlInfoMap &sensorControls,
> >>>                            ControlInfoMap *ipaControls);
> >>> -     void updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,
> >>> -                                     const ControlInfoMap &sensorControls);
> >>> +     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,
> >>> @@ -174,6 +173,8 @@ private:
> >>>        uint32_t minGain_;
> >>>        uint32_t maxGain_;
> >>>    
> >>> +     utils::Duration lineDuration_;
> >>> +
> >>>        /* Interface to the Camera Helper */
> >>>        std::unique_ptr<CameraSensorHelper> camHelper_;
> >>>    
> >>> @@ -188,16 +189,12 @@ private:
> >>>     * \brief Compute IPASessionConfiguration using the sensor information and the
> >>>     * sensor V4L2 controls
> >>>     */
> >>> -void IPAIPU3::updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,
> >>> -                                      const ControlInfoMap &sensorControls)
> >>> +void IPAIPU3::updateSessionConfiguration(const ControlInfoMap &sensorControls)
> >>>    {
> >>>        const ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;
> >>>        int32_t minExposure = v4l2Exposure.min().get<int32_t>();
> >>>        int32_t maxExposure = v4l2Exposure.max().get<int32_t>();
> >>>    
> >>> -     utils::Duration lineDuration = sensorInfo.lineLength * 1.0s
> >>> -                                  / sensorInfo.pixelRate;
> >>> -
> >>>        const ControlInfo &v4l2Gain = sensorControls.find(V4L2_CID_ANALOGUE_GAIN)->second;
> >>>        int32_t minGain = v4l2Gain.min().get<int32_t>();
> >>>        int32_t maxGain = v4l2Gain.max().get<int32_t>();
> >>> @@ -209,8 +206,8 @@ void IPAIPU3::updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,
> >>>         *
> >>>         * \todo take VBLANK into account for maximum shutter speed
> >>>         */
> >>> -     context_.configuration.agc.minShutterSpeed = minExposure * lineDuration;
> >>> -     context_.configuration.agc.maxShutterSpeed = maxExposure * lineDuration;
> >>> +     context_.configuration.agc.minShutterSpeed = minExposure * lineDuration_;
> >>> +     context_.configuration.agc.maxShutterSpeed = maxExposure * lineDuration_;
> >>>        context_.configuration.agc.minAnalogueGain = camHelper_->gain(minGain);
> >>>        context_.configuration.agc.maxAnalogueGain = camHelper_->gain(maxGain);
> >>>    }
> >>> @@ -239,11 +236,10 @@ void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo,
> >>>         * exposure min, max and default and convert it from lines to
> >>>         * microseconds.
> >>>         */
> >>> -     double lineDuration = sensorInfo.lineLength / (sensorInfo.pixelRate / 1e6);
> >>>        const ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;
> >>> -     int32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration;
> >>> -     int32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration;
> >>> -     int32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration;
> >>> +     int32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration_.get<std::micro>();
> >>> +     int32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration_.get<std::micro>();
> >>> +     int32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration_.get<std::micro>();
> >>>        controls[&controls::ExposureTime] = ControlInfo(minExposure, maxExposure,
> >>>                                                        defExposure);
> >>>    
> >>> @@ -463,11 +459,13 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo,
> >>>    
> >>>        calculateBdsGrid(configInfo.bdsOutputSize);
> >>>    
> >>> +     lineDuration_ = sensorInfo_.lineLength * 1.0s / sensorInfo_.pixelRate;
> >>> +
> >>>        /* Update the camera controls using the new sensor settings. */
> >>>        updateControls(sensorInfo_, ctrls_, ipaControls);
> >>>    
> >>>        /* Update the IPASessionConfiguration using the sensor settings. */
> >>> -     updateSessionConfiguration(sensorInfo_, ctrls_);
> >>> +     updateSessionConfiguration(ctrls_);
> >>>    
> >>>        for (auto const &algo : algorithms_) {
> >>>                int ret = algo->configure(context_, configInfo);
> >>> @@ -627,8 +625,7 @@ void IPAIPU3::parseStatistics(unsigned int frame,
> >>>        setControls(frame);
> >>>    
> >>>        /* \todo Use VBlank value calculated from each frame exposure. */
> >>> -     int64_t frameDuration = sensorInfo_.lineLength * (defVBlank_ + sensorInfo_.outputSize.height) /
> >>> -                             (sensorInfo_.pixelRate / 1e6);
> >>> +     int64_t frameDuration = (defVBlank_ + sensorInfo_.outputSize.height) * lineDuration_.get<std::micro>();
> >>>        ctrls.set(controls::FrameDuration, frameDuration);
> >>>    
> >>>        ctrls.set(controls::ColourTemperature, context_.frameContext.awb.temperatureK);
Jean-Michel Hautbois Nov. 12, 2021, 4:44 p.m. UTC | #5
On 12/11/2021 17:19, Kieran Bingham wrote:
> Quoting Jean-Michel Hautbois (2021-11-12 16:03:53)
>> Hi Kieran,
>>
>> On 12/11/2021 14:21, Kieran Bingham wrote:
>>> Quoting Umang Jain (2021-11-12 12:36:21)
>>>> Hi JM,
>>>>
>>>> On 11/11/21 7:39 PM, Jean-Michel Hautbois wrote:
>>>>> We use the line duration several times in the IPAIPU3. Instead of
>>>>> recalculating it each time, cache the value as a utils::Duration. When
>>>>> the value is needed, cast it to a std::micro value.
>>>
>>> Aren't values always 'needed' when they're obtained? This isn't quite
>>> helping improve the clarity.
>>>
>>> Why is it needed in micros, vs other usages?
>>
>> OK, I may have to specify it is documented in
>> src/libcamera/control_ids.yaml ?
>>
>> '''
>> - ExposureTime:
>>       type: int32_t
>>       description: |
>> Exposure time (shutter speed) for the frame applied in the sensor
>> device. This value is specified in micro-seconds.
>> '''
>>
>> How can I reference this file in the commit message ?
> 
> I don't think you need to reference the file, just the fact that
> ExposureTime and FrameDuration units are in micro-seconds, and so the
> Duration is cast accordingly.

Thanks,

'''
We use the line duration several times in the IPAIPU3. Instead of
recalculating it each time, cache the value as a utils::Duration.
ExposureTime and FrameDuration units are in micro-seconds, cast the
Duration accordingly.

As sensorInfo is no longer used in updateSessionConfiguration remove the
reference to it.
'''

> 
> 
> 
>>>>> As sensorInfo is no longer used in updateSessionConfiguration remove the
>>>>> reference to it.
>>>>>
>>>>> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
>>>>> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
>>>>
>>>>
>>>> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
>>>>
>>>>> ---
>>>>>     src/ipa/ipu3/ipu3.cpp | 29 +++++++++++++----------------
>>>>>     1 file changed, 13 insertions(+), 16 deletions(-)
>>>>>
>>>>> diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp
>>>>> index d3195de6..f1597f78 100644
>>>>> --- a/src/ipa/ipu3/ipu3.cpp
>>>>> +++ b/src/ipa/ipu3/ipu3.cpp
>>>>> @@ -148,8 +148,7 @@ private:
>>>>>         void updateControls(const IPACameraSensorInfo &sensorInfo,
>>>>>                             const ControlInfoMap &sensorControls,
>>>>>                             ControlInfoMap *ipaControls);
>>>>> -     void updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,
>>>>> -                                     const ControlInfoMap &sensorControls);
>>>>> +     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,
>>>>> @@ -174,6 +173,8 @@ private:
>>>>>         uint32_t minGain_;
>>>>>         uint32_t maxGain_;
>>>>>     
>>>>> +     utils::Duration lineDuration_;
>>>>> +
>>>>>         /* Interface to the Camera Helper */
>>>>>         std::unique_ptr<CameraSensorHelper> camHelper_;
>>>>>     
>>>>> @@ -188,16 +189,12 @@ private:
>>>>>      * \brief Compute IPASessionConfiguration using the sensor information and the
>>>>>      * sensor V4L2 controls
>>>>>      */
>>>>> -void IPAIPU3::updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,
>>>>> -                                      const ControlInfoMap &sensorControls)
>>>>> +void IPAIPU3::updateSessionConfiguration(const ControlInfoMap &sensorControls)
>>>>>     {
>>>>>         const ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;
>>>>>         int32_t minExposure = v4l2Exposure.min().get<int32_t>();
>>>>>         int32_t maxExposure = v4l2Exposure.max().get<int32_t>();
>>>>>     
>>>>> -     utils::Duration lineDuration = sensorInfo.lineLength * 1.0s
>>>>> -                                  / sensorInfo.pixelRate;
>>>>> -
>>>>>         const ControlInfo &v4l2Gain = sensorControls.find(V4L2_CID_ANALOGUE_GAIN)->second;
>>>>>         int32_t minGain = v4l2Gain.min().get<int32_t>();
>>>>>         int32_t maxGain = v4l2Gain.max().get<int32_t>();
>>>>> @@ -209,8 +206,8 @@ void IPAIPU3::updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,
>>>>>          *
>>>>>          * \todo take VBLANK into account for maximum shutter speed
>>>>>          */
>>>>> -     context_.configuration.agc.minShutterSpeed = minExposure * lineDuration;
>>>>> -     context_.configuration.agc.maxShutterSpeed = maxExposure * lineDuration;
>>>>> +     context_.configuration.agc.minShutterSpeed = minExposure * lineDuration_;
>>>>> +     context_.configuration.agc.maxShutterSpeed = maxExposure * lineDuration_;
>>>>>         context_.configuration.agc.minAnalogueGain = camHelper_->gain(minGain);
>>>>>         context_.configuration.agc.maxAnalogueGain = camHelper_->gain(maxGain);
>>>>>     }
>>>>> @@ -239,11 +236,10 @@ void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo,
>>>>>          * exposure min, max and default and convert it from lines to
>>>>>          * microseconds.
>>>>>          */
>>>>> -     double lineDuration = sensorInfo.lineLength / (sensorInfo.pixelRate / 1e6);
>>>>>         const ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;
>>>>> -     int32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration;
>>>>> -     int32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration;
>>>>> -     int32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration;
>>>>> +     int32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration_.get<std::micro>();
>>>>> +     int32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration_.get<std::micro>();
>>>>> +     int32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration_.get<std::micro>();
>>>>>         controls[&controls::ExposureTime] = ControlInfo(minExposure, maxExposure,
>>>>>                                                         defExposure);
>>>>>     
>>>>> @@ -463,11 +459,13 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo,
>>>>>     
>>>>>         calculateBdsGrid(configInfo.bdsOutputSize);
>>>>>     
>>>>> +     lineDuration_ = sensorInfo_.lineLength * 1.0s / sensorInfo_.pixelRate;
>>>>> +
>>>>>         /* Update the camera controls using the new sensor settings. */
>>>>>         updateControls(sensorInfo_, ctrls_, ipaControls);
>>>>>     
>>>>>         /* Update the IPASessionConfiguration using the sensor settings. */
>>>>> -     updateSessionConfiguration(sensorInfo_, ctrls_);
>>>>> +     updateSessionConfiguration(ctrls_);
>>>>>     
>>>>>         for (auto const &algo : algorithms_) {
>>>>>                 int ret = algo->configure(context_, configInfo);
>>>>> @@ -627,8 +625,7 @@ void IPAIPU3::parseStatistics(unsigned int frame,
>>>>>         setControls(frame);
>>>>>     
>>>>>         /* \todo Use VBlank value calculated from each frame exposure. */
>>>>> -     int64_t frameDuration = sensorInfo_.lineLength * (defVBlank_ + sensorInfo_.outputSize.height) /
>>>>> -                             (sensorInfo_.pixelRate / 1e6);
>>>>> +     int64_t frameDuration = (defVBlank_ + sensorInfo_.outputSize.height) * lineDuration_.get<std::micro>();
>>>>>         ctrls.set(controls::FrameDuration, frameDuration);
>>>>>     
>>>>>         ctrls.set(controls::ColourTemperature, context_.frameContext.awb.temperatureK);
Kieran Bingham Nov. 12, 2021, 5:34 p.m. UTC | #6
Quoting Jean-Michel Hautbois (2021-11-12 16:44:08)
> 
> 
> On 12/11/2021 17:19, Kieran Bingham wrote:
> > Quoting Jean-Michel Hautbois (2021-11-12 16:03:53)
> >> Hi Kieran,
> >>
> >> On 12/11/2021 14:21, Kieran Bingham wrote:
> >>> Quoting Umang Jain (2021-11-12 12:36:21)
> >>>> Hi JM,
> >>>>
> >>>> On 11/11/21 7:39 PM, Jean-Michel Hautbois wrote:
> >>>>> We use the line duration several times in the IPAIPU3. Instead of
> >>>>> recalculating it each time, cache the value as a utils::Duration. When
> >>>>> the value is needed, cast it to a std::micro value.
> >>>
> >>> Aren't values always 'needed' when they're obtained? This isn't quite
> >>> helping improve the clarity.
> >>>
> >>> Why is it needed in micros, vs other usages?
> >>
> >> OK, I may have to specify it is documented in
> >> src/libcamera/control_ids.yaml ?
> >>
> >> '''
> >> - ExposureTime:
> >>       type: int32_t
> >>       description: |
> >> Exposure time (shutter speed) for the frame applied in the sensor
> >> device. This value is specified in micro-seconds.
> >> '''
> >>
> >> How can I reference this file in the commit message ?
> > 
> > I don't think you need to reference the file, just the fact that
> > ExposureTime and FrameDuration units are in micro-seconds, and so the
> > Duration is cast accordingly.
> 
> Thanks,
> 
> '''
> We use the line duration several times in the IPAIPU3. Instead of
> recalculating it each time, cache the value as a utils::Duration.
> ExposureTime and FrameDuration units are in micro-seconds, cast the
> Duration accordingly.
> 
> As sensorInfo is no longer used in updateSessionConfiguration remove the
> reference to it.
> '''

Works for me!

Thanks,
Kieran
Paul Elder Nov. 12, 2021, 11:22 p.m. UTC | #7
Hi Jean-Michel,

On Thu, Nov 11, 2021 at 03:09:26PM +0100, Jean-Michel Hautbois wrote:
> We use the line duration several times in the IPAIPU3. Instead of
> recalculating it each time, cache the value as a utils::Duration. When
> the value is needed, cast it to a std::micro value.
> 
> As sensorInfo is no longer used in updateSessionConfiguration remove the
> reference to it.
> 
> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  src/ipa/ipu3/ipu3.cpp | 29 +++++++++++++----------------
>  1 file changed, 13 insertions(+), 16 deletions(-)
> 
> diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp
> index d3195de6..f1597f78 100644
> --- a/src/ipa/ipu3/ipu3.cpp
> +++ b/src/ipa/ipu3/ipu3.cpp
> @@ -148,8 +148,7 @@ private:
>  	void updateControls(const IPACameraSensorInfo &sensorInfo,
>  			    const ControlInfoMap &sensorControls,
>  			    ControlInfoMap *ipaControls);
> -	void updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,
> -					const ControlInfoMap &sensorControls);
> +	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,
> @@ -174,6 +173,8 @@ private:
>  	uint32_t minGain_;
>  	uint32_t maxGain_;
>  
> +	utils::Duration lineDuration_;
> +
>  	/* Interface to the Camera Helper */
>  	std::unique_ptr<CameraSensorHelper> camHelper_;
>  
> @@ -188,16 +189,12 @@ private:
>   * \brief Compute IPASessionConfiguration using the sensor information and the
>   * sensor V4L2 controls
>   */
> -void IPAIPU3::updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,
> -					 const ControlInfoMap &sensorControls)
> +void IPAIPU3::updateSessionConfiguration(const ControlInfoMap &sensorControls)
>  {
>  	const ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;
>  	int32_t minExposure = v4l2Exposure.min().get<int32_t>();
>  	int32_t maxExposure = v4l2Exposure.max().get<int32_t>();
>  
> -	utils::Duration lineDuration = sensorInfo.lineLength * 1.0s
> -				     / sensorInfo.pixelRate;
> -
>  	const ControlInfo &v4l2Gain = sensorControls.find(V4L2_CID_ANALOGUE_GAIN)->second;
>  	int32_t minGain = v4l2Gain.min().get<int32_t>();
>  	int32_t maxGain = v4l2Gain.max().get<int32_t>();
> @@ -209,8 +206,8 @@ void IPAIPU3::updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,
>  	 *
>  	 * \todo take VBLANK into account for maximum shutter speed
>  	 */
> -	context_.configuration.agc.minShutterSpeed = minExposure * lineDuration;
> -	context_.configuration.agc.maxShutterSpeed = maxExposure * lineDuration;
> +	context_.configuration.agc.minShutterSpeed = minExposure * lineDuration_;
> +	context_.configuration.agc.maxShutterSpeed = maxExposure * lineDuration_;
>  	context_.configuration.agc.minAnalogueGain = camHelper_->gain(minGain);
>  	context_.configuration.agc.maxAnalogueGain = camHelper_->gain(maxGain);
>  }
> @@ -239,11 +236,10 @@ void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo,
>  	 * exposure min, max and default and convert it from lines to
>  	 * microseconds.
>  	 */
> -	double lineDuration = sensorInfo.lineLength / (sensorInfo.pixelRate / 1e6);
>  	const ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;
> -	int32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration;
> -	int32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration;
> -	int32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration;
> +	int32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration_.get<std::micro>();
> +	int32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration_.get<std::micro>();
> +	int32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration_.get<std::micro>();
>  	controls[&controls::ExposureTime] = ControlInfo(minExposure, maxExposure,
>  							defExposure);
>  
> @@ -463,11 +459,13 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo,
>  
>  	calculateBdsGrid(configInfo.bdsOutputSize);
>  
> +	lineDuration_ = sensorInfo_.lineLength * 1.0s / sensorInfo_.pixelRate;
> +
>  	/* Update the camera controls using the new sensor settings. */
>  	updateControls(sensorInfo_, ctrls_, ipaControls);
>  
>  	/* Update the IPASessionConfiguration using the sensor settings. */
> -	updateSessionConfiguration(sensorInfo_, ctrls_);
> +	updateSessionConfiguration(ctrls_);
>  
>  	for (auto const &algo : algorithms_) {
>  		int ret = algo->configure(context_, configInfo);
> @@ -627,8 +625,7 @@ void IPAIPU3::parseStatistics(unsigned int frame,
>  	setControls(frame);
>  
>  	/* \todo Use VBlank value calculated from each frame exposure. */
> -	int64_t frameDuration = sensorInfo_.lineLength * (defVBlank_ + sensorInfo_.outputSize.height) /
> -				(sensorInfo_.pixelRate / 1e6);
> +	int64_t frameDuration = (defVBlank_ + sensorInfo_.outputSize.height) * lineDuration_.get<std::micro>();
>  	ctrls.set(controls::FrameDuration, frameDuration);
>  
>  	ctrls.set(controls::ColourTemperature, context_.frameContext.awb.temperatureK);
> -- 
> 2.32.0
>

Patch
diff mbox series

diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp
index d3195de6..f1597f78 100644
--- a/src/ipa/ipu3/ipu3.cpp
+++ b/src/ipa/ipu3/ipu3.cpp
@@ -148,8 +148,7 @@  private:
 	void updateControls(const IPACameraSensorInfo &sensorInfo,
 			    const ControlInfoMap &sensorControls,
 			    ControlInfoMap *ipaControls);
-	void updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,
-					const ControlInfoMap &sensorControls);
+	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,
@@ -174,6 +173,8 @@  private:
 	uint32_t minGain_;
 	uint32_t maxGain_;
 
+	utils::Duration lineDuration_;
+
 	/* Interface to the Camera Helper */
 	std::unique_ptr<CameraSensorHelper> camHelper_;
 
@@ -188,16 +189,12 @@  private:
  * \brief Compute IPASessionConfiguration using the sensor information and the
  * sensor V4L2 controls
  */
-void IPAIPU3::updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,
-					 const ControlInfoMap &sensorControls)
+void IPAIPU3::updateSessionConfiguration(const ControlInfoMap &sensorControls)
 {
 	const ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;
 	int32_t minExposure = v4l2Exposure.min().get<int32_t>();
 	int32_t maxExposure = v4l2Exposure.max().get<int32_t>();
 
-	utils::Duration lineDuration = sensorInfo.lineLength * 1.0s
-				     / sensorInfo.pixelRate;
-
 	const ControlInfo &v4l2Gain = sensorControls.find(V4L2_CID_ANALOGUE_GAIN)->second;
 	int32_t minGain = v4l2Gain.min().get<int32_t>();
 	int32_t maxGain = v4l2Gain.max().get<int32_t>();
@@ -209,8 +206,8 @@  void IPAIPU3::updateSessionConfiguration(const IPACameraSensorInfo &sensorInfo,
 	 *
 	 * \todo take VBLANK into account for maximum shutter speed
 	 */
-	context_.configuration.agc.minShutterSpeed = minExposure * lineDuration;
-	context_.configuration.agc.maxShutterSpeed = maxExposure * lineDuration;
+	context_.configuration.agc.minShutterSpeed = minExposure * lineDuration_;
+	context_.configuration.agc.maxShutterSpeed = maxExposure * lineDuration_;
 	context_.configuration.agc.minAnalogueGain = camHelper_->gain(minGain);
 	context_.configuration.agc.maxAnalogueGain = camHelper_->gain(maxGain);
 }
@@ -239,11 +236,10 @@  void IPAIPU3::updateControls(const IPACameraSensorInfo &sensorInfo,
 	 * exposure min, max and default and convert it from lines to
 	 * microseconds.
 	 */
-	double lineDuration = sensorInfo.lineLength / (sensorInfo.pixelRate / 1e6);
 	const ControlInfo &v4l2Exposure = sensorControls.find(V4L2_CID_EXPOSURE)->second;
-	int32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration;
-	int32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration;
-	int32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration;
+	int32_t minExposure = v4l2Exposure.min().get<int32_t>() * lineDuration_.get<std::micro>();
+	int32_t maxExposure = v4l2Exposure.max().get<int32_t>() * lineDuration_.get<std::micro>();
+	int32_t defExposure = v4l2Exposure.def().get<int32_t>() * lineDuration_.get<std::micro>();
 	controls[&controls::ExposureTime] = ControlInfo(minExposure, maxExposure,
 							defExposure);
 
@@ -463,11 +459,13 @@  int IPAIPU3::configure(const IPAConfigInfo &configInfo,
 
 	calculateBdsGrid(configInfo.bdsOutputSize);
 
+	lineDuration_ = sensorInfo_.lineLength * 1.0s / sensorInfo_.pixelRate;
+
 	/* Update the camera controls using the new sensor settings. */
 	updateControls(sensorInfo_, ctrls_, ipaControls);
 
 	/* Update the IPASessionConfiguration using the sensor settings. */
-	updateSessionConfiguration(sensorInfo_, ctrls_);
+	updateSessionConfiguration(ctrls_);
 
 	for (auto const &algo : algorithms_) {
 		int ret = algo->configure(context_, configInfo);
@@ -627,8 +625,7 @@  void IPAIPU3::parseStatistics(unsigned int frame,
 	setControls(frame);
 
 	/* \todo Use VBlank value calculated from each frame exposure. */
-	int64_t frameDuration = sensorInfo_.lineLength * (defVBlank_ + sensorInfo_.outputSize.height) /
-				(sensorInfo_.pixelRate / 1e6);
+	int64_t frameDuration = (defVBlank_ + sensorInfo_.outputSize.height) * lineDuration_.get<std::micro>();
 	ctrls.set(controls::FrameDuration, frameDuration);
 
 	ctrls.set(controls::ColourTemperature, context_.frameContext.awb.temperatureK);