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