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