From d9d213e67be3518c183d32a0e095f04797147007 Mon Sep 17 00:00:00 2001 From: Mattia Iavarone Date: Mon, 1 Jul 2019 10:21:32 -0500 Subject: [PATCH] Create setHasFrameProcessors API --- .../cameraview/engine/MockCameraEngine.java | 46 +++++++++++++------ .../otaliastudios/cameraview/CameraView.java | 10 ++++ .../cameraview/engine/Camera1Engine.java | 4 ++ .../cameraview/engine/Camera2Engine.java | 36 ++++++++++----- .../cameraview/engine/CameraEngine.java | 11 ++++- 5 files changed, 78 insertions(+), 29 deletions(-) diff --git a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/engine/MockCameraEngine.java b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/engine/MockCameraEngine.java index d0c4e95b..63e553a1 100644 --- a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/engine/MockCameraEngine.java +++ b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/engine/MockCameraEngine.java @@ -119,10 +119,6 @@ public class MockCameraEngine extends CameraEngine { mExposureCorrectionChanged = true; } - @Override - public void setFacing(@NonNull Facing facing) { - mFacing = facing; - } @Override public void setFlash(@NonNull Flash flash) { @@ -134,21 +130,11 @@ public class MockCameraEngine extends CameraEngine { mWhiteBalance = whiteBalance; } - @Override - public void setMode(@NonNull Mode mode) { - mMode = mode; - } - @Override public void setHdr(@NonNull Hdr hdr) { mHdr = hdr; } - @Override - public void setAudio(@NonNull Audio audio) { - mAudio = audio; - } - @Override public void setLocation(@Nullable Location location) { mLocation = location; @@ -165,7 +151,8 @@ public class MockCameraEngine extends CameraEngine { } @Override - public void takeVideo(@NonNull VideoResult.Stub stub, @NonNull File file) { + protected void onTakeVideo(@NonNull VideoResult.Stub stub) { + } @Override @@ -197,4 +184,33 @@ public class MockCameraEngine extends CameraEngine { public void setPlaySounds(boolean playSounds) { } + + @Override + public void setHasFrameProcessors(boolean hasFrameProcessors) { + + } + + @Override + protected boolean collectCameraInfo(@NonNull Facing facing) { + return true; + } + + /* + + @Override + public void setFacing(@NonNull Facing facing) { + mFacing = facing; + } + + @Override + public void setMode(@NonNull Mode mode) { + mMode = mode; + } + + @Override + public void setAudio(@NonNull Audio audio) { + mAudio = audio; + } + + */ } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java index e4a44ec6..b79059de 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java @@ -1301,6 +1301,9 @@ public class CameraView extends FrameLayout implements LifecycleObserver { public void addFrameProcessor(@Nullable FrameProcessor processor) { if (processor != null) { mFrameProcessors.add(processor); + if (mFrameProcessors.size() == 1) { + mCameraEngine.setHasFrameProcessors(true); + } } } @@ -1313,6 +1316,9 @@ public class CameraView extends FrameLayout implements LifecycleObserver { public void removeFrameProcessor(@Nullable FrameProcessor processor) { if (processor != null) { mFrameProcessors.remove(processor); + if (mFrameProcessors.size() == 0) { + mCameraEngine.setHasFrameProcessors(false); + } } } @@ -1322,7 +1328,11 @@ public class CameraView extends FrameLayout implements LifecycleObserver { * to preview frames. */ public void clearFrameProcessors() { + boolean had = mFrameProcessors.size() > 0; mFrameProcessors.clear(); + if (had) { + mCameraEngine.setHasFrameProcessors(false); + } } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera1Engine.java b/cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera1Engine.java index 82259965..bbd799a1 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera1Engine.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera1Engine.java @@ -279,6 +279,10 @@ public class Camera1Engine extends CameraEngine implements Camera.PreviewCallbac return false; } + @Override + public void setHasFrameProcessors(boolean hasFrameProcessors) { + mHasFrameProcessors = hasFrameProcessors; + } @Override public void onBufferAvailable(@NonNull byte[] buffer) { diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera2Engine.java b/cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera2Engine.java index 22df2dd8..57fed0a5 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera2Engine.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera2Engine.java @@ -437,6 +437,11 @@ public class Camera2Engine extends CameraEngine { mPictureRecorder.take(); } + @Override + public void takePicture(@NonNull PictureResult.Stub stub) { + // TODO + } + //endregion //region Videos @@ -726,32 +731,39 @@ public class Camera2Engine extends CameraEngine { mPlaySoundsOp.end(null); } - //endregion - - - @Override - public void onBufferAvailable(@NonNull byte[] buffer) { - - } - @Override public void setZoom(float zoom, @Nullable PointF[] points, boolean notify) { - + // TODO } @Override public void setExposureCorrection(float EVvalue, @NonNull float[] bounds, @Nullable PointF[] points, boolean notify) { - + // TODO } + //endregion + + //region FrameProcessing + @Override - public void takePicture(@NonNull PictureResult.Stub stub) { + public void onBufferAvailable(@NonNull byte[] buffer) { + // TODO + } + @Override + public void setHasFrameProcessors(boolean hasFrameProcessors) { + mHasFrameProcessors = hasFrameProcessors; } + //endregion + + //region Auto focus + @Override public void startAutoFocus(@Nullable Gesture gesture, @NonNull PointF point) { - + // TODO } + + //endregion } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraEngine.java b/cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraEngine.java index 689dbd4d..d9723ed2 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraEngine.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraEngine.java @@ -166,6 +166,7 @@ public abstract class CameraEngine implements protected float mZoomValue; protected float mExposureCorrectionValue; protected boolean mPlaySounds; + protected boolean mHasFrameProcessors; @Nullable private SizeSelector mPreviewStreamSizeSelector; private SizeSelector mPictureSizeSelector; @@ -916,6 +917,8 @@ public abstract class CameraEngine implements public abstract void setPlaySounds(boolean playSounds); + public abstract void setHasFrameProcessors(boolean hasFrameProcessors); + //endregion //region picture and video control @@ -1160,12 +1163,16 @@ public abstract class CameraEngine implements public final long getAutoFocusResetDelay() { return mAutoFocusResetDelayMillis; } - final boolean shouldResetAutoFocus() { - return mAutoFocusResetDelayMillis > 0 && mAutoFocusResetDelayMillis != Long.MAX_VALUE; + public boolean getHasFrameProcessors() { + return mHasFrameProcessors; } //endregion + final boolean shouldResetAutoFocus() { + return mAutoFocusResetDelayMillis > 0 && mAutoFocusResetDelayMillis != Long.MAX_VALUE; + } + //region Orientation utils private int computeSensorToViewOffset() {