|
|
@ -104,6 +104,9 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv |
|
|
|
|
|
|
|
|
|
|
|
// 3A metering
|
|
|
|
// 3A metering
|
|
|
|
private Meter mMeter; |
|
|
|
private Meter mMeter; |
|
|
|
|
|
|
|
private Gesture mMeteringGesture; |
|
|
|
|
|
|
|
private PictureResult.Stub mDelayedPictureStub; |
|
|
|
|
|
|
|
private AspectRatio mDelayedPictureRatio; |
|
|
|
|
|
|
|
|
|
|
|
public Camera2Engine(Callback callback) { |
|
|
|
public Camera2Engine(Callback callback) { |
|
|
|
super(callback); |
|
|
|
super(callback); |
|
|
@ -613,18 +616,31 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv |
|
|
|
protected void onTakePictureSnapshot(@NonNull PictureResult.Stub stub, @NonNull AspectRatio outputRatio, boolean doMetering) { |
|
|
|
protected void onTakePictureSnapshot(@NonNull PictureResult.Stub stub, @NonNull AspectRatio outputRatio, boolean doMetering) { |
|
|
|
stub.size = getUncroppedSnapshotSize(Reference.OUTPUT); // Not the real size: it will be cropped to match the view ratio
|
|
|
|
stub.size = getUncroppedSnapshotSize(Reference.OUTPUT); // Not the real size: it will be cropped to match the view ratio
|
|
|
|
stub.rotation = getAngles().offset(Reference.SENSOR, Reference.OUTPUT, Axis.RELATIVE_TO_SENSOR); // Actually it will be rotated and set to 0.
|
|
|
|
stub.rotation = getAngles().offset(Reference.SENSOR, Reference.OUTPUT, Axis.RELATIVE_TO_SENSOR); // Actually it will be rotated and set to 0.
|
|
|
|
if (mPreview instanceof GlCameraPreview) { |
|
|
|
if (doMetering) { |
|
|
|
mPictureRecorder = new SnapshotGlPictureRecorder(stub, this, (GlCameraPreview) mPreview, outputRatio, getOverlay()); |
|
|
|
mDelayedPictureStub = stub; |
|
|
|
|
|
|
|
mDelayedPictureRatio = outputRatio; |
|
|
|
|
|
|
|
startMetering(null, null); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
if (!(mPreview instanceof GlCameraPreview)) { |
|
|
|
throw new RuntimeException("takePictureSnapshot with Camera2 is only supported with Preview.GL_SURFACE"); |
|
|
|
throw new RuntimeException("takePictureSnapshot with Camera2 is only supported with Preview.GL_SURFACE"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
mPictureRecorder = new SnapshotGlPictureRecorder(stub, this, |
|
|
|
|
|
|
|
(GlCameraPreview) mPreview, |
|
|
|
|
|
|
|
outputRatio, |
|
|
|
|
|
|
|
getOverlay()); |
|
|
|
mPictureRecorder.take(); |
|
|
|
mPictureRecorder.take(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void onTakePicture(@NonNull PictureResult.Stub stub, boolean doMetering) { |
|
|
|
protected void onTakePicture(@NonNull PictureResult.Stub stub, boolean doMetering) { |
|
|
|
stub.rotation = getAngles().offset(Reference.SENSOR, Reference.OUTPUT, Axis.RELATIVE_TO_SENSOR); |
|
|
|
stub.rotation = getAngles().offset(Reference.SENSOR, Reference.OUTPUT, Axis.RELATIVE_TO_SENSOR); |
|
|
|
stub.size = getPictureSize(Reference.OUTPUT); |
|
|
|
stub.size = getPictureSize(Reference.OUTPUT); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (doMetering) { |
|
|
|
|
|
|
|
mDelayedPictureStub = stub; |
|
|
|
|
|
|
|
startMetering(null, null); |
|
|
|
|
|
|
|
} else { |
|
|
|
try { |
|
|
|
try { |
|
|
|
CaptureRequest.Builder builder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE); |
|
|
|
CaptureRequest.Builder builder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE); |
|
|
|
applyAllParameters(builder); |
|
|
|
applyAllParameters(builder); |
|
|
@ -639,6 +655,7 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv |
|
|
|
throw createCameraException(e); |
|
|
|
throw createCameraException(e); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onPictureResult(@Nullable PictureResult.Stub result, @Nullable Exception error) { |
|
|
|
public void onPictureResult(@Nullable PictureResult.Stub result, @Nullable Exception error) { |
|
|
@ -1136,11 +1153,10 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void startAutoFocus(@Nullable final Gesture gesture, @NonNull final PointF point) { |
|
|
|
public void startAutoFocus(@Nullable final Gesture gesture, @NonNull final PointF point) { |
|
|
|
// TODO Should change this name at some point, and deprecate AF methods
|
|
|
|
|
|
|
|
startMetering(gesture, point); |
|
|
|
startMetering(gesture, point); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void startMetering(@Nullable final Gesture gesture, @NonNull final PointF point) { |
|
|
|
private void startMetering(@Nullable final Gesture gesture, @Nullable final PointF point) { |
|
|
|
LOG.i("startMetering", "dispatching. Gesture:", gesture); |
|
|
|
LOG.i("startMetering", "dispatching. Gesture:", gesture); |
|
|
|
mHandler.run(new Runnable() { |
|
|
|
mHandler.run(new Runnable() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -1151,8 +1167,8 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv |
|
|
|
if (getPreviewState() < STATE_STARTED) return; |
|
|
|
if (getPreviewState() < STATE_STARTED) return; |
|
|
|
|
|
|
|
|
|
|
|
// The camera options API still has the auto focus API but it really
|
|
|
|
// The camera options API still has the auto focus API but it really
|
|
|
|
// refers to 3A metering.
|
|
|
|
// refers to "3A metering to a specific point". So if we have one, let's check.
|
|
|
|
if (!mCameraOptions.isAutoFocusSupported()) return; |
|
|
|
if (point != null && !mCameraOptions.isAutoFocusSupported()) return; |
|
|
|
|
|
|
|
|
|
|
|
// Reset the old meter if present.
|
|
|
|
// Reset the old meter if present.
|
|
|
|
if (mMeter != null) { |
|
|
|
if (mMeter != null) { |
|
|
@ -1168,11 +1184,12 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv |
|
|
|
applyFocusForMetering(mRepeatingRequestBuilder); |
|
|
|
applyFocusForMetering(mRepeatingRequestBuilder); |
|
|
|
|
|
|
|
|
|
|
|
// Create the meter and start.
|
|
|
|
// Create the meter and start.
|
|
|
|
|
|
|
|
mMeteringGesture = gesture; |
|
|
|
mMeter = new Meter(Camera2Engine.this, |
|
|
|
mMeter = new Meter(Camera2Engine.this, |
|
|
|
mRepeatingRequestBuilder, |
|
|
|
mRepeatingRequestBuilder, |
|
|
|
mCameraCharacteristics, |
|
|
|
mCameraCharacteristics, |
|
|
|
Camera2Engine.this); |
|
|
|
Camera2Engine.this); |
|
|
|
mMeter.startMetering(mLastRepeatingResult, point, gesture); |
|
|
|
mMeter.startMetering(mLastRepeatingResult, point); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -1181,13 +1198,13 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv |
|
|
|
* 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. |
|
|
|
* @param point point |
|
|
|
* @param point point |
|
|
|
* @param gesture gesture |
|
|
|
* |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onMeteringStarted(@Nullable PointF point, @Nullable Gesture gesture) { |
|
|
|
public void onMeteringStarted(@Nullable PointF point) { |
|
|
|
LOG.w("onMeteringStarted - point:", point, "gesture:", gesture); |
|
|
|
LOG.w("onMeteringStarted - point:", point, "gesture:", mMeteringGesture); |
|
|
|
if (point != null) { |
|
|
|
if (point != null) { |
|
|
|
mCallback.dispatchOnFocusStart(gesture, point); |
|
|
|
mCallback.dispatchOnFocusStart(mMeteringGesture, point); |
|
|
|
} |
|
|
|
} |
|
|
|
applyRepeatingRequestBuilder(); |
|
|
|
applyRepeatingRequestBuilder(); |
|
|
|
} |
|
|
|
} |
|
|
@ -1196,14 +1213,21 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv |
|
|
|
* Called by {@link Meter} when the metering process has ended. |
|
|
|
* Called by {@link Meter} when the metering process has ended. |
|
|
|
* 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. |
|
|
|
* @param point point |
|
|
|
* @param point point |
|
|
|
* @param gesture gesture |
|
|
|
|
|
|
|
* @param success success |
|
|
|
* @param success success |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onMeteringEnd(@Nullable PointF point, @Nullable Gesture gesture, boolean success) { |
|
|
|
public void onMeteringEnd(@Nullable PointF point, boolean success) { |
|
|
|
LOG.w("onMeteringEnd - point:", point, "gesture:", gesture, "success:", success); |
|
|
|
LOG.w("onMeteringEnd - point:", point, "gesture:", mMeteringGesture, "success:", success); |
|
|
|
if (point != null) { |
|
|
|
if (point != null) { |
|
|
|
mCallback.dispatchOnFocusEnd(gesture, success, point); |
|
|
|
mCallback.dispatchOnFocusEnd(mMeteringGesture, success, point); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (mDelayedPictureStub.isSnapshot) { |
|
|
|
|
|
|
|
onTakePictureSnapshot(mDelayedPictureStub, mDelayedPictureRatio, false); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
onTakePicture(mDelayedPictureStub, false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
mDelayedPictureStub = null; |
|
|
|
|
|
|
|
mDelayedPictureRatio = null; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1211,11 +1235,10 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv |
|
|
|
* When metering is reset, we're not sure that the engine is still alive. |
|
|
|
* When metering is reset, we're not sure that the engine is still alive. |
|
|
|
* We should check this here. |
|
|
|
* We should check this here. |
|
|
|
* @param point point |
|
|
|
* @param point point |
|
|
|
* @param gesture gesture |
|
|
|
|
|
|
|
* @return true if metering can be reset |
|
|
|
* @return true if metering can be reset |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean canResetMetering(@Nullable PointF point, @Nullable Gesture gesture) { |
|
|
|
public boolean canResetMetering(@Nullable PointF point) { |
|
|
|
return getEngineState() == STATE_STARTED; |
|
|
|
return getEngineState() == STATE_STARTED; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1223,10 +1246,10 @@ public class Camera2Engine extends CameraEngine implements ImageReader.OnImageAv |
|
|
|
* Called by {@link Meter} after resetting the metering parameters. |
|
|
|
* Called by {@link Meter} after resetting the metering parameters. |
|
|
|
* We should apply them, and also go back to default focus. |
|
|
|
* We should apply them, and also go back to default focus. |
|
|
|
* @param point point |
|
|
|
* @param point point |
|
|
|
* @param gesture gesture |
|
|
|
* |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onMeteringReset(@Nullable PointF point, @Nullable Gesture gesture) { |
|
|
|
public void onMeteringReset(@Nullable PointF point) { |
|
|
|
applyDefaultFocus(mRepeatingRequestBuilder); |
|
|
|
applyDefaultFocus(mRepeatingRequestBuilder); |
|
|
|
applyRepeatingRequestBuilder(); // only if preview started already
|
|
|
|
applyRepeatingRequestBuilder(); // only if preview started already
|
|
|
|
} |
|
|
|
} |
|
|
|