[libcamera-devel,4/5] ipa: raspberrypi: Send the AF status back
diff mbox series

Message ID 20221201145133.479794-5-umang.jain@ideasonboard.com
State New
Headers show
Series
  • ipa: rapsberrypi: Introduce auto-focus (auto-mode)
Related show

Commit Message

Umang Jain Dec. 1, 2022, 2:51 p.m. UTC
From: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>

The user can read the status for each frame with the AfState control
value. Populate the AF status into the metadata when it is available.

Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
---
 src/ipa/raspberrypi/raspberrypi.cpp | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp
index 3d1ac8fc..19669600 100644
--- a/src/ipa/raspberrypi/raspberrypi.cpp
+++ b/src/ipa/raspberrypi/raspberrypi.cpp
@@ -91,7 +91,8 @@  static const ControlInfoMap::Map ipaControls{
 	{ &controls::ColourCorrectionMatrix, ControlInfo(-16.0f, 16.0f) },
 	{ &controls::ScalerCrop, ControlInfo(Rectangle{}, Rectangle(65535, 65535, 65535, 65535), Rectangle{}) },
 	{ &controls::FrameDurationLimits, ControlInfo(INT64_C(33333), INT64_C(120000)) },
-	{ &controls::draft::NoiseReductionMode, ControlInfo(controls::draft::NoiseReductionModeValues) }
+	{ &controls::draft::NoiseReductionMode, ControlInfo(controls::draft::NoiseReductionModeValues) },
+	{ &controls::AfState, ControlInfo(controls::AfStateValues) },
 };
 
 LOG_DEFINE_CATEGORY(IPARPI)
@@ -611,6 +612,10 @@  void IPARPi::reportMetadata()
 			m[i] = ccmStatus->matrix[i];
 		libcameraMetadata_.set(controls::ColourCorrectionMatrix, m);
 	}
+
+	AfStatus *afStatus = rpiMetadata_.getLocked<AfStatus>("af.status");
+	if (afStatus)
+		libcameraMetadata_.set(controls::AfState, afStatus->state);
 }
 
 bool IPARPi::validateSensorControls()
@@ -1170,6 +1175,14 @@  void IPARPi::processStats(unsigned int bufferId)
 
 		setDelayedControls.emit(ctrls);
 	}
+
+	struct AfStatus afStatus;
+	if (rpiMetadata_.get("af.status", afStatus) == 0) {
+		ControlList lensCtrls(lensCtrls_);
+		lensCtrls.set(V4L2_CID_FOCUS_ABSOLUTE,
+			      static_cast<int32_t>(afStatus.lensPosition));
+		setLensControls.emit(lensCtrls);
+	}
 }
 
 void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls)