Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added timeout for waiting pre-capture state Android
  • Loading branch information
mvanbeusekom committed Feb 17, 2021
commit abfa9a1c4cc1d9c0a6cc50f02c35066850364d80
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import android.os.Build.VERSION_CODES;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import android.util.Log;
import android.util.Range;
import android.util.Rational;
Expand Down Expand Up @@ -73,6 +74,11 @@ interface ErrorCallback {
public class Camera {
private static final String TAG = "Camera";

/**
* Timeout for the pre-capture sequence.
*/
private static final long PRECAPTURE_TIMEOUT_MS = 1000;

private final SurfaceTextureEntry flutterTexture;
private final CameraManager cameraManager;
private final DeviceOrientationManager deviceOrientationListener;
Expand Down Expand Up @@ -105,6 +111,7 @@ public class Camera {
private boolean useAutoFocus = true;
private Range<Integer> fpsRange;
private PlatformChannel.DeviceOrientation lockedCaptureOrientation;
private long preCaptureStartTime;

private static final HashMap<String, Integer> supportedImageFormats;
// Current supported outputs
Expand Down Expand Up @@ -503,11 +510,16 @@ private void processCapture(CaptureResult result) {
|| aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED
|| aeState == CaptureRequest.CONTROL_AE_STATE_CONVERGED) {
pictureCaptureRequest.setState(State.waitingPreCaptureReady);
setPreCaptureStartTime();
}
break;
case waitingPreCaptureReady:
if (aeState == null || aeState != CaptureRequest.CONTROL_AE_STATE_PRECAPTURE) {
runPictureCapture();
} else {
if (hitPreCaptureTimeout()) {
unlockAutoFocus();
}
}
}
}
Expand Down Expand Up @@ -1142,6 +1154,22 @@ public void stopImageStream() throws CameraAccessException {
startPreview();
}

/**
* Sets the time the pre-capture sequence started.
*/
private void setPreCaptureStartTime() {
preCaptureStartTime = SystemClock.elapsedRealtime();
}

/**
* Check if the timeout for the pre-capture sequence has been reached.
*
* @return true if the timeout is reached; otherwise false is returned.
*/
private boolean hitPreCaptureTimeout() {
return (SystemClock.elapsedRealtime() - preCaptureStartTime) > PRECAPTURE_TIMEOUT_MS;
}

private void closeCaptureSession() {
if (cameraCaptureSession != null) {
cameraCaptureSession.close();
Expand Down