Added smarter logic for understand that need restart camera or preview when we switch mode

pull/806/head
alexander.melnikov 5 years ago
parent 17439581a9
commit 3b28133623
  1. 12
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  2. 26
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera1Engine.java
  3. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera2Engine.java
  4. 8
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraBaseEngine.java
  5. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraEngine.java

@ -159,7 +159,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
@SuppressWarnings({"FieldCanBeLocal", "unused"})
private boolean mExperimental;
private boolean mInEditor;
private boolean mChangeModeWithoutRestart;
// Overlays
@VisibleForTesting OverlayLayout mOverlayLayout;
@ -870,15 +869,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
mExperimental = experimental;
}
/**
* Sets the flag if you want disable restart camera on change mode (Photo/Video),
* but only for {@link Engine#CAMERA1}
* @param changeModeWithoutRestart - true if you want disable restart
*/
public void setChangeModeWithoutRestart(boolean changeModeWithoutRestart) {
mChangeModeWithoutRestart = changeModeWithoutRestart;
}
/**
* Shorthand for the appropriate set* method.
* For example, if control is a {@link Grid}, this calls {@link #setGrid(Grid)}.
@ -1430,7 +1420,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @param mode desired session type.
*/
public void setMode(@NonNull Mode mode) {
mCameraEngine.setMode(mode, mChangeModeWithoutRestart);
mCameraEngine.setMode(mode);
}
/**

@ -148,12 +148,28 @@ public class Camera1Engine extends CameraBaseEngine implements
@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() {
Size prevModeSize = mCaptureSize;
mCaptureSize = computeCaptureSize();
Camera.Parameters params = mCamera.getParameters();
setPictureSize(params);
applyDefaultFocus(params);
params.setRecordingHint(getMode() == Mode.VIDEO);
mCamera.setParameters(params);
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

@ -393,7 +393,7 @@ public class Camera2Engine extends CameraBaseEngine implements
@Override
protected void prepareNewMode() {
LOG.w("prepareNewMode:", "can't prepare new mode without restart for Engine2");
restart();
restartBind();
}
//endregion

@ -384,18 +384,14 @@ public abstract class CameraBaseEngine extends CameraEngine {
* @param mode desired mode.
*/
@Override
public final void setMode(@NonNull Mode mode, final boolean withoutRestart) {
public final void setMode(@NonNull Mode mode) {
if (mode != mMode) {
mMode = mode;
getOrchestrator().scheduleStateful("mode", CameraState.ENGINE,
new Runnable() {
@Override
public void run() {
if (withoutRestart) {
prepareNewMode();
} else {
restart();
}
prepareNewMode();
}
});
}

@ -664,7 +664,7 @@ public abstract class CameraEngine implements
public abstract void setAudio(@NonNull Audio audio);
@NonNull public abstract Audio getAudio();
public abstract void setMode(@NonNull Mode mode, boolean withoutRestart);
public abstract void setMode(@NonNull Mode mode);
@NonNull public abstract Mode getMode();
public abstract void setZoom(float zoom, @Nullable PointF[] points, boolean notify);

Loading…
Cancel
Save