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