From d3feb3d62c139f08879bbb7f7a0513d593dafcc0 Mon Sep 17 00:00:00 2001 From: Shuzhen Wang Date: Fri, 17 Aug 2018 13:52:40 -0700 Subject: Camera: Add support for physical camera characteristics query - Add version 3.5 for ICameraDevice for physical camera characteristics query. - Add version 3.5 for ICameraDeviceSession to work around HIDL versioning bug. Test: Camera CTS Bug: 79523700 Change-Id: I8df6cdd4ee6ac5755758510c0dc1ea1cec31aa73 --- camera/common/1.0/default/CameraModule.cpp | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'camera/common/1.0/default/CameraModule.cpp') diff --git a/camera/common/1.0/default/CameraModule.cpp b/camera/common/1.0/default/CameraModule.cpp index dc4e0f01ff..eb840a74f4 100644 --- a/camera/common/1.0/default/CameraModule.cpp +++ b/camera/common/1.0/default/CameraModule.cpp @@ -319,6 +319,41 @@ int CameraModule::getCameraInfo(int cameraId, struct camera_info *info) { return OK; } +int CameraModule::getPhysicalCameraInfo(int physicalCameraId, camera_metadata_t **physicalInfo) { + ATRACE_CALL(); + Mutex::Autolock lock(mCameraInfoLock); + if (physicalCameraId < 0) { + ALOGE("%s: Invalid physical camera ID %d", __FUNCTION__, physicalCameraId); + return -EINVAL; + } + + // Only query physical camera info for 2.5 version for newer + int apiVersion = mModule->common.module_api_version; + if (apiVersion < CAMERA_MODULE_API_VERSION_2_5) { + ALOGE("%s: Module version must be at least 2.5 to handle getPhysicalCameraInfo", + __FUNCTION__); + return -ENODEV; + } + + ssize_t index = mPhysicalCameraInfoMap.indexOfKey(physicalCameraId); + if (index == NAME_NOT_FOUND) { + // Get physical camera characteristics, and cache it + camera_metadata_t *info = nullptr; + ATRACE_BEGIN("camera_module->get_physical_camera_info"); + int ret = mModule->get_physical_camera_info(physicalCameraId, &info); + ATRACE_END(); + if (ret != 0) { + return ret; + } + + index = mPhysicalCameraInfoMap.add(physicalCameraId, info); + } + + assert(index != NAME_NOT_FOUND); + *physicalInfo = mPhysicalCameraInfoMap[index]; + return OK; +} + int CameraModule::getDeviceVersion(int cameraId) { ssize_t index = mDeviceVersionMap.indexOfKey(cameraId); if (index == NAME_NOT_FOUND) { -- cgit v1.2.3 From 6bdeaf55bf5cb7d313628d0ff092413c42b5782c Mon Sep 17 00:00:00 2001 From: Shuzhen Wang Date: Wed, 5 Sep 2018 09:40:00 -0700 Subject: VTS: Add test for device version 3.5 Also includes: - Add test for getPhysicalCameraCharacteristics. - Doc update for the new HIDL API. - Tighten boundary check for camera ID in CameraModule. Test: vts-tradefed run commandAndExit vts --skip-all-system-status-check --skip-preconditions --module VtsHalCameraProviderV2_4Target -l INFO Bug: 79523700 Bug: 115969176 Bug: 116512585 Change-Id: I051d1b0c91834781a1f8d893ed5ebfa579b03774 --- camera/common/1.0/default/CameraModule.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'camera/common/1.0/default/CameraModule.cpp') diff --git a/camera/common/1.0/default/CameraModule.cpp b/camera/common/1.0/default/CameraModule.cpp index eb840a74f4..392ebbc237 100644 --- a/camera/common/1.0/default/CameraModule.cpp +++ b/camera/common/1.0/default/CameraModule.cpp @@ -235,7 +235,7 @@ void CameraModule::appendAvailableKeys(CameraMetadata &chars, chars.update(keyTag, availableKeys); } -CameraModule::CameraModule(camera_module_t *module) { +CameraModule::CameraModule(camera_module_t *module) : mNumberOfCameras(0) { if (module == NULL) { ALOGE("%s: camera hardware module must not be null", __FUNCTION__); assert(0); @@ -264,7 +264,8 @@ int CameraModule::init() { res = mModule->init(); ATRACE_END(); } - mCameraInfoMap.setCapacity(getNumberOfCameras()); + mNumberOfCameras = getNumberOfCameras(); + mCameraInfoMap.setCapacity(mNumberOfCameras); return res; } @@ -322,7 +323,7 @@ int CameraModule::getCameraInfo(int cameraId, struct camera_info *info) { int CameraModule::getPhysicalCameraInfo(int physicalCameraId, camera_metadata_t **physicalInfo) { ATRACE_CALL(); Mutex::Autolock lock(mCameraInfoLock); - if (physicalCameraId < 0) { + if (physicalCameraId < mNumberOfCameras) { ALOGE("%s: Invalid physical camera ID %d", __FUNCTION__, physicalCameraId); return -EINVAL; } @@ -334,6 +335,10 @@ int CameraModule::getPhysicalCameraInfo(int physicalCameraId, camera_metadata_t __FUNCTION__); return -ENODEV; } + if (mModule->get_physical_camera_info == nullptr) { + ALOGE("%s: get_physical_camera is NULL for module version 2.5", __FUNCTION__); + return -EINVAL; + } ssize_t index = mPhysicalCameraInfoMap.indexOfKey(physicalCameraId); if (index == NAME_NOT_FOUND) { -- cgit v1.2.3 From d4b8d2179f17a261b348b8a38cbc5278f8b4d45d Mon Sep 17 00:00:00 2001 From: Shik Chen Date: Thu, 25 Oct 2018 18:00:27 +0800 Subject: Camera: Fix a crash in removeCamera() mCameraInfoMap is a KeyedVector, we should use .valueFor() instead of operator[] to get the value from a key. Bug: 118364955 Bug: 118359878 Bug: 77833131 Test: Plug and unplug the external camera 10+ times. Change-Id: Ibf48e5a78b16bdeba08b02242379eaf571fc76cb --- camera/common/1.0/default/CameraModule.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'camera/common/1.0/default/CameraModule.cpp') diff --git a/camera/common/1.0/default/CameraModule.cpp b/camera/common/1.0/default/CameraModule.cpp index 392ebbc237..9c2b02ba0c 100644 --- a/camera/common/1.0/default/CameraModule.cpp +++ b/camera/common/1.0/default/CameraModule.cpp @@ -466,8 +466,8 @@ status_t CameraModule::filterOpenErrorCode(status_t err) { } void CameraModule::removeCamera(int cameraId) { - free_camera_metadata( - const_cast(mCameraInfoMap[cameraId].static_camera_characteristics)); + free_camera_metadata(const_cast( + mCameraInfoMap.valueFor(cameraId).static_camera_characteristics)); mCameraInfoMap.removeItem(cameraId); mDeviceVersionMap.removeItem(cameraId); } -- cgit v1.2.3 From 40a8c6ed51abdf0ebebd566879ef232573696ab0 Mon Sep 17 00:00:00 2001 From: Emilian Peev Date: Mon, 29 Oct 2018 09:35:21 +0000 Subject: Camera: Add support for stream combination query Camera devices 3.5 and later can optionally support stream combination queries. These use the regular 'StreamConfiguration' structure however in contrast to normal stream configuration, the query will be much faster and will not cause any HW/SW side effects. Additionally it will be possible to run stream combination queries at any time after the camera device is open. Implement stream combination query for the external camera provider. Bug: 111593096 Test: vts-tradefed run commandAndExit vts --skip-all-system-status-check --skip-preconditions --module VtsHalCameraProviderV2_4Target -l INFO Change-Id: I59ec936d17dabc89ba49407a750df1cd2e61b145 --- camera/common/1.0/default/CameraModule.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'camera/common/1.0/default/CameraModule.cpp') diff --git a/camera/common/1.0/default/CameraModule.cpp b/camera/common/1.0/default/CameraModule.cpp index 9c2b02ba0c..08354b312d 100644 --- a/camera/common/1.0/default/CameraModule.cpp +++ b/camera/common/1.0/default/CameraModule.cpp @@ -452,6 +452,16 @@ int CameraModule::setTorchMode(const char* camera_id, bool enable) { return res; } +int CameraModule::isStreamCombinationSupported(int cameraId, camera_stream_combination_t *streams) { + int res = INVALID_OPERATION; + if (mModule->is_stream_combination_supported != NULL) { + ATRACE_BEGIN("camera_module->is_stream_combination_supported"); + res = mModule->is_stream_combination_supported(cameraId, streams); + ATRACE_END(); + } + return res; +} + status_t CameraModule::filterOpenErrorCode(status_t err) { switch(err) { case NO_ERROR: -- cgit v1.2.3 From 2951804146cd3239f3b4371021cb95b4aa52fc2f Mon Sep 17 00:00:00 2001 From: Eino-Ville Talvala Date: Fri, 18 Jan 2019 17:32:06 -0800 Subject: Camera: Restructure default camera.provider 2.4 To allow for implementation inheritance of @2.4 legacy wrapper and @2.4 external webcamera HALs in the @2.5 implementations, restructure the existing default provider to separate the service interface into a thin shim that calls the implementations. Test: Camera starts as usual after refactor, VTS tests pass Bug: 121379978 Change-Id: Id40790ed4fb495577fd2b885c706b2ed7a96d64e --- camera/common/1.0/default/CameraModule.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'camera/common/1.0/default/CameraModule.cpp') diff --git a/camera/common/1.0/default/CameraModule.cpp b/camera/common/1.0/default/CameraModule.cpp index 08354b312d..3e3ef433a5 100644 --- a/camera/common/1.0/default/CameraModule.cpp +++ b/camera/common/1.0/default/CameraModule.cpp @@ -462,6 +462,17 @@ int CameraModule::isStreamCombinationSupported(int cameraId, camera_stream_combi return res; } +void CameraModule::notifyDeviceStateChange(uint64_t deviceState) { + if (getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_5 && + mModule->notify_device_state_change != NULL) { + ATRACE_BEGIN("camera_module->notify_device_state_change"); + ALOGI("%s: calling notify_device_state_change with state %" PRId64, __FUNCTION__, + deviceState); + mModule->notify_device_state_change(deviceState); + ATRACE_END(); + } +} + status_t CameraModule::filterOpenErrorCode(status_t err) { switch(err) { case NO_ERROR: -- cgit v1.2.3 From 892e826a3286a138f246a7e8303051e161a19318 Mon Sep 17 00:00:00 2001 From: Shuzhen Wang Date: Fri, 8 Feb 2019 16:12:30 -0800 Subject: Camera: Handle binder call failure due to static metadata size For physical camera static metadata, we should reduce its size before passing it across binder if possible. Test: Camera CTS Bug: 124129552 Change-Id: I0d9129642ddcbb4c1a1c7fcf7a88bac734be4f5a --- camera/common/1.0/default/CameraModule.cpp | 74 ++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 3 deletions(-) (limited to 'camera/common/1.0/default/CameraModule.cpp') diff --git a/camera/common/1.0/default/CameraModule.cpp b/camera/common/1.0/default/CameraModule.cpp index 3e3ef433a5..467c121a94 100644 --- a/camera/common/1.0/default/CameraModule.cpp +++ b/camera/common/1.0/default/CameraModule.cpp @@ -253,6 +253,14 @@ CameraModule::~CameraModule() } mCameraInfoMap.removeItemsAt(0); } + + while (mPhysicalCameraInfoMap.size() > 0) { + camera_metadata_t* metadata = mPhysicalCameraInfoMap.editValueAt(0); + if (metadata != NULL) { + free_camera_metadata(metadata); + } + mPhysicalCameraInfoMap.removeItemsAt(0); + } } int CameraModule::init() { @@ -351,7 +359,14 @@ int CameraModule::getPhysicalCameraInfo(int physicalCameraId, camera_metadata_t return ret; } - index = mPhysicalCameraInfoMap.add(physicalCameraId, info); + // The camera_metadata_t returned by get_physical_camera_info could be using + // more memory than necessary due to unused reserved space. Reduce the + // size by appending it to a new CameraMetadata object, which internally + // calls resizeIfNeeded. + CameraMetadata m; + m.append(info); + camera_metadata_t* derivedMetadata = m.release(); + index = mPhysicalCameraInfoMap.add(physicalCameraId, derivedMetadata); } assert(index != NAME_NOT_FOUND); @@ -473,6 +488,43 @@ void CameraModule::notifyDeviceStateChange(uint64_t deviceState) { } } +bool CameraModule::isLogicalMultiCamera( + const common::V1_0::helper::CameraMetadata& metadata, + std::unordered_set* physicalCameraIds) { + if (physicalCameraIds == nullptr) { + ALOGE("%s: physicalCameraIds must not be null", __FUNCTION__); + return false; + } + + bool isLogicalMultiCamera = false; + camera_metadata_ro_entry_t capabilities = + metadata.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES); + for (size_t i = 0; i < capabilities.count; i++) { + if (capabilities.data.u8[i] == + ANDROID_REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA) { + isLogicalMultiCamera = true; + break; + } + } + + if (isLogicalMultiCamera) { + camera_metadata_ro_entry_t entry = + metadata.find(ANDROID_LOGICAL_MULTI_CAMERA_PHYSICAL_IDS); + const uint8_t* ids = entry.data.u8; + size_t start = 0; + for (size_t i = 0; i < entry.count; ++i) { + if (ids[i] == '\0') { + if (start != i) { + const char* physicalId = reinterpret_cast(ids+start); + physicalCameraIds->emplace(physicalId); + } + start = i + 1; + } + } + } + return isLogicalMultiCamera; +} + status_t CameraModule::filterOpenErrorCode(status_t err) { switch(err) { case NO_ERROR: @@ -487,8 +539,24 @@ status_t CameraModule::filterOpenErrorCode(status_t err) { } void CameraModule::removeCamera(int cameraId) { - free_camera_metadata(const_cast( - mCameraInfoMap.valueFor(cameraId).static_camera_characteristics)); + std::unordered_set physicalIds; + camera_metadata_t *metadata = const_cast( + mCameraInfoMap.valueFor(cameraId).static_camera_characteristics); + common::V1_0::helper::CameraMetadata hidlMetadata(metadata); + + if (isLogicalMultiCamera(hidlMetadata, &physicalIds)) { + for (const auto& id : physicalIds) { + int idInt = std::stoi(id); + if (mPhysicalCameraInfoMap.indexOfKey(idInt) >= 0) { + free_camera_metadata(mPhysicalCameraInfoMap[idInt]); + mPhysicalCameraInfoMap.removeItem(idInt); + } else { + ALOGE("%s: Cannot find corresponding static metadata for physical id %s", + __FUNCTION__, id.c_str()); + } + } + } + free_camera_metadata(metadata); mCameraInfoMap.removeItem(cameraId); mDeviceVersionMap.removeItem(cameraId); } -- cgit v1.2.3