public class AutoFocusStateMachine extends Object
Requests are created only when the AF needs to be manipulated from the user, but automatic camera-caused AF state changes are broadcasted from any new result.
Modifier and Type | Class and Description |
---|---|
static interface |
AutoFocusStateMachine.AutoFocusStateListener
Observe state AF state transitions triggered by
onCaptureCompleted . |
Constructor and Description |
---|
AutoFocusStateMachine(AutoFocusStateMachine.AutoFocusStateListener listener) |
Modifier and Type | Method and Description |
---|---|
void |
lockAutoFocus(CaptureRequest.Builder repeatingBuilder,
CaptureRequest.Builder requestBuilder)
Lock the lens from moving.
|
void |
onCaptureCompleted(CaptureResult result)
Invoke every time we get a new CaptureResult via
CameraDevice.CaptureCallback#onCaptureCompleted . |
void |
resetState()
Reset the current AF state.
|
void |
setActiveAutoFocus(CaptureRequest.Builder repeatingBuilder,
CaptureRequest.Builder requestBuilder)
Enable active auto focus, immediately triggering a converging scan.
|
void |
setPassiveAutoFocus(boolean picture,
CaptureRequest.Builder repeatingBuilder)
Enable passive autofocus, immediately triggering a non-converging scan.
|
void |
unlockAutoFocus(CaptureRequest.Builder repeatingBuilder,
CaptureRequest.Builder requestBuilder)
Unlock the lens, allowing it to move again.
|
void |
updateCaptureRequest(CaptureRequest.Builder repeatingBuilder)
Update the repeating request with current focus mode.
|
public AutoFocusStateMachine(AutoFocusStateMachine.AutoFocusStateListener listener)
public void onCaptureCompleted(CaptureResult result)
CameraDevice.CaptureCallback#onCaptureCompleted
.
This function is responsible for dispatching updates via the
AutoFocusStateMachine.AutoFocusStateListener
so without calling this on a regular basis, no
AF changes will be observed.
result
- CaptureResultpublic void resetState()
When dropping capture results (by not invoking onCaptureCompleted(android.hardware.camera2.CaptureResult)
when a new
CaptureResult
is available), call this function to reset the state. Otherwise
the next time a new state is observed this class may incorrectly consider it as the same
state as before, and not issue any callbacks by AutoFocusStateMachine.AutoFocusStateListener
.
public void lockAutoFocus(CaptureRequest.Builder repeatingBuilder, CaptureRequest.Builder requestBuilder)
After calling this function, submit the new requestBuilder as a separate capture. Do not submit it as a repeating request or the AF lock will be repeated every time.
Create a new repeating request from repeatingBuilder and set that as the updated repeating request.
If the lock succeeds, AutoFocusStateMachine.AutoFocusStateListener.onAutoFocusSuccess(android.hardware.camera2.CaptureResult, boolean)
with
locked == true
will be invoked. If the lock fails,
AutoFocusStateMachine.AutoFocusStateListener.onAutoFocusFail(android.hardware.camera2.CaptureResult, boolean)
with scanning == false
will be
invoked.
repeatingBuilder
- Builder for a repeating request.requestBuilder
- Builder for a non-repeating request.public void unlockAutoFocus(CaptureRequest.Builder repeatingBuilder, CaptureRequest.Builder requestBuilder)
After calling this function, submit the new requestBuilder as a separate capture. Do not submit it as a repeating request or the AF lock will be repeated every time.
Create a new repeating request from repeatingBuilder and set that as the updated repeating request.
Once the unlock takes effect, AutoFocusStateMachine.AutoFocusStateListener.onAutoFocusInactive(android.hardware.camera2.CaptureResult)
is
invoked, and after that the effects depend on which mode you were in:
AutoFocusStateMachine.AutoFocusStateListener.onAutoFocusScan(android.hardware.camera2.CaptureResult)
repeatingBuilder
- Builder for a repeating request.requestBuilder
- Builder for a non-repeating request.public void setActiveAutoFocus(CaptureRequest.Builder repeatingBuilder, CaptureRequest.Builder requestBuilder)
This is typically only used when locking the passive AF has failed.
Once active AF scanning starts, AutoFocusStateMachine.AutoFocusStateListener.onAutoFocusScan(android.hardware.camera2.CaptureResult)
will be
invoked.
If the active scan succeeds, AutoFocusStateMachine.AutoFocusStateListener.onAutoFocusSuccess(android.hardware.camera2.CaptureResult, boolean)
with
locked == true
will be invoked. If the active scan fails,
AutoFocusStateMachine.AutoFocusStateListener.onAutoFocusFail(android.hardware.camera2.CaptureResult, boolean)
with scanning == false
will be
invoked.
After calling this function, submit the new requestBuilder as a separate capture. Do not submit it as a repeating request or the AF trigger will be repeated every time.
Create a new repeating request from repeatingBuilder and set that as the updated repeating request.
repeatingBuilder
- Builder for a repeating request.requestBuilder
- Builder for a non-repeating request.repeatingBuilder
- Builder for a repeating request.public void setPassiveAutoFocus(boolean picture, CaptureRequest.Builder repeatingBuilder)
While passive autofocus is enabled, use lockAutoFocus(android.hardware.camera2.CaptureRequest.Builder, android.hardware.camera2.CaptureRequest.Builder)
to lock
the lens before taking a picture. Once a picture is taken, use unlockAutoFocus(android.hardware.camera2.CaptureRequest.Builder, android.hardware.camera2.CaptureRequest.Builder)
to let the lens go back into passive scanning.
Once passive AF scanning starts, AutoFocusStateMachine.AutoFocusStateListener.onAutoFocusScan(android.hardware.camera2.CaptureResult)
will be
invoked.
repeatingBuilder
- Builder for a repeating request.picture
- True for still capture AF, false for video AF.public void updateCaptureRequest(CaptureRequest.Builder repeatingBuilder)
This is typically used when a new repeating request is created to update preview with new metadata (i.e. crop region). The current auto focus mode needs to be carried over for correct auto focus behavior.
repeatingBuilder
- Builder for a repeating request.