pull/806/merge
Alexander 5 years ago committed by GitHub
commit 359acfc072
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 43
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera1Engine.java
  2. 7
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera2Engine.java
  3. 20
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraBaseEngine.java

@ -145,6 +145,36 @@ public class Camera1Engine extends CameraBaseEngine implements
return false;
}
@EngineThread
@Override
protected void prepareNewMode() {
if(previewAspectRatioEqualsForModes()) {
Camera.Parameters params = mCamera.getParameters();
setPictureSize(params);
applyDefaultFocus(params);
params.setRecordingHint(getMode() == Mode.VIDEO);
mCamera.setParameters(params);
} else {
restartBind();
}
}
private boolean previewAspectRatioEqualsForModes() {
if (mCaptureSize == null) {
return false;
}
Size prevModeSize = mCaptureSize;
mCaptureSize = computeCaptureSize();
boolean flip = getAngles().flip(Reference.SENSOR, Reference.VIEW);
AspectRatio prevModePreviewTargetRatio = AspectRatio.of(prevModeSize.getWidth(), prevModeSize.getHeight());
AspectRatio targetRatio = AspectRatio.of(mCaptureSize.getWidth(), mCaptureSize.getHeight());
if (flip) prevModePreviewTargetRatio = prevModePreviewTargetRatio.flip();
if (flip) targetRatio = targetRatio.flip();
return prevModePreviewTargetRatio.equals(targetRatio);
}
//endregion
//region Start
@ -217,18 +247,7 @@ public class Camera1Engine extends CameraBaseEngine implements
params.setPreviewFormat(ImageFormat.NV21);
// setPreviewSize is not allowed during preview
params.setPreviewSize(mPreviewStreamSize.getWidth(), mPreviewStreamSize.getHeight());
if (getMode() == Mode.PICTURE) {
// setPictureSize is allowed during preview
params.setPictureSize(mCaptureSize.getWidth(), mCaptureSize.getHeight());
} else {
// mCaptureSize in this case is a video size. The available video sizes are not
// necessarily a subset of the picture sizes, so we can't use the mCaptureSize value:
// it might crash. However, the setPictureSize() passed here is useless : we don't allow
// HQ pictures in video mode.
// While this might be lifted in the future, for now, just use a picture capture size.
Size pictureSize = computeCaptureSize(Mode.PICTURE);
params.setPictureSize(pictureSize.getWidth(), pictureSize.getHeight());
}
setPictureSize(params);
mCamera.setParameters(params);
mCamera.setPreviewCallbackWithBuffer(null); // Release anything left

@ -389,6 +389,13 @@ public class Camera2Engine extends CameraBaseEngine implements
return false;
}
@EngineThread
@Override
protected void prepareNewMode() {
LOG.w("prepareNewMode:", "can't prepare new mode without restart for Engine2");
restartBind();
}
//endregion
//region Start

@ -2,6 +2,7 @@ package com.otaliastudios.cameraview.engine;
import android.graphics.PointF;
import android.graphics.RectF;
import android.hardware.Camera;
import android.location.Location;
import androidx.annotation.CallSuper;
@ -403,12 +404,14 @@ public abstract class CameraBaseEngine extends CameraEngine {
new Runnable() {
@Override
public void run() {
restart();
prepareNewMode();
}
});
}
}
protected abstract void prepareNewMode();
@NonNull
@Override
public final Mode getMode() {
@ -765,6 +768,21 @@ public abstract class CameraBaseEngine extends CameraEngine {
: preview.getSurfaceSize();
}
void setPictureSize(Camera.Parameters params) {
if (getMode() == Mode.PICTURE) {
// setPictureSize is allowed during preview
params.setPictureSize(mCaptureSize.getWidth(), mCaptureSize.getHeight());
} else {
// mCaptureSize in this case is a video size. The available video sizes are not
// necessarily a subset of the picture sizes, so we can't use the mCaptureSize value:
// it might crash. However, the setPictureSize() passed here is useless : we don't allow
// HQ pictures in video mode.
// While this might be lifted in the future, for now, just use a picture capture size.
Size pictureSize = computeCaptureSize(Mode.PICTURE);
params.setPictureSize(pictureSize.getWidth(), pictureSize.getHeight());
}
}
/**
* Returns the snapshot size, but not cropped with the view dimensions, which
* is what we will do before creating the snapshot. However, cropping is done at various

Loading…
Cancel
Save