[libcamera-devel,v4,3/4] android: Override camera as "Internal" provided found in HAL config
diff mbox series

Message ID 20210803140237.19302-4-umang.jain@ideasonboard.com
State Accepted
Delegated to: Umang Jain
Headers show
Series
  • android: Handle internal UVC cameras
Related show

Commit Message

Umang Jain Aug. 3, 2021, 2:02 p.m. UTC
Currently, all UVC cameras are reported with CameraLocationExternal [1]
by libcamera-core since there is no universal information or standard,
to know the location of these cameras. However, in the libcamera HAL
layer, we can make an informed decision whether it's external or
internal, simply by checking its presence in the HAL configuration
file.

The CameraHalManager will now assign the numerical id of the camera
accordingly when initializing the CameraDevice, based on the camera
facing value set in the HAL config file.

[1] 76809320bb1a ("libcamera: pipeline: uvcvideo: Treat all UVC cameras
                   as external")

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/android/camera_device.cpp      | 13 ++++++++++++-
 src/android/camera_hal_manager.cpp | 17 +++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletion(-)

Comments

Paul Elder Aug. 4, 2021, 2:41 a.m. UTC | #1
Hi Umang,

On Tue, Aug 03, 2021 at 07:32:36PM +0530, Umang Jain wrote:
> Currently, all UVC cameras are reported with CameraLocationExternal [1]
> by libcamera-core since there is no universal information or standard,
> to know the location of these cameras. However, in the libcamera HAL
> layer, we can make an informed decision whether it's external or
> internal, simply by checking its presence in the HAL configuration
> file.
> 
> The CameraHalManager will now assign the numerical id of the camera
> accordingly when initializing the CameraDevice, based on the camera
> facing value set in the HAL config file.
> 
> [1] 76809320bb1a ("libcamera: pipeline: uvcvideo: Treat all UVC cameras
>                    as external")
> 
> Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
>  src/android/camera_device.cpp      | 13 ++++++++++++-
>  src/android/camera_hal_manager.cpp | 17 +++++++++++++++++
>  2 files changed, 29 insertions(+), 1 deletion(-)
> 
> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
> index 692d0a5b..4ebc1524 100644
> --- a/src/android/camera_device.cpp
> +++ b/src/android/camera_device.cpp
> @@ -330,7 +330,18 @@ int CameraDevice::initialize(const CameraConfigData *cameraConfigData)
>  			facing_ = CAMERA_FACING_BACK;
>  			break;
>  		case properties::CameraLocationExternal:
> -			facing_ = CAMERA_FACING_EXTERNAL;
> +			/*
> +			 * If the camera is reported as external, but the
> +			 * CameraHalManager has overriden it, use what is
> +			 * reported in the configuration file. This typically
> +			 * happens for UVC cameras reported as 'External' by
> +			 * libcamera but installed in fixed position on the
> +			 * device.
> +			 */
> +			if (cameraConfigData && cameraConfigData->facing != -1)
> +			       facing_ = cameraConfigData->facing;
> +			else
> +			       facing_ = CAMERA_FACING_EXTERNAL;
>  			break;
>  		}
>  
> diff --git a/src/android/camera_hal_manager.cpp b/src/android/camera_hal_manager.cpp
> index b364f62a..5f7bfe26 100644
> --- a/src/android/camera_hal_manager.cpp
> +++ b/src/android/camera_hal_manager.cpp
> @@ -145,6 +145,23 @@ void CameraHalManager::cameraAdded(std::shared_ptr<Camera> cam)
>  	}
>  
>  	const CameraConfigData *cameraConfigData = halConfig_.cameraConfigData(cam->id());
> +
> +	/*
> +	 * Some cameras whose location is reported by libcamera as external may
> +	 * actually be internal to the device. This is common with UVC cameras
> +	 * that are integrated in a laptop. In that case the real location
> +	 * should be specified in the configuration file.
> +	 *
> +	 * If the camera location is external and a configuration entry exists
> +	 * for it, override its location.
> +	 */
> +	if (isCameraNew && isCameraExternal) {
> +		if (cameraConfigData && cameraConfigData->facing != -1) {
> +			isCameraExternal = false;
> +			id = numInternalCameras_;
> +		}
> +	}
> +
>  	if (!isCameraExternal && !cameraConfigData) {
>  		LOG(HAL, Error)
>  			<< "HAL configuration entry for internal camera "
> -- 
> 2.31.1
>

Patch
diff mbox series

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 692d0a5b..4ebc1524 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -330,7 +330,18 @@  int CameraDevice::initialize(const CameraConfigData *cameraConfigData)
 			facing_ = CAMERA_FACING_BACK;
 			break;
 		case properties::CameraLocationExternal:
-			facing_ = CAMERA_FACING_EXTERNAL;
+			/*
+			 * If the camera is reported as external, but the
+			 * CameraHalManager has overriden it, use what is
+			 * reported in the configuration file. This typically
+			 * happens for UVC cameras reported as 'External' by
+			 * libcamera but installed in fixed position on the
+			 * device.
+			 */
+			if (cameraConfigData && cameraConfigData->facing != -1)
+			       facing_ = cameraConfigData->facing;
+			else
+			       facing_ = CAMERA_FACING_EXTERNAL;
 			break;
 		}
 
diff --git a/src/android/camera_hal_manager.cpp b/src/android/camera_hal_manager.cpp
index b364f62a..5f7bfe26 100644
--- a/src/android/camera_hal_manager.cpp
+++ b/src/android/camera_hal_manager.cpp
@@ -145,6 +145,23 @@  void CameraHalManager::cameraAdded(std::shared_ptr<Camera> cam)
 	}
 
 	const CameraConfigData *cameraConfigData = halConfig_.cameraConfigData(cam->id());
+
+	/*
+	 * Some cameras whose location is reported by libcamera as external may
+	 * actually be internal to the device. This is common with UVC cameras
+	 * that are integrated in a laptop. In that case the real location
+	 * should be specified in the configuration file.
+	 *
+	 * If the camera location is external and a configuration entry exists
+	 * for it, override its location.
+	 */
+	if (isCameraNew && isCameraExternal) {
+		if (cameraConfigData && cameraConfigData->facing != -1) {
+			isCameraExternal = false;
+			id = numInternalCameras_;
+		}
+	}
+
 	if (!isCameraExternal && !cameraConfigData) {
 		LOG(HAL, Error)
 			<< "HAL configuration entry for internal camera "