[libcamera-devel] [PATCH 1/2] android: Override camera is "Internal" provided if found on HAL config

Umang Jain umang.jain at ideasonboard.com
Tue Jul 27 15:54:39 CEST 2021


Currently, all UVC cameras are marked with CameraLocationExternal [1]
property, 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 its external or internal,
simply by checking the presence of it, in the HAL configuration file.

If the camera is found to be present on the HAL configuration file,
treat it as internal and assign its numerical id accordingly.

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

Signed-off-by: Umang Jain <umang.jain at ideasonboard.com>
---
 src/android/camera_device.cpp      | 10 +++++++++-
 src/android/camera_hal_manager.cpp | 14 ++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 678cde23..ba4e2d15 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -330,7 +330,15 @@ int CameraDevice::initialize(const CameraConfigData *cameraConfigData)
 			facing_ = CAMERA_FACING_BACK;
 			break;
 		case properties::CameraLocationExternal:
-			facing_ = CAMERA_FACING_EXTERNAL;
+			/*
+			 * If the camera is 'internal' as found by
+			 * CameraHalManager, use its location from
+			 * HAL config file.
+			 */
+			if (id_ < 1000 && cameraConfigData)
+				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 4cd67544..1a9b3413 100644
--- a/src/android/camera_hal_manager.cpp
+++ b/src/android/camera_hal_manager.cpp
@@ -133,6 +133,20 @@ void CameraHalManager::cameraAdded(std::shared_ptr<Camera> cam)
 		}
 	}
 
+	/*
+	 * In some cases, particularly in UVC cameras, the camera location is defaulted
+	 * to 'External'. However, if the HAL config file mentions the camera in question,
+	 * it shall mean that the camera is integrated to the system so, override to treat
+	 * it correctly as a 'internal' camera.
+	 */
+	if (isCameraNew && isCameraExternal && halConfig_.exists()) {
+		const CameraConfigData *configData = halConfig_.cameraConfigData(cam->id());
+		if (configData && configData->facing != CAMERA_FACING_EXTERNAL) {
+			isCameraExternal = false;
+			id = numInternalCameras_;
+		}
+	}
+
 	/* Create a CameraDevice instance to wrap the libcamera Camera. */
 	std::unique_ptr<CameraDevice> camera = CameraDevice::create(id, cam);
 
-- 
2.31.0



More information about the libcamera-devel mailing list