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