camera: add support for camera removal

Add camera removal support to CameraProvider and CameraModule.

Change-Id: I047e486d1665ba9e0b1455f77a7bbbb5e0d66653
Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@intel.com>
This commit is contained in:
Guennadi Liakhovetski 2017-12-07 10:59:35 +01:00 committed by Yin-Chia Yeh
parent d7a0f2984d
commit eca1d45ba7
5 changed files with 51 additions and 2 deletions

View file

@ -425,6 +425,13 @@ status_t CameraModule::filterOpenErrorCode(status_t err) {
return -ENODEV;
}
void CameraModule::removeCamera(int cameraId) {
free_camera_metadata(
const_cast<camera_metadata_t*>(mCameraInfoMap[cameraId].static_camera_characteristics));
mCameraInfoMap.removeItem(cameraId);
mDeviceVersionMap.removeItem(cameraId);
}
uint16_t CameraModule::getModuleApiVersion() const {
return mModule->common.module_api_version;
}

View file

@ -0,0 +1,6 @@
cychen@google.com
epeev@google.com
etalvala@google.com
shuzhenwang@google.com
yinchiayeh@google.com
zhijunhe@google.com

View file

@ -63,6 +63,8 @@ public:
const char* getModuleAuthor() const;
// Only used by CameraModuleFixture native test. Do NOT use elsewhere.
void *getDso();
// Only used by CameraProvider
void removeCamera(int cameraId);
private:
// Derive camera characteristics keys defined after HAL device version

View file

@ -104,6 +104,30 @@ void CameraProvider::addDeviceNames(int camera_id, CameraDeviceStatus status, bo
}
}
void CameraProvider::removeDeviceNames(int camera_id)
{
std::string cameraIdStr = std::to_string(camera_id);
mCameraIds.remove(cameraIdStr);
int deviceVersion = mModule->getDeviceVersion(camera_id);
auto deviceNamePair = std::make_pair(cameraIdStr,
getHidlDeviceName(cameraIdStr, deviceVersion));
mCameraDeviceNames.remove(deviceNamePair);
mCallbacks->cameraDeviceStatusChange(deviceNamePair.second, CameraDeviceStatus::NOT_PRESENT);
if (deviceVersion >= CAMERA_DEVICE_API_VERSION_3_2 &&
mModule->isOpenLegacyDefined() && mOpenLegacySupported[cameraIdStr]) {
deviceNamePair = std::make_pair(cameraIdStr,
getHidlDeviceName(cameraIdStr, CAMERA_DEVICE_API_VERSION_1_0));
mCameraDeviceNames.remove(deviceNamePair);
mCallbacks->cameraDeviceStatusChange(deviceNamePair.second,
CameraDeviceStatus::NOT_PRESENT);
}
mModule->removeCamera(camera_id);
}
/**
* static callback forwarding methods from HAL to instance
*/
@ -135,8 +159,17 @@ void CameraProvider::sCameraDeviceStatusChange(
}
}
if (!found) {
cp->addDeviceNames(camera_id, status, true);
switch (status) {
case CameraDeviceStatus::PRESENT:
case CameraDeviceStatus::ENUMERATING:
if (!found) {
cp->addDeviceNames(camera_id, status, true);
}
break;
case CameraDeviceStatus::NOT_PRESENT:
if (found) {
cp->removeDeviceNames(camera_id);
}
}
}
}

View file

@ -115,6 +115,7 @@ private:
void addDeviceNames(int camera_id, CameraDeviceStatus status = CameraDeviceStatus::PRESENT,
bool cam_new = false);
void removeDeviceNames(int camera_id);
};
extern "C" ICameraProvider* HIDL_FETCH_ICameraProvider(const char* name);