summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/CaptureModule.java
diff options
context:
space:
mode:
authorCamera Software Integration <camswint@localhost>2016-11-28 22:17:54 -0800
committerGerrit - the friendly Code Review server <code-review@localhost>2016-11-28 22:17:54 -0800
commite8cefc2dccb9145e1db7ea207fd39adb9eb9c9bc (patch)
treeee74721ef56a8070c171a2422f672b5f8701c2ce /src/com/android/camera/CaptureModule.java
parent1ac1654e76a15b1e0a871d0942900fd8d1bf88c5 (diff)
parente8195cdf81eb59b8714001e6243925cf846e2314 (diff)
downloadandroid_packages_apps_Snap-e8cefc2dccb9145e1db7ea207fd39adb9eb9c9bc.tar.gz
android_packages_apps_Snap-e8cefc2dccb9145e1db7ea207fd39adb9eb9c9bc.tar.bz2
android_packages_apps_Snap-e8cefc2dccb9145e1db7ea207fd39adb9eb9c9bc.zip
Merge "SnapdragonCamera: Improve onResume" into camera.lnx.1.0-dev.1.0
Diffstat (limited to 'src/com/android/camera/CaptureModule.java')
-rw-r--r--src/com/android/camera/CaptureModule.java57
1 files changed, 43 insertions, 14 deletions
diff --git a/src/com/android/camera/CaptureModule.java b/src/com/android/camera/CaptureModule.java
index 84843e382..732623e83 100644
--- a/src/com/android/camera/CaptureModule.java
+++ b/src/com/android/camera/CaptureModule.java
@@ -104,7 +104,6 @@ import java.io.IOException;
import java.nio.ByteBuffer;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
-import java.util.Comparator;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
@@ -212,7 +211,8 @@ public class CaptureModule implements CameraModule, PhotoController,
private boolean mIsLinked = false;
private long mCaptureStartTime;
private boolean mPaused = true;
- private boolean mSurfaceReady = false;
+ private Semaphore mSurfaceReadyLock = new Semaphore(1);
+ private boolean mSurfaceReady = true;
private boolean[] mCameraOpened = new boolean[MAX_NUM_CAM];
private CameraDevice[] mCameraDevice = new CameraDevice[MAX_NUM_CAM];
private String[] mCameraId = new String[MAX_NUM_CAM];
@@ -795,7 +795,7 @@ public class CaptureModule implements CameraModule, PhotoController,
}
private void createSessions() {
- if (mPaused || !mCamerasOpened || !mSurfaceReady) return;
+ if (mPaused || !mCamerasOpened ) return;
if (isBackCamera()) {
switch (getCameraMode()) {
case DUAL_MODE:
@@ -824,12 +824,42 @@ public class CaptureModule implements CameraModule, PhotoController,
return builder;
}
+ private void waitForPreviewSurfaceReady() {
+ try {
+ if (!mSurfaceReady) {
+ if (!mSurfaceReadyLock.tryAcquire(2000, TimeUnit.MILLISECONDS)) {
+ Log.d(TAG, "Time out waiting for surface.");
+ throw new RuntimeException("Time out waiting for surface.");
+ }
+ mSurfaceReadyLock.release();
+ }
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void updatePreviewSurfaceReadyState(boolean rdy) {
+ if (rdy != mSurfaceReady) {
+ if (rdy) {
+ Log.i(TAG, "Preview Surface is ready!");
+ mSurfaceReadyLock.release();
+ mSurfaceReady = true;
+ } else {
+ try {
+ Log.i(TAG, "Preview Surface is not ready!");
+ mSurfaceReady = false;
+ mSurfaceReadyLock.acquire();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
private void createSession(final int id) {
- if (mPaused || !mCameraOpened[id] || !mSurfaceReady) return;
+ if (mPaused || !mCameraOpened[id]) return;
Log.d(TAG, "createSession " + id);
List<Surface> list = new LinkedList<Surface>();
try {
- Surface surface = getPreviewSurfaceForSession(id);
// We set up a CaptureRequest.Builder with the output Surface.
mPreviewRequestBuilder[id] = getRequestBuilder(id);
mPreviewRequestBuilder[id].setTag(id);
@@ -899,6 +929,8 @@ public class CaptureModule implements CameraModule, PhotoController,
Log.d(TAG, "cameracapturesession - onClosed");
}
};
+ waitForPreviewSurfaceReady();
+ Surface surface = getPreviewSurfaceForSession(id);
if(id == getMainCameraId()) {
mFrameProcessor.setOutputSurface(surface);
@@ -1022,8 +1054,6 @@ public class CaptureModule implements CameraModule, PhotoController,
mCameraOpened[i] = false;
mTakingPicture[i] = false;
}
- mSurfaceReady = false;
-
for (int i = 0; i < MAX_NUM_CAM; i++) {
mState[i] = STATE_PREVIEW;
}
@@ -1882,6 +1912,7 @@ public class CaptureModule implements CameraModule, PhotoController,
}
mLongshotActive = false;
mZoomValue = 1.0f;
+ updatePreviewSurfaceReadyState(false);
}
private ArrayList<Integer> getFrameProcFilterId() {
@@ -2038,7 +2069,6 @@ public class CaptureModule implements CameraModule, PhotoController,
Log.d(TAG, "onResume " + getCameraMode());
initializeValues();
updatePreviewSize();
- mUI.showSurfaceView();
mCameraIdList = new ArrayList<>();
if (mSound == null) {
@@ -2067,6 +2097,7 @@ public class CaptureModule implements CameraModule, PhotoController,
msg.arg1 = FRONT_ID;
mCameraHandler.sendMessage(msg);
}
+ mUI.showSurfaceView();
if (!mFirstTimeInitialized) {
initializeFirstTime();
} else {
@@ -2393,17 +2424,16 @@ public class CaptureModule implements CameraModule, PhotoController,
@Override
public void onPreviewUIReady() {
+ updatePreviewSurfaceReadyState(true);
+
if (mPaused || mIsRecordingVideo) {
return;
}
- Log.d(TAG, "onPreviewUIReady");
- mSurfaceReady = true;
- createSessions();
}
@Override
public void onPreviewUIDestroyed() {
- mSurfaceReady = false;
+ updatePreviewSurfaceReadyState(false);
}
@Override
@@ -2869,9 +2899,8 @@ public class CaptureModule implements CameraModule, PhotoController,
if (changed) {
mUI.hideSurfaceView();
mUI.showSurfaceView();
- } else {
- createSession(cameraId);
}
+ createSessions();
mUI.showUIafterRecording();
mUI.resetTrackingFocus();
}