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 MetadataConverter.cpp
21 * \brief source file for Metadata converter ( for camera hal2 implementation )
22 * \author Sungjoong Kang(sj3.kang@samsung.com)
23 * \date 2012/05/31
24 *
25 * <b>Revision History: </b>
26 * - 2012/05/31 : Sungjoong Kang(sj3.kang@samsung.com) \n
27 * Initial Release
28 */
29
30 //#define LOG_NDEBUG 0
31 #define LOG_TAG "MetadataConverter"
32 #include <utils/Log.h>
33
34 #include "MetadataConverter.h"
35 #include "exynos_format.h"
36
37 namespace android {
38
39
MetadataConverter()40 MetadataConverter::MetadataConverter()
41 {
42 return;
43 }
44
45
~MetadataConverter()46 MetadataConverter::~MetadataConverter()
47 {
48 ALOGV("DEBUG(%s)destroy!!:", __FUNCTION__);
49 return;
50 }
51
CheckEntryTypeMismatch(camera_metadata_entry_t * entry,uint8_t type)52 status_t MetadataConverter::CheckEntryTypeMismatch(camera_metadata_entry_t * entry,
53 uint8_t type)
54 {
55 if (!(entry->type==type))
56 {
57 ALOGV("DEBUG(%s):Metadata Missmatch tag(%s) type (%d) count(%d)",
58 __FUNCTION__, get_camera_metadata_tag_name(entry->tag), entry->type, entry->count);
59 return BAD_VALUE;
60 }
61 return NO_ERROR;
62 }
63
CheckEntryTypeMismatch(camera_metadata_entry_t * entry,uint8_t type,size_t count)64 status_t MetadataConverter::CheckEntryTypeMismatch(camera_metadata_entry_t * entry,
65 uint8_t type, size_t count)
66 {
67 if (!((entry->type==type)&&(entry->count==count)))
68 {
69 ALOGV("DEBUG(%s):Metadata Missmatch tag(%s) type (%d) count(%d)",
70 __FUNCTION__, get_camera_metadata_tag_name(entry->tag), entry->type, entry->count);
71 return BAD_VALUE;
72 }
73 return NO_ERROR;
74 }
75
ToInternalShot(camera_metadata_t * request,struct camera2_shot_ext * dst_ext)76 status_t MetadataConverter::ToInternalShot(camera_metadata_t * request, struct camera2_shot_ext * dst_ext)
77 {
78 uint32_t num_entry = 0;
79 uint32_t index = 0;
80 uint32_t i = 0;
81 uint32_t cnt = 0;
82 camera_metadata_entry_t curr_entry;
83 struct camera2_shot * dst = NULL;
84
85 if (request == NULL || dst_ext == NULL)
86 return BAD_VALUE;
87
88 memset((void*)dst_ext, 0, sizeof(struct camera2_shot_ext));
89 dst = &dst_ext->shot;
90
91 dst->magicNumber = 0x23456789;
92 dst->ctl.aa.aeTargetFpsRange[0] = 15;
93 dst->ctl.aa.aeTargetFpsRange[1] = 30;
94 dst->ctl.aa.aeExpCompensation = 5;
95
96 num_entry = (uint32_t)get_camera_metadata_entry_count(request);
97 for (index = 0 ; index < num_entry ; index++) {
98
99 if (get_camera_metadata_entry(request, index, &curr_entry)==0) {
100 switch (curr_entry.tag) {
101
102 case ANDROID_LENS_FOCUS_DISTANCE:
103 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_FLOAT, 1))
104 break;
105 dst->ctl.lens.focusDistance = curr_entry.data.f[0];
106 break;
107
108 case ANDROID_LENS_APERTURE:
109 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_FLOAT, 1))
110 break;
111 dst->ctl.lens.aperture = curr_entry.data.f[0];
112 break;
113
114 case ANDROID_LENS_FOCAL_LENGTH:
115 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_FLOAT, 1))
116 break;
117 dst->ctl.lens.focalLength = curr_entry.data.f[0];
118 break;
119
120 case ANDROID_LENS_FILTER_DENSITY:
121 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_FLOAT, 1))
122 break;
123 dst->ctl.lens.filterDensity = curr_entry.data.f[0];
124 break;
125
126 case ANDROID_LENS_OPTICAL_STABILIZATION_MODE:
127 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_BYTE, 1))
128 break;
129 dst->ctl.lens.opticalStabilizationMode =
130 (enum optical_stabilization_mode)curr_entry.data.u8[0];
131 break;
132
133
134 case ANDROID_SENSOR_TIMESTAMP:
135 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_INT64, 1))
136 break;
137 dst->dm.sensor.timeStamp = curr_entry.data.i64[0];
138 break;
139
140
141 case ANDROID_SENSOR_SENSITIVITY:
142 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_INT32, 1))
143 break;
144 dst->dm.aa.isoValue = curr_entry.data.i32[0];
145 break;
146
147 case ANDROID_SENSOR_EXPOSURE_TIME:
148 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_INT64, 1))
149 break;
150 dst->dm.sensor.exposureTime = curr_entry.data.i64[0];
151 break;
152
153
154 case ANDROID_FLASH_MODE:
155 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_BYTE, 1))
156 break;
157 dst->ctl.flash.flashMode = (enum flash_mode)(curr_entry.data.u8[0] + 1);
158 break;
159
160 case ANDROID_FLASH_FIRING_POWER:
161 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_BYTE, 1))
162 break;
163 dst->ctl.flash.firingPower = curr_entry.data.u8[0];
164 break;
165
166 case ANDROID_FLASH_FIRING_TIME:
167 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_INT64, 1))
168 break;
169 dst->ctl.flash.firingTime = curr_entry.data.i64[0];
170 break;
171
172
173
174 case ANDROID_SCALER_CROP_REGION:
175 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_INT32, 3))
176 break;
177 for (i=0 ; i<curr_entry.count ; i++)
178 dst->ctl.scaler.cropRegion[i] = ALIGN(curr_entry.data.i32[i], 2);
179 break;
180
181
182 case ANDROID_JPEG_QUALITY:
183 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_INT32, 1))
184 break;
185 dst->ctl.jpeg.quality= curr_entry.data.i32[0];
186 break;
187
188 case ANDROID_JPEG_THUMBNAIL_SIZE:
189 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_INT32, 2))
190 break;
191 for (i=0 ; i<curr_entry.count ; i++)
192 dst->ctl.jpeg.thumbnailSize[i] = curr_entry.data.i32[i];
193 break;
194
195 case ANDROID_JPEG_THUMBNAIL_QUALITY:
196 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_INT32, 1))
197 break;
198 dst->ctl.jpeg.thumbnailQuality= curr_entry.data.i32[0];
199 break;
200
201 case ANDROID_JPEG_GPS_COORDINATES:
202 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_DOUBLE, 3))
203 break;
204 for (i=0 ; i<curr_entry.count ; i++)
205 dst->ctl.jpeg.gpsCoordinates[i] = curr_entry.data.d[i];
206 break;
207
208 case ANDROID_JPEG_GPS_PROCESSING_METHOD:
209 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_BYTE))
210 break;
211 if (curr_entry.count > 32)
212 cnt = 32;
213 else
214 cnt = curr_entry.count;
215 for (i = 0 ; i < cnt ; i++)
216 dst_ext->gpsProcessingMethod[i] = curr_entry.data.u8[i];
217 break;
218
219 case ANDROID_JPEG_GPS_TIMESTAMP:
220 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_INT64, 1))
221 break;
222 dst->ctl.jpeg.gpsTimestamp = curr_entry.data.i64[0];
223 break;
224
225 case ANDROID_JPEG_ORIENTATION:
226 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_INT32, 1))
227 break;
228 dst->ctl.jpeg.orientation = curr_entry.data.i32[0];
229 break;
230
231
232
233 case ANDROID_STATS_FACE_DETECT_MODE:
234 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_BYTE, 1))
235 break;
236 dst->ctl.stats.faceDetectMode = (enum facedetect_mode)(curr_entry.data.u8[0] + 1);
237 break;
238
239 case ANDROID_CONTROL_CAPTURE_INTENT:
240 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_BYTE, 1))
241 break;
242 dst->ctl.aa.captureIntent = (enum aa_capture_intent)curr_entry.data.u8[0];
243 break;
244
245 case ANDROID_CONTROL_MODE:
246 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_BYTE, 1))
247 break;
248 dst->ctl.aa.mode = (enum aa_mode)(curr_entry.data.u8[0] + 1);
249 break;
250
251
252 case ANDROID_CONTROL_VIDEO_STABILIZATION_MODE:
253 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_BYTE, 1))
254 break;
255 dst->ctl.aa.videoStabilizationMode = curr_entry.data.u8[0];
256 break;
257
258 case ANDROID_CONTROL_AE_MODE:
259 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_BYTE, 1))
260 break;
261 dst->ctl.aa.aeMode = (enum aa_aemode)(curr_entry.data.u8[0] + 2);
262 // skip locked mode
263 if (dst->ctl.aa.aeMode == AA_AEMODE_LOCKED)
264 dst->ctl.aa.aeMode = AA_AEMODE_OFF;
265 ALOGV("DEBUG(%s): ANDROID_CONTROL_AE_MODE (%d)", __FUNCTION__, dst->ctl.aa.aeMode);
266 break;
267
268 case ANDROID_CONTROL_AE_LOCK:
269 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_BYTE, 1))
270 break;
271 dst_ext->ae_lock = (enum ae_lockmode)(curr_entry.data.u8[0]);
272 break;
273
274 case ANDROID_CONTROL_AE_EXP_COMPENSATION:
275 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_INT32, 1))
276 break;
277 dst->ctl.aa.aeExpCompensation = curr_entry.data.i32[0] + 5;
278 break;
279
280 case ANDROID_CONTROL_AWB_MODE:
281 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_BYTE, 1))
282 break;
283 dst->ctl.aa.awbMode = (enum aa_awbmode)(curr_entry.data.u8[0] + 2);
284 // skip locked mode
285 if (dst->ctl.aa.awbMode == AA_AWBMODE_LOCKED)
286 dst->ctl.aa.awbMode = AA_AWBMODE_OFF;
287 dst_ext->awb_mode_dm = (enum aa_awbmode)(curr_entry.data.u8[0] + 2);
288 break;
289
290 case ANDROID_CONTROL_AWB_LOCK:
291 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_BYTE, 1))
292 break;
293 dst_ext->awb_lock = (enum awb_lockmode)(curr_entry.data.u8[0]);
294 break;
295
296 case ANDROID_CONTROL_AF_MODE:
297 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_BYTE, 1))
298 break;
299 dst->ctl.aa.afMode = (enum aa_afmode)(curr_entry.data.u8[0] + 1);
300 if (dst->ctl.aa.afMode == AA_AFMODE_OFF)
301 dst->ctl.aa.afMode = AA_AFMODE_MANUAL;
302 break;
303
304 case ANDROID_CONTROL_AF_REGIONS:
305 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_INT32, 5))
306 break;
307 for (i=0 ; i<curr_entry.count ; i++)
308 dst->ctl.aa.afRegions[i] = curr_entry.data.i32[i];
309 break;
310
311 case ANDROID_CONTROL_AE_REGIONS:
312 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_INT32, 5))
313 break;
314 for (i=0 ; i<curr_entry.count ; i++)
315 dst->ctl.aa.aeRegions[i] = curr_entry.data.i32[i];
316 break;
317
318
319 case ANDROID_REQUEST_ID:
320 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_INT32, 1))
321 break;
322 dst->ctl.request.id = curr_entry.data.i32[0];
323 ALOGV("DEBUG(%s): ANDROID_REQUEST_ID (%d)", __FUNCTION__, dst->ctl.request.id);
324 break;
325
326 case ANDROID_REQUEST_METADATA_MODE:
327 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_BYTE, 1))
328 break;
329 dst->ctl.request.metadataMode = (enum metadata_mode)curr_entry.data.u8[0];
330 ALOGV("DEBUG(%s): ANDROID_REQUEST_METADATA_MODE (%d)", __FUNCTION__, (int)( dst->ctl.request.metadataMode));
331 break;
332
333 case ANDROID_REQUEST_OUTPUT_STREAMS:
334 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_BYTE))
335 break;
336
337 dst->ctl.request.outputStreams[0] = 0;
338 for (i=0 ; i<curr_entry.count ; i++) {
339 ALOGV("DEBUG(%s): OUTPUT_STREAM[%d] = %d ", __FUNCTION__, i, curr_entry.data.u8[i]);
340 dst->ctl.request.outputStreams[0] |= (1 << curr_entry.data.u8[i]);
341 }
342 break;
343
344 case ANDROID_REQUEST_INPUT_STREAMS:
345 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_BYTE))
346 break;
347
348 for (i=0 ; i<curr_entry.count ; i++) {
349 dst_ext->reprocessInput = curr_entry.data.u8[0];
350 ALOGV("DEBUG(%s): ANDROID_REQUEST_INPUT_STREAMS[%d] = %d ", __FUNCTION__, i, dst_ext->reprocessInput);
351 }
352 break;
353
354 case ANDROID_REQUEST_TYPE:
355 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_BYTE, 1))
356 break;
357 dst_ext->isReprocessing = curr_entry.data.u8[0];
358 ALOGV("DEBUG(%s): ANDROID_REQUEST_TYPE (%d)", __FUNCTION__, dst_ext->isReprocessing);
359 break;
360
361 case ANDROID_REQUEST_FRAME_COUNT:
362 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_INT32, 1))
363 break;
364 dst->ctl.request.frameCount = curr_entry.data.i32[0];
365 ALOGV("DEBUG(%s): ANDROID_REQUEST_FRAME_COUNT (%d)", __FUNCTION__, dst->ctl.request.frameCount);
366 break;
367
368 case ANDROID_CONTROL_SCENE_MODE:
369 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_BYTE, 1))
370 break;
371 dst->ctl.aa.sceneMode = (enum aa_scene_mode)(curr_entry.data.u8[0] + 1);
372 break;
373
374 case ANDROID_CONTROL_AE_TARGET_FPS_RANGE:
375 if (NO_ERROR != CheckEntryTypeMismatch(&curr_entry, TYPE_INT32, 2))
376 break;
377 for (i=0 ; i<curr_entry.count ; i++)
378 dst->ctl.aa.aeTargetFpsRange[i] = curr_entry.data.i32[i];
379 break;
380
381 default:
382 ALOGV("DEBUG(%s):Bad Metadata tag (%d)", __FUNCTION__, curr_entry.tag);
383 break;
384 }
385 }
386 }
387 if (dst->ctl.aa.mode != AA_CONTROL_USE_SCENE_MODE)
388 dst->ctl.aa.sceneMode = AA_SCENE_MODE_UNSUPPORTED;
389 ApplySceneModeParameters(request, dst_ext);
390 return NO_ERROR;
391 }
392
ApplySceneModeParameters(camera_metadata_t * request,struct camera2_shot_ext * dst_ext)393 status_t MetadataConverter::ApplySceneModeParameters(camera_metadata_t * request, struct camera2_shot_ext * dst_ext)
394 {
395 camera_metadata_entry_t curr_entry;
396 struct camera2_shot * dst = NULL;
397
398 ALOGV("DEBUG(%s):", __FUNCTION__);
399
400 dst = &(dst_ext->shot);
401
402 switch (dst->ctl.aa.sceneMode) {
403
404 case AA_SCENE_MODE_ACTION:
405 dst->ctl.aa.mode = AA_CONTROL_USE_SCENE_MODE;
406 if (dst->ctl.aa.aeMode != AA_AEMODE_LOCKED)
407 dst->ctl.aa.aeMode = AA_AEMODE_ON;
408 dst->ctl.aa.awbMode = AA_AWBMODE_WB_AUTO;
409 dst_ext->awb_mode_dm = AA_AWBMODE_WB_AUTO;
410 dst->ctl.aa.isoMode = AA_ISOMODE_AUTO;
411 dst->ctl.aa.isoValue = 0;
412 dst->ctl.aa.aeTargetFpsRange[0] = 30;
413 dst->ctl.aa.aeTargetFpsRange[1] = 30;
414
415 dst->ctl.noise.mode = PROCESSING_MODE_FAST;
416 dst->ctl.noise.strength = 0;
417 dst->ctl.edge.mode = PROCESSING_MODE_FAST;
418 dst->ctl.edge.strength = 0;
419
420 dst->ctl.color.saturation = 3; // means '0'
421 break;
422
423 case AA_SCENE_MODE_PARTY:
424 dst->ctl.aa.mode = AA_CONTROL_USE_SCENE_MODE;
425 if (dst->ctl.aa.aeMode != AA_AEMODE_LOCKED)
426 dst->ctl.aa.aeMode = AA_AEMODE_ON;
427 dst->ctl.aa.awbMode = AA_AWBMODE_WB_AUTO;
428 dst_ext->awb_mode_dm = AA_AWBMODE_WB_AUTO;
429 dst->ctl.aa.isoMode = AA_ISOMODE_MANUAL;
430 dst->ctl.aa.isoValue = 200;
431 dst->ctl.aa.aeTargetFpsRange[0] = 15;
432 dst->ctl.aa.aeTargetFpsRange[1] = 30;
433
434 dst->ctl.noise.mode = PROCESSING_MODE_FAST;
435 dst->ctl.noise.strength = 0;
436 dst->ctl.edge.mode = PROCESSING_MODE_FAST;
437 dst->ctl.edge.strength = 0;
438
439 dst->ctl.color.saturation = 4; // means '+1'
440 break;
441
442 case AA_SCENE_MODE_SUNSET:
443 dst->ctl.aa.mode = AA_CONTROL_USE_SCENE_MODE;
444 if (dst->ctl.aa.aeMode != AA_AEMODE_LOCKED)
445 dst->ctl.aa.aeMode = AA_AEMODE_ON;
446 dst->ctl.aa.awbMode = AA_AWBMODE_WB_DAYLIGHT;
447 dst_ext->awb_mode_dm = AA_AWBMODE_WB_DAYLIGHT;
448 dst->ctl.aa.isoMode = AA_ISOMODE_AUTO;
449 dst->ctl.aa.isoValue = 0;
450 dst->ctl.aa.aeTargetFpsRange[0] = 15;
451 dst->ctl.aa.aeTargetFpsRange[1] = 30;
452
453 dst->ctl.noise.mode = PROCESSING_MODE_FAST;
454 dst->ctl.noise.strength = 0;
455 dst->ctl.edge.mode = PROCESSING_MODE_FAST;
456 dst->ctl.edge.strength = 0;
457
458 dst->ctl.color.saturation = 3; // means '0'
459 break;
460
461 case AA_SCENE_MODE_NIGHT:
462 dst->ctl.aa.mode = AA_CONTROL_USE_SCENE_MODE;
463 dst->ctl.aa.aeMode = AA_AEMODE_ON; // AE_LOCK is prohibited
464 dst->ctl.aa.awbMode = AA_AWBMODE_WB_AUTO;
465 dst_ext->awb_mode_dm = AA_AWBMODE_WB_AUTO;
466 dst->ctl.aa.isoMode = AA_ISOMODE_AUTO;
467 dst->ctl.aa.isoValue = 0;
468 dst->ctl.aa.aeTargetFpsRange[0] = 8;
469 dst->ctl.aa.aeTargetFpsRange[1] = 30;
470
471 dst->ctl.noise.mode = PROCESSING_MODE_FAST;
472 dst->ctl.noise.strength = 0;
473 dst->ctl.edge.mode = PROCESSING_MODE_FAST;
474 dst->ctl.edge.strength = 0;
475
476 dst->ctl.color.saturation = 3; // means '0'
477 break;
478
479 case AA_SCENE_MODE_FACE_PRIORITY:
480 dst->ctl.aa.mode = AA_CONTROL_AUTO;
481 if ((dst->ctl.aa.aeMode != AA_AEMODE_LOCKED) && (dst->ctl.aa.aeMode < AA_AEMODE_ON_AUTO_FLASH))
482 dst->ctl.aa.aeMode = AA_AEMODE_ON;
483 dst->ctl.aa.sceneMode = AA_SCENE_MODE_FACE_PRIORITY;
484 dst->ctl.aa.isoMode = AA_ISOMODE_AUTO;
485 dst->ctl.aa.isoValue = 0;
486 dst->ctl.noise.mode = PROCESSING_MODE_OFF;
487 dst->ctl.noise.strength = 0;
488 dst->ctl.edge.mode = PROCESSING_MODE_OFF;
489 dst->ctl.edge.strength = 0;
490 dst->ctl.color.saturation = 3; // means '0'
491 break;
492
493 default:
494 dst->ctl.aa.mode = AA_CONTROL_AUTO;
495 if ((dst->ctl.aa.aeMode != AA_AEMODE_LOCKED) && (dst->ctl.aa.aeMode < AA_AEMODE_ON_AUTO_FLASH))
496 dst->ctl.aa.aeMode = AA_AEMODE_ON;
497 dst->ctl.aa.sceneMode = AA_SCENE_MODE_UNSUPPORTED;
498 dst->ctl.aa.isoMode = AA_ISOMODE_AUTO;
499 dst->ctl.aa.isoValue = 0;
500 dst->ctl.noise.mode = PROCESSING_MODE_OFF;
501 dst->ctl.noise.strength = 0;
502 dst->ctl.edge.mode = PROCESSING_MODE_OFF;
503 dst->ctl.edge.strength = 0;
504 dst->ctl.color.saturation = 3; // means '0'
505 break;
506 }
507
508 return NO_ERROR;
509 }
510
511
ToDynamicMetadata(struct camera2_shot_ext * metadata_ext,camera_metadata_t * dst)512 status_t MetadataConverter::ToDynamicMetadata(struct camera2_shot_ext * metadata_ext, camera_metadata_t * dst)
513 {
514 status_t res;
515 struct camera2_shot * metadata = &metadata_ext->shot;
516 uint8_t byteData;
517 uint32_t intData;
518
519 if (0 != add_camera_metadata_entry(dst, ANDROID_REQUEST_ID,
520 &(metadata->ctl.request.id), 1))
521 return NO_MEMORY;
522
523 if (0 != add_camera_metadata_entry(dst, ANDROID_REQUEST_METADATA_MODE,
524 &(metadata->ctl.request.metadataMode), 1))
525 return NO_MEMORY;
526
527 if (0 != add_camera_metadata_entry(dst, ANDROID_REQUEST_FRAME_COUNT,
528 &(metadata->ctl.request.frameCount), 1))
529 return NO_MEMORY;
530
531 if (0 != add_camera_metadata_entry(dst, ANDROID_SENSOR_TIMESTAMP,
532 &metadata->dm.sensor.timeStamp, 1))
533 return NO_MEMORY;
534
535 if (0 != add_camera_metadata_entry(dst, ANDROID_SENSOR_EXPOSURE_TIME,
536 &metadata->dm.sensor.exposureTime, 1))
537 return NO_MEMORY;
538
539 if (0 != add_camera_metadata_entry(dst, ANDROID_LENS_APERTURE,
540 &metadata->dm.lens.aperture, 1))
541 return NO_MEMORY;
542
543 if (0 != add_camera_metadata_entry(dst, ANDROID_CONTROL_AE_TARGET_FPS_RANGE,
544 &(metadata->ctl.aa.aeTargetFpsRange), 2))
545 return NO_MEMORY;
546
547 ALOGV("(%s): ID(%d) METAMODE(%d) FrameCnt(%d) Timestamp(%lld) exposure(%lld) aper(%f)", __FUNCTION__,
548 metadata->ctl.request.id, metadata->ctl.request.metadataMode, metadata->ctl.request.frameCount,
549 metadata->dm.sensor.timeStamp, metadata->dm.sensor.exposureTime, metadata->dm.lens.aperture);
550
551
552 byteData = metadata_ext->awb_mode_dm- 2;
553 if (0 != add_camera_metadata_entry(dst, ANDROID_CONTROL_AWB_MODE,
554 &byteData, 1))
555 return NO_MEMORY;
556
557 byteData = metadata->dm.aa.aeMode - 1;
558 if (0 != add_camera_metadata_entry(dst, ANDROID_CONTROL_AE_MODE,
559 &byteData, 1))
560 return NO_MEMORY;
561
562 byteData = metadata->ctl.aa.afMode - 1;
563 if (0 != add_camera_metadata_entry(dst, ANDROID_CONTROL_AF_MODE,
564 &byteData, 1))
565 return NO_MEMORY;
566
567 byteData = metadata->ctl.aa.sceneMode - 1;
568 if (0 != add_camera_metadata_entry(dst, ANDROID_CONTROL_SCENE_MODE,
569 &byteData, 1))
570 return NO_MEMORY;
571
572 intData = metadata->ctl.aa.aeExpCompensation - 5;
573 if (0 != add_camera_metadata_entry(dst, ANDROID_CONTROL_AE_EXP_COMPENSATION,
574 &intData, 1))
575 return NO_MEMORY;
576
577 byteData = metadata->dm.stats.faceDetectMode - 1;
578 if (0 != add_camera_metadata_entry(dst, ANDROID_STATS_FACE_DETECT_MODE,
579 &byteData, 1))
580 return NO_MEMORY;
581
582 int maxFacecount = CAMERA2_MAX_FACES;
583 if (0 != add_camera_metadata_entry(dst, ANDROID_STATS_MAX_FACE_COUNT,
584 &maxFacecount, 1))
585 return NO_MEMORY;
586
587 int tempFaceCount = 0;
588 for (int i = 0; i < CAMERA2_MAX_FACES; i++) {
589 if (metadata->dm.stats.faceIds[i] > 0) {
590 mataFaceIds[tempFaceCount] = metadata->dm.stats.faceIds[i];
591 // clipping fd score because the max face score of android is 100
592 if (metadata->dm.stats.faceScores[i] > 100)
593 metaFaceScores[tempFaceCount] = 100;
594 else
595 metaFaceScores[tempFaceCount] = metadata->dm.stats.faceScores[i];
596
597 memcpy(&mataFaceLandmarks[tempFaceCount][0], &metadata->dm.stats.faceLandmarks[i][0], 6*sizeof(uint32_t));
598 memcpy(&metaFaceRectangles[tempFaceCount][0], &metadata->dm.stats.faceRectangles[i][0], 4*sizeof(uint32_t));
599 tempFaceCount++;
600 }
601 }
602
603 if (tempFaceCount > 0) {
604 if (0 != add_camera_metadata_entry(dst, ANDROID_STATS_FACE_RECTANGLES,
605 &metaFaceRectangles, 4 * tempFaceCount))
606 return NO_MEMORY;
607
608 if (0 != add_camera_metadata_entry(dst, ANDROID_STATS_FACE_LANDMARKS,
609 &mataFaceLandmarks, 6 * tempFaceCount))
610 return NO_MEMORY;
611
612 if (0 != add_camera_metadata_entry(dst, ANDROID_STATS_FACE_IDS,
613 &mataFaceIds, tempFaceCount))
614 return NO_MEMORY;
615
616 if (0 != add_camera_metadata_entry(dst, ANDROID_STATS_FACE_SCORES,
617 &metaFaceScores, tempFaceCount))
618 return NO_MEMORY;
619 }
620 if (0 != add_camera_metadata_entry(dst, ANDROID_SENSOR_SENSITIVITY,
621 &metadata->dm.aa.isoValue, 1))
622 return NO_MEMORY;
623
624
625 if (0 != add_camera_metadata_entry(dst, ANDROID_SCALER_CROP_REGION,
626 &metadata->ctl.scaler.cropRegion, 3))
627 return NO_MEMORY;
628
629 byteData = metadata->dm.aa.aeState - 1;
630 if (0 != add_camera_metadata_entry(dst, ANDROID_CONTROL_AE_STATE,
631 &byteData, 1))
632 return NO_MEMORY;
633
634 if (0 != add_camera_metadata_entry(dst, ANDROID_CONTROL_AWB_STATE,
635 &(metadata->dm.aa.awbState), 1))
636 return NO_MEMORY;
637
638
639 if (0 != add_camera_metadata_entry(dst, ANDROID_JPEG_ORIENTATION,
640 &metadata->ctl.jpeg.orientation, 1))
641 return NO_MEMORY;
642
643 if (0 != add_camera_metadata_entry(dst, ANDROID_JPEG_QUALITY,
644 &metadata->ctl.jpeg.quality, 1))
645 return NO_MEMORY;
646
647 if (0 != add_camera_metadata_entry(dst, ANDROID_JPEG_THUMBNAIL_SIZE,
648 &metadata->ctl.jpeg.thumbnailSize, 2))
649 return NO_MEMORY;
650
651 if (0 != add_camera_metadata_entry(dst, ANDROID_JPEG_THUMBNAIL_QUALITY,
652 &metadata->ctl.jpeg.thumbnailQuality, 1))
653 return NO_MEMORY;
654
655
656 if (0 != add_camera_metadata_entry(dst, ANDROID_JPEG_GPS_COORDINATES,
657 &(metadata->ctl.jpeg.gpsCoordinates), 3))
658 return NO_MEMORY;
659
660 if (0 != add_camera_metadata_entry(dst, ANDROID_JPEG_GPS_PROCESSING_METHOD,
661 &(metadata_ext->gpsProcessingMethod), 32))
662 return NO_MEMORY;
663
664 if (0 != add_camera_metadata_entry(dst, ANDROID_JPEG_GPS_TIMESTAMP,
665 &(metadata->ctl.jpeg.gpsTimestamp), 1))
666 return NO_MEMORY;
667 ALOGV("(%s): AWB(%d) AE(%d) SCENE(%d) AEComp(%d) AF(%d)", __FUNCTION__,
668 metadata_ext->awb_mode_dm- 2, metadata->dm.aa.aeMode - 1, metadata->ctl.aa.sceneMode - 1,
669 metadata->ctl.aa.aeExpCompensation, metadata->ctl.aa.afMode - 1);
670
671
672 if (metadata->ctl.request.metadataMode == METADATA_MODE_NONE) {
673 ALOGV("DEBUG(%s): METADATA_MODE_NONE", __FUNCTION__);
674 return NO_ERROR;
675 }
676 return NO_ERROR;
677
678
679 }
680
681 }; // namespace android
682