summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/android/camera/VideoController.java4
-rw-r--r--src/com/android/camera/VideoModule.java70
-rw-r--r--src/com/android/camera/VideoUI.java19
3 files changed, 41 insertions, 52 deletions
diff --git a/src/com/android/camera/VideoController.java b/src/com/android/camera/VideoController.java
index b53dec616..e84654821 100644
--- a/src/com/android/camera/VideoController.java
+++ b/src/com/android/camera/VideoController.java
@@ -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();
}
diff --git a/src/com/android/camera/VideoModule.java b/src/com/android/camera/VideoModule.java
index 0daa67246..bba2363b9 100644
--- a/src/com/android/camera/VideoModule.java
+++ b/src/com/android/camera/VideoModule.java
@@ -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;
@@ -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;
@@ -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;
@@ -226,11 +228,9 @@ public class VideoModule implements CameraModule,
private void openCamera() {
try {
- synchronized(mCameraOpened) {
- if (!mCameraOpened) {
- mCameraDevice = Util.openCamera(mActivity, mCameraId);
- mCameraOpened = true;
- }
+ if (!mCameraOpened) {
+ mCameraDevice = Util.openCamera(mActivity, mCameraId);
+ mCameraOpened = true;
}
mParameters = mCameraDevice.getParameters();
} catch (CameraHardwareException e) {
@@ -667,6 +667,7 @@ public class VideoModule implements CameraModule,
if (mCaptureTimeLapse) quality += 1000;
mProfile = CamcorderProfile.get(mCameraId, quality);
getDesiredPreviewSize();
+ mPreferenceRead = true;
}
private void writeDefaultEffectToPrefs() {
@@ -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();
+ startPreview();
} else {
// preview already started
mUI.enableShutter(true);
@@ -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();
@@ -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;
@@ -854,16 +846,11 @@ 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);
- }
- }
- });
+ if (mOpenCameraFail) {
+ Util.showErrorAndFinish(mActivity, R.string.cannot_connect_camera);
+ } else if (mCameraDisabled) {
+ Util.showErrorAndFinish(mActivity, R.string.camera_disabled);
+ }
}
}
@@ -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;
+ if (mCameraOpened) {
+ CameraHolder.instance().release();
}
+ mCameraOpened = false;
+ mCameraDevice = null;
mPreviewing = false;
mSnapshotInProgress = false;
}
@@ -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.
}
@@ -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();
+ }
}
diff --git a/src/com/android/camera/VideoUI.java b/src/com/android/camera/VideoUI.java
index 4ee199be5..551b72596 100644
--- a/src/com/android/camera/VideoUI.java
+++ b/src/com/android/camera/VideoUI.java
@@ -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;
@@ -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();
- }
+ mSurfaceTexture = surface;
+ mController.onPreviewUIReady();
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
mSurfaceTexture = null;
- mController.stopPreview();
+ mController.onPreviewUIDestroyed();
Log.d(TAG, "surfaceTexture is destroyed");
return true;
}