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 #include "CameraHal.h"
25 #include "OMXCameraAdapter.h"
26 #include "ErrorUtils.h"
27 
28 #include <cutils/properties.h>
29 
30 #define METERING_AREAS_RANGE 0xFF
31 
32 static const char PARAM_SEP[] = ",";
33 
34 namespace Ti {
35 namespace Camera {
36 
getSceneModeEntry(const char * name,OMX_SCENEMODETYPE scene)37 const SceneModesEntry* OMXCameraAdapter::getSceneModeEntry(const char* name,
38                                                                   OMX_SCENEMODETYPE scene) {
39     const SceneModesEntry* cameraLUT = NULL;
40     const SceneModesEntry* entry = NULL;
41     unsigned int numEntries = 0;
42 
43     // 1. Find camera's scene mode LUT
44     for (unsigned int i = 0; i < ARRAY_SIZE(CameraToSensorModesLUT); i++) {
45         if (strcmp(CameraToSensorModesLUT[i].name, name) == 0) {
46             cameraLUT = CameraToSensorModesLUT[i].Table;
47             numEntries = CameraToSensorModesLUT[i].size;
48             break;
49         }
50     }
51 
52     // 2. Find scene mode entry in table
53     if (!cameraLUT) {
54         goto EXIT;
55     }
56 
57     for (unsigned int i = 0; i < numEntries; i++) {
58         if(cameraLUT[i].scene == scene) {
59             entry = cameraLUT + i;
60             break;
61         }
62     }
63  EXIT:
64     return entry;
65 }
66 
setParameters3A(const android::CameraParameters & params,BaseCameraAdapter::AdapterState state)67 status_t OMXCameraAdapter::setParameters3A(const android::CameraParameters &params,
68                                            BaseCameraAdapter::AdapterState state)
69 {
70     status_t ret = NO_ERROR;
71     int mode = 0;
72     const char *str = NULL;
73     int varint = 0;
74     BaseCameraAdapter::AdapterState nextState;
75     BaseCameraAdapter::getNextState(nextState);
76 
77     LOG_FUNCTION_NAME;
78 
79     android::AutoMutex lock(m3ASettingsUpdateLock);
80 
81     str = params.get(android::CameraParameters::KEY_SCENE_MODE);
82     mode = getLUTvalue_HALtoOMX( str, SceneLUT);
83     if ( mFirstTimeInit || ((str != NULL) && ( mParameters3A.SceneMode != mode )) ) {
84         if ( 0 <= mode ) {
85             mParameters3A.SceneMode = mode;
86             if ((mode == OMX_Manual) && (mFirstTimeInit == false)){//Auto mode
87                 mFirstTimeInit = true;
88             }
89             if ((mode != OMX_Manual) &&
90                 (state & PREVIEW_ACTIVE) && !(nextState & CAPTURE_ACTIVE)) {
91                 // if setting preset scene mode, previewing, and not in the middle of capture
92                 // set preset scene mode immediately instead of in next FBD
93                 // for feedback params to work properly since they need to be read
94                 // by application in subsequent getParameters()
95                 ret |= setScene(mParameters3A);
96                 // re-apply EV compensation after setting scene mode since it probably reset it
97                 if(mParameters3A.EVCompensation) {
98                    setEVCompensation(mParameters3A);
99                 }
100                 return ret;
101             } else {
102                 mPending3Asettings |= SetSceneMode;
103             }
104         } else {
105             mParameters3A.SceneMode = OMX_Manual;
106         }
107         CAMHAL_LOGVB("SceneMode %d", mParameters3A.SceneMode);
108     }
109 
110 #ifdef OMAP_ENHANCEMENT
111     if ( (str = params.get(TICameraParameters::KEY_EXPOSURE_MODE)) != NULL ) {
112         mode = getLUTvalue_HALtoOMX(str, ExpLUT);
113         if ( mParameters3A.Exposure != mode ) {
114             // If either the new or the old exposure mode is manual set also
115             // the SetManualExposure flag to call setManualExposureVal where
116             // the auto gain and exposure flags are configured
117             if ( mParameters3A.Exposure == OMX_ExposureControlOff ||
118                  mode == OMX_ExposureControlOff ) {
119                 mPending3Asettings |= SetManualExposure;
120             }
121             mParameters3A.Exposure = mode;
122             CAMHAL_LOGDB("Exposure mode %d", mode);
123             if ( 0 <= mParameters3A.Exposure ) {
124                 mPending3Asettings |= SetExpMode;
125             }
126         }
127         if ( mode == OMX_ExposureControlOff ) {
128             mode = params.getInt(TICameraParameters::KEY_MANUAL_EXPOSURE);
129             if ( mParameters3A.ManualExposure != mode ) {
130                 mParameters3A.ManualExposure = mode;
131                 CAMHAL_LOGDB("Manual Exposure = %d", mode);
132                 mPending3Asettings |= SetManualExposure;
133             }
134             mode = params.getInt(TICameraParameters::KEY_MANUAL_EXPOSURE_RIGHT);
135             if ( mParameters3A.ManualExposureRight != mode ) {
136                 mParameters3A.ManualExposureRight = mode;
137                 CAMHAL_LOGDB("Manual Exposure right = %d", mode);
138                 mPending3Asettings |= SetManualExposure;
139             }
140             mode = params.getInt(TICameraParameters::KEY_MANUAL_GAIN_ISO);
141             if ( mParameters3A.ManualGain != mode ) {
142                 mParameters3A.ManualGain = mode;
143                 CAMHAL_LOGDB("Manual Gain = %d", mode);
144                 mPending3Asettings |= SetManualExposure;
145             }
146             mode = params.getInt(TICameraParameters::KEY_MANUAL_GAIN_ISO_RIGHT);
147             if ( mParameters3A.ManualGainRight != mode ) {
148                 mParameters3A.ManualGainRight = mode;
149                 CAMHAL_LOGDB("Manual Gain right = %d", mode);
150                 mPending3Asettings |= SetManualExposure;
151             }
152         }
153     }
154 #endif
155 
156     str = params.get(android::CameraParameters::KEY_WHITE_BALANCE);
157     mode = getLUTvalue_HALtoOMX( str, WBalLUT);
158     if (mFirstTimeInit || ((str != NULL) && (mode != mParameters3A.WhiteBallance)))
159         {
160         mParameters3A.WhiteBallance = mode;
161         CAMHAL_LOGDB("Whitebalance mode %d", mode);
162         if ( 0 <= mParameters3A.WhiteBallance )
163             {
164             mPending3Asettings |= SetWhiteBallance;
165             }
166         }
167 
168 #ifdef OMAP_ENHANCEMENT
169     varint = params.getInt(TICameraParameters::KEY_CONTRAST);
170     if ( 0 <= varint )
171         {
172         if ( mFirstTimeInit ||
173              ( (mParameters3A.Contrast  + CONTRAST_OFFSET) != varint ) )
174             {
175             mParameters3A.Contrast = varint - CONTRAST_OFFSET;
176             CAMHAL_LOGDB("Contrast %d", mParameters3A.Contrast);
177             mPending3Asettings |= SetContrast;
178             }
179         }
180 
181     varint = params.getInt(TICameraParameters::KEY_SHARPNESS);
182     if ( 0 <= varint )
183         {
184         if ( mFirstTimeInit ||
185              ((mParameters3A.Sharpness + SHARPNESS_OFFSET) != varint ))
186             {
187             mParameters3A.Sharpness = varint - SHARPNESS_OFFSET;
188             CAMHAL_LOGDB("Sharpness %d", mParameters3A.Sharpness);
189             mPending3Asettings |= SetSharpness;
190             }
191         }
192 
193     varint = params.getInt(TICameraParameters::KEY_SATURATION);
194     if ( 0 <= varint )
195         {
196         if ( mFirstTimeInit ||
197              ((mParameters3A.Saturation + SATURATION_OFFSET) != varint ) )
198             {
199             mParameters3A.Saturation = varint - SATURATION_OFFSET;
200             CAMHAL_LOGDB("Saturation %d", mParameters3A.Saturation);
201             mPending3Asettings |= SetSaturation;
202             }
203         }
204 
205     varint = params.getInt(TICameraParameters::KEY_BRIGHTNESS);
206     if ( 0 <= varint )
207         {
208         if ( mFirstTimeInit ||
209              (( mParameters3A.Brightness != varint )) )
210             {
211             mParameters3A.Brightness = (unsigned) varint;
212             CAMHAL_LOGDB("Brightness %d", mParameters3A.Brightness);
213             mPending3Asettings |= SetBrightness;
214             }
215         }
216 #endif
217 
218     str = params.get(android::CameraParameters::KEY_ANTIBANDING);
219     mode = getLUTvalue_HALtoOMX(str,FlickerLUT);
220     if ( mFirstTimeInit || ( ( str != NULL ) && ( mParameters3A.Flicker != mode ) ))
221         {
222         mParameters3A.Flicker = mode;
223         CAMHAL_LOGDB("Flicker %d", mParameters3A.Flicker);
224         if ( 0 <= mParameters3A.Flicker )
225             {
226             mPending3Asettings |= SetFlicker;
227             }
228         }
229 
230 #ifdef OMAP_ENHANCEMENT
231     str = params.get(TICameraParameters::KEY_ISO);
232     mode = getLUTvalue_HALtoOMX(str, IsoLUT);
233     CAMHAL_LOGVB("ISO mode arrived in HAL : %s", str);
234     if ( mFirstTimeInit || (  ( str != NULL ) && ( mParameters3A.ISO != mode )) )
235         {
236         mParameters3A.ISO = mode;
237         CAMHAL_LOGDB("ISO %d", mParameters3A.ISO);
238         if ( 0 <= mParameters3A.ISO )
239             {
240             mPending3Asettings |= SetISO;
241             }
242         }
243 #endif
244 
245     str = params.get(android::CameraParameters::KEY_FOCUS_MODE);
246     mode = getLUTvalue_HALtoOMX(str, FocusLUT);
247     if ( (mFirstTimeInit || ((str != NULL) && (mParameters3A.Focus != mode))))
248         {
249         mPending3Asettings |= SetFocus;
250 
251         mParameters3A.Focus = mode;
252 
253         // if focus mode is set to infinity...update focus distance immediately
254         if (mode == OMX_IMAGE_FocusControlAutoInfinity) {
255             updateFocusDistances(mParameters);
256         }
257 
258         CAMHAL_LOGDB("Focus %x", mParameters3A.Focus);
259         }
260 
261     str = params.get(android::CameraParameters::KEY_EXPOSURE_COMPENSATION);
262     varint = params.getInt(android::CameraParameters::KEY_EXPOSURE_COMPENSATION);
263     if ( mFirstTimeInit || (str && (mParameters3A.EVCompensation != varint))) {
264         CAMHAL_LOGDB("Setting EV Compensation to %d", varint);
265         mParameters3A.EVCompensation = varint;
266         mPending3Asettings |= SetEVCompensation;
267         }
268 
269     str = params.get(android::CameraParameters::KEY_FLASH_MODE);
270     mode = getLUTvalue_HALtoOMX( str, FlashLUT);
271     if (  mFirstTimeInit || (( str != NULL ) && ( mParameters3A.FlashMode != mode )) )
272         {
273         if ( 0 <= mode )
274             {
275             mParameters3A.FlashMode = mode;
276             mPending3Asettings |= SetFlash;
277             }
278         else
279             {
280             mParameters3A.FlashMode = OMX_IMAGE_FlashControlAuto;
281             }
282         }
283 
284     CAMHAL_LOGVB("Flash Setting %s", str);
285     CAMHAL_LOGVB("FlashMode %d", mParameters3A.FlashMode);
286 
287     str = params.get(android::CameraParameters::KEY_EFFECT);
288     mode = getLUTvalue_HALtoOMX( str, EffLUT);
289     if (  mFirstTimeInit || (( str != NULL ) && ( mParameters3A.Effect != mode )) )
290         {
291         mParameters3A.Effect = mode;
292         CAMHAL_LOGDB("Effect %d", mParameters3A.Effect);
293         if ( 0 <= mParameters3A.Effect )
294             {
295             mPending3Asettings |= SetEffect;
296             }
297         }
298 
299     str = params.get(android::CameraParameters::KEY_AUTO_EXPOSURE_LOCK_SUPPORTED);
300     if ( (str != NULL) && (!strcmp(str, android::CameraParameters::TRUE)) )
301       {
302         OMX_BOOL lock = OMX_FALSE;
303         mUserSetExpLock = OMX_FALSE;
304         str = params.get(android::CameraParameters::KEY_AUTO_EXPOSURE_LOCK);
305         if (str && ((strcmp(str, android::CameraParameters::TRUE)) == 0))
306           {
307             CAMHAL_LOGVA("Locking Exposure");
308             lock = OMX_TRUE;
309             mUserSetExpLock = OMX_TRUE;
310           }
311         else
312           {
313             CAMHAL_LOGVA("UnLocking Exposure");
314           }
315 
316         if (mParameters3A.ExposureLock != lock)
317           {
318             mParameters3A.ExposureLock = lock;
319             CAMHAL_LOGDB("ExposureLock %d", lock);
320             mPending3Asettings |= SetExpLock;
321           }
322       }
323 
324     str = params.get(android::CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK_SUPPORTED);
325     if ( (str != NULL) && (!strcmp(str, android::CameraParameters::TRUE)) )
326       {
327         OMX_BOOL lock = OMX_FALSE;
328         mUserSetWbLock = OMX_FALSE;
329         str = params.get(android::CameraParameters::KEY_AUTO_WHITEBALANCE_LOCK);
330         if (str && ((strcmp(str, android::CameraParameters::TRUE)) == 0))
331           {
332             CAMHAL_LOGVA("Locking WhiteBalance");
333             lock = OMX_TRUE;
334             mUserSetWbLock = OMX_TRUE;
335           }
336         else
337           {
338             CAMHAL_LOGVA("UnLocking WhiteBalance");
339           }
340         if (mParameters3A.WhiteBalanceLock != lock)
341           {
342             mParameters3A.WhiteBalanceLock = lock;
343             CAMHAL_LOGDB("WhiteBalanceLock %d", lock);
344             mPending3Asettings |= SetWBLock;
345           }
346       }
347 
348     str = params.get(TICameraParameters::KEY_AUTO_FOCUS_LOCK);
349     if (str && (strcmp(str, android::CameraParameters::TRUE) == 0) && (mParameters3A.FocusLock != OMX_TRUE)) {
350         CAMHAL_LOGVA("Locking Focus");
351         mParameters3A.FocusLock = OMX_TRUE;
352         setFocusLock(mParameters3A);
353     } else if (str && (strcmp(str, android::CameraParameters::FALSE) == 0) && (mParameters3A.FocusLock != OMX_FALSE)) {
354         CAMHAL_LOGVA("UnLocking Focus");
355         mParameters3A.FocusLock = OMX_FALSE;
356         setFocusLock(mParameters3A);
357     }
358 
359     str = params.get(android::CameraParameters::KEY_METERING_AREAS);
360     if ( (str != NULL) ) {
361         size_t MAX_METERING_AREAS;
362         android::Vector<android::sp<CameraArea> > tempAreas;
363 
364         MAX_METERING_AREAS = atoi(params.get(android::CameraParameters::KEY_MAX_NUM_METERING_AREAS));
365 
366         android::AutoMutex lock(mMeteringAreasLock);
367 
368         ret = CameraArea::parseAreas(str, ( strlen(str) + 1 ), tempAreas);
369 
370         CAMHAL_LOGVB("areAreasDifferent? = %d",
371                      CameraArea::areAreasDifferent(mMeteringAreas, tempAreas));
372 
373         if ( (NO_ERROR == ret) && CameraArea::areAreasDifferent(mMeteringAreas, tempAreas) ) {
374             mMeteringAreas.clear();
375             mMeteringAreas = tempAreas;
376 
377             if ( MAX_METERING_AREAS >= mMeteringAreas.size() ) {
378                 CAMHAL_LOGDB("Setting Metering Areas %s",
379                         params.get(android::CameraParameters::KEY_METERING_AREAS));
380 
381                 mPending3Asettings |= SetMeteringAreas;
382             } else {
383                 CAMHAL_LOGEB("Metering areas supported %d, metering areas set %d",
384                              MAX_METERING_AREAS, mMeteringAreas.size());
385                 ret = -EINVAL;
386             }
387         }
388     }
389 
390 // TI extensions for enable/disable algos
391     declareParameter3ABool(params, TICameraParameters::KEY_ALGO_EXTERNAL_GAMMA,
392                        mParameters3A.AlgoExternalGamma, SetAlgoExternalGamma, "External Gamma");
393     declareParameter3ABool(params, TICameraParameters::KEY_ALGO_NSF1,
394                        mParameters3A.AlgoNSF1, SetAlgoNSF1, "NSF1");
395     declareParameter3ABool(params, TICameraParameters::KEY_ALGO_NSF2,
396                        mParameters3A.AlgoNSF2, SetAlgoNSF2, "NSF2");
397     declareParameter3ABool(params, TICameraParameters::KEY_ALGO_SHARPENING,
398                        mParameters3A.AlgoSharpening, SetAlgoSharpening, "Sharpening");
399     declareParameter3ABool(params, TICameraParameters::KEY_ALGO_THREELINCOLORMAP,
400                        mParameters3A.AlgoThreeLinColorMap, SetAlgoThreeLinColorMap, "ThreeLinColorMap");
401     declareParameter3ABool(params, TICameraParameters::KEY_ALGO_GIC, mParameters3A.AlgoGIC, SetAlgoGIC, "GIC");
402 
403     // Gamma table
404     str = params.get(TICameraParameters::KEY_GAMMA_TABLE);
405     updateGammaTable(str);
406 
407     LOG_FUNCTION_NAME_EXIT;
408 
409     return ret;
410 }
411 
updateGammaTable(const char * gamma)412 void OMXCameraAdapter::updateGammaTable(const char* gamma)
413 {
414     unsigned int plane = 0;
415     unsigned int i = 0;
416     bool gamma_changed = false;
417     const char *a = gamma;
418     OMX_TI_GAMMATABLE_ELEM_TYPE *elem[3] = { mParameters3A.mGammaTable.pR,
419                                              mParameters3A.mGammaTable.pG,
420                                              mParameters3A.mGammaTable.pB};
421 
422     if (!gamma) return;
423 
424     mPending3Asettings &= ~SetGammaTable;
425     memset(&mParameters3A.mGammaTable, 0, sizeof(mParameters3A.mGammaTable));
426     for (plane = 0; plane < 3; plane++) {
427         a = strchr(a, '(');
428         if (NULL != a) {
429             a++;
430             for (i = 0; i < OMX_TI_GAMMATABLE_SIZE; i++) {
431                 char *b;
432                 int newVal;
433                 newVal = strtod(a, &b);
434                 if (newVal != elem[plane][i].nOffset) {
435                     elem[plane][i].nOffset = newVal;
436                     gamma_changed = true;
437                 }
438                 a = strpbrk(b, ",:)");
439                 if ((NULL != a) && (':' == *a)) {
440                     a++;
441                 } else if ((NULL != a) && (',' == *a)){
442                     a++;
443                     break;
444                 } else if ((NULL != a) && (')' == *a)){
445                     a++;
446                     break;
447                 } else {
448                     CAMHAL_LOGE("Error while parsing values");
449                     gamma_changed = false;
450                     break;
451                 }
452                 newVal = strtod(a, &b);
453                 if (newVal != elem[plane][i].nSlope) {
454                     elem[plane][i].nSlope = newVal;
455                     gamma_changed = true;
456                 }
457                 a = strpbrk(b, ",:)");
458                 if ((NULL != a) && (',' == *a)) {
459                     a++;
460                 } else if ((NULL != a) && (':' == *a)){
461                     a++;
462                     break;
463                 } else if ((NULL != a) && (')' == *a)){
464                     a++;
465                     break;
466                 } else {
467                     CAMHAL_LOGE("Error while parsing values");
468                     gamma_changed = false;
469                     break;
470                 }
471             }
472             if ((OMX_TI_GAMMATABLE_SIZE - 1) != i) {
473                 CAMHAL_LOGE("Error while parsing values (incorrect count %u)", i);
474                 gamma_changed = false;
475                 break;
476             }
477         } else {
478             CAMHAL_LOGE("Error while parsing planes (%u)", plane);
479             gamma_changed = false;
480             break;
481         }
482     }
483 
484     if (gamma_changed) {
485         mPending3Asettings |= SetGammaTable;
486     }
487 }
488 
declareParameter3ABool(const android::CameraParameters & params,const char * key,OMX_BOOL & current_setting,E3ASettingsFlags pending,const char * msg)489 void OMXCameraAdapter::declareParameter3ABool(const android::CameraParameters &params, const char *key,
490                                               OMX_BOOL &current_setting, E3ASettingsFlags pending,
491                                               const char *msg)
492 {
493     OMX_BOOL val = OMX_TRUE;
494     const char *str = params.get(key);
495 
496     if (str && ((strcmp(str, android::CameraParameters::FALSE)) == 0))
497         {
498         CAMHAL_LOGVB("Disabling %s", msg);
499         val = OMX_FALSE;
500         }
501     else
502         {
503         CAMHAL_LOGVB("Enabling %s", msg);
504         }
505     if (current_setting != val)
506         {
507         current_setting = val;
508         CAMHAL_LOGDB("%s %s", msg, current_setting ? "enabled" : "disabled");
509         mPending3Asettings |= pending;
510         }
511 }
512 
getLUTvalue_HALtoOMX(const char * HalValue,LUTtype LUT)513 int OMXCameraAdapter::getLUTvalue_HALtoOMX(const char * HalValue, LUTtype LUT)
514 {
515     int LUTsize = LUT.size;
516     if( HalValue )
517         for(int i = 0; i < LUTsize; i++)
518             if( 0 == strcmp(LUT.Table[i].userDefinition, HalValue) )
519                 return LUT.Table[i].omxDefinition;
520 
521     return -ENOENT;
522 }
523 
getLUTvalue_OMXtoHAL(int OMXValue,LUTtype LUT)524 const char* OMXCameraAdapter::getLUTvalue_OMXtoHAL(int OMXValue, LUTtype LUT)
525 {
526     int LUTsize = LUT.size;
527     for(int i = 0; i < LUTsize; i++)
528         if( LUT.Table[i].omxDefinition == OMXValue )
529             return LUT.Table[i].userDefinition;
530 
531     return NULL;
532 }
533 
getMultipleLUTvalue_OMXtoHAL(int OMXValue,LUTtype LUT,char * supported)534 int OMXCameraAdapter::getMultipleLUTvalue_OMXtoHAL(int OMXValue, LUTtype LUT, char * supported)
535 {
536     int num = 0;
537     int remaining_size;
538     int LUTsize = LUT.size;
539     for(int i = 0; i < LUTsize; i++)
540         if( LUT.Table[i].omxDefinition == OMXValue )
541         {
542             num++;
543             if (supported[0] != '\0') {
544                 strncat(supported, PARAM_SEP, 1);
545             }
546             remaining_size = ((((int)MAX_PROP_VALUE_LENGTH - 1 - (int)strlen(supported)) < 0) ? 0 : (MAX_PROP_VALUE_LENGTH - 1 - strlen(supported)));
547             strncat(supported, LUT.Table[i].userDefinition, remaining_size);
548         }
549 
550     return num;
551 }
552 
setExposureMode(Gen3A_settings & Gen3A)553 status_t OMXCameraAdapter::setExposureMode(Gen3A_settings& Gen3A)
554 {
555     OMX_ERRORTYPE eError = OMX_ErrorNone;
556     OMX_CONFIG_EXPOSURECONTROLTYPE exp;
557 
558     LOG_FUNCTION_NAME;
559 
560     if ( OMX_StateInvalid == mComponentState )
561         {
562         CAMHAL_LOGEA("OMX component is in invalid state");
563         return NO_INIT;
564         }
565 
566     OMX_INIT_STRUCT_PTR (&exp, OMX_CONFIG_EXPOSURECONTROLTYPE);
567     exp.nPortIndex = OMX_ALL;
568     exp.eExposureControl = (OMX_EXPOSURECONTROLTYPE)Gen3A.Exposure;
569 
570     eError =  OMX_SetConfig(mCameraAdapterParameters.mHandleComp,
571                             OMX_IndexConfigCommonExposure,
572                             &exp);
573     if ( OMX_ErrorNone != eError )
574         {
575         CAMHAL_LOGEB("Error while configuring exposure mode 0x%x", eError);
576         }
577     else
578         {
579         CAMHAL_LOGDA("Camera exposure mode configured successfully");
580         }
581 
582     LOG_FUNCTION_NAME_EXIT;
583 
584     return Utils::ErrorUtils::omxToAndroidError(eError);
585 }
586 
isFlashDisabled()587 static bool isFlashDisabled() {
588 #if (PROPERTY_VALUE_MAX < 5)
589 #error "PROPERTY_VALUE_MAX must be at least 5"
590 #endif
591 
592     // Ignore flash_off system property for user build.
593     char buildType[PROPERTY_VALUE_MAX];
594     if (property_get("ro.build.type", buildType, NULL) &&
595         !strcasecmp(buildType, "user")) {
596         return false;
597     }
598 
599     char value[PROPERTY_VALUE_MAX];
600     if (property_get("camera.flash_off", value, NULL) &&
601         (!strcasecmp(value, android::CameraParameters::TRUE) || !strcasecmp(value, "1"))) {
602         CAMHAL_LOGW("flash is disabled for testing purpose");
603         return true;
604     }
605 
606     return false;
607 }
608 
setManualExposureVal(Gen3A_settings & Gen3A)609 status_t OMXCameraAdapter::setManualExposureVal(Gen3A_settings& Gen3A) {
610     OMX_ERRORTYPE eError = OMX_ErrorNone;
611     OMX_CONFIG_EXPOSUREVALUETYPE expVal;
612     OMX_TI_CONFIG_EXPOSUREVALUERIGHTTYPE expValRight;
613 
614     LOG_FUNCTION_NAME;
615 
616     if ( OMX_StateInvalid == mComponentState ) {
617         CAMHAL_LOGEA("OMX component is in invalid state");
618         return NO_INIT;
619     }
620 
621     OMX_INIT_STRUCT_PTR (&expVal, OMX_CONFIG_EXPOSUREVALUETYPE);
622     OMX_INIT_STRUCT_PTR (&expValRight, OMX_TI_CONFIG_EXPOSUREVALUERIGHTTYPE);
623     expVal.nPortIndex = OMX_ALL;
624     expValRight.nPortIndex = OMX_ALL;
625 
626     eError = OMX_GetConfig(mCameraAdapterParameters.mHandleComp,
627                    OMX_IndexConfigCommonExposureValue,
628                    &expVal);
629     if ( OMX_ErrorNone == eError ) {
630         eError = OMX_GetConfig(mCameraAdapterParameters.mHandleComp,
631                        (OMX_INDEXTYPE) OMX_TI_IndexConfigRightExposureValue,
632                        &expValRight);
633     }
634     if ( OMX_ErrorNone != eError ) {
635         CAMHAL_LOGEB("OMX_GetConfig error 0x%x (manual exposure values)", eError);
636         return Utils::ErrorUtils::omxToAndroidError(eError);
637     }
638 
639     if ( Gen3A.Exposure != OMX_ExposureControlOff ) {
640         expVal.bAutoShutterSpeed = OMX_TRUE;
641         expVal.bAutoSensitivity = OMX_TRUE;
642     } else {
643         expVal.bAutoShutterSpeed = OMX_FALSE;
644         expVal.nShutterSpeedMsec = Gen3A.ManualExposure;
645         expValRight.nShutterSpeedMsec = Gen3A.ManualExposureRight;
646         if ( Gen3A.ManualGain <= 0 || Gen3A.ManualGainRight <= 0 ) {
647             expVal.bAutoSensitivity = OMX_TRUE;
648         } else {
649             expVal.bAutoSensitivity = OMX_FALSE;
650             expVal.nSensitivity = Gen3A.ManualGain;
651             expValRight.nSensitivity = Gen3A.ManualGainRight;
652         }
653     }
654 
655     eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp,
656                             OMX_IndexConfigCommonExposureValue,
657                             &expVal);
658     if ( OMX_ErrorNone == eError ) {
659         eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp,
660                                 (OMX_INDEXTYPE) OMX_TI_IndexConfigRightExposureValue,
661                                 &expValRight);
662     }
663 
664     if ( OMX_ErrorNone != eError ) {
665         CAMHAL_LOGEB("Error 0x%x while configuring manual exposure values", eError);
666     } else {
667         CAMHAL_LOGDA("Camera manual exposure values configured successfully");
668     }
669 
670     LOG_FUNCTION_NAME_EXIT;
671 
672     return Utils::ErrorUtils::omxToAndroidError(eError);
673 }
674 
setFlashMode(Gen3A_settings & Gen3A)675 status_t OMXCameraAdapter::setFlashMode(Gen3A_settings& Gen3A)
676 {
677     status_t ret = NO_ERROR;
678     OMX_ERRORTYPE eError = OMX_ErrorNone;
679     OMX_IMAGE_PARAM_FLASHCONTROLTYPE flash;
680     OMX_CONFIG_FOCUSASSISTTYPE focusAssist;
681 
682     LOG_FUNCTION_NAME;
683 
684     if ( OMX_StateInvalid == mComponentState )
685         {
686         CAMHAL_LOGEA("OMX component is in invalid state");
687         return NO_INIT;
688         }
689 
690     OMX_INIT_STRUCT_PTR (&flash, OMX_IMAGE_PARAM_FLASHCONTROLTYPE);
691     flash.nPortIndex = OMX_ALL;
692 
693     if (isFlashDisabled()) {
694         flash.eFlashControl = ( OMX_IMAGE_FLASHCONTROLTYPE ) OMX_IMAGE_FlashControlOff;
695     } else {
696         flash.eFlashControl = ( OMX_IMAGE_FLASHCONTROLTYPE ) Gen3A.FlashMode;
697     }
698 
699     CAMHAL_LOGDB("Configuring flash mode 0x%x", flash.eFlashControl);
700     eError =  OMX_SetConfig(mCameraAdapterParameters.mHandleComp,
701                             (OMX_INDEXTYPE) OMX_IndexConfigFlashControl,
702                             &flash);
703     if ( OMX_ErrorNone != eError )
704         {
705         CAMHAL_LOGEB("Error while configuring flash mode 0x%x", eError);
706         }
707     else
708         {
709         CAMHAL_LOGDA("Camera flash mode configured successfully");
710         }
711 
712     if ( OMX_ErrorNone == eError )
713         {
714         OMX_INIT_STRUCT_PTR (&focusAssist, OMX_CONFIG_FOCUSASSISTTYPE);
715         focusAssist.nPortIndex = OMX_ALL;
716         if ( flash.eFlashControl == OMX_IMAGE_FlashControlOff )
717             {
718             focusAssist.bFocusAssist = OMX_FALSE;
719             }
720         else
721             {
722             focusAssist.bFocusAssist = OMX_TRUE;
723             }
724 
725         CAMHAL_LOGDB("Configuring AF Assist mode 0x%x", focusAssist.bFocusAssist);
726         eError =  OMX_SetConfig(mCameraAdapterParameters.mHandleComp,
727                                 (OMX_INDEXTYPE) OMX_IndexConfigFocusAssist,
728                                 &focusAssist);
729         if ( OMX_ErrorNone != eError )
730             {
731             CAMHAL_LOGEB("Error while configuring AF Assist mode 0x%x", eError);
732             }
733         else
734             {
735             CAMHAL_LOGDA("Camera AF Assist  mode configured successfully");
736             }
737         }
738 
739     LOG_FUNCTION_NAME_EXIT;
740 
741     return Utils::ErrorUtils::omxToAndroidError(eError);
742 }
743 
getFlashMode(Gen3A_settings & Gen3A)744 status_t OMXCameraAdapter::getFlashMode(Gen3A_settings& Gen3A)
745 {
746     status_t ret = NO_ERROR;
747     OMX_ERRORTYPE eError = OMX_ErrorNone;
748     OMX_IMAGE_PARAM_FLASHCONTROLTYPE flash;
749 
750     LOG_FUNCTION_NAME;
751 
752     if ( OMX_StateInvalid == mComponentState ) {
753         CAMHAL_LOGEA("OMX component is in invalid state");
754         return NO_INIT;
755     }
756 
757     OMX_INIT_STRUCT_PTR (&flash, OMX_IMAGE_PARAM_FLASHCONTROLTYPE);
758     flash.nPortIndex = OMX_ALL;
759 
760     eError =  OMX_GetConfig(mCameraAdapterParameters.mHandleComp,
761                             (OMX_INDEXTYPE) OMX_IndexConfigFlashControl,
762                             &flash);
763 
764     if ( OMX_ErrorNone != eError ) {
765         CAMHAL_LOGEB("Error while getting flash mode 0x%x", eError);
766     } else {
767         Gen3A.FlashMode = flash.eFlashControl;
768         CAMHAL_LOGDB("Gen3A.FlashMode 0x%x", Gen3A.FlashMode);
769     }
770 
771     LOG_FUNCTION_NAME_EXIT;
772 
773     return Utils::ErrorUtils::omxToAndroidError(eError);
774 }
775 
setFocusMode(Gen3A_settings & Gen3A)776 status_t OMXCameraAdapter::setFocusMode(Gen3A_settings& Gen3A)
777 {
778     status_t ret = NO_ERROR;
779     OMX_ERRORTYPE eError = OMX_ErrorNone;
780     OMX_IMAGE_CONFIG_FOCUSCONTROLTYPE focus;
781     size_t top, left, width, height, weight;
782     OMX_CONFIG_BOOLEANTYPE bOMX;
783 
784     LOG_FUNCTION_NAME;
785 
786     BaseCameraAdapter::AdapterState state;
787     BaseCameraAdapter::getState(state);
788 
789     if ( OMX_StateInvalid == mComponentState )
790         {
791         CAMHAL_LOGEA("OMX component is in invalid state");
792         return NO_INIT;
793         }
794 
795 
796     ///Face detection takes precedence over touch AF
797     if ( mFaceDetectionRunning )
798         {
799         //Disable region priority first
800         setAlgoPriority(REGION_PRIORITY, FOCUS_ALGO, false);
801 
802         //Enable face algorithm priority for focus
803         setAlgoPriority(FACE_PRIORITY, FOCUS_ALGO , true);
804 
805         //Do normal focus afterwards
806         ////FIXME: Check if the extended focus control is needed? this overrides caf
807         //focusControl.eFocusControl = ( OMX_IMAGE_FOCUSCONTROLTYPE ) OMX_IMAGE_FocusControlExtended;
808         }
809     else if ( (!mFocusAreas.isEmpty()) && (!mFocusAreas.itemAt(0)->isZeroArea()) )
810         {
811 
812         //Disable face priority first
813         setAlgoPriority(FACE_PRIORITY, FOCUS_ALGO, false);
814 
815         //Enable region algorithm priority
816         setAlgoPriority(REGION_PRIORITY, FOCUS_ALGO, true);
817 
818 
819         //Do normal focus afterwards
820         //FIXME: Check if the extended focus control is needed? this overrides caf
821         //focus.eFocusControl = ( OMX_IMAGE_FOCUSCONTROLTYPE ) OMX_IMAGE_FocusControlExtended;
822 
823         }
824     else
825         {
826 
827         //Disable both region and face priority
828         setAlgoPriority(REGION_PRIORITY, FOCUS_ALGO, false);
829 
830         setAlgoPriority(FACE_PRIORITY, FOCUS_ALGO, false);
831 
832         }
833 
834     if ( NO_ERROR == ret && ((state & AF_ACTIVE) == 0) )
835         {
836         OMX_INIT_STRUCT_PTR (&bOMX, OMX_CONFIG_BOOLEANTYPE);
837 
838         if ( Gen3A.Focus == OMX_IMAGE_FocusControlAutoInfinity)
839             {
840             // Don't lock at infinity, otherwise the AF cannot drive
841             // the lens at infinity position
842             if( set3ALock(mUserSetExpLock, mUserSetWbLock, OMX_FALSE) != NO_ERROR)
843                 {
844                 CAMHAL_LOGEA("Error Applying 3A locks");
845                 } else {
846                 CAMHAL_LOGDA("Focus locked. Applied focus locks successfully");
847                 }
848             }
849         if ( Gen3A.Focus == OMX_IMAGE_FocusControlAuto ||
850              Gen3A.Focus == OMX_IMAGE_FocusControlAutoInfinity)
851             {
852             // Run focus scanning if switching to continuous infinity focus mode
853             bOMX.bEnabled = OMX_TRUE;
854             }
855         else
856             {
857             bOMX.bEnabled = OMX_FALSE;
858             }
859 
860         eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp,
861                                (OMX_INDEXTYPE)OMX_TI_IndexConfigAutofocusEnable,
862                                &bOMX);
863 
864         OMX_INIT_STRUCT_PTR (&focus, OMX_IMAGE_CONFIG_FOCUSCONTROLTYPE);
865         focus.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
866         focus.eFocusControl = (OMX_IMAGE_FOCUSCONTROLTYPE)Gen3A.Focus;
867 
868         CAMHAL_LOGDB("Configuring focus mode 0x%x", focus.eFocusControl);
869         eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp, OMX_IndexConfigFocusControl, &focus);
870         if ( OMX_ErrorNone != eError )
871             {
872             CAMHAL_LOGEB("Error while configuring focus mode 0x%x", eError);
873             }
874         else
875             {
876             CAMHAL_LOGDA("Camera focus mode configured successfully");
877             }
878         }
879 
880     LOG_FUNCTION_NAME_EXIT;
881 
882     return Utils::ErrorUtils::omxToAndroidError(eError);
883 }
884 
getFocusMode(Gen3A_settings & Gen3A)885 status_t OMXCameraAdapter::getFocusMode(Gen3A_settings& Gen3A)
886 {
887     status_t ret = NO_ERROR;
888     OMX_ERRORTYPE eError = OMX_ErrorNone;
889     OMX_IMAGE_CONFIG_FOCUSCONTROLTYPE focus;
890     size_t top, left, width, height, weight;
891 
892     LOG_FUNCTION_NAME;
893 
894     if (OMX_StateInvalid == mComponentState) {
895         CAMHAL_LOGEA("OMX component is in invalid state");
896         return NO_INIT;
897     }
898 
899     OMX_INIT_STRUCT_PTR (&focus, OMX_IMAGE_CONFIG_FOCUSCONTROLTYPE);
900     focus.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
901     eError = OMX_GetConfig(mCameraAdapterParameters.mHandleComp,
902                            OMX_IndexConfigFocusControl, &focus);
903 
904     if (OMX_ErrorNone != eError) {
905         CAMHAL_LOGEB("Error while configuring focus mode 0x%x", eError);
906     } else {
907         Gen3A.Focus = focus.eFocusControl;
908         CAMHAL_LOGDB("Gen3A.Focus 0x%x", Gen3A.Focus);
909     }
910 
911     LOG_FUNCTION_NAME_EXIT;
912 
913     return Utils::ErrorUtils::omxToAndroidError(eError);
914 }
915 
setScene(Gen3A_settings & Gen3A)916 status_t OMXCameraAdapter::setScene(Gen3A_settings& Gen3A)
917 {
918     OMX_ERRORTYPE eError = OMX_ErrorNone;
919     OMX_CONFIG_SCENEMODETYPE scene;
920 
921     LOG_FUNCTION_NAME;
922 
923     if ( OMX_StateInvalid == mComponentState )
924         {
925         CAMHAL_LOGEA("OMX component is in invalid state");
926         return NO_INIT;
927         }
928 
929     OMX_INIT_STRUCT_PTR (&scene, OMX_CONFIG_SCENEMODETYPE);
930     scene.nPortIndex = OMX_ALL;
931     scene.eSceneMode = ( OMX_SCENEMODETYPE ) Gen3A.SceneMode;
932 
933     CAMHAL_LOGDB("Configuring scene mode 0x%x", scene.eSceneMode);
934     eError =  OMX_SetConfig(mCameraAdapterParameters.mHandleComp,
935                             ( OMX_INDEXTYPE ) OMX_TI_IndexConfigSceneMode,
936                             &scene);
937 
938     if (OMX_ErrorNone != eError) {
939         CAMHAL_LOGEB("Error while configuring scene mode 0x%x", eError);
940     } else {
941         CAMHAL_LOGDA("Camera scene configured successfully");
942         if (Gen3A.SceneMode != OMX_Manual) {
943             // Get preset scene mode feedback
944             getFocusMode(Gen3A);
945             getFlashMode(Gen3A);
946             getWBMode(Gen3A);
947 
948             // TODO(XXX): Re-enable these for mainline
949             // getSharpness(Gen3A);
950             // getSaturation(Gen3A);
951             // getISO(Gen3A);
952         }
953     }
954 
955     LOG_FUNCTION_NAME_EXIT;
956 
957     return Utils::ErrorUtils::omxToAndroidError(eError);
958 }
959 
setEVCompensation(Gen3A_settings & Gen3A)960 status_t OMXCameraAdapter::setEVCompensation(Gen3A_settings& Gen3A)
961 {
962     OMX_ERRORTYPE eError = OMX_ErrorNone;
963     OMX_CONFIG_EXPOSUREVALUETYPE expValues;
964 
965     LOG_FUNCTION_NAME;
966 
967     if ( OMX_StateInvalid == mComponentState )
968         {
969         CAMHAL_LOGEA("OMX component is in invalid state");
970         return NO_INIT;
971         }
972 
973     OMX_INIT_STRUCT_PTR (&expValues, OMX_CONFIG_EXPOSUREVALUETYPE);
974     expValues.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
975 
976     OMX_GetConfig( mCameraAdapterParameters.mHandleComp,
977                    OMX_IndexConfigCommonExposureValue,
978                    &expValues);
979     CAMHAL_LOGDB("old EV Compensation for OMX = 0x%x", (int)expValues.xEVCompensation);
980     CAMHAL_LOGDB("EV Compensation for HAL = %d", Gen3A.EVCompensation);
981 
982     expValues.xEVCompensation = ( Gen3A.EVCompensation * ( 1 << Q16_OFFSET ) )  / 10;
983     eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp,
984                             OMX_IndexConfigCommonExposureValue,
985                             &expValues);
986     CAMHAL_LOGDB("new EV Compensation for OMX = 0x%x", (int)expValues.xEVCompensation);
987     if ( OMX_ErrorNone != eError )
988         {
989         CAMHAL_LOGEB("Error while configuring EV Compensation 0x%x error = 0x%x",
990                      ( unsigned int ) expValues.xEVCompensation,
991                      eError);
992         }
993     else
994         {
995         CAMHAL_LOGDB("EV Compensation 0x%x configured successfully",
996                      ( unsigned int ) expValues.xEVCompensation);
997         }
998 
999     LOG_FUNCTION_NAME_EXIT;
1000 
1001     return Utils::ErrorUtils::omxToAndroidError(eError);
1002 }
1003 
getEVCompensation(Gen3A_settings & Gen3A)1004 status_t OMXCameraAdapter::getEVCompensation(Gen3A_settings& Gen3A)
1005 {
1006     OMX_ERRORTYPE eError = OMX_ErrorNone;
1007     OMX_CONFIG_EXPOSUREVALUETYPE expValues;
1008 
1009     LOG_FUNCTION_NAME;
1010 
1011     if ( OMX_StateInvalid == mComponentState ) {
1012         CAMHAL_LOGEA("OMX component is in invalid state");
1013         return NO_INIT;
1014     }
1015 
1016     OMX_INIT_STRUCT_PTR (&expValues, OMX_CONFIG_EXPOSUREVALUETYPE);
1017     expValues.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1018 
1019     OMX_GetConfig(mCameraAdapterParameters.mHandleComp,
1020                   OMX_IndexConfigCommonExposureValue,
1021                   &expValues);
1022 
1023     if ( OMX_ErrorNone != eError ) {
1024         CAMHAL_LOGEB("Error while getting EV Compensation error = 0x%x", eError);
1025     } else {
1026         Gen3A.EVCompensation = (10 * expValues.xEVCompensation) / (1 << Q16_OFFSET);
1027         CAMHAL_LOGDB("Gen3A.EVCompensation 0x%x", Gen3A.EVCompensation);
1028     }
1029 
1030     LOG_FUNCTION_NAME_EXIT;
1031 
1032     return Utils::ErrorUtils::omxToAndroidError(eError);
1033 }
1034 
setWBMode(Gen3A_settings & Gen3A)1035 status_t OMXCameraAdapter::setWBMode(Gen3A_settings& Gen3A)
1036 {
1037     OMX_ERRORTYPE eError = OMX_ErrorNone;
1038     OMX_CONFIG_WHITEBALCONTROLTYPE wb;
1039 
1040     LOG_FUNCTION_NAME;
1041 
1042     if ( OMX_StateInvalid == mComponentState )
1043         {
1044         CAMHAL_LOGEA("OMX component is in invalid state");
1045         return NO_INIT;
1046         }
1047 
1048     OMX_INIT_STRUCT_PTR (&wb, OMX_CONFIG_WHITEBALCONTROLTYPE);
1049     wb.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1050     wb.eWhiteBalControl = ( OMX_WHITEBALCONTROLTYPE ) Gen3A.WhiteBallance;
1051 
1052     // disable face and region priorities
1053     setAlgoPriority(FACE_PRIORITY, WHITE_BALANCE_ALGO, false);
1054     setAlgoPriority(REGION_PRIORITY, WHITE_BALANCE_ALGO, false);
1055 
1056     eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp,
1057                          OMX_IndexConfigCommonWhiteBalance,
1058                          &wb);
1059     if ( OMX_ErrorNone != eError )
1060         {
1061         CAMHAL_LOGEB("Error while configuring Whitebalance mode 0x%x error = 0x%x",
1062                      ( unsigned int ) wb.eWhiteBalControl,
1063                      eError);
1064         }
1065     else
1066         {
1067         CAMHAL_LOGDB("Whitebalance mode 0x%x configured successfully",
1068                      ( unsigned int ) wb.eWhiteBalControl);
1069         }
1070 
1071     LOG_FUNCTION_NAME_EXIT;
1072 
1073     return eError;
1074 }
1075 
getWBMode(Gen3A_settings & Gen3A)1076 status_t OMXCameraAdapter::getWBMode(Gen3A_settings& Gen3A)
1077 {
1078     OMX_ERRORTYPE eError = OMX_ErrorNone;
1079     OMX_CONFIG_WHITEBALCONTROLTYPE wb;
1080 
1081     LOG_FUNCTION_NAME;
1082 
1083     if ( OMX_StateInvalid == mComponentState ) {
1084         CAMHAL_LOGEA("OMX component is in invalid state");
1085         return NO_INIT;
1086     }
1087 
1088     OMX_INIT_STRUCT_PTR (&wb, OMX_CONFIG_WHITEBALCONTROLTYPE);
1089     wb.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1090 
1091     eError = OMX_GetConfig(mCameraAdapterParameters.mHandleComp,
1092                            OMX_IndexConfigCommonWhiteBalance,
1093                            &wb);
1094 
1095     if (OMX_ErrorNone != eError) {
1096         CAMHAL_LOGEB("Error while getting Whitebalance mode error = 0x%x", eError);
1097     } else {
1098         Gen3A.WhiteBallance = wb.eWhiteBalControl;
1099         CAMHAL_LOGDB("Gen3A.WhiteBallance 0x%x", Gen3A.WhiteBallance);
1100     }
1101 
1102     LOG_FUNCTION_NAME_EXIT;
1103 
1104     return eError;
1105 }
1106 
setFlicker(Gen3A_settings & Gen3A)1107 status_t OMXCameraAdapter::setFlicker(Gen3A_settings& Gen3A)
1108 {
1109     OMX_ERRORTYPE eError = OMX_ErrorNone;
1110     OMX_CONFIG_FLICKERCANCELTYPE flicker;
1111 
1112     LOG_FUNCTION_NAME;
1113 
1114     if ( OMX_StateInvalid == mComponentState )
1115         {
1116         CAMHAL_LOGEA("OMX component is in invalid state");
1117         return NO_INIT;
1118         }
1119 
1120     OMX_INIT_STRUCT_PTR (&flicker, OMX_CONFIG_FLICKERCANCELTYPE);
1121     flicker.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1122     flicker.eFlickerCancel = (OMX_COMMONFLICKERCANCELTYPE)Gen3A.Flicker;
1123 
1124     eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp,
1125                             (OMX_INDEXTYPE)OMX_IndexConfigFlickerCancel,
1126                             &flicker );
1127     if ( OMX_ErrorNone != eError )
1128         {
1129         CAMHAL_LOGEB("Error while configuring Flicker mode 0x%x error = 0x%x",
1130                      ( unsigned int ) flicker.eFlickerCancel,
1131                      eError);
1132         }
1133     else
1134         {
1135         CAMHAL_LOGDB("Flicker mode 0x%x configured successfully",
1136                      ( unsigned int ) flicker.eFlickerCancel);
1137         }
1138 
1139     LOG_FUNCTION_NAME_EXIT;
1140 
1141     return Utils::ErrorUtils::omxToAndroidError(eError);
1142 }
1143 
setBrightness(Gen3A_settings & Gen3A)1144 status_t OMXCameraAdapter::setBrightness(Gen3A_settings& Gen3A)
1145 {
1146     OMX_ERRORTYPE eError = OMX_ErrorNone;
1147     OMX_CONFIG_BRIGHTNESSTYPE brightness;
1148 
1149     LOG_FUNCTION_NAME;
1150 
1151     if ( OMX_StateInvalid == mComponentState )
1152         {
1153         CAMHAL_LOGEA("OMX component is in invalid state");
1154         return NO_INIT;
1155         }
1156 
1157     OMX_INIT_STRUCT_PTR (&brightness, OMX_CONFIG_BRIGHTNESSTYPE);
1158     brightness.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1159     brightness.nBrightness = Gen3A.Brightness;
1160 
1161     eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp,
1162                          OMX_IndexConfigCommonBrightness,
1163                          &brightness);
1164     if ( OMX_ErrorNone != eError )
1165         {
1166         CAMHAL_LOGEB("Error while configuring Brightness 0x%x error = 0x%x",
1167                      ( unsigned int ) brightness.nBrightness,
1168                      eError);
1169         }
1170     else
1171         {
1172         CAMHAL_LOGDB("Brightness 0x%x configured successfully",
1173                      ( unsigned int ) brightness.nBrightness);
1174         }
1175 
1176     LOG_FUNCTION_NAME_EXIT;
1177 
1178     return Utils::ErrorUtils::omxToAndroidError(eError);
1179 }
1180 
setContrast(Gen3A_settings & Gen3A)1181 status_t OMXCameraAdapter::setContrast(Gen3A_settings& Gen3A)
1182 {
1183     OMX_ERRORTYPE eError = OMX_ErrorNone;
1184     OMX_CONFIG_CONTRASTTYPE contrast;
1185 
1186     LOG_FUNCTION_NAME;
1187 
1188     if ( OMX_StateInvalid == mComponentState )
1189         {
1190         CAMHAL_LOGEA("OMX component is in invalid state");
1191         return NO_INIT;
1192         }
1193 
1194     OMX_INIT_STRUCT_PTR (&contrast, OMX_CONFIG_CONTRASTTYPE);
1195     contrast.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1196     contrast.nContrast = Gen3A.Contrast;
1197 
1198     eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp,
1199                          OMX_IndexConfigCommonContrast,
1200                          &contrast);
1201     if ( OMX_ErrorNone != eError )
1202         {
1203         CAMHAL_LOGEB("Error while configuring Contrast 0x%x error = 0x%x",
1204                      ( unsigned int ) contrast.nContrast,
1205                      eError);
1206         }
1207     else
1208         {
1209         CAMHAL_LOGDB("Contrast 0x%x configured successfully",
1210                      ( unsigned int ) contrast.nContrast);
1211         }
1212 
1213     LOG_FUNCTION_NAME_EXIT;
1214 
1215     return eError;
1216 }
1217 
setSharpness(Gen3A_settings & Gen3A)1218 status_t OMXCameraAdapter::setSharpness(Gen3A_settings& Gen3A)
1219 {
1220     OMX_ERRORTYPE eError = OMX_ErrorNone;
1221     OMX_IMAGE_CONFIG_PROCESSINGLEVELTYPE procSharpness;
1222 
1223     LOG_FUNCTION_NAME;
1224 
1225     if ( OMX_StateInvalid == mComponentState )
1226         {
1227         CAMHAL_LOGEA("OMX component is in invalid state");
1228         return NO_INIT;
1229         }
1230 
1231     OMX_INIT_STRUCT_PTR (&procSharpness, OMX_IMAGE_CONFIG_PROCESSINGLEVELTYPE);
1232     procSharpness.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1233     procSharpness.nLevel = Gen3A.Sharpness;
1234 
1235     if( procSharpness.nLevel == 0 )
1236         {
1237         procSharpness.bAuto = OMX_TRUE;
1238         }
1239     else
1240         {
1241         procSharpness.bAuto = OMX_FALSE;
1242         }
1243 
1244     eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp,
1245                          (OMX_INDEXTYPE)OMX_IndexConfigSharpeningLevel,
1246                          &procSharpness);
1247     if ( OMX_ErrorNone != eError )
1248         {
1249         CAMHAL_LOGEB("Error while configuring Sharpness 0x%x error = 0x%x",
1250                      ( unsigned int ) procSharpness.nLevel,
1251                      eError);
1252         }
1253     else
1254         {
1255         CAMHAL_LOGDB("Sharpness 0x%x configured successfully",
1256                      ( unsigned int ) procSharpness.nLevel);
1257         }
1258 
1259     LOG_FUNCTION_NAME_EXIT;
1260 
1261     return Utils::ErrorUtils::omxToAndroidError(eError);
1262 }
1263 
getSharpness(Gen3A_settings & Gen3A)1264 status_t OMXCameraAdapter::getSharpness(Gen3A_settings& Gen3A)
1265 {
1266     OMX_ERRORTYPE eError = OMX_ErrorNone;
1267     OMX_IMAGE_CONFIG_PROCESSINGLEVELTYPE procSharpness;
1268 
1269     LOG_FUNCTION_NAME;
1270 
1271     if (OMX_StateInvalid == mComponentState) {
1272         CAMHAL_LOGEA("OMX component is in invalid state");
1273         return NO_INIT;
1274     }
1275 
1276     OMX_INIT_STRUCT_PTR (&procSharpness, OMX_IMAGE_CONFIG_PROCESSINGLEVELTYPE);
1277     procSharpness.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1278 
1279     eError = OMX_GetConfig(mCameraAdapterParameters.mHandleComp,
1280                            (OMX_INDEXTYPE)OMX_IndexConfigSharpeningLevel,
1281                            &procSharpness);
1282 
1283     if (OMX_ErrorNone != eError) {
1284         CAMHAL_LOGEB("Error while configuring Sharpness error = 0x%x", eError);
1285     } else {
1286         Gen3A.Sharpness = procSharpness.nLevel;
1287         CAMHAL_LOGDB("Gen3A.Sharpness 0x%x", Gen3A.Sharpness);
1288     }
1289 
1290     LOG_FUNCTION_NAME_EXIT;
1291 
1292     return Utils::ErrorUtils::omxToAndroidError(eError);
1293 }
1294 
setSaturation(Gen3A_settings & Gen3A)1295 status_t OMXCameraAdapter::setSaturation(Gen3A_settings& Gen3A)
1296 {
1297     OMX_ERRORTYPE eError = OMX_ErrorNone;
1298     OMX_CONFIG_SATURATIONTYPE saturation;
1299 
1300     LOG_FUNCTION_NAME;
1301 
1302     if ( OMX_StateInvalid == mComponentState )
1303         {
1304         CAMHAL_LOGEA("OMX component is in invalid state");
1305         return NO_INIT;
1306         }
1307 
1308     OMX_INIT_STRUCT_PTR (&saturation, OMX_CONFIG_SATURATIONTYPE);
1309     saturation.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1310     saturation.nSaturation = Gen3A.Saturation;
1311 
1312     eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp,
1313                          OMX_IndexConfigCommonSaturation,
1314                          &saturation);
1315     if ( OMX_ErrorNone != eError )
1316         {
1317         CAMHAL_LOGEB("Error while configuring Saturation 0x%x error = 0x%x",
1318                      ( unsigned int ) saturation.nSaturation,
1319                      eError);
1320         }
1321     else
1322         {
1323         CAMHAL_LOGDB("Saturation 0x%x configured successfully",
1324                      ( unsigned int ) saturation.nSaturation);
1325         }
1326 
1327     LOG_FUNCTION_NAME_EXIT;
1328 
1329     return Utils::ErrorUtils::omxToAndroidError(eError);
1330 }
1331 
getSaturation(Gen3A_settings & Gen3A)1332 status_t OMXCameraAdapter::getSaturation(Gen3A_settings& Gen3A)
1333 {
1334     OMX_ERRORTYPE eError = OMX_ErrorNone;
1335     OMX_CONFIG_SATURATIONTYPE saturation;
1336 
1337     LOG_FUNCTION_NAME;
1338 
1339     if (OMX_StateInvalid == mComponentState) {
1340         CAMHAL_LOGEA("OMX component is in invalid state");
1341         return NO_INIT;
1342     }
1343 
1344     OMX_INIT_STRUCT_PTR (&saturation, OMX_CONFIG_SATURATIONTYPE);
1345     saturation.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1346 
1347     eError = OMX_GetConfig( mCameraAdapterParameters.mHandleComp,
1348                          OMX_IndexConfigCommonSaturation,
1349                          &saturation);
1350 
1351     if (OMX_ErrorNone != eError) {
1352         CAMHAL_LOGEB("Error while getting Saturation error = 0x%x", eError);
1353     } else {
1354         Gen3A.Saturation = saturation.nSaturation;
1355         CAMHAL_LOGDB("Gen3A.Saturation 0x%x", Gen3A.Saturation);
1356     }
1357 
1358     LOG_FUNCTION_NAME_EXIT;
1359 
1360     return Utils::ErrorUtils::omxToAndroidError(eError);
1361 }
1362 
setISO(Gen3A_settings & Gen3A)1363 status_t OMXCameraAdapter::setISO(Gen3A_settings& Gen3A)
1364 {
1365     OMX_ERRORTYPE eError = OMX_ErrorNone;
1366     OMX_CONFIG_EXPOSUREVALUETYPE expValues;
1367     OMX_TI_CONFIG_EXPOSUREVALUERIGHTTYPE expValRight;
1368 
1369     LOG_FUNCTION_NAME;
1370 
1371     if ( OMX_StateInvalid == mComponentState )
1372         {
1373         CAMHAL_LOGEA("OMX component is in invalid state");
1374         return NO_INIT;
1375         }
1376 
1377     // In case of manual exposure Gain is applied from setManualExposureVal
1378     if ( Gen3A.Exposure == OMX_ExposureControlOff ) {
1379         return NO_ERROR;
1380     }
1381 
1382     OMX_INIT_STRUCT_PTR (&expValues, OMX_CONFIG_EXPOSUREVALUETYPE);
1383     OMX_INIT_STRUCT_PTR (&expValRight, OMX_TI_CONFIG_EXPOSUREVALUERIGHTTYPE);
1384     expValues.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1385     expValRight.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1386 
1387     eError = OMX_GetConfig( mCameraAdapterParameters.mHandleComp,
1388                     OMX_IndexConfigCommonExposureValue,
1389                     &expValues);
1390 
1391     if ( OMX_ErrorNone == eError ) {
1392         eError = OMX_GetConfig(mCameraAdapterParameters.mHandleComp,
1393                         (OMX_INDEXTYPE) OMX_TI_IndexConfigRightExposureValue,
1394                         &expValRight);
1395     }
1396 
1397     if ( OMX_ErrorNone != eError ) {
1398         CAMHAL_LOGEB("OMX_GetConfig error 0x%x (manual exposure values)", eError);
1399         return Utils::ErrorUtils::omxToAndroidError(eError);
1400     }
1401 
1402     if( 0 == Gen3A.ISO ) {
1403         expValues.bAutoSensitivity = OMX_TRUE;
1404     } else {
1405         expValues.bAutoSensitivity = OMX_FALSE;
1406         expValues.nSensitivity = Gen3A.ISO;
1407         expValRight.nSensitivity = expValues.nSensitivity;
1408     }
1409 
1410     eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp,
1411                             OMX_IndexConfigCommonExposureValue,
1412                             &expValues);
1413 
1414     if ( OMX_ErrorNone == eError ) {
1415         eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp,
1416                             (OMX_INDEXTYPE) OMX_TI_IndexConfigRightExposureValue,
1417                             &expValRight);
1418     }
1419     if ( OMX_ErrorNone != eError ) {
1420         CAMHAL_LOGEB("Error while configuring ISO 0x%x error = 0x%x",
1421                      ( unsigned int ) expValues.nSensitivity,
1422                      eError);
1423     } else {
1424         CAMHAL_LOGDB("ISO 0x%x configured successfully",
1425                      ( unsigned int ) expValues.nSensitivity);
1426     }
1427 
1428     LOG_FUNCTION_NAME_EXIT;
1429 
1430     return Utils::ErrorUtils::omxToAndroidError(eError);
1431 }
1432 
getISO(Gen3A_settings & Gen3A)1433 status_t OMXCameraAdapter::getISO(Gen3A_settings& Gen3A)
1434 {
1435     OMX_ERRORTYPE eError = OMX_ErrorNone;
1436     OMX_CONFIG_EXPOSUREVALUETYPE expValues;
1437 
1438     LOG_FUNCTION_NAME;
1439 
1440     if (OMX_StateInvalid == mComponentState) {
1441         CAMHAL_LOGEA("OMX component is in invalid state");
1442         return NO_INIT;
1443     }
1444 
1445     OMX_INIT_STRUCT_PTR (&expValues, OMX_CONFIG_EXPOSUREVALUETYPE);
1446     expValues.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1447 
1448     OMX_GetConfig( mCameraAdapterParameters.mHandleComp,
1449                    OMX_IndexConfigCommonExposureValue,
1450                    &expValues);
1451 
1452     if (OMX_ErrorNone != eError) {
1453         CAMHAL_LOGEB("Error while getting ISO error = 0x%x", eError);
1454     } else {
1455         Gen3A.ISO = expValues.nSensitivity;
1456         CAMHAL_LOGDB("Gen3A.ISO %d", Gen3A.ISO);
1457     }
1458 
1459     LOG_FUNCTION_NAME_EXIT;
1460 
1461     return Utils::ErrorUtils::omxToAndroidError(eError);
1462 }
1463 
setEffect(Gen3A_settings & Gen3A)1464 status_t OMXCameraAdapter::setEffect(Gen3A_settings& Gen3A)
1465 {
1466     OMX_ERRORTYPE eError = OMX_ErrorNone;
1467     OMX_CONFIG_IMAGEFILTERTYPE effect;
1468 
1469     LOG_FUNCTION_NAME;
1470 
1471     if ( OMX_StateInvalid == mComponentState )
1472         {
1473         CAMHAL_LOGEA("OMX component is in invalid state");
1474         return NO_INIT;
1475         }
1476 
1477     OMX_INIT_STRUCT_PTR (&effect, OMX_CONFIG_IMAGEFILTERTYPE);
1478     effect.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1479     effect.eImageFilter = (OMX_IMAGEFILTERTYPE ) Gen3A.Effect;
1480 
1481     eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp,
1482                          OMX_IndexConfigCommonImageFilter,
1483                          &effect);
1484     if ( OMX_ErrorNone != eError )
1485         {
1486         CAMHAL_LOGEB("Error while configuring Effect 0x%x error = 0x%x",
1487                      ( unsigned int )  effect.eImageFilter,
1488                      eError);
1489         }
1490     else
1491         {
1492         CAMHAL_LOGDB("Effect 0x%x configured successfully",
1493                      ( unsigned int )  effect.eImageFilter);
1494         }
1495 
1496     LOG_FUNCTION_NAME_EXIT;
1497 
1498     return Utils::ErrorUtils::omxToAndroidError(eError);
1499 }
1500 
setWhiteBalanceLock(Gen3A_settings & Gen3A)1501 status_t OMXCameraAdapter::setWhiteBalanceLock(Gen3A_settings& Gen3A)
1502 {
1503   OMX_ERRORTYPE eError = OMX_ErrorNone;
1504   OMX_IMAGE_CONFIG_LOCKTYPE lock;
1505 
1506   LOG_FUNCTION_NAME
1507 
1508   if ( OMX_StateInvalid == mComponentState )
1509     {
1510       CAMHAL_LOGEA("OMX component is in invalid state");
1511       return NO_INIT;
1512     }
1513 
1514   OMX_INIT_STRUCT_PTR (&lock, OMX_IMAGE_CONFIG_LOCKTYPE);
1515   lock.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1516   lock.bLock = Gen3A.WhiteBalanceLock;
1517   eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp,
1518                           (OMX_INDEXTYPE)OMX_IndexConfigImageWhiteBalanceLock,
1519                           &lock);
1520   if ( OMX_ErrorNone != eError )
1521     {
1522       CAMHAL_LOGEB("Error while configuring WhiteBalance Lock error = 0x%x", eError);
1523     }
1524   else
1525     {
1526       CAMHAL_LOGDB("WhiteBalance Lock configured successfully %d ", lock.bLock);
1527     }
1528   LOG_FUNCTION_NAME_EXIT
1529 
1530   return Utils::ErrorUtils::omxToAndroidError(eError);
1531 }
1532 
setExposureLock(Gen3A_settings & Gen3A)1533 status_t OMXCameraAdapter::setExposureLock(Gen3A_settings& Gen3A)
1534 {
1535   OMX_ERRORTYPE eError = OMX_ErrorNone;
1536   OMX_IMAGE_CONFIG_LOCKTYPE lock;
1537 
1538   LOG_FUNCTION_NAME
1539 
1540   if ( OMX_StateInvalid == mComponentState )
1541     {
1542       CAMHAL_LOGEA("OMX component is in invalid state");
1543       return NO_INIT;
1544     }
1545 
1546   OMX_INIT_STRUCT_PTR (&lock, OMX_IMAGE_CONFIG_LOCKTYPE);
1547   lock.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1548   lock.bLock = Gen3A.ExposureLock;
1549   eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp,
1550                           (OMX_INDEXTYPE)OMX_IndexConfigImageExposureLock,
1551                           &lock);
1552   if ( OMX_ErrorNone != eError )
1553     {
1554       CAMHAL_LOGEB("Error while configuring Exposure Lock error = 0x%x", eError);
1555     }
1556   else
1557     {
1558       CAMHAL_LOGDB("Exposure Lock configured successfully %d ", lock.bLock);
1559     }
1560   LOG_FUNCTION_NAME_EXIT
1561 
1562     return Utils::ErrorUtils::omxToAndroidError(eError);
1563 }
1564 
setFocusLock(Gen3A_settings & Gen3A)1565 status_t OMXCameraAdapter::setFocusLock(Gen3A_settings& Gen3A)
1566 {
1567     OMX_ERRORTYPE eError = OMX_ErrorNone;
1568     OMX_IMAGE_CONFIG_LOCKTYPE lock;
1569 
1570     LOG_FUNCTION_NAME
1571 
1572     if ( OMX_StateInvalid == mComponentState ) {
1573         CAMHAL_LOGEA("OMX component is in invalid state");
1574         return NO_INIT;
1575     }
1576 
1577     OMX_INIT_STRUCT_PTR (&lock, OMX_IMAGE_CONFIG_LOCKTYPE);
1578     lock.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1579 
1580     lock.bLock = Gen3A.FocusLock;
1581     eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp,
1582                            (OMX_INDEXTYPE)OMX_IndexConfigImageFocusLock,
1583                            &lock);
1584 
1585     if ( OMX_ErrorNone != eError ) {
1586         CAMHAL_LOGEB("Error while configuring Focus Lock error = 0x%x", eError);
1587     } else {
1588         CAMHAL_LOGDB("Focus Lock configured successfully %d ", lock.bLock);
1589     }
1590 
1591     LOG_FUNCTION_NAME_EXIT
1592 
1593     return Utils::ErrorUtils::omxToAndroidError(eError);
1594 }
1595 
set3ALock(OMX_BOOL toggleExp,OMX_BOOL toggleWb,OMX_BOOL toggleFocus)1596 status_t OMXCameraAdapter::set3ALock(OMX_BOOL toggleExp, OMX_BOOL toggleWb, OMX_BOOL toggleFocus)
1597 {
1598     OMX_ERRORTYPE eError = OMX_ErrorNone;
1599     OMX_IMAGE_CONFIG_LOCKTYPE lock;
1600 
1601     LOG_FUNCTION_NAME
1602 
1603     if ( OMX_StateInvalid == mComponentState )
1604     {
1605       CAMHAL_LOGEA("OMX component is in invalid state");
1606       return NO_INIT;
1607     }
1608 
1609     OMX_INIT_STRUCT_PTR (&lock, OMX_IMAGE_CONFIG_LOCKTYPE);
1610     lock.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1611 
1612     mParameters3A.ExposureLock = toggleExp;
1613     mParameters3A.FocusLock = toggleFocus;
1614     mParameters3A.WhiteBalanceLock = toggleWb;
1615 
1616     eError = OMX_GetConfig( mCameraAdapterParameters.mHandleComp,
1617                             (OMX_INDEXTYPE)OMX_IndexConfigImageExposureLock,
1618                             &lock);
1619 
1620     if ( OMX_ErrorNone != eError )
1621     {
1622         CAMHAL_LOGEB("Error GetConfig Exposure Lock error = 0x%x", eError);
1623         goto EXIT;
1624     }
1625     else
1626     {
1627         CAMHAL_LOGDA("Exposure Lock GetConfig successfull");
1628 
1629         /* Apply locks only when not applied already */
1630         if ( lock.bLock  != toggleExp )
1631         {
1632             setExposureLock(mParameters3A);
1633         }
1634 
1635     }
1636 
1637     OMX_INIT_STRUCT_PTR (&lock, OMX_IMAGE_CONFIG_LOCKTYPE);
1638     lock.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1639     eError = OMX_GetConfig( mCameraAdapterParameters.mHandleComp,
1640                             (OMX_INDEXTYPE)OMX_IndexConfigImageFocusLock,
1641                             &lock);
1642 
1643     if ( OMX_ErrorNone != eError )
1644     {
1645         CAMHAL_LOGEB("Error GetConfig Focus Lock error = 0x%x", eError);
1646         goto EXIT;
1647     }
1648     else
1649     {
1650         CAMHAL_LOGDB("Focus Lock GetConfig successfull bLock(%d)", lock.bLock);
1651 
1652         /* Apply locks only when not applied already */
1653         if ( lock.bLock  != toggleFocus )
1654         {
1655             setFocusLock(mParameters3A);
1656         }
1657     }
1658 
1659     OMX_INIT_STRUCT_PTR (&lock, OMX_IMAGE_CONFIG_LOCKTYPE);
1660     lock.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
1661     eError = OMX_GetConfig( mCameraAdapterParameters.mHandleComp,
1662                             (OMX_INDEXTYPE)OMX_IndexConfigImageWhiteBalanceLock,
1663                             &lock);
1664 
1665     if ( OMX_ErrorNone != eError )
1666     {
1667         CAMHAL_LOGEB("Error GetConfig WhiteBalance Lock error = 0x%x", eError);
1668         goto EXIT;
1669     }
1670     else
1671     {
1672         CAMHAL_LOGDA("WhiteBalance Lock GetConfig successfull");
1673 
1674         /* Apply locks only when not applied already */
1675         if ( lock.bLock != toggleWb )
1676         {
1677             setWhiteBalanceLock(mParameters3A);
1678         }
1679 
1680     }
1681  EXIT:
1682     return Utils::ErrorUtils::omxToAndroidError(eError);
1683 }
1684 
setMeteringAreas(Gen3A_settings & Gen3A)1685 status_t OMXCameraAdapter::setMeteringAreas(Gen3A_settings& Gen3A)
1686 {
1687   status_t ret = NO_ERROR;
1688   OMX_ERRORTYPE eError = OMX_ErrorNone;
1689 
1690   CameraBuffer *bufferlist;
1691   OMX_ALGOAREASTYPE *meteringAreas;
1692   OMX_TI_CONFIG_SHAREDBUFFER sharedBuffer;
1693   int areasSize = 0;
1694 
1695   LOG_FUNCTION_NAME
1696 
1697   android::AutoMutex lock(mMeteringAreasLock);
1698 
1699   if ( OMX_StateInvalid == mComponentState )
1700     {
1701       CAMHAL_LOGEA("OMX component is in invalid state");
1702       return NO_INIT;
1703     }
1704 
1705   areasSize = ((sizeof(OMX_ALGOAREASTYPE)+4095)/4096)*4096;
1706   bufferlist = mMemMgr.allocateBufferList(0, 0, NULL, areasSize, 1);
1707   meteringAreas = (OMX_ALGOAREASTYPE *)bufferlist[0].opaque;
1708 
1709   OMXCameraPortParameters * mPreviewData = NULL;
1710   mPreviewData = &mCameraAdapterParameters.mCameraPortParams[mCameraAdapterParameters.mPrevPortIndex];
1711 
1712   if (!meteringAreas)
1713       {
1714       CAMHAL_LOGEB("Error allocating buffer for metering areas %d", eError);
1715       return -ENOMEM;
1716       }
1717 
1718   OMX_INIT_STRUCT_PTR (meteringAreas, OMX_ALGOAREASTYPE);
1719 
1720   meteringAreas->nPortIndex = OMX_ALL;
1721   meteringAreas->nNumAreas = mMeteringAreas.size();
1722   meteringAreas->nAlgoAreaPurpose = OMX_AlgoAreaExposure;
1723 
1724   for ( unsigned int n = 0; n < mMeteringAreas.size(); n++)
1725       {
1726         int widthDivisor = 1;
1727         int heightDivisor = 1;
1728 
1729         if (mPreviewData->mFrameLayoutType == OMX_TI_StereoFrameLayoutTopBottom) {
1730             heightDivisor = 2;
1731         }
1732         if (mPreviewData->mFrameLayoutType == OMX_TI_StereoFrameLayoutLeftRight) {
1733             widthDivisor = 2;
1734         }
1735 
1736       // transform the coordinates to 3A-type coordinates
1737       mMeteringAreas.itemAt(n)->transfrom((size_t)mPreviewData->mWidth/widthDivisor,
1738                                       (size_t)mPreviewData->mHeight/heightDivisor,
1739                                       (size_t&)meteringAreas->tAlgoAreas[n].nTop,
1740                                       (size_t&)meteringAreas->tAlgoAreas[n].nLeft,
1741                                       (size_t&)meteringAreas->tAlgoAreas[n].nWidth,
1742                                       (size_t&)meteringAreas->tAlgoAreas[n].nHeight);
1743 
1744       meteringAreas->tAlgoAreas[n].nLeft =
1745               ( meteringAreas->tAlgoAreas[n].nLeft * METERING_AREAS_RANGE ) / mPreviewData->mWidth;
1746       meteringAreas->tAlgoAreas[n].nTop =
1747               ( meteringAreas->tAlgoAreas[n].nTop* METERING_AREAS_RANGE ) / mPreviewData->mHeight;
1748       meteringAreas->tAlgoAreas[n].nWidth =
1749               ( meteringAreas->tAlgoAreas[n].nWidth * METERING_AREAS_RANGE ) / mPreviewData->mWidth;
1750       meteringAreas->tAlgoAreas[n].nHeight =
1751               ( meteringAreas->tAlgoAreas[n].nHeight * METERING_AREAS_RANGE ) / mPreviewData->mHeight;
1752 
1753       meteringAreas->tAlgoAreas[n].nPriority = mMeteringAreas.itemAt(n)->getWeight();
1754 
1755       CAMHAL_LOGDB("Metering area %d : top = %d left = %d width = %d height = %d prio = %d",
1756               n, (int)meteringAreas->tAlgoAreas[n].nTop, (int)meteringAreas->tAlgoAreas[n].nLeft,
1757               (int)meteringAreas->tAlgoAreas[n].nWidth, (int)meteringAreas->tAlgoAreas[n].nHeight,
1758               (int)meteringAreas->tAlgoAreas[n].nPriority);
1759 
1760       }
1761 
1762   OMX_INIT_STRUCT_PTR (&sharedBuffer, OMX_TI_CONFIG_SHAREDBUFFER);
1763 
1764   sharedBuffer.nPortIndex = OMX_ALL;
1765   sharedBuffer.nSharedBuffSize = areasSize;
1766   sharedBuffer.pSharedBuff = (OMX_U8 *)camera_buffer_get_omx_ptr (&bufferlist[0]);
1767 
1768   if ( NULL == sharedBuffer.pSharedBuff )
1769       {
1770       CAMHAL_LOGEA("No resources to allocate OMX shared buffer");
1771       ret = -ENOMEM;
1772       goto EXIT;
1773       }
1774 
1775       eError =  OMX_SetConfig(mCameraAdapterParameters.mHandleComp,
1776                                 (OMX_INDEXTYPE) OMX_TI_IndexConfigAlgoAreas, &sharedBuffer);
1777 
1778   if ( OMX_ErrorNone != eError )
1779       {
1780       CAMHAL_LOGEB("Error while setting Focus Areas configuration 0x%x", eError);
1781       ret = -EINVAL;
1782       }
1783   else
1784       {
1785       CAMHAL_LOGDA("Metering Areas SetConfig successfull.");
1786       }
1787 
1788  EXIT:
1789   if (NULL != bufferlist)
1790       {
1791       mMemMgr.freeBufferList(bufferlist);
1792       }
1793 
1794   return ret;
1795 }
1796 
1797 //TI extensions for enable/disable algos
setParameter3ABoolInvert(const OMX_INDEXTYPE omx_idx,const OMX_BOOL data,const char * msg)1798 status_t OMXCameraAdapter::setParameter3ABoolInvert(const OMX_INDEXTYPE omx_idx,
1799                                                     const OMX_BOOL data, const char *msg)
1800 {
1801     OMX_BOOL inv_data;
1802 
1803     if (OMX_TRUE == data)
1804         {
1805         inv_data = OMX_FALSE;
1806         }
1807     else if (OMX_FALSE == data)
1808         {
1809         inv_data = OMX_TRUE;
1810         }
1811     else
1812         {
1813         return BAD_VALUE;
1814         }
1815     return setParameter3ABool(omx_idx, inv_data, msg);
1816 }
1817 
setParameter3ABool(const OMX_INDEXTYPE omx_idx,const OMX_BOOL data,const char * msg)1818 status_t OMXCameraAdapter::setParameter3ABool(const OMX_INDEXTYPE omx_idx,
1819                                               const OMX_BOOL data, const char *msg)
1820 {
1821   OMX_ERRORTYPE eError = OMX_ErrorNone;
1822   OMX_CONFIG_BOOLEANTYPE cfgdata;
1823 
1824   LOG_FUNCTION_NAME
1825 
1826   if ( OMX_StateInvalid == mComponentState )
1827     {
1828       CAMHAL_LOGEA("OMX component is in invalid state");
1829       return NO_INIT;
1830     }
1831 
1832   OMX_INIT_STRUCT_PTR (&cfgdata, OMX_CONFIG_BOOLEANTYPE);
1833   cfgdata.bEnabled = data;
1834   eError = OMX_SetConfig( mCameraAdapterParameters.mHandleComp,
1835                           omx_idx,
1836                           &cfgdata);
1837   if ( OMX_ErrorNone != eError )
1838     {
1839       CAMHAL_LOGEB("Error while configuring %s error = 0x%x", msg, eError);
1840     }
1841   else
1842     {
1843       CAMHAL_LOGDB("%s configured successfully %d ", msg, cfgdata.bEnabled);
1844     }
1845 
1846   LOG_FUNCTION_NAME_EXIT
1847 
1848   return Utils::ErrorUtils::omxToAndroidError(eError);
1849 }
1850 
setAlgoExternalGamma(Gen3A_settings & Gen3A)1851 status_t OMXCameraAdapter::setAlgoExternalGamma(Gen3A_settings& Gen3A)
1852 {
1853     return setParameter3ABool((OMX_INDEXTYPE) OMX_TI_IndexConfigExternalGamma, Gen3A.AlgoExternalGamma, "External Gamma");
1854 }
1855 
setAlgoNSF1(Gen3A_settings & Gen3A)1856 status_t OMXCameraAdapter::setAlgoNSF1(Gen3A_settings& Gen3A)
1857 {
1858     return setParameter3ABoolInvert((OMX_INDEXTYPE) OMX_TI_IndexConfigDisableNSF1, Gen3A.AlgoNSF1, "NSF1");
1859 }
1860 
setAlgoNSF2(Gen3A_settings & Gen3A)1861 status_t OMXCameraAdapter::setAlgoNSF2(Gen3A_settings& Gen3A)
1862 {
1863     return setParameter3ABoolInvert((OMX_INDEXTYPE) OMX_TI_IndexConfigDisableNSF2, Gen3A.AlgoNSF2, "NSF2");
1864 }
1865 
setAlgoSharpening(Gen3A_settings & Gen3A)1866 status_t OMXCameraAdapter::setAlgoSharpening(Gen3A_settings& Gen3A)
1867 {
1868     return setParameter3ABoolInvert((OMX_INDEXTYPE) OMX_TI_IndexConfigDisableSharpening, Gen3A.AlgoSharpening, "Sharpening");
1869 }
1870 
setAlgoThreeLinColorMap(Gen3A_settings & Gen3A)1871 status_t OMXCameraAdapter::setAlgoThreeLinColorMap(Gen3A_settings& Gen3A)
1872 {
1873     return setParameter3ABoolInvert((OMX_INDEXTYPE) OMX_TI_IndexConfigDisableThreeLinColorMap, Gen3A.AlgoThreeLinColorMap, "Color Conversion");
1874 }
1875 
setAlgoGIC(Gen3A_settings & Gen3A)1876 status_t OMXCameraAdapter::setAlgoGIC(Gen3A_settings& Gen3A)
1877 {
1878     return setParameter3ABoolInvert((OMX_INDEXTYPE) OMX_TI_IndexConfigDisableGIC, Gen3A.AlgoGIC, "Green Inballance Correction");
1879 }
1880 
setGammaTable(Gen3A_settings & Gen3A)1881 status_t OMXCameraAdapter::setGammaTable(Gen3A_settings& Gen3A)
1882 {
1883     status_t ret = NO_ERROR;
1884     OMX_ERRORTYPE eError = OMX_ErrorNone;
1885     CameraBuffer *bufferlist = NULL;
1886     OMX_TI_CONFIG_GAMMATABLE_TYPE *gammaTable = NULL;
1887     OMX_TI_CONFIG_SHAREDBUFFER sharedBuffer;
1888     int tblSize = 0;
1889 
1890     LOG_FUNCTION_NAME;
1891 
1892     if ( OMX_StateInvalid == mComponentState ) {
1893         CAMHAL_LOGEA("OMX component is in invalid state");
1894         ret = NO_INIT;
1895         goto EXIT;
1896     }
1897 
1898     tblSize = ((sizeof(OMX_TI_CONFIG_GAMMATABLE_TYPE)+4095)/4096)*4096;
1899     bufferlist = mMemMgr.allocateBufferList(0, 0, NULL, tblSize, 1);
1900     if (NULL == bufferlist) {
1901         CAMHAL_LOGEB("Error allocating buffer for gamma table");
1902         ret =  NO_MEMORY;
1903         goto EXIT;
1904     }
1905     gammaTable = (OMX_TI_CONFIG_GAMMATABLE_TYPE *)bufferlist[0].mapped;
1906     if (NULL == gammaTable) {
1907         CAMHAL_LOGEB("Error allocating buffer for gamma table (wrong data pointer)");
1908         ret =  NO_MEMORY;
1909         goto EXIT;
1910     }
1911 
1912     memcpy(gammaTable, &mParameters3A.mGammaTable, sizeof(OMX_TI_CONFIG_GAMMATABLE_TYPE));
1913 
1914 #ifdef CAMERAHAL_DEBUG
1915     {
1916         android::String8 DmpR;
1917         android::String8 DmpG;
1918         android::String8 DmpB;
1919         for (unsigned int i=0; i<OMX_TI_GAMMATABLE_SIZE;i++) {
1920             DmpR.appendFormat(" %d:%d;", (int)gammaTable->pR[i].nOffset, (int)(int)gammaTable->pR[i].nSlope);
1921             DmpG.appendFormat(" %d:%d;", (int)gammaTable->pG[i].nOffset, (int)(int)gammaTable->pG[i].nSlope);
1922             DmpB.appendFormat(" %d:%d;", (int)gammaTable->pB[i].nOffset, (int)(int)gammaTable->pB[i].nSlope);
1923         }
1924         CAMHAL_LOGE("Gamma table R:%s", DmpR.string());
1925         CAMHAL_LOGE("Gamma table G:%s", DmpG.string());
1926         CAMHAL_LOGE("Gamma table B:%s", DmpB.string());
1927     }
1928 #endif
1929 
1930     OMX_INIT_STRUCT_PTR (&sharedBuffer, OMX_TI_CONFIG_SHAREDBUFFER);
1931     sharedBuffer.nPortIndex = OMX_ALL;
1932     sharedBuffer.nSharedBuffSize = sizeof(OMX_TI_CONFIG_GAMMATABLE_TYPE);
1933     sharedBuffer.pSharedBuff = (OMX_U8 *)camera_buffer_get_omx_ptr (&bufferlist[0]);
1934     if ( NULL == sharedBuffer.pSharedBuff ) {
1935         CAMHAL_LOGEA("No resources to allocate OMX shared buffer");
1936         ret = NO_MEMORY;
1937         goto EXIT;
1938     }
1939 
1940     eError =  OMX_SetConfig(mCameraAdapterParameters.mHandleComp,
1941                             (OMX_INDEXTYPE) OMX_TI_IndexConfigGammaTable, &sharedBuffer);
1942     if ( OMX_ErrorNone != eError ) {
1943         CAMHAL_LOGEB("Error while setting Gamma Table configuration 0x%x", eError);
1944         ret = BAD_VALUE;
1945         goto EXIT;
1946     } else {
1947         CAMHAL_LOGDA("Gamma Table SetConfig successfull.");
1948     }
1949 
1950 EXIT:
1951 
1952     if (NULL != bufferlist) {
1953         mMemMgr.freeBufferList(bufferlist);
1954     }
1955 
1956     LOG_FUNCTION_NAME_EXIT;
1957 
1958     return ret;
1959 }
1960 
apply3Asettings(Gen3A_settings & Gen3A)1961 status_t OMXCameraAdapter::apply3Asettings( Gen3A_settings& Gen3A )
1962 {
1963     status_t ret = NO_ERROR;
1964     unsigned int currSett; // 32 bit
1965     int portIndex;
1966 
1967     LOG_FUNCTION_NAME;
1968 
1969     android::AutoMutex lock(m3ASettingsUpdateLock);
1970 
1971     /*
1972      * Scenes have a priority during the process
1973      * of applying 3A related parameters.
1974      * They can override pretty much all other 3A
1975      * settings and similarly get overridden when
1976      * for instance the focus mode gets switched.
1977      * There is only one exception to this rule,
1978      * the manual a.k.a. auto scene.
1979      */
1980     if (SetSceneMode & mPending3Asettings) {
1981         mPending3Asettings &= ~SetSceneMode;
1982         ret |= setScene(Gen3A);
1983         // re-apply EV compensation after setting scene mode since it probably reset it
1984         if(Gen3A.EVCompensation) {
1985             setEVCompensation(Gen3A);
1986         }
1987         return ret;
1988     } else if (OMX_Manual != Gen3A.SceneMode) {
1989         // only certain settings are allowed when scene mode is set
1990         mPending3Asettings &= (SetEVCompensation | SetFocus | SetWBLock |
1991                                SetExpLock | SetWhiteBallance | SetFlash);
1992         if ( mPending3Asettings == 0 ) return NO_ERROR;
1993     }
1994 
1995     for( currSett = 1; currSett < E3aSettingMax; currSett <<= 1)
1996         {
1997         if( currSett & mPending3Asettings )
1998             {
1999             switch( currSett )
2000                 {
2001                 case SetEVCompensation:
2002                     {
2003                     ret |= setEVCompensation(Gen3A);
2004                     break;
2005                     }
2006 
2007                 case SetWhiteBallance:
2008                     {
2009                     ret |= setWBMode(Gen3A);
2010                     break;
2011                     }
2012 
2013                 case SetFlicker:
2014                     {
2015                     ret |= setFlicker(Gen3A);
2016                     break;
2017                     }
2018 
2019                 case SetBrightness:
2020                     {
2021                     ret |= setBrightness(Gen3A);
2022                     break;
2023                     }
2024 
2025                 case SetContrast:
2026                     {
2027                     ret |= setContrast(Gen3A);
2028                     break;
2029                     }
2030 
2031                 case SetSharpness:
2032                     {
2033                     ret |= setSharpness(Gen3A);
2034                     break;
2035                     }
2036 
2037                 case SetSaturation:
2038                     {
2039                     ret |= setSaturation(Gen3A);
2040                     break;
2041                     }
2042 
2043                 case SetISO:
2044                     {
2045                     ret |= setISO(Gen3A);
2046                     break;
2047                     }
2048 
2049                 case SetEffect:
2050                     {
2051                     ret |= setEffect(Gen3A);
2052                     break;
2053                     }
2054 
2055                 case SetFocus:
2056                     {
2057                     ret |= setFocusMode(Gen3A);
2058                     break;
2059                     }
2060 
2061                 case SetExpMode:
2062                     {
2063                     ret |= setExposureMode(Gen3A);
2064                     break;
2065                     }
2066 
2067                 case SetManualExposure: {
2068                     ret |= setManualExposureVal(Gen3A);
2069                     break;
2070                 }
2071 
2072                 case SetFlash:
2073                     {
2074                     ret |= setFlashMode(Gen3A);
2075                     break;
2076                     }
2077 
2078                 case SetExpLock:
2079                   {
2080                     ret |= setExposureLock(Gen3A);
2081                     break;
2082                   }
2083 
2084                 case SetWBLock:
2085                   {
2086                     ret |= setWhiteBalanceLock(Gen3A);
2087                     break;
2088                   }
2089                 case SetMeteringAreas:
2090                   {
2091                     ret |= setMeteringAreas(Gen3A);
2092                   }
2093                   break;
2094 
2095                 //TI extensions for enable/disable algos
2096                 case SetAlgoExternalGamma:
2097                   {
2098                     ret |= setAlgoExternalGamma(Gen3A);
2099                   }
2100                   break;
2101 
2102                 case SetAlgoNSF1:
2103                   {
2104                     ret |= setAlgoNSF1(Gen3A);
2105                   }
2106                   break;
2107 
2108                 case SetAlgoNSF2:
2109                   {
2110                     ret |= setAlgoNSF2(Gen3A);
2111                   }
2112                   break;
2113 
2114                 case SetAlgoSharpening:
2115                   {
2116                     ret |= setAlgoSharpening(Gen3A);
2117                   }
2118                   break;
2119 
2120                 case SetAlgoThreeLinColorMap:
2121                   {
2122                     ret |= setAlgoThreeLinColorMap(Gen3A);
2123                   }
2124                   break;
2125 
2126                 case SetAlgoGIC:
2127                   {
2128                     ret |= setAlgoGIC(Gen3A);
2129                   }
2130                   break;
2131 
2132                 case SetGammaTable:
2133                   {
2134                     ret |= setGammaTable(Gen3A);
2135                   }
2136                   break;
2137 
2138                 default:
2139                     CAMHAL_LOGEB("this setting (0x%x) is still not supported in CameraAdapter ",
2140                                  currSett);
2141                     break;
2142                 }
2143                 mPending3Asettings &= ~currSett;
2144             }
2145         }
2146 
2147         LOG_FUNCTION_NAME_EXIT;
2148 
2149         return ret;
2150 }
2151 
2152 } // namespace Camera
2153 } // namespace Ti
2154