Improve logic, check focusLock when releasing

pull/521/head
Mattia Iavarone 6 years ago
parent e4b0b5cda5
commit 014fd9dcd1
  1. 18
      cameraview/src/main/java/com/otaliastudios/cameraview/picture/Full2PictureRecorder.java

@ -193,6 +193,9 @@ public class Full2PictureRecorder extends PictureRecorder implements ImageReader
Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE); Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
if (aeState == null if (aeState == null
|| aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE || aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE
// The one above is a transient state, which means it might not be reported
// by the camera. So in addition let's also check for the precature end states.
|| aeState == CaptureRequest.CONTROL_AE_STATE_CONVERGED
|| aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) { || aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) {
mState = STATE_WAITING_PRECAPTURE_END; mState = STATE_WAITING_PRECAPTURE_END;
} }
@ -201,7 +204,15 @@ public class Full2PictureRecorder extends PictureRecorder implements ImageReader
case STATE_WAITING_PRECAPTURE_END: { case STATE_WAITING_PRECAPTURE_END: {
Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE); Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
if (aeState == null if (aeState == null
|| aeState != CaptureResult.CONTROL_AE_STATE_PRECAPTURE) { || aeState == CaptureRequest.CONTROL_AE_STATE_CONVERGED
|| aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED
// The two above are the correct states. However, just for safety, and
// since we got STATE_WAITING_PRECAPTURE_START already, let's accept anything
// other than the precapturing state. We don't want to get stuck here.
|| aeState == CaptureRequest.CONTROL_AE_STATE_SEARCHING // Camera is in normal AE routine. Should never happen.
|| aeState == CaptureRequest.CONTROL_AE_STATE_INACTIVE // AE is OFF. Should never happen.
|| aeState == CaptureResult.CONTROL_AE_STATE_LOCKED // AE has been locked. Should never happen.
) {
runCapture(); runCapture();
} }
break; break;
@ -250,11 +261,14 @@ public class Full2PictureRecorder extends PictureRecorder implements ImageReader
} catch (IOException ignore) { } } catch (IOException ignore) { }
// Before leaving, unlock focus. // Before leaving, unlock focus.
if (supportsFocusLock()) {
try { try {
mBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, mBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
CaptureRequest.CONTROL_AF_TRIGGER_CANCEL); CaptureRequest.CONTROL_AF_TRIGGER_CANCEL);
mSession.capture(mBuilder.build(), mCallback, null); mSession.capture(mBuilder.build(), mCallback, null);
} catch (CameraAccessException ignore) { } } catch (CameraAccessException ignore) {
}
}
// Leave. // Leave.
LOG.i("onImageAvailable ended."); LOG.i("onImageAvailable ended.");

Loading…
Cancel
Save