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"}) @SuppressWarnings({"FieldCanBeLocal", "unused"})
private boolean mExperimental; private boolean mExperimental;
private boolean mInEditor; private boolean mInEditor;
private boolean mChangeModeWithoutRestart;
// Overlays // Overlays
@VisibleForTesting OverlayLayout mOverlayLayout; @VisibleForTesting OverlayLayout mOverlayLayout;
@ -870,15 +869,6 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
mExperimental = experimental; 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. * Shorthand for the appropriate set* method.
* For example, if control is a {@link Grid}, this calls {@link #setGrid(Grid)}. * 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. * @param mode desired session type.
*/ */
public void setMode(@NonNull Mode mode) { public void setMode(@NonNull Mode mode) {
mCameraEngine.setMode(mode, mChangeModeWithoutRestart); mCameraEngine.setMode(mode);
} }
/** /**

@ -148,12 +148,28 @@ public class Camera1Engine extends CameraBaseEngine implements
@EngineThread @EngineThread
@Override @Override
protected void prepareNewMode() { 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(); mCaptureSize = computeCaptureSize();
Camera.Parameters params = mCamera.getParameters();
setPictureSize(params); boolean flip = getAngles().flip(Reference.SENSOR, Reference.VIEW);
applyDefaultFocus(params); AspectRatio prevModePreviewTargetRatio = AspectRatio.of(prevModeSize.getWidth(), prevModeSize.getHeight());
params.setRecordingHint(getMode() == Mode.VIDEO); AspectRatio targetRatio = AspectRatio.of(mCaptureSize.getWidth(), mCaptureSize.getHeight());
mCamera.setParameters(params); if (flip) prevModePreviewTargetRatio = prevModePreviewTargetRatio.flip();
if (flip) targetRatio = targetRatio.flip();
return prevModePreviewTargetRatio.equals(targetRatio);
} }
//endregion //endregion

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

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

@ -664,7 +664,7 @@ public abstract class CameraEngine implements
public abstract void setAudio(@NonNull Audio audio); public abstract void setAudio(@NonNull Audio audio);
@NonNull public abstract Audio getAudio(); @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(); @NonNull public abstract Mode getMode();
public abstract void setZoom(float zoom, @Nullable PointF[] points, boolean notify); public abstract void setZoom(float zoom, @Nullable PointF[] points, boolean notify);

Loading…
Cancel
Save