Tried change switch mode without restart for Engine 1.

pull/806/head
alexander.melnikov 5 years ago
parent 778cdedc00
commit f70ee53a33
  1. 7
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  2. 22
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera1Engine.java
  3. 7
      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,6 +159,7 @@ 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;
@ -869,6 +870,10 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
mExperimental = experimental; mExperimental = experimental;
} }
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)}.
@ -1420,7 +1425,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); mCameraEngine.setMode(mode, mChangeModeWithoutRestart);
} }
/** /**

@ -145,6 +145,28 @@ public class Camera1Engine extends CameraBaseEngine implements
return false; return false;
} }
@EngineThread
@Override
protected void prepareNewMode() {
mCaptureSize = computeCaptureSize();
Camera.Parameters params = mCamera.getParameters();
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());
}
applyDefaultFocus(params);
params.setRecordingHint(getMode() == Mode.VIDEO);
mCamera.setParameters(params);
}
//endregion //endregion
//region Start //region Start

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

@ -383,19 +383,25 @@ public abstract class CameraBaseEngine extends CameraEngine {
* @param mode desired mode. * @param mode desired mode.
*/ */
@Override @Override
public final void setMode(@NonNull Mode mode) { public final void setMode(@NonNull Mode mode, final boolean withoutRestart) {
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();
} else {
restart(); restart();
} }
}
}); });
} }
} }
protected abstract void prepareNewMode();
@NonNull @NonNull
@Override @Override
public final Mode getMode() { public final Mode getMode() {

@ -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); public abstract void setMode(@NonNull Mode mode, boolean withoutRestart);
@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