Home | History | Annotate | Download | only in libcamera2
      1 /*
      2 **
      3 ** Copyright 2008, The Android Open Source Project
      4 ** Copyright 2012, Samsung Electronics Co. LTD
      5 **
      6 ** Licensed under the Apache License, Version 2.0 (the "License");
      7 ** you may not use this file except in compliance with the License.
      8 ** You may obtain a copy of the License at
      9 **
     10 **     http://www.apache.org/licenses/LICENSE-2.0
     11 **
     12 ** Unless required by applicable law or agreed to in writing, software
     13 ** distributed under the License is distributed on an "AS IS" BASIS,
     14 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 ** See the License for the specific language governing permissions and
     16 ** limitations under the License.
     17 */
     18 
     19 /*!
     20  * \file      ExynosCamera2.cpp
     21  * \brief     source file for static information of camera2
     22  * \author    Sungjoong Kang(sj3.kang (at) samsung.com)
     23  * \date      2012/08/06
     24  *
     25  * <b>Revision History: </b>
     26  * - 2012/08/06 : Sungjoong Kang(sj3.kang (at) samsung.com) \n
     27  *   Initial Release
     28  *
     29  */
     30 
     31 //#define LOG_NDEBUG 0
     32 #define LOG_TAG "ExynosCamera2"
     33 #include <utils/Log.h>
     34 
     35 #include "ExynosCamera2.h"
     36 
     37 #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
     38 
     39 namespace android {
     40 
     41 class Sensor {
     42 public:
     43     /**
     44      * Static sensor characteristics
     45      */
     46     static const unsigned int kResolution[2][2];
     47 
     48     static const nsecs_t kExposureTimeRange[2];
     49     static const nsecs_t kFrameDurationRange[2];
     50     static const nsecs_t kMinVerticalBlank;
     51 
     52     static const uint8_t kColorFilterArrangement;
     53 
     54     // Output image data characteristics
     55     static const uint32_t kMaxRawValue;
     56     static const uint32_t kBlackLevel;
     57     // Sensor sensitivity, approximate
     58 
     59     static const float kSaturationVoltage;
     60     static const uint32_t kSaturationElectrons;
     61     static const float kVoltsPerLuxSecond;
     62     static const float kElectronsPerLuxSecond;
     63 
     64     static const float kBaseGainFactor;
     65 
     66     static const float kReadNoiseStddevBeforeGain; // In electrons
     67     static const float kReadNoiseStddevAfterGain;  // In raw digital units
     68     static const float kReadNoiseVarBeforeGain;
     69     static const float kReadNoiseVarAfterGain;
     70 
     71     // While each row has to read out, reset, and then expose, the (reset +
     72     // expose) sequence can be overlapped by other row readouts, so the final
     73     // minimum frame duration is purely a function of row readout time, at least
     74     // if there's a reasonable number of rows.
     75     static const nsecs_t kRowReadoutTime;
     76 
     77     static const uint32_t kAvailableSensitivities[5];
     78     static const uint32_t kDefaultSensitivity;
     79 
     80 };
     81 
     82 
     83 
     84 const uint32_t Sensor::kAvailableSensitivities[5] =
     85     {100, 200, 400, 800, 1600};
     86 const nsecs_t Sensor::kExposureTimeRange[2] =
     87     {1000L, 30000000000L} ; // 1 us - 30 sec
     88 const nsecs_t Sensor::kFrameDurationRange[2] =
     89     {33331760L, 30000000000L}; // ~1/30 s - 30 sec
     90 
     91 const uint8_t Sensor::kColorFilterArrangement = ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT_RGGB;
     92 
     93 const uint32_t kAvailableFormats[5] = {
     94         HAL_PIXEL_FORMAT_RAW_SENSOR,
     95         HAL_PIXEL_FORMAT_BLOB,
     96         HAL_PIXEL_FORMAT_RGBA_8888,
     97         HAL_PIXEL_FORMAT_YV12,
     98         HAL_PIXEL_FORMAT_YCrCb_420_SP
     99 };
    100 
    101 // Output image data characteristics
    102 const uint32_t Sensor::kMaxRawValue = 4000;
    103 const uint32_t Sensor::kBlackLevel  = 1000;
    104 
    105 const uint64_t kAvailableRawMinDurations[1] = {
    106     Sensor::kFrameDurationRange[0]
    107 };
    108 
    109 const uint64_t kAvailableProcessedMinDurations[1] = {
    110     Sensor::kFrameDurationRange[0]
    111 };
    112 const uint64_t kAvailableJpegMinDurations[1] = {
    113     Sensor::kFrameDurationRange[0]
    114 };
    115 
    116 const int32_t scalerResolutionS5K4E5[] =
    117 {
    118     1920, 1080, // 16:9
    119     1440, 1080, // 4:3
    120     1440,  960, // 3:2
    121     1280, 1024, // 5:4
    122     1280,  720, // 16:9
    123      960,  720, // 4:3
    124      800,  480, // 5:3
    125      768,  576, // 4:3
    126      720,  576, // 5:4
    127      720,  480, // 3:2
    128      640,  480, // 4:3
    129      352,  288, // 11:9
    130      320,  240, // 4:3
    131      240,  160, // 3:2
    132      176,  144, // 6:5
    133      128,   96, // 4:3
    134 };
    135 
    136 const int32_t jpegResolutionS5K4E5[] =
    137 {
    138     2560, 1920,
    139     2560, 1440,
    140     2160, 1440,
    141     2048, 1536,
    142     1600, 1200,
    143     1280, 1024,
    144     1280,  960,
    145     1152,  864,
    146      640,  480,
    147      320,  240,
    148 };
    149 
    150 const uint8_t availableAfModesS5K4E5[] =
    151 {
    152     ANDROID_CONTROL_AF_MODE_OFF,
    153     ANDROID_CONTROL_AF_MODE_AUTO,
    154     ANDROID_CONTROL_AF_MODE_MACRO,
    155     ANDROID_CONTROL_AF_MODE_CONTINUOUS_PICTURE,
    156     ANDROID_CONTROL_AF_MODE_CONTINUOUS_VIDEO
    157 };
    158 
    159 const uint8_t sceneModeOverridesS5K4E5[] =
    160 {
    161     // ANDROID_CONTROL_SCENE_MODE_ACTION
    162     ANDROID_CONTROL_AE_MODE_ON,
    163     ANDROID_CONTROL_AWB_MODE_AUTO,
    164     ANDROID_CONTROL_AF_MODE_CONTINUOUS_PICTURE,
    165     // ANDROID_CONTROL_SCENE_MODE_NIGHT
    166     ANDROID_CONTROL_AE_MODE_ON,
    167     ANDROID_CONTROL_AWB_MODE_AUTO,
    168     ANDROID_CONTROL_AF_MODE_CONTINUOUS_PICTURE,
    169     // ANDROID_CONTROL_SCENE_MODE_SUNSET
    170     ANDROID_CONTROL_AE_MODE_ON,
    171     ANDROID_CONTROL_AWB_MODE_DAYLIGHT,
    172     ANDROID_CONTROL_AF_MODE_CONTINUOUS_PICTURE,
    173     // ANDROID_CONTROL_SCENE_MODE_PARTY
    174     ANDROID_CONTROL_AE_MODE_ON_AUTO_FLASH,
    175     ANDROID_CONTROL_AWB_MODE_AUTO,
    176     ANDROID_CONTROL_AF_MODE_CONTINUOUS_PICTURE
    177 };
    178 
    179 const uint8_t availableAeModesS5K4E5[] =
    180 {
    181     ANDROID_CONTROL_AE_MODE_OFF,
    182     ANDROID_CONTROL_AE_MODE_ON,
    183     ANDROID_CONTROL_AE_MODE_ON_AUTO_FLASH
    184 };
    185 
    186 ExynosCamera2InfoS5K4E5::ExynosCamera2InfoS5K4E5()
    187 {
    188     sensorW             = 2560;
    189     sensorH             = 1920;
    190     sensorRawW          = (2560 + 16);
    191     sensorRawH          = (1920 + 10);
    192     numScalerResolution = ARRAY_SIZE(scalerResolutionS5K4E5)/2;
    193     scalerResolutions   = scalerResolutionS5K4E5;
    194     numJpegResolution   = ARRAY_SIZE(jpegResolutionS5K4E5)/2;
    195     jpegResolutions     = jpegResolutionS5K4E5;
    196     minFocusDistance    = 0.1f;
    197     focalLength         = 3.43f;
    198     aperture            = 2.7f;
    199     fnumber             = 2.7f;
    200     availableAfModes    = availableAfModesS5K4E5;
    201     numAvailableAfModes = ARRAY_SIZE(availableAfModesS5K4E5);
    202     sceneModeOverrides  = sceneModeOverridesS5K4E5;
    203     numSceneModeOverrides = ARRAY_SIZE(sceneModeOverridesS5K4E5);
    204     availableAeModes    = availableAeModesS5K4E5;
    205     numAvailableAeModes = ARRAY_SIZE(availableAeModesS5K4E5);
    206 }
    207 
    208 ExynosCamera2InfoS5K4E5::~ExynosCamera2InfoS5K4E5()
    209 {
    210     ALOGV("%s", __FUNCTION__);
    211 }
    212 const int32_t scalerResolutionS5K6A3[] =
    213 {
    214     1344,  896, // 3:2
    215     1280, 1024, // 5:4
    216     1024, 1024, // 1:1
    217     1280,  960, // 4:3
    218     1280,  720, // 16:9
    219      960,  720, // 4:3
    220      800,  480, // 5:3
    221      768,  576, // 4:3
    222      720,  576, // 5:4
    223      720,  480, // 3:2
    224      640,  480, // 4:3
    225      352,  288, // 11:9
    226      320,  240, // 4:3
    227      240,  160, // 3:2
    228      176,  144, // 6:5
    229      128,   96, // 4:3
    230 };
    231 
    232 const int32_t jpegResolutionS5K6A3[] =
    233 {
    234     1392, 1392,
    235     1392, 1040,
    236     1392,  928,
    237     1392,  784,
    238     1280, 1024,
    239     1280,  960,
    240     1280,  720,
    241     1152,  864,
    242      640,  480,
    243      320,  240,
    244 };
    245 
    246 const uint8_t availableAfModesS5K6A3[] =
    247 {
    248     ANDROID_CONTROL_AF_MODE_OFF
    249 };
    250 
    251 const uint8_t sceneModeOverridesS5K6A3[] =
    252 {
    253     // ANDROID_CONTROL_SCENE_MODE_ACTION
    254     ANDROID_CONTROL_AE_MODE_ON,
    255     ANDROID_CONTROL_AWB_MODE_AUTO,
    256     ANDROID_CONTROL_AF_MODE_OFF,
    257     // ANDROID_CONTROL_SCENE_MODE_NIGHT
    258     ANDROID_CONTROL_AE_MODE_ON,
    259     ANDROID_CONTROL_AWB_MODE_AUTO,
    260     ANDROID_CONTROL_AF_MODE_OFF,
    261     // ANDROID_CONTROL_SCENE_MODE_SUNSET
    262     ANDROID_CONTROL_AE_MODE_ON,
    263     ANDROID_CONTROL_AWB_MODE_DAYLIGHT,
    264     ANDROID_CONTROL_AF_MODE_OFF,
    265     // ANDROID_CONTROL_SCENE_MODE_PARTY
    266     ANDROID_CONTROL_AE_MODE_ON,
    267     ANDROID_CONTROL_AWB_MODE_AUTO,
    268     ANDROID_CONTROL_AF_MODE_OFF
    269 };
    270 
    271 const uint8_t availableAeModesS5K6A3[] =
    272 {
    273     ANDROID_CONTROL_AE_MODE_OFF,
    274     ANDROID_CONTROL_AE_MODE_ON
    275 };
    276 
    277 ExynosCamera2InfoS5K6A3::ExynosCamera2InfoS5K6A3()
    278 {
    279     sensorW     = 1392;
    280     sensorH     = 1392;
    281     sensorRawW  = (1392 + 16);
    282     sensorRawH  = (1392 + 10);
    283     numScalerResolution = ARRAY_SIZE(scalerResolutionS5K6A3)/2;
    284     scalerResolutions   = scalerResolutionS5K6A3;
    285     numJpegResolution   = ARRAY_SIZE(jpegResolutionS5K6A3)/2;
    286     jpegResolutions     = jpegResolutionS5K6A3;
    287     minFocusDistance    = 0.0f;
    288     focalLength         = 2.73f;
    289     aperture            = 2.8f;
    290     fnumber             = 2.8f;
    291     availableAfModes    = availableAfModesS5K6A3;
    292     numAvailableAfModes = ARRAY_SIZE(availableAfModesS5K6A3);
    293     sceneModeOverrides  = sceneModeOverridesS5K6A3;
    294     numSceneModeOverrides = ARRAY_SIZE(sceneModeOverridesS5K6A3);
    295     availableAeModes    = availableAeModesS5K6A3;
    296     numAvailableAeModes = ARRAY_SIZE(availableAeModesS5K6A3);
    297 }
    298 
    299 ExynosCamera2InfoS5K6A3::~ExynosCamera2InfoS5K6A3()
    300 {
    301     ALOGV("%s", __FUNCTION__);
    302 }
    303 ExynosCamera2::ExynosCamera2(int cameraId):
    304     m_cameraId(cameraId)
    305 {
    306     if (cameraId == 0)
    307         m_curCameraInfo      = new ExynosCamera2InfoS5K4E5;
    308     else
    309         m_curCameraInfo      = new ExynosCamera2InfoS5K6A3;
    310 }
    311 
    312 ExynosCamera2::~ExynosCamera2()
    313 {
    314     ALOGV("%s", __FUNCTION__);
    315 	delete m_curCameraInfo;
    316     m_curCameraInfo = NULL;
    317 }
    318 
    319 int32_t ExynosCamera2::getSensorW()
    320 {
    321     return m_curCameraInfo->sensorW;
    322 }
    323 
    324 int32_t ExynosCamera2::getSensorH()
    325 {
    326     return m_curCameraInfo->sensorH;
    327 }
    328 
    329 int32_t ExynosCamera2::getSensorRawW()
    330 {
    331     return m_curCameraInfo->sensorRawW;
    332 }
    333 
    334 int32_t ExynosCamera2::getSensorRawH()
    335 {
    336     return m_curCameraInfo->sensorRawH;
    337 }
    338 
    339 bool ExynosCamera2::isSupportedResolution(int width, int height)
    340 {
    341     int i;
    342     for (i = 0 ; i < m_curCameraInfo->numScalerResolution ; i++) {
    343         if (m_curCameraInfo->scalerResolutions[2*i] == width
    344                 && m_curCameraInfo->scalerResolutions[2*i+1] == height) {
    345             return true;
    346         }
    347     }
    348     return false;
    349 }
    350 
    351 bool ExynosCamera2::isSupportedJpegResolution(int width, int height)
    352 {
    353     int i;
    354     for (i = 0 ; i < m_curCameraInfo->numJpegResolution ; i++) {
    355         if (m_curCameraInfo->jpegResolutions[2*i] == width
    356                 && m_curCameraInfo->jpegResolutions[2*i+1] == height) {
    357             return true;
    358         }
    359     }
    360     return false;
    361 }
    362 
    363 status_t addOrSize(camera_metadata_t *request,
    364         bool sizeRequest,
    365         size_t *entryCount,
    366         size_t *dataCount,
    367         uint32_t tag,
    368         const void *entryData,
    369         size_t entryDataCount) {
    370     status_t res;
    371     if (!sizeRequest) {
    372         return add_camera_metadata_entry(request, tag, entryData,
    373                 entryDataCount);
    374     } else {
    375         int type = get_camera_metadata_tag_type(tag);
    376         if (type < 0 ) return BAD_VALUE;
    377         (*entryCount)++;
    378         (*dataCount) += calculate_camera_metadata_entry_data_size(type,
    379                 entryDataCount);
    380         return OK;
    381     }
    382 }
    383 
    384 status_t ExynosCamera2::constructStaticInfo(camera_metadata_t **info,
    385         int cameraId, bool sizeRequest) {
    386 
    387     size_t entryCount = 0;
    388     size_t dataCount = 0;
    389     status_t ret;
    390 
    391 #define ADD_OR_SIZE( tag, data, count ) \
    392     if ( ( ret = addOrSize(*info, sizeRequest, &entryCount, &dataCount, \
    393             tag, data, count) ) != OK ) return ret
    394 
    395     // android.info
    396 
    397     int32_t hardwareLevel = ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_FULL;
    398     ADD_OR_SIZE(ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL,
    399             &hardwareLevel, 1);
    400 
    401     // android.lens
    402 
    403     ADD_OR_SIZE(ANDROID_LENS_INFO_MINIMUM_FOCUS_DISTANCE,
    404             &(m_curCameraInfo->minFocusDistance), 1);
    405     ADD_OR_SIZE(ANDROID_LENS_INFO_HYPERFOCAL_DISTANCE,
    406             &(m_curCameraInfo->minFocusDistance), 1);
    407 
    408     ADD_OR_SIZE(ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS,
    409             &m_curCameraInfo->focalLength, 1);
    410     ADD_OR_SIZE(ANDROID_LENS_INFO_AVAILABLE_APERTURES,
    411             &m_curCameraInfo->aperture, 1);
    412 
    413     static const float filterDensity = 0;
    414     ADD_OR_SIZE(ANDROID_LENS_INFO_AVAILABLE_FILTER_DENSITIES,
    415             &filterDensity, 1);
    416     static const uint8_t availableOpticalStabilization =
    417             ANDROID_LENS_OPTICAL_STABILIZATION_MODE_OFF;
    418     ADD_OR_SIZE(ANDROID_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION,
    419             &availableOpticalStabilization, 1);
    420 
    421     static const int32_t lensShadingMapSize[] = {1, 1};
    422     ADD_OR_SIZE(ANDROID_LENS_INFO_SHADING_MAP_SIZE, lensShadingMapSize,
    423             sizeof(lensShadingMapSize)/sizeof(int32_t));
    424 
    425     static const float lensShadingMap[3 * 1 * 1 ] =
    426             { 1.f, 1.f, 1.f };
    427     ADD_OR_SIZE(ANDROID_LENS_INFO_SHADING_MAP, lensShadingMap,
    428             sizeof(lensShadingMap)/sizeof(float));
    429 
    430     int32_t lensFacing = cameraId ?
    431             ANDROID_LENS_FACING_FRONT : ANDROID_LENS_FACING_BACK;
    432     ADD_OR_SIZE(ANDROID_LENS_FACING, &lensFacing, 1);
    433 
    434     // android.sensor
    435     ADD_OR_SIZE(ANDROID_SENSOR_INFO_EXPOSURE_TIME_RANGE,
    436             Sensor::kExposureTimeRange, 2);
    437 
    438     ADD_OR_SIZE(ANDROID_SENSOR_INFO_MAX_FRAME_DURATION,
    439             &Sensor::kFrameDurationRange[1], 1);
    440 
    441     ADD_OR_SIZE(ANDROID_SENSOR_INFO_AVAILABLE_SENSITIVITIES,
    442             Sensor::kAvailableSensitivities,
    443             sizeof(Sensor::kAvailableSensitivities)
    444             /sizeof(uint32_t));
    445 
    446     ADD_OR_SIZE(ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT,
    447             &Sensor::kColorFilterArrangement, 1);
    448 
    449     // Empirically derived to get correct FOV measurements
    450     static const float sensorPhysicalSize[2] = {3.50f, 2.625f}; // mm
    451     ADD_OR_SIZE(ANDROID_SENSOR_INFO_PHYSICAL_SIZE,
    452             sensorPhysicalSize, 2);
    453 
    454     int32_t pixelArraySize[2] = {
    455         m_curCameraInfo->sensorW, m_curCameraInfo->sensorH
    456     };
    457     ADD_OR_SIZE(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, pixelArraySize, 2);
    458     ADD_OR_SIZE(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, pixelArraySize,2);
    459 
    460     ADD_OR_SIZE(ANDROID_SENSOR_INFO_WHITE_LEVEL,
    461             &Sensor::kMaxRawValue, 1);
    462 
    463     static const int32_t blackLevelPattern[4] = {
    464             Sensor::kBlackLevel, Sensor::kBlackLevel,
    465             Sensor::kBlackLevel, Sensor::kBlackLevel
    466     };
    467     ADD_OR_SIZE(ANDROID_SENSOR_BLACK_LEVEL_PATTERN,
    468             blackLevelPattern, sizeof(blackLevelPattern)/sizeof(int32_t));
    469 
    470     //TODO: sensor color calibration fields
    471 
    472     // android.flash
    473     uint8_t flashAvailable;
    474     if (cameraId == 0)
    475         flashAvailable = 1;
    476     else
    477         flashAvailable = 0;
    478     ADD_OR_SIZE(ANDROID_FLASH_INFO_AVAILABLE, &flashAvailable, 1);
    479 
    480     static const int64_t flashChargeDuration = 0;
    481     ADD_OR_SIZE(ANDROID_FLASH_INFO_CHARGE_DURATION, &flashChargeDuration, 1);
    482 
    483     // android.tonemap
    484 
    485     static const int32_t tonemapCurvePoints = 128;
    486     ADD_OR_SIZE(ANDROID_TONEMAP_MAX_CURVE_POINTS, &tonemapCurvePoints, 1);
    487 
    488     // android.scaler
    489 
    490     ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_FORMATS,
    491             kAvailableFormats,
    492             sizeof(kAvailableFormats)/sizeof(uint32_t));
    493 
    494     int32_t availableRawSizes[2] = {
    495         m_curCameraInfo->sensorRawW, m_curCameraInfo->sensorRawH
    496     };
    497     ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_RAW_SIZES,
    498             availableRawSizes, 2);
    499 
    500     ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_RAW_MIN_DURATIONS,
    501             kAvailableRawMinDurations,
    502             sizeof(kAvailableRawMinDurations)/sizeof(uint64_t));
    503 
    504 
    505     ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_PROCESSED_SIZES,
    506         m_curCameraInfo->scalerResolutions,
    507         (m_curCameraInfo->numScalerResolution)*2);
    508     ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_JPEG_SIZES,
    509         m_curCameraInfo->jpegResolutions,
    510         (m_curCameraInfo->numJpegResolution)*2);
    511 
    512     ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_PROCESSED_MIN_DURATIONS,
    513             kAvailableProcessedMinDurations,
    514             sizeof(kAvailableProcessedMinDurations)/sizeof(uint64_t));
    515 
    516     ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_JPEG_MIN_DURATIONS,
    517             kAvailableJpegMinDurations,
    518             sizeof(kAvailableJpegMinDurations)/sizeof(uint64_t));
    519 
    520     static const float maxZoom = 4;
    521     ADD_OR_SIZE(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM, &maxZoom, 1);
    522 
    523     // android.jpeg
    524 
    525     static const int32_t jpegThumbnailSizes[] = {
    526             160, 120,
    527             160, 160,
    528             160, 90,
    529             144, 96,
    530               0, 0
    531     };
    532 
    533     ADD_OR_SIZE(ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES,
    534             jpegThumbnailSizes, sizeof(jpegThumbnailSizes)/sizeof(int32_t));
    535 
    536     static const int32_t jpegMaxSize = 10 * 1024 * 1024;
    537     ADD_OR_SIZE(ANDROID_JPEG_MAX_SIZE, &jpegMaxSize, 1);
    538 
    539     // android.stats
    540 
    541     static const uint8_t availableFaceDetectModes[] = {
    542             ANDROID_STATISTICS_FACE_DETECT_MODE_OFF,
    543             ANDROID_STATISTICS_FACE_DETECT_MODE_FULL
    544     };
    545     ADD_OR_SIZE(ANDROID_STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES,
    546             availableFaceDetectModes,
    547             sizeof(availableFaceDetectModes));
    548 
    549     m_curCameraInfo->maxFaceCount = CAMERA2_MAX_FACES;
    550     ADD_OR_SIZE(ANDROID_STATISTICS_INFO_MAX_FACE_COUNT,
    551             &(m_curCameraInfo->maxFaceCount), 1);
    552 
    553     static const int32_t histogramSize = 64;
    554     ADD_OR_SIZE(ANDROID_STATISTICS_INFO_HISTOGRAM_BUCKET_COUNT,
    555             &histogramSize, 1);
    556 
    557     static const int32_t maxHistogramCount = 1000;
    558     ADD_OR_SIZE(ANDROID_STATISTICS_INFO_MAX_HISTOGRAM_COUNT,
    559             &maxHistogramCount, 1);
    560 
    561     static const int32_t sharpnessMapSize[2] = {64, 64};
    562     ADD_OR_SIZE(ANDROID_STATISTICS_INFO_SHARPNESS_MAP_SIZE,
    563             sharpnessMapSize, sizeof(sharpnessMapSize)/sizeof(int32_t));
    564 
    565     static const int32_t maxSharpnessMapValue = 1000;
    566     ADD_OR_SIZE(ANDROID_STATISTICS_INFO_MAX_SHARPNESS_MAP_VALUE,
    567             &maxSharpnessMapValue, 1);
    568 
    569     // android.control
    570 
    571     static const uint8_t availableSceneModes[] = {
    572             ANDROID_CONTROL_SCENE_MODE_ACTION,
    573             ANDROID_CONTROL_SCENE_MODE_NIGHT,
    574             ANDROID_CONTROL_SCENE_MODE_SUNSET,
    575             ANDROID_CONTROL_SCENE_MODE_PARTY
    576     };
    577     ADD_OR_SIZE(ANDROID_CONTROL_AVAILABLE_SCENE_MODES,
    578             availableSceneModes, sizeof(availableSceneModes));
    579 
    580     static const uint8_t availableEffects[] = {
    581             ANDROID_CONTROL_EFFECT_MODE_OFF
    582     };
    583     ADD_OR_SIZE(ANDROID_CONTROL_AVAILABLE_EFFECTS,
    584             availableEffects, sizeof(availableEffects));
    585 
    586     int32_t max3aRegions = 1;
    587     ADD_OR_SIZE(ANDROID_CONTROL_MAX_REGIONS,
    588             &max3aRegions, 1);
    589 
    590     ADD_OR_SIZE(ANDROID_CONTROL_AE_AVAILABLE_MODES,
    591             m_curCameraInfo->availableAeModes, m_curCameraInfo->numAvailableAeModes);
    592 
    593     static const camera_metadata_rational exposureCompensationStep = {
    594             1, 1
    595     };
    596     ADD_OR_SIZE(ANDROID_CONTROL_AE_COMPENSATION_STEP,
    597             &exposureCompensationStep, 1);
    598 
    599     int32_t exposureCompensationRange[] = {-3, 3};
    600     ADD_OR_SIZE(ANDROID_CONTROL_AE_COMPENSATION_RANGE,
    601             exposureCompensationRange,
    602             sizeof(exposureCompensationRange)/sizeof(int32_t));
    603 
    604     static const int32_t availableTargetFpsRanges[] = {
    605             15, 15, 24, 24, 25, 25, 15, 30, 30, 30
    606     };
    607     ADD_OR_SIZE(ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES,
    608             availableTargetFpsRanges,
    609             sizeof(availableTargetFpsRanges)/sizeof(int32_t));
    610 
    611     static const uint8_t availableAntibandingModes[] = {
    612             ANDROID_CONTROL_AE_ANTIBANDING_MODE_OFF,
    613             ANDROID_CONTROL_AE_ANTIBANDING_MODE_AUTO
    614     };
    615     ADD_OR_SIZE(ANDROID_CONTROL_AE_AVAILABLE_ANTIBANDING_MODES,
    616             availableAntibandingModes, sizeof(availableAntibandingModes));
    617 
    618     static const uint8_t availableAwbModes[] = {
    619             ANDROID_CONTROL_AWB_MODE_OFF,
    620             ANDROID_CONTROL_AWB_MODE_AUTO,
    621             ANDROID_CONTROL_AWB_MODE_INCANDESCENT,
    622             ANDROID_CONTROL_AWB_MODE_FLUORESCENT,
    623             ANDROID_CONTROL_AWB_MODE_DAYLIGHT,
    624             ANDROID_CONTROL_AWB_MODE_CLOUDY_DAYLIGHT
    625     };
    626     ADD_OR_SIZE(ANDROID_CONTROL_AWB_AVAILABLE_MODES,
    627             availableAwbModes, sizeof(availableAwbModes));
    628 
    629     ADD_OR_SIZE(ANDROID_CONTROL_AF_AVAILABLE_MODES,
    630                 m_curCameraInfo->availableAfModes, m_curCameraInfo->numAvailableAfModes);
    631 
    632     static const uint8_t availableVstabModes[] = {
    633             ANDROID_CONTROL_VIDEO_STABILIZATION_MODE_OFF,
    634             ANDROID_CONTROL_VIDEO_STABILIZATION_MODE_ON
    635     };
    636     ADD_OR_SIZE(ANDROID_CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES,
    637             availableVstabModes, sizeof(availableVstabModes));
    638 
    639     ADD_OR_SIZE(ANDROID_CONTROL_SCENE_MODE_OVERRIDES,
    640             m_curCameraInfo->sceneModeOverrides, m_curCameraInfo->numSceneModeOverrides);
    641 
    642     static const uint8_t quirkTriggerAuto = 1;
    643     ADD_OR_SIZE(ANDROID_QUIRKS_TRIGGER_AF_WITH_AUTO,
    644             &quirkTriggerAuto, 1);
    645 
    646     static const uint8_t quirkUseZslFormat = 1;
    647     ADD_OR_SIZE(ANDROID_QUIRKS_USE_ZSL_FORMAT,
    648             &quirkUseZslFormat, 1);
    649 
    650     static const uint8_t quirkMeteringCropRegion = 1;
    651     ADD_OR_SIZE(ANDROID_QUIRKS_METERING_CROP_REGION,
    652             &quirkMeteringCropRegion, 1);
    653 
    654 
    655 #undef ADD_OR_SIZE
    656     /** Allocate metadata if sizing */
    657     if (sizeRequest) {
    658         ALOGV("Allocating %d entries, %d extra bytes for "
    659                 "static camera info",
    660                 entryCount, dataCount);
    661         *info = allocate_camera_metadata(entryCount, dataCount);
    662         if (*info == NULL) {
    663             ALOGE("Unable to allocate camera static info"
    664                     "(%d entries, %d bytes extra data)",
    665                     entryCount, dataCount);
    666             return NO_MEMORY;
    667         }
    668     }
    669     return OK;
    670 }
    671 
    672 status_t ExynosCamera2::constructDefaultRequest(
    673         int request_template,
    674         camera_metadata_t **request,
    675         bool sizeRequest) {
    676 
    677     size_t entryCount = 0;
    678     size_t dataCount = 0;
    679     status_t ret;
    680 
    681 #define ADD_OR_SIZE( tag, data, count ) \
    682     if ( ( ret = addOrSize(*request, sizeRequest, &entryCount, &dataCount, \
    683             tag, data, count) ) != OK ) return ret
    684 
    685     static const int64_t USEC = 1000LL;
    686     static const int64_t MSEC = USEC * 1000LL;
    687     static const int64_t SEC = MSEC * 1000LL;
    688 
    689     /** android.request */
    690 
    691     static const uint8_t metadataMode = ANDROID_REQUEST_METADATA_MODE_NONE;
    692     ADD_OR_SIZE(ANDROID_REQUEST_METADATA_MODE, &metadataMode, 1);
    693 
    694     static const int32_t id = 0;
    695     ADD_OR_SIZE(ANDROID_REQUEST_ID, &id, 1);
    696 
    697     static const int32_t frameCount = 0;
    698     ADD_OR_SIZE(ANDROID_REQUEST_FRAME_COUNT, &frameCount, 1);
    699 
    700     // OUTPUT_STREAMS set by user
    701     entryCount += 1;
    702     dataCount += 5; // TODO: Should be maximum stream number
    703 
    704     /** android.lens */
    705 
    706     static const float focusDistance = 0;
    707     ADD_OR_SIZE(ANDROID_LENS_FOCUS_DISTANCE, &focusDistance, 1);
    708 
    709     ADD_OR_SIZE(ANDROID_LENS_APERTURE, &m_curCameraInfo->aperture, 1);
    710 
    711     ADD_OR_SIZE(ANDROID_LENS_FOCAL_LENGTH, &m_curCameraInfo->focalLength, 1);
    712 
    713     static const float filterDensity = 0;
    714     ADD_OR_SIZE(ANDROID_LENS_FILTER_DENSITY, &filterDensity, 1);
    715 
    716     static const uint8_t opticalStabilizationMode =
    717             ANDROID_LENS_OPTICAL_STABILIZATION_MODE_OFF;
    718     ADD_OR_SIZE(ANDROID_LENS_OPTICAL_STABILIZATION_MODE,
    719             &opticalStabilizationMode, 1);
    720 
    721 
    722     /** android.sensor */
    723 
    724 
    725     static const int64_t frameDuration = 33333333L; // 1/30 s
    726     ADD_OR_SIZE(ANDROID_SENSOR_FRAME_DURATION, &frameDuration, 1);
    727 
    728 
    729     /** android.flash */
    730 
    731     static const uint8_t flashMode = ANDROID_FLASH_MODE_OFF;
    732     ADD_OR_SIZE(ANDROID_FLASH_MODE, &flashMode, 1);
    733 
    734     static const uint8_t flashPower = 10;
    735     ADD_OR_SIZE(ANDROID_FLASH_FIRING_POWER, &flashPower, 1);
    736 
    737     static const int64_t firingTime = 0;
    738     ADD_OR_SIZE(ANDROID_FLASH_FIRING_TIME, &firingTime, 1);
    739 
    740     /** Processing block modes */
    741     uint8_t hotPixelMode = 0;
    742     uint8_t demosaicMode = 0;
    743     uint8_t noiseMode = 0;
    744     uint8_t shadingMode = 0;
    745     uint8_t geometricMode = 0;
    746     uint8_t colorMode = 0;
    747     uint8_t tonemapMode = 0;
    748     uint8_t edgeMode = 0;
    749     uint8_t vstabMode = ANDROID_CONTROL_VIDEO_STABILIZATION_MODE_OFF;
    750 
    751     switch (request_template) {
    752       case CAMERA2_TEMPLATE_VIDEO_SNAPSHOT:
    753         vstabMode = ANDROID_CONTROL_VIDEO_STABILIZATION_MODE_ON;
    754         // fall-through
    755       case CAMERA2_TEMPLATE_STILL_CAPTURE:
    756         // fall-through
    757       case CAMERA2_TEMPLATE_ZERO_SHUTTER_LAG:
    758         hotPixelMode = ANDROID_HOT_PIXEL_MODE_HIGH_QUALITY;
    759         demosaicMode = ANDROID_DEMOSAIC_MODE_HIGH_QUALITY;
    760         noiseMode = ANDROID_NOISE_REDUCTION_MODE_HIGH_QUALITY;
    761         shadingMode = ANDROID_SHADING_MODE_HIGH_QUALITY;
    762         geometricMode = ANDROID_GEOMETRIC_MODE_HIGH_QUALITY;
    763         colorMode = ANDROID_COLOR_CORRECTION_MODE_HIGH_QUALITY;
    764         tonemapMode = ANDROID_TONEMAP_MODE_HIGH_QUALITY;
    765         edgeMode = ANDROID_EDGE_MODE_HIGH_QUALITY;
    766         break;
    767       case CAMERA2_TEMPLATE_VIDEO_RECORD:
    768         vstabMode = ANDROID_CONTROL_VIDEO_STABILIZATION_MODE_ON;
    769         // fall-through
    770       case CAMERA2_TEMPLATE_PREVIEW:
    771         // fall-through
    772       default:
    773         hotPixelMode = ANDROID_HOT_PIXEL_MODE_FAST;
    774         demosaicMode = ANDROID_DEMOSAIC_MODE_FAST;
    775         noiseMode = ANDROID_NOISE_REDUCTION_MODE_FAST;
    776         shadingMode = ANDROID_SHADING_MODE_FAST;
    777         geometricMode = ANDROID_GEOMETRIC_MODE_FAST;
    778         colorMode = ANDROID_COLOR_CORRECTION_MODE_FAST;
    779         tonemapMode = ANDROID_TONEMAP_MODE_FAST;
    780         edgeMode = ANDROID_EDGE_MODE_FAST;
    781         break;
    782     }
    783     ADD_OR_SIZE(ANDROID_HOT_PIXEL_MODE, &hotPixelMode, 1);
    784     ADD_OR_SIZE(ANDROID_DEMOSAIC_MODE, &demosaicMode, 1);
    785     ADD_OR_SIZE(ANDROID_NOISE_REDUCTION_MODE, &noiseMode, 1);
    786     ADD_OR_SIZE(ANDROID_SHADING_MODE, &shadingMode, 1);
    787     ADD_OR_SIZE(ANDROID_GEOMETRIC_MODE, &geometricMode, 1);
    788     ADD_OR_SIZE(ANDROID_COLOR_CORRECTION_MODE, &colorMode, 1);
    789     ADD_OR_SIZE(ANDROID_TONEMAP_MODE, &tonemapMode, 1);
    790     ADD_OR_SIZE(ANDROID_EDGE_MODE, &edgeMode, 1);
    791     ADD_OR_SIZE(ANDROID_CONTROL_VIDEO_STABILIZATION_MODE, &vstabMode, 1);
    792 
    793     /** android.noise */
    794     static const uint8_t noiseStrength = 5;
    795     ADD_OR_SIZE(ANDROID_NOISE_REDUCTION_STRENGTH, &noiseStrength, 1);
    796 
    797     /** android.color */
    798     static const float colorTransform[9] = {
    799         1.0f, 0.f, 0.f,
    800         0.f, 1.f, 0.f,
    801         0.f, 0.f, 1.f
    802     };
    803     ADD_OR_SIZE(ANDROID_COLOR_CORRECTION_TRANSFORM, colorTransform, 9);
    804 
    805     /** android.tonemap */
    806     static const float tonemapCurve[4] = {
    807         0.f, 0.f,
    808         1.f, 1.f
    809     };
    810     ADD_OR_SIZE(ANDROID_TONEMAP_CURVE_RED, tonemapCurve, 32); // sungjoong
    811     ADD_OR_SIZE(ANDROID_TONEMAP_CURVE_GREEN, tonemapCurve, 32);
    812     ADD_OR_SIZE(ANDROID_TONEMAP_CURVE_BLUE, tonemapCurve, 32);
    813 
    814     /** android.edge */
    815     static const uint8_t edgeStrength = 5;
    816     ADD_OR_SIZE(ANDROID_EDGE_STRENGTH, &edgeStrength, 1);
    817 
    818     /** android.scaler */
    819     int32_t cropRegion[3] = {
    820         0, 0, m_curCameraInfo->sensorW
    821     };
    822     ADD_OR_SIZE(ANDROID_SCALER_CROP_REGION, cropRegion, 3);
    823 
    824     /** android.jpeg */
    825     static const int32_t jpegQuality = 100;
    826     ADD_OR_SIZE(ANDROID_JPEG_QUALITY, &jpegQuality, 1);
    827 
    828     static const int32_t thumbnailSize[2] = {
    829         160, 120
    830     };
    831     ADD_OR_SIZE(ANDROID_JPEG_THUMBNAIL_SIZE, thumbnailSize, 2);
    832 
    833     static const int32_t thumbnailQuality = 100;
    834     ADD_OR_SIZE(ANDROID_JPEG_THUMBNAIL_QUALITY, &thumbnailQuality, 1);
    835 
    836     static const double gpsCoordinates[3] = {
    837         0, 0, 0
    838     };
    839     ADD_OR_SIZE(ANDROID_JPEG_GPS_COORDINATES, gpsCoordinates, 3);
    840 
    841     static const uint8_t gpsProcessingMethod[32] = "None";
    842     ADD_OR_SIZE(ANDROID_JPEG_GPS_PROCESSING_METHOD, gpsProcessingMethod, 32);
    843 
    844     static const int64_t gpsTimestamp = 0;
    845     ADD_OR_SIZE(ANDROID_JPEG_GPS_TIMESTAMP, &gpsTimestamp, 1);
    846 
    847     static const int32_t jpegOrientation = 0;
    848     ADD_OR_SIZE(ANDROID_JPEG_ORIENTATION, &jpegOrientation, 1);
    849 
    850     /** android.stats */
    851 
    852     static const uint8_t faceDetectMode = ANDROID_STATISTICS_FACE_DETECT_MODE_FULL;
    853     ADD_OR_SIZE(ANDROID_STATISTICS_FACE_DETECT_MODE, &faceDetectMode, 1);
    854 
    855     static const uint8_t histogramMode = ANDROID_STATISTICS_HISTOGRAM_MODE_OFF;
    856     ADD_OR_SIZE(ANDROID_STATISTICS_HISTOGRAM_MODE, &histogramMode, 1);
    857 
    858     static const uint8_t sharpnessMapMode = ANDROID_STATISTICS_HISTOGRAM_MODE_OFF;
    859     ADD_OR_SIZE(ANDROID_STATISTICS_SHARPNESS_MAP_MODE, &sharpnessMapMode, 1);
    860 
    861 
    862     /** android.control */
    863 
    864     uint8_t controlIntent = 0;
    865     switch (request_template) {
    866       case CAMERA2_TEMPLATE_PREVIEW:
    867         controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW;
    868         break;
    869       case CAMERA2_TEMPLATE_STILL_CAPTURE:
    870         controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_STILL_CAPTURE;
    871         break;
    872       case CAMERA2_TEMPLATE_VIDEO_RECORD:
    873         controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_RECORD;
    874         break;
    875       case CAMERA2_TEMPLATE_VIDEO_SNAPSHOT:
    876         controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT;
    877         break;
    878       case CAMERA2_TEMPLATE_ZERO_SHUTTER_LAG:
    879         controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_ZERO_SHUTTER_LAG;
    880         break;
    881       default:
    882         controlIntent = ANDROID_CONTROL_CAPTURE_INTENT_CUSTOM;
    883         break;
    884     }
    885     ADD_OR_SIZE(ANDROID_CONTROL_CAPTURE_INTENT, &controlIntent, 1);
    886 
    887     static const uint8_t controlMode = ANDROID_CONTROL_MODE_AUTO;
    888     ADD_OR_SIZE(ANDROID_CONTROL_MODE, &controlMode, 1);
    889 
    890     static const uint8_t effectMode = ANDROID_CONTROL_EFFECT_MODE_OFF;
    891     ADD_OR_SIZE(ANDROID_CONTROL_EFFECT_MODE, &effectMode, 1);
    892 
    893     static const uint8_t sceneMode = ANDROID_CONTROL_SCENE_MODE_UNSUPPORTED;
    894     ADD_OR_SIZE(ANDROID_CONTROL_SCENE_MODE, &sceneMode, 1);
    895 
    896     static const uint8_t aeMode = ANDROID_CONTROL_AE_MODE_ON;
    897     ADD_OR_SIZE(ANDROID_CONTROL_AE_MODE, &aeMode, 1);
    898 
    899     int32_t controlRegions[5] = {
    900         0, 0, m_curCameraInfo->sensorW, m_curCameraInfo->sensorH, 1000
    901     };
    902     ADD_OR_SIZE(ANDROID_CONTROL_AE_REGIONS, controlRegions, 5);
    903 
    904     static const int32_t aeExpCompensation = 0;
    905     ADD_OR_SIZE(ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION, &aeExpCompensation, 1);
    906 
    907     static const int32_t aeTargetFpsRange[2] = {
    908         15, 30
    909     };
    910     ADD_OR_SIZE(ANDROID_CONTROL_AE_TARGET_FPS_RANGE, aeTargetFpsRange, 2);
    911 
    912     static const uint8_t aeAntibandingMode =
    913             ANDROID_CONTROL_AE_ANTIBANDING_MODE_AUTO;
    914     ADD_OR_SIZE(ANDROID_CONTROL_AE_ANTIBANDING_MODE, &aeAntibandingMode, 1);
    915 
    916     static const uint8_t awbMode =
    917             ANDROID_CONTROL_AWB_MODE_AUTO;
    918     ADD_OR_SIZE(ANDROID_CONTROL_AWB_MODE, &awbMode, 1);
    919 
    920     ADD_OR_SIZE(ANDROID_CONTROL_AWB_REGIONS, controlRegions, 5);
    921 
    922     uint8_t afMode = 0;
    923     switch (request_template) {
    924       case CAMERA2_TEMPLATE_PREVIEW:
    925         afMode = ANDROID_CONTROL_AF_MODE_CONTINUOUS_PICTURE;
    926         break;
    927       case CAMERA2_TEMPLATE_STILL_CAPTURE:
    928         afMode = ANDROID_CONTROL_AF_MODE_CONTINUOUS_PICTURE;
    929         break;
    930       case CAMERA2_TEMPLATE_VIDEO_RECORD:
    931         afMode = ANDROID_CONTROL_AF_MODE_CONTINUOUS_VIDEO;
    932         break;
    933       case CAMERA2_TEMPLATE_VIDEO_SNAPSHOT:
    934         afMode = ANDROID_CONTROL_AF_MODE_CONTINUOUS_VIDEO;
    935         break;
    936       case CAMERA2_TEMPLATE_ZERO_SHUTTER_LAG:
    937         afMode = ANDROID_CONTROL_AF_MODE_CONTINUOUS_PICTURE;
    938         break;
    939       default:
    940         afMode = ANDROID_CONTROL_AF_MODE_AUTO;
    941         break;
    942     }
    943     ADD_OR_SIZE(ANDROID_CONTROL_AF_MODE, &afMode, 1);
    944 
    945     ADD_OR_SIZE(ANDROID_CONTROL_AF_REGIONS, controlRegions, 5);
    946 
    947     if (sizeRequest) {
    948         ALOGV("Allocating %d entries, %d extra bytes for "
    949                 "request template type %d",
    950                 entryCount, dataCount, request_template);
    951         *request = allocate_camera_metadata(entryCount, dataCount);
    952         if (*request == NULL) {
    953             ALOGE("Unable to allocate new request template type %d "
    954                     "(%d entries, %d bytes extra data)", request_template,
    955                     entryCount, dataCount);
    956             return NO_MEMORY;
    957         }
    958     }
    959     return OK;
    960 #undef ADD_OR_SIZE
    961 }
    962 
    963 }
    964