CameraHal: Allow only certain number of instances
1) Protect against simultaneous access to camera_device_open
2) Set a value of MAX_SIMUL_CAMERAS_SUPPORTED to dictate number
of simultaneous cameras that can be open at once. Set to 1 for
now in this patch. Return error if more is requested.
3) Change OMXCameraAdapter to allocate new instance for each
factory create call.
4) Add lock to capabalities factory function in OMXCameraAdapter
to protected against multiple OMXCamera GetHandles...
b/5401791 b/5404200 b/5405235
Change-Id: I179d493f8070d228877ebfac637047978afc7d55
Signed-off-by: Tyler Luu <[email protected]>
Signed-off-by: Iliyan Malchev <[email protected]>
diff --git a/camera/CameraHal_Module.cpp b/camera/CameraHal_Module.cpp
index 2df6928..c7d1910 100644
--- a/camera/CameraHal_Module.cpp
+++ b/camera/CameraHal_Module.cpp
@@ -23,6 +23,8 @@
#define LOG_TAG "CameraHAL"
+#include <utils/threads.h>
+
#include "CameraHal.h"
#include "CameraProperties.h"
#include "TICameraParameters.h"
@@ -30,6 +32,8 @@
static android::CameraProperties gCameraProperties;
static android::CameraHal* gCameraHals[MAX_CAMERAS_SUPPORTED];
+static unsigned int gCamerasOpen = 0;
+static android::Mutex gCameraHalDeviceLock;
static int camera_device_open(const hw_module_t* module, const char* name,
hw_device_t** device);
@@ -438,6 +442,8 @@
LOGV("%s", __FUNCTION__);
+ android::Mutex::Autolock lock(gCameraHalDeviceLock);
+
if (!device) {
ret = -EINVAL;
goto done;
@@ -448,6 +454,7 @@
if (gCameraHals[ti_dev->cameraid]) {
delete gCameraHals[ti_dev->cameraid];
gCameraHals[ti_dev->cameraid] = NULL;
+ gCamerasOpen--;
}
if (ti_dev->base.ops) {
@@ -483,6 +490,8 @@
android::CameraHal* camera = NULL;
android::CameraProperties::Properties* properties = NULL;
+ android::Mutex::Autolock lock(gCameraHalDeviceLock);
+
LOGI("camera_device open");
if (name != NULL) {
@@ -494,6 +503,14 @@
LOGE("camera service provided cameraid out of bounds, "
"cameraid = %d, num supported = %d",
cameraid, num_cameras);
+ rv = -EINVAL;
+ goto fail;
+ }
+
+ if(gCamerasOpen >= MAX_SIMUL_CAMERAS_SUPPORTED)
+ {
+ LOGE("maximum number of cameras already open");
+ rv = -ENOMEM;
goto fail;
}
@@ -576,12 +593,12 @@
}
gCameraHals[cameraid] = camera;
+ gCamerasOpen++;
}
return rv;
fail:
-
if(camera_device)
free(camera_device);
if(camera_ops)