diff options
author | Pavel Nedev <pnedev@mm-sol.com> | 2012-02-21 16:49:55 +0200 |
---|---|---|
committer | Daniel Levin <dendy@ti.com> | 2012-07-25 08:55:42 -0500 |
commit | fd797018180a61b82ead3347b55eca6591f6b6da (patch) | |
tree | 1301afc59a6d955739ebbd215b916f573827ff14 | |
parent | 63484b3b44b591f8de9f625aa5d61059b27c616c (diff) | |
download | hardware_ti_omap4-fd797018180a61b82ead3347b55eca6591f6b6da.zip hardware_ti_omap4-fd797018180a61b82ead3347b55eca6591f6b6da.tar.gz hardware_ti_omap4-fd797018180a61b82ead3347b55eca6591f6b6da.tar.bz2 |
CameraHal: Implementation for CAF status callbacks
Author: Tyler Luu <tluu@ti.com>
1. Remove internal handling of CAMERA_MSG_FOCUS. Before we were
enabling CAMERA_MSG_FOCUS only when application calls autoFocus().
No longer needed since the CAMERA_MSG_FOCUS can come just during
preview now.
2. Add handling of unregistered focus callbacks. Since OMXCamera
will send callbacks even when we are not waiting for one, add some
handling.
Change-Id: I70842a0b8f004873d728ff178ae3a4db12060a7c
Signed-off-by: Tyler Luu <tluu@ti.com>
-rw-r--r-- | camera/AppCallbackNotifier.cpp | 21 | ||||
-rw-r--r-- | camera/BaseCameraAdapter.cpp | 17 | ||||
-rw-r--r-- | camera/CameraHal.cpp | 2 | ||||
-rw-r--r-- | camera/OMXCameraAdapter/OMXCameraAdapter.cpp | 19 | ||||
-rw-r--r-- | camera/OMXCameraAdapter/OMXFocus.cpp | 80 | ||||
-rw-r--r-- | camera/inc/BaseCameraAdapter.h | 2 | ||||
-rw-r--r-- | camera/inc/CameraHal.h | 10 | ||||
-rw-r--r-- | camera/inc/OMXCameraAdapter/OMXCameraAdapter.h | 2 |
8 files changed, 106 insertions, 47 deletions
diff --git a/camera/AppCallbackNotifier.cpp b/camera/AppCallbackNotifier.cpp index b2e0e6f..540e69b 100644 --- a/camera/AppCallbackNotifier.cpp +++ b/camera/AppCallbackNotifier.cpp @@ -364,22 +364,19 @@ void AppCallbackNotifier::notifyEvent() case CameraHalEvent::EVENT_FOCUS_ERROR: focusEvtData = &evt->mEventData->focusEvent; - if ( ( focusEvtData->focusLocked ) && - ( NULL != mCameraHal ) && - ( NULL != mNotifyCb ) && - ( mCameraHal->msgTypeEnabled(CAMERA_MSG_FOCUS) ) ) - { + if ( ( focusEvtData->focusStatus == CameraHalEvent::FOCUS_STATUS_SUCCESS ) && + ( NULL != mCameraHal ) && + ( NULL != mNotifyCb ) && + ( mCameraHal->msgTypeEnabled(CAMERA_MSG_FOCUS) ) ) { mCameraHal->disableMsgType(CAMERA_MSG_FOCUS); mNotifyCb(CAMERA_MSG_FOCUS, true, 0, mCallbackCookie); - } - else if ( focusEvtData->focusError && - ( NULL != mCameraHal ) && - ( NULL != mNotifyCb ) && - ( mCameraHal->msgTypeEnabled(CAMERA_MSG_FOCUS) ) ) - { + } else if ( ( focusEvtData->focusStatus == CameraHalEvent::FOCUS_STATUS_FAIL ) && + ( NULL != mCameraHal ) && + ( NULL != mNotifyCb ) && + ( mCameraHal->msgTypeEnabled(CAMERA_MSG_FOCUS) ) ) { mCameraHal->disableMsgType(CAMERA_MSG_FOCUS); mNotifyCb(CAMERA_MSG_FOCUS, false, 0, mCallbackCookie); - } + } break; diff --git a/camera/BaseCameraAdapter.cpp b/camera/BaseCameraAdapter.cpp index df2812d..571e777 100644 --- a/camera/BaseCameraAdapter.cpp +++ b/camera/BaseCameraAdapter.cpp @@ -1026,7 +1026,7 @@ status_t BaseCameraAdapter::sendCommand(CameraCommands operation, int value1, in return ret; } -status_t BaseCameraAdapter::notifyFocusSubscribers(bool status) +status_t BaseCameraAdapter::notifyFocusSubscribers(CameraHalEvent::FocusStatus status) { event_callback eventCb; CameraHalEvent focusEvent; @@ -1040,10 +1040,12 @@ status_t BaseCameraAdapter::notifyFocusSubscribers(bool status) } #if PPM_INSTRUMENTATION || PPM_INSTRUMENTATION_ABS - - //dump the AF latency - CameraHal::PPM("Focus finished in: ", &mStartFocus); - + if (status == CameraHalEvent::FOCUS_STATUS_PENDING) { + gettimeofday(&mStartFocus, NULL); + } else { + //dump the AF latency + CameraHal::PPM("Focus finished in: ", &mStartFocus); + } #endif focusEvent.mEventData = new CameraHalEvent::CameraHalEventData(); @@ -1052,8 +1054,7 @@ status_t BaseCameraAdapter::notifyFocusSubscribers(bool status) } focusEvent.mEventType = CameraHalEvent::EVENT_FOCUS_LOCKED; - focusEvent.mEventData->focusEvent.focusLocked = status; - focusEvent.mEventData->focusEvent.focusError = !status; + focusEvent.mEventData->focusEvent.focusStatus = status; for (unsigned int i = 0 ; i < mFocusSubscribers.size(); i++ ) { @@ -1559,7 +1560,7 @@ status_t BaseCameraAdapter::autoFocus() LOG_FUNCTION_NAME; - notifyFocusSubscribers(false); + notifyFocusSubscribers(CameraHalEvent::FOCUS_STATUS_FAIL); LOG_FUNCTION_NAME_EXIT; diff --git a/camera/CameraHal.cpp b/camera/CameraHal.cpp index 1359114..6735e7b 100644 --- a/camera/CameraHal.cpp +++ b/camera/CameraHal.cpp @@ -2860,7 +2860,7 @@ status_t CameraHal::sendCommand(int32_t cmd, int32_t arg1, int32_t arg2) if ( ( NO_ERROR == ret ) && ( NULL == mCameraAdapter ) ) { CAMHAL_LOGEA("No CameraAdapter instance"); - ret = -EINVAL; + return -EINVAL; } if ( ( NO_ERROR == ret ) && ( !previewEnabled() )) diff --git a/camera/OMXCameraAdapter/OMXCameraAdapter.cpp b/camera/OMXCameraAdapter/OMXCameraAdapter.cpp index df6140d..7825e00 100644 --- a/camera/OMXCameraAdapter/OMXCameraAdapter.cpp +++ b/camera/OMXCameraAdapter/OMXCameraAdapter.cpp @@ -2796,6 +2796,7 @@ OMX_ERRORTYPE OMXCameraAdapter::SignalEvent(OMX_IN OMX_HANDLETYPE hComponent, { Mutex::Autolock lock(mEventLock); TIUTILS::Message *msg; + bool eventSignalled = false; LOG_FUNCTION_NAME; @@ -2829,6 +2830,19 @@ OMX_ERRORTYPE OMXCameraAdapter::SignalEvent(OMX_IN OMX_HANDLETYPE hComponent, CAMHAL_LOGDA("Event queue empty!!!"); } + // Special handling for any unregistered events + if (!eventSignalled) { + // Handling for focus callback + if ((nData2 == OMX_IndexConfigCommonFocusStatus) && + (eEvent == (OMX_EVENTTYPE) OMX_EventIndexSettingChanged)) { + TIUTILS::Message msg; + msg.command = OMXCallbackHandler::CAMERA_FOCUS_STATUS; + msg.arg1 = NULL; + msg.arg2 = NULL; + mOMXCallbackHandler->put(&msg); + } + } + LOG_FUNCTION_NAME_EXIT; return OMX_ErrorNone; @@ -3435,6 +3449,11 @@ bool OMXCameraAdapter::OMXCallbackHandler::Handler() ( OMX_BUFFERHEADERTYPE *) msg.arg2); break; } + case OMXCallbackHandler::CAMERA_FOCUS_STATUS: + { + mCameraAdapter->handleFocusCallback(); + break; + } case CommandHandler::COMMAND_EXIT: { CAMHAL_LOGDA("Exiting OMX callback handler"); diff --git a/camera/OMXCameraAdapter/OMXFocus.cpp b/camera/OMXCameraAdapter/OMXFocus.cpp index 44965c8..140e5b6 100644 --- a/camera/OMXCameraAdapter/OMXFocus.cpp +++ b/camera/OMXCameraAdapter/OMXFocus.cpp @@ -147,8 +147,7 @@ status_t OMXCameraAdapter::doAutoFocus() } else if ( mParameters3A.Focus == OMX_IMAGE_FocusControlAuto ) { // In case we have CAF running we should first check the AF status. // If it has managed to lock, then do as usual and return status - // immediately. If lock is not available, then switch temporarily - // to 'autolock' and do normal AF. + // immediately. ret = checkFocus(&focusStatus); if ( NO_ERROR != ret ) { CAMHAL_LOGEB("Focus status check failed 0x%x!", ret); @@ -170,15 +169,7 @@ status_t OMXCameraAdapter::doAutoFocus() (OMX_INDEXTYPE)OMX_TI_IndexConfigAutofocusEnable, &bOMX); - ret = RegisterForEvent(mCameraAdapterParameters.mHandleComp, - (OMX_EVENTTYPE) OMX_EventIndexSettingChanged, - OMX_ALL, - OMX_IndexConfigCommonFocusStatus, - mDoAFSem); - - if ( NO_ERROR == ret ) { - ret = setFocusCallback(true); - } + ret = setFocusCallback(true); eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp, OMX_IndexConfigFocusControl, @@ -198,19 +189,14 @@ status_t OMXCameraAdapter::doAutoFocus() //If somethiing bad happened while we wait if (mComponentState == OMX_StateInvalid) { CAMHAL_LOGEA("Invalid State after Auto Focus Exitting!!!"); - return EINVAL; + return -EINVAL; } - if( ret != NO_ERROR) { + if(ret != NO_ERROR) { //Disable auto focus callback from Ducati setFocusCallback(false); CAMHAL_LOGEA("Autofocus callback timeout expired"); - RemoveEvent(mCameraAdapterParameters.mHandleComp, - (OMX_EVENTTYPE) OMX_EventIndexSettingChanged, - OMX_ALL, - OMX_IndexConfigCommonFocusStatus, - NULL ); - returnFocusStatus(true); + ret = returnFocusStatus(true); } else { CAMHAL_LOGDA("Autofocus callback received"); //Disable auto focus callback from Ducati @@ -408,7 +394,7 @@ status_t OMXCameraAdapter::returnFocusStatus(bool timeoutReached) { status_t ret = NO_ERROR; OMX_PARAM_FOCUSSTATUSTYPE eFocusStatus; - bool focusStatus = false; + CameraHalEvent::FocusStatus focusStatus = CameraHalEvent::FOCUS_STATUS_FAIL; BaseCameraAdapter::AdapterState state, nextState; BaseCameraAdapter::getState(state); BaseCameraAdapter::getNextState(nextState); @@ -443,7 +429,7 @@ status_t OMXCameraAdapter::returnFocusStatus(bool timeoutReached) if ( timeoutReached ) { - focusStatus = false; + focusStatus = CameraHalEvent::FOCUS_STATUS_FAIL; } else { @@ -451,7 +437,7 @@ status_t OMXCameraAdapter::returnFocusStatus(bool timeoutReached) { case OMX_FocusStatusReached: { - focusStatus = true; + focusStatus = CameraHalEvent::FOCUS_STATUS_SUCCESS; break; } case OMX_FocusStatusOff: @@ -459,7 +445,7 @@ status_t OMXCameraAdapter::returnFocusStatus(bool timeoutReached) case OMX_FocusStatusRequest: default: { - focusStatus = false; + focusStatus = CameraHalEvent::FOCUS_STATUS_FAIL; break; } } @@ -816,4 +802,52 @@ status_t OMXCameraAdapter::setTouchFocus() return ret; } +void OMXCameraAdapter::handleFocusCallback() { + OMX_PARAM_FOCUSSTATUSTYPE eFocusStatus; + CameraHalEvent::FocusStatus focusStatus = CameraHalEvent::FOCUS_STATUS_FAIL; + status_t ret = NO_ERROR; + BaseCameraAdapter::AdapterState nextState; + BaseCameraAdapter::getNextState(nextState); + + OMX_INIT_STRUCT(eFocusStatus, OMX_PARAM_FOCUSSTATUSTYPE); + + ret = checkFocus(&eFocusStatus); + + if (NO_ERROR != ret) { + CAMHAL_LOGEA("Focus status check failed!"); + // signal and unblock doAutoFocus + if (AF_ACTIVE & nextState) { + mDoAFSem.Signal(); + } + return; + } else if (AF_ACTIVE & nextState) { // Handling for AF callback + // signal doAutoFocus when a end of scan message comes + // ignore start of scan + if (eFocusStatus.eFocusStatus != OMX_FocusStatusRequest) { + mDoAFSem.Signal(); + } + return; + } + + if (mParameters3A.Focus != (OMX_IMAGE_FOCUSCONTROLTYPE) OMX_IMAGE_FocusControlAuto) { + CAMHAL_LOGDA("unregistered focus callback when not in CAF or doAutoFocus... not handling"); + return; + } + + // Handling for CAF Callbacks + switch (eFocusStatus.eFocusStatus) { + case OMX_FocusStatusRequest: + focusStatus = CameraHalEvent::FOCUS_STATUS_PENDING; + break; + case OMX_FocusStatusReached: + case OMX_FocusStatusOff: + case OMX_FocusStatusUnableToReach: + default: + focusStatus = CameraHalEvent::FOCUS_STATUS_DONE; + break; + } + + notifyFocusSubscribers(focusStatus); +} + }; diff --git a/camera/inc/BaseCameraAdapter.h b/camera/inc/BaseCameraAdapter.h index b358427..119e1a5 100644 --- a/camera/inc/BaseCameraAdapter.h +++ b/camera/inc/BaseCameraAdapter.h @@ -145,7 +145,7 @@ protected: // ---------------------Interface ends----------------------------------- - status_t notifyFocusSubscribers(bool status); + status_t notifyFocusSubscribers(CameraHalEvent::FocusStatus status); status_t notifyShutterSubscribers(); status_t notifyZoomSubscribers(int zoomIdx, bool targetReached); status_t notifyFaceSubscribers(sp<CameraFDResult> &faces); diff --git a/camera/inc/CameraHal.h b/camera/inc/CameraHal.h index a4f02b0..d4c6357 100644 --- a/camera/inc/CameraHal.h +++ b/camera/inc/CameraHal.h @@ -333,6 +333,13 @@ public: ALL_EVENTS = 0xFFFF ///Maximum of 16 event types supported }; + enum FocusStatus { + FOCUS_STATUS_SUCCESS = 0x1, + FOCUS_STATUS_FAIL = 0x2, + FOCUS_STATUS_PENDING = 0x4, + FOCUS_STATUS_DONE = 0x8, + }; + ///Class declarations ///@remarks Add a new class for a new event type added above @@ -343,8 +350,7 @@ public: ///Focus event specific data typedef struct FocusEventData_t { - bool focusLocked; - bool focusError; + FocusStatus focusStatus; int currentFocusValue; } FocusEventData; diff --git a/camera/inc/OMXCameraAdapter/OMXCameraAdapter.h b/camera/inc/OMXCameraAdapter/OMXCameraAdapter.h index a48c240..7895c2f 100644 --- a/camera/inc/OMXCameraAdapter/OMXCameraAdapter.h +++ b/camera/inc/OMXCameraAdapter/OMXCameraAdapter.h @@ -468,6 +468,7 @@ private: status_t checkFocus(OMX_PARAM_FOCUSSTATUSTYPE *eFocusStatus); status_t returnFocusStatus(bool timeoutReached); status_t getFocusMode(OMX_IMAGE_CONFIG_FOCUSCONTROLTYPE &focusMode); + void handleFocusCallback(); //Focus distances @@ -765,6 +766,7 @@ public: enum { COMMAND_EXIT = -1, CAMERA_FILL_BUFFER_DONE, + CAMERA_FOCUS_STATUS }; private: |