From 180e46fe538b9c908e331d1456645c0a333559c0 Mon Sep 17 00:00:00 2001 From: Guosong Zhou Date: Wed, 02 Sep 2015 07:02:40 +0000 Subject: PD#111061:fix usb camera plug problem Change-Id: I85c8b3cf0942f761c71caea14197f3c098d317ff --- diff --git a/v3/EmulatedCameraFactory.cpp b/v3/EmulatedCameraFactory.cpp index 0f6a6fa..3e86aee 100644 --- a/v3/EmulatedCameraFactory.cpp +++ b/v3/EmulatedCameraFactory.cpp @@ -482,11 +482,18 @@ void EmulatedCameraFactory::onStatusChanged(int cameraId, int newStatus) CAMHAL_LOGDB("mEmulatedCameraNum =%d\n", mEmulatedCameraNum); n = getValidCameraOjectId(); if ((n != cameraId) && (mEmulatedCameras[n] != NULL)) { + DBG_LOGA("device node changed"); mEmulatedCameras[n]->unplugCamera(); delete mEmulatedCameras[n]; mEmulatedCameras[n] = NULL; } + if (mEmulatedCameras[cameraId] != NULL && (!mEmulatedCameras[cameraId]->getHotplugStatus())) { + DBG_LOGA("close EmulatedFakeCamera3 object for the last time"); + delete mEmulatedCameras[cameraId]; + mEmulatedCameras[cameraId] = NULL; + } + EmulatedBaseCamera *cam = mEmulatedCameras[cameraId]; if ((!cam) && (newStatus == CAMERA_DEVICE_STATUS_PRESENT)) { @@ -549,8 +556,9 @@ void EmulatedCameraFactory::onStatusChanged(int cameraId, int newStatus) CAMHAL_LOGDB("mEmulatedCameraNum =%d\n", mEmulatedCameraNum); if (newStatus == CAMERA_DEVICE_STATUS_NOT_PRESENT) { + mEmulatedCameraNum --; j = getValidCameraOjectId(); - while (m < 2000) { + while (m < 200) { if (mEmulatedCameras[j] != NULL) { if (mEmulatedCameras[j]->getCameraStatus()) { DBG_LOGA("start to delete EmulatedFakeCamera3 object"); @@ -565,7 +573,9 @@ void EmulatedCameraFactory::onStatusChanged(int cameraId, int newStatus) break; } } - mEmulatedCameraNum --; + if (m == 200) { + cam->unplugCamera(); + } } else if (newStatus == CAMERA_DEVICE_STATUS_PRESENT) { CAMHAL_LOGDA("camera plugged again?\n"); cam->plugCamera(); -- cgit