Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "CameraModule" |
Eino-Ville Talvala | a84bbe6 | 2015-09-08 17:59:17 -0700 | [diff] [blame] | 18 | #define ATRACE_TAG ATRACE_TAG_CAMERA |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 19 | //#define LOG_NDEBUG 0 |
| 20 | |
Eino-Ville Talvala | a84bbe6 | 2015-09-08 17:59:17 -0700 | [diff] [blame] | 21 | #include <utils/Trace.h> |
| 22 | |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 23 | #include "CameraModule.h" |
| 24 | |
| 25 | namespace android { |
| 26 | |
| 27 | void CameraModule::deriveCameraCharacteristicsKeys( |
| 28 | uint32_t deviceVersion, CameraMetadata &chars) { |
Eino-Ville Talvala | a84bbe6 | 2015-09-08 17:59:17 -0700 | [diff] [blame] | 29 | ATRACE_CALL(); |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 30 | |
Yin-Chia Yeh | e9154ce | 2015-12-07 14:38:04 -0800 | [diff] [blame] | 31 | Vector<int32_t> derivedCharKeys; |
Yin-Chia Yeh | 4c06099 | 2016-04-11 17:40:12 -0700 | [diff] [blame] | 32 | Vector<int32_t> derivedRequestKeys; |
| 33 | Vector<int32_t> derivedResultKeys; |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 34 | // Keys added in HAL3.3 |
| 35 | if (deviceVersion < CAMERA_DEVICE_API_VERSION_3_3) { |
| 36 | Vector<uint8_t> controlModes; |
| 37 | uint8_t data = ANDROID_CONTROL_AE_LOCK_AVAILABLE_TRUE; |
| 38 | chars.update(ANDROID_CONTROL_AE_LOCK_AVAILABLE, &data, /*count*/1); |
| 39 | data = ANDROID_CONTROL_AWB_LOCK_AVAILABLE_TRUE; |
| 40 | chars.update(ANDROID_CONTROL_AWB_LOCK_AVAILABLE, &data, /*count*/1); |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 41 | controlModes.push(ANDROID_CONTROL_MODE_AUTO); |
| 42 | camera_metadata_entry entry = chars.find(ANDROID_CONTROL_AVAILABLE_SCENE_MODES); |
| 43 | if (entry.count > 1 || entry.data.u8[0] != ANDROID_CONTROL_SCENE_MODE_DISABLED) { |
| 44 | controlModes.push(ANDROID_CONTROL_MODE_USE_SCENE_MODE); |
| 45 | } |
Zhijun He | 9c5af61 | 2015-05-04 16:34:37 -0700 | [diff] [blame] | 46 | |
| 47 | // Only advertise CONTROL_OFF mode if 3A manual controls are supported. |
| 48 | bool isManualAeSupported = false; |
| 49 | bool isManualAfSupported = false; |
| 50 | bool isManualAwbSupported = false; |
| 51 | entry = chars.find(ANDROID_CONTROL_AE_AVAILABLE_MODES); |
| 52 | if (entry.count > 0) { |
| 53 | for (size_t i = 0; i < entry.count; i++) { |
| 54 | if (entry.data.u8[i] == ANDROID_CONTROL_AE_MODE_OFF) { |
| 55 | isManualAeSupported = true; |
| 56 | break; |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | entry = chars.find(ANDROID_CONTROL_AF_AVAILABLE_MODES); |
| 61 | if (entry.count > 0) { |
| 62 | for (size_t i = 0; i < entry.count; i++) { |
| 63 | if (entry.data.u8[i] == ANDROID_CONTROL_AF_MODE_OFF) { |
| 64 | isManualAfSupported = true; |
| 65 | break; |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | entry = chars.find(ANDROID_CONTROL_AWB_AVAILABLE_MODES); |
| 70 | if (entry.count > 0) { |
| 71 | for (size_t i = 0; i < entry.count; i++) { |
| 72 | if (entry.data.u8[i] == ANDROID_CONTROL_AWB_MODE_OFF) { |
| 73 | isManualAwbSupported = true; |
| 74 | break; |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | if (isManualAeSupported && isManualAfSupported && isManualAwbSupported) { |
| 79 | controlModes.push(ANDROID_CONTROL_MODE_OFF); |
| 80 | } |
| 81 | |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 82 | chars.update(ANDROID_CONTROL_AVAILABLE_MODES, controlModes); |
Yin-Chia Yeh | b28c344 | 2015-05-07 14:43:19 -0700 | [diff] [blame] | 83 | |
Yin-Chia Yeh | 3e28a1a | 2015-05-22 15:03:38 -0700 | [diff] [blame] | 84 | entry = chars.find(ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS); |
| 85 | // HAL3.2 devices passing existing CTS test should all support all LSC modes and LSC map |
| 86 | bool lensShadingModeSupported = false; |
| 87 | if (entry.count > 0) { |
| 88 | for (size_t i = 0; i < entry.count; i++) { |
| 89 | if (entry.data.i32[i] == ANDROID_SHADING_MODE) { |
| 90 | lensShadingModeSupported = true; |
| 91 | break; |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | Vector<uint8_t> lscModes; |
| 96 | Vector<uint8_t> lscMapModes; |
| 97 | lscModes.push(ANDROID_SHADING_MODE_FAST); |
| 98 | lscModes.push(ANDROID_SHADING_MODE_HIGH_QUALITY); |
| 99 | lscMapModes.push(ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF); |
| 100 | if (lensShadingModeSupported) { |
| 101 | lscModes.push(ANDROID_SHADING_MODE_OFF); |
| 102 | lscMapModes.push(ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_ON); |
| 103 | } |
| 104 | chars.update(ANDROID_SHADING_AVAILABLE_MODES, lscModes); |
| 105 | chars.update(ANDROID_STATISTICS_INFO_AVAILABLE_LENS_SHADING_MAP_MODES, lscMapModes); |
| 106 | |
Yin-Chia Yeh | e9154ce | 2015-12-07 14:38:04 -0800 | [diff] [blame] | 107 | derivedCharKeys.push(ANDROID_CONTROL_AE_LOCK_AVAILABLE); |
| 108 | derivedCharKeys.push(ANDROID_CONTROL_AWB_LOCK_AVAILABLE); |
| 109 | derivedCharKeys.push(ANDROID_CONTROL_AVAILABLE_MODES); |
| 110 | derivedCharKeys.push(ANDROID_SHADING_AVAILABLE_MODES); |
| 111 | derivedCharKeys.push(ANDROID_STATISTICS_INFO_AVAILABLE_LENS_SHADING_MAP_MODES); |
Yin-Chia Yeh | 3e28a1a | 2015-05-22 15:03:38 -0700 | [diff] [blame] | 112 | |
Zhijun He | 1fa8999 | 2015-06-01 15:44:31 -0700 | [diff] [blame] | 113 | // Need update android.control.availableHighSpeedVideoConfigurations since HAL3.3 |
| 114 | // adds batch size to this array. |
| 115 | entry = chars.find(ANDROID_CONTROL_AVAILABLE_HIGH_SPEED_VIDEO_CONFIGURATIONS); |
| 116 | if (entry.count > 0) { |
| 117 | Vector<int32_t> highSpeedConfig; |
| 118 | for (size_t i = 0; i < entry.count; i += 4) { |
| 119 | highSpeedConfig.add(entry.data.i32[i]); // width |
| 120 | highSpeedConfig.add(entry.data.i32[i + 1]); // height |
| 121 | highSpeedConfig.add(entry.data.i32[i + 2]); // fps_min |
| 122 | highSpeedConfig.add(entry.data.i32[i + 3]); // fps_max |
| 123 | highSpeedConfig.add(1); // batchSize_max. default to 1 for HAL3.2 |
| 124 | } |
| 125 | chars.update(ANDROID_CONTROL_AVAILABLE_HIGH_SPEED_VIDEO_CONFIGURATIONS, |
| 126 | highSpeedConfig); |
| 127 | } |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 128 | } |
Ruben Brunk | a3b3caa | 2015-06-22 14:26:51 -0700 | [diff] [blame] | 129 | |
Yin-Chia Yeh | e9154ce | 2015-12-07 14:38:04 -0800 | [diff] [blame] | 130 | // Keys added in HAL3.4 |
| 131 | if (deviceVersion < CAMERA_DEVICE_API_VERSION_3_4) { |
| 132 | // Check if HAL supports RAW_OPAQUE output |
| 133 | camera_metadata_entry entry = chars.find(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS); |
| 134 | bool supportRawOpaque = false; |
Yin-Chia Yeh | f1d124e | 2016-01-28 16:32:15 -0800 | [diff] [blame] | 135 | bool supportAnyRaw = false; |
Yin-Chia Yeh | e9154ce | 2015-12-07 14:38:04 -0800 | [diff] [blame] | 136 | const int STREAM_CONFIGURATION_SIZE = 4; |
| 137 | const int STREAM_FORMAT_OFFSET = 0; |
| 138 | const int STREAM_WIDTH_OFFSET = 1; |
| 139 | const int STREAM_HEIGHT_OFFSET = 2; |
| 140 | const int STREAM_IS_INPUT_OFFSET = 3; |
| 141 | Vector<int32_t> rawOpaqueSizes; |
| 142 | |
| 143 | for (size_t i=0; i < entry.count; i += STREAM_CONFIGURATION_SIZE) { |
| 144 | int32_t format = entry.data.i32[i + STREAM_FORMAT_OFFSET]; |
| 145 | int32_t width = entry.data.i32[i + STREAM_WIDTH_OFFSET]; |
| 146 | int32_t height = entry.data.i32[i + STREAM_HEIGHT_OFFSET]; |
| 147 | int32_t isInput = entry.data.i32[i + STREAM_IS_INPUT_OFFSET]; |
| 148 | if (isInput == ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT && |
| 149 | format == HAL_PIXEL_FORMAT_RAW_OPAQUE) { |
| 150 | supportRawOpaque = true; |
| 151 | rawOpaqueSizes.push(width); |
| 152 | rawOpaqueSizes.push(height); |
| 153 | // 2 bytes per pixel. This rough estimation is only used when |
| 154 | // HAL does not fill in the opaque raw size |
| 155 | rawOpaqueSizes.push(width * height *2); |
| 156 | } |
Yin-Chia Yeh | f1d124e | 2016-01-28 16:32:15 -0800 | [diff] [blame] | 157 | if (isInput == ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT && |
| 158 | (format == HAL_PIXEL_FORMAT_RAW16 || |
| 159 | format == HAL_PIXEL_FORMAT_RAW10 || |
| 160 | format == HAL_PIXEL_FORMAT_RAW12 || |
| 161 | format == HAL_PIXEL_FORMAT_RAW_OPAQUE)) { |
| 162 | supportAnyRaw = true; |
| 163 | } |
Yin-Chia Yeh | e9154ce | 2015-12-07 14:38:04 -0800 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | if (supportRawOpaque) { |
| 167 | entry = chars.find(ANDROID_SENSOR_OPAQUE_RAW_SIZE); |
| 168 | if (entry.count == 0) { |
| 169 | // Fill in estimated value if HAL does not list it |
| 170 | chars.update(ANDROID_SENSOR_OPAQUE_RAW_SIZE, rawOpaqueSizes); |
| 171 | derivedCharKeys.push(ANDROID_SENSOR_OPAQUE_RAW_SIZE); |
| 172 | } |
| 173 | } |
Yin-Chia Yeh | f1d124e | 2016-01-28 16:32:15 -0800 | [diff] [blame] | 174 | |
| 175 | // Check if HAL supports any RAW output, if so, fill in postRawSensitivityBoost range |
| 176 | if (supportAnyRaw) { |
| 177 | int32_t defaultRange[2] = {100, 100}; |
| 178 | entry = chars.find(ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST_RANGE); |
| 179 | if (entry.count == 0) { |
| 180 | // Fill in default value (100, 100) |
| 181 | chars.update( |
| 182 | ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST_RANGE, |
| 183 | defaultRange, 2); |
| 184 | derivedCharKeys.push(ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST_RANGE); |
Yin-Chia Yeh | 4c06099 | 2016-04-11 17:40:12 -0700 | [diff] [blame] | 185 | // Actual request/results will be derived by camera device. |
| 186 | derivedRequestKeys.push(ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST); |
| 187 | derivedResultKeys.push(ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST); |
Yin-Chia Yeh | f1d124e | 2016-01-28 16:32:15 -0800 | [diff] [blame] | 188 | } |
| 189 | } |
Yin-Chia Yeh | e9154ce | 2015-12-07 14:38:04 -0800 | [diff] [blame] | 190 | } |
| 191 | |
Ruben Brunk | a3b3caa | 2015-06-22 14:26:51 -0700 | [diff] [blame] | 192 | // Always add a default for the pre-correction active array if the vendor chooses to omit this |
| 193 | camera_metadata_entry entry = chars.find(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE); |
| 194 | if (entry.count == 0) { |
Ruben Brunk | eff134a | 2015-07-17 15:22:01 -0700 | [diff] [blame] | 195 | Vector<int32_t> preCorrectionArray; |
Ruben Brunk | a3b3caa | 2015-06-22 14:26:51 -0700 | [diff] [blame] | 196 | entry = chars.find(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE); |
Ruben Brunk | eff134a | 2015-07-17 15:22:01 -0700 | [diff] [blame] | 197 | preCorrectionArray.appendArray(entry.data.i32, entry.count); |
| 198 | chars.update(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE, preCorrectionArray); |
Yin-Chia Yeh | e9154ce | 2015-12-07 14:38:04 -0800 | [diff] [blame] | 199 | derivedCharKeys.push(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE); |
Ruben Brunk | a3b3caa | 2015-06-22 14:26:51 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Yin-Chia Yeh | e9154ce | 2015-12-07 14:38:04 -0800 | [diff] [blame] | 202 | // Add those newly added keys to AVAILABLE_CHARACTERISTICS_KEYS |
| 203 | // This has to be done at this end of this function. |
Yin-Chia Yeh | 4c06099 | 2016-04-11 17:40:12 -0700 | [diff] [blame] | 204 | if (derivedCharKeys.size() > 0) { |
| 205 | appendAvailableKeys( |
| 206 | chars, ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS, derivedCharKeys); |
Yin-Chia Yeh | e9154ce | 2015-12-07 14:38:04 -0800 | [diff] [blame] | 207 | } |
Yin-Chia Yeh | 4c06099 | 2016-04-11 17:40:12 -0700 | [diff] [blame] | 208 | if (derivedRequestKeys.size() > 0) { |
| 209 | appendAvailableKeys( |
| 210 | chars, ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS, derivedRequestKeys); |
Yin-Chia Yeh | e9154ce | 2015-12-07 14:38:04 -0800 | [diff] [blame] | 211 | } |
Yin-Chia Yeh | 4c06099 | 2016-04-11 17:40:12 -0700 | [diff] [blame] | 212 | if (derivedResultKeys.size() > 0) { |
| 213 | appendAvailableKeys( |
| 214 | chars, ANDROID_REQUEST_AVAILABLE_RESULT_KEYS, derivedResultKeys); |
| 215 | } |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 216 | return; |
| 217 | } |
| 218 | |
Yin-Chia Yeh | 4c06099 | 2016-04-11 17:40:12 -0700 | [diff] [blame] | 219 | void CameraModule::appendAvailableKeys(CameraMetadata &chars, |
| 220 | int32_t keyTag, const Vector<int32_t>& appendKeys) { |
| 221 | camera_metadata_entry entry = chars.find(keyTag); |
| 222 | Vector<int32_t> availableKeys; |
| 223 | availableKeys.setCapacity(entry.count + appendKeys.size()); |
| 224 | for (size_t i = 0; i < entry.count; i++) { |
| 225 | availableKeys.push(entry.data.i32[i]); |
| 226 | } |
| 227 | for (size_t i = 0; i < appendKeys.size(); i++) { |
| 228 | availableKeys.push(appendKeys[i]); |
| 229 | } |
| 230 | chars.update(keyTag, availableKeys); |
| 231 | } |
| 232 | |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 233 | CameraModule::CameraModule(camera_module_t *module) { |
| 234 | if (module == NULL) { |
| 235 | ALOGE("%s: camera hardware module must not be null", __FUNCTION__); |
| 236 | assert(0); |
| 237 | } |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 238 | mModule = module; |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 239 | } |
| 240 | |
Chien-Yu Chen | 944f843 | 2015-07-01 17:08:03 -0700 | [diff] [blame] | 241 | CameraModule::~CameraModule() |
| 242 | { |
| 243 | while (mCameraInfoMap.size() > 0) { |
| 244 | camera_info cameraInfo = mCameraInfoMap.editValueAt(0); |
| 245 | if (cameraInfo.static_camera_characteristics != NULL) { |
| 246 | free_camera_metadata( |
| 247 | const_cast<camera_metadata_t*>(cameraInfo.static_camera_characteristics)); |
| 248 | } |
| 249 | mCameraInfoMap.removeItemsAt(0); |
| 250 | } |
| 251 | } |
| 252 | |
Eino-Ville Talvala | 1527f07 | 2015-04-07 15:55:31 -0700 | [diff] [blame] | 253 | int CameraModule::init() { |
Eino-Ville Talvala | a84bbe6 | 2015-09-08 17:59:17 -0700 | [diff] [blame] | 254 | ATRACE_CALL(); |
| 255 | int res = OK; |
Eino-Ville Talvala | 1527f07 | 2015-04-07 15:55:31 -0700 | [diff] [blame] | 256 | if (getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_4 && |
| 257 | mModule->init != NULL) { |
Eino-Ville Talvala | a84bbe6 | 2015-09-08 17:59:17 -0700 | [diff] [blame] | 258 | ATRACE_BEGIN("camera_module->init"); |
| 259 | res = mModule->init(); |
| 260 | ATRACE_END(); |
Eino-Ville Talvala | 1527f07 | 2015-04-07 15:55:31 -0700 | [diff] [blame] | 261 | } |
Eino-Ville Talvala | a84bbe6 | 2015-09-08 17:59:17 -0700 | [diff] [blame] | 262 | mCameraInfoMap.setCapacity(getNumberOfCameras()); |
| 263 | return res; |
Eino-Ville Talvala | 1527f07 | 2015-04-07 15:55:31 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 266 | int CameraModule::getCameraInfo(int cameraId, struct camera_info *info) { |
Eino-Ville Talvala | a84bbe6 | 2015-09-08 17:59:17 -0700 | [diff] [blame] | 267 | ATRACE_CALL(); |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 268 | Mutex::Autolock lock(mCameraInfoLock); |
Chien-Yu Chen | 676b21b | 2015-02-24 10:28:19 -0800 | [diff] [blame] | 269 | if (cameraId < 0) { |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 270 | ALOGE("%s: Invalid camera ID %d", __FUNCTION__, cameraId); |
| 271 | return -EINVAL; |
| 272 | } |
| 273 | |
Yin-Chia Yeh | b6dc0bf | 2015-02-18 14:42:16 -0800 | [diff] [blame] | 274 | // Only override static_camera_characteristics for API2 devices |
| 275 | int apiVersion = mModule->common.module_api_version; |
| 276 | if (apiVersion < CAMERA_MODULE_API_VERSION_2_0) { |
Eino-Ville Talvala | a84bbe6 | 2015-09-08 17:59:17 -0700 | [diff] [blame] | 277 | int ret; |
| 278 | ATRACE_BEGIN("camera_module->get_camera_info"); |
| 279 | ret = mModule->get_camera_info(cameraId, info); |
Yin-Chia Yeh | 654b4bf | 2015-12-08 12:19:31 -0800 | [diff] [blame] | 280 | // Fill in this so CameraService won't be confused by |
| 281 | // possibly 0 device_version |
| 282 | info->device_version = CAMERA_DEVICE_API_VERSION_1_0; |
Eino-Ville Talvala | a84bbe6 | 2015-09-08 17:59:17 -0700 | [diff] [blame] | 283 | ATRACE_END(); |
| 284 | return ret; |
Yin-Chia Yeh | b6dc0bf | 2015-02-18 14:42:16 -0800 | [diff] [blame] | 285 | } |
| 286 | |
Chien-Yu Chen | 676b21b | 2015-02-24 10:28:19 -0800 | [diff] [blame] | 287 | ssize_t index = mCameraInfoMap.indexOfKey(cameraId); |
| 288 | if (index == NAME_NOT_FOUND) { |
| 289 | // Get camera info from raw module and cache it |
Yin-Chia Yeh | 54298b3 | 2015-03-24 16:51:41 -0700 | [diff] [blame] | 290 | camera_info rawInfo, cameraInfo; |
Eino-Ville Talvala | a84bbe6 | 2015-09-08 17:59:17 -0700 | [diff] [blame] | 291 | ATRACE_BEGIN("camera_module->get_camera_info"); |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 292 | int ret = mModule->get_camera_info(cameraId, &rawInfo); |
Eino-Ville Talvala | a84bbe6 | 2015-09-08 17:59:17 -0700 | [diff] [blame] | 293 | ATRACE_END(); |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 294 | if (ret != 0) { |
| 295 | return ret; |
| 296 | } |
Zhijun He | 9c5af61 | 2015-05-04 16:34:37 -0700 | [diff] [blame] | 297 | int deviceVersion = rawInfo.device_version; |
Eino-Ville Talvala | d309fb9 | 2015-11-25 12:12:45 -0800 | [diff] [blame] | 298 | if (deviceVersion < CAMERA_DEVICE_API_VERSION_3_0) { |
Yin-Chia Yeh | 7768ded | 2015-04-15 12:16:02 -0700 | [diff] [blame] | 299 | // static_camera_characteristics is invalid |
| 300 | *info = rawInfo; |
| 301 | return ret; |
| 302 | } |
Yin-Chia Yeh | 54298b3 | 2015-03-24 16:51:41 -0700 | [diff] [blame] | 303 | CameraMetadata m; |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 304 | m = rawInfo.static_camera_characteristics; |
Yin-Chia Yeh | b6dc0bf | 2015-02-18 14:42:16 -0800 | [diff] [blame] | 305 | deriveCameraCharacteristicsKeys(rawInfo.device_version, m); |
Yin-Chia Yeh | 54298b3 | 2015-03-24 16:51:41 -0700 | [diff] [blame] | 306 | cameraInfo = rawInfo; |
Chien-Yu Chen | 944f843 | 2015-07-01 17:08:03 -0700 | [diff] [blame] | 307 | cameraInfo.static_camera_characteristics = m.release(); |
| 308 | index = mCameraInfoMap.add(cameraId, cameraInfo); |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 309 | } |
Chien-Yu Chen | 676b21b | 2015-02-24 10:28:19 -0800 | [diff] [blame] | 310 | |
| 311 | assert(index != NAME_NOT_FOUND); |
| 312 | // return the cached camera info |
Yin-Chia Yeh | 54298b3 | 2015-03-24 16:51:41 -0700 | [diff] [blame] | 313 | *info = mCameraInfoMap[index]; |
Eino-Ville Talvala | 1527f07 | 2015-04-07 15:55:31 -0700 | [diff] [blame] | 314 | return OK; |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | int CameraModule::open(const char* id, struct hw_device_t** device) { |
Eino-Ville Talvala | a84bbe6 | 2015-09-08 17:59:17 -0700 | [diff] [blame] | 318 | int res; |
| 319 | ATRACE_BEGIN("camera_module->open"); |
| 320 | res = filterOpenErrorCode(mModule->common.methods->open(&mModule->common, id, device)); |
| 321 | ATRACE_END(); |
| 322 | return res; |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | int CameraModule::openLegacy( |
| 326 | const char* id, uint32_t halVersion, struct hw_device_t** device) { |
Eino-Ville Talvala | a84bbe6 | 2015-09-08 17:59:17 -0700 | [diff] [blame] | 327 | int res; |
| 328 | ATRACE_BEGIN("camera_module->open_legacy"); |
| 329 | res = mModule->open_legacy(&mModule->common, id, halVersion, device); |
| 330 | ATRACE_END(); |
| 331 | return res; |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 332 | } |
| 333 | |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 334 | int CameraModule::getNumberOfCameras() { |
Eino-Ville Talvala | a84bbe6 | 2015-09-08 17:59:17 -0700 | [diff] [blame] | 335 | int numCameras; |
| 336 | ATRACE_BEGIN("camera_module->get_number_of_cameras"); |
| 337 | numCameras = mModule->get_number_of_cameras(); |
| 338 | ATRACE_END(); |
| 339 | return numCameras; |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | int CameraModule::setCallbacks(const camera_module_callbacks_t *callbacks) { |
Eino-Ville Talvala | a84bbe6 | 2015-09-08 17:59:17 -0700 | [diff] [blame] | 343 | int res; |
| 344 | ATRACE_BEGIN("camera_module->set_callbacks"); |
| 345 | res = mModule->set_callbacks(callbacks); |
| 346 | ATRACE_END(); |
| 347 | return res; |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | bool CameraModule::isVendorTagDefined() { |
| 351 | return mModule->get_vendor_tag_ops != NULL; |
| 352 | } |
| 353 | |
| 354 | void CameraModule::getVendorTagOps(vendor_tag_ops_t* ops) { |
| 355 | if (mModule->get_vendor_tag_ops) { |
Eino-Ville Talvala | a84bbe6 | 2015-09-08 17:59:17 -0700 | [diff] [blame] | 356 | ATRACE_BEGIN("camera_module->get_vendor_tag_ops"); |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 357 | mModule->get_vendor_tag_ops(ops); |
Eino-Ville Talvala | a84bbe6 | 2015-09-08 17:59:17 -0700 | [diff] [blame] | 358 | ATRACE_END(); |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | |
| 362 | int CameraModule::setTorchMode(const char* camera_id, bool enable) { |
Eino-Ville Talvala | a84bbe6 | 2015-09-08 17:59:17 -0700 | [diff] [blame] | 363 | int res; |
| 364 | ATRACE_BEGIN("camera_module->set_torch_mode"); |
| 365 | res = mModule->set_torch_mode(camera_id, enable); |
| 366 | ATRACE_END(); |
| 367 | return res; |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 368 | } |
| 369 | |
Chien-Yu Chen | d231fd6 | 2015-02-25 16:04:22 -0800 | [diff] [blame] | 370 | status_t CameraModule::filterOpenErrorCode(status_t err) { |
| 371 | switch(err) { |
| 372 | case NO_ERROR: |
| 373 | case -EBUSY: |
| 374 | case -EINVAL: |
| 375 | case -EUSERS: |
| 376 | return err; |
| 377 | default: |
| 378 | break; |
| 379 | } |
| 380 | return -ENODEV; |
| 381 | } |
| 382 | |
Chien-Yu Chen | 676b21b | 2015-02-24 10:28:19 -0800 | [diff] [blame] | 383 | uint16_t CameraModule::getModuleApiVersion() { |
| 384 | return mModule->common.module_api_version; |
| 385 | } |
| 386 | |
| 387 | const char* CameraModule::getModuleName() { |
| 388 | return mModule->common.name; |
| 389 | } |
| 390 | |
| 391 | uint16_t CameraModule::getHalApiVersion() { |
| 392 | return mModule->common.hal_api_version; |
| 393 | } |
| 394 | |
| 395 | const char* CameraModule::getModuleAuthor() { |
| 396 | return mModule->common.author; |
| 397 | } |
| 398 | |
| 399 | void* CameraModule::getDso() { |
| 400 | return mModule->common.dso; |
| 401 | } |
Chien-Yu Chen | d231fd6 | 2015-02-25 16:04:22 -0800 | [diff] [blame] | 402 | |
Yin-Chia Yeh | e074a93 | 2015-01-30 10:29:02 -0800 | [diff] [blame] | 403 | }; // namespace android |