From e43660b0942380839ac881a6af7106c4aace8a29 Mon Sep 17 00:00:00 2001 From: Alex Ray Date: Mon, 8 Oct 2012 13:20:21 -0700 Subject: [PATCH] libcamera2: Prevent multiple camera open calls Requires that previous open camera be closed before a new camera can be opened. Bug: 7298182 Change-Id: If128fd5bfa0ce5d6e721351245f220f0530373e8 --- libcamera2/ExynosCameraHWInterface2.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libcamera2/ExynosCameraHWInterface2.cpp b/libcamera2/ExynosCameraHWInterface2.cpp index 413416f..cf5ed6f 100644 --- a/libcamera2/ExynosCameraHWInterface2.cpp +++ b/libcamera2/ExynosCameraHWInterface2.cpp @@ -6129,10 +6129,12 @@ void ExynosCameraHWInterface2::initCameraMemory(ExynosBuffer *buf, int iMemoryNu static camera2_device_t *g_cam2_device = NULL; static bool g_camera_vaild = false; +static Mutex g_camera_mutex; ExynosCamera2 * g_camera2[2] = { NULL, NULL }; static int HAL2_camera_device_close(struct hw_device_t* device) { + Mutex::Autolock lock(g_camera_mutex); ALOGD("(%s): ENTER", __FUNCTION__); if (device) { @@ -6380,6 +6382,11 @@ static int HAL2_camera_device_open(const struct hw_module_t* module, int cameraId = atoi(id); int openInvalid = 0; + Mutex::Autolock lock(g_camera_mutex); + if (g_camera_vaild) { + ALOGE("ERR(%s): Can't open, other camera is in use", __FUNCTION__); + return -EBUSY; + } g_camera_vaild = false; ALOGD("\n\n>>> I'm Samsung's CameraHAL_2(ID:%d) <<<\n\n", cameraId); if (cameraId < 0 || cameraId >= HAL2_getNumberOfCameras()) { -- 2.20.1