summaryrefslogtreecommitdiffstats
path: root/camera
diff options
context:
space:
mode:
authorTyler Luu <tluu@ti.com>2012-01-31 13:36:22 -0600
committerIliyan Malchev <malchev@google.com>2012-02-01 14:47:16 -0800
commit057f4fd59ec05ded909e9eb9a3363d9ea345b0ca (patch)
tree8687455a958ce799dfb7237f11d70a3c12b28038 /camera
parenta6e104aadf560de4e33291c8e85f79acc8fb46c9 (diff)
downloadhardware_ti_omap4xxx-057f4fd59ec05ded909e9eb9a3363d9ea345b0ca.zip
hardware_ti_omap4xxx-057f4fd59ec05ded909e9eb9a3363d9ea345b0ca.tar.gz
hardware_ti_omap4xxx-057f4fd59ec05ded909e9eb9a3363d9ea345b0ca.tar.bz2
CameraHal: Implementation for CAF status callbacks
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. Signed-off-by: Tyler Luu <tluu@ti.com> Change-Id: I457e67b33b2561dd0b1ce3863ce807a8c27f79f6 Conflicts: camera/OMXCameraAdapter/OMXFocus.cpp
Diffstat (limited to 'camera')
-rw-r--r--camera/AppCallbackNotifier.cpp31
-rw-r--r--camera/BaseCameraAdapter.cpp17
-rw-r--r--camera/CameraHal.cpp26
-rwxr-xr-xcamera/OMXCameraAdapter/OMXCameraAdapter.cpp20
-rw-r--r--camera/OMXCameraAdapter/OMXFocus.cpp77
-rw-r--r--camera/inc/BaseCameraAdapter.h2
-rw-r--r--camera/inc/CameraHal.h10
-rw-r--r--camera/inc/OMXCameraAdapter/OMXCameraAdapter.h4
8 files changed, 141 insertions, 46 deletions
diff --git a/camera/AppCallbackNotifier.cpp b/camera/AppCallbackNotifier.cpp
index 58cb9a7..4489b1f 100644
--- a/camera/AppCallbackNotifier.cpp
+++ b/camera/AppCallbackNotifier.cpp
@@ -353,24 +353,37 @@ void AppCallbackNotifier::notifyEvent()
case CameraHalEvent::EVENT_FOCUS_LOCKED:
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);
}
+ else if ( ( focusEvtData->focusStatus == CameraHalEvent::FOCUS_STATUS_PENDING ) &&
+ ( NULL != mCameraHal ) &&
+ ( NULL != mNotifyCb ) &&
+ ( mCameraHal->msgTypeEnabled(CAMERA_MSG_FOCUS_MOVE) ) )
+ {
+ mNotifyCb(CAMERA_MSG_FOCUS_MOVE, true, 0, mCallbackCookie);
+ }
+ else if ( ( focusEvtData->focusStatus == CameraHalEvent::FOCUS_STATUS_DONE ) &&
+ ( NULL != mCameraHal ) &&
+ ( NULL != mNotifyCb ) &&
+ ( mCameraHal->msgTypeEnabled(CAMERA_MSG_FOCUS_MOVE) ) )
+ {
+ mNotifyCb(CAMERA_MSG_FOCUS_MOVE, false, 0, mCallbackCookie);
+ }
break;
diff --git a/camera/BaseCameraAdapter.cpp b/camera/BaseCameraAdapter.cpp
index 5f86166..a3d8183 100644
--- a/camera/BaseCameraAdapter.cpp
+++ b/camera/BaseCameraAdapter.cpp
@@ -985,7 +985,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;
@@ -999,10 +999,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();
@@ -1011,8 +1013,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++ )
{
@@ -1518,7 +1519,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 c64b7e2..9a158f4 100644
--- a/camera/CameraHal.cpp
+++ b/camera/CameraHal.cpp
@@ -131,9 +131,7 @@ void CameraHal::enableMsgType(int32_t msgType)
// ignoring enable focus message from camera service
// we will enable internally in autoFocus call
- if (msgType & CAMERA_MSG_FOCUS) {
- msgType &= ~CAMERA_MSG_FOCUS;
- }
+ msgType &= ~(CAMERA_MSG_FOCUS | CAMERA_MSG_FOCUS_MOVE);
{
Mutex::Autolock lock(mLock);
@@ -2678,15 +2676,35 @@ 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;
}
+ ///////////////////////////////////////////////////////
+ // Following commands do NOT need preview to be started
+ ///////////////////////////////////////////////////////
+ switch(cmd) {
+ case CAMERA_CMD_ENABLE_FOCUS_MOVE_MSG:
+ bool enable = static_cast<bool>(arg1);
+ Mutex::Autolock lock(mLock);
+ if (enable) {
+ mMsgEnabled |= CAMERA_MSG_FOCUS_MOVE;
+ } else {
+ mMsgEnabled &= ~CAMERA_MSG_FOCUS_MOVE;
+ }
+ return NO_ERROR;
+ break;
+ }
+
if ( ( NO_ERROR == ret ) && ( !previewEnabled() ))
{
CAMHAL_LOGEA("Preview is not running");
ret = -EINVAL;
}
+ ///////////////////////////////////////////////////////
+ // Following commands NEED preview to be started
+ ///////////////////////////////////////////////////////
+
if ( NO_ERROR == ret )
{
switch(cmd)
diff --git a/camera/OMXCameraAdapter/OMXCameraAdapter.cpp b/camera/OMXCameraAdapter/OMXCameraAdapter.cpp
index e6c733d..3d07d5e 100755
--- a/camera/OMXCameraAdapter/OMXCameraAdapter.cpp
+++ b/camera/OMXCameraAdapter/OMXCameraAdapter.cpp
@@ -2694,6 +2694,7 @@ OMX_ERRORTYPE OMXCameraAdapter::SignalEvent(OMX_IN OMX_HANDLETYPE hComponent,
{
Mutex::Autolock lock(mEventLock);
TIUTILS::Message *msg;
+ bool eventSignalled = false;
LOG_FUNCTION_NAME;
@@ -2717,6 +2718,7 @@ OMX_ERRORTYPE OMXCameraAdapter::SignalEvent(OMX_IN OMX_HANDLETYPE hComponent,
//Signal the semaphore provided
sem->Signal();
free(msg);
+ eventSignalled = true;
break;
}
}
@@ -2727,6 +2729,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;
@@ -3364,6 +3379,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 d9d4df4..c99b620 100644
--- a/camera/OMXCameraAdapter/OMXFocus.cpp
+++ b/camera/OMXCameraAdapter/OMXFocus.cpp
@@ -141,8 +141,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);
@@ -165,12 +164,6 @@ status_t OMXCameraAdapter::doAutoFocus()
(OMX_INDEXTYPE)OMX_TI_IndexConfigAutofocusEnable,
&bOMX);
- ret = RegisterForEvent(mCameraAdapterParameters.mHandleComp,
- (OMX_EVENTTYPE) OMX_EventIndexSettingChanged,
- OMX_ALL,
- OMX_IndexConfigCommonFocusStatus,
- mDoAFSem);
-
// force AF, Ducati will take care of whether CAF
// or AF will be performed, depending on light conditions
if ( focusControl.eFocusControl == OMX_IMAGE_FocusControlAuto
@@ -200,19 +193,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 {
ret = returnFocusStatus(false);
}
@@ -401,7 +389,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);
@@ -436,7 +424,7 @@ status_t OMXCameraAdapter::returnFocusStatus(bool timeoutReached)
if ( timeoutReached )
{
- focusStatus = false;
+ focusStatus = CameraHalEvent::FOCUS_STATUS_FAIL;
}
else
{
@@ -444,7 +432,7 @@ status_t OMXCameraAdapter::returnFocusStatus(bool timeoutReached)
{
case OMX_FocusStatusReached:
{
- focusStatus = true;
+ focusStatus = CameraHalEvent::FOCUS_STATUS_SUCCESS;
break;
}
case OMX_FocusStatusOff:
@@ -452,7 +440,7 @@ status_t OMXCameraAdapter::returnFocusStatus(bool timeoutReached)
case OMX_FocusStatusRequest:
default:
{
- focusStatus = false;
+ focusStatus = CameraHalEvent::FOCUS_STATUS_FAIL;
break;
}
}
@@ -520,7 +508,6 @@ status_t OMXCameraAdapter::checkFocus(OMX_PARAM_FOCUSSTATUSTYPE *eFocusStatus)
if ( NO_ERROR == ret )
{
OMX_INIT_STRUCT_PTR (eFocusStatus, OMX_PARAM_FOCUSSTATUSTYPE);
-
eError = OMX_GetConfig(mCameraAdapterParameters.mHandleComp,
OMX_IndexConfigCommonFocusStatus,
eFocusStatus);
@@ -800,4 +787,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 d778491..bc38e00 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 e7ea9c8..8b8392a 100644
--- a/camera/inc/CameraHal.h
+++ b/camera/inc/CameraHal.h
@@ -331,6 +331,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
@@ -341,8 +348,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 4786f82..2ab0b25 100644
--- a/camera/inc/OMXCameraAdapter/OMXCameraAdapter.h
+++ b/camera/inc/OMXCameraAdapter/OMXCameraAdapter.h
@@ -455,6 +455,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
@@ -670,7 +671,7 @@ private:
COMMAND_EXIT = -1,
CAMERA_START_IMAGE_CAPTURE = 0,
CAMERA_PERFORM_AUTOFOCUS = 1,
- CAMERA_SWITCH_TO_EXECUTING
+ CAMERA_SWITCH_TO_EXECUTING,
};
private:
@@ -708,6 +709,7 @@ public:
enum {
COMMAND_EXIT = -1,
CAMERA_FILL_BUFFER_DONE,
+ CAMERA_FOCUS_STATUS,
};
private: