1 /*
2 * Copyright (C) Texas Instruments - http://www.ti.com/
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 /**
18 * @file OMX3A.cpp
19 *
20 * This file contains functionality for handling 3A configurations.
21 *
22 */
23
24 #undef LOG_TAG
25
26 #define LOG_TAG "CameraHAL"
27
28 #include "CameraHal.h"
29 #include "OMXCameraAdapter.h"
30 #include "ErrorUtils.h"
31
32 #undef TRUE
33 #undef FALSE
34 #define TRUE "true"
35 #define FALSE "false"
36
37 #define METERING_AREAS_RANGE 0xFF
38
39 namespace android {
getSceneModeEntry(const char * name,OMX_SCENEMODETYPE scene)40 const SceneModesEntry* OMXCameraAdapter::getSceneModeEntry(const char* name,
41 OMX_SCENEMODETYPE scene) {
42 const SceneModesEntry* cameraLUT = NULL;
43 const SceneModesEntry* entry = NULL;
44 unsigned int numEntries = 0;
45
46 // 1. Find camera's scene mode LUT
47 for (unsigned int i = 0; i < ARRAY_SIZE(CameraToSensorModesLUT); i++) {
48 if (strcmp(CameraToSensorModesLUT[i].name, name) == 0) {
49 cameraLUT = CameraToSensorModesLUT[i].Table;
50 numEntries = CameraToSensorModesLUT[i].size;
51 break;
52 }
53 }
54
55 // 2. Find scene mode entry in table
56 if (!cameraLUT) {
57 goto EXIT;
58 }
59
60 for (unsigned int i = 0; i < numEntries; i++) {
61 if(cameraLUT[i].scene == scene) {
62 entry = cameraLUT + i;
63 break;
64 }
65 }
66 EXIT:
67 return entry;
68 }
69
setParameters3A(const CameraParameters & params,BaseCameraAdapter::AdapterState state)70 status_t OMXCameraAdapter::setParameters3A(const CameraParameters ¶ms,
71 BaseCameraAdapter::AdapterState state)
72 {
73 status_t ret = NO_ERROR;
74 int mode = 0;
75 const char *str = NULL;
76 BaseCameraAdapter::AdapterState nextState;
77 BaseCameraAdapter::getNextState(nextState);
78
79 LOG_FUNCTION_NAME;
80
81 Mutex::Autolock lock(m3ASettingsUpdateLock);
82
83 str = params.get(CameraParameters::KEY_SCENE_MODE);
84 mode = getLUTvalue_HALtoOMX( str, SceneLUT);
85 if ( mFirstTimeInit || ((str != NULL) && ( mParameters3A.SceneMode != mode )) ) {
86 if ( 0 <= mode ) {
87 mParameters3A.SceneMode = mode;
88 if ((mode == OMX_Manual) && (mFirstTimeInit == false)){//Auto mode
89 mFirstTimeInit = true;
90 }
91 if ((mode != OMX_Manual) &&
92 (state & PREVIEW_ACTIVE) && !(nextState & CAPTURE_ACTIVE)) {
93 // if setting preset scene mode, previewing, and not in the middle of capture
94 // set preset scene mode immediately instead of in next FBD
95 // for feedback params to work properly since they need to be read
96 // by application in subsequent getParameters()
97 ret |= setScene(mParameters3A);
98 // re-apply EV compensation after setting scene mode since it probably reset it
99 if(mParameters3A.EVCompensation) {
100 setEVCompensation(mParameters3A);
101 }
102 return ret;
103 } else {
104 mPending3Asettings |= SetSceneMode;
105 }
106 } else {
107 mParameters3A.SceneMode = OMX_Manual;
108 }
109 CAMHAL_LOGVB("SceneMode %d", mParameters3A.SceneMode);
110 }
111
112 str = params.get(TICameraParameters::KEY_EXPOSURE_MODE);
113 mode = getLUTvalue_HALtoOMX( str, ExpLUT);
114 if ( ( str != NULL ) && ( mParameters3A.Exposure != mode ))
115 {
116 mParameters3A.Exposure = mode;
117 CAMHAL_LOGDB("Exposure mode %d", mode);
118 if ( 0 <= mParameters3A.Exposure )
119 {
120 mPending3Asettings |= SetExpMode;
121 }
122 }
123
124 str = params.get(CameraParameters::KEY_WHITE_BALANCE);
125 mode = getLUTvalue_HALtoOMX( str, WBalLUT);
126 if (mFirstTimeInit || ((str != NULL) && (mode != mParameters3A.WhiteBallance)))
127 {
128 mParameters3A.WhiteBallance = mode;
129 CAMHAL_LOGDB("Whitebalance mode %d", mode);
130 if ( 0 <= mParameters3A.WhiteBallance )
131 {
132 mPending3Asettings |= SetWhiteBallance;
133 }
134 }
135
136 if ( 0 <= params.getInt(TICameraParameters::KEY_CONTRAST) )
137 {
138 if ( mFirstTimeInit ||
139 ( (mParameters3A.Contrast + CONTRAST_OFFSET) !=
140 params.getInt(TICameraParameters::KEY_CONTRAST)) )
141 {
142 mParameters3A.Contrast = params.getInt(TICameraParameters::KEY_CONTRAST) - CONTRAST_OFFSET;
143 CAMHAL_LOGDB("Contrast %d", mParameters3A.Contrast);
144 mPending3Asettings |= SetContrast;
145 }
146 }
147
148 if ( 0 <= params.getInt(TICameraParameters::KEY_SHARPNESS) )
149 {
150 if ( mFirstTimeInit ||
151 ((mParameters3A.Sharpness + SHARPNESS_OFFSET) !=
152 params.getInt(TICameraParameters::KEY_SHARPNESS)))
153 {
154 mParameters3A.Sharpness = params.getInt(TICameraParameters::KEY_SHARPNESS) - SHARPNESS_OFFSET;
155 CAMHAL_LOGDB("Sharpness %d", mParameters3A.Sharpness);
156 mPending3Asettings |= SetSharpness;
157 }
158 }
159
160 if ( 0 <= params.getInt(TICameraParameters::KEY_SATURATION) )
161 {
162 if ( mFirstTimeInit ||
163 ((mParameters3A.Saturation + SATURATION_OFFSET) !=
164 params.getInt(TICameraParameters::KEY_SATURATION)) )
165 {
166 mParameters3A.Saturation = params.getInt(TICameraParameters::KEY_SATURATION) - SATURATION_OFFSET;
167 CAMHAL_LOGDB("Saturation %d", mParameters3A.Saturation);
168 mPending3Asettings |= SetSaturation;
169 }
170 }
171
172 if ( 0 <= params.getInt(TICameraParameters::KEY_BRIGHTNESS) )
173 {
174 if ( mFirstTimeInit ||
175 (( mParameters3A.Brightness !=
176 ( unsigned int ) params.getInt(TICameraParameters::KEY_BRIGHTNESS))) )
177 {
178 mParameters3A.Brightness = (unsigned)params.getInt(TICameraParameters::KEY_BRIGHTNESS);
179 CAMHAL_LOGDB("Brightness %d", mParameters3A.Brightness);
180 mPending3Asettings |= SetBrightness;
181 }
182 }
183
184 str = params.get(CameraParameters::KEY_ANTIBANDING);
185 mode = getLUTvalue_HALtoOMX(str,FlickerLUT);
186 if ( mFirstTimeInit || ( ( str != NULL ) && ( mParameters3A.Flicker != mode ) ))
187 {
188 mParameters3A.Flicker = mode;
189 CAMHAL_LOGDB("Flicker %d", mParameters3A.Flicker);
190 if ( 0 <= mParameters3A.Flicker )
191 {
192 mPending3Asettings |= SetFlicker;
193 }
194 }
195
196 str = params.get(TICameraParameters::KEY_ISO);
197 mode = getLUTvalue_HALtoOMX(str, IsoLUT);
198 CAMHAL_LOGVB("ISO mode arrived in HAL : %s", str);
199 if ( mFirstTimeInit || ( ( str != NULL ) && ( mParameters3A.ISO != mode )) )
200 {
201 mParameters3A.ISO = mode;
202 CAMHAL_LOGDB("ISO %d", mParameters3A.ISO);
203 if ( 0 <= mParameters3A.ISO )
204 {
205 mPending3Asettings |= SetISO;
206 }
207 }
208
209 str = params.get(CameraParameters::KEY_FOCUS_MODE);
210 mode = getLUTvalue_HALtoOMX(str, FocusLUT);
211 if ( (mFirstTimeInit || ((str != NULL) && (mParameters3A.Focus != mode))))
212 {
213 //Apply focus mode immediatly only if CAF or Inifinity are selected
214 if ( ( mode == OMX_IMAGE_FocusControlAuto ) ||
215 ( mode == OMX_IMAGE_FocusControlAutoInfinity ) )
216 {
217 mPending3Asettings |= SetFocus;
218 }
219
220 mParameters3A.Focus = mode;
221
222 // if focus mode is set to infinity...update focus distance immediately
223 if (mode == OMX_IMAGE_FocusControlAutoInfinity) {
224 updateFocusDistances(mParameters);
225 }
226
227 CAMHAL_LOGDB("Focus %x", mParameters3A.Focus);
228 }
229
230 str = params.get(CameraParameters::KEY_EXPOSURE_COMPENSATION);
231 if ( mFirstTimeInit ||
232 (( str != NULL ) &&
233 (mParameters3A.EVCompensation !=
234 params.getInt(CameraParameters::KEY_EXPOSURE_COMPENSATION))))
235 {
236 CAMHAL_LOGDB("Setting EV Compensation to %d",
237 params.getInt(CameraParameters::KEY_EXPOSURE_COMPENSATION));
238
239 mParameters3A.EVCompensation = params.getInt(CameraParameters::KEY_EXPOSURE_COMPENSATION);
240 mPending3Asettings |= SetEVCompensation;
241 }
242
243 str = params.get(CameraParameters::KEY_FLASH_MODE);
244 mode = getLUTvalue_HALtoOMX( str, FlashLUT);
245 if ( mFirstTimeInit || (( str != NULL ) && ( mParameters3A.FlashMode != mode )) )
246 {
247 if ( 0 <= mode )
248 {
249 mParameters3A.FlashMode = mode;
250 mPending3Asettings |= SetFlash;
251 }
252 else
253 {
254 mParameters3A.FlashMode = OMX_Manual;
255 }
256 }
257
258 CAMHAL_LOGVB("Flash Setting %s", str);
259 CAMHAL_LOGVB("FlashMode %d", mParameters3A.FlashMode);
260
261 str = params.get(CameraParameters::KEY_EFFECT);
262 mode = getLUTvalue_HALtoOMX( str, EffLUT);
263 if ( mFirstTimeInit || (( str != NULL ) && ( mParameters3A.Effect != mode )) )
264 {
265 mParameters3A.Effect = mode;
266 CAMHAL_LOGDB("Effect %d", mParameters3A.Effect);
267 if ( 0 <= mParameters3A.Effect )
268 {
269 mPending3Asettings |= SetEffect;
270 }
271 }
272
273 str = params.get(CameraParameters::KEY_AUTO_EXPOSURE_LOCK_SUPPORTED);
274 if ( (str != NULL) && (!strcmp(str, "true")) )
275 {
276 OMX_BOOL lock = OMX_FALSE;
277 mUserSetExpLock = OMX_FALSE;
278 str = params.get(CameraParameters::KEY_AUTO_EXPOSURE_LOCK);
279 if ( (strcmp(str, "true")) == 0)
280 {
281 CAMHAL_LOGVA("Locking Exposure");
282 lock = OMX_TRUE;
283 mUserSetExpLock = OMX_TRUE;
284 }
285 else
286 {
287 CAMHAL_LOGVA("UnLocking Exposure");
288 }
289
290 if (mParameters3A.ExposureLock != lock)
291 {
292 mParameters3A.ExposureLock = lock;
293 CAMHAL_LOGDB("ExposureLock %d", lock);
294 mPending3Asettings |= SetExpLock;
295 }
296 }
297
298 str = params.get(CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED);
299 if ( (str != NULL) && (!strcmp(str, "true")) )
300 {
301 OMX_BOOL lock = OMX_FALSE;
302 mUserSetWbLock = OMX_FALSE;
303 str = params.get(CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK);
304 if ( (strcmp(str, "true")) == 0)
305 {
306 CAMHAL_LOGVA("Locking WhiteBalance");
307 lock = OMX_TRUE;
308 mUserSetWbLock = OMX_TRUE;
309 }
310 else
311 {
312 CAMHAL_LOGVA("UnLocking WhiteBalance");
313 }
314 if (mParameters3A.WhiteBalanceLock != lock)
315 {
316 mParameters3A.WhiteBalanceLock = lock;
317 CAMHAL_LOGDB("WhiteBalanceLock %d", lock);
318 mPending3Asettings |= SetWBLock;
319 }
320 }
321
322 str = params.get(TICameraParameters::KEY_AUTO_FOCUS_LOCK);
323 if (str && (strcmp(str, TRUE) == 0) && (mParameters3A.FocusLock != OMX_TRUE)) {
324 CAMHAL_LOGVA("Locking Focus");
325 mParameters3A.FocusLock = OMX_TRUE;
326 setFocusLock(mParameters3A);
327 } else if (str && (strcmp(str, FALSE) == 0) && (mParameters3A.FocusLock != OMX_FALSE)) {
328 CAMHAL_LOGVA("UnLocking Focus");
329 mParameters3A.FocusLock = OMX_FALSE;
330 setFocusLock(mParameters3A);
331 }
332
333 str = params.get(CameraParameters::KEY_METERING_AREAS);
334 if ( (str != NULL) ) {
335 size_t MAX_METERING_AREAS;
336 Vector< sp<CameraArea> > tempAreas;
337
338 MAX_METERING_AREAS = atoi(params.get(CameraParameters::KEY_MAX_NUM_METERING_AREAS));
339
340 Mutex::Autolock lock(mMeteringAreasLock);
341
342 ret = CameraArea::parseAreas(str, ( strlen(str) + 1 ), tempAreas);
343
344 CAMHAL_LOGVB("areAreasDifferent? = %d",
345 CameraArea::areAreasDifferent(mMeteringAreas, tempAreas));
346
347 if ( (NO_ERROR == ret) && CameraArea::areAreasDifferent(mMeteringAreas, tempAreas) ) {
348 mMeteringAreas.clear();
349 mMeteringAreas = tempAreas;
350
351 if ( MAX_METERING_AREAS >= mMeteringAreas.size() ) {
352 CAMHAL_LOGDB("Setting Metering Areas %s",
353 params.get(CameraParameters::KEY_METERING_AREAS));
354
355 mPending3Asettings |= SetMeteringAreas;
356 } else {
357 CAMHAL_LOGEB("Metering areas supported %d, metering areas set %d",
358 MAX_METERING_AREAS, mMeteringAreas.size());
359 ret = -EINVAL;
360 }
361 }
362 }
363
364 LOG_FUNCTION_NAME_EXIT;
365
366 return ret;
367 }
368
getLUTvalue_HALtoOMX(const char * HalValue,LUTtype LUT)369 int OMXCameraAdapter::getLUTvalue_HALtoOMX(const char * HalValue, LUTtype LUT)
370 {
371 int LUTsize = LUT.size;
372 if( HalValue )
373 for(int i = 0; i < LUTsize; i++)
374 if( 0 == strcmp(LUT.Table[i].userDefinition, HalValue) )
375 return LUT.Table[i].omxDefinition;
376
377 return -ENOENT;
378 }
379
getLUTvalue_OMXtoHAL(int OMXValue,LUTtype LUT)380 const char* OMXCameraAdapter::getLUTvalue_OMXtoHAL(int OMXValue, LUTtype LUT)
381 {
382 int LUTsize = LUT.size;
383 for(int i = 0; i < LUTsize; i++)
384 if( LUT.Table[i].omxDefinition == OMXValue )
385 return LUT.Table[i].userDefinition;
386
387 return NULL;
388 }
389
apply3ADefaults(Gen3A_settings & Gen3A)390 status_t OMXCameraAdapter::apply3ADefaults(Gen3A_settings &Gen3A)
391 {
392 status_t ret = NO_ERROR;
393
394 LOG_FUNCTION_NAME;
395
396 Gen3A.Effect = getLUTvalue_HALtoOMX(OMXCameraAdapter::DEFAULT_EFFECT, EffLUT);
397 ret |= setEffect(Gen3A);
398
399 Gen3A.FlashMode = getLUTvalue_HALtoOMX(OMXCameraAdapter::DEFAULT_FLASH_MODE, FlashLUT);
400 ret |= setFlashMode(Gen3A);
401
402 Gen3A.SceneMode = getLUTvalue_HALtoOMX(OMXCameraAdapter::DEFAULT_SCENE_MODE, SceneLUT);
403 ret |= setScene(Gen3A);
404
405 Gen3A.EVCompensation = atoi(OMXCameraAdapter::DEFAULT_EV_COMPENSATION);
406 ret |= setEVCompensation(Gen3A);
407
408 Gen3A.Focus = getLUTvalue_HALtoOMX(OMXCameraAdapter::DEFAULT_FOCUS_MODE, FocusLUT);
409 ret |= setFocusMode(Gen3A);
410
411 Gen3A.ISO = getLUTvalue_HALtoOMX(OMXCameraAdapter::DEFAULT_ISO_MODE, IsoLUT);
412 ret |= setISO(Gen3A);
413
414 Gen3A.Flicker = getLUTvalue_HALtoOMX(OMXCameraAdapter::DEFAULT_ANTIBANDING, FlickerLUT);
415 ret |= setFlicker(Gen3A);
416
417 Gen3A.Brightness = atoi(OMXCameraAdapter::DEFAULT_BRIGHTNESS);
418 ret |= setBrightness(Gen3A);
419
420 Gen3A.Saturation = atoi(OMXCameraAdapter::DEFAULT_SATURATION) - SATURATION_OFFSET;
421 ret |= setSaturation(Gen3A);
422
423 Gen3A.Sharpness = atoi(OMXCameraAdapter::DEFAULT_SHARPNESS) - SHARPNESS_OFFSET;
424 ret |= setSharpness(Gen3A);
425
426 Gen3A.Contrast = atoi(OMXCameraAdapter::DEFAULT_CONTRAST) - CONTRAST_OFFSET;
427 ret |= setContrast(Gen3A);
428
429 Gen3A.WhiteBallance = getLUTvalue_HALtoOMX(OMXCameraAdapter::DEFAULT_WB, WBalLUT);
430 ret |= setWBMode(Gen3A);
431
432 Gen3A.Exposure = getLUTvalue_HALtoOMX(OMXCameraAdapter::DEFAULT_EXPOSURE_MODE, ExpLUT);
433 ret |= setExposureMode(Gen3A);
434
435 Gen3A.ExposureLock = OMX_FALSE;
436 ret |= setExposureLock(Gen3A);
437
438 Gen3A.FocusLock = OMX_FALSE;
439 ret |= setFocusLock(Gen3A);
440
441 Gen3A.WhiteBalanceLock = OMX_FALSE;
442 ret |= setWhiteBalanceLock(Gen3A);
443
444 LOG_FUNCTION_NAME_EXIT;
445
446 return NO_ERROR;
447 }
448
setExposureMode(Gen3A_settings & Gen3A)449 status_t OMXCameraAdapter::setExposureMode(Gen3A_settings& Gen3A)
450 {
451 OMX_ERRORTYPE eError = OMX_ErrorNone;
452 OMX_CONFIG_EXPOSURECONTROLTYPE exp;
453
454 LOG_FUNCTION_NAME;
455
456 if ( OMX_StateInvalid == mComponentState )
457 {
458 CAMHAL_LOGEA("OMX component is in invalid state");
459 return NO_INIT;
460 }
461
462 OMX_INIT_STRUCT_PTR (&exp, OMX_CONFIG_EXPOSURECONTROLTYPE);
463 exp.nPortIndex = OMX_ALL;
464 exp.eExposureControl = (OMX_EXPOSURECONTROLTYPE)Gen3A.Exposure;
465
466 eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp,
467 OMX_IndexConfigCommonExposure,
468 &exp);
469 if ( OMX_ErrorNone != eError )
470 {
471 CAMHAL_LOGEB("Error while configuring exposure mode 0x%x", eError);
472 }
473 else
474 {
475 CAMHAL_LOGDA("Camera exposure mode configured successfully");
476 }
477
478 LOG_FUNCTION_NAME_EXIT;
479
480 return ErrorUtils::omxToAndroidError(eError);
481 }
482
setFlashMode(Gen3A_settings & Gen3A)483 status_t OMXCameraAdapter::setFlashMode(Gen3A_settings& Gen3A)
484 {
485 status_t ret = NO_ERROR;
486 OMX_ERRORTYPE eError = OMX_ErrorNone;
487 OMX_IMAGE_PARAM_FLASHCONTROLTYPE flash;
488 OMX_CONFIG_FOCUSASSISTTYPE focusAssist;
489
490 LOG_FUNCTION_NAME;
491
492 if ( OMX_StateInvalid == mComponentState )
493 {
494 CAMHAL_LOGEA("OMX component is in invalid state");
495 return NO_INIT;
496 }
497
498 OMX_INIT_STRUCT_PTR (&flash, OMX_IMAGE_PARAM_FLASHCONTROLTYPE);
499 flash.nPortIndex = OMX_ALL;
500 flash.eFlashControl = ( OMX_IMAGE_FLASHCONTROLTYPE ) Gen3A.FlashMode;
501
502 CAMHAL_LOGDB("Configuring flash mode 0x%x", flash.eFlashControl);
503 eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp,
504 (OMX_INDEXTYPE) OMX_IndexConfigFlashControl,
505 &flash);
506 if ( OMX_ErrorNone != eError )
507 {
508 CAMHAL_LOGEB("Error while configuring flash mode 0x%x", eError);
509 }
510 else
511 {
512 CAMHAL_LOGDA("Camera flash mode configured successfully");
513 }
514
515 if ( OMX_ErrorNone == eError )
516 {
517 OMX_INIT_STRUCT_PTR (&focusAssist, OMX_CONFIG_FOCUSASSISTTYPE);
518 focusAssist.nPortIndex = OMX_ALL;
519 if ( flash.eFlashControl == OMX_IMAGE_FlashControlOff )
520 {
521 focusAssist.bFocusAssist = OMX_FALSE;
522 }
523 else
524 {
525 focusAssist.bFocusAssist = OMX_TRUE;
526 }
527
528 CAMHAL_LOGDB("Configuring AF Assist mode 0x%x", focusAssist.bFocusAssist);
529 eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp,
530 (OMX_INDEXTYPE) OMX_IndexConfigFocusAssist,
531 &focusAssist);
532 if ( OMX_ErrorNone != eError )
533 {
534 CAMHAL_LOGEB("Error while configuring AF Assist mode 0x%x", eError);
535 }
536 else
537 {
538 CAMHAL_LOGDA("Camera AF Assist mode configured successfully");
539 }
540 }
541
542 LOG_FUNCTION_NAME_EXIT;
543
544 return ErrorUtils::omxToAndroidError(eError);
545 }
546
getFlashMode(Gen3A_settings & Gen3A)547 status_t OMXCameraAdapter::getFlashMode(Gen3A_settings& Gen3A)
548 {
549 status_t ret = NO_ERROR;
550 OMX_ERRORTYPE eError = OMX_ErrorNone;
551 OMX_IMAGE_PARAM_FLASHCONTROLTYPE flash;
552
553 LOG_FUNCTION_NAME;
554
555 if ( OMX_StateInvalid == mComponentState ) {
556 CAMHAL_LOGEA("OMX component is in invalid state");
557 return NO_INIT;
558 }
559
560 OMX_INIT_STRUCT_PTR (&flash, OMX_IMAGE_PARAM_FLASHCONTROLTYPE);
561 flash.nPortIndex = OMX_ALL;
562
563 eError = OMX_GetConfig(mCameraAdapterParameters.mHandleComp,
564 (OMX_INDEXTYPE) OMX_IndexConfigFlashControl,
565 &flash);
566
567 if ( OMX_ErrorNone != eError ) {
568 CAMHAL_LOGEB("Error while getting flash mode 0x%x", eError);
569 } else {
570 Gen3A.FlashMode = flash.eFlashControl;
571 CAMHAL_LOGDB("Gen3A.FlashMode 0x%x", Gen3A.FlashMode);
572 }
573
574 LOG_FUNCTION_NAME_EXIT;
575
576 return ErrorUtils::omxToAndroidError(eError);
577 }
578
setFocusMode(Gen3A_settings & Gen3A)579 status_t OMXCameraAdapter::setFocusMode(Gen3A_settings& Gen3A)
580 {
581 status_t ret = NO_ERROR;
582 OMX_ERRORTYPE eError = OMX_ErrorNone;
583 OMX_IMAGE_CONFIG_FOCUSCONTROLTYPE focus;
584 size_t top, left, width, height, weight;
585
586 LOG_FUNCTION_NAME;
587
588 BaseCameraAdapter::AdapterState state;
589 BaseCameraAdapter::getState(state);
590
591 if ( OMX_StateInvalid == mComponentState )
592 {
593 CAMHAL_LOGEA("OMX component is in invalid state");
594 return NO_INIT;
595 }
596
597
598 ///Face detection takes precedence over touch AF
599 if ( mFaceDetectionRunning )
600 {
601 //Disable region priority first
602 setAlgoPriority(REGION_PRIORITY, FOCUS_ALGO, false);
603
604 //Enable face algorithm priority for focus
605 setAlgoPriority(FACE_PRIORITY, FOCUS_ALGO , true);
606
607 //Do normal focus afterwards
608 ////FIXME: Check if the extended focus control is needed? this overrides caf
609 //focusControl.eFocusControl = ( OMX_IMAGE_FOCUSCONTROLTYPE ) OMX_IMAGE_FocusControlExtended;
610 }
611 else if ( (!mFocusAreas.isEmpty()) && (!mFocusAreas.itemAt(0)->isZeroArea()) )
612 {
613
614 //Disable face priority first
615 setAlgoPriority(FACE_PRIORITY, FOCUS_ALGO, false);
616
617 //Enable region algorithm priority
618 setAlgoPriority(REGION_PRIORITY, FOCUS_ALGO, true);
619
620
621 //Do normal focus afterwards
622 //FIXME: Check if the extended focus control is needed? this overrides caf
623 //focus.eFocusControl = ( OMX_IMAGE_FOCUSCONTROLTYPE ) OMX_IMAGE_FocusControlExtended;
624
625 }
626 else
627 {
628
629 //Disable both region and face priority
630 setAlgoPriority(REGION_PRIORITY, FOCUS_ALGO, false);
631
632 setAlgoPriority(FACE_PRIORITY, FOCUS_ALGO, false);
633
634 }
635
636 if ( NO_ERROR == ret && ((state & AF_ACTIVE) == 0) )
637 {
638 OMX_INIT_STRUCT_PTR (&focus, OMX_IMAGE_CONFIG_FOCUSCONTROLTYPE);
639 focus.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
640 focus.eFocusControl = (OMX_IMAGE_FOCUSCONTROLTYPE)Gen3A.Focus;
641
642 CAMHAL_LOGDB("Configuring focus mode 0x%x", focus.eFocusControl);
643 eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp, OMX_IndexConfigFocusControl, &focus);
644 if ( OMX_ErrorNone != eError )
645 {
646 CAMHAL_LOGEB("Error while configuring focus mode 0x%x", eError);
647 }
648 else
649 {
650 CAMHAL_LOGDA("Camera focus mode configured successfully");
651 }
652 }
653
654 LOG_FUNCTION_NAME_EXIT;
655
656 return ErrorUtils::omxToAndroidError(eError);
657 }
658
getFocusMode(Gen3A_settings & Gen3A)659 status_t OMXCameraAdapter::getFocusMode(Gen3A_settings& Gen3A)
660 {
661 status_t ret = NO_ERROR;
662 OMX_ERRORTYPE eError = OMX_ErrorNone;
663 OMX_IMAGE_CONFIG_FOCUSCONTROLTYPE focus;
664 size_t top, left, width, height, weight;
665
666 LOG_FUNCTION_NAME;
667
668 if (OMX_StateInvalid == mComponentState) {
669 CAMHAL_LOGEA("OMX component is in invalid state");
670 return NO_INIT;
671 }
672
673 OMX_INIT_STRUCT_PTR (&focus, OMX_IMAGE_CONFIG_FOCUSCONTROLTYPE);
674 focus.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
675 eError = OMX_GetConfig(mCameraAdapterParameters.mHandleComp,
676 OMX_IndexConfigFocusControl, &focus);
677
678 if (OMX_ErrorNone != eError) {
679 CAMHAL_LOGEB("Error while configuring focus mode 0x%x", eError);
680 } else {
681 Gen3A.Focus = focus.eFocusControl;
682 CAMHAL_LOGDB("Gen3A.Focus 0x%x", Gen3A.Focus);
683 }
684
685 LOG_FUNCTION_NAME_EXIT;
686
687 return ErrorUtils::omxToAndroidError(eError);
688 }
689
setScene(Gen3A_settings & Gen3A)690 status_t OMXCameraAdapter::setScene(Gen3A_settings& Gen3A)
691 {
692 OMX_ERRORTYPE eError = OMX_ErrorNone;
693 OMX_CONFIG_SCENEMODETYPE scene;
694
695 LOG_FUNCTION_NAME;
696
697 if ( OMX_StateInvalid == mComponentState )
698 {
699 CAMHAL_LOGEA("OMX component is in invalid state");
700 return NO_INIT;
701 }
702
703 OMX_INIT_STRUCT_PTR (&scene, OMX_CONFIG_SCENEMODETYPE);
704 scene.nPortIndex = OMX_ALL;
705 scene.eSceneMode = ( OMX_SCENEMODETYPE ) Gen3A.SceneMode;
706
707 CAMHAL_LOGDB("Configuring scene mode 0x%x", scene.eSceneMode);
708 eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp,
709 ( OMX_INDEXTYPE ) OMX_TI_IndexConfigSceneMode,
710 &scene);
711
712 if (OMX_ErrorNone != eError) {
713 CAMHAL_LOGEB("Error while configuring scene mode 0x%x", eError);
714 } else {
715 CAMHAL_LOGDA("Camera scene configured successfully");
716 if (Gen3A.SceneMode != OMX_Manual) {
717 // Get preset scene mode feedback
718 getFocusMode(Gen3A);
719 getFlashMode(Gen3A);
720 getWBMode(Gen3A);
721
722 // TODO(XXX): Re-enable these for mainline
723 // getSharpness(Gen3A);
724 // getSaturation(Gen3A);
725 // getISO(Gen3A);
726 }
727 }
728
729 LOG_FUNCTION_NAME_EXIT;
730
731 return ErrorUtils::omxToAndroidError(eError);
732 }
733
setEVCompensation(Gen3A_settings & Gen3A)734 status_t OMXCameraAdapter::setEVCompensation(Gen3A_settings& Gen3A)
735 {
736 OMX_ERRORTYPE eError = OMX_ErrorNone;
737 OMX_CONFIG_EXPOSUREVALUETYPE expValues;
738
739 LOG_FUNCTION_NAME;
740
741 if ( OMX_StateInvalid == mComponentState )
742 {
743 CAMHAL_LOGEA("OMX component is in invalid state");
744 return NO_INIT;
745 }
746
747 OMX_INIT_STRUCT_PTR (&expValues, OMX_CONFIG_EXPOSUREVALUETYPE);
748 expValues.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
749
750 OMX_GetConfig( mCameraAdapterParameters.mHandleComp,
751 OMX_IndexConfigCommonExposureValue,
752 &expValues);
753 CAMHAL_LOGDB("old EV Compensation for OMX = 0x%x", (int)expValues.xEVCompensation);
754 CAMHAL_LOGDB("EV Compensation for HAL = %d", Gen3A.EVCompensation);
755
756 expValues.xEVCompensation = ( Gen3A.EVCompensation * ( 1 << Q16_OFFSET ) ) / 10;
757 eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp,
758 OMX_IndexConfigCommonExposureValue,
759 &expValues);
760 CAMHAL_LOGDB("new EV Compensation for OMX = 0x%x", (int)expValues.xEVCompensation);
761 if ( OMX_ErrorNone != eError )
762 {
763 CAMHAL_LOGEB("Error while configuring EV Compensation 0x%x error = 0x%x",
764 ( unsigned int ) expValues.xEVCompensation,
765 eError);
766 }
767 else
768 {
769 CAMHAL_LOGDB("EV Compensation 0x%x configured successfully",
770 ( unsigned int ) expValues.xEVCompensation);
771 }
772
773 LOG_FUNCTION_NAME_EXIT;
774
775 return ErrorUtils::omxToAndroidError(eError);
776 }
777
getEVCompensation(Gen3A_settings & Gen3A)778 status_t OMXCameraAdapter::getEVCompensation(Gen3A_settings& Gen3A)
779 {
780 OMX_ERRORTYPE eError = OMX_ErrorNone;
781 OMX_CONFIG_EXPOSUREVALUETYPE expValues;
782
783 LOG_FUNCTION_NAME;
784
785 if ( OMX_StateInvalid == mComponentState ) {
786 CAMHAL_LOGEA("OMX component is in invalid state");
787 return NO_INIT;
788 }
789
790 OMX_INIT_STRUCT_PTR (&expValues, OMX_CONFIG_EXPOSUREVALUETYPE);
791 expValues.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
792
793 OMX_GetConfig(mCameraAdapterParameters.mHandleComp,
794 OMX_IndexConfigCommonExposureValue,
795 &expValues);
796
797 if ( OMX_ErrorNone != eError ) {
798 CAMHAL_LOGEB("Error while getting EV Compensation error = 0x%x", eError);
799 } else {
800 Gen3A.EVCompensation = (10 * expValues.xEVCompensation) / (1 << Q16_OFFSET);
801 CAMHAL_LOGDB("Gen3A.EVCompensation 0x%x", Gen3A.EVCompensation);
802 }
803
804 LOG_FUNCTION_NAME_EXIT;
805
806 return ErrorUtils::omxToAndroidError(eError);
807 }
808
setWBMode(Gen3A_settings & Gen3A)809 status_t OMXCameraAdapter::setWBMode(Gen3A_settings& Gen3A)
810 {
811 OMX_ERRORTYPE eError = OMX_ErrorNone;
812 OMX_CONFIG_WHITEBALCONTROLTYPE wb;
813
814 LOG_FUNCTION_NAME;
815
816 if ( OMX_StateInvalid == mComponentState )
817 {
818 CAMHAL_LOGEA("OMX component is in invalid state");
819 return NO_INIT;
820 }
821
822 OMX_INIT_STRUCT_PTR (&wb, OMX_CONFIG_WHITEBALCONTROLTYPE);
823 wb.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
824 wb.eWhiteBalControl = ( OMX_WHITEBALCONTROLTYPE ) Gen3A.WhiteBallance;
825
826 if ( WB_FACE_PRIORITY == Gen3A.WhiteBallance )
827 {
828 //Disable Region priority and enable Face priority
829 setAlgoPriority(REGION_PRIORITY, WHITE_BALANCE_ALGO, false);
830 setAlgoPriority(FACE_PRIORITY, WHITE_BALANCE_ALGO, true);
831
832 //Then set the mode to auto
833 wb.eWhiteBalControl = OMX_WhiteBalControlAuto;
834 }
835 else
836 {
837 //Disable Face and Region priority
838 setAlgoPriority(FACE_PRIORITY, WHITE_BALANCE_ALGO, false);
839 setAlgoPriority(REGION_PRIORITY, WHITE_BALANCE_ALGO, false);
840 }
841
842 eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp,
843 OMX_IndexConfigCommonWhiteBalance,
844 &wb);
845 if ( OMX_ErrorNone != eError )
846 {
847 CAMHAL_LOGEB("Error while configuring Whitebalance mode 0x%x error = 0x%x",
848 ( unsigned int ) wb.eWhiteBalControl,
849 eError);
850 }
851 else
852 {
853 CAMHAL_LOGDB("Whitebalance mode 0x%x configured successfully",
854 ( unsigned int ) wb.eWhiteBalControl);
855 }
856
857 LOG_FUNCTION_NAME_EXIT;
858
859 return eError;
860 }
861
getWBMode(Gen3A_settings & Gen3A)862 status_t OMXCameraAdapter::getWBMode(Gen3A_settings& Gen3A)
863 {
864 OMX_ERRORTYPE eError = OMX_ErrorNone;
865 OMX_CONFIG_WHITEBALCONTROLTYPE wb;
866
867 LOG_FUNCTION_NAME;
868
869 if ( OMX_StateInvalid == mComponentState ) {
870 CAMHAL_LOGEA("OMX component is in invalid state");
871 return NO_INIT;
872 }
873
874 OMX_INIT_STRUCT_PTR (&wb, OMX_CONFIG_WHITEBALCONTROLTYPE);
875 wb.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
876
877 eError = OMX_GetConfig(mCameraAdapterParameters.mHandleComp,
878 OMX_IndexConfigCommonWhiteBalance,
879 &wb);
880
881 if (OMX_ErrorNone != eError) {
882 CAMHAL_LOGEB("Error while getting Whitebalance mode error = 0x%x", eError);
883 } else {
884 Gen3A.WhiteBallance = wb.eWhiteBalControl;
885 CAMHAL_LOGDB("Gen3A.WhiteBallance 0x%x", Gen3A.WhiteBallance);
886 }
887
888 LOG_FUNCTION_NAME_EXIT;
889
890 return eError;
891 }
892
setFlicker(Gen3A_settings & Gen3A)893 status_t OMXCameraAdapter::setFlicker(Gen3A_settings& Gen3A)
894 {
895 OMX_ERRORTYPE eError = OMX_ErrorNone;
896 OMX_CONFIG_FLICKERCANCELTYPE flicker;
897
898 LOG_FUNCTION_NAME;
899
900 if ( OMX_StateInvalid == mComponentState )
901 {
902 CAMHAL_LOGEA("OMX component is in invalid state");
903 return NO_INIT;
904 }
905
906 OMX_INIT_STRUCT_PTR (&flicker, OMX_CONFIG_FLICKERCANCELTYPE);
907 flicker.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
908 flicker.eFlickerCancel = (OMX_COMMONFLICKERCANCELTYPE)Gen3A.Flicker;
909
910 eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp,
911 (OMX_INDEXTYPE)OMX_IndexConfigFlickerCancel,
912 &flicker );
913 if ( OMX_ErrorNone != eError )
914 {
915 CAMHAL_LOGEB("Error while configuring Flicker mode 0x%x error = 0x%x",
916 ( unsigned int ) flicker.eFlickerCancel,
917 eError);
918 }
919 else
920 {
921 CAMHAL_LOGDB("Flicker mode 0x%x configured successfully",
922 ( unsigned int ) flicker.eFlickerCancel);
923 }
924
925 LOG_FUNCTION_NAME_EXIT;
926
927 return ErrorUtils::omxToAndroidError(eError);
928 }
929
setBrightness(Gen3A_settings & Gen3A)930 status_t OMXCameraAdapter::setBrightness(Gen3A_settings& Gen3A)
931 {
932 OMX_ERRORTYPE eError = OMX_ErrorNone;
933 OMX_CONFIG_BRIGHTNESSTYPE brightness;
934
935 LOG_FUNCTION_NAME;
936
937 if ( OMX_StateInvalid == mComponentState )
938 {
939 CAMHAL_LOGEA("OMX component is in invalid state");
940 return NO_INIT;
941 }
942
943 OMX_INIT_STRUCT_PTR (&brightness, OMX_CONFIG_BRIGHTNESSTYPE);
944 brightness.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
945 brightness.nBrightness = Gen3A.Brightness;
946
947 eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp,
948 OMX_IndexConfigCommonBrightness,
949 &brightness);
950 if ( OMX_ErrorNone != eError )
951 {
952 CAMHAL_LOGEB("Error while configuring Brightness 0x%x error = 0x%x",
953 ( unsigned int ) brightness.nBrightness,
954 eError);
955 }
956 else
957 {
958 CAMHAL_LOGDB("Brightness 0x%x configured successfully",
959 ( unsigned int ) brightness.nBrightness);
960 }
961
962 LOG_FUNCTION_NAME_EXIT;
963
964 return ErrorUtils::omxToAndroidError(eError);
965 }
966
setContrast(Gen3A_settings & Gen3A)967 status_t OMXCameraAdapter::setContrast(Gen3A_settings& Gen3A)
968 {
969 OMX_ERRORTYPE eError = OMX_ErrorNone;
970 OMX_CONFIG_CONTRASTTYPE contrast;
971
972 LOG_FUNCTION_NAME;
973
974 if ( OMX_StateInvalid == mComponentState )
975 {
976 CAMHAL_LOGEA("OMX component is in invalid state");
977 return NO_INIT;
978 }
979
980 OMX_INIT_STRUCT_PTR (&contrast, OMX_CONFIG_CONTRASTTYPE);
981 contrast.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
982 contrast.nContrast = Gen3A.Contrast;
983
984 eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp,
985 OMX_IndexConfigCommonContrast,
986 &contrast);
987 if ( OMX_ErrorNone != eError )
988 {
989 CAMHAL_LOGEB("Error while configuring Contrast 0x%x error = 0x%x",
990 ( unsigned int ) contrast.nContrast,
991 eError);
992 }
993 else
994 {
995 CAMHAL_LOGDB("Contrast 0x%x configured successfully",
996 ( unsigned int ) contrast.nContrast);
997 }
998
999 LOG_FUNCTION_NAME_EXIT;
1000
1001 return eError;
1002 }
1003
setSharpness(Gen3A_settings & Gen3A)1004 status_t OMXCameraAdapter::setSharpness(Gen3A_settings& Gen3A)
1005 {
1006 OMX_ERRORTYPE eError = OMX_ErrorNone;
1007 OMX_IMAGE_CONFIG_PROCESSINGLEVELTYPE procSharpness;
1008
1009 LOG_FUNCTION_NAME;
1010
1011 if ( OMX_StateInvalid == mComponentState )
1012 {
1013 CAMHAL_LOGEA("OMX component is in invalid state");
1014 return NO_INIT;
1015 }
1016
1017 OMX_INIT_STRUCT_PTR (&procSharpness, OMX_IMAGE_CONFIG_PROCESSINGLEVELTYPE);
1018 procSharpness.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1019 procSharpness.nLevel = Gen3A.Sharpness;
1020
1021 if( procSharpness.nLevel == 0 )
1022 {
1023 procSharpness.bAuto = OMX_TRUE;
1024 }
1025 else
1026 {
1027 procSharpness.bAuto = OMX_FALSE;
1028 }
1029
1030 eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp,
1031 (OMX_INDEXTYPE)OMX_IndexConfigSharpeningLevel,
1032 &procSharpness);
1033 if ( OMX_ErrorNone != eError )
1034 {
1035 CAMHAL_LOGEB("Error while configuring Sharpness 0x%x error = 0x%x",
1036 ( unsigned int ) procSharpness.nLevel,
1037 eError);
1038 }
1039 else
1040 {
1041 CAMHAL_LOGDB("Sharpness 0x%x configured successfully",
1042 ( unsigned int ) procSharpness.nLevel);
1043 }
1044
1045 LOG_FUNCTION_NAME_EXIT;
1046
1047 return ErrorUtils::omxToAndroidError(eError);
1048 }
1049
getSharpness(Gen3A_settings & Gen3A)1050 status_t OMXCameraAdapter::getSharpness(Gen3A_settings& Gen3A)
1051 {
1052 OMX_ERRORTYPE eError = OMX_ErrorNone;
1053 OMX_IMAGE_CONFIG_PROCESSINGLEVELTYPE procSharpness;
1054
1055 LOG_FUNCTION_NAME;
1056
1057 if (OMX_StateInvalid == mComponentState) {
1058 CAMHAL_LOGEA("OMX component is in invalid state");
1059 return NO_INIT;
1060 }
1061
1062 OMX_INIT_STRUCT_PTR (&procSharpness, OMX_IMAGE_CONFIG_PROCESSINGLEVELTYPE);
1063 procSharpness.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1064
1065 eError = OMX_GetConfig(mCameraAdapterParameters.mHandleComp,
1066 (OMX_INDEXTYPE)OMX_IndexConfigSharpeningLevel,
1067 &procSharpness);
1068
1069 if (OMX_ErrorNone != eError) {
1070 CAMHAL_LOGEB("Error while configuring Sharpness error = 0x%x", eError);
1071 } else {
1072 Gen3A.Sharpness = procSharpness.nLevel;
1073 CAMHAL_LOGDB("Gen3A.Sharpness 0x%x", Gen3A.Sharpness);
1074 }
1075
1076 LOG_FUNCTION_NAME_EXIT;
1077
1078 return ErrorUtils::omxToAndroidError(eError);
1079 }
1080
setSaturation(Gen3A_settings & Gen3A)1081 status_t OMXCameraAdapter::setSaturation(Gen3A_settings& Gen3A)
1082 {
1083 OMX_ERRORTYPE eError = OMX_ErrorNone;
1084 OMX_CONFIG_SATURATIONTYPE saturation;
1085
1086 LOG_FUNCTION_NAME;
1087
1088 if ( OMX_StateInvalid == mComponentState )
1089 {
1090 CAMHAL_LOGEA("OMX component is in invalid state");
1091 return NO_INIT;
1092 }
1093
1094 OMX_INIT_STRUCT_PTR (&saturation, OMX_CONFIG_SATURATIONTYPE);
1095 saturation.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1096 saturation.nSaturation = Gen3A.Saturation;
1097
1098 eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp,
1099 OMX_IndexConfigCommonSaturation,
1100 &saturation);
1101 if ( OMX_ErrorNone != eError )
1102 {
1103 CAMHAL_LOGEB("Error while configuring Saturation 0x%x error = 0x%x",
1104 ( unsigned int ) saturation.nSaturation,
1105 eError);
1106 }
1107 else
1108 {
1109 CAMHAL_LOGDB("Saturation 0x%x configured successfully",
1110 ( unsigned int ) saturation.nSaturation);
1111 }
1112
1113 LOG_FUNCTION_NAME_EXIT;
1114
1115 return ErrorUtils::omxToAndroidError(eError);
1116 }
1117
getSaturation(Gen3A_settings & Gen3A)1118 status_t OMXCameraAdapter::getSaturation(Gen3A_settings& Gen3A)
1119 {
1120 OMX_ERRORTYPE eError = OMX_ErrorNone;
1121 OMX_CONFIG_SATURATIONTYPE saturation;
1122
1123 LOG_FUNCTION_NAME;
1124
1125 if (OMX_StateInvalid == mComponentState) {
1126 CAMHAL_LOGEA("OMX component is in invalid state");
1127 return NO_INIT;
1128 }
1129
1130 OMX_INIT_STRUCT_PTR (&saturation, OMX_CONFIG_SATURATIONTYPE);
1131 saturation.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1132
1133 eError = OMX_GetConfig( mCameraAdapterParameters.mHandleComp,
1134 OMX_IndexConfigCommonSaturation,
1135 &saturation);
1136
1137 if (OMX_ErrorNone != eError) {
1138 CAMHAL_LOGEB("Error while getting Saturation error = 0x%x", eError);
1139 } else {
1140 Gen3A.Saturation = saturation.nSaturation;
1141 CAMHAL_LOGDB("Gen3A.Saturation 0x%x", Gen3A.Saturation);
1142 }
1143
1144 LOG_FUNCTION_NAME_EXIT;
1145
1146 return ErrorUtils::omxToAndroidError(eError);
1147 }
1148
setISO(Gen3A_settings & Gen3A)1149 status_t OMXCameraAdapter::setISO(Gen3A_settings& Gen3A)
1150 {
1151 OMX_ERRORTYPE eError = OMX_ErrorNone;
1152 OMX_CONFIG_EXPOSUREVALUETYPE expValues;
1153
1154 LOG_FUNCTION_NAME;
1155
1156 if ( OMX_StateInvalid == mComponentState )
1157 {
1158 CAMHAL_LOGEA("OMX component is in invalid state");
1159 return NO_INIT;
1160 }
1161
1162 OMX_INIT_STRUCT_PTR (&expValues, OMX_CONFIG_EXPOSUREVALUETYPE);
1163 expValues.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1164
1165 OMX_GetConfig( mCameraAdapterParameters.mHandleComp,
1166 OMX_IndexConfigCommonExposureValue,
1167 &expValues);
1168
1169 if( 0 == Gen3A.ISO )
1170 {
1171 expValues.bAutoSensitivity = OMX_TRUE;
1172 }
1173 else
1174 {
1175 expValues.bAutoSensitivity = OMX_FALSE;
1176 expValues.nSensitivity = Gen3A.ISO;
1177 }
1178
1179 eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp,
1180 OMX_IndexConfigCommonExposureValue,
1181 &expValues);
1182 if ( OMX_ErrorNone != eError )
1183 {
1184 CAMHAL_LOGEB("Error while configuring ISO 0x%x error = 0x%x",
1185 ( unsigned int ) expValues.nSensitivity,
1186 eError);
1187 }
1188 else
1189 {
1190 CAMHAL_LOGDB("ISO 0x%x configured successfully",
1191 ( unsigned int ) expValues.nSensitivity);
1192 }
1193
1194 LOG_FUNCTION_NAME_EXIT;
1195
1196 return ErrorUtils::omxToAndroidError(eError);
1197 }
1198
getISO(Gen3A_settings & Gen3A)1199 status_t OMXCameraAdapter::getISO(Gen3A_settings& Gen3A)
1200 {
1201 OMX_ERRORTYPE eError = OMX_ErrorNone;
1202 OMX_CONFIG_EXPOSUREVALUETYPE expValues;
1203
1204 LOG_FUNCTION_NAME;
1205
1206 if (OMX_StateInvalid == mComponentState) {
1207 CAMHAL_LOGEA("OMX component is in invalid state");
1208 return NO_INIT;
1209 }
1210
1211 OMX_INIT_STRUCT_PTR (&expValues, OMX_CONFIG_EXPOSUREVALUETYPE);
1212 expValues.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1213
1214 OMX_GetConfig( mCameraAdapterParameters.mHandleComp,
1215 OMX_IndexConfigCommonExposureValue,
1216 &expValues);
1217
1218 if (OMX_ErrorNone != eError) {
1219 CAMHAL_LOGEB("Error while getting ISO error = 0x%x", eError);
1220 } else {
1221 Gen3A.ISO = expValues.nSensitivity;
1222 CAMHAL_LOGDB("Gen3A.ISO %d", Gen3A.ISO);
1223 }
1224
1225 LOG_FUNCTION_NAME_EXIT;
1226
1227 return ErrorUtils::omxToAndroidError(eError);
1228 }
1229
setEffect(Gen3A_settings & Gen3A)1230 status_t OMXCameraAdapter::setEffect(Gen3A_settings& Gen3A)
1231 {
1232 OMX_ERRORTYPE eError = OMX_ErrorNone;
1233 OMX_CONFIG_IMAGEFILTERTYPE effect;
1234
1235 LOG_FUNCTION_NAME;
1236
1237 if ( OMX_StateInvalid == mComponentState )
1238 {
1239 CAMHAL_LOGEA("OMX component is in invalid state");
1240 return NO_INIT;
1241 }
1242
1243 OMX_INIT_STRUCT_PTR (&effect, OMX_CONFIG_IMAGEFILTERTYPE);
1244 effect.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1245 effect.eImageFilter = (OMX_IMAGEFILTERTYPE ) Gen3A.Effect;
1246
1247 eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp,
1248 OMX_IndexConfigCommonImageFilter,
1249 &effect);
1250 if ( OMX_ErrorNone != eError )
1251 {
1252 CAMHAL_LOGEB("Error while configuring Effect 0x%x error = 0x%x",
1253 ( unsigned int ) effect.eImageFilter,
1254 eError);
1255 }
1256 else
1257 {
1258 CAMHAL_LOGDB("Effect 0x%x configured successfully",
1259 ( unsigned int ) effect.eImageFilter);
1260 }
1261
1262 LOG_FUNCTION_NAME_EXIT;
1263
1264 return ErrorUtils::omxToAndroidError(eError);
1265 }
1266
setWhiteBalanceLock(Gen3A_settings & Gen3A)1267 status_t OMXCameraAdapter::setWhiteBalanceLock(Gen3A_settings& Gen3A)
1268 {
1269 OMX_ERRORTYPE eError = OMX_ErrorNone;
1270 OMX_IMAGE_CONFIG_LOCKTYPE lock;
1271
1272 LOG_FUNCTION_NAME
1273
1274 if ( OMX_StateInvalid == mComponentState )
1275 {
1276 CAMHAL_LOGEA("OMX component is in invalid state");
1277 return NO_INIT;
1278 }
1279
1280 OMX_INIT_STRUCT_PTR (&lock, OMX_IMAGE_CONFIG_LOCKTYPE);
1281 lock.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1282 lock.bLock = Gen3A.WhiteBalanceLock;
1283 eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp,
1284 (OMX_INDEXTYPE)OMX_IndexConfigImageWhiteBalanceLock,
1285 &lock);
1286 if ( OMX_ErrorNone != eError )
1287 {
1288 CAMHAL_LOGEB("Error while configuring WhiteBalance Lock error = 0x%x", eError);
1289 }
1290 else
1291 {
1292 CAMHAL_LOGDB("WhiteBalance Lock configured successfully %d ", lock.bLock);
1293 }
1294 LOG_FUNCTION_NAME_EXIT
1295
1296 return ErrorUtils::omxToAndroidError(eError);
1297 }
1298
setExposureLock(Gen3A_settings & Gen3A)1299 status_t OMXCameraAdapter::setExposureLock(Gen3A_settings& Gen3A)
1300 {
1301 OMX_ERRORTYPE eError = OMX_ErrorNone;
1302 OMX_IMAGE_CONFIG_LOCKTYPE lock;
1303
1304 LOG_FUNCTION_NAME
1305
1306 if ( OMX_StateInvalid == mComponentState )
1307 {
1308 CAMHAL_LOGEA("OMX component is in invalid state");
1309 return NO_INIT;
1310 }
1311
1312 OMX_INIT_STRUCT_PTR (&lock, OMX_IMAGE_CONFIG_LOCKTYPE);
1313 lock.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1314 lock.bLock = Gen3A.ExposureLock;
1315 eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp,
1316 (OMX_INDEXTYPE)OMX_IndexConfigImageExposureLock,
1317 &lock);
1318 if ( OMX_ErrorNone != eError )
1319 {
1320 CAMHAL_LOGEB("Error while configuring Exposure Lock error = 0x%x", eError);
1321 }
1322 else
1323 {
1324 CAMHAL_LOGDB("Exposure Lock configured successfully %d ", lock.bLock);
1325 }
1326 LOG_FUNCTION_NAME_EXIT
1327
1328 return ErrorUtils::omxToAndroidError(eError);
1329 }
1330
setFocusLock(Gen3A_settings & Gen3A)1331 status_t OMXCameraAdapter::setFocusLock(Gen3A_settings& Gen3A)
1332 {
1333 OMX_ERRORTYPE eError = OMX_ErrorNone;
1334 OMX_IMAGE_CONFIG_LOCKTYPE lock;
1335
1336 LOG_FUNCTION_NAME
1337
1338 if ( OMX_StateInvalid == mComponentState ) {
1339 CAMHAL_LOGEA("OMX component is in invalid state");
1340 return NO_INIT;
1341 }
1342
1343 OMX_INIT_STRUCT_PTR (&lock, OMX_IMAGE_CONFIG_LOCKTYPE);
1344 lock.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1345
1346 lock.bLock = Gen3A.FocusLock;
1347 eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp,
1348 (OMX_INDEXTYPE)OMX_IndexConfigImageFocusLock,
1349 &lock);
1350
1351 if ( OMX_ErrorNone != eError ) {
1352 CAMHAL_LOGEB("Error while configuring Focus Lock error = 0x%x", eError);
1353 } else {
1354 CAMHAL_LOGDB("Focus Lock configured successfully %d ", lock.bLock);
1355 }
1356
1357 LOG_FUNCTION_NAME_EXIT
1358
1359 return ErrorUtils::omxToAndroidError(eError);
1360 }
1361
set3ALock(OMX_BOOL toggleExp,OMX_BOOL toggleWb,OMX_BOOL toggleFocus)1362 status_t OMXCameraAdapter::set3ALock(OMX_BOOL toggleExp, OMX_BOOL toggleWb, OMX_BOOL toggleFocus)
1363 {
1364 OMX_ERRORTYPE eError = OMX_ErrorNone;
1365 OMX_IMAGE_CONFIG_LOCKTYPE lock;
1366
1367 LOG_FUNCTION_NAME
1368
1369 if ( OMX_StateInvalid == mComponentState )
1370 {
1371 CAMHAL_LOGEA("OMX component is in invalid state");
1372 return NO_INIT;
1373 }
1374
1375 OMX_INIT_STRUCT_PTR (&lock, OMX_IMAGE_CONFIG_LOCKTYPE);
1376 lock.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1377
1378 mParameters3A.ExposureLock = toggleExp;
1379 mParameters3A.FocusLock = toggleFocus;
1380 mParameters3A.WhiteBalanceLock = toggleWb;
1381
1382 eError = OMX_GetConfig( mCameraAdapterParameters.mHandleComp,
1383 (OMX_INDEXTYPE)OMX_IndexConfigImageExposureLock,
1384 &lock);
1385
1386 if ( OMX_ErrorNone != eError )
1387 {
1388 CAMHAL_LOGEB("Error GetConfig Exposure Lock error = 0x%x", eError);
1389 goto EXIT;
1390 }
1391 else
1392 {
1393 const char *lock_state_exp = toggleExp ? TRUE : FALSE;
1394 CAMHAL_LOGDA("Exposure Lock GetConfig successfull");
1395
1396 /* Apply locks only when not applied already */
1397 if ( lock.bLock != toggleExp )
1398 {
1399 setExposureLock(mParameters3A);
1400 }
1401
1402 mParams.set(CameraParameters::KEY_AUTO_EXPOSURE_LOCK, lock_state_exp);
1403 }
1404
1405 OMX_INIT_STRUCT_PTR (&lock, OMX_IMAGE_CONFIG_LOCKTYPE);
1406 lock.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1407 eError = OMX_GetConfig( mCameraAdapterParameters.mHandleComp,
1408 (OMX_INDEXTYPE)OMX_IndexConfigImageFocusLock,
1409 &lock);
1410
1411 if ( OMX_ErrorNone != eError )
1412 {
1413 CAMHAL_LOGEB("Error GetConfig Focus Lock error = 0x%x", eError);
1414 goto EXIT;
1415 }
1416 else
1417 {
1418 CAMHAL_LOGDB("Focus Lock GetConfig successfull bLock(%d)", lock.bLock);
1419
1420 /* Apply locks only when not applied already */
1421 if ( lock.bLock != toggleFocus )
1422 {
1423 setFocusLock(mParameters3A);
1424 }
1425 }
1426
1427 OMX_INIT_STRUCT_PTR (&lock, OMX_IMAGE_CONFIG_LOCKTYPE);
1428 lock.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1429 eError = OMX_GetConfig( mCameraAdapterParameters.mHandleComp,
1430 (OMX_INDEXTYPE)OMX_IndexConfigImageWhiteBalanceLock,
1431 &lock);
1432
1433 if ( OMX_ErrorNone != eError )
1434 {
1435 CAMHAL_LOGEB("Error GetConfig WhiteBalance Lock error = 0x%x", eError);
1436 goto EXIT;
1437 }
1438 else
1439 {
1440 const char *lock_state_wb = toggleWb ? TRUE : FALSE;
1441 CAMHAL_LOGDA("WhiteBalance Lock GetConfig successfull");
1442
1443 /* Apply locks only when not applied already */
1444 if ( lock.bLock != toggleWb )
1445 {
1446 setWhiteBalanceLock(mParameters3A);
1447 }
1448
1449 mParams.set(CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK, lock_state_wb);
1450 }
1451 EXIT:
1452 return ErrorUtils::omxToAndroidError(eError);
1453 }
1454
setMeteringAreas(Gen3A_settings & Gen3A)1455 status_t OMXCameraAdapter::setMeteringAreas(Gen3A_settings& Gen3A)
1456 {
1457 status_t ret = NO_ERROR;
1458 OMX_ERRORTYPE eError = OMX_ErrorNone;
1459
1460 OMX_ALGOAREASTYPE **meteringAreas;
1461 OMX_TI_CONFIG_SHAREDBUFFER sharedBuffer;
1462 MemoryManager memMgr;
1463 int areasSize = 0;
1464
1465 LOG_FUNCTION_NAME
1466
1467 Mutex::Autolock lock(mMeteringAreasLock);
1468
1469 if ( OMX_StateInvalid == mComponentState )
1470 {
1471 CAMHAL_LOGEA("OMX component is in invalid state");
1472 return NO_INIT;
1473 }
1474
1475 areasSize = ((sizeof(OMX_ALGOAREASTYPE)+4095)/4096)*4096;
1476 meteringAreas = (OMX_ALGOAREASTYPE**) memMgr.allocateBuffer(0, 0, NULL, areasSize, 1);
1477
1478 OMXCameraPortParameters * mPreviewData = NULL;
1479 mPreviewData = &mCameraAdapterParameters.mCameraPortParams[mCameraAdapterParameters.mPrevPortIndex];
1480
1481 if (!meteringAreas)
1482 {
1483 CAMHAL_LOGEB("Error allocating buffer for metering areas %d", eError);
1484 return -ENOMEM;
1485 }
1486
1487 OMX_INIT_STRUCT_PTR (meteringAreas[0], OMX_ALGOAREASTYPE);
1488
1489 meteringAreas[0]->nPortIndex = OMX_ALL;
1490 meteringAreas[0]->nNumAreas = mMeteringAreas.size();
1491 meteringAreas[0]->nAlgoAreaPurpose = OMX_AlgoAreaExposure;
1492
1493 for ( unsigned int n = 0; n < mMeteringAreas.size(); n++)
1494 {
1495 // transform the coordinates to 3A-type coordinates
1496 mMeteringAreas.itemAt(n)->transfrom((size_t)mPreviewData->mWidth,
1497 (size_t)mPreviewData->mHeight,
1498 (size_t&)meteringAreas[0]->tAlgoAreas[n].nTop,
1499 (size_t&)meteringAreas[0]->tAlgoAreas[n].nLeft,
1500 (size_t&)meteringAreas[0]->tAlgoAreas[n].nWidth,
1501 (size_t&)meteringAreas[0]->tAlgoAreas[n].nHeight);
1502
1503 meteringAreas[0]->tAlgoAreas[n].nLeft =
1504 ( meteringAreas[0]->tAlgoAreas[n].nLeft * METERING_AREAS_RANGE ) / mPreviewData->mWidth;
1505 meteringAreas[0]->tAlgoAreas[n].nTop =
1506 ( meteringAreas[0]->tAlgoAreas[n].nTop* METERING_AREAS_RANGE ) / mPreviewData->mHeight;
1507 meteringAreas[0]->tAlgoAreas[n].nWidth =
1508 ( meteringAreas[0]->tAlgoAreas[n].nWidth * METERING_AREAS_RANGE ) / mPreviewData->mWidth;
1509 meteringAreas[0]->tAlgoAreas[n].nHeight =
1510 ( meteringAreas[0]->tAlgoAreas[n].nHeight * METERING_AREAS_RANGE ) / mPreviewData->mHeight;
1511
1512 meteringAreas[0]->tAlgoAreas[n].nPriority = mMeteringAreas.itemAt(n)->getWeight();
1513
1514 CAMHAL_LOGDB("Metering area %d : top = %d left = %d width = %d height = %d prio = %d",
1515 n, (int)meteringAreas[0]->tAlgoAreas[n].nTop, (int)meteringAreas[0]->tAlgoAreas[n].nLeft,
1516 (int)meteringAreas[0]->tAlgoAreas[n].nWidth, (int)meteringAreas[0]->tAlgoAreas[n].nHeight,
1517 (int)meteringAreas[0]->tAlgoAreas[n].nPriority);
1518
1519 }
1520
1521 OMX_INIT_STRUCT_PTR (&sharedBuffer, OMX_TI_CONFIG_SHAREDBUFFER);
1522
1523 sharedBuffer.nPortIndex = OMX_ALL;
1524 sharedBuffer.nSharedBuffSize = areasSize;
1525 sharedBuffer.pSharedBuff = (OMX_U8 *) meteringAreas[0];
1526
1527 if ( NULL == sharedBuffer.pSharedBuff )
1528 {
1529 CAMHAL_LOGEA("No resources to allocate OMX shared buffer");
1530 ret = -ENOMEM;
1531 goto EXIT;
1532 }
1533
1534 eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp,
1535 (OMX_INDEXTYPE) OMX_TI_IndexConfigAlgoAreas, &sharedBuffer);
1536
1537 if ( OMX_ErrorNone != eError )
1538 {
1539 CAMHAL_LOGEB("Error while setting Focus Areas configuration 0x%x", eError);
1540 ret = -EINVAL;
1541 }
1542 else
1543 {
1544 CAMHAL_LOGDA("Metering Areas SetConfig successfull.");
1545 }
1546
1547 EXIT:
1548 if (NULL != meteringAreas)
1549 {
1550 memMgr.freeBuffer((void*) meteringAreas);
1551 meteringAreas = NULL;
1552 }
1553
1554 return ret;
1555 }
1556
apply3Asettings(Gen3A_settings & Gen3A)1557 status_t OMXCameraAdapter::apply3Asettings( Gen3A_settings& Gen3A )
1558 {
1559 status_t ret = NO_ERROR;
1560 unsigned int currSett; // 32 bit
1561 int portIndex;
1562
1563 LOG_FUNCTION_NAME;
1564
1565 Mutex::Autolock lock(m3ASettingsUpdateLock);
1566
1567 /*
1568 * Scenes have a priority during the process
1569 * of applying 3A related parameters.
1570 * They can override pretty much all other 3A
1571 * settings and similarly get overridden when
1572 * for instance the focus mode gets switched.
1573 * There is only one exception to this rule,
1574 * the manual a.k.a. auto scene.
1575 */
1576 if (SetSceneMode & mPending3Asettings) {
1577 mPending3Asettings &= ~SetSceneMode;
1578 ret |= setScene(Gen3A);
1579 // re-apply EV compensation after setting scene mode since it probably reset it
1580 if(Gen3A.EVCompensation) {
1581 setEVCompensation(Gen3A);
1582 }
1583 return ret;
1584 } else if (OMX_Manual != Gen3A.SceneMode) {
1585 // only certain settings are allowed when scene mode is set
1586 mPending3Asettings &= (SetEVCompensation | SetFocus | SetWBLock |
1587 SetExpLock | SetWhiteBallance | SetFlash);
1588 if ( mPending3Asettings == 0 ) return NO_ERROR;
1589 }
1590
1591 for( currSett = 1; currSett < E3aSettingMax; currSett <<= 1)
1592 {
1593 if( currSett & mPending3Asettings )
1594 {
1595 switch( currSett )
1596 {
1597 case SetEVCompensation:
1598 {
1599 ret |= setEVCompensation(Gen3A);
1600 break;
1601 }
1602
1603 case SetWhiteBallance:
1604 {
1605 ret |= setWBMode(Gen3A);
1606 break;
1607 }
1608
1609 case SetFlicker:
1610 {
1611 ret |= setFlicker(Gen3A);
1612 break;
1613 }
1614
1615 case SetBrightness:
1616 {
1617 ret |= setBrightness(Gen3A);
1618 break;
1619 }
1620
1621 case SetContrast:
1622 {
1623 ret |= setContrast(Gen3A);
1624 break;
1625 }
1626
1627 case SetSharpness:
1628 {
1629 ret |= setSharpness(Gen3A);
1630 break;
1631 }
1632
1633 case SetSaturation:
1634 {
1635 ret |= setSaturation(Gen3A);
1636 break;
1637 }
1638
1639 case SetISO:
1640 {
1641 ret |= setISO(Gen3A);
1642 break;
1643 }
1644
1645 case SetEffect:
1646 {
1647 ret |= setEffect(Gen3A);
1648 break;
1649 }
1650
1651 case SetFocus:
1652 {
1653 ret |= setFocusMode(Gen3A);
1654 break;
1655 }
1656
1657 case SetExpMode:
1658 {
1659 ret |= setExposureMode(Gen3A);
1660 break;
1661 }
1662
1663 case SetFlash:
1664 {
1665 ret |= setFlashMode(Gen3A);
1666 break;
1667 }
1668
1669 case SetExpLock:
1670 {
1671 ret |= setExposureLock(Gen3A);
1672 break;
1673 }
1674
1675 case SetWBLock:
1676 {
1677 ret |= setWhiteBalanceLock(Gen3A);
1678 break;
1679 }
1680 case SetMeteringAreas:
1681 {
1682 ret |= setMeteringAreas(Gen3A);
1683 }
1684 break;
1685 default:
1686 CAMHAL_LOGEB("this setting (0x%x) is still not supported in CameraAdapter ",
1687 currSett);
1688 break;
1689 }
1690 mPending3Asettings &= ~currSett;
1691 }
1692 }
1693
1694 LOG_FUNCTION_NAME_EXIT;
1695
1696 return ret;
1697 }
1698
1699 };
1700