Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -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_NDEBUG 0 |
| 18 | #define LOG_TAG "ACameraMetadata" |
| 19 | |
| 20 | #include "ACameraMetadata.h" |
| 21 | #include <utils/Vector.h> |
Yin-Chia Yeh | c360382 | 2016-01-18 22:11:19 -0800 | [diff] [blame] | 22 | #include <system/graphics.h> |
| 23 | #include "NdkImage.h" |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 24 | |
| 25 | using namespace android; |
| 26 | |
| 27 | /** |
| 28 | * ACameraMetadata Implementation |
| 29 | */ |
| 30 | ACameraMetadata::ACameraMetadata(camera_metadata_t* buffer, ACAMERA_METADATA_TYPE type) : |
| 31 | mData(buffer), mType(type) { |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 32 | if (mType == ACM_CHARACTERISTICS) { |
| 33 | filterUnsupportedFeatures(); |
Yin-Chia Yeh | c360382 | 2016-01-18 22:11:19 -0800 | [diff] [blame] | 34 | filterStreamConfigurations(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 35 | } |
| 36 | // TODO: filter request/result keys |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | bool |
| 40 | ACameraMetadata::isNdkSupportedCapability(int32_t capability) { |
| 41 | switch (capability) { |
| 42 | case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE: |
| 43 | case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR: |
| 44 | case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_MANUAL_POST_PROCESSING: |
| 45 | case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_RAW: |
| 46 | case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_READ_SENSOR_SETTINGS: |
| 47 | case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BURST_CAPTURE: |
| 48 | case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_DEPTH_OUTPUT: |
| 49 | return true; |
| 50 | case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_YUV_REPROCESSING: |
| 51 | case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_PRIVATE_REPROCESSING: |
| 52 | case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_CONSTRAINED_HIGH_SPEED_VIDEO: |
| 53 | return false; |
| 54 | default: |
| 55 | // Newly defined capabilities will be unsupported by default (blacklist) |
| 56 | // TODO: Should we do whitelist or blacklist here? |
| 57 | ALOGE("%s: Unknonwn capability %d", __FUNCTION__, capability); |
| 58 | return false; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | void |
| 63 | ACameraMetadata::filterUnsupportedFeatures() { |
| 64 | // Hide unsupported capabilities (reprocessing) |
| 65 | camera_metadata_entry entry = mData.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES); |
Yin-Chia Yeh | c360382 | 2016-01-18 22:11:19 -0800 | [diff] [blame] | 66 | if (entry.count == 0 || entry.type != TYPE_BYTE) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 67 | ALOGE("%s: malformed available capability key! count %zu, type %d", |
| 68 | __FUNCTION__, entry.count, entry.type); |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | Vector<uint8_t> capabilities; |
| 73 | capabilities.setCapacity(entry.count); |
| 74 | for (size_t i = 0; i < entry.count; i++) { |
| 75 | uint8_t capability = entry.data.u8[i]; |
| 76 | if (isNdkSupportedCapability(capability)) { |
| 77 | capabilities.push(capability); |
| 78 | } |
| 79 | } |
| 80 | mData.update(ANDROID_REQUEST_AVAILABLE_CAPABILITIES, capabilities); |
Yin-Chia Yeh | c360382 | 2016-01-18 22:11:19 -0800 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | |
| 84 | void |
| 85 | ACameraMetadata::filterStreamConfigurations() { |
| 86 | const int STREAM_CONFIGURATION_SIZE = 4; |
| 87 | const int STREAM_FORMAT_OFFSET = 0; |
| 88 | const int STREAM_WIDTH_OFFSET = 1; |
| 89 | const int STREAM_HEIGHT_OFFSET = 2; |
| 90 | const int STREAM_IS_INPUT_OFFSET = 3; |
| 91 | camera_metadata_entry entry = mData.find(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS); |
| 92 | if (entry.count == 0 || entry.count % 4 || entry.type != TYPE_INT32) { |
| 93 | ALOGE("%s: malformed available stream configuration key! count %zu, type %d", |
| 94 | __FUNCTION__, entry.count, entry.type); |
| 95 | return; |
| 96 | } |
| 97 | |
| 98 | Vector<int32_t> filteredStreamConfigs; |
| 99 | filteredStreamConfigs.setCapacity(entry.count); |
| 100 | |
| 101 | for (size_t i=0; i < entry.count; i += STREAM_CONFIGURATION_SIZE) { |
| 102 | int32_t format = entry.data.i32[i + STREAM_FORMAT_OFFSET]; |
| 103 | int32_t width = entry.data.i32[i + STREAM_WIDTH_OFFSET]; |
| 104 | int32_t height = entry.data.i32[i + STREAM_HEIGHT_OFFSET]; |
| 105 | int32_t isInput = entry.data.i32[i + STREAM_IS_INPUT_OFFSET]; |
| 106 | if (isInput == ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_INPUT) { |
| 107 | // Hide input streams |
| 108 | continue; |
| 109 | } |
| 110 | // Translate HAL formats to NDK format |
| 111 | if (format == HAL_PIXEL_FORMAT_BLOB) { |
| 112 | format = AIMAGE_FORMAT_JPEG; |
| 113 | } |
| 114 | filteredStreamConfigs.push_back(format); |
| 115 | filteredStreamConfigs.push_back(width); |
| 116 | filteredStreamConfigs.push_back(height); |
| 117 | filteredStreamConfigs.push_back(isInput); |
| 118 | } |
| 119 | |
| 120 | mData.update(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS, filteredStreamConfigs); |
| 121 | |
| 122 | entry = mData.find(ANDROID_DEPTH_AVAILABLE_DEPTH_STREAM_CONFIGURATIONS); |
| 123 | Vector<int32_t> filteredDepthStreamConfigs; |
| 124 | filteredDepthStreamConfigs.setCapacity(entry.count); |
| 125 | |
| 126 | for (size_t i=0; i < entry.count; i += STREAM_CONFIGURATION_SIZE) { |
| 127 | int32_t format = entry.data.i32[i + STREAM_FORMAT_OFFSET]; |
| 128 | int32_t width = entry.data.i32[i + STREAM_WIDTH_OFFSET]; |
| 129 | int32_t height = entry.data.i32[i + STREAM_HEIGHT_OFFSET]; |
| 130 | int32_t isInput = entry.data.i32[i + STREAM_IS_INPUT_OFFSET]; |
| 131 | if (isInput == ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_INPUT) { |
| 132 | // Hide input streams |
| 133 | continue; |
| 134 | } |
| 135 | // Translate HAL formats to NDK format |
| 136 | if (format == HAL_PIXEL_FORMAT_BLOB) { |
| 137 | format = AIMAGE_FORMAT_DEPTH_POINT_CLOUD; |
| 138 | } else if (format == HAL_PIXEL_FORMAT_Y16) { |
| 139 | format = AIMAGE_FORMAT_DEPTH16; |
| 140 | } |
| 141 | |
| 142 | filteredDepthStreamConfigs.push_back(format); |
| 143 | filteredDepthStreamConfigs.push_back(width); |
| 144 | filteredDepthStreamConfigs.push_back(height); |
| 145 | filteredDepthStreamConfigs.push_back(isInput); |
| 146 | } |
| 147 | mData.update(ANDROID_DEPTH_AVAILABLE_DEPTH_STREAM_CONFIGURATIONS, filteredDepthStreamConfigs); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | bool |
| 151 | ACameraMetadata::isVendorTag(const uint32_t tag) { |
| 152 | uint32_t tag_section = tag >> 16; |
| 153 | if (tag_section >= VENDOR_SECTION) { |
| 154 | return true; |
| 155 | } |
| 156 | return false; |
| 157 | } |
| 158 | |
| 159 | camera_status_t |
| 160 | ACameraMetadata::getConstEntry(uint32_t tag, ACameraMetadata_const_entry* entry) const { |
| 161 | if (entry == nullptr) { |
| 162 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 163 | } |
| 164 | |
| 165 | camera_metadata_ro_entry rawEntry = mData.find(tag); |
| 166 | if (rawEntry.count == 0) { |
| 167 | ALOGE("%s: cannot find metadata tag %d", __FUNCTION__, tag); |
| 168 | return ACAMERA_ERROR_METADATA_NOT_FOUND; |
| 169 | } |
| 170 | entry->tag = tag; |
| 171 | entry->type = rawEntry.type; |
| 172 | entry->count = rawEntry.count; |
| 173 | entry->data.u8 = rawEntry.data.u8; |
| 174 | return ACAMERA_OK; |
| 175 | } |
| 176 | |
| 177 | camera_status_t |
| 178 | ACameraMetadata::update(uint32_t tag, uint32_t count, const uint8_t* data) { |
| 179 | return updateImpl<uint8_t>(tag, count, data); |
| 180 | } |
| 181 | |
| 182 | camera_status_t |
| 183 | ACameraMetadata::update(uint32_t tag, uint32_t count, const int32_t* data) { |
| 184 | return updateImpl<int32_t>(tag, count, data); |
| 185 | } |
| 186 | |
| 187 | camera_status_t |
| 188 | ACameraMetadata::update(uint32_t tag, uint32_t count, const float* data) { |
| 189 | return updateImpl<float>(tag, count, data); |
| 190 | } |
| 191 | |
| 192 | camera_status_t |
| 193 | ACameraMetadata::update(uint32_t tag, uint32_t count, const double* data) { |
| 194 | return updateImpl<double>(tag, count, data); |
| 195 | } |
| 196 | |
| 197 | camera_status_t |
| 198 | ACameraMetadata::update(uint32_t tag, uint32_t count, const int64_t* data) { |
| 199 | return updateImpl<int64_t>(tag, count, data); |
| 200 | } |
| 201 | |
| 202 | camera_status_t |
| 203 | ACameraMetadata::update(uint32_t tag, uint32_t count, const ACameraMetadata_rational* data) { |
| 204 | return updateImpl<camera_metadata_rational_t>(tag, count, data); |
| 205 | } |
| 206 | |
| 207 | |
| 208 | // TODO: some of key below should be hidden from user |
| 209 | // ex: ACAMERA_REQUEST_ID and ACAMERA_REPROCESS_EFFECTIVE_EXPOSURE_FACTOR |
| 210 | /*@O~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~ |
| 211 | * The key entries below this point are generated from metadata |
| 212 | * definitions in /system/media/camera/docs. Do not modify by hand or |
| 213 | * modify the comment blocks at the start or end. |
| 214 | *~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~*/ |
| 215 | |
| 216 | bool |
| 217 | ACameraMetadata::isCaptureRequestTag(const uint32_t tag) { |
| 218 | // Skip check for vendor keys |
| 219 | if (isVendorTag(tag)) { |
| 220 | return true; |
| 221 | } |
| 222 | |
| 223 | switch (tag) { |
| 224 | case ACAMERA_COLOR_CORRECTION_MODE: |
| 225 | case ACAMERA_COLOR_CORRECTION_TRANSFORM: |
| 226 | case ACAMERA_COLOR_CORRECTION_GAINS: |
| 227 | case ACAMERA_COLOR_CORRECTION_ABERRATION_MODE: |
| 228 | case ACAMERA_CONTROL_AE_ANTIBANDING_MODE: |
| 229 | case ACAMERA_CONTROL_AE_EXPOSURE_COMPENSATION: |
| 230 | case ACAMERA_CONTROL_AE_LOCK: |
| 231 | case ACAMERA_CONTROL_AE_MODE: |
| 232 | case ACAMERA_CONTROL_AE_REGIONS: |
| 233 | case ACAMERA_CONTROL_AE_TARGET_FPS_RANGE: |
| 234 | case ACAMERA_CONTROL_AE_PRECAPTURE_TRIGGER: |
| 235 | case ACAMERA_CONTROL_AF_MODE: |
| 236 | case ACAMERA_CONTROL_AF_REGIONS: |
| 237 | case ACAMERA_CONTROL_AF_TRIGGER: |
| 238 | case ACAMERA_CONTROL_AWB_LOCK: |
| 239 | case ACAMERA_CONTROL_AWB_MODE: |
| 240 | case ACAMERA_CONTROL_AWB_REGIONS: |
| 241 | case ACAMERA_CONTROL_CAPTURE_INTENT: |
| 242 | case ACAMERA_CONTROL_EFFECT_MODE: |
| 243 | case ACAMERA_CONTROL_MODE: |
| 244 | case ACAMERA_CONTROL_SCENE_MODE: |
| 245 | case ACAMERA_CONTROL_VIDEO_STABILIZATION_MODE: |
| 246 | case ACAMERA_CONTROL_POST_RAW_SENSITIVITY_BOOST: |
| 247 | case ACAMERA_EDGE_MODE: |
| 248 | case ACAMERA_FLASH_MODE: |
| 249 | case ACAMERA_HOT_PIXEL_MODE: |
| 250 | case ACAMERA_JPEG_GPS_COORDINATES: |
| 251 | case ACAMERA_JPEG_GPS_PROCESSING_METHOD: |
| 252 | case ACAMERA_JPEG_GPS_TIMESTAMP: |
| 253 | case ACAMERA_JPEG_ORIENTATION: |
| 254 | case ACAMERA_JPEG_QUALITY: |
| 255 | case ACAMERA_JPEG_THUMBNAIL_QUALITY: |
| 256 | case ACAMERA_JPEG_THUMBNAIL_SIZE: |
| 257 | case ACAMERA_LENS_APERTURE: |
| 258 | case ACAMERA_LENS_FILTER_DENSITY: |
| 259 | case ACAMERA_LENS_FOCAL_LENGTH: |
| 260 | case ACAMERA_LENS_FOCUS_DISTANCE: |
| 261 | case ACAMERA_LENS_OPTICAL_STABILIZATION_MODE: |
| 262 | case ACAMERA_NOISE_REDUCTION_MODE: |
| 263 | case ACAMERA_REQUEST_ID: |
| 264 | case ACAMERA_SCALER_CROP_REGION: |
| 265 | case ACAMERA_SENSOR_EXPOSURE_TIME: |
| 266 | case ACAMERA_SENSOR_FRAME_DURATION: |
| 267 | case ACAMERA_SENSOR_SENSITIVITY: |
| 268 | case ACAMERA_SENSOR_TEST_PATTERN_DATA: |
| 269 | case ACAMERA_SENSOR_TEST_PATTERN_MODE: |
| 270 | case ACAMERA_SHADING_MODE: |
| 271 | case ACAMERA_STATISTICS_FACE_DETECT_MODE: |
| 272 | case ACAMERA_STATISTICS_HOT_PIXEL_MAP_MODE: |
| 273 | case ACAMERA_STATISTICS_LENS_SHADING_MAP_MODE: |
| 274 | case ACAMERA_TONEMAP_CURVE_BLUE: |
| 275 | case ACAMERA_TONEMAP_CURVE_GREEN: |
| 276 | case ACAMERA_TONEMAP_CURVE_RED: |
| 277 | case ACAMERA_TONEMAP_MODE: |
| 278 | case ACAMERA_TONEMAP_GAMMA: |
| 279 | case ACAMERA_TONEMAP_PRESET_CURVE: |
| 280 | case ACAMERA_LED_TRANSMIT: |
| 281 | case ACAMERA_BLACK_LEVEL_LOCK: |
| 282 | case ACAMERA_REPROCESS_EFFECTIVE_EXPOSURE_FACTOR: |
| 283 | return true; |
| 284 | default: |
| 285 | return false; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | /*~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~ |
| 290 | * End generated code |
| 291 | *~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~O@*/ |