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

@ -33,9 +33,7 @@ import java.util.List;
* - Call {@link #startMetering(CaptureResult, PointF, boolean)} to start * - Call {@link #startMetering(CaptureResult, PointF, boolean)} to start
* - Call {@link #onCapture(CaptureResult)} when they have partial or total results, as long as the * - 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()} * 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 * - Call {@link #resetMetering()} to reset the metering parameters if needed.
* 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.
*/ */
@RequiresApi(Build.VERSION_CODES.LOLLIPOP) @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public class Meter { public class Meter {
@ -349,19 +347,13 @@ public class Meter {
private void onMeteringEnd(boolean success) { private void onMeteringEnd(boolean success) {
mCallback.onMeteringEnd(mPoint, success); mCallback.onMeteringEnd(mPoint, success);
mIsMetering = false; 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 * Can be called to perform the reset.
* specified by the {@link CameraEngine} reset delay.
*/ */
@SuppressWarnings("WeakerAccess") @SuppressWarnings("WeakerAccess")
public void resetMetering() { public void resetMetering() {
mEngine.mHandler.remove(mResetRunnable);
LOG.i("Resetting the meter parameters."); LOG.i("Resetting the meter parameters.");
MeteringRectangle whole = null; MeteringRectangle whole = null;
if (mPoint != null) { if (mPoint != null) {
@ -375,11 +367,4 @@ public class Meter {
mAutoExposure.resetMetering(mCharacteristics, mCallback.getMeteringBuilder(), whole); mAutoExposure.resetMetering(mCharacteristics, mCallback.getMeteringBuilder(), whole);
mCallback.onMeteringReset(mPoint); mCallback.onMeteringReset(mPoint);
} }
private Runnable mResetRunnable = new Runnable() {
@Override
public void run() {
resetMetering();
}
};
} }

Loading…
Cancel
Save