Implement reset delay in Camera2Engine instead of Meter

pull/580/head
Mattia Iavarone 6 years ago
parent d1acae558e
commit 1e5bb27cc2
  1. 45
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera2Engine.java
  2. 19
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Meter.java

@ -558,14 +558,7 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv
mVideoRecorder = null;
}
mPictureRecorder = null;
if (mMeter != null) {
mMeter.resetMetering();
mMeter = null;
}
if (mLocker != null) {
mLocker.unlock();
mLocker = null;
}
mMeteringResetRunnable.run();
if (hasFrameProcessors()) {
getFrameManager().release();
}
@ -694,14 +687,7 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv
boolean unlock = (fullPicture && getPictureMetering()) ||
(!fullPicture && getPictureSnapshotMetering());
if (unlock) {
if (mLocker != null) {
mLocker.unlock();
mLocker = null;
}
if (mMeter != null) {
mMeter.resetMetering();
mMeter = null;
}
mMeteringResetRunnable.run();
}
}
@ -1232,14 +1218,7 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv
if (point != null && !mCameraOptions.isAutoFocusSupported()) return;
// Reset the old meter and locker if present.
if (mLocker != null) {
mLocker.unlock();
mLocker = null;
}
if (mMeter != null) {
mMeter.resetMetering();
mMeter = null;
}
mMeteringResetRunnable.run();
// The meter will check the current configuration to see if AF/AE/AWB should run.
// - AE should be on CONTROL_AE_MODE_ON* (this depends on setFlash())
@ -1260,6 +1239,20 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv
});
}
private final Runnable mMeteringResetRunnable = new Runnable() {
@Override
public void run() {
if (mLocker != null) {
mLocker.unlock();
mLocker = null;
}
if (mMeter != null) {
mMeter.resetMetering();
mMeter = null;
}
}
};
/**
* Called by {@link Meter} when the metering process has started.
* We are currently exposing an auto focus API so that's what we dispatch.
@ -1305,6 +1298,10 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv
LOG.w("onLocked - point:", point, "gesture:", mMeteringGesture, "success:", success);
if (point != null) {
mCallback.dispatchOnFocusEnd(mMeteringGesture, success, point);
mHandler.remove(mMeteringResetRunnable);
if (shouldResetAutoFocus()) {
mHandler.post(getAutoFocusResetDelay(), mMeteringResetRunnable);
}
} else {
LOG.w("onLocked - restoring the picture capturing. isSnapshot:", mDelayedPictureStub.isSnapshot);
if (mDelayedPictureStub.isSnapshot) {

@ -33,9 +33,7 @@ import java.util.List;
* - Call {@link #startMetering(CaptureResult, PointF, boolean)} to start
* - Call {@link #onCapture(CaptureResult)} when they have partial or total results, as long as the
* meter is still in a metering operation, which can be checked through {@link #isMetering()}
* - Call {@link #resetMetering()} to reset the metering parameters if needed. This is done automatically
* by the meter based on the reset delay configuration in the engine, but can be called explicitly
* for example when we have multiple meter requests and want to cancel the old one.
* - Call {@link #resetMetering()} to reset the metering parameters if needed.
*/
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public class Meter {
@ -349,19 +347,13 @@ public class Meter {
private void onMeteringEnd(boolean success) {
mCallback.onMeteringEnd(mPoint, success);
mIsMetering = false;
mEngine.mHandler.remove(mResetRunnable);
if (mEngine.shouldResetAutoFocus()) {
mEngine.mHandler.post(mEngine.getAutoFocusResetDelay(), mResetRunnable);
}
}
/**
* Can be called to perform the reset at a time different than the one
* specified by the {@link CameraEngine} reset delay.
* Can be called to perform the reset.
*/
@SuppressWarnings("WeakerAccess")
public void resetMetering() {
mEngine.mHandler.remove(mResetRunnable);
LOG.i("Resetting the meter parameters.");
MeteringRectangle whole = null;
if (mPoint != null) {
@ -375,11 +367,4 @@ public class Meter {
mAutoExposure.resetMetering(mCharacteristics, mCallback.getMeteringBuilder(), whole);
mCallback.onMeteringReset(mPoint);
}
private Runnable mResetRunnable = new Runnable() {
@Override
public void run() {
resetMetering();
}
};
}

Loading…
Cancel
Save