diff options
Diffstat (limited to 'camera2/portability/src/com/android/ex/camera2/portability/AndroidCamera2AgentImpl.java')
-rw-r--r-- | camera2/portability/src/com/android/ex/camera2/portability/AndroidCamera2AgentImpl.java | 66 |
1 files changed, 50 insertions, 16 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 c4eea50..913a575 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; @@ -305,6 +305,10 @@ class AndroidCamera2AgentImpl extends CameraAgent { break; } + // FIXME: We need to tear down the CameraCaptureSession here + // (and unlock the CameraSettings object from our + // CameraProxy) so that the preview/photo sizes can be + // changed again while no preview is running. case CameraActions.STOP_PREVIEW: { if (mCameraState.getState() < AndroidCamera2StateHolder.CAMERA_PREVIEW_ACTIVE) { @@ -936,6 +940,7 @@ class AndroidCamera2AgentImpl extends CameraAgent { private final CameraDeviceInfo.Characteristics mCharacteristics; private final AndroidCamera2Capabilities mCapabilities; private CameraSettings mLastSettings; + private boolean mShutterSoundEnabled; public AndroidCamera2ProxyImpl(int cameraIndex, CameraDevice camera, CameraDeviceInfo.Characteristics characteristics, @@ -945,6 +950,7 @@ class AndroidCamera2AgentImpl extends CameraAgent { mCharacteristics = characteristics; mCapabilities = new AndroidCamera2Capabilities(properties); mLastSettings = null; + mShutterSoundEnabled = true; } // TODO: Implement @@ -970,6 +976,26 @@ class AndroidCamera2AgentImpl extends CameraAgent { return mCapabilities; } + // FIXME: Unlock the sizes in stopPreview(), as per the corresponding + // explanation on the STOP_PREVIEW case in the handler. + @Override + public void setPreviewTexture(SurfaceTexture surfaceTexture) { + // Once the Surface has been selected, we configure the session and + // are no longer able to change the sizes. + getSettings().setSizesLocked(true); + super.setPreviewTexture(surfaceTexture); + } + + // FIXME: Unlock the sizes in stopPreview(), as per the corresponding + // explanation on the STOP_PREVIEW case in the handler. + @Override + public void setPreviewTextureSync(SurfaceTexture surfaceTexture) { + // Once the Surface has been selected, we configure the session and + // are no longer able to change the sizes. + getSettings().setSizesLocked(true); + super.setPreviewTexture(surfaceTexture); + } + // TODO: Implement @Override public void setPreviewDataCallback(Handler handler, CameraPreviewDataCallback cb) {} @@ -1053,7 +1079,9 @@ class AndroidCamera2AgentImpl extends CameraAgent { handler.post(new Runnable() { @Override public void run() { - mNoisemaker.play(MediaActionSound.SHUTTER_CLICK); + if (mShutterSoundEnabled) { + mNoisemaker.play(MediaActionSound.SHUTTER_CLICK); + } shutter.onShutter(AndroidCamera2ProxyImpl.this); }}); } @@ -1077,8 +1105,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(); }}); @@ -1132,15 +1161,19 @@ 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; } return false; } + @Override + public void enableShutterSound(boolean enable) { + mShutterSoundEnabled = enable; + } + // TODO: Implement @Override public String dumpDeviceSettings() { return null; } @@ -1165,19 +1198,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); @@ -1298,9 +1334,7 @@ class AndroidCamera2AgentImpl extends CameraAgent { @Override public boolean canDisableShutterSound() { - // The new API doesn't support this operation, so don't encourage people to try it. - // TODO: What kind of assumptions have callers made about this result's meaning? - return false; + return true; } private static float[] convertRectToPoly(RectF rf) { |