[libcamera-devel,v2,09/10] android: camera_device: Use Camera properties for static Metadata

Message ID 20191205204350.28196-10-jacopo@jmondi.org
State Superseded
Headers show
Series
  • Introduce camera properties
Related show

Commit Message

Jacopo Mondi Dec. 5, 2019, 8:43 p.m. UTC
Construct two example static metadata to be reported to the Android
framework using the properties reported by the Camera.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/android/camera_device.cpp | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

Comments

Niklas Söderlund Dec. 6, 2019, 10:47 p.m. UTC | #1
Hi Jacopo,

I really like this patch!

On 2019-12-05 21:43:49 +0100, Jacopo Mondi wrote:
> Construct two example static metadata to be reported to the Android
> framework using the properties reported by the Camera.
> 
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> ---
>  src/android/camera_device.cpp | 29 +++++++++++++++++++++++++++--
>  1 file changed, 27 insertions(+), 2 deletions(-)
> 
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index 065e0292e186..e01c7fb2e541 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -7,6 +7,9 @@
>  
>  #include "camera_device.h"
>  
> +#include <libcamera/controls.h>
> +#include <libcamera/property_ids.h>
> +
>  #include "log.h"
>  #include "utils.h"
>  
> @@ -97,6 +100,8 @@ camera_metadata_t *CameraDevice::getStaticMetadata()
>  	if (staticMetadata_)
>  		return staticMetadata_->get();
>  
> +	const ControlList &properties = camera_->properties();
> +
>  	/*
>  	 * The here reported metadata are enough to implement a basic capture
>  	 * example application, but a real camera implementation will require
> @@ -261,9 +266,15 @@ camera_metadata_t *CameraDevice::getStaticMetadata()
>  	staticMetadata_->addEntry(ANDROID_SENSOR_INFO_EXPOSURE_TIME_RANGE,
>  				  &exposureTimeRange, 2);
>  
> +	/*
> +	 * Android reports orientation as clockwise correction, while libcamera
> +	 * uses counter-clockwise.
> +	 */
>  	int32_t orientation = 0;
> -	staticMetadata_->addEntry(ANDROID_SENSOR_ORIENTATION,
> -				  &orientation, 1);
> +	if (properties.contains(properties::Rotation))
> +		orientation = (360 - properties.get(properties::Rotation))
> +			    % 360;

If we limit properties::Rotation to 0 - 360 degrees the mod operation is 
not need here.

With or without adding the bound in previous patches and dropping the 
mod here,

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

> +	staticMetadata_->addEntry(ANDROID_SENSOR_ORIENTATION, &orientation, 1);
>  
>  	std::vector<int32_t> testPatterModes = {
>  		ANDROID_SENSOR_TEST_PATTERN_MODE_OFF,
> @@ -310,6 +321,20 @@ camera_metadata_t *CameraDevice::getStaticMetadata()
>  				  lensApertures.size());
>  
>  	uint8_t lensFacing = ANDROID_LENS_FACING_FRONT;
> +	if (properties.contains(properties::Location)) {
> +		int32_t location = properties.get(properties::Location);
> +		switch (location) {
> +		case CAMERA_LOCATION_FRONT:
> +			lensFacing = ANDROID_LENS_FACING_FRONT;
> +			break;
> +		case CAMERA_LOCATION_BACK:
> +			lensFacing = ANDROID_LENS_FACING_BACK;
> +			break;
> +		case CAMERA_LOCATION_EXTERNAL:
> +			lensFacing = ANDROID_LENS_FACING_EXTERNAL;
> +			break;
> +		}
> +	}
>  	staticMetadata_->addEntry(ANDROID_LENS_FACING, &lensFacing, 1);
>  
>  	std::vector<float> lensFocalLenghts = {
> -- 
> 2.23.0
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
Jacopo Mondi Dec. 8, 2019, 6:18 p.m. UTC | #2
Hi Niklas,

On Fri, Dec 06, 2019 at 11:47:41PM +0100, Niklas Söderlund wrote:
> Hi Jacopo,
>
> I really like this patch!
>

Thanks, I'm happy the direction this series takes is welcome

> On 2019-12-05 21:43:49 +0100, Jacopo Mondi wrote:
> > Construct two example static metadata to be reported to the Android
> > framework using the properties reported by the Camera.
> >
> > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
> > ---
> >  src/android/camera_device.cpp | 29 +++++++++++++++++++++++++++--
> >  1 file changed, 27 insertions(+), 2 deletions(-)
> >
> > diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> > index 065e0292e186..e01c7fb2e541 100644
> > --- a/src/android/camera_device.cpp
> > +++ b/src/android/camera_device.cpp
> > @@ -7,6 +7,9 @@
> >
> >  #include "camera_device.h"
> >
> > +#include <libcamera/controls.h>
> > +#include <libcamera/property_ids.h>
> > +
> >  #include "log.h"
> >  #include "utils.h"
> >
> > @@ -97,6 +100,8 @@ camera_metadata_t *CameraDevice::getStaticMetadata()
> >  	if (staticMetadata_)
> >  		return staticMetadata_->get();
> >
> > +	const ControlList &properties = camera_->properties();
> > +
> >  	/*
> >  	 * The here reported metadata are enough to implement a basic capture
> >  	 * example application, but a real camera implementation will require
> > @@ -261,9 +266,15 @@ camera_metadata_t *CameraDevice::getStaticMetadata()
> >  	staticMetadata_->addEntry(ANDROID_SENSOR_INFO_EXPOSURE_TIME_RANGE,
> >  				  &exposureTimeRange, 2);
> >
> > +	/*
> > +	 * Android reports orientation as clockwise correction, while libcamera
> > +	 * uses counter-clockwise.
> > +	 */
> >  	int32_t orientation = 0;
> > -	staticMetadata_->addEntry(ANDROID_SENSOR_ORIENTATION,
> > -				  &orientation, 1);
> > +	if (properties.contains(properties::Rotation))
> > +		orientation = (360 - properties.get(properties::Rotation))
> > +			    % 360;
>
> If we limit properties::Rotation to 0 - 360 degrees the mod operation is
> not need here.

I need the modulo operation to make sure a rotation of 0 degrees, it's
actually 0, otherwise 360 - 0 = 360

>
> With or without adding the bound in previous patches and dropping the
> mod here,

It should be bounded and verified by kernel, but we can stay safe and
do the same when parsing the property maybe.

>
> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

Thanks
   j

>
> > +	staticMetadata_->addEntry(ANDROID_SENSOR_ORIENTATION, &orientation, 1);
> >
> >  	std::vector<int32_t> testPatterModes = {
> >  		ANDROID_SENSOR_TEST_PATTERN_MODE_OFF,
> > @@ -310,6 +321,20 @@ camera_metadata_t *CameraDevice::getStaticMetadata()
> >  				  lensApertures.size());
> >
> >  	uint8_t lensFacing = ANDROID_LENS_FACING_FRONT;
> > +	if (properties.contains(properties::Location)) {
> > +		int32_t location = properties.get(properties::Location);
> > +		switch (location) {
> > +		case CAMERA_LOCATION_FRONT:
> > +			lensFacing = ANDROID_LENS_FACING_FRONT;
> > +			break;
> > +		case CAMERA_LOCATION_BACK:
> > +			lensFacing = ANDROID_LENS_FACING_BACK;
> > +			break;
> > +		case CAMERA_LOCATION_EXTERNAL:
> > +			lensFacing = ANDROID_LENS_FACING_EXTERNAL;
> > +			break;
> > +		}
> > +	}
> >  	staticMetadata_->addEntry(ANDROID_LENS_FACING, &lensFacing, 1);
> >
> >  	std::vector<float> lensFocalLenghts = {
> > --
> > 2.23.0
> >
> > _______________________________________________
> > libcamera-devel mailing list
> > libcamera-devel@lists.libcamera.org
> > https://lists.libcamera.org/listinfo/libcamera-devel
>
> --
> Regards,
> Niklas Söderlund

Patch

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 065e0292e186..e01c7fb2e541 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -7,6 +7,9 @@ 
 
 #include "camera_device.h"
 
+#include <libcamera/controls.h>
+#include <libcamera/property_ids.h>
+
 #include "log.h"
 #include "utils.h"
 
@@ -97,6 +100,8 @@  camera_metadata_t *CameraDevice::getStaticMetadata()
 	if (staticMetadata_)
 		return staticMetadata_->get();
 
+	const ControlList &properties = camera_->properties();
+
 	/*
 	 * The here reported metadata are enough to implement a basic capture
 	 * example application, but a real camera implementation will require
@@ -261,9 +266,15 @@  camera_metadata_t *CameraDevice::getStaticMetadata()
 	staticMetadata_->addEntry(ANDROID_SENSOR_INFO_EXPOSURE_TIME_RANGE,
 				  &exposureTimeRange, 2);
 
+	/*
+	 * Android reports orientation as clockwise correction, while libcamera
+	 * uses counter-clockwise.
+	 */
 	int32_t orientation = 0;
-	staticMetadata_->addEntry(ANDROID_SENSOR_ORIENTATION,
-				  &orientation, 1);
+	if (properties.contains(properties::Rotation))
+		orientation = (360 - properties.get(properties::Rotation))
+			    % 360;
+	staticMetadata_->addEntry(ANDROID_SENSOR_ORIENTATION, &orientation, 1);
 
 	std::vector<int32_t> testPatterModes = {
 		ANDROID_SENSOR_TEST_PATTERN_MODE_OFF,
@@ -310,6 +321,20 @@  camera_metadata_t *CameraDevice::getStaticMetadata()
 				  lensApertures.size());
 
 	uint8_t lensFacing = ANDROID_LENS_FACING_FRONT;
+	if (properties.contains(properties::Location)) {
+		int32_t location = properties.get(properties::Location);
+		switch (location) {
+		case CAMERA_LOCATION_FRONT:
+			lensFacing = ANDROID_LENS_FACING_FRONT;
+			break;
+		case CAMERA_LOCATION_BACK:
+			lensFacing = ANDROID_LENS_FACING_BACK;
+			break;
+		case CAMERA_LOCATION_EXTERNAL:
+			lensFacing = ANDROID_LENS_FACING_EXTERNAL;
+			break;
+		}
+	}
 	staticMetadata_->addEntry(ANDROID_LENS_FACING, &lensFacing, 1);
 
 	std::vector<float> lensFocalLenghts = {