public class CameraDeviceState extends Object
This class acts as the state machine for a camera device. Valid state transitions are given in the table below:
UNCONFIGURED -> CONFIGURING
CONFIGURING -> IDLE
IDLE -> CONFIGURING
IDLE -> CAPTURING
IDLE -> IDLE
CAPTURING -> IDLE
ANY -> ERROR
Modifier and Type | Class and Description |
---|---|
static interface |
CameraDeviceState.CameraDeviceStateListener
CameraDeviceStateListener callbacks to be called after state transitions.
|
Modifier and Type | Field and Description |
---|---|
static int |
NO_CAPTURE_ERROR
Error code used by
setCaptureStart(android.hardware.camera2.legacy.RequestHolder, long, int) and setCaptureResult(android.hardware.camera2.legacy.RequestHolder, android.hardware.camera2.impl.CameraMetadataNative, int, java.lang.Object) to indicate that no
error has occurred. |
Constructor and Description |
---|
CameraDeviceState() |
Modifier and Type | Method and Description |
---|---|
void |
setCameraDeviceCallbacks(Handler handler,
CameraDeviceState.CameraDeviceStateListener listener)
Set the listener for state transition callbacks.
|
boolean |
setCaptureResult(RequestHolder request,
CameraMetadataNative result) |
boolean |
setCaptureResult(RequestHolder request,
CameraMetadataNative result,
int captureError,
Object captureErrorArg)
Set the result for a capture.
|
boolean |
setCaptureStart(RequestHolder request,
long timestamp,
int captureError)
Transition to the
CAPTURING state, or ERROR if in an invalid state. |
boolean |
setConfiguring()
Transition to the
CONFIGURING state, or ERROR if in an invalid state. |
void |
setError(int error)
Transition to the
ERROR state. |
boolean |
setIdle()
Transition to the
IDLE state, or ERROR if in an invalid state. |
void |
setRepeatingRequestError(long lastFrameNumber)
Set repeating request error.
|
public static final int NO_CAPTURE_ERROR
setCaptureStart(android.hardware.camera2.legacy.RequestHolder, long, int)
and setCaptureResult(android.hardware.camera2.legacy.RequestHolder, android.hardware.camera2.impl.CameraMetadataNative, int, java.lang.Object)
to indicate that no
error has occurred.public void setError(int error)
ERROR
state.
The device cannot exit the ERROR
state. If the device was not already in the
ERROR
state, CameraDeviceStateListener#onError(int, RequestHolder)
will be
called.
error
- the error to set. Should be one of the error codes defined in
CameraDeviceImpl.CameraDeviceCallbacks
.public boolean setConfiguring()
CONFIGURING
state, or ERROR
if in an invalid state.
If the device was not already in the CONFIGURING
state,
CameraDeviceState.CameraDeviceStateListener.onConfiguring()
will be called.
false
if an error has occurred.public boolean setIdle()
IDLE
state, or ERROR
if in an invalid state.
If the device was not already in the IDLE
state,
CameraDeviceState.CameraDeviceStateListener.onIdle()
will be called.
false
if an error has occurred.public boolean setCaptureStart(RequestHolder request, long timestamp, int captureError)
CAPTURING
state, or ERROR
if in an invalid state.
If the device was not already in the CAPTURING
state,
CameraDeviceStateListener#onCaptureStarted(RequestHolder)
will be called.
request
- A RequestHolder
containing the request for the current capture.timestamp
- The timestamp of the capture start in nanoseconds.captureError
- Report a recoverable error for a single request using a valid
error code for ICameraDeviceCallbacks
, or
NO_CAPTURE_ERROR
false
if an error has occurred.public boolean setCaptureResult(RequestHolder request, CameraMetadataNative result, int captureError, Object captureErrorArg)
If the device was in the CAPTURING
state,
CameraDeviceState.CameraDeviceStateListener.onCaptureResult(CameraMetadataNative, RequestHolder)
will
be called with the given result, otherwise this will result in the device transitioning to
the ERROR
state,
request
- The RequestHolder
request that created this result.result
- The CameraMetadataNative
result to set.captureError
- Report a recoverable error for a single buffer or result using a valid
error code for ICameraDeviceCallbacks
, or
NO_CAPTURE_ERROR
.captureErrorArg
- An argument for some error captureError codes.false
if an error has occurred.public boolean setCaptureResult(RequestHolder request, CameraMetadataNative result)
public void setRepeatingRequestError(long lastFrameNumber)
Repeating request has been stopped due to an error such as abandoned output surfaces.
lastFrameNumber
- Frame number of the last repeating request before it is stopped.public void setCameraDeviceCallbacks(Handler handler, CameraDeviceState.CameraDeviceStateListener listener)
handler
- handler on which to call the callbacks.listener
- the CameraDeviceState.CameraDeviceStateListener
callbacks to call.