[libcamera-devel,4/6] libcamera: ipa: rkisp1: Fill in meta data about auto exposure

Message ID 20190831210220.29819-5-niklas.soderlund@ragnatech.se
State Superseded
Delegated to: Niklas Söderlund
Headers show
Series
  • libcamera: ipa: Add IPA meta data
Related show

Commit Message

Niklas Söderlund Aug. 31, 2019, 9:02 p.m. UTC
Fill in the meta data parsed from the statistics buffer and use the
metaDataReady signal to notify the pipeline handler that the data is
ready.

The method to judge if auto exposure is converged or not is just as
simple as the algorithm controlling the exposure time. If we are +/- 5%
from our target value we are converged.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 src/ipa/ipa_rkisp1.cpp | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

Patch

diff --git a/src/ipa/ipa_rkisp1.cpp b/src/ipa/ipa_rkisp1.cpp
index 063b075d8358c30d..cc926867d6fde478 100644
--- a/src/ipa/ipa_rkisp1.cpp
+++ b/src/ipa/ipa_rkisp1.cpp
@@ -6,6 +6,7 @@ 
  */
 
 #include <algorithm>
+#include <math.h>
 #include <string.h>
 
 #include <linux/rkisp1-config.h>
@@ -112,8 +113,9 @@  void IPARkISP1::updateStatistics(const void *cookie, Buffer &statistics)
 	const rkisp1_stat_buffer *stats =
 		static_cast<rkisp1_stat_buffer *>(statistics.mem()->planes()[0].mem());
 	const cifisp_stat *params = &stats->params;
+	IPAMetaData metaData = {};
 
-	if ((stats->meas_type & CIFISP_STAT_AUTOEXP) && (statFrame_ % 2 == 0)) {
+	if (stats->meas_type & CIFISP_STAT_AUTOEXP) {
 		const cifisp_ae_stat *ae = &params->ae;
 
 		const unsigned int target = 60;
@@ -129,18 +131,28 @@  void IPARkISP1::updateStatistics(const void *cookie, Buffer &statistics)
 		value /= num;
 
 		double factor = (double)target / value;
-		double tmp;
 
-		tmp = factor * exposure_ * gain_ / minGain_;
-		exposure_ = utils::clamp<uint64_t>((uint64_t)tmp, minExposure_, maxExposure_);
+		if (statFrame_ % 3 == 0) {
+			double tmp;
 
-		tmp = tmp / exposure_ * minGain_;
-		gain_ = utils::clamp<uint64_t>((uint64_t)tmp, minGain_, maxGain_);
+			tmp = factor * exposure_ * gain_ / minGain_;
+			exposure_ = utils::clamp<uint64_t>((uint64_t)tmp, minExposure_, maxExposure_);
 
-		setControls();
+			tmp = tmp / exposure_ * minGain_;
+			gain_ = utils::clamp<uint64_t>((uint64_t)tmp, minGain_, maxGain_);
+
+			setControls();
+		}
+
+		metaData.aeState = fabs(factor - 1.0f) < 0.05f ?
+			AeState::Converged : AeState::Searching;
+	} else {
+		metaData.aeState = AeState::Inactive;
 	}
 
 	statFrame_++;
+
+	metaDataReady.emit(cookie, metaData);
 }
 
 /*