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