[libcamera-devel,RFC,3/4] libcamera: lens: Add a helper to get the fixed range lens values
diff mbox series

Message ID 20220609060306.57953-4-jeanmichel.hautbois@ideasonboard.com
State New
Headers show
Series
  • Introduce camera lens properties
Related show

Commit Message

Jean-Michel Hautbois June 9, 2022, 6:03 a.m. UTC
When the focus algorithm runs, it can be asked to go to a specific
position, through the controls::LensPosition control. Those controls
need specific values to be known, in particular the minimum and maximum
value the driver can set to the lens to make it move to a given
position.

Add a new helper on the camera lens side to get this range or a default
nulled structure if it is not available. This particular value needs to
be taken into account by the caller and it shall use the minimum and
maximum reported by the driver.

Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
---
 include/libcamera/internal/camera_lens.h      |  1 +
 .../internal/camera_lens_properties.h         |  2 ++
 src/libcamera/camera_lens.cpp                 | 19 +++++++++++++++++++
 src/libcamera/camera_lens_properties.cpp      |  9 ++++++++-
 4 files changed, 30 insertions(+), 1 deletion(-)

Comments

Laurent Pinchart June 9, 2022, 9:34 a.m. UTC | #1
On Thu, Jun 09, 2022 at 08:03:05AM +0200, Jean-Michel Hautbois via libcamera-devel wrote:
> When the focus algorithm runs, it can be asked to go to a specific
> position, through the controls::LensPosition control. Those controls
> need specific values to be known, in particular the minimum and maximum
> value the driver can set to the lens to make it move to a given
> position.
> 
> Add a new helper on the camera lens side to get this range or a default
> nulled structure if it is not available. This particular value needs to
> be taken into account by the caller and it shall use the minimum and
> maximum reported by the driver.
> 
> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
> ---
>  include/libcamera/internal/camera_lens.h      |  1 +
>  .../internal/camera_lens_properties.h         |  2 ++
>  src/libcamera/camera_lens.cpp                 | 19 +++++++++++++++++++
>  src/libcamera/camera_lens_properties.cpp      |  9 ++++++++-
>  4 files changed, 30 insertions(+), 1 deletion(-)
> 
> diff --git a/include/libcamera/internal/camera_lens.h b/include/libcamera/internal/camera_lens.h
> index 523a1481..f6daff01 100644
> --- a/include/libcamera/internal/camera_lens.h
> +++ b/include/libcamera/internal/camera_lens.h
> @@ -29,6 +29,7 @@ public:
>  
>  	int init();
>  	int setFocusPosition(int32_t position);
> +	const Size &getLensRange();
>  
>  	const std::string &model() const { return model_; }
>  
> diff --git a/include/libcamera/internal/camera_lens_properties.h b/include/libcamera/internal/camera_lens_properties.h
> index 73982550..7424b375 100644
> --- a/include/libcamera/internal/camera_lens_properties.h
> +++ b/include/libcamera/internal/camera_lens_properties.h
> @@ -17,6 +17,8 @@ namespace libcamera {
>  
>  struct CameraLensProperties {
>  	static const CameraLensProperties *get(const std::string &lens);
> +
> +	Size lensFocusRange;
>  };
>  
>  } /* namespace libcamera */
> diff --git a/src/libcamera/camera_lens.cpp b/src/libcamera/camera_lens.cpp
> index d4d44bc7..abec5a27 100644
> --- a/src/libcamera/camera_lens.cpp
> +++ b/src/libcamera/camera_lens.cpp
> @@ -79,6 +79,25 @@ int CameraLens::init()
>  	return 0;
>  }
>  
> +/**
> + * \brief Retrieve the lens position range
> + * \return The minimum and maximum positions for the given lens or a default
> + * nulled Size reference
> + *
> + * If a lens has no static properties associated, a special value is returned,
> + * where the minimum and maximum are set to 0. The caller may then chose the
> + * ones returned by the V4L2_CID_FOCUS_ABSOLUTE call.
> + */
> +const Size &CameraLens::getLensRange()
> +{
> +	static const Size defaultLensFocusRange = { 0, 0 };
> +	if (!staticProps_ || staticProps_->lensFocusRange.isNull())
> +		return defaultLensFocusRange;
> +
> +	return staticProps_->lensFocusRange;
> +}
> +
> +
>  /**
>   * \brief This function sets the focal point of the lens to a specific position.
>   * \param[in] position The focal point of the lens
> diff --git a/src/libcamera/camera_lens_properties.cpp b/src/libcamera/camera_lens_properties.cpp
> index dee73b43..225546ae 100644
> --- a/src/libcamera/camera_lens_properties.cpp
> +++ b/src/libcamera/camera_lens_properties.cpp
> @@ -32,6 +32,9 @@ LOG_DEFINE_CATEGORY(CameraLensProperties)
>  /**
>   * \struct CameraLensProperties
>   * \brief Database of camera lens properties
> + *
> + * \var CameraLensProperties::lensFocusRange
> + * \brief The limits for the sensor position, stored as a min and a max.
>   */
>  
>  /**
> @@ -42,7 +45,11 @@ LOG_DEFINE_CATEGORY(CameraLensProperties)
>   */
>  const CameraLensProperties *CameraLensProperties::get(const std::string &lens)
>  {
> -	static const std::map<std::string, const CameraLensProperties> lensProps = {};
> +	static const std::map<std::string, const CameraLensProperties> lensProps = {
> +		{ "dw9714", {
> +				.lensFocusRange = { 150, 800 },
> +		} },
> +	};

This partly answers the question I asked in a reply to the cover letter.

What makes you think the lens focus range is an intrinsic property of
the VCM driver ?

>  
>  	const auto it = lensProps.find(lens);
>  	if (it == lensProps.end()) {
Jean-Michel Hautbois June 9, 2022, 9:40 a.m. UTC | #2
Hi Laurent,

On 09/06/2022 11:34, Laurent Pinchart wrote:
> On Thu, Jun 09, 2022 at 08:03:05AM +0200, Jean-Michel Hautbois via libcamera-devel wrote:
>> When the focus algorithm runs, it can be asked to go to a specific
>> position, through the controls::LensPosition control. Those controls
>> need specific values to be known, in particular the minimum and maximum
>> value the driver can set to the lens to make it move to a given
>> position.
>>
>> Add a new helper on the camera lens side to get this range or a default
>> nulled structure if it is not available. This particular value needs to
>> be taken into account by the caller and it shall use the minimum and
>> maximum reported by the driver.
>>
>> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
>> ---
>>   include/libcamera/internal/camera_lens.h      |  1 +
>>   .../internal/camera_lens_properties.h         |  2 ++
>>   src/libcamera/camera_lens.cpp                 | 19 +++++++++++++++++++
>>   src/libcamera/camera_lens_properties.cpp      |  9 ++++++++-
>>   4 files changed, 30 insertions(+), 1 deletion(-)
>>
>> diff --git a/include/libcamera/internal/camera_lens.h b/include/libcamera/internal/camera_lens.h
>> index 523a1481..f6daff01 100644
>> --- a/include/libcamera/internal/camera_lens.h
>> +++ b/include/libcamera/internal/camera_lens.h
>> @@ -29,6 +29,7 @@ public:
>>   
>>   	int init();
>>   	int setFocusPosition(int32_t position);
>> +	const Size &getLensRange();
>>   
>>   	const std::string &model() const { return model_; }
>>   
>> diff --git a/include/libcamera/internal/camera_lens_properties.h b/include/libcamera/internal/camera_lens_properties.h
>> index 73982550..7424b375 100644
>> --- a/include/libcamera/internal/camera_lens_properties.h
>> +++ b/include/libcamera/internal/camera_lens_properties.h
>> @@ -17,6 +17,8 @@ namespace libcamera {
>>   
>>   struct CameraLensProperties {
>>   	static const CameraLensProperties *get(const std::string &lens);
>> +
>> +	Size lensFocusRange;
>>   };
>>   
>>   } /* namespace libcamera */
>> diff --git a/src/libcamera/camera_lens.cpp b/src/libcamera/camera_lens.cpp
>> index d4d44bc7..abec5a27 100644
>> --- a/src/libcamera/camera_lens.cpp
>> +++ b/src/libcamera/camera_lens.cpp
>> @@ -79,6 +79,25 @@ int CameraLens::init()
>>   	return 0;
>>   }
>>   
>> +/**
>> + * \brief Retrieve the lens position range
>> + * \return The minimum and maximum positions for the given lens or a default
>> + * nulled Size reference
>> + *
>> + * If a lens has no static properties associated, a special value is returned,
>> + * where the minimum and maximum are set to 0. The caller may then chose the
>> + * ones returned by the V4L2_CID_FOCUS_ABSOLUTE call.
>> + */
>> +const Size &CameraLens::getLensRange()
>> +{
>> +	static const Size defaultLensFocusRange = { 0, 0 };
>> +	if (!staticProps_ || staticProps_->lensFocusRange.isNull())
>> +		return defaultLensFocusRange;
>> +
>> +	return staticProps_->lensFocusRange;
>> +}
>> +
>> +
>>   /**
>>    * \brief This function sets the focal point of the lens to a specific position.
>>    * \param[in] position The focal point of the lens
>> diff --git a/src/libcamera/camera_lens_properties.cpp b/src/libcamera/camera_lens_properties.cpp
>> index dee73b43..225546ae 100644
>> --- a/src/libcamera/camera_lens_properties.cpp
>> +++ b/src/libcamera/camera_lens_properties.cpp
>> @@ -32,6 +32,9 @@ LOG_DEFINE_CATEGORY(CameraLensProperties)
>>   /**
>>    * \struct CameraLensProperties
>>    * \brief Database of camera lens properties
>> + *
>> + * \var CameraLensProperties::lensFocusRange
>> + * \brief The limits for the sensor position, stored as a min and a max.
>>    */
>>   
>>   /**
>> @@ -42,7 +45,11 @@ LOG_DEFINE_CATEGORY(CameraLensProperties)
>>    */
>>   const CameraLensProperties *CameraLensProperties::get(const std::string &lens)
>>   {
>> -	static const std::map<std::string, const CameraLensProperties> lensProps = {};
>> +	static const std::map<std::string, const CameraLensProperties> lensProps = {
>> +		{ "dw9714", {
>> +				.lensFocusRange = { 150, 800 },
>> +		} },
>> +	};
> 
> This partly answers the question I asked in a reply to the cover letter.
> 
> What makes you think the lens focus range is an intrinsic property of
> the VCM driver ?

I am not sure of this indeed, probably it will be a couple lens/sensor 
model... And what else do we have than the vcm driver ?
I don't have any tune files as example from "real life" so I don't 
really know what is usually done, any insight will be appreciated ;-).

Thanks,
JM

> 
>>   
>>   	const auto it = lensProps.find(lens);
>>   	if (it == lensProps.end()) {
>

Patch
diff mbox series

diff --git a/include/libcamera/internal/camera_lens.h b/include/libcamera/internal/camera_lens.h
index 523a1481..f6daff01 100644
--- a/include/libcamera/internal/camera_lens.h
+++ b/include/libcamera/internal/camera_lens.h
@@ -29,6 +29,7 @@  public:
 
 	int init();
 	int setFocusPosition(int32_t position);
+	const Size &getLensRange();
 
 	const std::string &model() const { return model_; }
 
diff --git a/include/libcamera/internal/camera_lens_properties.h b/include/libcamera/internal/camera_lens_properties.h
index 73982550..7424b375 100644
--- a/include/libcamera/internal/camera_lens_properties.h
+++ b/include/libcamera/internal/camera_lens_properties.h
@@ -17,6 +17,8 @@  namespace libcamera {
 
 struct CameraLensProperties {
 	static const CameraLensProperties *get(const std::string &lens);
+
+	Size lensFocusRange;
 };
 
 } /* namespace libcamera */
diff --git a/src/libcamera/camera_lens.cpp b/src/libcamera/camera_lens.cpp
index d4d44bc7..abec5a27 100644
--- a/src/libcamera/camera_lens.cpp
+++ b/src/libcamera/camera_lens.cpp
@@ -79,6 +79,25 @@  int CameraLens::init()
 	return 0;
 }
 
+/**
+ * \brief Retrieve the lens position range
+ * \return The minimum and maximum positions for the given lens or a default
+ * nulled Size reference
+ *
+ * If a lens has no static properties associated, a special value is returned,
+ * where the minimum and maximum are set to 0. The caller may then chose the
+ * ones returned by the V4L2_CID_FOCUS_ABSOLUTE call.
+ */
+const Size &CameraLens::getLensRange()
+{
+	static const Size defaultLensFocusRange = { 0, 0 };
+	if (!staticProps_ || staticProps_->lensFocusRange.isNull())
+		return defaultLensFocusRange;
+
+	return staticProps_->lensFocusRange;
+}
+
+
 /**
  * \brief This function sets the focal point of the lens to a specific position.
  * \param[in] position The focal point of the lens
diff --git a/src/libcamera/camera_lens_properties.cpp b/src/libcamera/camera_lens_properties.cpp
index dee73b43..225546ae 100644
--- a/src/libcamera/camera_lens_properties.cpp
+++ b/src/libcamera/camera_lens_properties.cpp
@@ -32,6 +32,9 @@  LOG_DEFINE_CATEGORY(CameraLensProperties)
 /**
  * \struct CameraLensProperties
  * \brief Database of camera lens properties
+ *
+ * \var CameraLensProperties::lensFocusRange
+ * \brief The limits for the sensor position, stored as a min and a max.
  */
 
 /**
@@ -42,7 +45,11 @@  LOG_DEFINE_CATEGORY(CameraLensProperties)
  */
 const CameraLensProperties *CameraLensProperties::get(const std::string &lens)
 {
-	static const std::map<std::string, const CameraLensProperties> lensProps = {};
+	static const std::map<std::string, const CameraLensProperties> lensProps = {
+		{ "dw9714", {
+				.lensFocusRange = { 150, 800 },
+		} },
+	};
 
 	const auto it = lensProps.find(lens);
 	if (it == lensProps.end()) {