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

Umang Jain umang.jain at ideasonboard.com
Wed Jul 28 09:37:59 CEST 2021


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 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. CameraHalManager will now assign the numerical id
of the camera accordingly, based on which the facing of the camera is set
as well (as per the HAL config file) while initializing the CameraDevice
wrapper.

[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 | 18 ++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 678cde23..c7f5fc4e 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 != -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..4950bd75 100644
--- a/src/android/camera_hal_manager.cpp
+++ b/src/android/camera_hal_manager.cpp
@@ -145,6 +145,24 @@ 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 can be integrated in a laptop, but are all considered by
+	 * libcamera as external. The true location for those cameras is
+	 * specified in the HAL configuration file. If the camera location is
+	 * external and a configuration entry exists for it, override the
+	 * location.
+	 */
+	if (isCameraNew && isCameraExternal) {
+		if (cameraConfigData && cameraConfigData->facing != -1 &&
+		    cameraConfigData->facing != CAMERA_FACING_EXTERNAL) {
+			isCameraExternal = false;
+			id = numInternalCameras_;
+		}
+	}
+
 	if (!isCameraExternal && !cameraConfigData) {
 		LOG(HAL, Error)
 			<< "HAL configuration entry for internal camera "
-- 
2.31.0



More information about the libcamera-devel mailing list