OMXFocus.cpp revision 2f15c6a9f1d24904705ddab6a6c005126e8846dd
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/**
19* @file OMXFocus.cpp
20*
21* This file contains functionality for handling focus configurations.
22*
23*/
24
25#undef LOG_TAG
26
27#define LOG_TAG "CameraHAL"
28
29#include "CameraHal.h"
30#include "OMXCameraAdapter.h"
31#include "ErrorUtils.h"
32
33#define TOUCH_FOCUS_RANGE 0xFF
34#define AF_CALLBACK_TIMEOUT 5000000 //5 seconds timeout
35
36namespace android {
37
38status_t OMXCameraAdapter::setParametersFocus(const CameraParameters &params,
39                                              BaseCameraAdapter::AdapterState state)
40{
41    status_t ret = NO_ERROR;
42    const char *str = NULL;
43    Mutex::Autolock lock(mFocusAreasLock);
44    size_t MAX_FOCUS_AREAS;
45
46
47    LOG_FUNCTION_NAME;
48
49    str = params.get(CameraParameters::KEY_FOCUS_AREAS);
50
51    MAX_FOCUS_AREAS = atoi(params.get(CameraParameters::KEY_MAX_NUM_FOCUS_AREAS));
52
53    mFocusAreas.clear();
54    if ( NULL != str ) {
55        ret = CameraArea::parseAreas(str, ( strlen(str) + 1 ), mFocusAreas);
56    }
57
58    if ( NO_ERROR == ret ) {
59        if ( MAX_FOCUS_AREAS < mFocusAreas.size() ) {
60            CAMHAL_LOGEB("Focus areas supported %d, focus areas set %d",
61                         MAX_FOCUS_AREAS,
62                         mFocusAreas.size());
63            ret = -EINVAL;
64        }
65    }
66
67    LOG_FUNCTION_NAME;
68
69    return ret;
70}
71
72status_t OMXCameraAdapter::doAutoFocus()
73{
74    status_t ret = NO_ERROR;
75    OMX_ERRORTYPE eError = OMX_ErrorNone;
76    OMX_IMAGE_CONFIG_FOCUSCONTROLTYPE focusControl;
77    OMX_PARAM_FOCUSSTATUSTYPE focusStatus;
78
79    LOG_FUNCTION_NAME;
80
81    if ( OMX_StateExecuting != mComponentState )
82        {
83        CAMHAL_LOGEA("OMX component not in executing state");
84        returnFocusStatus(false);
85        return NO_INIT;
86        }
87
88    if ( 0 != mDoAFSem.Count() )
89        {
90        CAMHAL_LOGEB("Error mDoAFSem semaphore count %d", mDoAFSem.Count());
91        return NO_INIT;
92        }
93
94    // If the app calls autoFocus, the camera will stop sending face callbacks.
95    pauseFaceDetection(true);
96
97    OMX_INIT_STRUCT_PTR (&focusControl, OMX_IMAGE_CONFIG_FOCUSCONTROLTYPE);
98    focusControl.eFocusControl = ( OMX_IMAGE_FOCUSCONTROLTYPE ) mParameters3A.Focus;
99
100    //In case we have CAF running we should first check the AF status.
101    //If it has managed to lock, then do as usual and return status
102    //immediately. If lock is not available, then switch temporarily
103    //to 'autolock' and do normal AF.
104    if ( mParameters3A.Focus == OMX_IMAGE_FocusControlAuto ) {
105
106        ret = checkFocus(&focusStatus);
107        if ( NO_ERROR != ret ) {
108            CAMHAL_LOGEB("Focus status check failed 0x%x!", ret);
109            return ret;
110        } else {
111            CAMHAL_LOGDB("Focus status check 0x%x!", focusStatus.eFocusStatus);
112        }
113
114        if ( OMX_FocusStatusReached != focusStatus.eFocusStatus ) {
115            focusControl.eFocusControl = OMX_IMAGE_FocusControlAutoLock;
116        }
117    }
118
119    if ( ( focusControl.eFocusControl != OMX_IMAGE_FocusControlAuto ) &&
120         ( focusControl.eFocusControl != ( OMX_IMAGE_FOCUSCONTROLTYPE )
121                 OMX_IMAGE_FocusControlAutoInfinity ) ) {
122
123        ret = RegisterForEvent(mCameraAdapterParameters.mHandleComp,
124                                    (OMX_EVENTTYPE) OMX_EventIndexSettingChanged,
125                                    OMX_ALL,
126                                    OMX_IndexConfigCommonFocusStatus,
127                                    mDoAFSem);
128
129        if ( NO_ERROR == ret ) {
130            ret = setFocusCallback(true);
131        }
132
133    }
134
135    eError =  OMX_SetConfig(mCameraAdapterParameters.mHandleComp,
136                            OMX_IndexConfigFocusControl,
137                            &focusControl);
138
139    if ( OMX_ErrorNone != eError ) {
140        CAMHAL_LOGEB("Error while starting focus 0x%x", eError);
141        return INVALID_OPERATION;
142    } else {
143        CAMHAL_LOGDA("Autofocus started successfully");
144    }
145
146    if ( ( focusControl.eFocusControl != OMX_IMAGE_FocusControlAuto ) &&
147         ( focusControl.eFocusControl != ( OMX_IMAGE_FOCUSCONTROLTYPE )
148                 OMX_IMAGE_FocusControlAutoInfinity ) ) {
149
150      if(mDoAFSem.WaitTimeout(AF_CALLBACK_TIMEOUT) != NO_ERROR) {
151
152        //If somethiing bad happened while we wait
153        if (mComponentState == OMX_StateInvalid)
154          {
155            CAMHAL_LOGEA("Invalid State after Auto Focus Exitting!!!");
156            return EINVAL;
157          }
158
159           //Disable auto focus callback from Ducati
160            setFocusCallback(false);
161            CAMHAL_LOGEA("Autofocus callback timeout expired");
162            RemoveEvent(mCameraAdapterParameters.mHandleComp,
163                                        (OMX_EVENTTYPE) OMX_EventIndexSettingChanged,
164                                        OMX_ALL,
165                                        OMX_IndexConfigCommonFocusStatus,
166                                        NULL );
167            returnFocusStatus(true);
168        } else {
169            CAMHAL_LOGDA("Autofocus callback received");
170            //Disable auto focus callback from Ducati
171            setFocusCallback(false);
172            ret = returnFocusStatus(false);
173        }
174
175    } else {
176        if ( NO_ERROR == ret ) {
177            ret = returnFocusStatus(false);
178        }
179    }
180
181    //Restore CAF if needed
182    if ( ( mParameters3A.Focus == OMX_IMAGE_FocusControlAuto ) &&
183         ( focusControl.eFocusControl == OMX_IMAGE_FocusControlAutoLock ) ) {
184        mPending3Asettings |= SetFocus;
185    }
186
187    LOG_FUNCTION_NAME_EXIT;
188
189    return ret;
190}
191
192status_t OMXCameraAdapter::stopAutoFocus()
193{
194    status_t ret = NO_ERROR;
195    OMX_ERRORTYPE eError = OMX_ErrorNone;
196    OMX_IMAGE_CONFIG_FOCUSCONTROLTYPE focusControl;
197
198    LOG_FUNCTION_NAME;
199
200    if ( OMX_StateExecuting != mComponentState )
201        {
202        CAMHAL_LOGEA("OMX component not in executing state");
203        return NO_INIT;
204        }
205
206    if ( mParameters3A.Focus == OMX_IMAGE_FocusControlAutoInfinity ) {
207        // No need to stop focus if we are in infinity mode. Nothing to stop.
208        return NO_ERROR;
209    }
210
211    if ( NO_ERROR == ret )
212       {
213       //Disable the callback first
214       ret = setFocusCallback(false);
215       }
216
217    if ( NO_ERROR == ret )
218        {
219        OMX_INIT_STRUCT_PTR (&focusControl, OMX_IMAGE_CONFIG_FOCUSCONTROLTYPE);
220        focusControl.eFocusControl = OMX_IMAGE_FocusControlOff;
221
222        eError =  OMX_SetConfig(mCameraAdapterParameters.mHandleComp,
223                                OMX_IndexConfigFocusControl,
224                                &focusControl);
225        if ( OMX_ErrorNone != eError )
226            {
227            CAMHAL_LOGEB("Error while stopping focus 0x%x", eError);
228            return ErrorUtils::omxToAndroidError(eError);
229            }
230        }
231
232    //Query current focus distance after AF is complete
233    updateFocusDistances(mParameters);
234
235    LOG_FUNCTION_NAME_EXIT;
236
237    return ret;
238}
239
240status_t OMXCameraAdapter::getFocusMode(OMX_IMAGE_CONFIG_FOCUSCONTROLTYPE &focusMode)
241{;
242    OMX_ERRORTYPE eError = OMX_ErrorNone;
243
244    LOG_FUNCTION_NAME;
245
246    if ( OMX_StateInvalid == mComponentState ) {
247        CAMHAL_LOGEA("OMX component is in invalid state");
248        return NO_INIT;
249    }
250
251    OMX_INIT_STRUCT_PTR (&focusMode, OMX_IMAGE_CONFIG_FOCUSCONTROLTYPE);
252    focusMode.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
253
254    eError =  OMX_GetConfig(mCameraAdapterParameters.mHandleComp,
255                            OMX_IndexConfigFocusControl,
256                            &focusMode);
257
258    if ( OMX_ErrorNone != eError ) {
259        CAMHAL_LOGEB("Error while retrieving focus mode 0x%x", eError);
260    }
261
262    LOG_FUNCTION_NAME_EXIT;
263
264    return ErrorUtils::omxToAndroidError(eError);
265}
266
267status_t OMXCameraAdapter::cancelAutoFocus()
268{
269    status_t ret = NO_ERROR;
270    OMX_ERRORTYPE eError = OMX_ErrorNone;
271    OMX_IMAGE_CONFIG_FOCUSCONTROLTYPE focusMode;
272
273    LOG_FUNCTION_NAME;
274    // Unlock 3A locks since they were locked by AF conditionally
275    if( set3ALock(mUserSetExpLock, mUserSetWbLock, OMX_FALSE) != NO_ERROR) {
276      CAMHAL_LOGEA("Error Unlocking 3A locks");
277    }
278    else{
279      CAMHAL_LOGDA("AE/AWB unlocked successfully");
280    }
281
282    ret = getFocusMode(focusMode);
283    if ( NO_ERROR != ret ) {
284        return ret;
285    }
286
287    //Stop the AF only for modes other than CAF  or Inifinity
288    if ( ( focusMode.eFocusControl != OMX_IMAGE_FocusControlAuto ) &&
289         ( focusMode.eFocusControl != ( OMX_IMAGE_FOCUSCONTROLTYPE )
290                 OMX_IMAGE_FocusControlAutoInfinity ) ) {
291        stopAutoFocus();
292        //Signal a dummy AF event so that in case the callback from ducati
293        //does come then it doesnt crash after
294        //exiting this function since eventSem will go out of scope.
295        ret |= SignalEvent(mCameraAdapterParameters.mHandleComp,
296                                    (OMX_EVENTTYPE) OMX_EventIndexSettingChanged,
297                                    OMX_ALL,
298                                    OMX_IndexConfigCommonFocusStatus,
299                                    NULL );
300    }
301
302    // If the apps call #cancelAutoFocus()}, the face callbacks will also resume.
303    pauseFaceDetection(false);
304
305    LOG_FUNCTION_NAME_EXIT;
306
307    return ret;
308
309}
310
311status_t OMXCameraAdapter::setFocusCallback(bool enabled)
312{
313    status_t ret = NO_ERROR;
314    OMX_ERRORTYPE eError = OMX_ErrorNone;
315    OMX_CONFIG_CALLBACKREQUESTTYPE focusRequstCallback;
316
317    LOG_FUNCTION_NAME;
318
319    if ( OMX_StateExecuting != mComponentState )
320        {
321        CAMHAL_LOGEA("OMX component not in executing state");
322        ret = -1;
323        }
324
325    if ( NO_ERROR == ret )
326        {
327
328        OMX_INIT_STRUCT_PTR (&focusRequstCallback, OMX_CONFIG_CALLBACKREQUESTTYPE);
329        focusRequstCallback.nPortIndex = OMX_ALL;
330        focusRequstCallback.nIndex = OMX_IndexConfigCommonFocusStatus;
331
332        if ( enabled )
333            {
334            focusRequstCallback.bEnable = OMX_TRUE;
335            }
336        else
337            {
338            focusRequstCallback.bEnable = OMX_FALSE;
339            }
340
341        eError =  OMX_SetConfig(mCameraAdapterParameters.mHandleComp,
342                                (OMX_INDEXTYPE) OMX_IndexConfigCallbackRequest,
343                                &focusRequstCallback);
344        if ( OMX_ErrorNone != eError )
345            {
346            CAMHAL_LOGEB("Error registering focus callback 0x%x", eError);
347            ret = -1;
348            }
349        else
350            {
351            CAMHAL_LOGDB("Autofocus callback for index 0x%x registered successfully",
352                         OMX_IndexConfigCommonFocusStatus);
353            }
354        }
355
356    LOG_FUNCTION_NAME_EXIT;
357
358    return ret;
359}
360
361status_t OMXCameraAdapter::returnFocusStatus(bool timeoutReached)
362{
363    status_t ret = NO_ERROR;
364    OMX_PARAM_FOCUSSTATUSTYPE eFocusStatus;
365    bool focusStatus = false;
366    BaseCameraAdapter::AdapterState state;
367    BaseCameraAdapter::getState(state);
368
369    LOG_FUNCTION_NAME;
370
371    OMX_INIT_STRUCT(eFocusStatus, OMX_PARAM_FOCUSSTATUSTYPE);
372
373    if( ( AF_ACTIVE & state ) != AF_ACTIVE )
374       {
375        /// We don't send focus callback if focus was not started
376       return NO_ERROR;
377       }
378
379    if ( NO_ERROR == ret )
380        {
381
382        if ( !timeoutReached )
383            {
384            ret = checkFocus(&eFocusStatus);
385
386            if ( NO_ERROR != ret )
387                {
388                CAMHAL_LOGEA("Focus status check failed!");
389                }
390            }
391        }
392
393    if ( NO_ERROR == ret )
394        {
395
396        if ( timeoutReached )
397            {
398            focusStatus = false;
399            }
400        else
401            {
402            switch (eFocusStatus.eFocusStatus)
403                {
404                    case OMX_FocusStatusReached:
405                        {
406                        focusStatus = true;
407                        break;
408                        }
409                    case OMX_FocusStatusOff:
410                    case OMX_FocusStatusUnableToReach:
411                    case OMX_FocusStatusRequest:
412                    default:
413                        {
414                        focusStatus = false;
415                        break;
416                        }
417                }
418            //Lock the AE and AWB here
419            // Apply 3A locks after AF
420            if( set3ALock(OMX_TRUE, OMX_TRUE, OMX_TRUE) != NO_ERROR) {
421                CAMHAL_LOGEA("Error Applying 3A locks");
422            }
423            else
424                {
425                CAMHAL_LOGDA("Focus locked. Applied focus locks successfully");
426                }
427
428            stopAutoFocus();
429            }
430        }
431
432    ret =  BaseCameraAdapter::setState(CAMERA_CANCEL_AUTOFOCUS);
433    if ( NO_ERROR == ret )
434        {
435        ret = BaseCameraAdapter::commitState();
436        }
437    else
438        {
439        ret |= BaseCameraAdapter::rollbackState();
440        }
441
442    if ( NO_ERROR == ret )
443        {
444        notifyFocusSubscribers(focusStatus);
445        }
446
447    // After focus, face detection will resume sending face callbacks
448    pauseFaceDetection(false);
449
450    LOG_FUNCTION_NAME_EXIT;
451
452    return ret;
453}
454
455status_t OMXCameraAdapter::checkFocus(OMX_PARAM_FOCUSSTATUSTYPE *eFocusStatus)
456{
457    status_t ret = NO_ERROR;
458    OMX_ERRORTYPE eError = OMX_ErrorNone;
459
460    LOG_FUNCTION_NAME;
461
462    if ( NULL == eFocusStatus )
463        {
464        CAMHAL_LOGEA("Invalid focus status");
465        ret = -EINVAL;
466        }
467
468    if ( OMX_StateExecuting != mComponentState )
469        {
470        CAMHAL_LOGEA("OMX component not in executing state");
471        ret = -EINVAL;
472        }
473
474    if ( NO_ERROR == ret )
475        {
476        OMX_INIT_STRUCT_PTR (eFocusStatus, OMX_PARAM_FOCUSSTATUSTYPE);
477
478        eError = OMX_GetConfig(mCameraAdapterParameters.mHandleComp,
479                               OMX_IndexConfigCommonFocusStatus,
480                               eFocusStatus);
481        if ( OMX_ErrorNone != eError )
482            {
483            CAMHAL_LOGEB("Error while retrieving focus status: 0x%x", eError);
484            ret = -1;
485            }
486        }
487
488    if ( NO_ERROR == ret )
489        {
490        CAMHAL_LOGDB("Focus Status: %d", eFocusStatus->eFocusStatus);
491        }
492
493    LOG_FUNCTION_NAME_EXIT;
494
495    return ret;
496}
497
498status_t OMXCameraAdapter::updateFocusDistances(CameraParameters &params)
499{
500    OMX_U32 focusNear, focusOptimal, focusFar;
501    status_t ret = NO_ERROR;
502
503    LOG_FUNCTION_NAME;
504
505    ret = getFocusDistances(focusNear, focusOptimal, focusFar);
506    if ( NO_ERROR == ret)
507        {
508        ret = addFocusDistances(focusNear, focusOptimal, focusFar, params);
509            if ( NO_ERROR != ret )
510                {
511                CAMHAL_LOGEB("Error in call to addFocusDistances() 0x%x", ret);
512                }
513        }
514    else
515        {
516        CAMHAL_LOGEB("Error in call to getFocusDistances() 0x%x", ret);
517        }
518
519    LOG_FUNCTION_NAME_EXIT;
520
521    return ret;
522}
523
524status_t OMXCameraAdapter::getFocusDistances(OMX_U32 &near,OMX_U32 &optimal, OMX_U32 &far)
525{
526    status_t ret = NO_ERROR;
527    OMX_ERRORTYPE eError;
528
529    OMX_TI_CONFIG_FOCUSDISTANCETYPE focusDist;
530
531    LOG_FUNCTION_NAME;
532
533    if ( OMX_StateInvalid == mComponentState )
534        {
535        CAMHAL_LOGEA("OMX component is in invalid state");
536        ret = UNKNOWN_ERROR;
537        }
538
539    if ( NO_ERROR == ret )
540        {
541        OMX_INIT_STRUCT_PTR(&focusDist, OMX_TI_CONFIG_FOCUSDISTANCETYPE);
542        focusDist.nPortIndex = mCameraAdapterParameters.mPrevPortIndex;
543
544        eError = OMX_GetConfig(mCameraAdapterParameters.mHandleComp,
545                               ( OMX_INDEXTYPE ) OMX_TI_IndexConfigFocusDistance,
546                               &focusDist);
547        if ( OMX_ErrorNone != eError )
548            {
549            CAMHAL_LOGEB("Error while querying focus distances 0x%x", eError);
550            ret = UNKNOWN_ERROR;
551            }
552
553        }
554
555    if ( NO_ERROR == ret )
556        {
557        near = focusDist.nFocusDistanceNear;
558        optimal = focusDist.nFocusDistanceOptimal;
559        far = focusDist.nFocusDistanceFar;
560        }
561
562    LOG_FUNCTION_NAME_EXIT;
563
564    return ret;
565}
566
567status_t OMXCameraAdapter::encodeFocusDistance(OMX_U32 dist, char *buffer, size_t length)
568{
569    status_t ret = NO_ERROR;
570    uint32_t focusScale = 1000;
571    float distFinal;
572
573    LOG_FUNCTION_NAME;
574
575    if(mParameters3A.Focus == OMX_IMAGE_FocusControlAutoInfinity)
576        {
577        dist=0;
578        }
579
580    if ( NO_ERROR == ret )
581        {
582        if ( 0 == dist )
583            {
584            strncpy(buffer, CameraParameters::FOCUS_DISTANCE_INFINITY, ( length - 1 ));
585            }
586        else
587            {
588            distFinal = dist;
589            distFinal /= focusScale;
590            snprintf(buffer, ( length - 1 ) , "%5.3f", distFinal);
591            }
592        }
593
594    LOG_FUNCTION_NAME_EXIT;
595
596    return ret;
597}
598
599status_t OMXCameraAdapter::addFocusDistances(OMX_U32 &near,
600                                             OMX_U32 &optimal,
601                                             OMX_U32 &far,
602                                             CameraParameters& params)
603{
604    status_t ret = NO_ERROR;
605
606    LOG_FUNCTION_NAME;
607
608    if ( NO_ERROR == ret )
609        {
610        ret = encodeFocusDistance(near, mFocusDistNear, FOCUS_DIST_SIZE);
611        if ( NO_ERROR != ret )
612            {
613            CAMHAL_LOGEB("Error encoding near focus distance 0x%x", ret);
614            }
615        }
616
617    if ( NO_ERROR == ret )
618        {
619        ret = encodeFocusDistance(optimal, mFocusDistOptimal, FOCUS_DIST_SIZE);
620        if ( NO_ERROR != ret )
621            {
622            CAMHAL_LOGEB("Error encoding near focus distance 0x%x", ret);
623            }
624        }
625
626    if ( NO_ERROR == ret )
627        {
628        ret = encodeFocusDistance(far, mFocusDistFar, FOCUS_DIST_SIZE);
629        if ( NO_ERROR != ret )
630            {
631            CAMHAL_LOGEB("Error encoding near focus distance 0x%x", ret);
632            }
633        }
634
635    if ( NO_ERROR == ret )
636        {
637        snprintf(mFocusDistBuffer, ( FOCUS_DIST_BUFFER_SIZE - 1) ,"%s,%s,%s", mFocusDistNear,
638                                                                              mFocusDistOptimal,
639                                                                              mFocusDistFar);
640
641        params.set(CameraParameters::KEY_FOCUS_DISTANCES, mFocusDistBuffer);
642        }
643
644    LOG_FUNCTION_NAME_EXIT;
645
646    return ret;
647}
648
649status_t OMXCameraAdapter::setTouchFocus()
650{
651    status_t ret = NO_ERROR;
652    OMX_ERRORTYPE eError = OMX_ErrorNone;
653
654    OMX_ALGOAREASTYPE **focusAreas;
655    OMX_TI_CONFIG_SHAREDBUFFER sharedBuffer;
656    MemoryManager memMgr;
657    int areasSize = 0;
658
659    LOG_FUNCTION_NAME;
660
661    if ( OMX_StateInvalid == mComponentState )
662        {
663        CAMHAL_LOGEA("OMX component is in invalid state");
664        ret = -1;
665        }
666
667    if ( NO_ERROR == ret )
668        {
669
670        areasSize = ((sizeof(OMX_ALGOAREASTYPE)+4095)/4096)*4096;
671        focusAreas = (OMX_ALGOAREASTYPE**) memMgr.allocateBuffer(0, 0, NULL, areasSize, 1);
672
673        OMXCameraPortParameters * mPreviewData = NULL;
674        mPreviewData = &mCameraAdapterParameters.mCameraPortParams[mCameraAdapterParameters.mPrevPortIndex];
675
676        if (!focusAreas)
677            {
678            CAMHAL_LOGEB("Error allocating buffer for focus areas %d", eError);
679            return -ENOMEM;
680            }
681
682        OMX_INIT_STRUCT_PTR (focusAreas[0], OMX_ALGOAREASTYPE);
683
684        focusAreas[0]->nPortIndex = OMX_ALL;
685        focusAreas[0]->nNumAreas = mFocusAreas.size();
686        focusAreas[0]->nAlgoAreaPurpose = OMX_AlgoAreaFocus;
687
688        // If the area is the special case of (0, 0, 0, 0, 0), then
689        // the algorithm needs nNumAreas to be set to 0,
690        // in order to automatically choose the best fitting areas.
691        if ( mFocusAreas.itemAt(0)->isZeroArea() )
692            {
693            focusAreas[0]->nNumAreas = 0;
694            }
695
696        for ( unsigned int n = 0; n < mFocusAreas.size(); n++)
697            {
698            // transform the coordinates to 3A-type coordinates
699            mFocusAreas.itemAt(n)->transfrom((size_t)mPreviewData->mWidth,
700                                            (size_t)mPreviewData->mHeight,
701                                            (size_t&)focusAreas[0]->tAlgoAreas[n].nTop,
702                                            (size_t&)focusAreas[0]->tAlgoAreas[n].nLeft,
703                                            (size_t&)focusAreas[0]->tAlgoAreas[n].nWidth,
704                                            (size_t&)focusAreas[0]->tAlgoAreas[n].nHeight);
705
706            focusAreas[0]->tAlgoAreas[n].nLeft =
707                    ( focusAreas[0]->tAlgoAreas[n].nLeft * TOUCH_FOCUS_RANGE ) / mPreviewData->mWidth;
708            focusAreas[0]->tAlgoAreas[n].nTop =
709                    ( focusAreas[0]->tAlgoAreas[n].nTop* TOUCH_FOCUS_RANGE ) / mPreviewData->mHeight;
710            focusAreas[0]->tAlgoAreas[n].nWidth =
711                    ( focusAreas[0]->tAlgoAreas[n].nWidth * TOUCH_FOCUS_RANGE ) / mPreviewData->mWidth;
712            focusAreas[0]->tAlgoAreas[n].nHeight =
713                    ( focusAreas[0]->tAlgoAreas[n].nHeight * TOUCH_FOCUS_RANGE ) / mPreviewData->mHeight;
714            focusAreas[0]->tAlgoAreas[n].nPriority = mFocusAreas.itemAt(n)->getWeight();
715
716             CAMHAL_LOGDB("Focus area %d : top = %d left = %d width = %d height = %d prio = %d",
717                    n, (int)focusAreas[0]->tAlgoAreas[n].nTop, (int)focusAreas[0]->tAlgoAreas[n].nLeft,
718                    (int)focusAreas[0]->tAlgoAreas[n].nWidth, (int)focusAreas[0]->tAlgoAreas[n].nHeight,
719                    (int)focusAreas[0]->tAlgoAreas[n].nPriority);
720             }
721
722        OMX_INIT_STRUCT_PTR (&sharedBuffer, OMX_TI_CONFIG_SHAREDBUFFER);
723
724        sharedBuffer.nPortIndex = OMX_ALL;
725        sharedBuffer.nSharedBuffSize = areasSize;
726        sharedBuffer.pSharedBuff = (OMX_U8 *) focusAreas[0];
727
728        if ( NULL == sharedBuffer.pSharedBuff )
729            {
730            CAMHAL_LOGEA("No resources to allocate OMX shared buffer");
731            ret = -ENOMEM;
732            goto EXIT;
733            }
734
735            eError =  OMX_SetConfig(mCameraAdapterParameters.mHandleComp,
736                                      (OMX_INDEXTYPE) OMX_TI_IndexConfigAlgoAreas, &sharedBuffer);
737
738        if ( OMX_ErrorNone != eError )
739            {
740            CAMHAL_LOGEB("Error while setting Focus Areas configuration 0x%x", eError);
741            ret = -EINVAL;
742            }
743
744    EXIT:
745        if (NULL != focusAreas)
746            {
747            memMgr.freeBuffer((void*) focusAreas);
748            focusAreas = NULL;
749            }
750        }
751
752    LOG_FUNCTION_NAME_EXIT;
753
754    return ret;
755}
756
757};
758