Loading src/com/android/camera/VideoController.java +4 −0 Original line number Diff line number Diff line Loading @@ -35,4 +35,8 @@ public interface VideoController extends OnShutterButtonListener { public void stopPreview(); public void updateCameraOrientation(); // Callbacks for camera preview UI events. public void onPreviewUIReady(); public void onPreviewUIDestroyed(); } src/com/android/camera/VideoModule.java +33 −37 Original line number Diff line number Diff line Loading @@ -49,7 +49,6 @@ import android.provider.MediaStore.MediaColumns; import android.provider.MediaStore.Video; import android.util.Log; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.OrientationEventListener; import android.view.Surface; import android.view.View; Loading Loading @@ -115,7 +114,7 @@ public class VideoModule implements CameraModule, private int mCameraId; private Parameters mParameters; private Boolean mCameraOpened = false; private boolean mCameraOpened = false; private boolean mIsInReviewMode; private boolean mSnapshotInProgress = false; Loading @@ -125,6 +124,9 @@ public class VideoModule implements CameraModule, private ComboPreferences mPreferences; private PreferenceGroup mPreferenceGroup; // Preference must be read before starting preview. We check this before starting // preview. private boolean mPreferenceRead; private boolean mIsVideoCaptureIntent; private boolean mQuickCapture; Loading Loading @@ -226,12 +228,10 @@ public class VideoModule implements CameraModule, private void openCamera() { try { synchronized(mCameraOpened) { if (!mCameraOpened) { mCameraDevice = Util.openCamera(mActivity, mCameraId); mCameraOpened = true; } } mParameters = mCameraDevice.getParameters(); } catch (CameraHardwareException e) { mOpenCameraFail = true; Loading Loading @@ -667,6 +667,7 @@ public class VideoModule implements CameraModule, if (mCaptureTimeLapse) quality += 1000; mProfile = CamcorderProfile.get(mCameraId, quality); getDesiredPreviewSize(); mPreferenceRead = true; } private void writeDefaultEffectToPrefs() { Loading Loading @@ -752,16 +753,7 @@ public class VideoModule implements CameraModule, } readVideoPreferences(); resizeForPreviewAspectRatio(); new Thread(new Runnable() { @Override public void run() { synchronized (mCameraOpened) { if (mCameraOpened) { startPreview(); } } } }).start(); } else { // preview already started mUI.enableShutter(true); Loading Loading @@ -818,9 +810,13 @@ public class VideoModule implements CameraModule, if (p != null) return p.getZoom(); return index; } private void startPreview() { Log.v(TAG, "startPreview"); SurfaceTexture surfaceTexture = mUI.getSurfaceTexture(); if (!mPreferenceRead || surfaceTexture == null || mPaused == true) return; mCameraDevice.setErrorCallback(mErrorCallback); if (mPreviewing == true) { stopPreview(); Loading @@ -836,10 +832,6 @@ public class VideoModule implements CameraModule, try { if (!effectsActive()) { SurfaceTexture surfaceTexture = mUI.getSurfaceTexture(); if (surfaceTexture == null) { return; // The texture has been destroyed (pause, etc) } mCameraDevice.setPreviewTextureAsync(surfaceTexture); mCameraDevice.startPreviewAsync(); mPreviewing = true; Loading @@ -854,17 +846,12 @@ public class VideoModule implements CameraModule, closeCamera(); throw new RuntimeException("startPreview failed", ex); } finally { mActivity.runOnUiThread(new Runnable() { @Override public void run() { if (mOpenCameraFail) { Util.showErrorAndFinish(mActivity, R.string.cannot_connect_camera); } else if (mCameraDisabled) { Util.showErrorAndFinish(mActivity, R.string.camera_disabled); } } }); } } Loading Loading @@ -924,13 +911,11 @@ public class VideoModule implements CameraModule, if (closeEffectsAlso) closeEffects(); mCameraDevice.setZoomChangeListener(null); mCameraDevice.setErrorCallback(null); synchronized(mCameraOpened) { if (mCameraOpened) { CameraHolder.instance().release(); } mCameraOpened = false; mCameraDevice = null; } mPreviewing = false; mSnapshotInProgress = false; } Loading Loading @@ -984,6 +969,7 @@ public class VideoModule implements CameraModule, mHandler.removeMessages(SWITCH_CAMERA_START_ANIMATION); mPendingSwitchCameraId = -1; mSwitchingCamera = false; mPreferenceRead = false; // Call onPause after stopping video recording. So the camera can be // released as soon as possible. } Loading Loading @@ -2246,4 +2232,14 @@ public class VideoModule implements CameraModule, public void onMediaSaveServiceConnected(MediaSaveService s) { // do nothing. } @Override public void onPreviewUIReady() { startPreview(); } @Override public void onPreviewUIDestroyed() { stopPreview(); } } src/com/android/camera/VideoUI.java +4 −15 Original line number Diff line number Diff line Loading @@ -57,7 +57,7 @@ public class VideoUI implements PieRenderer.PieListener, PreviewGestures.SingleTapListener, CameraRootView.MyDisplayListener, SurfaceTextureListener, SurfaceHolder.Callback { private final static String TAG = "CAM_VideoUI"; private static final String TAG = "CAM_VideoUI"; private static final int UPDATE_TRANSFORM_MATRIX = 1; // module fields private CameraActivity mActivity; Loading Loading @@ -653,31 +653,20 @@ public class VideoUI implements PieRenderer.PieListener, } public SurfaceTexture getSurfaceTexture() { synchronized (mLock) { if (mSurfaceTexture == null) { try { mLock.wait(); } catch (InterruptedException e) { Log.w(TAG, "Unexpected interruption when waiting to get surface texture"); } } } return mSurfaceTexture; } // SurfaceTexture callbacks @Override public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { synchronized (mLock) { mSurfaceTexture = surface; mLock.notifyAll(); } mController.onPreviewUIReady(); } @Override public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { mSurfaceTexture = null; mController.stopPreview(); mController.onPreviewUIDestroyed(); Log.d(TAG, "surfaceTexture is destroyed"); return true; } Loading Loading
src/com/android/camera/VideoController.java +4 −0 Original line number Diff line number Diff line Loading @@ -35,4 +35,8 @@ public interface VideoController extends OnShutterButtonListener { public void stopPreview(); public void updateCameraOrientation(); // Callbacks for camera preview UI events. public void onPreviewUIReady(); public void onPreviewUIDestroyed(); }
src/com/android/camera/VideoModule.java +33 −37 Original line number Diff line number Diff line Loading @@ -49,7 +49,6 @@ import android.provider.MediaStore.MediaColumns; import android.provider.MediaStore.Video; import android.util.Log; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.OrientationEventListener; import android.view.Surface; import android.view.View; Loading Loading @@ -115,7 +114,7 @@ public class VideoModule implements CameraModule, private int mCameraId; private Parameters mParameters; private Boolean mCameraOpened = false; private boolean mCameraOpened = false; private boolean mIsInReviewMode; private boolean mSnapshotInProgress = false; Loading @@ -125,6 +124,9 @@ public class VideoModule implements CameraModule, private ComboPreferences mPreferences; private PreferenceGroup mPreferenceGroup; // Preference must be read before starting preview. We check this before starting // preview. private boolean mPreferenceRead; private boolean mIsVideoCaptureIntent; private boolean mQuickCapture; Loading Loading @@ -226,12 +228,10 @@ public class VideoModule implements CameraModule, private void openCamera() { try { synchronized(mCameraOpened) { if (!mCameraOpened) { mCameraDevice = Util.openCamera(mActivity, mCameraId); mCameraOpened = true; } } mParameters = mCameraDevice.getParameters(); } catch (CameraHardwareException e) { mOpenCameraFail = true; Loading Loading @@ -667,6 +667,7 @@ public class VideoModule implements CameraModule, if (mCaptureTimeLapse) quality += 1000; mProfile = CamcorderProfile.get(mCameraId, quality); getDesiredPreviewSize(); mPreferenceRead = true; } private void writeDefaultEffectToPrefs() { Loading Loading @@ -752,16 +753,7 @@ public class VideoModule implements CameraModule, } readVideoPreferences(); resizeForPreviewAspectRatio(); new Thread(new Runnable() { @Override public void run() { synchronized (mCameraOpened) { if (mCameraOpened) { startPreview(); } } } }).start(); } else { // preview already started mUI.enableShutter(true); Loading Loading @@ -818,9 +810,13 @@ public class VideoModule implements CameraModule, if (p != null) return p.getZoom(); return index; } private void startPreview() { Log.v(TAG, "startPreview"); SurfaceTexture surfaceTexture = mUI.getSurfaceTexture(); if (!mPreferenceRead || surfaceTexture == null || mPaused == true) return; mCameraDevice.setErrorCallback(mErrorCallback); if (mPreviewing == true) { stopPreview(); Loading @@ -836,10 +832,6 @@ public class VideoModule implements CameraModule, try { if (!effectsActive()) { SurfaceTexture surfaceTexture = mUI.getSurfaceTexture(); if (surfaceTexture == null) { return; // The texture has been destroyed (pause, etc) } mCameraDevice.setPreviewTextureAsync(surfaceTexture); mCameraDevice.startPreviewAsync(); mPreviewing = true; Loading @@ -854,17 +846,12 @@ public class VideoModule implements CameraModule, closeCamera(); throw new RuntimeException("startPreview failed", ex); } finally { mActivity.runOnUiThread(new Runnable() { @Override public void run() { if (mOpenCameraFail) { Util.showErrorAndFinish(mActivity, R.string.cannot_connect_camera); } else if (mCameraDisabled) { Util.showErrorAndFinish(mActivity, R.string.camera_disabled); } } }); } } Loading Loading @@ -924,13 +911,11 @@ public class VideoModule implements CameraModule, if (closeEffectsAlso) closeEffects(); mCameraDevice.setZoomChangeListener(null); mCameraDevice.setErrorCallback(null); synchronized(mCameraOpened) { if (mCameraOpened) { CameraHolder.instance().release(); } mCameraOpened = false; mCameraDevice = null; } mPreviewing = false; mSnapshotInProgress = false; } Loading Loading @@ -984,6 +969,7 @@ public class VideoModule implements CameraModule, mHandler.removeMessages(SWITCH_CAMERA_START_ANIMATION); mPendingSwitchCameraId = -1; mSwitchingCamera = false; mPreferenceRead = false; // Call onPause after stopping video recording. So the camera can be // released as soon as possible. } Loading Loading @@ -2246,4 +2232,14 @@ public class VideoModule implements CameraModule, public void onMediaSaveServiceConnected(MediaSaveService s) { // do nothing. } @Override public void onPreviewUIReady() { startPreview(); } @Override public void onPreviewUIDestroyed() { stopPreview(); } }
src/com/android/camera/VideoUI.java +4 −15 Original line number Diff line number Diff line Loading @@ -57,7 +57,7 @@ public class VideoUI implements PieRenderer.PieListener, PreviewGestures.SingleTapListener, CameraRootView.MyDisplayListener, SurfaceTextureListener, SurfaceHolder.Callback { private final static String TAG = "CAM_VideoUI"; private static final String TAG = "CAM_VideoUI"; private static final int UPDATE_TRANSFORM_MATRIX = 1; // module fields private CameraActivity mActivity; Loading Loading @@ -653,31 +653,20 @@ public class VideoUI implements PieRenderer.PieListener, } public SurfaceTexture getSurfaceTexture() { synchronized (mLock) { if (mSurfaceTexture == null) { try { mLock.wait(); } catch (InterruptedException e) { Log.w(TAG, "Unexpected interruption when waiting to get surface texture"); } } } return mSurfaceTexture; } // SurfaceTexture callbacks @Override public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { synchronized (mLock) { mSurfaceTexture = surface; mLock.notifyAll(); } mController.onPreviewUIReady(); } @Override public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { mSurfaceTexture = null; mController.stopPreview(); mController.onPreviewUIDestroyed(); Log.d(TAG, "surfaceTexture is destroyed"); return true; } Loading