summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/CaptureModule.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/camera/CaptureModule.java')
-rw-r--r--[-rwxr-xr-x]src/com/android/camera/CaptureModule.java386
1 files changed, 300 insertions, 86 deletions
diff --git a/src/com/android/camera/CaptureModule.java b/src/com/android/camera/CaptureModule.java
index 2b363dbfe..e870161f3 100755..100644
--- a/src/com/android/camera/CaptureModule.java
+++ b/src/com/android/camera/CaptureModule.java
@@ -56,11 +56,14 @@ import android.media.ImageReader;
import android.media.MediaActionSound;
import android.media.MediaMetadataRetriever;
import android.media.MediaRecorder;
+import android.media.EncoderCapabilities;
+import android.media.EncoderCapabilities.VideoEncoderCap;
import android.net.Uri;
import android.os.Debug;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
+import android.os.Bundle;
import android.os.Message;
import android.os.SystemClock;
import android.provider.MediaStore;
@@ -76,7 +79,6 @@ import android.view.WindowManager;
import android.widget.Toast;
import com.android.camera.exif.ExifInterface;
-import com.android.camera.Exif;
import com.android.camera.imageprocessor.filter.BlurbusterFilter;
import com.android.camera.imageprocessor.filter.ChromaflashFilter;
import com.android.camera.imageprocessor.filter.ImageFilter;
@@ -236,6 +238,13 @@ public class CaptureModule implements CameraModule, PhotoController,
private int mChosenImageFormat;
private Toast mToast;
+ private boolean mStartRecPending = false;
+ private boolean mStopRecPending = false;
+
+ boolean mUnsupportedResolution = false;
+
+ private static final int SDCARD_SIZE_LIMIT = 4000 * 1024 * 1024;
+
/**
* A {@link CameraCaptureSession } for camera preview.
*/
@@ -312,6 +321,7 @@ public class CaptureModule implements CameraModule, PhotoController,
private MediaActionSound mSound;
private Size mSupportedMaxPictureSize;
+
private class SelfieThread extends Thread {
public void run() {
try {
@@ -632,10 +642,10 @@ public class CaptureModule implements CameraModule, PhotoController,
break;
}
case STATE_AF_AE_LOCKED: {
- Integer afState = result.get(CaptureResult.CONTROL_AF_STATE);
- Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
- Log.d(TAG, "STATE_AF_AE_LOCKED id: " + id + " afState:" + afState + " aeState:" + aeState);
- break;
+ Integer afState = result.get(CaptureResult.CONTROL_AF_STATE);
+ Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
+ Log.d(TAG, "STATE_AF_AE_LOCKED id: " + id + " afState:" + afState + " aeState:" + aeState);
+ break;
}
case STATE_WAITING_TOUCH_FOCUS:
break;
@@ -913,7 +923,7 @@ public class CaptureModule implements CameraModule, PhotoController,
@Override
public void onConfigureFailed(CameraCaptureSession cameraCaptureSession) {
- Log.e(TAG, "cameracapturesession - onConfigureFailed "+id);
+ Log.e(TAG, "cameracapturesession - onConfigureFailed "+ id);
if (mActivity.isFinishing()) {
return;
}
@@ -986,6 +996,9 @@ public class CaptureModule implements CameraModule, PhotoController,
}
public void setAFModeToPreview(int id, int afMode) {
+ if (!checkSessionAndBuilder(mCaptureSession[id], mPreviewRequestBuilder[id])) {
+ return;
+ }
Log.d(TAG, "setAFModeToPreview " + afMode);
mPreviewRequestBuilder[id].set(CaptureRequest.CONTROL_AF_MODE, afMode);
applyAFRegions(mPreviewRequestBuilder[id], id);
@@ -994,14 +1007,17 @@ public class CaptureModule implements CameraModule, PhotoController,
try {
mCaptureSession[id].setRepeatingRequest(mPreviewRequestBuilder[id]
.build(), mCaptureCallback, mCameraHandler);
- } catch (CameraAccessException e) {
+ } catch (CameraAccessException | IllegalStateException e) {
e.printStackTrace();
}
}
public void setFlashModeToPreview(int id, boolean isFlashOn) {
Log.d(TAG, "setFlashModeToPreview " + isFlashOn);
- if(isFlashOn) {
+ if (!checkSessionAndBuilder(mCaptureSession[id], mPreviewRequestBuilder[id])) {
+ return;
+ }
+ if (isFlashOn) {
mPreviewRequestBuilder[id].set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH);
mPreviewRequestBuilder[id].set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_SINGLE);
} else {
@@ -1014,23 +1030,26 @@ public class CaptureModule implements CameraModule, PhotoController,
try {
mCaptureSession[id].setRepeatingRequest(mPreviewRequestBuilder[id]
.build(), mCaptureCallback, mCameraHandler);
- } catch (CameraAccessException e) {
+ } catch (CameraAccessException | IllegalStateException e) {
e.printStackTrace();
}
}
public void setFocusDistanceToPreview(int id, float fd) {
+ if (!checkSessionAndBuilder(mCaptureSession[id], mPreviewRequestBuilder[id])) {
+ return;
+ }
mPreviewRequestBuilder[id].set(CaptureRequest.LENS_FOCUS_DISTANCE, fd);
mPreviewRequestBuilder[id].setTag(id);
try {
- if(id == MONO_ID && !canStartMonoPreview()) {
+ if (id == MONO_ID && !canStartMonoPreview()) {
mCaptureSession[id].capture(mPreviewRequestBuilder[id]
.build(), mCaptureCallback, mCameraHandler);
} else {
mCaptureSession[id].setRepeatingRequest(mPreviewRequestBuilder[id]
.build(), mCaptureCallback, mCameraHandler);
}
- } catch (CameraAccessException e) {
+ } catch (CameraAccessException | IllegalStateException e) {
e.printStackTrace();
}
}
@@ -1123,7 +1142,9 @@ public class CaptureModule implements CameraModule, PhotoController,
* Lock the focus as the first step for a still image capture.
*/
private void lockFocus(int id) {
- if (mActivity == null || mCameraDevice[id] == null) {
+ if (mActivity == null || mCameraDevice[id] == null
+ || !checkSessionAndBuilder(mCaptureSession[id], mPreviewRequestBuilder[id])) {
+ mUI.enableShutter(true);
warningToast("Camera is not ready yet to take a picture.");
return;
}
@@ -1166,14 +1187,15 @@ public class CaptureModule implements CameraModule, PhotoController,
mLockRequestHashCode[id] = request.hashCode();
mState[id] = STATE_WAITING_AF_LOCK;
mCaptureSession[id].capture(request, mCaptureCallback, mCameraHandler);
- } catch (CameraAccessException e) {
+ } catch (CameraAccessException | IllegalStateException e) {
e.printStackTrace();
}
}
private void autoFocusTrigger(int id) {
Log.d(TAG, "autoFocusTrigger " + id);
- if (null == mActivity || null == mCameraDevice[id]) {
+ if (null == mActivity || null == mCameraDevice[id]
+ || !checkSessionAndBuilder(mCaptureSession[id], mPreviewRequestBuilder[id])) {
warningToast("Camera is not ready yet to take a picture.");
return;
}
@@ -1190,7 +1212,7 @@ public class CaptureModule implements CameraModule, PhotoController,
Message message = mCameraHandler.obtainMessage(
CANCEL_TOUCH_FOCUS, Integer.valueOf(mCameraId[id]), 0);
mCameraHandler.sendMessageDelayed(message, CANCEL_TOUCH_FOCUS_DELAY);
- } catch (CameraAccessException e) {
+ } catch (CameraAccessException | IllegalStateException e) {
e.printStackTrace();
}
}
@@ -1383,7 +1405,7 @@ public class CaptureModule implements CameraModule, PhotoController,
private void captureVideoSnapshot(final int id) {
Log.d(TAG, "captureStillPicture " + id);
try {
- if (null == mActivity || null == mCameraDevice[id]) {
+ if (null == mActivity || null == mCameraDevice[id] || mCurrentSession == null) {
warningToast("Camera is not ready yet to take a video snapshot.");
return;
}
@@ -1433,6 +1455,9 @@ public class CaptureModule implements CameraModule, PhotoController,
*/
private void runPrecaptureSequence(int id) {
Log.d(TAG, "runPrecaptureSequence: " + id);
+ if (!checkSessionAndBuilder(mCaptureSession[id], mPreviewRequestBuilder[id])) {
+ return;
+ }
try {
CaptureRequest.Builder builder = getRequestBuilder(id);
builder.setTag(id);
@@ -1443,7 +1468,7 @@ public class CaptureModule implements CameraModule, PhotoController,
mState[id] = STATE_WAITING_PRECAPTURE;
mCaptureSession[id].capture(request, mCaptureCallback, mCameraHandler);
- } catch (CameraAccessException e) {
+ } catch (CameraAccessException | IllegalStateException e) {
e.printStackTrace();
}
}
@@ -1588,6 +1613,9 @@ public class CaptureModule implements CameraModule, PhotoController,
*/
public void unlockFocus(int id) {
Log.d(TAG, "unlockFocus " + id);
+ if (!checkSessionAndBuilder(mCaptureSession[id], mPreviewRequestBuilder[id])) {
+ return;
+ }
try {
CaptureRequest.Builder builder = getRequestBuilder(id);
builder.setTag(id);
@@ -1619,12 +1647,8 @@ public class CaptureModule implements CameraModule, PhotoController,
}
});
}
- } catch (NullPointerException e) {
+ } catch (NullPointerException | IllegalStateException | CameraAccessException e) {
Log.w(TAG, "Session is already closed");
- } catch (IllegalStateException e) {
- Log.w(TAG, "Session is already closed");
- } catch (CameraAccessException e) {
- e.printStackTrace();
}
}
@@ -1645,6 +1669,15 @@ public class CaptureModule implements CameraModule, PhotoController,
}
}
+ public boolean isAllSessionClosed() {
+ for (int i = MAX_NUM_CAM - 1; i >= 0; i--) {
+ if (mCaptureSession[i] != null) {
+ return false;
+ }
+ }
+ return true;
+ }
+
private void closeSessions() {
for (int i = MAX_NUM_CAM-1; i >= 0; i--) {
if (null != mCaptureSession[i]) {
@@ -1727,13 +1760,16 @@ public class CaptureModule implements CameraModule, PhotoController,
* Lock the exposure for capture
*/
private void lockExposure(int id) {
+ if (!checkSessionAndBuilder(mCaptureSession[id], mPreviewRequestBuilder[id])) {
+ return;
+ }
Log.d(TAG, "lockExposure: " + id);
try {
applySettingsForLockExposure(mPreviewRequestBuilder[id], id);
mState[id] = STATE_WAITING_AE_LOCK;
mCaptureSession[id].setRepeatingRequest(mPreviewRequestBuilder[id].build(),
mCaptureCallback, mCameraHandler);
- } catch (CameraAccessException e) {
+ } catch (CameraAccessException | IllegalStateException e) {
e.printStackTrace();
}
}
@@ -1918,6 +1954,7 @@ public class CaptureModule implements CameraModule, PhotoController,
mFirstPreviewLoaded = false;
stopBackgroundThread();
mLastJpegData = null;
+ setProModeVisible();
}
@Override
@@ -2132,14 +2169,9 @@ public class CaptureModule implements CameraModule, PhotoController,
});
mUI.enableShutter(true);
mUI.enableVideo(true);
- String scene = mSettingsManager.getValue(SettingsManager.KEY_SCENE_MODE);
- boolean promode = false;
- if (scene != null) {
- int mode = Integer.parseInt(scene);
- if (mode == SettingsManager.SCENE_MODE_PROMODE_INT) promode = true;
- }
- mUI.initializeProMode(promode);
+ setProModeVisible();
+ String scene = mSettingsManager.getValue(SettingsManager.KEY_SCENE_MODE);
if(isPanoSetting(scene)) {
mActivity.onModuleSelected(ModuleSwitcher.PANOCAPTURE_MODULE_INDEX);
}
@@ -2403,8 +2435,8 @@ public class CaptureModule implements CameraModule, PhotoController,
@Override
public void onCountDownFinished() {
- mUI.showUIAfterCountDown();
checkSelfieFlashAndTakePicture();
+ mUI.showUIAfterCountDown();
}
@Override
@@ -2603,30 +2635,54 @@ public class CaptureModule implements CameraModule, PhotoController,
}
}
- private void startRecordingVideo(final int cameraId) {
+ private boolean startRecordingVideo(final int cameraId) {
if (null == mCameraDevice[cameraId]) {
- return;
+ return false;
}
Log.d(TAG, "StartRecordingVideo " + cameraId);
+ mStartRecPending = true;
mIsRecordingVideo = true;
mMediaRecorderPausing = false;
mUI.hideUIwhileRecording();
- mUI.clearFocus();
- mCameraHandler.removeMessages(CANCEL_TOUCH_FOCUS, mCameraId[cameraId]);
- mState[cameraId] = STATE_PREVIEW;
- mControlAFMode = CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE;
- closePreviewSession();
- mFrameProcessor.onClose();
- boolean changed = mUI.setPreviewSize(mVideoPreviewSize.getWidth(),
- mVideoPreviewSize.getHeight());
- if (changed) {
- mUI.hideSurfaceView();
- mUI.showSurfaceView();
+
+ mActivity.updateStorageSpaceAndHint();
+ if (mActivity.getStorageSpaceBytes() <= Storage.LOW_STORAGE_THRESHOLD_BYTES) {
+ Log.w(TAG, "Storage issue, ignore the start request");
+ mStartRecPending = false;
+ mIsRecordingVideo = false;
+ return false;
}
- mUI.resetTrackingFocus();
try {
setUpMediaRecorder(cameraId);
+ if (mUnsupportedResolution == true ) {
+ Log.v(TAG, "Unsupported Resolution according to target");
+ mStartRecPending = false;
+ mIsRecordingVideo = false;
+ return false;
+ }
+ if (mMediaRecorder == null) {
+ Log.e(TAG, "Fail to initialize media recorder");
+ mStartRecPending = false;
+ mIsRecordingVideo = false;
+ return false;
+ }
+
+ requestAudioFocus();
+ mUI.clearFocus();
+ mCameraHandler.removeMessages(CANCEL_TOUCH_FOCUS, mCameraId[cameraId]);
+ mState[cameraId] = STATE_PREVIEW;
+ mControlAFMode = CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE;
+ closePreviewSession();
+ mFrameProcessor.onClose();
+ boolean changed = mUI.setPreviewSize(mVideoPreviewSize.getWidth(),
+ mVideoPreviewSize.getHeight());
+ if (changed) {
+ mUI.hideSurfaceView();
+ mUI.showSurfaceView();
+ }
+ mUI.resetTrackingFocus();
+
createVideoSnapshotImageReader();
mVideoRequestBuilder = mCameraDevice[cameraId].createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
mVideoRequestBuilder.setTag(cameraId);
@@ -2660,8 +2716,8 @@ public class CaptureModule implements CameraModule, PhotoController,
CameraConstrainedHighSpeedCaptureSession session =
(CameraConstrainedHighSpeedCaptureSession) mCurrentSession;
try {
- List list = session
- .createHighSpeedRequestList(mVideoRequestBuilder.build());
+ List list = CameraUtil
+ .createHighSpeedRequestList(mVideoRequestBuilder.build(),cameraId);
session.setRepeatingBurst(list, mCaptureCallback, mCameraHandler);
} catch (CameraAccessException e) {
Log.e(TAG, "Failed to start high speed video recording "
@@ -2676,7 +2732,17 @@ public class CaptureModule implements CameraModule, PhotoController,
+ e.getMessage());
e.printStackTrace();
}
- mMediaRecorder.start();
+ try {
+ mMediaRecorder.start(); // Recording is now started
+ } catch (RuntimeException e) {
+ Toast.makeText(mActivity,"Could not start media recorder.\n " +
+ "Can't start video recording.", Toast.LENGTH_LONG).show();
+ releaseMediaRecorder();
+ releaseAudioFocus();
+ mStartRecPending = false;
+ mIsRecordingVideo = false;
+ return;
+ }
mUI.clearFocus();
mUI.resetPauseButton();
mRecordingTotalTime = 0L;
@@ -2705,11 +2771,23 @@ public class CaptureModule implements CameraModule, PhotoController,
try {
setUpVideoCaptureRequestBuilder(mVideoRequestBuilder);
mCurrentSession.setRepeatingRequest(mVideoRequestBuilder.build(),
- mCaptureCallback, mCameraHandler);
+ mCaptureCallback, mCameraHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
+ } catch (IllegalStateException e) {
+ e.printStackTrace();
+ }
+ try {
+ mMediaRecorder.start(); // Recording is now started
+ } catch (RuntimeException e) {
+ Toast.makeText(mActivity,"Could not start media recorder.\n " +
+ "Can't start video recording.", Toast.LENGTH_LONG).show();
+ releaseMediaRecorder();
+ releaseAudioFocus();
+ mStartRecPending = false;
+ mIsRecordingVideo = false;
+ return;
}
- mMediaRecorder.start();
mUI.clearFocus();
mUI.resetPauseButton();
mRecordingTotalTime = 0L;
@@ -2730,6 +2808,8 @@ public class CaptureModule implements CameraModule, PhotoController,
} catch (IOException e) {
e.printStackTrace();
}
+ mStartRecPending = false;
+ return true;
}
private void updateTimeLapseSetting() {
@@ -2799,7 +2879,7 @@ public class CaptureModule implements CameraModule, PhotoController,
private void applyVideoStabilization(CaptureRequest.Builder builder) {
String value = mSettingsManager.getValue(SettingsManager.KEY_DIS);
if (value == null) return;
- if (value.equals("enable")) {
+ if (value.equals("on")) {
builder.set(CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE, CaptureRequest
.CONTROL_VIDEO_STABILIZATION_MODE_ON);
} else {
@@ -2903,6 +2983,7 @@ public class CaptureModule implements CameraModule, PhotoController,
private void stopRecordingVideo(int cameraId) {
Log.d(TAG, "stopRecordingVideo " + cameraId);
+ mStopRecPending = true;
boolean shouldAddToMediaStoreNow = false;
// Stop recording
mFrameProcessor.setVideoOutputSurface(null);
@@ -2916,7 +2997,7 @@ public class CaptureModule implements CameraModule, PhotoController,
AccessibilityUtils.makeAnnouncement(mUI.getVideoButton(),
mActivity.getString(R.string.video_recording_stopped));
} catch (RuntimeException e) {
- Log.e(TAG, "MediaRecoder stop fail", e);
+ Log.w(TAG, "MediaRecoder stop fail", e);
if (mVideoFilename != null) deleteVideoFile(mVideoFilename);
}
if (shouldAddToMediaStoreNow) {
@@ -2943,6 +3024,7 @@ public class CaptureModule implements CameraModule, PhotoController,
createSessions();
mUI.showUIafterRecording();
mUI.resetTrackingFocus();
+ mStopRecPending = false;
}
private void closePreviewSession() {
@@ -3024,11 +3106,19 @@ public class CaptureModule implements CameraModule, PhotoController,
size = CameraSettings.getTimeLapseQualityFor(size);
}
+ Intent intent = mActivity.getIntent();
+ Bundle myExtras = intent.getExtras();
+
if (mMediaRecorder == null) mMediaRecorder = new MediaRecorder();
updateHFRSetting();
boolean hfr = mHighSpeedCapture && !mHighSpeedRecordingMode;
+
mProfile = CamcorderProfile.get(cameraId, size);
+ int videoWidth = mProfile.videoFrameWidth;
+ int videoHeight = mProfile.videoFrameHeight;
+ mUnsupportedResolution = false;
+
int videoEncoder = SettingTranslation
.getVideoEncoder(mSettingsManager.getValue(SettingsManager.KEY_VIDEO_ENCODER));
int audioEncoder = SettingTranslation
@@ -3081,6 +3171,54 @@ public class CaptureModule implements CameraModule, PhotoController,
mMediaRecorder.setVideoEncodingBitRate(scaledBitrate);
}
+ long requestedSizeLimit = 0;
+ if (isVideoCaptureIntent() && myExtras != null) {
+ requestedSizeLimit = myExtras.getLong(MediaStore.EXTRA_SIZE_LIMIT);
+ }
+ //check if codec supports the resolution, otherwise throw toast
+ List<VideoEncoderCap> videoEncoders = EncoderCapabilities.getVideoEncoders();
+ for (VideoEncoderCap videoEnc: videoEncoders) {
+ if (videoEnc.mCodec == videoEncoder) {
+ if (videoWidth > videoEnc.mMaxFrameWidth ||
+ videoWidth < videoEnc.mMinFrameWidth ||
+ videoHeight > videoEnc.mMaxFrameHeight ||
+ videoHeight < videoEnc.mMinFrameHeight) {
+ Log.e(TAG, "Selected codec " + videoEncoder +
+ " does not support "+ videoWidth + "x" + videoHeight
+ + " resolution");
+ Log.e(TAG, "Codec capabilities: " +
+ "mMinFrameWidth = " + videoEnc.mMinFrameWidth + " , " +
+ "mMinFrameHeight = " + videoEnc.mMinFrameHeight + " , " +
+ "mMaxFrameWidth = " + videoEnc.mMaxFrameWidth + " , " +
+ "mMaxFrameHeight = " + videoEnc.mMaxFrameHeight);
+ mUnsupportedResolution = true;
+ RotateTextToast.makeText(mActivity, R.string.error_app_unsupported,
+ Toast.LENGTH_LONG).show();
+ return;
+ }
+ break;
+ }
+ }
+
+ // Set maximum file size.
+ long maxFileSize = mActivity.getStorageSpaceBytes() - Storage.LOW_STORAGE_THRESHOLD_BYTES;
+ if (requestedSizeLimit > 0 && requestedSizeLimit < maxFileSize) {
+ maxFileSize = requestedSizeLimit;
+ }
+
+ if (Storage.isSaveSDCard() && maxFileSize > SDCARD_SIZE_LIMIT) {
+ maxFileSize = SDCARD_SIZE_LIMIT;
+ }
+ Log.i(TAG, "MediaRecorder setMaxFileSize: " + maxFileSize);
+ try {
+ mMediaRecorder.setMaxFileSize(maxFileSize);
+ } catch (RuntimeException exception) {
+ // We are going to ignore failure of setMaxFileSize here, as
+ // a) The composer selected may simply not support it, or
+ // b) The underlying media framework may not handle 64-bit range
+ // on the size restriction.
+ }
+
Location loc = mLocationManager.getCurrentLocation();
if (loc != null) {
mMediaRecorder.setLocation((float) loc.getLatitude(),
@@ -3110,11 +3248,17 @@ public class CaptureModule implements CameraModule, PhotoController,
}
public void onVideoButtonClick() {
+ if (isRecorderReady() == false) return;
+
if (getCameraMode() == DUAL_MODE) return;
if (mIsRecordingVideo) {
stopRecordingVideo(getMainCameraId());
} else {
- startRecordingVideo(getMainCameraId());
+ if (!startRecordingVideo(getMainCameraId())) {
+ // Show ui when start recording failed.
+ mUI.showUIafterRecording();
+ releaseMediaRecorder();
+ }
}
}
@@ -3200,7 +3344,7 @@ public class CaptureModule implements CameraModule, PhotoController,
}
private void estimateJpegFileSize() {
- String quality = mSettingsManager.getValue(SettingsManager
+ String quality = mSettingsManager.getValue(SettingsManager
.KEY_JPEG_QUALITY);
int[] ratios = mActivity.getResources().getIntArray(R.array.jpegquality_compression_ratio);
String[] qualities = mActivity.getResources().getStringArray(
@@ -3307,6 +3451,9 @@ public class CaptureModule implements CameraModule, PhotoController,
}
private boolean applyPreferenceToPreview(int cameraId, String key, String value) {
+ if (!checkSessionAndBuilder(mCaptureSession[cameraId], mPreviewRequestBuilder[cameraId])) {
+ return false;
+ }
boolean updatePreview = false;
switch (key) {
case SettingsManager.KEY_WHITE_BALANCE:
@@ -3341,6 +3488,9 @@ public class CaptureModule implements CameraModule, PhotoController,
}
private void applyZoomAndUpdate(int id) {
+ if (!checkSessionAndBuilder(mCaptureSession[id], mPreviewRequestBuilder[id])) {
+ return;
+ }
applyZoom(mPreviewRequestBuilder[id], id);
try {
if(id == MONO_ID && !canStartMonoPreview()) {
@@ -3350,7 +3500,7 @@ public class CaptureModule implements CameraModule, PhotoController,
mCaptureSession[id].setRepeatingRequest(mPreviewRequestBuilder[id]
.build(), mCaptureCallback, mCameraHandler);
}
- } catch (CameraAccessException e) {
+ } catch (CameraAccessException | IllegalStateException e) {
e.printStackTrace();
}
}
@@ -3464,11 +3614,11 @@ public class CaptureModule implements CameraModule, PhotoController,
}
private void applyFaceDetection(CaptureRequest.Builder request) {
- String value = mSettingsManager.getValue(SettingsManager.KEY_FACE_DETECTION);
- if (value != null && value.equals("on")) {
- request.set(CaptureRequest.STATISTICS_FACE_DETECT_MODE,
- CaptureRequest.STATISTICS_FACE_DETECT_MODE_SIMPLE);
- }
+ String value = mSettingsManager.getValue(SettingsManager.KEY_FACE_DETECTION);
+ if (value != null && value.equals("on")) {
+ request.set(CaptureRequest.STATISTICS_FACE_DETECT_MODE,
+ CaptureRequest.STATISTICS_FACE_DETECT_MODE_SIMPLE);
+ }
}
private void applyFlash(CaptureRequest.Builder request, int id) {
@@ -3681,30 +3831,39 @@ public class CaptureModule implements CameraModule, PhotoController,
}
if (updatePreviewBayer) {
try {
- mCaptureSession[BAYER_ID].setRepeatingRequest(mPreviewRequestBuilder[BAYER_ID]
- .build(), mCaptureCallback, mCameraHandler);
- } catch (CameraAccessException e) {
+ if (checkSessionAndBuilder(mCaptureSession[BAYER_ID],
+ mPreviewRequestBuilder[BAYER_ID])) {
+ mCaptureSession[BAYER_ID].setRepeatingRequest(mPreviewRequestBuilder[BAYER_ID]
+ .build(), mCaptureCallback, mCameraHandler);
+ }
+ } catch (CameraAccessException | IllegalStateException e) {
e.printStackTrace();
}
}
if (updatePreviewMono) {
try {
- if(canStartMonoPreview()) {
- mCaptureSession[MONO_ID].setRepeatingRequest(mPreviewRequestBuilder[MONO_ID]
- .build(), mCaptureCallback, mCameraHandler);
- } else {
- mCaptureSession[MONO_ID].capture(mPreviewRequestBuilder[MONO_ID]
- .build(), mCaptureCallback, mCameraHandler);
+ if (checkSessionAndBuilder(mCaptureSession[MONO_ID],
+ mPreviewRequestBuilder[MONO_ID])) {
+ if (canStartMonoPreview()) {
+ mCaptureSession[MONO_ID].setRepeatingRequest(mPreviewRequestBuilder[MONO_ID]
+ .build(), mCaptureCallback, mCameraHandler);
+ } else {
+ mCaptureSession[MONO_ID].capture(mPreviewRequestBuilder[MONO_ID]
+ .build(), mCaptureCallback, mCameraHandler);
+ }
}
- } catch (CameraAccessException e) {
+ } catch (CameraAccessException | IllegalStateException e) {
e.printStackTrace();
}
}
if (updatePreviewFront) {
try {
- mCaptureSession[FRONT_ID].setRepeatingRequest(mPreviewRequestBuilder[FRONT_ID]
- .build(), mCaptureCallback, mCameraHandler);
- } catch (CameraAccessException e) {
+ if (checkSessionAndBuilder(mCaptureSession[FRONT_ID],
+ mPreviewRequestBuilder[FRONT_ID])) {
+ mCaptureSession[FRONT_ID].setRepeatingRequest(mPreviewRequestBuilder[FRONT_ID]
+ .build(), mCaptureCallback, mCameraHandler);
+ }
+ } catch (CameraAccessException | IllegalStateException e) {
e.printStackTrace();
}
}
@@ -3745,25 +3904,36 @@ public class CaptureModule implements CameraModule, PhotoController,
}
public void restartSession(boolean isSurfaceChanged) {
+ Log.d(TAG, "restartSession isSurfaceChanged = " + isSurfaceChanged);
+ if (isAllSessionClosed()) return;
+
+ closeProcessors();
+ closeSessions();
+
if(isSurfaceChanged) {
mUI.hideSurfaceView();
+ mUI.showSurfaceView();
}
- closeProcessors();
- closeSessions();
+
initializeValues();
updatePreviewSize();
openProcessors();
- if(isSurfaceChanged) {
- mUI.showSurfaceView();
- } else {
- createSessions();
- }
+ createSessions();
if(isTrackingFocusSettingOn()) {
mUI.resetTrackingFocus();
}
+ resetStateMachine();
}
+ private void resetStateMachine() {
+ for (int i = 0; i < MAX_NUM_CAM; i++) {
+ mState[i] = STATE_PREVIEW;
+ }
+ mUI.enableShutter(true);
+ }
+
+
private Size getOptimalPreviewSize(Size pictureSize, Size[] prevSizes, int screenW, int
screenH) {
if (pictureSize.getWidth() <= screenH && pictureSize.getHeight() <= screenW) {
@@ -4027,6 +4197,36 @@ public class CaptureModule implements CameraModule, PhotoController,
}
}
+ private void showToast(String tips) {
+ if (mToast == null) {
+ mToast = Toast.makeText(mActivity, tips, Toast.LENGTH_LONG);
+ }
+ mToast.setText(tips);
+ mToast.show();
+ }
+
+ private boolean isRecorderReady() {
+ if ((mStartRecPending == true || mStopRecPending == true))
+ return false;
+ else
+ return true;
+ }
+
+ /*
+ * Make sure we're not recording music playing in the background, ask the
+ * MediaPlaybackService to pause playback.
+ */
+ private void requestAudioFocus() {
+ AudioManager am = (AudioManager)mActivity.getSystemService(Context.AUDIO_SERVICE);
+ // Send request to obtain audio focus. This will stop other
+ // music stream.
+ int result = am.requestAudioFocus(null, AudioManager.STREAM_MUSIC,
+ AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
+ if (result == AudioManager.AUDIOFOCUS_REQUEST_FAILED) {
+ Log.v(TAG, "Audio focus request failed");
+ }
+ }
+
private void releaseAudioFocus() {
AudioManager am = (AudioManager)mActivity.getSystemService(Context.AUDIO_SERVICE);
int result = am.abandonAudioFocus(null);
@@ -4035,12 +4235,9 @@ public class CaptureModule implements CameraModule, PhotoController,
}
}
- private void showToast(String tips) {
- if (mToast == null) {
- mToast = Toast.makeText(mActivity, tips, Toast.LENGTH_LONG);
- }
- mToast.setText(tips);
- mToast.show();
+ private boolean isVideoCaptureIntent() {
+ String action = mActivity.getIntent().getAction();
+ return (MediaStore.ACTION_VIDEO_CAPTURE.equals(action));
}
private void resetScreenOn() {
@@ -4058,4 +4255,21 @@ public class CaptureModule implements CameraModule, PhotoController,
mHandler.removeMessages(CLEAR_SCREEN_DELAY);
mActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
+
+
+ private void setProModeVisible() {
+ String scene = mSettingsManager.getValue(SettingsManager.KEY_SCENE_MODE);
+ boolean promode = false;
+ if (scene != null) {
+ int mode = Integer.parseInt(scene);
+ if (mode == SettingsManager.SCENE_MODE_PROMODE_INT) {
+ promode = true;
+ }
+ }
+ mUI.initializeProMode(!mPaused && promode);
+ }
+
+ boolean checkSessionAndBuilder(CameraCaptureSession session, CaptureRequest.Builder builder) {
+ return session != null && builder != null;
+ }
}