|
|
@ -47,7 +47,6 @@ import androidx.annotation.CallSuper; |
|
|
|
import androidx.annotation.NonNull; |
|
|
|
import androidx.annotation.NonNull; |
|
|
|
import androidx.annotation.Nullable; |
|
|
|
import androidx.annotation.Nullable; |
|
|
|
import androidx.annotation.VisibleForTesting; |
|
|
|
import androidx.annotation.VisibleForTesting; |
|
|
|
import androidx.annotation.WorkerThread; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
@ -303,7 +302,7 @@ public abstract class CameraEngine implements |
|
|
|
|
|
|
|
|
|
|
|
final CameraException cameraException = (CameraException) throwable; |
|
|
|
final CameraException cameraException = (CameraException) throwable; |
|
|
|
LOG.e("uncaughtException:", "Got CameraException:", cameraException, |
|
|
|
LOG.e("uncaughtException:", "Got CameraException:", cameraException, |
|
|
|
"on engine state:", getEngineStateName()); |
|
|
|
"on engine state:", getEngineState()); |
|
|
|
if (fromExceptionHandler) { |
|
|
|
if (fromExceptionHandler) { |
|
|
|
// Got to restart the handler.
|
|
|
|
// Got to restart the handler.
|
|
|
|
thread.interrupt(); |
|
|
|
thread.interrupt(); |
|
|
@ -336,11 +335,6 @@ public abstract class CameraEngine implements |
|
|
|
return mPreviewStep.getState(); |
|
|
|
return mPreviewStep.getState(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
|
|
|
|
private String getEngineStateName() { |
|
|
|
|
|
|
|
return mEngineStep.getStateName(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean canStartEngine() { |
|
|
|
private boolean canStartEngine() { |
|
|
|
return mEngineStep.isStoppingOrStopped(); |
|
|
|
return mEngineStep.isStoppingOrStopped(); |
|
|
|
} |
|
|
|
} |
|
|
@ -375,7 +369,7 @@ public abstract class CameraEngine implements |
|
|
|
//region Start & Stop the engine
|
|
|
|
//region Start & Stop the engine
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
@WorkerThread |
|
|
|
@EngineThread |
|
|
|
private Task<Void> startEngine() { |
|
|
|
private Task<Void> startEngine() { |
|
|
|
if (canStartEngine()) { |
|
|
|
if (canStartEngine()) { |
|
|
|
mEngineStep.doStart(false, new Callable<Task<Void>>() { |
|
|
|
mEngineStep.doStart(false, new Callable<Task<Void>>() { |
|
|
@ -398,7 +392,7 @@ public abstract class CameraEngine implements |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
@WorkerThread |
|
|
|
@EngineThread |
|
|
|
private Task<Void> stopEngine(boolean swallowExceptions) { |
|
|
|
private Task<Void> stopEngine(boolean swallowExceptions) { |
|
|
|
if (needsStopEngine()) { |
|
|
|
if (needsStopEngine()) { |
|
|
|
mEngineStep.doStop(swallowExceptions, new Callable<Task<Void>>() { |
|
|
|
mEngineStep.doStop(swallowExceptions, new Callable<Task<Void>>() { |
|
|
@ -421,7 +415,7 @@ public abstract class CameraEngine implements |
|
|
|
* @return a task |
|
|
|
* @return a task |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
@WorkerThread |
|
|
|
@EngineThread |
|
|
|
protected abstract Task<Void> onStartEngine(); |
|
|
|
protected abstract Task<Void> onStartEngine(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -431,7 +425,7 @@ public abstract class CameraEngine implements |
|
|
|
* @return a task |
|
|
|
* @return a task |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
@WorkerThread |
|
|
|
@EngineThread |
|
|
|
protected abstract Task<Void> onStopEngine(); |
|
|
|
protected abstract Task<Void> onStopEngine(); |
|
|
|
|
|
|
|
|
|
|
|
//endregion
|
|
|
|
//endregion
|
|
|
@ -439,7 +433,7 @@ public abstract class CameraEngine implements |
|
|
|
//region Start & Stop binding
|
|
|
|
//region Start & Stop binding
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
@WorkerThread |
|
|
|
@EngineThread |
|
|
|
private Task<Void> startBind() { |
|
|
|
private Task<Void> startBind() { |
|
|
|
if (canStartBind()) { |
|
|
|
if (canStartBind()) { |
|
|
|
mBindStep.doStart(false, new Callable<Task<Void>>() { |
|
|
|
mBindStep.doStart(false, new Callable<Task<Void>>() { |
|
|
@ -453,7 +447,7 @@ public abstract class CameraEngine implements |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
@WorkerThread |
|
|
|
@EngineThread |
|
|
|
private Task<Void> stopBind(boolean swallowExceptions) { |
|
|
|
private Task<Void> stopBind(boolean swallowExceptions) { |
|
|
|
if (needsStopBind()) { |
|
|
|
if (needsStopBind()) { |
|
|
|
mBindStep.doStop(swallowExceptions, new Callable<Task<Void>>() { |
|
|
|
mBindStep.doStop(swallowExceptions, new Callable<Task<Void>>() { |
|
|
@ -471,7 +465,7 @@ public abstract class CameraEngine implements |
|
|
|
* @return a task |
|
|
|
* @return a task |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
@WorkerThread |
|
|
|
@EngineThread |
|
|
|
protected abstract Task<Void> onStartBind(); |
|
|
|
protected abstract Task<Void> onStartBind(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -481,7 +475,7 @@ public abstract class CameraEngine implements |
|
|
|
* @return a task |
|
|
|
* @return a task |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
@WorkerThread |
|
|
|
@EngineThread |
|
|
|
protected abstract Task<Void> onStopBind(); |
|
|
|
protected abstract Task<Void> onStopBind(); |
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("WeakerAccess") |
|
|
|
@SuppressWarnings("WeakerAccess") |
|
|
@ -522,7 +516,7 @@ public abstract class CameraEngine implements |
|
|
|
//region Start & Stop preview
|
|
|
|
//region Start & Stop preview
|
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
@WorkerThread |
|
|
|
@EngineThread |
|
|
|
private Task<Void> startPreview() { |
|
|
|
private Task<Void> startPreview() { |
|
|
|
LOG.i("startPreview", "canStartPreview:", canStartPreview()); |
|
|
|
LOG.i("startPreview", "canStartPreview:", canStartPreview()); |
|
|
|
if (canStartPreview()) { |
|
|
|
if (canStartPreview()) { |
|
|
@ -537,7 +531,7 @@ public abstract class CameraEngine implements |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
@WorkerThread |
|
|
|
@EngineThread |
|
|
|
private Task<Void> stopPreview(boolean swallowExceptions) { |
|
|
|
private Task<Void> stopPreview(boolean swallowExceptions) { |
|
|
|
LOG.i("stopPreview", |
|
|
|
LOG.i("stopPreview", |
|
|
|
"needsStopPreview:", needsStopPreview(), |
|
|
|
"needsStopPreview:", needsStopPreview(), |
|
|
@ -571,7 +565,7 @@ public abstract class CameraEngine implements |
|
|
|
* @return a task |
|
|
|
* @return a task |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
@WorkerThread |
|
|
|
@EngineThread |
|
|
|
protected abstract Task<Void> onStartPreview(); |
|
|
|
protected abstract Task<Void> onStartPreview(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -581,7 +575,7 @@ public abstract class CameraEngine implements |
|
|
|
* @return a task |
|
|
|
* @return a task |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
@WorkerThread |
|
|
|
@EngineThread |
|
|
|
protected abstract Task<Void> onStopPreview(); |
|
|
|
protected abstract Task<Void> onStopPreview(); |
|
|
|
|
|
|
|
|
|
|
|
//endregion
|
|
|
|
//endregion
|
|
|
@ -643,7 +637,7 @@ public abstract class CameraEngine implements |
|
|
|
* |
|
|
|
* |
|
|
|
* It basically depends on the step at which the preview stream size is actually used. |
|
|
|
* It basically depends on the step at which the preview stream size is actually used. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@WorkerThread |
|
|
|
@EngineThread |
|
|
|
protected abstract void onPreviewStreamSizeChanged(); |
|
|
|
protected abstract void onPreviewStreamSizeChanged(); |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -676,7 +670,7 @@ public abstract class CameraEngine implements |
|
|
|
* that would cause deadlocks due to us awaiting for {@link #stop()} to return. |
|
|
|
* that would cause deadlocks due to us awaiting for {@link #stop()} to return. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void destroy() { |
|
|
|
public void destroy() { |
|
|
|
LOG.i("destroy:", "state:", getEngineStateName(), "thread:", Thread.currentThread()); |
|
|
|
LOG.i("destroy:", "state:", getEngineState(), "thread:", Thread.currentThread()); |
|
|
|
// Prevent CameraEngine leaks. Don't set to null, or exceptions
|
|
|
|
// Prevent CameraEngine leaks. Don't set to null, or exceptions
|
|
|
|
// inside the standard stop() method might crash the main thread.
|
|
|
|
// inside the standard stop() method might crash the main thread.
|
|
|
|
mHandler.getThread().setUncaughtExceptionHandler(new NoOpExceptionHandler()); |
|
|
|
mHandler.getThread().setUncaughtExceptionHandler(new NoOpExceptionHandler()); |
|
|
@ -710,7 +704,7 @@ public abstract class CameraEngine implements |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
public Task<Void> start() { |
|
|
|
public Task<Void> start() { |
|
|
|
LOG.i("Start:", "posting runnable. State:", getEngineStateName()); |
|
|
|
LOG.i("Start:", "posting runnable. State:", getEngineState()); |
|
|
|
final TaskCompletionSource<Void> outTask = new TaskCompletionSource<>(); |
|
|
|
final TaskCompletionSource<Void> outTask = new TaskCompletionSource<>(); |
|
|
|
mHandler.run(new Runnable() { |
|
|
|
mHandler.run(new Runnable() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -765,7 +759,7 @@ public abstract class CameraEngine implements |
|
|
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
private Task<Void> stop(final boolean swallowExceptions) { |
|
|
|
private Task<Void> stop(final boolean swallowExceptions) { |
|
|
|
LOG.i("Stop:", "posting runnable. State:", getEngineStateName()); |
|
|
|
LOG.i("Stop:", "posting runnable. State:", getEngineState()); |
|
|
|
final TaskCompletionSource<Void> outTask = new TaskCompletionSource<>(); |
|
|
|
final TaskCompletionSource<Void> outTask = new TaskCompletionSource<>(); |
|
|
|
mHandler.run(new Runnable() { |
|
|
|
mHandler.run(new Runnable() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -1077,6 +1071,7 @@ public abstract class CameraEngine implements |
|
|
|
* @param facing the facing value |
|
|
|
* @param facing the facing value |
|
|
|
* @return true if we have one |
|
|
|
* @return true if we have one |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@EngineThread |
|
|
|
protected abstract boolean collectCameraInfo(@NonNull Facing facing); |
|
|
|
protected abstract boolean collectCameraInfo(@NonNull Facing facing); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -1256,6 +1251,7 @@ public abstract class CameraEngine implements |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@EngineThread |
|
|
|
@SuppressWarnings("WeakerAccess") |
|
|
|
@SuppressWarnings("WeakerAccess") |
|
|
|
protected void onStopVideo() { |
|
|
|
protected void onStopVideo() { |
|
|
|
if (mVideoRecorder != null) { |
|
|
|
if (mVideoRecorder != null) { |
|
|
@ -1289,19 +1285,19 @@ public abstract class CameraEngine implements |
|
|
|
mCallback.dispatchOnVideoRecordingEnd(); |
|
|
|
mCallback.dispatchOnVideoRecordingEnd(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@WorkerThread |
|
|
|
@EngineThread |
|
|
|
protected abstract void onTakePicture(@NonNull PictureResult.Stub stub, boolean doMetering); |
|
|
|
protected abstract void onTakePicture(@NonNull PictureResult.Stub stub, boolean doMetering); |
|
|
|
|
|
|
|
|
|
|
|
@WorkerThread |
|
|
|
@EngineThread |
|
|
|
protected abstract void onTakePictureSnapshot(@NonNull PictureResult.Stub stub, |
|
|
|
protected abstract void onTakePictureSnapshot(@NonNull PictureResult.Stub stub, |
|
|
|
@NonNull AspectRatio outputRatio, |
|
|
|
@NonNull AspectRatio outputRatio, |
|
|
|
boolean doMetering); |
|
|
|
boolean doMetering); |
|
|
|
|
|
|
|
|
|
|
|
@WorkerThread |
|
|
|
@EngineThread |
|
|
|
protected abstract void onTakeVideoSnapshot(@NonNull VideoResult.Stub stub, |
|
|
|
protected abstract void onTakeVideoSnapshot(@NonNull VideoResult.Stub stub, |
|
|
|
@NonNull AspectRatio outputRatio); |
|
|
|
@NonNull AspectRatio outputRatio); |
|
|
|
|
|
|
|
|
|
|
|
@WorkerThread |
|
|
|
@EngineThread |
|
|
|
protected abstract void onTakeVideo(@NonNull VideoResult.Stub stub); |
|
|
|
protected abstract void onTakeVideo(@NonNull VideoResult.Stub stub); |
|
|
|
|
|
|
|
|
|
|
|
//endregion
|
|
|
|
//endregion
|
|
|
@ -1430,9 +1426,11 @@ public abstract class CameraEngine implements |
|
|
|
* we can be sure that the camera is available (engineState == STARTED). |
|
|
|
* we can be sure that the camera is available (engineState == STARTED). |
|
|
|
* @return a list of available sizes for preview |
|
|
|
* @return a list of available sizes for preview |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
@EngineThread |
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
protected abstract List<Size> getPreviewStreamAvailableSizes(); |
|
|
|
protected abstract List<Size> getPreviewStreamAvailableSizes(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@EngineThread |
|
|
|
@NonNull |
|
|
|
@NonNull |
|
|
|
@SuppressWarnings("WeakerAccess") |
|
|
|
@SuppressWarnings("WeakerAccess") |
|
|
|
protected final Size computePreviewStreamSize() { |
|
|
|
protected final Size computePreviewStreamSize() { |
|
|
|