1 /* 2 ** Copyright (c) 2011-2012 The Linux Foundation. All rights reserved. 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 /*#error uncomment this for compiler test!*/ 18 19 #define ALOG_NIDEBUG 0 20 21 #define ALOG_TAG __FILE__ 22 #include <utils/Log.h> 23 #include <utils/threads.h> 24 #include <cutils/properties.h> 25 #include <fcntl.h> 26 #include <sys/mman.h> 27 28 #include <hardware/camera2.h> 29 #include <mm_camera_interface.h> 30 31 32 namespace android { 33 34 35 const uint32_t QCAvailableFormats[4] = { 36 HAL_PIXEL_FORMAT_RAW_SENSOR, 37 HAL_PIXEL_FORMAT_BLOB, 38 HAL_PIXEL_FORMAT_YV12, 39 HAL_PIXEL_FORMAT_YCrCb_420_SP 40 }; 41 42 const uint32_t QCAvailableRawSizes[2] = { 43 640, 480 44 }; 45 46 47 const nsecs_t QCExposureTimeRange[2] = 48 {1000L, 30000000000L} ; // 1 us - 30 sec 49 const nsecs_t QCFrameDurationRange[2] = 50 {33331760L, 30000000000L}; // ~1/30 s - 30 sec 51 const nsecs_t QCMinVerticalBlank = 10000L; 52 53 const uint8_t QCColorFilterArrangement = ANDROID_SENSOR_RGGB; 54 55 // Output image data characteristics 56 const uint32_t QCMaxRawValue = 4000; 57 const uint32_t QCBlackLevel = 1000; 58 59 const uint64_t QCAvailableRawMinDurations[1] = { 60 QCFrameDurationRange[0] 61 }; 62 63 const uint32_t QCAvailableProcessedSizes[4] = { 64 640, 480, 320, 240 65 // Sensor::kResolution[0], Sensor::kResolution[1] 66 }; 67 68 const uint64_t QCAvailableProcessedMinDurations[1] = { 69 QCFrameDurationRange[0] 70 }; 71 72 73 const uint32_t QCAvailableJpegSizes[2] = { 74 640, 480 75 // Sensor::kResolution[0], Sensor::kResolution[1] 76 }; 77 78 const uint64_t QCAvailableJpegMinDurations[1] = { 79 QCFrameDurationRange[0] 80 }; 81 82 static status_t addOrSize(camera_metadata_t *request, 83 bool sizeRequest, 84 size_t *entryCount, 85 size_t *dataCount, 86 uint32_t tag, 87 const void *entryData, 88 size_t entryDataCount) { 89 status_t res; 90 if (!sizeRequest) { 91 return add_camera_metadata_entry(request, tag, entryData, 92 entryDataCount); 93 } else { 94 int type = get_camera_metadata_tag_type(tag); 95 if (type < 0 ) return BAD_VALUE; 96 (*entryCount)++; 97 (*dataCount) += calculate_camera_metadata_entry_data_size(type, 98 entryDataCount); 99 return OK; 100 } 101 } 102 103 extern "C" status_t getStaticInfo(camera_metadata_t **info, 104 mm_camera_vtbl_t *camera_vtbl, bool sizeRequest) 105 { 106 size_t entryCount = 0; 107 size_t dataCount = 0; 108 status_t ret; 109 110 if(!camera_vtbl) return BAD_VALUE; 111 112 bool mFacingBack = (camera_vtbl->camera_info->camera_info.position==BACK_CAMERA)? 113 true:false; 114 115 #define ADD_OR_SIZE( tag, data, count ) \ 116 if ( ( ret = addOrSize(*info, sizeRequest, &entryCount, &dataCount, \ 117 tag, data, count) ) != OK ) return ret 118 119 // android.lens 120 121 static float minFocusDistance = 0; 122 ADD_OR_SIZE(ANDROID_LENS_MINIMUM_FOCUS_DISTANCE, 123 &minFocusDistance, 1); 124 ADD_OR_SIZE(ANDROID_LENS_HYPERFOCAL_DISTANCE, 125 &minFocusDistance, 1); 126 127 static float focalLength = 0.0f; 128 camera_vtbl->ops->get_parm(camera_vtbl->camera_handle, 129 MM_CAMERA_PARM_FOCAL_LENGTH, 130 (void *)&focalLength); 131 ADD_OR_SIZE(ANDROID_LENS_AVAILABLE_FOCAL_LENGTHS, 132 &focalLength, 1); 133 134 static float aperture = 2.8f; 135 camera_vtbl->ops->get_parm(camera_vtbl->camera_handle, 136 MM_CAMERA_PARM_APERTURE, 137 (void *)&aperture); 138 ADD_OR_SIZE(ANDROID_LENS_AVAILABLE_APERTURES, 139 &aperture, 1); 140 141 static float filterDensity = 0; 142 ADD_OR_SIZE(ANDROID_LENS_AVAILABLE_FILTER_DENSITY, 143 &filterDensity, 1); 144 145 static const uint8_t availableOpticalStabilization = 146 ANDROID_LENS_OPTICAL_STABILIZATION_OFF; 147 ADD_OR_SIZE(ANDROID_LENS_AVAILABLE_OPTICAL_STABILIZATION, 148 &availableOpticalStabilization, 1); 149 150 static const int32_t lensShadingMapSize[] = {1, 1}; 151 ADD_OR_SIZE(ANDROID_LENS_SHADING_MAP_SIZE, lensShadingMapSize, 152 sizeof(lensShadingMapSize)/sizeof(int32_t)); 153 154 static const float lensShadingMap[3 * 1 * 1 ] = 155 { 1.f, 1.f, 1.f }; 156 ADD_OR_SIZE(ANDROID_LENS_SHADING_MAP, lensShadingMap, 157 sizeof(lensShadingMap)/sizeof(float)); 158 159 // Identity transform 160 static const int32_t geometricCorrectionMapSize[] = {2, 2}; 161 ADD_OR_SIZE(ANDROID_LENS_GEOMETRIC_CORRECTION_MAP_SIZE, 162 geometricCorrectionMapSize, 163 sizeof(geometricCorrectionMapSize)/sizeof(int32_t)); 164 165 static const float geometricCorrectionMap[2 * 3 * 2 * 2] = { 166 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 167 1.f, 0.f, 1.f, 0.f, 1.f, 0.f, 168 0.f, 1.f, 0.f, 1.f, 0.f, 1.f, 169 1.f, 1.f, 1.f, 1.f, 1.f, 1.f}; 170 ADD_OR_SIZE(ANDROID_LENS_GEOMETRIC_CORRECTION_MAP, 171 geometricCorrectionMap, 172 sizeof(geometricCorrectionMap)/sizeof(float)); 173 174 int32_t lensFacing = mFacingBack ? 175 ANDROID_LENS_FACING_BACK : ANDROID_LENS_FACING_FRONT; 176 ADD_OR_SIZE(ANDROID_LENS_FACING, &lensFacing, 1); 177 178 float lensPosition[3]; 179 if (mFacingBack) { 180 // Back-facing camera is center-top on device 181 lensPosition[0] = 0; 182 lensPosition[1] = 20; 183 lensPosition[2] = -5; 184 } else { 185 // Front-facing camera is center-right on device 186 lensPosition[0] = 20; 187 lensPosition[1] = 20; 188 lensPosition[2] = 0; 189 } 190 ADD_OR_SIZE(ANDROID_LENS_POSITION, lensPosition, sizeof(lensPosition)/ 191 sizeof(float)); 192 193 #if 0 194 // android.sensor 195 196 ADD_OR_SIZE(ANDROID_SENSOR_EXPOSURE_TIME_RANGE, 197 QCExposureTimeRange, 2); 198 199 ADD_OR_SIZE(ANDROID_SENSOR_MAX_FRAME_DURATION, 200 &QCFrameDurationRange[1], 1); 201 202 ADD_OR_SIZE(ANDROID_SENSOR_AVAILABLE_SENSITIVITIES, 203 QCAvailableSensitivities, 204 sizeof(QCAvailableSensitivities) 205 /sizeof(uint32_t)); 206 207 ADD_OR_SIZE(ANDROID_SENSOR_COLOR_FILTER_ARRANGEMENT, 208 &QCColorFilterArrangement, 1); 209 #endif 210 static const float sensorPhysicalSize[2] = {3.20f, 2.40f}; // mm 211 ADD_OR_SIZE(ANDROID_SENSOR_PHYSICAL_SIZE, 212 sensorPhysicalSize, 2); 213 214 const unsigned int kResolution[2] = {640, 480}; 215 ADD_OR_SIZE(ANDROID_SENSOR_PIXEL_ARRAY_SIZE, 216 kResolution, 2); 217 218 ADD_OR_SIZE(ANDROID_SENSOR_ACTIVE_ARRAY_SIZE, 219 kResolution, 2); 220 221 #if 0 222 ADD_OR_SIZE(ANDROID_SENSOR_WHITE_LEVEL, 223 &QCMaxRawValue, 1); 224 225 static const int32_t blackLevelPattern[4] = { 226 QCBlackLevel, QCBlackLevel, 227 QCBlackLevel, QCBlackLevel 228 }; 229 ADD_OR_SIZE(ANDROID_SENSOR_BLACK_LEVEL_PATTERN, 230 blackLevelPattern, sizeof(blackLevelPattern)/sizeof(int32_t)); 231 232 #endif 233 //TODO: sensor color calibration fields 234 235 // android.flash 236 static const uint8_t flashAvailable = 0; 237 ADD_OR_SIZE(ANDROID_FLASH_AVAILABLE, &flashAvailable, 1); 238 239 static const int64_t flashChargeDuration = 0; 240 ADD_OR_SIZE(ANDROID_FLASH_CHARGE_DURATION, &flashChargeDuration, 1); 241 242 // android.tonemap 243 244 static const int32_t tonemapCurvePoints = 128; 245 ADD_OR_SIZE(ANDROID_TONEMAP_MAX_CURVE_POINTS, &tonemapCurvePoints, 1); 246 247 #if 1 248 // android.scaler 249 ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_FORMATS, 250 QCAvailableFormats, 251 sizeof(QCAvailableFormats)/sizeof(uint32_t)); 252 253 ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_RAW_SIZES, 254 QCAvailableRawSizes, 255 sizeof(QCAvailableRawSizes)/sizeof(uint32_t)); 256 257 ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_RAW_MIN_DURATIONS, 258 QCAvailableRawMinDurations, 259 sizeof(QCAvailableRawMinDurations)/sizeof(uint64_t)); 260 261 ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_PROCESSED_SIZES, 262 QCAvailableProcessedSizes, 263 sizeof(QCAvailableProcessedSizes)/sizeof(uint32_t)); 264 265 ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_PROCESSED_MIN_DURATIONS, 266 QCAvailableProcessedMinDurations, 267 sizeof(QCAvailableProcessedMinDurations)/sizeof(uint64_t)); 268 269 ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_JPEG_SIZES, 270 QCAvailableJpegSizes, 271 sizeof(QCAvailableJpegSizes)/sizeof(uint32_t)); 272 273 ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_JPEG_MIN_DURATIONS, 274 QCAvailableJpegMinDurations, 275 sizeof(QCAvailableJpegMinDurations)/sizeof(uint64_t)); 276 277 static const float maxZoom = 10; 278 ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_MAX_ZOOM, 279 &maxZoom, 1); 280 281 // android.jpeg 282 283 static const int32_t jpegThumbnailSizes[] = { 284 160, 120, 285 320, 240 286 }; 287 ADD_OR_SIZE(ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES, 288 jpegThumbnailSizes, sizeof(jpegThumbnailSizes)/sizeof(int32_t)); 289 290 static const int32_t jpegMaxSize = 300000; 291 ADD_OR_SIZE(ANDROID_JPEG_MAX_SIZE, &jpegMaxSize, 1); 292 293 // android.stats 294 295 static const uint8_t availableFaceDetectModes[] = { 296 ANDROID_STATS_FACE_DETECTION_OFF 297 }; 298 ADD_OR_SIZE(ANDROID_STATS_AVAILABLE_FACE_DETECT_MODES, 299 availableFaceDetectModes, 300 sizeof(availableFaceDetectModes)); 301 302 static const int32_t maxFaceCount = 0; 303 ADD_OR_SIZE(ANDROID_STATS_MAX_FACE_COUNT, 304 &maxFaceCount, 1); 305 306 static const int32_t histogramSize = 64; 307 ADD_OR_SIZE(ANDROID_STATS_HISTOGRAM_BUCKET_COUNT, 308 &histogramSize, 1); 309 310 static const int32_t maxHistogramCount = 1000; 311 ADD_OR_SIZE(ANDROID_STATS_MAX_HISTOGRAM_COUNT, 312 &maxHistogramCount, 1); 313 314 static const int32_t sharpnessMapSize[2] = {64, 64}; 315 ADD_OR_SIZE(ANDROID_STATS_SHARPNESS_MAP_SIZE, 316 sharpnessMapSize, sizeof(sharpnessMapSize)/sizeof(int32_t)); 317 318 static const int32_t maxSharpnessMapValue = 1000; 319 ADD_OR_SIZE(ANDROID_STATS_MAX_SHARPNESS_MAP_VALUE, 320 &maxSharpnessMapValue, 1); 321 322 // android.control 323 324 static const uint8_t availableSceneModes[] = { 325 ANDROID_CONTROL_SCENE_MODE_UNSUPPORTED 326 }; 327 ADD_OR_SIZE(ANDROID_CONTROL_AVAILABLE_SCENE_MODES, 328 availableSceneModes, sizeof(availableSceneModes)); 329 330 static const uint8_t availableEffects[] = { 331 ANDROID_CONTROL_EFFECT_OFF 332 }; 333 ADD_OR_SIZE(ANDROID_CONTROL_AVAILABLE_EFFECTS, 334 availableEffects, sizeof(availableEffects)); 335 336 int32_t max3aRegions = 0; 337 ADD_OR_SIZE(ANDROID_CONTROL_MAX_REGIONS, 338 &max3aRegions, 1); 339 340 static const uint8_t availableAeModes[] = { 341 ANDROID_CONTROL_AE_OFF, 342 ANDROID_CONTROL_AE_ON 343 }; 344 ADD_OR_SIZE(ANDROID_CONTROL_AE_AVAILABLE_MODES, 345 availableAeModes, sizeof(availableAeModes)); 346 347 static const camera_metadata_rational exposureCompensationStep = { 348 1, 3 349 }; 350 ADD_OR_SIZE(ANDROID_CONTROL_AE_EXP_COMPENSATION_STEP, 351 &exposureCompensationStep, 1); 352 353 int32_t exposureCompensationRange[] = {-9, 9}; 354 ADD_OR_SIZE(ANDROID_CONTROL_AE_EXP_COMPENSATION_RANGE, 355 exposureCompensationRange, 356 sizeof(exposureCompensationRange)/sizeof(int32_t)); 357 358 static const int32_t availableTargetFpsRanges[] = { 359 5, 30, 15, 30 360 }; 361 ADD_OR_SIZE(ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, 362 availableTargetFpsRanges, 363 sizeof(availableTargetFpsRanges)/sizeof(int32_t)); 364 365 static const uint8_t availableAntibandingModes[] = { 366 ANDROID_CONTROL_AE_ANTIBANDING_OFF, 367 ANDROID_CONTROL_AE_ANTIBANDING_AUTO 368 }; 369 ADD_OR_SIZE(ANDROID_CONTROL_AE_AVAILABLE_ANTIBANDING_MODES, 370 availableAntibandingModes, sizeof(availableAntibandingModes)); 371 372 static const uint8_t availableAwbModes[] = { 373 ANDROID_CONTROL_AWB_OFF, 374 ANDROID_CONTROL_AWB_AUTO, 375 ANDROID_CONTROL_AWB_INCANDESCENT, 376 ANDROID_CONTROL_AWB_FLUORESCENT, 377 ANDROID_CONTROL_AWB_DAYLIGHT, 378 ANDROID_CONTROL_AWB_SHADE 379 }; 380 ADD_OR_SIZE(ANDROID_CONTROL_AWB_AVAILABLE_MODES, 381 availableAwbModes, sizeof(availableAwbModes)); 382 383 static const uint8_t availableAfModes[] = { 384 ANDROID_CONTROL_AF_OFF 385 }; 386 ADD_OR_SIZE(ANDROID_CONTROL_AF_AVAILABLE_MODES, 387 availableAfModes, sizeof(availableAfModes)); 388 389 static const uint8_t availableVstabModes[] = { 390 ANDROID_CONTROL_VIDEO_STABILIZATION_OFF 391 }; 392 ADD_OR_SIZE(ANDROID_CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES, 393 availableVstabModes, sizeof(availableVstabModes)); 394 #endif 395 #undef ADD_OR_SIZE 396 /** Allocate metadata if sizing */ 397 if (sizeRequest) { 398 ALOGV("Allocating %d entries, %d extra bytes for " 399 "static camera info", 400 entryCount, dataCount); 401 *info = allocate_camera_metadata(entryCount, dataCount); 402 if (*info == NULL) { 403 ALOGE("Unable to allocate camera static info" 404 "(%d entries, %d bytes extra data)", 405 entryCount, dataCount); 406 return NO_MEMORY; 407 } 408 } 409 return OK; 410 } 411 412 extern "C" status_t constructDefaultRequest(int request_template, 413 camera_metadata_t **request, bool sizeRequest) 414 { 415 size_t entryCount = 0; 416 size_t dataCount = 0; 417 status_t ret; 418 419 #define ADD_OR_SIZE( tag, data, count ) \ 420 if ( ( ret = addOrSize(*request, sizeRequest, &entryCount, &dataCount, \ 421 tag, data, count) ) != OK ) return ret 422 423 static const int64_t USEC = 1000LL; 424 static const int64_t MSEC = USEC * 1000LL; 425 static const int64_t SEC = MSEC * 1000LL; 426 427 /** android.request */ 428 429 static const uint8_t metadataMode = ANDROID_REQUEST_METADATA_NONE; 430 ADD_OR_SIZE(ANDROID_REQUEST_METADATA_MODE, &metadataMode, 1); 431 432 static const int32_t id = 0; 433 ADD_OR_SIZE(ANDROID_REQUEST_ID, &id, 1); 434 435 static const int32_t frameCount = 0; 436 ADD_OR_SIZE(ANDROID_REQUEST_FRAME_COUNT, &frameCount, 1); 437 438 // OUTPUT_STREAMS set by user 439 entryCount += 1; 440 dataCount += 5; // TODO: Should be maximum stream number 441 442 /** android.lens */ 443 444 static const float focusDistance = 0; 445 ADD_OR_SIZE(ANDROID_LENS_FOCUS_DISTANCE, &focusDistance, 1); 446 447 static const float aperture = 2.8f; 448 ADD_OR_SIZE(ANDROID_LENS_APERTURE, &aperture, 1); 449 450 static const float focalLength = 5.0f; 451 ADD_OR_SIZE(ANDROID_LENS_FOCAL_LENGTH, &focalLength, 1); 452 453 static const float filterDensity = 0; 454 ADD_OR_SIZE(ANDROID_LENS_FILTER_DENSITY, &filterDensity, 1); 455 456 static const uint8_t opticalStabilizationMode = 457 ANDROID_LENS_OPTICAL_STABILIZATION_OFF; 458 ADD_OR_SIZE(ANDROID_LENS_OPTICAL_STABILIZATION_MODE, 459 &opticalStabilizationMode, 1); 460 461 // FOCUS_RANGE set only in frame 462 463 /** android.sensor */ 464 465 static const int64_t exposureTime = 10 * MSEC; 466 ADD_OR_SIZE(ANDROID_SENSOR_EXPOSURE_TIME, &exposureTime, 1); 467 468 static const int64_t frameDuration = 33333333L; // 1/30 s 469 ADD_OR_SIZE(ANDROID_SENSOR_FRAME_DURATION, &frameDuration, 1); 470 471 static const int32_t sensitivity = 100; 472 ADD_OR_SIZE(ANDROID_SENSOR_SENSITIVITY, &sensitivity, 1); 473 474 // TIMESTAMP set only in frame 475 476 /** android.flash */ 477 478 static const uint8_t flashMode = ANDROID_FLASH_OFF; 479 ADD_OR_SIZE(ANDROID_FLASH_MODE, &flashMode, 1); 480 481 static const uint8_t flashPower = 10; 482 ADD_OR_SIZE(ANDROID_FLASH_FIRING_POWER, &flashPower, 1); 483 484 static const int64_t firingTime = 0; 485 ADD_OR_SIZE(ANDROID_FLASH_FIRING_TIME, &firingTime, 1); 486 487 /** Processing block modes */ 488 uint8_t hotPixelMode = 0; 489 uint8_t demosaicMode = 0; 490 uint8_t noiseMode = 0; 491 uint8_t shadingMode = 0; 492 uint8_t geometricMode = 0; 493 uint8_t colorMode = 0; 494 uint8_t tonemapMode = 0; 495 uint8_t edgeMode = 0; 496 switch (request_template) { 497 case CAMERA2_TEMPLATE_PREVIEW: 498 hotPixelMode = ANDROID_PROCESSING_FAST; 499 demosaicMode = ANDROID_PROCESSING_FAST; 500 noiseMode = ANDROID_PROCESSING_FAST; 501 shadingMode = ANDROID_PROCESSING_FAST; 502 geometricMode = ANDROID_PROCESSING_FAST; 503 colorMode = ANDROID_PROCESSING_FAST; 504 tonemapMode = ANDROID_PROCESSING_FAST; 505 edgeMode = ANDROID_PROCESSING_FAST; 506 break; 507 case CAMERA2_TEMPLATE_STILL_CAPTURE: 508 hotPixelMode = ANDROID_PROCESSING_HIGH_QUALITY; 509 demosaicMode = ANDROID_PROCESSING_HIGH_QUALITY; 510 noiseMode = ANDROID_PROCESSING_HIGH_QUALITY; 511 shadingMode = ANDROID_PROCESSING_HIGH_QUALITY; 512 geometricMode = ANDROID_PROCESSING_HIGH_QUALITY; 513 colorMode = ANDROID_PROCESSING_HIGH_QUALITY; 514 tonemapMode = ANDROID_PROCESSING_HIGH_QUALITY; 515 edgeMode = ANDROID_PROCESSING_HIGH_QUALITY; 516 break; 517 case CAMERA2_TEMPLATE_VIDEO_RECORD: 518 hotPixelMode = ANDROID_PROCESSING_FAST; 519 demosaicMode = ANDROID_PROCESSING_FAST; 520 noiseMode = ANDROID_PROCESSING_FAST; 521 shadingMode = ANDROID_PROCESSING_FAST; 522 geometricMode = ANDROID_PROCESSING_FAST; 523 colorMode = ANDROID_PROCESSING_FAST; 524 tonemapMode = ANDROID_PROCESSING_FAST; 525 edgeMode = ANDROID_PROCESSING_FAST; 526 break; 527 case CAMERA2_TEMPLATE_VIDEO_SNAPSHOT: 528 hotPixelMode = ANDROID_PROCESSING_HIGH_QUALITY; 529 demosaicMode = ANDROID_PROCESSING_HIGH_QUALITY; 530 noiseMode = ANDROID_PROCESSING_HIGH_QUALITY; 531 shadingMode = ANDROID_PROCESSING_HIGH_QUALITY; 532 geometricMode = ANDROID_PROCESSING_HIGH_QUALITY; 533 colorMode = ANDROID_PROCESSING_HIGH_QUALITY; 534 tonemapMode = ANDROID_PROCESSING_HIGH_QUALITY; 535 edgeMode = ANDROID_PROCESSING_HIGH_QUALITY; 536 break; 537 case CAMERA2_TEMPLATE_ZERO_SHUTTER_LAG: 538 hotPixelMode = ANDROID_PROCESSING_HIGH_QUALITY; 539 demosaicMode = ANDROID_PROCESSING_HIGH_QUALITY; 540 noiseMode = ANDROID_PROCESSING_HIGH_QUALITY; 541 shadingMode = ANDROID_PROCESSING_HIGH_QUALITY; 542 geometricMode = ANDROID_PROCESSING_HIGH_QUALITY; 543 colorMode = ANDROID_PROCESSING_HIGH_QUALITY; 544 tonemapMode = ANDROID_PROCESSING_HIGH_QUALITY; 545 edgeMode = ANDROID_PROCESSING_HIGH_QUALITY; 546 break; 547 default: 548 hotPixelMode = ANDROID_PROCESSING_FAST; 549 demosaicMode = ANDROID_PROCESSING_FAST; 550 noiseMode = ANDROID_PROCESSING_FAST; 551 shadingMode = ANDROID_PROCESSING_FAST; 552 geometricMode = ANDROID_PROCESSING_FAST; 553 colorMode = ANDROID_PROCESSING_FAST; 554 tonemapMode = ANDROID_PROCESSING_FAST; 555 edgeMode = ANDROID_PROCESSING_FAST; 556 break; 557 } 558 ADD_OR_SIZE(ANDROID_HOT_PIXEL_MODE, &hotPixelMode, 1); 559 ADD_OR_SIZE(ANDROID_DEMOSAIC_MODE, &demosaicMode, 1); 560 ADD_OR_SIZE(ANDROID_NOISE_MODE, &noiseMode, 1); 561 ADD_OR_SIZE(ANDROID_SHADING_MODE, &shadingMode, 1); 562 ADD_OR_SIZE(ANDROID_GEOMETRIC_MODE, &geometricMode, 1); 563 ADD_OR_SIZE(ANDROID_COLOR_MODE, &colorMode, 1); 564 ADD_OR_SIZE(ANDROID_TONEMAP_MODE, &tonemapMode, 1); 565 ADD_OR_SIZE(ANDROID_EDGE_MODE, &edgeMode, 1); 566 567 /** android.noise */ 568 static const uint8_t noiseStrength = 5; 569 ADD_OR_SIZE(ANDROID_NOISE_STRENGTH, &noiseStrength, 1); 570 571 /** android.color */ 572 static const float colorTransform[9] = { 573 1.0f, 0.f, 0.f, 574 0.f, 1.f, 0.f, 575 0.f, 0.f, 1.f 576 }; 577 ADD_OR_SIZE(ANDROID_COLOR_TRANSFORM, colorTransform, 9); 578 579 /** android.tonemap */ 580 static const float tonemapCurve[4] = { 581 0.f, 0.f, 582 1.f, 1.f 583 }; 584 ADD_OR_SIZE(ANDROID_TONEMAP_CURVE_RED, tonemapCurve, 4); 585 ADD_OR_SIZE(ANDROID_TONEMAP_CURVE_GREEN, tonemapCurve, 4); 586 ADD_OR_SIZE(ANDROID_TONEMAP_CURVE_BLUE, tonemapCurve, 4); 587 588 /** android.edge */ 589 static const uint8_t edgeStrength = 5; 590 ADD_OR_SIZE(ANDROID_EDGE_STRENGTH, &edgeStrength, 1); 591 592 /** android.scaler */ 593 static const int32_t cropRegion[3] = { 594 0, 0, /*kResolution[0]*/ 595 }; 596 ADD_OR_SIZE(ANDROID_SCALER_CROP_REGION, cropRegion, 3); 597 598 /** android.jpeg */ 599 static const int32_t jpegQuality = 80; 600 ADD_OR_SIZE(ANDROID_JPEG_QUALITY, &jpegQuality, 1); 601 602 static const int32_t thumbnailSize[2] = { 603 640, 480 604 }; 605 ADD_OR_SIZE(ANDROID_JPEG_THUMBNAIL_SIZE, thumbnailSize, 2); 606 607 static const int32_t thumbnailQuality = 80; 608 ADD_OR_SIZE(ANDROID_JPEG_THUMBNAIL_QUALITY, &thumbnailQuality, 1); 609 610 static const double gpsCoordinates[2] = { 611 0, 0 612 }; 613 ADD_OR_SIZE(ANDROID_JPEG_GPS_COORDINATES, gpsCoordinates, 2); 614 615 static const uint8_t gpsProcessingMethod[32] = "None"; 616 ADD_OR_SIZE(ANDROID_JPEG_GPS_PROCESSING_METHOD, gpsProcessingMethod, 32); 617 618 static const int64_t gpsTimestamp = 0; 619 ADD_OR_SIZE(ANDROID_JPEG_GPS_TIMESTAMP, &gpsTimestamp, 1); 620 621 static const int32_t jpegOrientation = 0; 622 ADD_OR_SIZE(ANDROID_JPEG_ORIENTATION, &jpegOrientation, 1); 623 624 /** android.stats */ 625 626 static const uint8_t faceDetectMode = ANDROID_STATS_FACE_DETECTION_OFF; 627 ADD_OR_SIZE(ANDROID_STATS_FACE_DETECT_MODE, &faceDetectMode, 1); 628 629 static const uint8_t histogramMode = ANDROID_STATS_OFF; 630 ADD_OR_SIZE(ANDROID_STATS_HISTOGRAM_MODE, &histogramMode, 1); 631 632 static const uint8_t sharpnessMapMode = ANDROID_STATS_OFF; 633 ADD_OR_SIZE(ANDROID_STATS_SHARPNESS_MAP_MODE, &sharpnessMapMode, 1); 634 635 // faceRectangles, faceScores, faceLandmarks, faceIds, histogram, 636 // sharpnessMap only in frames 637 638 /** android.control */ 639 640 uint8_t controlIntent = 0; 641 switch (request_template) { 642 case CAMERA2_TEMPLATE_PREVIEW: 643 controlIntent = ANDROID_CONTROL_INTENT_PREVIEW; 644 break; 645 case CAMERA2_TEMPLATE_STILL_CAPTURE: 646 controlIntent = ANDROID_CONTROL_INTENT_STILL_CAPTURE; 647 break; 648 case CAMERA2_TEMPLATE_VIDEO_RECORD: 649 controlIntent = ANDROID_CONTROL_INTENT_VIDEO_RECORD; 650 break; 651 case CAMERA2_TEMPLATE_VIDEO_SNAPSHOT: 652 controlIntent = ANDROID_CONTROL_INTENT_VIDEO_SNAPSHOT; 653 break; 654 case CAMERA2_TEMPLATE_ZERO_SHUTTER_LAG: 655 controlIntent = ANDROID_CONTROL_INTENT_ZERO_SHUTTER_LAG; 656 break; 657 default: 658 controlIntent = ANDROID_CONTROL_INTENT_CUSTOM; 659 break; 660 } 661 ADD_OR_SIZE(ANDROID_CONTROL_CAPTURE_INTENT, &controlIntent, 1); 662 663 static const uint8_t controlMode = ANDROID_CONTROL_AUTO; 664 ADD_OR_SIZE(ANDROID_CONTROL_MODE, &controlMode, 1); 665 666 static const uint8_t effectMode = ANDROID_CONTROL_EFFECT_OFF; 667 ADD_OR_SIZE(ANDROID_CONTROL_EFFECT_MODE, &effectMode, 1); 668 669 static const uint8_t sceneMode = ANDROID_CONTROL_SCENE_MODE_FACE_PRIORITY; 670 ADD_OR_SIZE(ANDROID_CONTROL_SCENE_MODE, &sceneMode, 1); 671 672 static const uint8_t aeMode = ANDROID_CONTROL_AE_ON_AUTO_FLASH; 673 ADD_OR_SIZE(ANDROID_CONTROL_AE_MODE, &aeMode, 1); 674 675 const unsigned int kResolution[2] = {640, 480}; 676 static const int32_t controlRegions[5] = { 677 0, 0, kResolution[0], kResolution[1], 1000 678 }; 679 ADD_OR_SIZE(ANDROID_CONTROL_AE_REGIONS, controlRegions, 5); 680 681 static const int32_t aeExpCompensation = 0; 682 ADD_OR_SIZE(ANDROID_CONTROL_AE_EXP_COMPENSATION, &aeExpCompensation, 1); 683 684 static const int32_t aeTargetFpsRange[2] = { 685 10, 30 686 }; 687 ADD_OR_SIZE(ANDROID_CONTROL_AE_TARGET_FPS_RANGE, aeTargetFpsRange, 2); 688 689 static const uint8_t aeAntibandingMode = 690 ANDROID_CONTROL_AE_ANTIBANDING_AUTO; 691 ADD_OR_SIZE(ANDROID_CONTROL_AE_ANTIBANDING_MODE, &aeAntibandingMode, 1); 692 693 static const uint8_t awbMode = 694 ANDROID_CONTROL_AWB_AUTO; 695 ADD_OR_SIZE(ANDROID_CONTROL_AWB_MODE, &awbMode, 1); 696 697 ADD_OR_SIZE(ANDROID_CONTROL_AWB_REGIONS, controlRegions, 5); 698 699 uint8_t afMode = 0; 700 switch (request_template) { 701 case CAMERA2_TEMPLATE_PREVIEW: 702 afMode = ANDROID_CONTROL_AF_AUTO; 703 break; 704 case CAMERA2_TEMPLATE_STILL_CAPTURE: 705 afMode = ANDROID_CONTROL_AF_AUTO; 706 break; 707 case CAMERA2_TEMPLATE_VIDEO_RECORD: 708 afMode = ANDROID_CONTROL_AF_CONTINUOUS_VIDEO; 709 break; 710 case CAMERA2_TEMPLATE_VIDEO_SNAPSHOT: 711 afMode = ANDROID_CONTROL_AF_CONTINUOUS_VIDEO; 712 break; 713 case CAMERA2_TEMPLATE_ZERO_SHUTTER_LAG: 714 afMode = ANDROID_CONTROL_AF_CONTINUOUS_PICTURE; 715 break; 716 default: 717 afMode = ANDROID_CONTROL_AF_AUTO; 718 break; 719 } 720 ADD_OR_SIZE(ANDROID_CONTROL_AF_MODE, &afMode, 1); 721 722 ADD_OR_SIZE(ANDROID_CONTROL_AF_REGIONS, controlRegions, 5); 723 724 static const uint8_t vstabMode = ANDROID_CONTROL_VIDEO_STABILIZATION_OFF; 725 ADD_OR_SIZE(ANDROID_CONTROL_VIDEO_STABILIZATION_MODE, &vstabMode, 1); 726 727 // aeState, awbState, afState only in frame 728 729 /** Allocate metadata if sizing */ 730 if (sizeRequest) { 731 ALOGV("Allocating %d entries, %d extra bytes for " 732 "request template type %d", 733 entryCount, dataCount, request_template); 734 *request = allocate_camera_metadata(entryCount, dataCount); 735 if (*request == NULL) { 736 ALOGE("Unable to allocate new request template type %d " 737 "(%d entries, %d bytes extra data)", request_template, 738 entryCount, dataCount); 739 return NO_MEMORY; 740 } 741 } 742 return OK; 743 #undef ADD_OR_SIZE 744 } 745 746 }; 747