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

Message ID 20220613142853.98484-5-jeanmichel.hautbois@ideasonboard.com
State New
Headers show
Series
  • ipa: raspberrypi: Introduce an autofocus algorithm
Related show

Commit Message

Jean-Michel Hautbois June 13, 2022, 2:28 p.m. UTC
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>
---
 include/libcamera/ipa/raspberrypi.h |  3 ++-
 src/ipa/raspberrypi/raspberrypi.cpp | 13 +++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/include/libcamera/ipa/raspberrypi.h b/include/libcamera/ipa/raspberrypi.h
index 6a56b008..519f7160 100644
--- a/include/libcamera/ipa/raspberrypi.h
+++ b/include/libcamera/ipa/raspberrypi.h
@@ -45,7 +45,8 @@  static const ControlInfoMap Controls({
 		{ &controls::ColourCorrectionMatrix, ControlInfo(-16.0f, 16.0f) },
 		{ &controls::ScalerCrop, ControlInfo(Rectangle{}, Rectangle(65535, 65535, 65535, 65535), Rectangle{}) },
 		{ &controls::FrameDurationLimits, ControlInfo(INT64_C(1000), INT64_C(1000000000)) },
-		{ &controls::draft::NoiseReductionMode, ControlInfo(controls::draft::NoiseReductionModeValues) }
+		{ &controls::draft::NoiseReductionMode, ControlInfo(controls::draft::NoiseReductionModeValues) },
+		{ &controls::AfState, ControlInfo(controls::AfStateValues) }
 	}, controls::controls);
 
 } /* namespace RPi */
diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp
index 1e9e2e61..a4e1c834 100644
--- a/src/ipa/raspberrypi/raspberrypi.cpp
+++ b/src/ipa/raspberrypi/raspberrypi.cpp
@@ -547,6 +547,11 @@  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()
@@ -1101,6 +1106,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)