[RFC,2/3] libcamera: libipa: camera_sensor: Add sensorDelays method
diff mbox series

Message ID 20241028173659.247353-3-mike.rudenko@gmail.com
State New
Headers show
Series
  • Pass sensor delays from rkisp1 IPA to the pipeline handler
Related show

Commit Message

Mikhail Rudenko Oct. 28, 2024, 5:36 p.m. UTC
Add a method to return sensor control application delays. Internally,
a protected member variable sensorDelays_ with default delays is added
to the base class CameraSensorHelper. Subsclasses for specific sensor,
where the delays are known, are supposed to override default values in
their constructors.

Also override the defaults where correct delays are known from
CamHelper or other sources.

Signed-off-by: Mikhail Rudenko <mike.rudenko@gmail.com>
---
 src/ipa/libipa/camera_sensor_helper.cpp | 59 +++++++++++++++++++++++++
 src/ipa/libipa/camera_sensor_helper.h   |  5 +++
 2 files changed, 64 insertions(+)

Patch
diff mbox series

diff --git a/src/ipa/libipa/camera_sensor_helper.cpp b/src/ipa/libipa/camera_sensor_helper.cpp
index c6169bdc..117c2f4e 100644
--- a/src/ipa/libipa/camera_sensor_helper.cpp
+++ b/src/ipa/libipa/camera_sensor_helper.cpp
@@ -140,6 +140,17 @@  double CameraSensorHelper::gain(uint32_t gainCode) const
 	}
 }
 
+/**
+ * \fn CameraSensorHelper::sensorDelays()
+ * \brief Fetch the delays for sensor subdevice controls
+ *
+ * This function returns the delays between setting a control on a
+ * sensor subdevice and it becoming effective, measured in frames. If
+ * they are unknown, default values are used.
+ *
+ * \return The delays for sensor subdevice controls
+ */
+
 /**
  * \enum CameraSensorHelper::AnalogueGainType
  * \brief The gain calculation modes as defined by the MIPI CCS
@@ -252,6 +263,12 @@  double CameraSensorHelper::gain(uint32_t gainCode) const
  * sensor specific. Use this variable to store the values at init time.
  */
 
+/**
+ * \var CameraSensorHelper::sensorDelays_
+ * \brief The delays for sensor subdevice controls
+ * \sa CameraSensorHelper::sensorDelays()
+ */
+
 /**
  * \class CameraSensorHelperFactoryBase
  * \brief Base class for camera sensor helper factories
@@ -567,6 +584,12 @@  public:
 		blackLevel_ = 3200;
 		gainType_ = AnalogueGainLinear;
 		gainConstants_.linear = { 0, 2048, -1, 2048 };
+
+		/* Taken from CamHelper. */
+		sensorDelays_.exposureDelay = 2;
+		sensorDelays_.gainDelay = 2;
+		sensorDelays_.vblankDelay = 2;
+		sensorDelays_.hblankDelay = 2;
 	}
 };
 REGISTER_CAMERA_SENSOR_HELPER("imx283", CameraSensorHelperImx283)
@@ -578,6 +601,12 @@  public:
 	{
 		gainType_ = AnalogueGainExponential;
 		gainConstants_.exp = { 1.0, expGainDb(0.3) };
+
+		/* Taken from CamHelper. */
+		sensorDelays_.exposureDelay = 2;
+		sensorDelays_.gainDelay = 2;
+		sensorDelays_.vblankDelay = 2;
+		sensorDelays_.hblankDelay = 2;
 	}
 };
 REGISTER_CAMERA_SENSOR_HELPER("imx290", CameraSensorHelperImx290)
@@ -589,6 +618,12 @@  public:
 	{
 		gainType_ = AnalogueGainExponential;
 		gainConstants_.exp = { 1.0, expGainDb(0.1) };
+
+		/* Taken from CamHelper. */
+		sensorDelays_.exposureDelay = 2;
+		sensorDelays_.gainDelay = 2;
+		sensorDelays_.vblankDelay = 2;
+		sensorDelays_.hblankDelay = 2;
 	}
 };
 REGISTER_CAMERA_SENSOR_HELPER("imx296", CameraSensorHelperImx296)
@@ -629,6 +664,12 @@  public:
 	{
 		gainType_ = AnalogueGainLinear;
 		gainConstants_.linear = { 0, 1024, -1, 1024 };
+
+		/* Taken from CamHelper. */
+		sensorDelays_.exposureDelay = 2;
+		sensorDelays_.gainDelay = 2;
+		sensorDelays_.vblankDelay = 3;
+		sensorDelays_.hblankDelay = 3;
 	}
 };
 REGISTER_CAMERA_SENSOR_HELPER("imx477", CameraSensorHelperImx477)
@@ -668,6 +709,12 @@  public:
 		blackLevel_ = 1024;
 		gainType_ = AnalogueGainLinear;
 		gainConstants_.linear = { 1, 0, 0, 128 };
+
+		/* Found by experimentation. */
+		sensorDelays_.exposureDelay = 2;
+		sensorDelays_.gainDelay = 2;
+		sensorDelays_.vblankDelay = 2;
+		sensorDelays_.hblankDelay = 2;
 	}
 };
 REGISTER_CAMERA_SENSOR_HELPER("ov4689", CameraSensorHelperOv4689)
@@ -692,6 +739,12 @@  public:
 	{
 		gainType_ = AnalogueGainLinear;
 		gainConstants_.linear = { 1, 0, 0, 16 };
+
+		/* Taken from CamHelper. */
+		sensorDelays_.exposureDelay = 2;
+		sensorDelays_.gainDelay = 2;
+		sensorDelays_.vblankDelay = 2;
+		sensorDelays_.hblankDelay = 2;
 	}
 };
 REGISTER_CAMERA_SENSOR_HELPER("ov5647", CameraSensorHelperOv5647)
@@ -738,6 +791,12 @@  public:
 	{
 		gainType_ = AnalogueGainLinear;
 		gainConstants_.linear = { 1, 0, 0, 128 };
+
+		/* Taken from CamHelper. */
+		sensorDelays_.exposureDelay = 2;
+		sensorDelays_.gainDelay = 2;
+		sensorDelays_.vblankDelay = 2;
+		sensorDelays_.hblankDelay = 2;
 	}
 };
 REGISTER_CAMERA_SENSOR_HELPER("ov64a40", CameraSensorHelperOv64a40)
diff --git a/src/ipa/libipa/camera_sensor_helper.h b/src/ipa/libipa/camera_sensor_helper.h
index 75868205..bef8380e 100644
--- a/src/ipa/libipa/camera_sensor_helper.h
+++ b/src/ipa/libipa/camera_sensor_helper.h
@@ -14,6 +14,7 @@ 
 #include <vector>
 
 #include <libcamera/base/class.h>
+#include <libcamera/ipa/core_ipa_interface.h>
 
 namespace libcamera {
 
@@ -28,6 +29,7 @@  public:
 	std::optional<int16_t> blackLevel() const { return blackLevel_; }
 	virtual uint32_t gainCode(double gain) const;
 	virtual double gain(uint32_t gainCode) const;
+	IPASensorDelays sensorDelays() const { return sensorDelays_; };
 
 protected:
 	enum AnalogueGainType {
@@ -56,6 +58,9 @@  protected:
 	AnalogueGainType gainType_;
 	AnalogueGainConstants gainConstants_;
 
+	/* Generic values taken from the Raspberry Pi. */
+	IPASensorDelays sensorDelays_{ 2, 1, 2, 2 };
+
 private:
 	LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraSensorHelper)
 };