Create setHasFrameProcessors API

pull/493/head
Mattia Iavarone 5 years ago
parent ccdc50ea42
commit d9d213e67b
  1. 46
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/engine/MockCameraEngine.java
  2. 10
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  3. 4
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera1Engine.java
  4. 36
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera2Engine.java
  5. 11
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraEngine.java

@ -119,10 +119,6 @@ public class MockCameraEngine extends CameraEngine {
mExposureCorrectionChanged = true; mExposureCorrectionChanged = true;
} }
@Override
public void setFacing(@NonNull Facing facing) {
mFacing = facing;
}
@Override @Override
public void setFlash(@NonNull Flash flash) { public void setFlash(@NonNull Flash flash) {
@ -134,21 +130,11 @@ public class MockCameraEngine extends CameraEngine {
mWhiteBalance = whiteBalance; mWhiteBalance = whiteBalance;
} }
@Override
public void setMode(@NonNull Mode mode) {
mMode = mode;
}
@Override @Override
public void setHdr(@NonNull Hdr hdr) { public void setHdr(@NonNull Hdr hdr) {
mHdr = hdr; mHdr = hdr;
} }
@Override
public void setAudio(@NonNull Audio audio) {
mAudio = audio;
}
@Override @Override
public void setLocation(@Nullable Location location) { public void setLocation(@Nullable Location location) {
mLocation = location; mLocation = location;
@ -165,7 +151,8 @@ public class MockCameraEngine extends CameraEngine {
} }
@Override @Override
public void takeVideo(@NonNull VideoResult.Stub stub, @NonNull File file) { protected void onTakeVideo(@NonNull VideoResult.Stub stub) {
} }
@Override @Override
@ -197,4 +184,33 @@ public class MockCameraEngine extends CameraEngine {
public void setPlaySounds(boolean playSounds) { 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;
}
*/
} }

@ -1301,6 +1301,9 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
public void addFrameProcessor(@Nullable FrameProcessor processor) { public void addFrameProcessor(@Nullable FrameProcessor processor) {
if (processor != null) { if (processor != null) {
mFrameProcessors.add(processor); 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) { public void removeFrameProcessor(@Nullable FrameProcessor processor) {
if (processor != null) { if (processor != null) {
mFrameProcessors.remove(processor); mFrameProcessors.remove(processor);
if (mFrameProcessors.size() == 0) {
mCameraEngine.setHasFrameProcessors(false);
}
} }
} }
@ -1322,7 +1328,11 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* to preview frames. * to preview frames.
*/ */
public void clearFrameProcessors() { public void clearFrameProcessors() {
boolean had = mFrameProcessors.size() > 0;
mFrameProcessors.clear(); mFrameProcessors.clear();
if (had) {
mCameraEngine.setHasFrameProcessors(false);
}
} }

@ -279,6 +279,10 @@ public class Camera1Engine extends CameraEngine implements Camera.PreviewCallbac
return false; return false;
} }
@Override
public void setHasFrameProcessors(boolean hasFrameProcessors) {
mHasFrameProcessors = hasFrameProcessors;
}
@Override @Override
public void onBufferAvailable(@NonNull byte[] buffer) { public void onBufferAvailable(@NonNull byte[] buffer) {

@ -437,6 +437,11 @@ public class Camera2Engine extends CameraEngine {
mPictureRecorder.take(); mPictureRecorder.take();
} }
@Override
public void takePicture(@NonNull PictureResult.Stub stub) {
// TODO
}
//endregion //endregion
//region Videos //region Videos
@ -726,32 +731,39 @@ public class Camera2Engine extends CameraEngine {
mPlaySoundsOp.end(null); mPlaySoundsOp.end(null);
} }
//endregion
@Override
public void onBufferAvailable(@NonNull byte[] buffer) {
}
@Override @Override
public void setZoom(float zoom, @Nullable PointF[] points, boolean notify) { public void setZoom(float zoom, @Nullable PointF[] points, boolean notify) {
// TODO
} }
@Override @Override
public void setExposureCorrection(float EVvalue, @NonNull float[] bounds, @Nullable PointF[] points, boolean notify) { public void setExposureCorrection(float EVvalue, @NonNull float[] bounds, @Nullable PointF[] points, boolean notify) {
// TODO
} }
//endregion
//region FrameProcessing
@Override @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 @Override
public void startAutoFocus(@Nullable Gesture gesture, @NonNull PointF point) { public void startAutoFocus(@Nullable Gesture gesture, @NonNull PointF point) {
// TODO
} }
//endregion
} }

@ -166,6 +166,7 @@ public abstract class CameraEngine implements
protected float mZoomValue; protected float mZoomValue;
protected float mExposureCorrectionValue; protected float mExposureCorrectionValue;
protected boolean mPlaySounds; protected boolean mPlaySounds;
protected boolean mHasFrameProcessors;
@Nullable private SizeSelector mPreviewStreamSizeSelector; @Nullable private SizeSelector mPreviewStreamSizeSelector;
private SizeSelector mPictureSizeSelector; private SizeSelector mPictureSizeSelector;
@ -916,6 +917,8 @@ public abstract class CameraEngine implements
public abstract void setPlaySounds(boolean playSounds); public abstract void setPlaySounds(boolean playSounds);
public abstract void setHasFrameProcessors(boolean hasFrameProcessors);
//endregion //endregion
//region picture and video control //region picture and video control
@ -1160,12 +1163,16 @@ public abstract class CameraEngine implements
public final long getAutoFocusResetDelay() { return mAutoFocusResetDelayMillis; } public final long getAutoFocusResetDelay() { return mAutoFocusResetDelayMillis; }
final boolean shouldResetAutoFocus() { public boolean getHasFrameProcessors() {
return mAutoFocusResetDelayMillis > 0 && mAutoFocusResetDelayMillis != Long.MAX_VALUE; return mHasFrameProcessors;
} }
//endregion //endregion
final boolean shouldResetAutoFocus() {
return mAutoFocusResetDelayMillis > 0 && mAutoFocusResetDelayMillis != Long.MAX_VALUE;
}
//region Orientation utils //region Orientation utils
private int computeSensorToViewOffset() { private int computeSensorToViewOffset() {

Loading…
Cancel
Save