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