@@ -77,8 +77,13 @@ static int hal_dev_open(const hw_module_t *module, const char *name,
LOG(HAL, Debug) << "Open camera " << name;
int id = atoi(name);
- CameraDevice *camera = cameraManager.open(id, module);
- if (!camera) {
+ auto [camera, ret] = cameraManager.open(id, module);
+ if (ret == -EBUSY) {
+ LOG(HAL, Error)
+ << "Failed to open camera module '" << id
+ << "', as it is in use";
+ return -EUSERS;
+ } else if (!camera) {
LOG(HAL, Error)
<< "Failed to open camera module '" << id << "'";
return -ENODEV;
@@ -65,28 +65,29 @@ int CameraHalManager::init()
return 0;
}
-CameraDevice *CameraHalManager::open(unsigned int id,
- const hw_module_t *hardwareModule)
+std::tuple<CameraDevice *, int>
+CameraHalManager::open(unsigned int id, const hw_module_t *hardwareModule)
{
MutexLocker locker(mutex_);
if (!callbacks_) {
LOG(HAL, Error) << "Can't open camera before callbacks are set";
- return nullptr;
+ return { nullptr, -ENODEV };
}
CameraDevice *camera = cameraDeviceFromHalId(id);
if (!camera) {
LOG(HAL, Error) << "Invalid camera id '" << id << "'";
- return nullptr;
+ return { nullptr, -ENODEV };
}
- if (camera->open(hardwareModule))
- return nullptr;
+ int ret = camera->open(hardwareModule);
+ if (ret)
+ return { nullptr, ret };
LOG(HAL, Info) << "Open camera '" << id << "'";
- return camera;
+ return { camera, 0 };
}
void CameraHalManager::cameraAdded(std::shared_ptr<Camera> cam)
@@ -10,6 +10,7 @@
#include <map>
#include <mutex>
#include <stddef.h>
+#include <tuple>
#include <vector>
#include <hardware/camera_common.h>
@@ -28,7 +29,8 @@ public:
int init();
- CameraDevice *open(unsigned int id, const hw_module_t *module);
+ std::tuple<CameraDevice *, int>
+ open(unsigned int id, const hw_module_t *module);
unsigned int numCameras() const;
int getCameraInfo(unsigned int id, struct camera_info *info);
The correct return value for the HAL for hal_dev_open() when trying to open a camera that's already opened is EUSERS. Make hal_dev_open() return -EUSERS, and plumb the logic for this through CameraHalManager::open(). Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> --- I think the only discussion point that we have so far is whether -EUSERS should be returned only in HAL, or in libcamera as well, which currently returners -EBUSY. Changes in v2: - use structured binding when opening the camera in hal_dev_open() - expand the error message --- src/android/camera3_hal.cpp | 9 +++++++-- src/android/camera_hal_manager.cpp | 15 ++++++++------- src/android/camera_hal_manager.h | 4 +++- 3 files changed, 18 insertions(+), 10 deletions(-)