[libcamera-devel,v2,1/4] ipa: raspberrypi: Add sensor mode limits to CameraMode
diff mbox series

Message ID 20230327093439.24670-2-naush@raspberrypi.com
State Accepted
Headers show
Series
  • Raspberry Pi: Sensor limits
Related show

Commit Message

Naushir Patuck March 27, 2023, 9:34 a.m. UTC
Add fields in the CameraMode structure to capture the mode specific
limits for analogue gain and shutter speed. For convenience, also add
fields for minimum and maximum frame durations.

Populate these new fields when setting up the CameraMode structure.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
---
 src/ipa/raspberrypi/controller/camera_mode.h | 10 +++++++++-
 src/ipa/raspberrypi/raspberrypi.cpp          | 16 ++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

Comments

David Plowman March 27, 2023, 1:18 p.m. UTC | #1
Hi Naush

Thanks for the patch.

On Mon, 27 Mar 2023 at 10:34, Naushir Patuck via libcamera-devel
<libcamera-devel@lists.libcamera.org> wrote:
>
> Add fields in the CameraMode structure to capture the mode specific
> limits for analogue gain and shutter speed. For convenience, also add
> fields for minimum and maximum frame durations.
>
> Populate these new fields when setting up the CameraMode structure.
>
> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>

Reviewed-by: David Plowman <david.plowman@raspberrypi.com>

Thanks!
David

> ---
>  src/ipa/raspberrypi/controller/camera_mode.h | 10 +++++++++-
>  src/ipa/raspberrypi/raspberrypi.cpp          | 16 ++++++++++++++++
>  2 files changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/src/ipa/raspberrypi/controller/camera_mode.h b/src/ipa/raspberrypi/controller/camera_mode.h
> index 94c51ddf1686..63b1177852d0 100644
> --- a/src/ipa/raspberrypi/controller/camera_mode.h
> +++ b/src/ipa/raspberrypi/controller/camera_mode.h
> @@ -36,9 +36,11 @@ struct CameraMode {
>         double scaleY;
>         /* scaling of the noise compared to the native sensor mode */
>         double noiseFactor;
> -       /* minimum and maximum line time */
> +       /* minimum and maximum line time and frame durations */
>         libcamera::utils::Duration minLineLength;
>         libcamera::utils::Duration maxLineLength;
> +       libcamera::utils::Duration minFrameDuration;
> +       libcamera::utils::Duration maxFrameDuration;
>         /* any camera transform *not* reflected already in the camera tuning */
>         libcamera::Transform transform;
>         /* minimum and maximum frame lengths in units of lines */
> @@ -48,4 +50,10 @@ struct CameraMode {
>         double sensitivity;
>         /* pixel clock rate */
>         uint64_t pixelRate;
> +       /* Mode specific shutter speed limits */
> +       libcamera::utils::Duration minShutter;
> +       libcamera::utils::Duration maxShutter;
> +       /* Mode specific analogue gain limits */
> +       double minAnalogueGain;
> +       double maxAnalogueGain;
>  };
> diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp
> index 1375795568e2..3f1afb846420 100644
> --- a/src/ipa/raspberrypi/raspberrypi.cpp
> +++ b/src/ipa/raspberrypi/raspberrypi.cpp
> @@ -407,11 +407,27 @@ void IPARPi::setMode(const IPACameraSensorInfo &sensorInfo)
>         mode_.minFrameLength = sensorInfo.minFrameLength;
>         mode_.maxFrameLength = sensorInfo.maxFrameLength;
>
> +       /* Store these for convenience. */
> +       mode_.minFrameDuration = mode_.minFrameLength * mode_.minLineLength;
> +       mode_.maxFrameDuration = mode_.maxFrameLength * mode_.maxLineLength;
> +
>         /*
>          * Some sensors may have different sensitivities in different modes;
>          * the CamHelper will know the correct value.
>          */
>         mode_.sensitivity = helper_->getModeSensitivity(mode_);
> +
> +       const ControlInfo &gainCtrl = sensorCtrls_.at(V4L2_CID_ANALOGUE_GAIN);
> +       const ControlInfo &shutterCtrl = sensorCtrls_.at(V4L2_CID_EXPOSURE);
> +
> +       mode_.minAnalogueGain = helper_->gain(gainCtrl.min().get<int32_t>());
> +       mode_.maxAnalogueGain = helper_->gain(gainCtrl.max().get<int32_t>());
> +
> +       /* Shutter speed is calculated based on the limits of the frame durations. */
> +       mode_.minShutter = helper_->exposure(shutterCtrl.min().get<int32_t>(), mode_.minLineLength);
> +       mode_.maxShutter = Duration::max();
> +       helper_->getBlanking(mode_.maxShutter,
> +                            mode_.minFrameDuration, mode_.maxFrameDuration);
>  }
>
>  int IPARPi::configure(const IPACameraSensorInfo &sensorInfo, const IPAConfig &ipaConfig,
> --
> 2.34.1
>
Jacopo Mondi March 27, 2023, 1:49 p.m. UTC | #2
Hi Naush

On Mon, Mar 27, 2023 at 10:34:36AM +0100, Naushir Patuck via libcamera-devel wrote:
> Add fields in the CameraMode structure to capture the mode specific
> limits for analogue gain and shutter speed. For convenience, also add
> fields for minimum and maximum frame durations.
>
> Populate these new fields when setting up the CameraMode structure.
>
> Signed-off-by: Naushir Patuck <naush@raspberrypi.com>

Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>

Thanks
  j
> ---
>  src/ipa/raspberrypi/controller/camera_mode.h | 10 +++++++++-
>  src/ipa/raspberrypi/raspberrypi.cpp          | 16 ++++++++++++++++
>  2 files changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/src/ipa/raspberrypi/controller/camera_mode.h b/src/ipa/raspberrypi/controller/camera_mode.h
> index 94c51ddf1686..63b1177852d0 100644
> --- a/src/ipa/raspberrypi/controller/camera_mode.h
> +++ b/src/ipa/raspberrypi/controller/camera_mode.h
> @@ -36,9 +36,11 @@ struct CameraMode {
>  	double scaleY;
>  	/* scaling of the noise compared to the native sensor mode */
>  	double noiseFactor;
> -	/* minimum and maximum line time */
> +	/* minimum and maximum line time and frame durations */
>  	libcamera::utils::Duration minLineLength;
>  	libcamera::utils::Duration maxLineLength;
> +	libcamera::utils::Duration minFrameDuration;
> +	libcamera::utils::Duration maxFrameDuration;
>  	/* any camera transform *not* reflected already in the camera tuning */
>  	libcamera::Transform transform;
>  	/* minimum and maximum frame lengths in units of lines */
> @@ -48,4 +50,10 @@ struct CameraMode {
>  	double sensitivity;
>  	/* pixel clock rate */
>  	uint64_t pixelRate;
> +	/* Mode specific shutter speed limits */
> +	libcamera::utils::Duration minShutter;
> +	libcamera::utils::Duration maxShutter;
> +	/* Mode specific analogue gain limits */
> +	double minAnalogueGain;
> +	double maxAnalogueGain;
>  };
> diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp
> index 1375795568e2..3f1afb846420 100644
> --- a/src/ipa/raspberrypi/raspberrypi.cpp
> +++ b/src/ipa/raspberrypi/raspberrypi.cpp
> @@ -407,11 +407,27 @@ void IPARPi::setMode(const IPACameraSensorInfo &sensorInfo)
>  	mode_.minFrameLength = sensorInfo.minFrameLength;
>  	mode_.maxFrameLength = sensorInfo.maxFrameLength;
>
> +	/* Store these for convenience. */
> +	mode_.minFrameDuration = mode_.minFrameLength * mode_.minLineLength;
> +	mode_.maxFrameDuration = mode_.maxFrameLength * mode_.maxLineLength;
> +
>  	/*
>  	 * Some sensors may have different sensitivities in different modes;
>  	 * the CamHelper will know the correct value.
>  	 */
>  	mode_.sensitivity = helper_->getModeSensitivity(mode_);
> +
> +	const ControlInfo &gainCtrl = sensorCtrls_.at(V4L2_CID_ANALOGUE_GAIN);
> +	const ControlInfo &shutterCtrl = sensorCtrls_.at(V4L2_CID_EXPOSURE);
> +
> +	mode_.minAnalogueGain = helper_->gain(gainCtrl.min().get<int32_t>());
> +	mode_.maxAnalogueGain = helper_->gain(gainCtrl.max().get<int32_t>());
> +
> +	/* Shutter speed is calculated based on the limits of the frame durations. */
> +	mode_.minShutter = helper_->exposure(shutterCtrl.min().get<int32_t>(), mode_.minLineLength);
> +	mode_.maxShutter = Duration::max();
> +	helper_->getBlanking(mode_.maxShutter,
> +			     mode_.minFrameDuration, mode_.maxFrameDuration);
>  }
>
>  int IPARPi::configure(const IPACameraSensorInfo &sensorInfo, const IPAConfig &ipaConfig,
> --
> 2.34.1
>

Patch
diff mbox series

diff --git a/src/ipa/raspberrypi/controller/camera_mode.h b/src/ipa/raspberrypi/controller/camera_mode.h
index 94c51ddf1686..63b1177852d0 100644
--- a/src/ipa/raspberrypi/controller/camera_mode.h
+++ b/src/ipa/raspberrypi/controller/camera_mode.h
@@ -36,9 +36,11 @@  struct CameraMode {
 	double scaleY;
 	/* scaling of the noise compared to the native sensor mode */
 	double noiseFactor;
-	/* minimum and maximum line time */
+	/* minimum and maximum line time and frame durations */
 	libcamera::utils::Duration minLineLength;
 	libcamera::utils::Duration maxLineLength;
+	libcamera::utils::Duration minFrameDuration;
+	libcamera::utils::Duration maxFrameDuration;
 	/* any camera transform *not* reflected already in the camera tuning */
 	libcamera::Transform transform;
 	/* minimum and maximum frame lengths in units of lines */
@@ -48,4 +50,10 @@  struct CameraMode {
 	double sensitivity;
 	/* pixel clock rate */
 	uint64_t pixelRate;
+	/* Mode specific shutter speed limits */
+	libcamera::utils::Duration minShutter;
+	libcamera::utils::Duration maxShutter;
+	/* Mode specific analogue gain limits */
+	double minAnalogueGain;
+	double maxAnalogueGain;
 };
diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp
index 1375795568e2..3f1afb846420 100644
--- a/src/ipa/raspberrypi/raspberrypi.cpp
+++ b/src/ipa/raspberrypi/raspberrypi.cpp
@@ -407,11 +407,27 @@  void IPARPi::setMode(const IPACameraSensorInfo &sensorInfo)
 	mode_.minFrameLength = sensorInfo.minFrameLength;
 	mode_.maxFrameLength = sensorInfo.maxFrameLength;
 
+	/* Store these for convenience. */
+	mode_.minFrameDuration = mode_.minFrameLength * mode_.minLineLength;
+	mode_.maxFrameDuration = mode_.maxFrameLength * mode_.maxLineLength;
+
 	/*
 	 * Some sensors may have different sensitivities in different modes;
 	 * the CamHelper will know the correct value.
 	 */
 	mode_.sensitivity = helper_->getModeSensitivity(mode_);
+
+	const ControlInfo &gainCtrl = sensorCtrls_.at(V4L2_CID_ANALOGUE_GAIN);
+	const ControlInfo &shutterCtrl = sensorCtrls_.at(V4L2_CID_EXPOSURE);
+
+	mode_.minAnalogueGain = helper_->gain(gainCtrl.min().get<int32_t>());
+	mode_.maxAnalogueGain = helper_->gain(gainCtrl.max().get<int32_t>());
+
+	/* Shutter speed is calculated based on the limits of the frame durations. */
+	mode_.minShutter = helper_->exposure(shutterCtrl.min().get<int32_t>(), mode_.minLineLength);
+	mode_.maxShutter = Duration::max();
+	helper_->getBlanking(mode_.maxShutter,
+			     mode_.minFrameDuration, mode_.maxFrameDuration);
 }
 
 int IPARPi::configure(const IPACameraSensorInfo &sensorInfo, const IPAConfig &ipaConfig,