hardware: samsung_slsi: libcamera2: Modified CAF Algorithm
authorSungjoong Kang <sj3.kang@samsung.com>
Fri, 24 Aug 2012 00:38:20 +0000 (17:38 -0700)
committerRebecca Schultz Zavin <rebecca@android.com>
Tue, 28 Aug 2012 16:41:08 +0000 (09:41 -0700)
Modified CAF Algorithm and fixed lockup during operation.

Change-Id: I313171d13414825d3bce1e12c1b123a1922b2296
Signed-off-by: Sungjoong Kang <sj3.kang@samsung.com>
libcamera2/ExynosCameraHWInterface2.cpp
libcamera2/ExynosCameraHWInterface2.h

index d7202f672b1f73f202d2a12b08eafbc773677183..5cc6c698398ba404b19c153bad3caf61da762423 100644 (file)
@@ -2321,6 +2321,7 @@ void ExynosCameraHWInterface2::m_sensorThreadFunc(SignalDrivenThread * self)
         if (matchedFrameCnt != -1) {
                 frameTime = systemTime();
         m_requestManager->RegisterTimestamp(matchedFrameCnt, &frameTime);
+            m_requestManager->UpdateIspParameters(shot_ext, matchedFrameCnt, false);
             if (m_IsAfModeUpdateRequired) {
                 ALOGE("### AF Mode change(Mode %d) ", m_afMode);
                 shot_ext->shot.ctl.aa.afMode = m_afMode;
@@ -2342,16 +2343,19 @@ void ExynosCameraHWInterface2::m_sensorThreadFunc(SignalDrivenThread * self)
             }
             if (m_IsAfTriggerRequired) {
                 ALOGE("### AF Triggering with mode (%d)", m_afMode);
-                if (m_afState != HAL_AFSTATE_NEEDS_COMMAND)
-                    ALOGE("(%s): wrong trigger state %d", __FUNCTION__, m_afState);
-                else
-                    m_afState = HAL_AFSTATE_STARTED;
-                m_requestManager->UpdateIspParameters(shot_ext, matchedFrameCnt, true);
+                if (m_afState == HAL_AFSTATE_SCANNING) {
+                     ALOGE("(%s): restarting trigger ", __FUNCTION__);
+                }
+                else {
+                    if (m_afState != HAL_AFSTATE_NEEDS_COMMAND)
+                        ALOGE("(%s): wrong trigger state %d", __FUNCTION__, m_afState);
+                    else
+                        m_afState = HAL_AFSTATE_STARTED;
+                }
                 shot_ext->shot.ctl.aa.afMode = m_afMode;
                 m_IsAfTriggerRequired = false;
             }
             else {
-                m_requestManager->UpdateIspParameters(shot_ext, matchedFrameCnt, false);
             }
             if (m_wideAspect) {
 //                shot_ext->setfile = ISS_SUB_SCENARIO_VIDEO;
@@ -3221,17 +3225,28 @@ void ExynosCameraHWInterface2::OnAfTriggerCAFPicture(int id)
         break;
     case HAL_AFSTATE_STARTED:
         nextState = HAL_AFSTATE_NEEDS_DETERMINATION;
+        m_AfHwStateFailed = false;
         break;
     case HAL_AFSTATE_SCANNING:
         nextState = HAL_AFSTATE_NEEDS_DETERMINATION;
+        m_AfHwStateFailed = false;
         break;
     case HAL_AFSTATE_NEEDS_DETERMINATION:
         nextState = NO_TRANSITION;
         break;
     case HAL_AFSTATE_PASSIVE_FOCUSED:
         m_IsAfLockRequired = true;
-        SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED);
-        nextState = HAL_AFSTATE_LOCKED;
+        if (m_AfHwStateFailed) {
+            ALOGV("(%s): LAST : fail", __FUNCTION__);
+            SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
+            nextState = HAL_AFSTATE_FAILED;
+        }
+        else {
+            ALOGV("(%s): LAST : success", __FUNCTION__);
+            SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED);
+            nextState = HAL_AFSTATE_LOCKED;
+        }
+        m_AfHwStateFailed = false;
         break;
     case HAL_AFSTATE_LOCKED:
         nextState = NO_TRANSITION;
@@ -3449,17 +3464,21 @@ void ExynosCameraHWInterface2::OnAfNotificationCAFPicture(enum aa_afstate noti)
     else if (m_afState == HAL_AFSTATE_SCANNING) {
         switch (noti) {
         case AA_AFSTATE_INACTIVE:
-            bWrongTransition = true;
+            nextState = NO_TRANSITION;
             break;
         case AA_AFSTATE_ACTIVE_SCAN:
             nextState = NO_TRANSITION;
+            m_AfHwStateFailed = false;
             break;
         case AA_AFSTATE_AF_ACQUIRED_FOCUS:
             nextState = HAL_AFSTATE_PASSIVE_FOCUSED;
+            m_AfHwStateFailed = false;
             SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED);
             break;
         case AA_AFSTATE_AF_FAILED_FOCUS:
-            nextState = NO_TRANSITION;
+            nextState = HAL_AFSTATE_PASSIVE_FOCUSED;
+            m_AfHwStateFailed = true;
+            SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED);
             break;
         default:
             bWrongTransition = true;
@@ -3469,18 +3488,20 @@ void ExynosCameraHWInterface2::OnAfNotificationCAFPicture(enum aa_afstate noti)
     else if (m_afState == HAL_AFSTATE_PASSIVE_FOCUSED) {
         switch (noti) {
         case AA_AFSTATE_INACTIVE:
-            bWrongTransition = true;
+            nextState = NO_TRANSITION;
             break;
         case AA_AFSTATE_ACTIVE_SCAN:
             nextState = HAL_AFSTATE_SCANNING;
+            m_AfHwStateFailed = false;
             SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN);
             break;
         case AA_AFSTATE_AF_ACQUIRED_FOCUS:
             nextState = NO_TRANSITION;
+            m_AfHwStateFailed = false;
             break;
         case AA_AFSTATE_AF_FAILED_FOCUS:
-            nextState = HAL_AFSTATE_FAILED;
-            SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
+            nextState = NO_TRANSITION;
+            m_AfHwStateFailed = true;
             break;
         default:
             bWrongTransition = true;
@@ -3490,7 +3511,7 @@ void ExynosCameraHWInterface2::OnAfNotificationCAFPicture(enum aa_afstate noti)
     else if (m_afState == HAL_AFSTATE_NEEDS_DETERMINATION) {
         switch (noti) {
         case AA_AFSTATE_INACTIVE:
-            bWrongTransition = true;
+            nextState = NO_TRANSITION;
             break;
         case AA_AFSTATE_ACTIVE_SCAN:
             nextState = NO_TRANSITION;
@@ -3530,7 +3551,11 @@ void ExynosCameraHWInterface2::OnAfNotificationCAFPicture(enum aa_afstate noti)
     else if (m_afState == HAL_AFSTATE_FAILED) {
         switch (noti) {
             case AA_AFSTATE_INACTIVE:
+                bWrongTransition = true;
+                break;
             case AA_AFSTATE_ACTIVE_SCAN:
+                nextState = HAL_AFSTATE_SCANNING;
+                break;
             case AA_AFSTATE_AF_ACQUIRED_FOCUS:
                 bWrongTransition = true;
                 break;
@@ -3603,6 +3628,7 @@ void ExynosCameraHWInterface2::OnAfNotificationCAFVideo(enum aa_afstate noti)
             break;
         case AA_AFSTATE_AF_FAILED_FOCUS:
             nextState = NO_TRANSITION;
+            m_IsAfTriggerRequired = true;
             break;
         default:
             bWrongTransition = true;
index 88ce630d1448e8d06e4b218aac8195f2ed3dd6eb..9328486f4d4b5ed56483b7d31614920edb26c636 100644 (file)
@@ -547,6 +547,7 @@ class MainThread : public SignalDrivenThread {
     bool                                m_IsAfTriggerRequired;
     bool                                m_IsAfLockRequired;
     int                                 m_serviceAfState;
+    bool                                m_AfHwStateFailed;
     struct camera2_shot                 m_jpegMetadata;
 };