Methods Summary |
---|
private void | doStateTransition(int newState)
doStateTransition(newState, /*timestamp*/0, NO_CAPTURE_ERROR);
|
private void | doStateTransition(int newState, long timestamp, int error)
if (newState != mCurrentState) {
String stateName = "UNKNOWN";
if (newState >= 0 && newState < sStateNames.length) {
stateName = sStateNames[newState];
}
Log.i(TAG, "Legacy camera service transitioning to state " + stateName);
}
// If we transitioned into a non-IDLE/non-ERROR state then mark the device as busy
if(newState != STATE_ERROR && newState != STATE_IDLE) {
if (mCurrentState != newState && mCurrentHandler != null &&
mCurrentListener != null) {
mCurrentHandler.post(new Runnable() {
@Override
public void run() {
mCurrentListener.onBusy();
}
});
}
}
switch(newState) {
case STATE_ERROR:
if (mCurrentState != STATE_ERROR && mCurrentHandler != null &&
mCurrentListener != null) {
mCurrentHandler.post(new Runnable() {
@Override
public void run() {
mCurrentListener.onError(mCurrentError, mCurrentRequest);
}
});
}
mCurrentState = STATE_ERROR;
break;
case STATE_CONFIGURING:
if (mCurrentState != STATE_UNCONFIGURED && mCurrentState != STATE_IDLE) {
Log.e(TAG, "Cannot call configure while in state: " + mCurrentState);
mCurrentError = CameraDeviceImpl.CameraDeviceCallbacks.ERROR_CAMERA_DEVICE;
doStateTransition(STATE_ERROR);
break;
}
if (mCurrentState != STATE_CONFIGURING && mCurrentHandler != null &&
mCurrentListener != null) {
mCurrentHandler.post(new Runnable() {
@Override
public void run() {
mCurrentListener.onConfiguring();
}
});
}
mCurrentState = STATE_CONFIGURING;
break;
case STATE_IDLE:
if (mCurrentState == STATE_IDLE) {
break;
}
if (mCurrentState != STATE_CONFIGURING && mCurrentState != STATE_CAPTURING) {
Log.e(TAG, "Cannot call idle while in state: " + mCurrentState);
mCurrentError = CameraDeviceImpl.CameraDeviceCallbacks.ERROR_CAMERA_DEVICE;
doStateTransition(STATE_ERROR);
break;
}
if (mCurrentState != STATE_IDLE && mCurrentHandler != null &&
mCurrentListener != null) {
mCurrentHandler.post(new Runnable() {
@Override
public void run() {
mCurrentListener.onIdle();
}
});
}
mCurrentState = STATE_IDLE;
break;
case STATE_CAPTURING:
if (mCurrentState != STATE_IDLE && mCurrentState != STATE_CAPTURING) {
Log.e(TAG, "Cannot call capture while in state: " + mCurrentState);
mCurrentError = CameraDeviceImpl.CameraDeviceCallbacks.ERROR_CAMERA_DEVICE;
doStateTransition(STATE_ERROR);
break;
}
if (mCurrentHandler != null && mCurrentListener != null) {
if (error != NO_CAPTURE_ERROR) {
mCurrentHandler.post(new Runnable() {
@Override
public void run() {
mCurrentListener.onError(error, mCurrentRequest);
}
});
} else {
mCurrentHandler.post(new Runnable() {
@Override
public void run() {
mCurrentListener.onCaptureStarted(mCurrentRequest, timestamp);
}
});
}
}
mCurrentState = STATE_CAPTURING;
break;
default:
throw new IllegalStateException("Transition to unknown state: " + newState);
}
|
public synchronized void | setCameraDeviceCallbacks(android.os.Handler handler, android.hardware.camera2.legacy.CameraDeviceState$CameraDeviceStateListener listener)Set the listener for state transition callbacks.
mCurrentHandler = handler;
mCurrentListener = listener;
|
public synchronized boolean | setCaptureResult(RequestHolder request, android.hardware.camera2.impl.CameraMetadataNative result, int captureError)Set the result for a capture.
If the device was in the {@code CAPTURING} state,
{@link CameraDeviceStateListener#onCaptureResult(CameraMetadataNative, RequestHolder)} will
be called with the given result, otherwise this will result in the device transitioning to
the {@code ERROR} state,
if (mCurrentState != STATE_CAPTURING) {
Log.e(TAG, "Cannot receive result while in state: " + mCurrentState);
mCurrentError = CameraDeviceImpl.CameraDeviceCallbacks.ERROR_CAMERA_DEVICE;
doStateTransition(STATE_ERROR);
return mCurrentError == NO_CAPTURE_ERROR;
}
if (mCurrentHandler != null && mCurrentListener != null) {
if (captureError != NO_CAPTURE_ERROR) {
mCurrentHandler.post(new Runnable() {
@Override
public void run() {
mCurrentListener.onError(captureError, request);
}
});
} else {
mCurrentHandler.post(new Runnable() {
@Override
public void run() {
mCurrentListener.onCaptureResult(result, request);
}
});
}
}
return mCurrentError == NO_CAPTURE_ERROR;
|
public synchronized boolean | setCaptureStart(RequestHolder request, long timestamp, int captureError)Transition to the {@code CAPTURING} state, or {@code ERROR} if in an invalid state.
If the device was not already in the {@code CAPTURING} state,
{@link CameraDeviceStateListener#onCaptureStarted(RequestHolder)} will be called.
mCurrentRequest = request;
doStateTransition(STATE_CAPTURING, timestamp, captureError);
return mCurrentError == NO_CAPTURE_ERROR;
|
public synchronized boolean | setConfiguring()Transition to the {@code CONFIGURING} state, or {@code ERROR} if in an invalid state.
If the device was not already in the {@code CONFIGURING} state,
{@link CameraDeviceStateListener#onConfiguring()} will be called.
doStateTransition(STATE_CONFIGURING);
return mCurrentError == NO_CAPTURE_ERROR;
|
public synchronized void | setError(int error)Transition to the {@code ERROR} state.
The device cannot exit the {@code ERROR} state. If the device was not already in the
{@code ERROR} state, {@link CameraDeviceStateListener#onError(int, RequestHolder)} will be
called.
mCurrentError = error;
doStateTransition(STATE_ERROR);
|
public synchronized boolean | setIdle()Transition to the {@code IDLE} state, or {@code ERROR} if in an invalid state.
If the device was not already in the {@code IDLE} state,
{@link CameraDeviceStateListener#onIdle()} will be called.
doStateTransition(STATE_IDLE);
return mCurrentError == NO_CAPTURE_ERROR;
|