fix: focus lock policy
This commit is contained in:
1 parent
cedd8a1fa3
commit
d91a4bbacc
3 files changed
+109
No files matched your search
@@ -5931,6 +5931,29 @@ class Camera2Controller(private val context: Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if (MultiFrameFocusLockPolicy.canFreezeSettledContinuousFocus(
|
||||
afMode = currentAfMode,
|
||||
afState = afState,
|
||||
lensState = lensState,
|
||||
focusDistanceDiopters = focusDistance,
|
||||
supportsAfOff = availableAfModes.contains(CaptureRequest.CONTROL_AF_MODE_OFF),
|
||||
)
|
||||
) {
|
||||
activeMultiFrameFocusSnapshot = createMultiFrameFocusSnapshot(
|
||||
result = baseResult,
|
||||
fallbackAfMode = currentAfMode,
|
||||
source = "settled_continuous_af",
|
||||
).copy(afMode = CaptureRequest.CONTROL_AF_MODE_OFF)
|
||||
PLog.i(
|
||||
TAG,
|
||||
"Multi-frame focus froze settled continuous AF without retrigger: " +
|
||||
"previousMode=$currentAfMode fixedMode=${CaptureRequest.CONTROL_AF_MODE_OFF} " +
|
||||
"afState=$afState lensState=$lensState focus=$focusDistance",
|
||||
)
|
||||
continueCaptureAfterFocusPreparation(device, reader, baseResult)
|
||||
return
|
||||
}
|
||||
|
||||
val generation = ++multiFrameFocusGeneration
|
||||
val pending = PendingMultiFrameFocusCapture(
|
||||
generation = generation,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.hinnka.mycamera.camera
|
||||
|
||||
import android.hardware.camera2.CaptureRequest
|
||||
import android.hardware.camera2.CaptureResult
|
||||
|
||||
/**
|
||||
@@ -13,4 +14,27 @@ internal object MultiFrameFocusLockPolicy {
|
||||
val lensStationary = lensState == null || lensState == CaptureResult.LENS_STATE_STATIONARY
|
||||
return afLocked && lensStationary
|
||||
}
|
||||
|
||||
/**
|
||||
* Continuous AF has already completed an attempt in either passive terminal state. When the
|
||||
* current lens position can be carried into an AF-off still request, another AF trigger only
|
||||
* adds shutter lag and can restart focus hunting without improving the captured focus plane.
|
||||
*/
|
||||
fun canFreezeSettledContinuousFocus(
|
||||
afMode: Int,
|
||||
afState: Int?,
|
||||
lensState: Int?,
|
||||
focusDistanceDiopters: Float?,
|
||||
supportsAfOff: Boolean,
|
||||
): Boolean {
|
||||
val continuousAf = afMode == CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE ||
|
||||
afMode == CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_VIDEO
|
||||
val passiveAttemptFinished = afState == CaptureResult.CONTROL_AF_STATE_PASSIVE_FOCUSED ||
|
||||
afState == CaptureResult.CONTROL_AF_STATE_PASSIVE_UNFOCUSED
|
||||
val lensStationary = lensState == null || lensState == CaptureResult.LENS_STATE_STATIONARY
|
||||
val hasReusableFocusDistance = focusDistanceDiopters != null &&
|
||||
focusDistanceDiopters.isFinite() && focusDistanceDiopters >= 0f
|
||||
return continuousAf && passiveAttemptFinished && lensStationary &&
|
||||
hasReusableFocusDistance && supportsAfOff
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.hinnka.mycamera.camera
|
||||
|
||||
import android.hardware.camera2.CaptureRequest
|
||||
import android.hardware.camera2.CaptureResult
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
@@ -55,4 +56,65 @@ class MultiFrameFocusLockPolicyTest {
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun settledPassiveUnfocusedCanBeFrozenInsteadOfRetriggered() {
|
||||
assertTrue(
|
||||
MultiFrameFocusLockPolicy.canFreezeSettledContinuousFocus(
|
||||
afMode = CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE,
|
||||
afState = CaptureResult.CONTROL_AF_STATE_PASSIVE_UNFOCUSED,
|
||||
lensState = CaptureResult.LENS_STATE_STATIONARY,
|
||||
focusDistanceDiopters = 7.181988f,
|
||||
supportsAfOff = true,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun settledPassiveFocusedCanBeFrozenInsteadOfRetriggered() {
|
||||
assertTrue(
|
||||
MultiFrameFocusLockPolicy.canFreezeSettledContinuousFocus(
|
||||
afMode = CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_VIDEO,
|
||||
afState = CaptureResult.CONTROL_AF_STATE_PASSIVE_FOCUSED,
|
||||
lensState = null,
|
||||
focusDistanceDiopters = 0f,
|
||||
supportsAfOff = true,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun passiveScanMustStillWaitForFocus() {
|
||||
assertFalse(
|
||||
MultiFrameFocusLockPolicy.canFreezeSettledContinuousFocus(
|
||||
afMode = CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE,
|
||||
afState = CaptureResult.CONTROL_AF_STATE_PASSIVE_SCAN,
|
||||
lensState = CaptureResult.LENS_STATE_STATIONARY,
|
||||
focusDistanceDiopters = 7.181988f,
|
||||
supportsAfOff = true,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun settledContinuousFocusNeedsReusableManualFocusControl() {
|
||||
assertFalse(
|
||||
MultiFrameFocusLockPolicy.canFreezeSettledContinuousFocus(
|
||||
afMode = CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE,
|
||||
afState = CaptureResult.CONTROL_AF_STATE_PASSIVE_UNFOCUSED,
|
||||
lensState = CaptureResult.LENS_STATE_STATIONARY,
|
||||
focusDistanceDiopters = 7.181988f,
|
||||
supportsAfOff = false,
|
||||
),
|
||||
)
|
||||
assertFalse(
|
||||
MultiFrameFocusLockPolicy.canFreezeSettledContinuousFocus(
|
||||
afMode = CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE,
|
||||
afState = CaptureResult.CONTROL_AF_STATE_PASSIVE_UNFOCUSED,
|
||||
lensState = CaptureResult.LENS_STATE_STATIONARY,
|
||||
focusDistanceDiopters = null,
|
||||
supportsAfOff = true,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user