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 OMXAlgo.cpp 19 * 20 * This file contains functionality for handling algorithm 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 34 namespace android { 35 36 status_t OMXCameraAdapter::setParametersAlgo(const CameraParameters ¶ms, 37 BaseCameraAdapter::AdapterState state) 38 { 39 status_t ret = NO_ERROR; 40 const char *valstr = NULL; 41 const char *oldstr = NULL; 42 43 LOG_FUNCTION_NAME; 44 45 CaptureMode capMode; 46 CAMHAL_LOGDB("Capture mode %s", params.get(TICameraParameters::KEY_CAP_MODE)); 47 if ( (valstr = params.get(TICameraParameters::KEY_CAP_MODE)) != NULL ) 48 { 49 if (strcmp(valstr, (const char *) TICameraParameters::HIGH_PERFORMANCE_MODE) == 0) 50 { 51 capMode = OMXCameraAdapter::HIGH_SPEED; 52 } 53 else if (strcmp(valstr, (const char *) TICameraParameters::HIGH_QUALITY_MODE) == 0) 54 { 55 capMode = OMXCameraAdapter::HIGH_QUALITY; 56 } 57 else if (strcmp(valstr, (const char *) TICameraParameters::HIGH_QUALITY_ZSL_MODE) == 0) 58 { 59 capMode = OMXCameraAdapter::HIGH_QUALITY_ZSL; 60 } 61 else if (strcmp(valstr, (const char *) TICameraParameters::VIDEO_MODE) == 0) 62 { 63 capMode = OMXCameraAdapter::VIDEO_MODE; 64 } 65 else 66 { 67 capMode = OMXCameraAdapter::HIGH_QUALITY; 68 } 69 } 70 else 71 { 72 capMode = OMXCameraAdapter::HIGH_QUALITY_ZSL; 73 74 } 75 76 if ( mCapMode != capMode ) 77 { 78 mCapMode = capMode; 79 mOMXStateSwitch = true; 80 } 81 82 CAMHAL_LOGDB("Capture Mode set %d", mCapMode); 83 84 /// Configure IPP, LDCNSF, GBCE and GLBCE only in HQ mode 85 IPPMode ipp; 86 if((mCapMode == OMXCameraAdapter::HIGH_QUALITY) || (mCapMode == OMXCameraAdapter::HIGH_QUALITY_ZSL) 87 || (mCapMode == OMXCameraAdapter::VIDEO_MODE) ) 88 { 89 if ( (valstr = params.get(TICameraParameters::KEY_IPP)) != NULL ) 90 { 91 if (strcmp(valstr, (const char *) TICameraParameters::IPP_LDCNSF) == 0) 92 { 93 ipp = OMXCameraAdapter::IPP_LDCNSF; 94 } 95 else if (strcmp(valstr, (const char *) TICameraParameters::IPP_LDC) == 0) 96 { 97 ipp = OMXCameraAdapter::IPP_LDC; 98 } 99 else if (strcmp(valstr, (const char *) TICameraParameters::IPP_NSF) == 0) 100 { 101 ipp = OMXCameraAdapter::IPP_NSF; 102 } 103 else if (strcmp(valstr, (const char *) TICameraParameters::IPP_NONE) == 0) 104 { 105 ipp = OMXCameraAdapter::IPP_NONE; 106 } 107 else 108 { 109 ipp = OMXCameraAdapter::IPP_NONE; 110 } 111 } 112 else 113 { 114 ipp = OMXCameraAdapter::IPP_NONE; 115 } 116 117 CAMHAL_LOGVB("IPP Mode set %d", ipp); 118 119 if (((valstr = params.get(TICameraParameters::KEY_GBCE)) != NULL) ) 120 { 121 // Configure GBCE only if the setting has changed since last time 122 oldstr = mParams.get(TICameraParameters::KEY_GBCE); 123 bool cmpRes = true; 124 if ( NULL != oldstr ) 125 { 126 cmpRes = strcmp(valstr, oldstr) != 0; 127 } 128 else 129 { 130 cmpRes = true; 131 } 132 133 134 if( cmpRes ) 135 { 136 if (strcmp(valstr, ( const char * ) TICameraParameters::GBCE_ENABLE ) == 0) 137 { 138 setGBCE(OMXCameraAdapter::BRIGHTNESS_ON); 139 } 140 else if (strcmp(valstr, ( const char * ) TICameraParameters::GBCE_DISABLE ) == 0) 141 { 142 setGBCE(OMXCameraAdapter::BRIGHTNESS_OFF); 143 } 144 else 145 { 146 setGBCE(OMXCameraAdapter::BRIGHTNESS_OFF); 147 } 148 } 149 } 150 else if(mParams.get(TICameraParameters::KEY_GBCE) || mFirstTimeInit) 151 { 152 //Disable GBCE by default 153 setGBCE(OMXCameraAdapter::BRIGHTNESS_OFF); 154 } 155 156 if ( ( valstr = params.get(TICameraParameters::KEY_GLBCE) ) != NULL ) 157 { 158 // Configure GLBCE only if the setting has changed since last time 159 160 oldstr = mParams.get(TICameraParameters::KEY_GLBCE); 161 bool cmpRes = true; 162 if ( NULL != oldstr ) 163 { 164 cmpRes = strcmp(valstr, oldstr) != 0; 165 } 166 else 167 { 168 cmpRes = true; 169 } 170 171 172 if( cmpRes ) 173 { 174 if (strcmp(valstr, ( const char * ) TICameraParameters::GLBCE_ENABLE ) == 0) 175 { 176 setGLBCE(OMXCameraAdapter::BRIGHTNESS_ON); 177 } 178 else if (strcmp(valstr, ( const char * ) TICameraParameters::GLBCE_DISABLE ) == 0) 179 { 180 setGLBCE(OMXCameraAdapter::BRIGHTNESS_OFF); 181 } 182 else 183 { 184 setGLBCE(OMXCameraAdapter::BRIGHTNESS_OFF); 185 } 186 } 187 } 188 else if(mParams.get(TICameraParameters::KEY_GLBCE) || mFirstTimeInit) 189 { 190 //Disable GLBCE by default 191 setGLBCE(OMXCameraAdapter::BRIGHTNESS_OFF); 192 } 193 } 194 else 195 { 196 ipp = OMXCameraAdapter::IPP_NONE; 197 } 198 199 if ( mIPP != ipp ) 200 { 201 mIPP = ipp; 202 mOMXStateSwitch = true; 203 } 204 205 ///Set VNF Configuration 206 bool vnfEnabled = false; 207 if ( params.getInt(TICameraParameters::KEY_VNF) > 0 ) 208 { 209 CAMHAL_LOGDA("VNF Enabled"); 210 vnfEnabled = true; 211 } 212 else 213 { 214 CAMHAL_LOGDA("VNF Disabled"); 215 vnfEnabled = false; 216 } 217 218 if ( mVnfEnabled != vnfEnabled ) 219 { 220 mVnfEnabled = vnfEnabled; 221 mOMXStateSwitch = true; 222 } 223 224 ///Set VSTAB Configuration 225 bool vstabEnabled = false; 226 valstr = params.get(CameraParameters::KEY_VIDEO_STABILIZATION); 227 if (valstr && strcmp(valstr, CameraParameters::TRUE) == 0) { 228 CAMHAL_LOGDA("VSTAB Enabled"); 229 vstabEnabled = true; 230 } 231 else 232 { 233 CAMHAL_LOGDA("VSTAB Disabled"); 234 vstabEnabled = false; 235 } 236 237 if ( mVstabEnabled != vstabEnabled ) 238 { 239 mVstabEnabled = vstabEnabled; 240 mOMXStateSwitch = true; 241 } 242 243 //A work-around for a failing call to OMX flush buffers 244 if ( ( capMode = OMXCameraAdapter::VIDEO_MODE ) && 245 ( mVstabEnabled ) ) 246 { 247 mOMXStateSwitch = true; 248 } 249 250 //Set Auto Convergence Mode 251 valstr = params.get((const char *) TICameraParameters::KEY_AUTOCONVERGENCE); 252 if ( valstr != NULL ) 253 { 254 // Set ManualConvergence default value 255 OMX_S32 manualconvergence = -30; 256 if ( strcmp (valstr, (const char *) TICameraParameters::AUTOCONVERGENCE_MODE_DISABLE) == 0 ) 257 { 258 setAutoConvergence(OMX_TI_AutoConvergenceModeDisable, manualconvergence); 259 } 260 else if ( strcmp (valstr, (const char *) TICameraParameters::AUTOCONVERGENCE_MODE_FRAME) == 0 ) 261 { 262 setAutoConvergence(OMX_TI_AutoConvergenceModeFrame, manualconvergence); 263 } 264 else if ( strcmp (valstr, (const char *) TICameraParameters::AUTOCONVERGENCE_MODE_CENTER) == 0 ) 265 { 266 setAutoConvergence(OMX_TI_AutoConvergenceModeCenter, manualconvergence); 267 } 268 else if ( strcmp (valstr, (const char *) TICameraParameters::AUTOCONVERGENCE_MODE_FFT) == 0 ) 269 { 270 setAutoConvergence(OMX_TI_AutoConvergenceModeFocusFaceTouch, manualconvergence); 271 } 272 else if ( strcmp (valstr, (const char *) TICameraParameters::AUTOCONVERGENCE_MODE_MANUAL) == 0 ) 273 { 274 manualconvergence = (OMX_S32)params.getInt(TICameraParameters::KEY_MANUALCONVERGENCE_VALUES); 275 setAutoConvergence(OMX_TI_AutoConvergenceModeManual, manualconvergence); 276 } 277 CAMHAL_LOGVB("AutoConvergenceMode %s, value = %d", valstr, (int) manualconvergence); 278 } 279 280 LOG_FUNCTION_NAME_EXIT; 281 282 return ret; 283 } 284 285 // Get AutoConvergence 286 status_t OMXCameraAdapter::getAutoConvergence(OMX_TI_AUTOCONVERGENCEMODETYPE *pACMode, 287 OMX_S32 *pManualConverence) 288 { 289 status_t ret = NO_ERROR; 290 OMX_ERRORTYPE eError = OMX_ErrorNone; 291 OMX_TI_CONFIG_CONVERGENCETYPE ACParams; 292 293 ACParams.nSize = sizeof(OMX_TI_CONFIG_CONVERGENCETYPE); 294 ACParams.nVersion = mLocalVersionParam; 295 ACParams.nPortIndex = OMX_ALL; 296 297 LOG_FUNCTION_NAME; 298 299 eError = OMX_GetConfig(mCameraAdapterParameters.mHandleComp, 300 (OMX_INDEXTYPE)OMX_TI_IndexConfigAutoConvergence, 301 &ACParams); 302 if ( eError != OMX_ErrorNone ) 303 { 304 CAMHAL_LOGEB("Error while getting AutoConvergence 0x%x", eError); 305 ret = -EINVAL; 306 } 307 else 308 { 309 *pManualConverence = ACParams.nManualConverence; 310 *pACMode = ACParams.eACMode; 311 CAMHAL_LOGDA("AutoConvergence got successfully"); 312 } 313 314 LOG_FUNCTION_NAME_EXIT; 315 316 return ret; 317 } 318 319 // Set AutoConvergence 320 status_t OMXCameraAdapter::setAutoConvergence(OMX_TI_AUTOCONVERGENCEMODETYPE pACMode, 321 OMX_S32 pManualConverence) 322 { 323 status_t ret = NO_ERROR; 324 OMX_ERRORTYPE eError = OMX_ErrorNone; 325 OMX_TI_CONFIG_CONVERGENCETYPE ACParams; 326 327 LOG_FUNCTION_NAME; 328 329 ACParams.nSize = sizeof(OMX_TI_CONFIG_CONVERGENCETYPE); 330 ACParams.nVersion = mLocalVersionParam; 331 ACParams.nPortIndex = OMX_ALL; 332 ACParams.nManualConverence = pManualConverence; 333 ACParams.eACMode = pACMode; 334 eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp, 335 (OMX_INDEXTYPE)OMX_TI_IndexConfigAutoConvergence, 336 &ACParams); 337 if ( eError != OMX_ErrorNone ) 338 { 339 CAMHAL_LOGEB("Error while setting AutoConvergence 0x%x", eError); 340 ret = -EINVAL; 341 } 342 else 343 { 344 CAMHAL_LOGDA("AutoConvergence applied successfully"); 345 } 346 347 LOG_FUNCTION_NAME_EXIT; 348 349 return ret; 350 } 351 352 status_t OMXCameraAdapter::enableVideoNoiseFilter(bool enable) 353 { 354 status_t ret = NO_ERROR; 355 OMX_ERRORTYPE eError = OMX_ErrorNone; 356 OMX_PARAM_VIDEONOISEFILTERTYPE vnfCfg; 357 358 359 LOG_FUNCTION_NAME; 360 361 if ( NO_ERROR == ret ) 362 { 363 OMX_INIT_STRUCT_PTR (&vnfCfg, OMX_PARAM_VIDEONOISEFILTERTYPE); 364 365 if ( enable ) 366 { 367 CAMHAL_LOGDA("VNF is enabled"); 368 vnfCfg.eMode = OMX_VideoNoiseFilterModeOn; 369 } 370 else 371 { 372 CAMHAL_LOGDA("VNF is disabled"); 373 vnfCfg.eMode = OMX_VideoNoiseFilterModeOff; 374 } 375 376 eError = OMX_SetParameter(mCameraAdapterParameters.mHandleComp, 377 ( OMX_INDEXTYPE ) OMX_IndexParamVideoNoiseFilter, 378 &vnfCfg); 379 if ( OMX_ErrorNone != eError ) 380 { 381 CAMHAL_LOGEB("Error while configuring video noise filter 0x%x", eError); 382 ret = -1; 383 } 384 else 385 { 386 CAMHAL_LOGDA("Video noise filter is configured successfully"); 387 } 388 } 389 390 LOG_FUNCTION_NAME_EXIT; 391 392 return ret; 393 } 394 395 status_t OMXCameraAdapter::enableVideoStabilization(bool enable) 396 { 397 status_t ret = NO_ERROR; 398 OMX_ERRORTYPE eError = OMX_ErrorNone; 399 OMX_CONFIG_FRAMESTABTYPE frameStabCfg; 400 401 402 LOG_FUNCTION_NAME; 403 404 if ( NO_ERROR == ret ) 405 { 406 OMX_CONFIG_BOOLEANTYPE vstabp; 407 OMX_INIT_STRUCT_PTR (&vstabp, OMX_CONFIG_BOOLEANTYPE); 408 if(enable) 409 { 410 vstabp.bEnabled = OMX_TRUE; 411 } 412 else 413 { 414 vstabp.bEnabled = OMX_FALSE; 415 } 416 417 eError = OMX_SetParameter(mCameraAdapterParameters.mHandleComp, 418 (OMX_INDEXTYPE)OMX_IndexParamFrameStabilisation, 419 &vstabp); 420 if ( OMX_ErrorNone != eError ) 421 { 422 CAMHAL_LOGEB("Error while configuring video stabilization param 0x%x", eError); 423 ret = -1; 424 } 425 else 426 { 427 CAMHAL_LOGDA("Video stabilization param configured successfully"); 428 } 429 430 } 431 432 if ( NO_ERROR == ret ) 433 { 434 435 OMX_INIT_STRUCT_PTR (&frameStabCfg, OMX_CONFIG_FRAMESTABTYPE); 436 437 438 eError = OMX_GetConfig(mCameraAdapterParameters.mHandleComp, 439 ( OMX_INDEXTYPE ) OMX_IndexConfigCommonFrameStabilisation, 440 &frameStabCfg); 441 if ( OMX_ErrorNone != eError ) 442 { 443 CAMHAL_LOGEB("Error while getting video stabilization mode 0x%x", 444 (unsigned int)eError); 445 ret = -1; 446 } 447 448 CAMHAL_LOGDB("VSTAB Port Index = %d", (int)frameStabCfg.nPortIndex); 449 450 frameStabCfg.nPortIndex = mCameraAdapterParameters.mPrevPortIndex; 451 if ( enable ) 452 { 453 CAMHAL_LOGDA("VSTAB is enabled"); 454 frameStabCfg.bStab = OMX_TRUE; 455 } 456 else 457 { 458 CAMHAL_LOGDA("VSTAB is disabled"); 459 frameStabCfg.bStab = OMX_FALSE; 460 461 } 462 463 eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp, 464 ( OMX_INDEXTYPE ) OMX_IndexConfigCommonFrameStabilisation, 465 &frameStabCfg); 466 if ( OMX_ErrorNone != eError ) 467 { 468 CAMHAL_LOGEB("Error while configuring video stabilization mode 0x%x", eError); 469 ret = -1; 470 } 471 else 472 { 473 CAMHAL_LOGDA("Video stabilization mode configured successfully"); 474 } 475 } 476 477 LOG_FUNCTION_NAME_EXIT; 478 479 return ret; 480 } 481 482 status_t OMXCameraAdapter::setGBCE(OMXCameraAdapter::BrightnessMode mode) 483 { 484 status_t ret = NO_ERROR; 485 OMX_ERRORTYPE eError = OMX_ErrorNone; 486 OMX_TI_CONFIG_LOCAL_AND_GLOBAL_BRIGHTNESSCONTRASTTYPE bControl; 487 488 LOG_FUNCTION_NAME; 489 490 if ( OMX_StateInvalid == mComponentState ) 491 { 492 CAMHAL_LOGEA("OMX component is in invalid state"); 493 ret = -EINVAL; 494 } 495 496 if ( NO_ERROR == ret ) 497 { 498 OMX_INIT_STRUCT_PTR (&bControl, OMX_TI_CONFIG_LOCAL_AND_GLOBAL_BRIGHTNESSCONTRASTTYPE); 499 500 bControl.nPortIndex = OMX_ALL; 501 502 switch ( mode ) 503 { 504 case OMXCameraAdapter::BRIGHTNESS_ON: 505 { 506 bControl.eControl = OMX_TI_BceModeOn; 507 break; 508 } 509 case OMXCameraAdapter::BRIGHTNESS_AUTO: 510 { 511 bControl.eControl = OMX_TI_BceModeAuto; 512 break; 513 } 514 case OMXCameraAdapter::BRIGHTNESS_OFF: 515 default: 516 { 517 bControl.eControl = OMX_TI_BceModeOff; 518 break; 519 } 520 } 521 522 eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp, 523 ( OMX_INDEXTYPE ) OMX_TI_IndexConfigGlobalBrightnessContrastEnhance, 524 &bControl); 525 if ( OMX_ErrorNone != eError ) 526 { 527 CAMHAL_LOGEB("Error while setting GBCE 0x%x", eError); 528 } 529 else 530 { 531 CAMHAL_LOGDB("GBCE configured successfully 0x%x", mode); 532 } 533 } 534 535 LOG_FUNCTION_NAME_EXIT; 536 537 return ret; 538 } 539 540 status_t OMXCameraAdapter::setGLBCE(OMXCameraAdapter::BrightnessMode mode) 541 { 542 status_t ret = NO_ERROR; 543 OMX_ERRORTYPE eError = OMX_ErrorNone; 544 OMX_TI_CONFIG_LOCAL_AND_GLOBAL_BRIGHTNESSCONTRASTTYPE bControl; 545 546 LOG_FUNCTION_NAME; 547 548 if ( OMX_StateInvalid == mComponentState ) 549 { 550 CAMHAL_LOGEA("OMX component is in invalid state"); 551 ret = -EINVAL; 552 } 553 554 if ( NO_ERROR == ret ) 555 { 556 OMX_INIT_STRUCT_PTR (&bControl, OMX_TI_CONFIG_LOCAL_AND_GLOBAL_BRIGHTNESSCONTRASTTYPE); 557 bControl.nPortIndex = OMX_ALL; 558 559 switch ( mode ) 560 { 561 case OMXCameraAdapter::BRIGHTNESS_ON: 562 { 563 bControl.eControl = OMX_TI_BceModeOn; 564 break; 565 } 566 case OMXCameraAdapter::BRIGHTNESS_AUTO: 567 { 568 bControl.eControl = OMX_TI_BceModeAuto; 569 break; 570 } 571 case OMXCameraAdapter::BRIGHTNESS_OFF: 572 default: 573 { 574 bControl.eControl = OMX_TI_BceModeOff; 575 break; 576 } 577 } 578 579 eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp, 580 ( OMX_INDEXTYPE ) OMX_TI_IndexConfigLocalBrightnessContrastEnhance, 581 &bControl); 582 if ( OMX_ErrorNone != eError ) 583 { 584 CAMHAL_LOGEB("Error while configure GLBCE 0x%x", eError); 585 } 586 else 587 { 588 CAMHAL_LOGDA("GLBCE configured successfully"); 589 } 590 } 591 592 LOG_FUNCTION_NAME_EXIT; 593 594 return ret; 595 } 596 597 status_t OMXCameraAdapter::setCaptureMode(OMXCameraAdapter::CaptureMode mode) 598 { 599 status_t ret = NO_ERROR; 600 OMX_ERRORTYPE eError = OMX_ErrorNone; 601 OMX_CONFIG_CAMOPERATINGMODETYPE camMode; 602 OMX_TI_PARAM_ZSLHISTORYLENTYPE zslHistoryLen; 603 OMX_CONFIG_BOOLEANTYPE bCAC; 604 605 LOG_FUNCTION_NAME; 606 607 //ZSL have 4 buffers history by default 608 OMX_INIT_STRUCT_PTR (&zslHistoryLen, OMX_TI_PARAM_ZSLHISTORYLENTYPE); 609 zslHistoryLen.nHistoryLen = 4; 610 611 //CAC is disabled by default 612 OMX_INIT_STRUCT_PTR (&bCAC, OMX_CONFIG_BOOLEANTYPE); 613 bCAC.bEnabled = OMX_FALSE; 614 615 if ( NO_ERROR == ret ) 616 { 617 618 OMX_INIT_STRUCT_PTR (&camMode, OMX_CONFIG_CAMOPERATINGMODETYPE); 619 if ( mSensorIndex == OMX_TI_StereoSensor ) 620 { 621 CAMHAL_LOGDA("Camera mode: STEREO"); 622 camMode.eCamOperatingMode = OMX_CaptureStereoImageCapture; 623 } 624 else if ( OMXCameraAdapter::HIGH_SPEED == mode ) 625 { 626 CAMHAL_LOGDA("Camera mode: HIGH SPEED"); 627 camMode.eCamOperatingMode = OMX_CaptureImageHighSpeedTemporalBracketing; 628 } 629 else if( OMXCameraAdapter::HIGH_QUALITY == mode ) 630 { 631 CAMHAL_LOGDA("Camera mode: HIGH QUALITY"); 632 camMode.eCamOperatingMode = OMX_CaptureImageProfileBase; 633 } 634 else if( OMXCameraAdapter::HIGH_QUALITY_ZSL== mode ) 635 { 636 const char* valstr = NULL; 637 CAMHAL_LOGDA("Camera mode: HIGH QUALITY_ZSL"); 638 camMode.eCamOperatingMode = OMX_TI_CaptureImageProfileZeroShutterLag; 639 640 valstr = mParams.get(TICameraParameters::KEY_RECORDING_HINT); 641 if (!valstr || (valstr && (strcmp(valstr, "false")))) { 642 zslHistoryLen.nHistoryLen = 5; 643 } 644 } 645 else if( OMXCameraAdapter::VIDEO_MODE == mode ) 646 { 647 CAMHAL_LOGDA("Camera mode: VIDEO MODE"); 648 camMode.eCamOperatingMode = OMX_CaptureVideo; 649 } 650 else 651 { 652 CAMHAL_LOGEA("Camera mode: INVALID mode passed!"); 653 return BAD_VALUE; 654 } 655 656 if( NO_ERROR == ret ) 657 { 658 eError = OMX_SetParameter(mCameraAdapterParameters.mHandleComp, 659 ( OMX_INDEXTYPE ) OMX_TI_IndexParamZslHistoryLen, 660 &zslHistoryLen); 661 if ( OMX_ErrorNone != eError ) 662 { 663 CAMHAL_LOGEB("Error while configuring ZSL History len 0x%x", eError); 664 // Don't return status for now 665 // as high history values might lead 666 // to errors on some platforms. 667 // ret = ErrorUtils::omxToAndroidError(eError); 668 } 669 else 670 { 671 CAMHAL_LOGDA("ZSL History len configured successfully"); 672 } 673 } 674 675 if( NO_ERROR == ret ) 676 { 677 eError = OMX_SetParameter(mCameraAdapterParameters.mHandleComp, 678 ( OMX_INDEXTYPE ) OMX_IndexCameraOperatingMode, 679 &camMode); 680 if ( OMX_ErrorNone != eError ) 681 { 682 CAMHAL_LOGEB("Error while configuring camera mode 0x%x", eError); 683 ret = ErrorUtils::omxToAndroidError(eError); 684 } 685 else 686 { 687 CAMHAL_LOGDA("Camera mode configured successfully"); 688 } 689 } 690 691 if( NO_ERROR == ret ) 692 { 693 //Configure CAC 694 eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp, 695 ( OMX_INDEXTYPE ) OMX_IndexConfigChromaticAberrationCorrection, 696 &bCAC); 697 if ( OMX_ErrorNone != eError ) 698 { 699 CAMHAL_LOGEB("Error while configuring CAC 0x%x", eError); 700 ret = ErrorUtils::omxToAndroidError(eError); 701 } 702 else 703 { 704 CAMHAL_LOGDA("CAC configured successfully"); 705 } 706 } 707 } 708 709 LOG_FUNCTION_NAME_EXIT; 710 711 return ret; 712 } 713 714 status_t OMXCameraAdapter::setLDC(OMXCameraAdapter::IPPMode mode) 715 { 716 status_t ret = NO_ERROR; 717 OMX_ERRORTYPE eError = OMX_ErrorNone; 718 OMX_CONFIG_BOOLEANTYPE bOMX; 719 720 LOG_FUNCTION_NAME; 721 722 if ( OMX_StateLoaded != mComponentState ) 723 { 724 CAMHAL_LOGEA("OMX component is not in loaded state"); 725 ret = -EINVAL; 726 } 727 728 if ( NO_ERROR == ret ) 729 { 730 OMX_INIT_STRUCT_PTR (&bOMX, OMX_CONFIG_BOOLEANTYPE); 731 732 switch ( mode ) 733 { 734 case OMXCameraAdapter::IPP_LDCNSF: 735 case OMXCameraAdapter::IPP_LDC: 736 { 737 bOMX.bEnabled = OMX_TRUE; 738 break; 739 } 740 case OMXCameraAdapter::IPP_NONE: 741 case OMXCameraAdapter::IPP_NSF: 742 default: 743 { 744 bOMX.bEnabled = OMX_FALSE; 745 break; 746 } 747 } 748 749 CAMHAL_LOGVB("Configuring LDC mode 0x%x", bOMX.bEnabled); 750 eError = OMX_SetParameter(mCameraAdapterParameters.mHandleComp, 751 ( OMX_INDEXTYPE ) OMX_IndexParamLensDistortionCorrection, 752 &bOMX); 753 if ( OMX_ErrorNone != eError ) 754 { 755 CAMHAL_LOGEA("Error while setting LDC"); 756 ret = -1; 757 } 758 } 759 760 LOG_FUNCTION_NAME_EXIT; 761 762 return ret; 763 } 764 765 status_t OMXCameraAdapter::setNSF(OMXCameraAdapter::IPPMode mode) 766 { 767 status_t ret = NO_ERROR; 768 OMX_ERRORTYPE eError = OMX_ErrorNone; 769 OMX_PARAM_ISONOISEFILTERTYPE nsf; 770 771 LOG_FUNCTION_NAME; 772 773 if ( OMX_StateLoaded != mComponentState ) 774 { 775 CAMHAL_LOGEA("OMX component is not in loaded state"); 776 ret = -EINVAL; 777 } 778 779 if ( NO_ERROR == ret ) 780 { 781 OMX_INIT_STRUCT_PTR (&nsf, OMX_PARAM_ISONOISEFILTERTYPE); 782 nsf.nPortIndex = OMX_ALL; 783 784 switch ( mode ) 785 { 786 case OMXCameraAdapter::IPP_LDCNSF: 787 case OMXCameraAdapter::IPP_NSF: 788 { 789 nsf.eMode = OMX_ISONoiseFilterModeOn; 790 break; 791 } 792 case OMXCameraAdapter::IPP_LDC: 793 case OMXCameraAdapter::IPP_NONE: 794 default: 795 { 796 nsf.eMode = OMX_ISONoiseFilterModeOff; 797 break; 798 } 799 } 800 801 CAMHAL_LOGVB("Configuring NSF mode 0x%x", nsf.eMode); 802 eError = OMX_SetParameter(mCameraAdapterParameters.mHandleComp, 803 (OMX_INDEXTYPE)OMX_IndexParamHighISONoiseFiler, 804 &nsf); 805 if ( OMX_ErrorNone != eError ) 806 { 807 CAMHAL_LOGEA("Error while setting NSF"); 808 ret = -1; 809 } 810 } 811 812 LOG_FUNCTION_NAME_EXIT; 813 814 return ret; 815 } 816 817 status_t OMXCameraAdapter::setImageQuality(unsigned int quality) 818 { 819 status_t ret = NO_ERROR; 820 OMX_ERRORTYPE eError = OMX_ErrorNone; 821 OMX_IMAGE_PARAM_QFACTORTYPE jpegQualityConf; 822 823 LOG_FUNCTION_NAME; 824 825 if ( OMX_StateInvalid == mComponentState ) 826 { 827 CAMHAL_LOGEA("OMX component is in invalid state"); 828 ret = -EINVAL; 829 } 830 831 if ( NO_ERROR == ret ) 832 { 833 OMX_INIT_STRUCT(jpegQualityConf, OMX_IMAGE_PARAM_QFACTORTYPE); 834 jpegQualityConf.nQFactor = quality; 835 jpegQualityConf.nPortIndex = mCameraAdapterParameters.mImagePortIndex; 836 837 eError = OMX_SetParameter(mCameraAdapterParameters.mHandleComp, 838 OMX_IndexParamQFactor, 839 &jpegQualityConf); 840 if ( OMX_ErrorNone != eError ) 841 { 842 CAMHAL_LOGEB("Error while configuring jpeg Quality 0x%x", eError); 843 ret = -1; 844 } 845 } 846 847 LOG_FUNCTION_NAME_EXIT; 848 849 return ret; 850 } 851 852 status_t OMXCameraAdapter::setThumbnailParams(unsigned int width, 853 unsigned int height, 854 unsigned int quality) 855 { 856 status_t ret = NO_ERROR; 857 OMX_ERRORTYPE eError = OMX_ErrorNone; 858 OMX_PARAM_THUMBNAILTYPE thumbConf; 859 860 LOG_FUNCTION_NAME; 861 862 if ( OMX_StateInvalid == mComponentState ) 863 { 864 CAMHAL_LOGEA("OMX component is in invalid state"); 865 ret = -EINVAL; 866 } 867 868 if ( NO_ERROR == ret ) 869 { 870 OMX_INIT_STRUCT(thumbConf, OMX_PARAM_THUMBNAILTYPE); 871 thumbConf.nPortIndex = mCameraAdapterParameters.mImagePortIndex; 872 873 eError = OMX_GetParameter(mCameraAdapterParameters.mHandleComp, 874 ( OMX_INDEXTYPE ) OMX_IndexParamThumbnail, 875 &thumbConf); 876 if ( OMX_ErrorNone != eError ) 877 { 878 CAMHAL_LOGEB("Error while retrieving thumbnail size 0x%x", eError); 879 ret = -1; 880 } 881 882 //CTS Requirement: width or height equal to zero should 883 //result in absent EXIF thumbnail 884 if ( ( 0 == width ) || ( 0 == height ) ) 885 { 886 thumbConf.nWidth = mThumbRes[0].width; 887 thumbConf.nHeight = mThumbRes[0].height; 888 thumbConf.eCompressionFormat = OMX_IMAGE_CodingUnused; 889 } 890 else 891 { 892 thumbConf.nWidth = width; 893 thumbConf.nHeight = height; 894 thumbConf.nQuality = quality; 895 thumbConf.eCompressionFormat = OMX_IMAGE_CodingJPEG; 896 } 897 898 CAMHAL_LOGDB("Thumbnail width = %d, Thumbnail Height = %d", width, height); 899 900 eError = OMX_SetParameter(mCameraAdapterParameters.mHandleComp, 901 ( OMX_INDEXTYPE ) OMX_IndexParamThumbnail, 902 &thumbConf); 903 if ( OMX_ErrorNone != eError ) 904 { 905 CAMHAL_LOGEB("Error while configuring thumbnail size 0x%x", eError); 906 ret = -1; 907 } 908 } 909 910 LOG_FUNCTION_NAME_EXIT; 911 912 return ret; 913 } 914 915 status_t OMXCameraAdapter::setAlgoPriority(AlgoPriority priority, 916 Algorithm3A algo, 917 bool enable) 918 { 919 OMX_ERRORTYPE eError = OMX_ErrorNone; 920 921 LOG_FUNCTION_NAME; 922 923 if ( OMX_StateInvalid == mComponentState ) { 924 CAMHAL_LOGEA("OMX component is in invalid state"); 925 return NO_INIT; 926 } 927 928 if ( FACE_PRIORITY == priority ) { 929 930 if ( algo & WHITE_BALANCE_ALGO ) { 931 if ( enable ) { 932 mFacePriority.bAwbFaceEnable = OMX_TRUE; 933 } else { 934 mFacePriority.bAwbFaceEnable = OMX_FALSE; 935 } 936 } 937 938 if ( algo & EXPOSURE_ALGO ) { 939 if ( enable ) { 940 mFacePriority.bAeFaceEnable = OMX_TRUE; 941 } else { 942 mFacePriority.bAeFaceEnable = OMX_FALSE; 943 } 944 } 945 946 if ( algo & FOCUS_ALGO ) { 947 if ( enable ) { 948 mFacePriority.bAfFaceEnable = OMX_TRUE; 949 } else { 950 mFacePriority.bAfFaceEnable = OMX_FALSE; 951 } 952 } 953 954 eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp, 955 ( OMX_INDEXTYPE ) OMX_TI_IndexConfigFacePriority3a, 956 &mFacePriority); 957 if ( OMX_ErrorNone != eError ) { 958 CAMHAL_LOGEB("Error while configuring face priority 0x%x", eError); 959 } else { 960 CAMHAL_LOGDB("Face priority for algorithms set successfully 0x%x, 0x%x, 0x%x", 961 mFacePriority.bAfFaceEnable, 962 mFacePriority.bAeFaceEnable, 963 mFacePriority.bAwbFaceEnable); 964 } 965 966 } else if ( REGION_PRIORITY == priority ) { 967 968 if ( algo & WHITE_BALANCE_ALGO ) { 969 if ( enable ) { 970 mRegionPriority.bAwbRegionEnable= OMX_TRUE; 971 } else { 972 mRegionPriority.bAwbRegionEnable = OMX_FALSE; 973 } 974 } 975 976 if ( algo & EXPOSURE_ALGO ) { 977 if ( enable ) { 978 mRegionPriority.bAeRegionEnable = OMX_TRUE; 979 } else { 980 mRegionPriority.bAeRegionEnable = OMX_FALSE; 981 } 982 } 983 984 if ( algo & FOCUS_ALGO ) { 985 if ( enable ) { 986 mRegionPriority.bAfRegionEnable = OMX_TRUE; 987 } else { 988 mRegionPriority.bAfRegionEnable = OMX_FALSE; 989 } 990 } 991 992 eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp, 993 ( OMX_INDEXTYPE ) OMX_TI_IndexConfigRegionPriority3a, 994 &mRegionPriority); 995 if ( OMX_ErrorNone != eError ) { 996 CAMHAL_LOGEB("Error while configuring region priority 0x%x", eError); 997 } else { 998 CAMHAL_LOGDB("Region priority for algorithms set successfully 0x%x, 0x%x, 0x%x", 999 mRegionPriority.bAfRegionEnable, 1000 mRegionPriority.bAeRegionEnable, 1001 mRegionPriority.bAwbRegionEnable); 1002 } 1003 1004 } 1005 1006 LOG_FUNCTION_NAME_EXIT; 1007 1008 return ErrorUtils::omxToAndroidError(eError); 1009 } 1010 1011 status_t OMXCameraAdapter::setPictureRotation(unsigned int degree) 1012 { 1013 status_t ret = NO_ERROR; 1014 OMX_ERRORTYPE eError = OMX_ErrorNone; 1015 OMX_CONFIG_ROTATIONTYPE rotation; 1016 1017 LOG_FUNCTION_NAME; 1018 1019 if ( OMX_StateInvalid == mComponentState ) 1020 { 1021 CAMHAL_LOGEA("OMX component is in invalid state"); 1022 ret = -1; 1023 } 1024 1025 if ( NO_ERROR == ret ) 1026 { 1027 OMX_INIT_STRUCT(rotation, OMX_CONFIG_ROTATIONTYPE); 1028 rotation.nRotation = degree; 1029 rotation.nPortIndex = mCameraAdapterParameters.mImagePortIndex; 1030 1031 eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp, 1032 OMX_IndexConfigCommonRotate, 1033 &rotation); 1034 if ( OMX_ErrorNone != eError ) 1035 { 1036 CAMHAL_LOGEB("Error while configuring rotation 0x%x", eError); 1037 } 1038 } 1039 1040 LOG_FUNCTION_NAME_EXIT; 1041 1042 return ret; 1043 } 1044 1045 status_t OMXCameraAdapter::setSensorOrientation(unsigned int degree) 1046 { 1047 status_t ret = NO_ERROR; 1048 OMX_ERRORTYPE eError = OMX_ErrorNone; 1049 OMX_CONFIG_ROTATIONTYPE sensorOrientation; 1050 int tmpHeight, tmpWidth; 1051 OMXCameraPortParameters *mPreviewData = &mCameraAdapterParameters.mCameraPortParams[mCameraAdapterParameters.mPrevPortIndex]; 1052 1053 LOG_FUNCTION_NAME; 1054 if ( OMX_StateInvalid == mComponentState ) 1055 { 1056 CAMHAL_LOGEA("OMX component is in invalid state"); 1057 ret = -1; 1058 } 1059 1060 /* Set Temproary Port resolution. 1061 * For resolution with height > 1008,resolution cannot be set without configuring orientation. 1062 * So we first set a temp resolution. We have used VGA 1063 */ 1064 tmpHeight = mPreviewData->mHeight; 1065 tmpWidth = mPreviewData->mWidth; 1066 mPreviewData->mWidth = 640; 1067 mPreviewData->mHeight = 480; 1068 ret = setFormat(OMX_CAMERA_PORT_VIDEO_OUT_PREVIEW, *mPreviewData); 1069 if ( ret != NO_ERROR ) 1070 { 1071 CAMHAL_LOGEB("setFormat() failed %d", ret); 1072 } 1073 1074 /* Now set Required Orientation*/ 1075 if ( NO_ERROR == ret ) 1076 { 1077 OMX_INIT_STRUCT(sensorOrientation, OMX_CONFIG_ROTATIONTYPE); 1078 sensorOrientation.nPortIndex = mCameraAdapterParameters.mPrevPortIndex; 1079 eError = OMX_GetConfig(mCameraAdapterParameters.mHandleComp, 1080 OMX_IndexConfigCommonRotate, 1081 &sensorOrientation); 1082 if ( OMX_ErrorNone != eError ) 1083 { 1084 CAMHAL_LOGEB("Error while Reading Sensor Orientation : 0x%x", eError); 1085 } 1086 CAMHAL_LOGVB(" Currently Sensor Orientation is set to : %d", 1087 ( unsigned int ) sensorOrientation.nRotation); 1088 sensorOrientation.nPortIndex = mCameraAdapterParameters.mPrevPortIndex; 1089 sensorOrientation.nRotation = degree; 1090 eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp, 1091 OMX_IndexConfigCommonRotate, 1092 &sensorOrientation); 1093 if ( OMX_ErrorNone != eError ) 1094 { 1095 CAMHAL_LOGEB("Error while configuring rotation 0x%x", eError); 1096 } 1097 CAMHAL_LOGVA(" Read the Parameters that are set"); 1098 eError = OMX_GetConfig(mCameraAdapterParameters.mHandleComp, 1099 OMX_IndexConfigCommonRotate, 1100 &sensorOrientation); 1101 if ( OMX_ErrorNone != eError ) 1102 { 1103 CAMHAL_LOGEB("Error while Reading Sensor Orientation : 0x%x", eError); 1104 } 1105 CAMHAL_LOGVB(" Currently Sensor Orientation is set to : %d", 1106 ( unsigned int ) sensorOrientation.nRotation); 1107 CAMHAL_LOGVB(" Sensor Configured for Port : %d", 1108 ( unsigned int ) sensorOrientation.nPortIndex); 1109 } 1110 1111 /* Now set the required resolution as requested */ 1112 1113 mPreviewData->mWidth = tmpWidth; 1114 mPreviewData->mHeight = tmpHeight; 1115 if ( NO_ERROR == ret ) 1116 { 1117 ret = setFormat (mCameraAdapterParameters.mPrevPortIndex, 1118 mCameraAdapterParameters.mCameraPortParams[mCameraAdapterParameters.mPrevPortIndex]); 1119 if ( NO_ERROR != ret ) 1120 { 1121 CAMHAL_LOGEB("setFormat() failed %d", ret); 1122 } 1123 } 1124 1125 LOG_FUNCTION_NAME_EXIT; 1126 1127 return ret; 1128 } 1129 1130 status_t OMXCameraAdapter::setVFramerate(OMX_U32 minFrameRate, OMX_U32 maxFrameRate) 1131 { 1132 status_t ret = NO_ERROR; 1133 OMX_ERRORTYPE eError = OMX_ErrorNone; 1134 OMX_TI_CONFIG_VARFRMRANGETYPE vfr; 1135 OMXCameraPortParameters * mPreviewData = 1136 &mCameraAdapterParameters.mCameraPortParams[mCameraAdapterParameters.mPrevPortIndex]; 1137 1138 LOG_FUNCTION_NAME; 1139 1140 if ( OMX_StateInvalid == mComponentState ) { 1141 CAMHAL_LOGEA("OMX component is in invalid state"); 1142 ret = -EINVAL; 1143 } 1144 1145 // The port framerate should never be smaller 1146 // than max framerate. 1147 if ( mPreviewData->mFrameRate < maxFrameRate ) { 1148 return NO_INIT; 1149 } 1150 1151 if ( NO_ERROR == ret ) { 1152 OMX_INIT_STRUCT_PTR (&vfr, OMX_TI_CONFIG_VARFRMRANGETYPE); 1153 1154 vfr.xMin = minFrameRate<<16; 1155 vfr.xMax = maxFrameRate<<16; 1156 1157 eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp, 1158 (OMX_INDEXTYPE)OMX_TI_IndexConfigVarFrmRange, 1159 &vfr); 1160 if(OMX_ErrorNone != eError) { 1161 CAMHAL_LOGEB("Error while setting VFR min = %d, max = %d, error = 0x%x", 1162 ( unsigned int ) minFrameRate, 1163 ( unsigned int ) maxFrameRate, 1164 eError); 1165 ret = -1; 1166 } else { 1167 CAMHAL_LOGDB("VFR Configured Successfully [%d:%d]", 1168 ( unsigned int ) minFrameRate, 1169 ( unsigned int ) maxFrameRate); 1170 } 1171 } 1172 1173 return ret; 1174 } 1175 1176 }; 1177