|
36 | 36 | import android.os.Build.VERSION_CODES;
|
37 | 37 | import android.os.Handler;
|
38 | 38 | import android.os.Looper;
|
| 39 | +import android.os.SystemClock; |
39 | 40 | import android.util.Log;
|
40 | 41 | import android.util.Range;
|
41 | 42 | import android.util.Rational;
|
@@ -73,6 +74,9 @@ interface ErrorCallback {
|
73 | 74 | public class Camera {
|
74 | 75 | private static final String TAG = "Camera";
|
75 | 76 |
|
| 77 | + /** Timeout for the pre-capture sequence. */ |
| 78 | + private static final long PRECAPTURE_TIMEOUT_MS = 1000; |
| 79 | + |
76 | 80 | private final SurfaceTextureEntry flutterTexture;
|
77 | 81 | private final CameraManager cameraManager;
|
78 | 82 | private final DeviceOrientationManager deviceOrientationListener;
|
@@ -105,6 +109,7 @@ public class Camera {
|
105 | 109 | private boolean useAutoFocus = true;
|
106 | 110 | private Range<Integer> fpsRange;
|
107 | 111 | private PlatformChannel.DeviceOrientation lockedCaptureOrientation;
|
| 112 | + private long preCaptureStartTime; |
108 | 113 |
|
109 | 114 | private static final HashMap<String, Integer> supportedImageFormats;
|
110 | 115 | // Current supported outputs
|
@@ -503,11 +508,16 @@ private void processCapture(CaptureResult result) {
|
503 | 508 | || aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED
|
504 | 509 | || aeState == CaptureRequest.CONTROL_AE_STATE_CONVERGED) {
|
505 | 510 | pictureCaptureRequest.setState(State.waitingPreCaptureReady);
|
| 511 | + setPreCaptureStartTime(); |
506 | 512 | }
|
507 | 513 | break;
|
508 | 514 | case waitingPreCaptureReady:
|
509 | 515 | if (aeState == null || aeState != CaptureRequest.CONTROL_AE_STATE_PRECAPTURE) {
|
510 | 516 | runPictureCapture();
|
| 517 | + } else { |
| 518 | + if (hitPreCaptureTimeout()) { |
| 519 | + unlockAutoFocus(); |
| 520 | + } |
511 | 521 | }
|
512 | 522 | }
|
513 | 523 | }
|
@@ -1142,6 +1152,20 @@ public void stopImageStream() throws CameraAccessException {
|
1142 | 1152 | startPreview();
|
1143 | 1153 | }
|
1144 | 1154 |
|
| 1155 | + /** Sets the time the pre-capture sequence started. */ |
| 1156 | + private void setPreCaptureStartTime() { |
| 1157 | + preCaptureStartTime = SystemClock.elapsedRealtime(); |
| 1158 | + } |
| 1159 | + |
| 1160 | + /** |
| 1161 | + * Check if the timeout for the pre-capture sequence has been reached. |
| 1162 | + * |
| 1163 | + * @return true if the timeout is reached; otherwise false is returned. |
| 1164 | + */ |
| 1165 | + private boolean hitPreCaptureTimeout() { |
| 1166 | + return (SystemClock.elapsedRealtime() - preCaptureStartTime) > PRECAPTURE_TIMEOUT_MS; |
| 1167 | + } |
| 1168 | + |
1145 | 1169 | private void closeCaptureSession() {
|
1146 | 1170 | if (cameraCaptureSession != null) {
|
1147 | 1171 | cameraCaptureSession.close();
|
|
0 commit comments