Reorder CameraEngine members

pull/494/head
Mattia Iavarone 6 years ago
parent c617a7da2a
commit 62cfb5d7f0
  1. 14
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraViewTest.java
  2. 26
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/engine/MockCameraEngine.java
  3. 11
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera1Engine.java
  4. 16
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera2Engine.java
  5. 355
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/CameraEngine.java
  6. 10
      cameraview/src/main/java/com/otaliastudios/cameraview/gesture/GestureFinder.java

@ -231,7 +231,7 @@ public class CameraViewTest extends BaseTest {
ui(new Runnable() { ui(new Runnable() {
@Override @Override
public void run() { public void run() {
cameraView.mTapGestureFinder = new TapGestureFinder(cameraView.getContext()) { cameraView.mTapGestureFinder = new TapGestureFinder(cameraView.mCameraCallbacks) {
protected boolean handleTouchEvent(@NonNull MotionEvent event) { protected boolean handleTouchEvent(@NonNull MotionEvent event) {
setGesture(Gesture.TAP); setGesture(Gesture.TAP);
return true; return true;
@ -253,7 +253,7 @@ public class CameraViewTest extends BaseTest {
ui(new Runnable() { ui(new Runnable() {
@Override @Override
public void run() { public void run() {
cameraView.mTapGestureFinder = new TapGestureFinder(cameraView.getContext()) { cameraView.mTapGestureFinder = new TapGestureFinder(cameraView.mCameraCallbacks) {
protected boolean handleTouchEvent(@NonNull MotionEvent event) { protected boolean handleTouchEvent(@NonNull MotionEvent event) {
setGesture(Gesture.TAP); setGesture(Gesture.TAP);
return true; return true;
@ -280,7 +280,7 @@ public class CameraViewTest extends BaseTest {
ui(new Runnable() { ui(new Runnable() {
@Override @Override
public void run() { public void run() {
cameraView.mPinchGestureFinder = new PinchGestureFinder(cameraView.getContext()) { cameraView.mPinchGestureFinder = new PinchGestureFinder(cameraView.mCameraCallbacks) {
@Override @Override
protected boolean handleTouchEvent(@NonNull MotionEvent event) { protected boolean handleTouchEvent(@NonNull MotionEvent event) {
setGesture(Gesture.PINCH); setGesture(Gesture.PINCH);
@ -321,7 +321,7 @@ public class CameraViewTest extends BaseTest {
ui(new Runnable() { ui(new Runnable() {
@Override @Override
public void run() { public void run() {
cameraView.mScrollGestureFinder = new ScrollGestureFinder(cameraView.getContext()) { cameraView.mScrollGestureFinder = new ScrollGestureFinder(cameraView.mCameraCallbacks) {
@Override @Override
protected boolean handleTouchEvent(@NonNull MotionEvent event) { protected boolean handleTouchEvent(@NonNull MotionEvent event) {
setGesture(Gesture.SCROLL_HORIZONTAL); setGesture(Gesture.SCROLL_HORIZONTAL);
@ -626,7 +626,7 @@ public class CameraViewTest extends BaseTest {
public void testPreviewStreamSizeSelector() { public void testPreviewStreamSizeSelector() {
SizeSelector source = SizeSelectors.minHeight(50); SizeSelector source = SizeSelectors.minHeight(50);
cameraView.setPreviewStreamSize(source); cameraView.setPreviewStreamSize(source);
SizeSelector result = mockController.getInternalPreviewStreamSizeSelector(); SizeSelector result = mockController.getPreviewStreamSizeSelector();
assertNotNull(result); assertNotNull(result);
assertEquals(result, source); assertEquals(result, source);
} }
@ -635,7 +635,7 @@ public class CameraViewTest extends BaseTest {
public void testPictureSizeSelector() { public void testPictureSizeSelector() {
SizeSelector source = SizeSelectors.minHeight(50); SizeSelector source = SizeSelectors.minHeight(50);
cameraView.setPictureSize(source); cameraView.setPictureSize(source);
SizeSelector result = mockController.getInternalPictureSizeSelector(); SizeSelector result = mockController.getPictureSizeSelector();
assertNotNull(result); assertNotNull(result);
assertEquals(result, source); assertEquals(result, source);
} }
@ -644,7 +644,7 @@ public class CameraViewTest extends BaseTest {
public void testVideoSizeSelector() { public void testVideoSizeSelector() {
SizeSelector source = SizeSelectors.minHeight(50); SizeSelector source = SizeSelectors.minHeight(50);
cameraView.setVideoSize(source); cameraView.setVideoSize(source);
SizeSelector result = mockController.getInternalVideoSizeSelector(); SizeSelector result = mockController.getVideoSizeSelector();
assertNotNull(result); assertNotNull(result);
assertEquals(result, source); assertEquals(result, source);
} }

@ -87,27 +87,6 @@ public class MockCameraEngine extends CameraEngine {
mEngineStep.setState(started ? STATE_STARTED : STATE_STOPPED); mEngineStep.setState(started ? STATE_STARTED : STATE_STOPPED);
} }
public int getSnapshotMaxWidth() {
return mSnapshotMaxWidth;
}
public int getSnapshotMaxHeight() {
return mSnapshotMaxHeight;
}
public SizeSelector getInternalPreviewStreamSizeSelector() {
return super.getPreviewStreamSizeSelector();
}
public SizeSelector getInternalPictureSizeSelector() {
return super.getPictureSizeSelector();
}
public SizeSelector getInternalVideoSizeSelector() {
return super.getVideoSizeSelector();
}
@Override @Override
public void setZoom(float zoom, @Nullable PointF[] points, boolean notify) { public void setZoom(float zoom, @Nullable PointF[] points, boolean notify) {
mZoomValue = zoom; mZoomValue = zoom;
@ -194,11 +173,6 @@ public class MockCameraEngine extends CameraEngine {
} }
@Override
public void setHasFrameProcessors(boolean hasFrameProcessors) {
}
@Override @Override
protected boolean collectCameraInfo(@NonNull Facing facing) { protected boolean collectCameraInfo(@NonNull Facing facing) {
return true; return true;

@ -125,7 +125,7 @@ public class Camera1Engine extends CameraEngine implements
applyWhiteBalance(params, WhiteBalance.AUTO); applyWhiteBalance(params, WhiteBalance.AUTO);
applyHdr(params, Hdr.OFF); applyHdr(params, Hdr.OFF);
applyPlaySounds(mPlaySounds); applyPlaySounds(mPlaySounds);
params.setRecordingHint(mMode == Mode.VIDEO); params.setRecordingHint(getMode() == Mode.VIDEO);
mCamera.setParameters(params); mCamera.setParameters(params);
mCamera.setDisplayOrientation(offset(REF_SENSOR, REF_VIEW)); // <- not allowed during preview mCamera.setDisplayOrientation(offset(REF_SENSOR, REF_VIEW)); // <- not allowed during preview
LOG.i("onStartEngine:", "Ended"); LOG.i("onStartEngine:", "Ended");
@ -170,7 +170,7 @@ public class Camera1Engine extends CameraEngine implements
Camera.Parameters params = mCamera.getParameters(); Camera.Parameters params = mCamera.getParameters();
mPreviewStreamFormat = params.getPreviewFormat(); mPreviewStreamFormat = params.getPreviewFormat();
params.setPreviewSize(mPreviewStreamSize.getWidth(), mPreviewStreamSize.getHeight()); // <- not allowed during preview params.setPreviewSize(mPreviewStreamSize.getWidth(), mPreviewStreamSize.getHeight()); // <- not allowed during preview
if (mMode == Mode.PICTURE) { if (getMode() == Mode.PICTURE) {
params.setPictureSize(mCaptureSize.getWidth(), mCaptureSize.getHeight()); // <- allowed params.setPictureSize(mCaptureSize.getWidth(), mCaptureSize.getHeight()); // <- allowed
} else { } else {
// mCaptureSize in this case is a video size. The available video sizes are not necessarily // mCaptureSize in this case is a video size. The available video sizes are not necessarily
@ -285,11 +285,6 @@ public class Camera1Engine extends CameraEngine implements
return false; return false;
} }
@Override
public void setHasFrameProcessors(boolean hasFrameProcessors) {
mHasFrameProcessors = hasFrameProcessors;
}
@NonNull @NonNull
@Override @Override
protected FrameManager instantiateFrameManager() { protected FrameManager instantiateFrameManager() {
@ -443,7 +438,7 @@ public class Camera1Engine extends CameraEngine implements
private void applyDefaultFocus(@NonNull Camera.Parameters params) { private void applyDefaultFocus(@NonNull Camera.Parameters params) {
List<String> modes = params.getSupportedFocusModes(); List<String> modes = params.getSupportedFocusModes();
if (mMode == Mode.VIDEO && if (getMode() == Mode.VIDEO &&
modes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) { modes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO); params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
return; return;

@ -406,7 +406,7 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv
outputSurfaces.add(mPreviewStreamSurface); outputSurfaces.add(mPreviewStreamSurface);
// 2. VIDEO RECORDING // 2. VIDEO RECORDING
if (mMode == Mode.VIDEO) { if (getMode() == Mode.VIDEO) {
if (Full2VideoRecorder.SUPPORTS_PERSISTENT_SURFACE) { if (Full2VideoRecorder.SUPPORTS_PERSISTENT_SURFACE) {
mFullVideoPersistentSurface = MediaCodec.createPersistentInputSurface(); mFullVideoPersistentSurface = MediaCodec.createPersistentInputSurface();
outputSurfaces.add(mFullVideoPersistentSurface); outputSurfaces.add(mFullVideoPersistentSurface);
@ -422,7 +422,7 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv
} }
// 3. PICTURE RECORDING // 3. PICTURE RECORDING
if (mMode == Mode.PICTURE) { if (getMode() == Mode.PICTURE) {
mPictureReader = ImageReader.newInstance( mPictureReader = ImageReader.newInstance(
mCaptureSize.getWidth(), mCaptureSize.getWidth(),
mCaptureSize.getHeight(), mCaptureSize.getHeight(),
@ -433,7 +433,7 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv
} }
// 4. FRAME PROCESSING // 4. FRAME PROCESSING
if (mHasFrameProcessors) { if (hasFrameProcessors()) {
// Choose the size. // Choose the size.
StreamConfigurationMap streamMap = mCameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); StreamConfigurationMap streamMap = mCameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
if (streamMap == null) throw new RuntimeException("StreamConfigurationMap is null. Should not happen."); if (streamMap == null) throw new RuntimeException("StreamConfigurationMap is null. Should not happen.");
@ -494,8 +494,8 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv
throw new IllegalStateException("previewStreamSize should not be null at this point."); throw new IllegalStateException("previewStreamSize should not be null at this point.");
} }
mPreview.setStreamSize(previewSizeForView.getWidth(), previewSizeForView.getHeight()); mPreview.setStreamSize(previewSizeForView.getWidth(), previewSizeForView.getHeight());
mPreview.setDrawRotation(mDisplayOffset); mPreview.setDrawRotation(getDisplayOffset());
if (mHasFrameProcessors) { if (hasFrameProcessors()) {
getFrameManager().setUp(ImageFormat.getBitsPerPixel(FRAME_PROCESSING_FORMAT), mFrameProcessingSize); getFrameManager().setUp(ImageFormat.getBitsPerPixel(FRAME_PROCESSING_FORMAT), mFrameProcessingSize);
} }
@ -537,7 +537,7 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv
mVideoRecorder = null; mVideoRecorder = null;
} }
mPictureRecorder = null; mPictureRecorder = null;
if (mHasFrameProcessors) { if (hasFrameProcessors()) {
getFrameManager().release(); getFrameManager().release();
} }
try { try {
@ -764,7 +764,7 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv
int[] modesArray = readCharacteristic(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES, new int[]{}); int[] modesArray = readCharacteristic(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES, new int[]{});
List<Integer> modes = new ArrayList<>(); List<Integer> modes = new ArrayList<>();
for (int mode : modesArray) { modes.add(mode); } for (int mode : modesArray) { modes.add(mode); }
if (mMode == Mode.VIDEO && if (getMode() == Mode.VIDEO &&
modes.contains(CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_VIDEO)) { modes.contains(CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_VIDEO)) {
builder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_VIDEO); builder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_VIDEO);
return; return;
@ -1064,8 +1064,8 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv
@Override @Override
public void setHasFrameProcessors(final boolean hasFrameProcessors) { public void setHasFrameProcessors(final boolean hasFrameProcessors) {
super.setHasFrameProcessors(hasFrameProcessors);
LOG.i("setHasFrameProcessors", "changed to", hasFrameProcessors, "posting."); LOG.i("setHasFrameProcessors", "changed to", hasFrameProcessors, "posting.");
mHasFrameProcessors = hasFrameProcessors;
mHandler.run(new Runnable() { mHandler.run(new Runnable() {
@Override @Override
public void run() { public void run() {

@ -139,10 +139,10 @@ public abstract class CameraEngine implements
private static final String TAG = CameraEngine.class.getSimpleName(); private static final String TAG = CameraEngine.class.getSimpleName();
private static final CameraLogger LOG = CameraLogger.create(TAG); private static final CameraLogger LOG = CameraLogger.create(TAG);
@SuppressWarnings("WeakerAccess") @SuppressWarnings({"WeakerAccess", "unused"})
public static final int STATE_STOPPING = CameraEngineStep.STATE_STOPPING; public static final int STATE_STOPPING = CameraEngineStep.STATE_STOPPING;
public static final int STATE_STOPPED = CameraEngineStep.STATE_STOPPED; public static final int STATE_STOPPED = CameraEngineStep.STATE_STOPPED;
@SuppressWarnings("WeakerAccess") @SuppressWarnings({"WeakerAccess", "unused"})
public static final int STATE_STARTING = CameraEngineStep.STATE_STARTING; public static final int STATE_STARTING = CameraEngineStep.STATE_STARTING;
public static final int STATE_STARTED = CameraEngineStep.STATE_STARTED; public static final int STATE_STARTED = CameraEngineStep.STATE_STARTED;
@ -150,48 +150,47 @@ public abstract class CameraEngine implements
public static final int REF_VIEW = 1; public static final int REF_VIEW = 1;
public static final int REF_OUTPUT = 2; public static final int REF_OUTPUT = 2;
protected final Callback mCallback; // Need to be protected
private final FrameManager mFrameManager; @SuppressWarnings("WeakerAccess") protected WorkerHandler mHandler;
protected CameraPreview mPreview; @SuppressWarnings("WeakerAccess") protected final Callback mCallback;
protected WorkerHandler mHandler; @SuppressWarnings("WeakerAccess") protected CameraPreview mPreview;
@SuppressWarnings("WeakerAccess") protected CameraOptions mCameraOptions;
@SuppressWarnings("WeakerAccess") protected Mapper mMapper;
@SuppressWarnings("WeakerAccess") protected PictureRecorder mPictureRecorder;
@SuppressWarnings("WeakerAccess") protected VideoRecorder mVideoRecorder;
@SuppressWarnings("WeakerAccess") protected Size mCaptureSize;
@SuppressWarnings("WeakerAccess") protected Size mPreviewStreamSize;
@SuppressWarnings("WeakerAccess") protected Facing mFacing;
@SuppressWarnings("WeakerAccess") protected Flash mFlash;
@SuppressWarnings("WeakerAccess") protected WhiteBalance mWhiteBalance;
@SuppressWarnings("WeakerAccess") protected VideoCodec mVideoCodec;
@SuppressWarnings("WeakerAccess") protected Hdr mHdr;
@SuppressWarnings("WeakerAccess") protected Location mLocation;
@SuppressWarnings("WeakerAccess") protected float mZoomValue;
@SuppressWarnings("WeakerAccess") protected float mExposureCorrectionValue;
@SuppressWarnings("WeakerAccess") protected boolean mPlaySounds;
@SuppressWarnings("WeakerAccess") protected int mSensorOffset;
// Can be private
@VisibleForTesting Handler mCrashHandler; @VisibleForTesting Handler mCrashHandler;
private final FrameManager mFrameManager;
protected Facing mFacing;
protected Flash mFlash;
protected WhiteBalance mWhiteBalance;
protected VideoCodec mVideoCodec;
protected Mode mMode;
protected Hdr mHdr;
protected Location mLocation;
protected Audio mAudio;
protected float mZoomValue;
protected float mExposureCorrectionValue;
protected boolean mPlaySounds;
protected boolean mHasFrameProcessors;
@Nullable private SizeSelector mPreviewStreamSizeSelector; @Nullable private SizeSelector mPreviewStreamSizeSelector;
private SizeSelector mPictureSizeSelector; private SizeSelector mPictureSizeSelector;
private SizeSelector mVideoSizeSelector; private SizeSelector mVideoSizeSelector;
private Mode mMode;
@VisibleForTesting int mSnapshotMaxWidth = Integer.MAX_VALUE; // in REF_VIEW for consistency with SizeSelectors private Audio mAudio;
@VisibleForTesting int mSnapshotMaxHeight = Integer.MAX_VALUE; // in REF_VIEW for consistency with SizeSelectors private long mVideoMaxSize;
private int mVideoMaxDuration;
protected CameraOptions mCameraOptions; private int mVideoBitRate;
protected Mapper mMapper; private int mAudioBitRate;
protected PictureRecorder mPictureRecorder; private boolean mHasFrameProcessors;
protected VideoRecorder mVideoRecorder; private long mAutoFocusResetDelayMillis;
protected long mVideoMaxSize; private int mSnapshotMaxWidth = Integer.MAX_VALUE; // in REF_VIEW for consistency with SizeSelectors
protected int mVideoMaxDuration; private int mSnapshotMaxHeight = Integer.MAX_VALUE; // in REF_VIEW for consistency with SizeSelectors
protected int mVideoBitRate; private int mDisplayOffset;
protected int mAudioBitRate; private int mDeviceOrientation;
protected Size mCaptureSize;
protected Size mPreviewStreamSize; // Steps
protected long mAutoFocusResetDelayMillis;
protected int mSensorOffset;
protected int mDisplayOffset;
protected int mDeviceOrientation;
private final CameraEngineStep.Callback mStepCallback = new CameraEngineStep.Callback() { private final CameraEngineStep.Callback mStepCallback = new CameraEngineStep.Callback() {
@Override @NonNull public Executor getExecutor() { return mHandler.getExecutor(); } @Override @NonNull public Executor getExecutor() { return mHandler.getExecutor(); }
@Override public void handleException(@NonNull Exception exception) { @Override public void handleException(@NonNull Exception exception) {
@ -203,24 +202,17 @@ public abstract class CameraEngine implements
private CameraEngineStep mPreviewStep = new CameraEngineStep("preview", mStepCallback); private CameraEngineStep mPreviewStep = new CameraEngineStep("preview", mStepCallback);
private CameraEngineStep mAllStep = new CameraEngineStep("all", mStepCallback); private CameraEngineStep mAllStep = new CameraEngineStep("all", mStepCallback);
// Used for testing. // Ops used for testing.
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
Op<Void> mZoomOp = new Op<>();
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
Op<Void> mExposureCorrectionOp = new Op<>();
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
Op<Void> mFlashOp = new Op<>();
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
Op<Void> mWhiteBalanceOp = new Op<>();
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
Op<Void> mHdrOp = new Op<>();
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
Op<Void> mLocationOp = new Op<>();
@VisibleForTesting Op<Void> mStartVideoOp = new Op<>(); @VisibleForTesting Op<Void> mStartVideoOp = new Op<>();
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED) @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED) Op<Void> mZoomOp = new Op<>();
Op<Void> mPlaySoundsOp = new Op<>(); @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED) Op<Void> mExposureCorrectionOp = new Op<>();
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED) Op<Void> mFlashOp = new Op<>();
protected CameraEngine(Callback callback) { @VisibleForTesting(otherwise = VisibleForTesting.PROTECTED) Op<Void> mWhiteBalanceOp = new Op<>();
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED) Op<Void> mHdrOp = new Op<>();
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED) Op<Void> mLocationOp = new Op<>();
@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED) Op<Void> mPlaySoundsOp = new Op<>();
protected CameraEngine(@NonNull Callback callback) {
mCallback = callback; mCallback = callback;
mCrashHandler = new Handler(Looper.getMainLooper()); mCrashHandler = new Handler(Looper.getMainLooper());
mHandler = WorkerHandler.get("CameraViewEngine"); mHandler = WorkerHandler.get("CameraViewEngine");
@ -320,7 +312,7 @@ public abstract class CameraEngine implements
return mBindStep.getState(); return mBindStep.getState();
} }
@SuppressWarnings("unused") @SuppressWarnings({"unused", "WeakerAccess"})
public final int getPreviewState() { public final int getPreviewState() {
return mPreviewStep.getState(); return mPreviewStep.getState();
} }
@ -674,6 +666,7 @@ public abstract class CameraEngine implements
try { try {
boolean success = latch.await(3, TimeUnit.SECONDS); boolean success = latch.await(3, TimeUnit.SECONDS);
if (!success) { if (!success) {
// TODO seems like this is always the case?
LOG.e("Probably some deadlock in destroy.", LOG.e("Probably some deadlock in destroy.",
"Current thread:", Thread.currentThread(), "Current thread:", Thread.currentThread(),
"Handler thread: ", mHandler.getThread()); "Handler thread: ", mHandler.getThread());
@ -790,13 +783,18 @@ public abstract class CameraEngine implements
//endregion //endregion
//region final setters //region Final setters and getters
// This is called before start() and never again. // This is called before start() and never again.
public final void setDisplayOffset(int displayOffset) { public final void setDisplayOffset(int displayOffset) {
mDisplayOffset = displayOffset; mDisplayOffset = displayOffset;
} }
@SuppressWarnings("WeakerAccess")
public final int getDisplayOffset() {
return mDisplayOffset;
}
// This can be called multiple times. // This can be called multiple times.
public final void setDeviceOrientation(int deviceOrientation) { public final void setDeviceOrientation(int deviceOrientation) {
mDeviceOrientation = deviceOrientation; mDeviceOrientation = deviceOrientation;
@ -806,44 +804,89 @@ public abstract class CameraEngine implements
mPreviewStreamSizeSelector = selector; mPreviewStreamSizeSelector = selector;
} }
@Nullable
public final SizeSelector getPreviewStreamSizeSelector() {
return mPreviewStreamSizeSelector;
}
public final void setPictureSizeSelector(@NonNull SizeSelector selector) { public final void setPictureSizeSelector(@NonNull SizeSelector selector) {
mPictureSizeSelector = selector; mPictureSizeSelector = selector;
} }
@NonNull
public final SizeSelector getPictureSizeSelector() {
return mPictureSizeSelector;
}
public final void setVideoSizeSelector(@NonNull SizeSelector selector) { public final void setVideoSizeSelector(@NonNull SizeSelector selector) {
mVideoSizeSelector = selector; mVideoSizeSelector = selector;
} }
@NonNull
public final SizeSelector getVideoSizeSelector() {
return mVideoSizeSelector;
}
public final void setVideoMaxSize(long videoMaxSizeBytes) { public final void setVideoMaxSize(long videoMaxSizeBytes) {
mVideoMaxSize = videoMaxSizeBytes; mVideoMaxSize = videoMaxSizeBytes;
} }
public final long getVideoMaxSize() {
return mVideoMaxSize;
}
public final void setVideoMaxDuration(int videoMaxDurationMillis) { public final void setVideoMaxDuration(int videoMaxDurationMillis) {
mVideoMaxDuration = videoMaxDurationMillis; mVideoMaxDuration = videoMaxDurationMillis;
} }
public final int getVideoMaxDuration() {
return mVideoMaxDuration;
}
public final void setVideoCodec(@NonNull VideoCodec codec) { public final void setVideoCodec(@NonNull VideoCodec codec) {
mVideoCodec = codec; mVideoCodec = codec;
} }
public final VideoCodec getVideoCodec() {
return mVideoCodec;
}
public final void setVideoBitRate(int videoBitRate) { public final void setVideoBitRate(int videoBitRate) {
mVideoBitRate = videoBitRate; mVideoBitRate = videoBitRate;
} }
public final int getVideoBitRate() {
return mVideoBitRate;
}
public final void setAudioBitRate(int audioBitRate) { public final void setAudioBitRate(int audioBitRate) {
mAudioBitRate = audioBitRate; mAudioBitRate = audioBitRate;
} }
public final int getAudioBitRate() {
return mAudioBitRate;
}
public final void setSnapshotMaxWidth(int maxWidth) { public final void setSnapshotMaxWidth(int maxWidth) {
mSnapshotMaxWidth = maxWidth; mSnapshotMaxWidth = maxWidth;
} }
public int getSnapshotMaxWidth() {
return mSnapshotMaxWidth;
}
public final void setSnapshotMaxHeight(int maxHeight) { public final void setSnapshotMaxHeight(int maxHeight) {
mSnapshotMaxHeight = maxHeight; mSnapshotMaxHeight = maxHeight;
} }
public int getSnapshotMaxHeight() {
return mSnapshotMaxHeight;
}
public final void setAutoFocusResetDelay(long delayMillis) { mAutoFocusResetDelayMillis = delayMillis; } public final void setAutoFocusResetDelay(long delayMillis) { mAutoFocusResetDelayMillis = delayMillis; }
public final long getAutoFocusResetDelay() { return mAutoFocusResetDelayMillis; }
/** /**
* Sets a new facing value. This will restart the session (if there's any) * Sets a new facing value. This will restart the session (if there's any)
* so that we can open the new facing camera. * so that we can open the new facing camera.
@ -867,6 +910,11 @@ public abstract class CameraEngine implements
} }
} }
@NonNull
public final Facing getFacing() {
return mFacing;
}
/** /**
* Sets a new audio value that will be used for video recordings. * Sets a new audio value that will be used for video recordings.
* @param audio desired audio * @param audio desired audio
@ -881,6 +929,11 @@ public abstract class CameraEngine implements
} }
} }
@NonNull
public final Audio getAudio() {
return mAudio;
}
/** /**
* Sets the desired mode (either picture or video). * Sets the desired mode (either picture or video).
* @param mode desired mode. * @param mode desired mode.
@ -899,6 +952,64 @@ public abstract class CameraEngine implements
} }
} }
@NonNull
public final Mode getMode() {
return mMode;
}
@NonNull
public final FrameManager getFrameManager() {
return mFrameManager;
}
@Nullable
public final CameraOptions getCameraOptions() {
return mCameraOptions;
}
@NonNull
public final Flash getFlash() {
return mFlash;
}
@NonNull
public final WhiteBalance getWhiteBalance() {
return mWhiteBalance;
}
@NonNull
public final Hdr getHdr() {
return mHdr;
}
@Nullable
public final Location getLocation() {
return mLocation;
}
public final float getZoomValue() {
return mZoomValue;
}
public final float getExposureCorrectionValue() {
return mExposureCorrectionValue;
}
@CallSuper
public void setHasFrameProcessors(boolean hasFrameProcessors) {
mHasFrameProcessors = hasFrameProcessors;
}
@SuppressWarnings("WeakerAccess")
public final boolean hasFrameProcessors() {
return mHasFrameProcessors;
}
@SuppressWarnings("WeakerAccess")
protected final boolean shouldResetAutoFocus() {
return mAutoFocusResetDelayMillis > 0 && mAutoFocusResetDelayMillis != Long.MAX_VALUE;
}
//endregion //endregion
//region Abstract setters and APIs //region Abstract setters and APIs
@ -945,12 +1056,14 @@ 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
public final boolean isTakingPicture() {
return mPictureRecorder != null;
}
/* not final for tests */ /* not final for tests */
public void takePicture(final @NonNull PictureResult.Stub stub) { public void takePicture(final @NonNull PictureResult.Stub stub) {
LOG.v("takePicture", "scheduling"); LOG.v("takePicture", "scheduling");
@ -970,7 +1083,7 @@ public abstract class CameraEngine implements
onTakePicture(stub); onTakePicture(stub);
} }
}); });
}; }
/** /**
* The snapshot size is the {@link #getPreviewStreamSize(int)}, but cropped based on the * The snapshot size is the {@link #getPreviewStreamSize(int)}, but cropped based on the
@ -1014,6 +1127,10 @@ public abstract class CameraEngine implements
} }
} }
public final boolean isTakingVideo() {
return mVideoRecorder != null && mVideoRecorder.isRecording();
}
public final void takeVideo(final @NonNull VideoResult.Stub stub, final @NonNull File file) { public final void takeVideo(final @NonNull VideoResult.Stub stub, final @NonNull File file) {
LOG.v("takeVideo", "scheduling"); LOG.v("takeVideo", "scheduling");
mHandler.run(new Runnable() { mHandler.run(new Runnable() {
@ -1110,120 +1227,6 @@ public abstract class CameraEngine implements
//endregion //endregion
//region final getters
@NonNull
public final FrameManager getFrameManager() {
return mFrameManager;
}
@Nullable
public final CameraOptions getCameraOptions() {
return mCameraOptions;
}
@NonNull
public final Facing getFacing() {
return mFacing;
}
@NonNull
public final Flash getFlash() {
return mFlash;
}
@NonNull
public final WhiteBalance getWhiteBalance() {
return mWhiteBalance;
}
public final VideoCodec getVideoCodec() {
return mVideoCodec;
}
public final int getVideoBitRate() {
return mVideoBitRate;
}
public final long getVideoMaxSize() {
return mVideoMaxSize;
}
public final int getVideoMaxDuration() {
return mVideoMaxDuration;
}
@NonNull
public final Mode getMode() {
return mMode;
}
@NonNull
public final Hdr getHdr() {
return mHdr;
}
@Nullable
public final Location getLocation() {
return mLocation;
}
@NonNull
public final Audio getAudio() {
return mAudio;
}
public final int getAudioBitRate() {
return mAudioBitRate;
}
@SuppressWarnings("unused")
@Nullable
@VisibleForTesting
final SizeSelector getPreviewStreamSizeSelector() {
return mPreviewStreamSizeSelector;
}
@SuppressWarnings("unused")
@NonNull
public final SizeSelector getPictureSizeSelector() {
return mPictureSizeSelector;
}
@SuppressWarnings("unused")
@NonNull
public final SizeSelector getVideoSizeSelector() {
return mVideoSizeSelector;
}
public final float getZoomValue() {
return mZoomValue;
}
public final float getExposureCorrectionValue() {
return mExposureCorrectionValue;
}
public final boolean isTakingVideo() {
return mVideoRecorder != null && mVideoRecorder.isRecording();
}
public final boolean isTakingPicture() {
return mPictureRecorder != null;
}
public final long getAutoFocusResetDelay() { return mAutoFocusResetDelayMillis; }
public boolean getHasFrameProcessors() {
return mHasFrameProcessors;
}
//endregion
final boolean shouldResetAutoFocus() {
return mAutoFocusResetDelayMillis > 0 && mAutoFocusResetDelayMillis != Long.MAX_VALUE;
}
//region Orientation utils //region Orientation utils
private int computeSensorToViewOffset() { private int computeSensorToViewOffset() {

@ -4,7 +4,6 @@ import android.content.Context;
import android.graphics.PointF; import android.graphics.PointF;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.widget.FrameLayout;
/** /**
* Base class for gesture finders. * Base class for gesture finders.
@ -165,4 +164,13 @@ public abstract class GestureFinder {
} }
return newValue; return newValue;
} }
/**
* Returns the controller for this finder.
* @return the controller
*/
@NonNull
protected Controller getController() {
return mController;
}
} }

Loading…
Cancel
Save