[libcamera-devel,RFC,3/3] android: camera_hal_manager: error on init if cameras not initialized

Message ID 20190930053520.2711-3-paul.elder@ideasonboard.com
State Superseded
Delegated to: Paul Elder
Headers show
Series
  • [libcamera-devel,RFC,1/3] libcamera: pipeline: Add device IDs
Related show

Commit Message

Paul Elder Sept. 30, 2019, 5:35 a.m. UTC
Return error from hal_init() if the built-in cameras have not been
initialized yet. On Chromium OS, this causes Upstart to restart the
camera service at a later time, allowing the built-in cameras to be
enumerated correctly. This fixes the problem where the camera service
is started before the camera device nodes are available.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
---
 src/android/camera3_hal.cpp        |  4 +---
 src/android/camera_hal_manager.cpp | 11 ++++++++++-
 2 files changed, 11 insertions(+), 4 deletions(-)

Patch

diff --git a/src/android/camera3_hal.cpp b/src/android/camera3_hal.cpp
index 8d2629ca..9d18b999 100644
--- a/src/android/camera3_hal.cpp
+++ b/src/android/camera3_hal.cpp
@@ -56,9 +56,7 @@  static int hal_init()
 {
 	LOG(HAL, Info) << "Initialising Android camera HAL";
 
-	cameraManager.init();
-
-	return 0;
+	return cameraManager.init();
 }
 
 /*------------------------------------------------------------------------------
diff --git a/src/android/camera_hal_manager.cpp b/src/android/camera_hal_manager.cpp
index 22f0323b..af0114fc 100644
--- a/src/android/camera_hal_manager.cpp
+++ b/src/android/camera_hal_manager.cpp
@@ -13,11 +13,14 @@ 
 
 #include "camera_device.h"
 #include "camera_proxy.h"
+#include "device_enumerator.h"
 
 using namespace libcamera;
 
 LOG_DECLARE_CATEGORY(HAL);
 
+static int initRet = 0;
+
 /*
  * \class CameraHalManager
  *
@@ -49,7 +52,7 @@  int CameraHalManager::init()
 	MutexLocker locker(mutex_);
 	cv_.wait(locker);
 
-	return 0;
+	return initRet;
 }
 
 void CameraHalManager::run()
@@ -68,6 +71,12 @@  void CameraHalManager::run()
 		return;
 	}
 
+	if (!DeviceEnumerator::haveExpectedCameras(cameraManager_)) {
+		LOG(HAL, Warning) << "Expected cameras not loaded";
+		initRet = -EAGAIN;
+		cv_.notify_one();
+	}
+
 	/*
 	 * For each Camera registered in the system, a CameraProxy
 	 * gets created here to wraps a camera device.