[libcamera-devel,RFC,v2,4/4] ipa: raspberrypi: Control the lens position
diff mbox series

Message ID 20220323160145.90606-5-jeanmichel.hautbois@ideasonboard.com
State Superseded
Headers show
Series
  • RPi: Introduce AF algorithm
Related show

Commit Message

Jean-Michel Hautbois March 23, 2022, 4:01 p.m. UTC
Now that the ancillary links are configured, we can use the CameraLens
class and control the VCM through the IPA.
For now, force a default value for the lens position, until the AF
algorithm is introduced.

Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
---
v2: Change the need for lens control to be present
---
 src/ipa/raspberrypi/raspberrypi.cpp | 42 ++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

Comments

Kieran Bingham March 23, 2022, 11:59 p.m. UTC | #1
Quoting Jean-Michel Hautbois via libcamera-devel (2022-03-23 16:01:45)
> Now that the ancillary links are configured, we can use the CameraLens
> class and control the VCM through the IPA.
> For now, force a default value for the lens position, until the AF
> algorithm is introduced.

I think that needs updating, as there is an algorithm.

> 
> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
> ---
> v2: Change the need for lens control to be present
> ---
>  src/ipa/raspberrypi/raspberrypi.cpp | 42 ++++++++++++++++++++++++++++-
>  1 file changed, 41 insertions(+), 1 deletion(-)
> 
> diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp
> index cf4e6cab..ff302e37 100644
> --- a/src/ipa/raspberrypi/raspberrypi.cpp
> +++ b/src/ipa/raspberrypi/raspberrypi.cpp
> @@ -30,6 +30,7 @@
>  
>  #include "libcamera/internal/mapped_framebuffer.h"
>  
> +#include "af_status.h"
>  #include "agc_algorithm.hpp"
>  #include "agc_status.h"
>  #include "alsc_status.h"
> @@ -110,6 +111,7 @@ private:
>         void setMode(const IPACameraSensorInfo &sensorInfo);
>         bool validateSensorControls();
>         bool validateIspControls();
> +       bool validateLensControls();
>         void queueRequest(const ControlList &controls);
>         void returnEmbeddedBuffer(unsigned int bufferId);
>         void prepareISP(const ISPConfig &data);
> @@ -134,6 +136,7 @@ private:
>  
>         ControlInfoMap sensorCtrls_;
>         ControlInfoMap ispCtrls_;
> +       ControlInfoMap lensCtrls_;
>         ControlList libcameraMetadata_;
>  
>         /* Camera sensor params. */
> @@ -344,7 +347,7 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo,
>                       const IPAConfig &ipaConfig,
>                       ControlList *controls)
>  {
> -       if (entityControls.size() != 2) {
> +       if (entityControls.size() < 2) {
>                 LOG(IPARPI, Error) << "No ISP or sensor controls found.";
>                 return -1;
>         }
> @@ -352,6 +355,14 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo,
>         sensorCtrls_ = entityControls.at(0);
>         ispCtrls_ = entityControls.at(1);
>  
> +       /* Lens may not be present, don't make it an hard assumption. */
> +       auto lensControl = entityControls.find(2);
> +       if (lensControl != entityControls.end()) {
> +               lensCtrls_ = lensControl->second;
> +               if (!validateLensControls())
> +                       LOG(IPARPI, Error) << "Lens control validation failed.";
> +       }
> +
>         if (!validateSensorControls()) {
>                 LOG(IPARPI, Error) << "Sensor control validation failed.";
>                 return -1;
> @@ -362,6 +373,10 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo,
>                 return -1;
>         }
>  
> +       if (!validateLensControls()) {
> +               LOG(IPARPI, Error) << "Lens control validation failed.";
> +       }

Is this validating lens controls twice ? Do we need this second call?


> +
>         maxSensorGainCode_ = sensorCtrls_.at(V4L2_CID_ANALOGUE_GAIN).max().get<int32_t>();
>  
>         /* Setup a metadata ControlList to output metadata. */
> @@ -580,6 +595,23 @@ bool IPARPi::validateIspControls()
>         return true;
>  }
>  
> +bool IPARPi::validateLensControls()
> +{
> +       static const uint32_t ctrls[] = {
> +               V4L2_CID_FOCUS_ABSOLUTE,
> +       };
> +
> +       for (auto c : ctrls) {
> +               if (lensCtrls_.find(c) == lensCtrls_.end()) {
> +                       LOG(IPARPI, Error) << "Unable to find lens control "
> +                                          << utils::hex(c);
> +                       return false;
> +               }
> +       }
> +
> +       return true;
> +}
> +
>  /*
>   * Converting between enums (used in the libcamera API) and the names that
>   * we use to identify different modes. Unfortunately, the conversion tables
> @@ -1068,6 +1100,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.focus));
> +               setLensControls.emit(lensCtrls);
> +       }
>  }
>  
>  void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls)
> -- 
> 2.32.0
>
Jean-Michel Hautbois March 24, 2022, 8:21 a.m. UTC | #2
Hi Kieran,

On 24/03/2022 00:59, Kieran Bingham wrote:
> Quoting Jean-Michel Hautbois via libcamera-devel (2022-03-23 16:01:45)
>> Now that the ancillary links are configured, we can use the CameraLens
>> class and control the VCM through the IPA.
>> For now, force a default value for the lens position, until the AF
>> algorithm is introduced.
> 
> I think that needs updating, as there is an algorithm.

The last sentence is indeed not needed.

> 
>>
>> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
>> ---
>> v2: Change the need for lens control to be present
>> ---
>>   src/ipa/raspberrypi/raspberrypi.cpp | 42 ++++++++++++++++++++++++++++-
>>   1 file changed, 41 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp
>> index cf4e6cab..ff302e37 100644
>> --- a/src/ipa/raspberrypi/raspberrypi.cpp
>> +++ b/src/ipa/raspberrypi/raspberrypi.cpp
>> @@ -30,6 +30,7 @@
>>   
>>   #include "libcamera/internal/mapped_framebuffer.h"
>>   
>> +#include "af_status.h"
>>   #include "agc_algorithm.hpp"
>>   #include "agc_status.h"
>>   #include "alsc_status.h"
>> @@ -110,6 +111,7 @@ private:
>>          void setMode(const IPACameraSensorInfo &sensorInfo);
>>          bool validateSensorControls();
>>          bool validateIspControls();
>> +       bool validateLensControls();
>>          void queueRequest(const ControlList &controls);
>>          void returnEmbeddedBuffer(unsigned int bufferId);
>>          void prepareISP(const ISPConfig &data);
>> @@ -134,6 +136,7 @@ private:
>>   
>>          ControlInfoMap sensorCtrls_;
>>          ControlInfoMap ispCtrls_;
>> +       ControlInfoMap lensCtrls_;
>>          ControlList libcameraMetadata_;
>>   
>>          /* Camera sensor params. */
>> @@ -344,7 +347,7 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo,
>>                        const IPAConfig &ipaConfig,
>>                        ControlList *controls)
>>   {
>> -       if (entityControls.size() != 2) {
>> +       if (entityControls.size() < 2) {
>>                  LOG(IPARPI, Error) << "No ISP or sensor controls found.";
>>                  return -1;
>>          }
>> @@ -352,6 +355,14 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo,
>>          sensorCtrls_ = entityControls.at(0);
>>          ispCtrls_ = entityControls.at(1);
>>   
>> +       /* Lens may not be present, don't make it an hard assumption. */
>> +       auto lensControl = entityControls.find(2);
>> +       if (lensControl != entityControls.end()) {
>> +               lensCtrls_ = lensControl->second;
>> +               if (!validateLensControls())
>> +                       LOG(IPARPI, Error) << "Lens control validation failed.";
>> +       }
>> +
>>          if (!validateSensorControls()) {
>>                  LOG(IPARPI, Error) << "Sensor control validation failed.";
>>                  return -1;
>> @@ -362,6 +373,10 @@ int IPARPi::configure(const IPACameraSensorInfo &sensorInfo,
>>                  return -1;
>>          }
>>   
>> +       if (!validateLensControls()) {
>> +               LOG(IPARPI, Error) << "Lens control validation failed.";
>> +       }
> 
> Is this validating lens controls twice ? Do we need this second call?

Oh, yes, mixing two patches... now corrected, thanks !

> 
> 
>> +
>>          maxSensorGainCode_ = sensorCtrls_.at(V4L2_CID_ANALOGUE_GAIN).max().get<int32_t>();
>>   
>>          /* Setup a metadata ControlList to output metadata. */
>> @@ -580,6 +595,23 @@ bool IPARPi::validateIspControls()
>>          return true;
>>   }
>>   
>> +bool IPARPi::validateLensControls()
>> +{
>> +       static const uint32_t ctrls[] = {
>> +               V4L2_CID_FOCUS_ABSOLUTE,
>> +       };
>> +
>> +       for (auto c : ctrls) {
>> +               if (lensCtrls_.find(c) == lensCtrls_.end()) {
>> +                       LOG(IPARPI, Error) << "Unable to find lens control "
>> +                                          << utils::hex(c);
>> +                       return false;
>> +               }
>> +       }
>> +
>> +       return true;
>> +}
>> +
>>   /*
>>    * Converting between enums (used in the libcamera API) and the names that
>>    * we use to identify different modes. Unfortunately, the conversion tables
>> @@ -1068,6 +1100,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.focus));
>> +               setLensControls.emit(lensCtrls);
>> +       }
>>   }
>>   
>>   void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls)
>> -- 
>> 2.32.0
>>
Naushir Patuck March 24, 2022, 10:34 a.m. UTC | #3
Hi Jean-Michel,

Thank you for your work.

On Wed, 23 Mar 2022 at 16:01, Jean-Michel Hautbois via libcamera-devel <
libcamera-devel@lists.libcamera.org> wrote:

> Now that the ancillary links are configured, we can use the CameraLens
> class and control the VCM through the IPA.
> For now, force a default value for the lens position, until the AF
> algorithm is introduced.
>
> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
> ---
> v2: Change the need for lens control to be present
> ---
>  src/ipa/raspberrypi/raspberrypi.cpp | 42 ++++++++++++++++++++++++++++-
>  1 file changed, 41 insertions(+), 1 deletion(-)
>
> diff --git a/src/ipa/raspberrypi/raspberrypi.cpp
> b/src/ipa/raspberrypi/raspberrypi.cpp
> index cf4e6cab..ff302e37 100644
> --- a/src/ipa/raspberrypi/raspberrypi.cpp
> +++ b/src/ipa/raspberrypi/raspberrypi.cpp
> @@ -30,6 +30,7 @@
>
>  #include "libcamera/internal/mapped_framebuffer.h"
>
> +#include "af_status.h"
>  #include "agc_algorithm.hpp"
>  #include "agc_status.h"
>  #include "alsc_status.h"
> @@ -110,6 +111,7 @@ private:
>         void setMode(const IPACameraSensorInfo &sensorInfo);
>         bool validateSensorControls();
>         bool validateIspControls();
> +       bool validateLensControls();
>         void queueRequest(const ControlList &controls);
>         void returnEmbeddedBuffer(unsigned int bufferId);
>         void prepareISP(const ISPConfig &data);
> @@ -134,6 +136,7 @@ private:
>
>         ControlInfoMap sensorCtrls_;
>         ControlInfoMap ispCtrls_;
> +       ControlInfoMap lensCtrls_;
>         ControlList libcameraMetadata_;
>
>         /* Camera sensor params. */
> @@ -344,7 +347,7 @@ int IPARPi::configure(const IPACameraSensorInfo
> &sensorInfo,
>                       const IPAConfig &ipaConfig,
>                       ControlList *controls)
>  {
> -       if (entityControls.size() != 2) {
> +       if (entityControls.size() < 2) {
>                 LOG(IPARPI, Error) << "No ISP or sensor controls found.";
>                 return -1;
>         }
> @@ -352,6 +355,14 @@ int IPARPi::configure(const IPACameraSensorInfo
> &sensorInfo,
>         sensorCtrls_ = entityControls.at(0);
>         ispCtrls_ = entityControls.at(1);
>
> +       /* Lens may not be present, don't make it an hard assumption. */
> +       auto lensControl = entityControls.find(2);
> +       if (lensControl != entityControls.end()) {
> +               lensCtrls_ = lensControl->second;
> +               if (!validateLensControls())
> +                       LOG(IPARPI, Error) << "Lens control validation
> failed.";
> +       }
> +
>

I wonder if we should be fetching the lens min/max/default values somewhere
here to pass to the algorithm?


>         if (!validateSensorControls()) {
>                 LOG(IPARPI, Error) << "Sensor control validation failed.";
>                 return -1;
> @@ -362,6 +373,10 @@ int IPARPi::configure(const IPACameraSensorInfo
> &sensorInfo,
>                 return -1;
>         }
>
> +       if (!validateLensControls()) {
> +               LOG(IPARPI, Error) << "Lens control validation failed.";
> +       }
> +
>

This can be removed, the validation is done earlier.

Regards,
Naush



>         maxSensorGainCode_ =
> sensorCtrls_.at(V4L2_CID_ANALOGUE_GAIN).max().get<int32_t>();
>
>         /* Setup a metadata ControlList to output metadata. */
> @@ -580,6 +595,23 @@ bool IPARPi::validateIspControls()
>         return true;
>  }
>
> +bool IPARPi::validateLensControls()
> +{
> +       static const uint32_t ctrls[] = {
> +               V4L2_CID_FOCUS_ABSOLUTE,
> +       };
> +
> +       for (auto c : ctrls) {
> +               if (lensCtrls_.find(c) == lensCtrls_.end()) {
> +                       LOG(IPARPI, Error) << "Unable to find lens control
> "
> +                                          << utils::hex(c);
> +                       return false;
> +               }
> +       }
> +
> +       return true;
> +}
> +
>  /*
>   * Converting between enums (used in the libcamera API) and the names that
>   * we use to identify different modes. Unfortunately, the conversion
> tables
> @@ -1068,6 +1100,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.focus));
> +               setLensControls.emit(lensCtrls);
> +       }
>  }
>
>  void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList
> &ctrls)
> --
> 2.32.0
>
>

Patch
diff mbox series

diff --git a/src/ipa/raspberrypi/raspberrypi.cpp b/src/ipa/raspberrypi/raspberrypi.cpp
index cf4e6cab..ff302e37 100644
--- a/src/ipa/raspberrypi/raspberrypi.cpp
+++ b/src/ipa/raspberrypi/raspberrypi.cpp
@@ -30,6 +30,7 @@ 
 
 #include "libcamera/internal/mapped_framebuffer.h"
 
+#include "af_status.h"
 #include "agc_algorithm.hpp"
 #include "agc_status.h"
 #include "alsc_status.h"
@@ -110,6 +111,7 @@  private:
 	void setMode(const IPACameraSensorInfo &sensorInfo);
 	bool validateSensorControls();
 	bool validateIspControls();
+	bool validateLensControls();
 	void queueRequest(const ControlList &controls);
 	void returnEmbeddedBuffer(unsigned int bufferId);
 	void prepareISP(const ISPConfig &data);
@@ -134,6 +136,7 @@  private:
 
 	ControlInfoMap sensorCtrls_;
 	ControlInfoMap ispCtrls_;
+	ControlInfoMap lensCtrls_;
 	ControlList libcameraMetadata_;
 
 	/* Camera sensor params. */
@@ -344,7 +347,7 @@  int IPARPi::configure(const IPACameraSensorInfo &sensorInfo,
 		      const IPAConfig &ipaConfig,
 		      ControlList *controls)
 {
-	if (entityControls.size() != 2) {
+	if (entityControls.size() < 2) {
 		LOG(IPARPI, Error) << "No ISP or sensor controls found.";
 		return -1;
 	}
@@ -352,6 +355,14 @@  int IPARPi::configure(const IPACameraSensorInfo &sensorInfo,
 	sensorCtrls_ = entityControls.at(0);
 	ispCtrls_ = entityControls.at(1);
 
+	/* Lens may not be present, don't make it an hard assumption. */
+	auto lensControl = entityControls.find(2);
+	if (lensControl != entityControls.end()) {
+		lensCtrls_ = lensControl->second;
+		if (!validateLensControls())
+			LOG(IPARPI, Error) << "Lens control validation failed.";
+	}
+
 	if (!validateSensorControls()) {
 		LOG(IPARPI, Error) << "Sensor control validation failed.";
 		return -1;
@@ -362,6 +373,10 @@  int IPARPi::configure(const IPACameraSensorInfo &sensorInfo,
 		return -1;
 	}
 
+	if (!validateLensControls()) {
+		LOG(IPARPI, Error) << "Lens control validation failed.";
+	}
+
 	maxSensorGainCode_ = sensorCtrls_.at(V4L2_CID_ANALOGUE_GAIN).max().get<int32_t>();
 
 	/* Setup a metadata ControlList to output metadata. */
@@ -580,6 +595,23 @@  bool IPARPi::validateIspControls()
 	return true;
 }
 
+bool IPARPi::validateLensControls()
+{
+	static const uint32_t ctrls[] = {
+		V4L2_CID_FOCUS_ABSOLUTE,
+	};
+
+	for (auto c : ctrls) {
+		if (lensCtrls_.find(c) == lensCtrls_.end()) {
+			LOG(IPARPI, Error) << "Unable to find lens control "
+					   << utils::hex(c);
+			return false;
+		}
+	}
+
+	return true;
+}
+
 /*
  * Converting between enums (used in the libcamera API) and the names that
  * we use to identify different modes. Unfortunately, the conversion tables
@@ -1068,6 +1100,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.focus));
+		setLensControls.emit(lensCtrls);
+	}
 }
 
 void IPARPi::applyAWB(const struct AwbStatus *awbStatus, ControlList &ctrls)