diff options
author | Sol Boucher <solb@google.com> | 2014-08-26 21:38:52 -0700 |
---|---|---|
committer | Sol Boucher <solb@google.com> | 2014-08-27 13:47:44 -0700 |
commit | 772fcce3e51a9c7d33df6a9c278a908ac6902880 (patch) | |
tree | 359f8945b4e8a11376772679a5db0a1dc39d1a15 | |
parent | 7c8d6957b96c75ce11f7373f4ab2451ee4666360 (diff) | |
download | android_frameworks_ex-772fcce3e51a9c7d33df6a9c278a908ac6902880.tar.gz android_frameworks_ex-772fcce3e51a9c7d33df6a9c278a908ac6902880.tar.bz2 android_frameworks_ex-772fcce3e51a9c7d33df6a9c278a908ac6902880.zip |
camera2-portability: Fix and document obscure state machine bug
The numeric state codes defined by the camera2 implementation were incompatible
with the StateHolder class's wait interface; thus, blocking operations didn't
always behave as expected.
Bug: 17300466
Change-Id: I54f462d5de876c9dcf99b2a4c7ae79879cc0eca2
-rw-r--r-- | camera2/portability/src/com/android/ex/camera2/portability/AndroidCamera2AgentImpl.java | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/camera2/portability/src/com/android/ex/camera2/portability/AndroidCamera2AgentImpl.java b/camera2/portability/src/com/android/ex/camera2/portability/AndroidCamera2AgentImpl.java index 44f19bc..bdeda5a 100644 --- a/camera2/portability/src/com/android/ex/camera2/portability/AndroidCamera2AgentImpl.java +++ b/camera2/portability/src/com/android/ex/camera2/portability/AndroidCamera2AgentImpl.java @@ -215,7 +215,7 @@ class AndroidCamera2AgentImpl extends CameraAgent { CameraOpenCallback openCallback = (CameraOpenCallback) msg.obj; int cameraIndex = msg.arg1; - if (mCameraState.getState() != AndroidCamera2StateHolder.CAMERA_UNOPENED) { + if (mCameraState.getState() > AndroidCamera2StateHolder.CAMERA_UNOPENED) { openCallback.onDeviceOpenedAlready(cameraIndex, generateHistoryString(cameraIndex)); break; @@ -1072,8 +1072,9 @@ class AndroidCamera2AgentImpl extends CameraAgent { mDispatchThread.runJob(new Runnable() { @Override public void run() { - mCameraState.waitForStates(AndroidCamera2StateHolder.CAMERA_PREVIEW_ACTIVE | - AndroidCamera2StateHolder.CAMERA_FOCUS_LOCKED); + // Wait until PREVIEW_ACTIVE or better + mCameraState.waitForStates( + ~(AndroidCamera2StateHolder.CAMERA_PREVIEW_ACTIVE - 1)); mCameraHandler.obtainMessage(CameraActions.CAPTURE_PHOTO, picListener) .sendToTarget(); }}); @@ -1127,9 +1128,8 @@ class AndroidCamera2AgentImpl extends CameraAgent { return false; } - if (applySettingsHelper(settings, AndroidCamera2StateHolder.CAMERA_UNCONFIGURED | - AndroidCamera2StateHolder.CAMERA_CONFIGURED | - AndroidCamera2StateHolder.CAMERA_PREVIEW_READY)) { + // Wait for any state that isn't OPENED + if (applySettingsHelper(settings, ~AndroidCamera2StateHolder.CAMERA_UNOPENED)) { mLastSettings = settings; return true; } @@ -1160,19 +1160,22 @@ class AndroidCamera2AgentImpl extends CameraAgent { private static class AndroidCamera2StateHolder extends CameraStateHolder { // Usage flow: openCamera() -> applySettings() -> setPreviewTexture() -> startPreview() -> // autoFocus() -> takePicture() + // States are mutually exclusive, but must be separate bits so that they can be used with + // the StateHolder#waitForStates() and StateHolder#waitToAvoidStates() methods. + // Do not set the state to be a combination of these values! /* Camera states */ /** No camera device is opened. */ - public static final int CAMERA_UNOPENED = 1; + public static final int CAMERA_UNOPENED = 1 << 0; /** A camera is opened, but no settings have been provided. */ - public static final int CAMERA_UNCONFIGURED = 2; + public static final int CAMERA_UNCONFIGURED = 1 << 1; /** The open camera has been configured by providing it with settings. */ - public static final int CAMERA_CONFIGURED = 3; + public static final int CAMERA_CONFIGURED = 1 << 2; /** A capture session is ready to stream a preview, but still has no repeating request. */ - public static final int CAMERA_PREVIEW_READY = 4; + public static final int CAMERA_PREVIEW_READY = 1 << 3; /** A preview is currently being streamed. */ - public static final int CAMERA_PREVIEW_ACTIVE = 5; + public static final int CAMERA_PREVIEW_ACTIVE = 1 << 4; /** The lens is locked on a particular region. */ - public static final int CAMERA_FOCUS_LOCKED = 6; + public static final int CAMERA_FOCUS_LOCKED = 1 << 5; public AndroidCamera2StateHolder() { this(CAMERA_UNOPENED); |