Skip to content

Commit

Permalink
Revert "[camera] Add iOS and Android implementations for managing aut…
Browse files Browse the repository at this point in the history
…o focus. (flutter#3370)"

This reverts commit 71a8317.
  • Loading branch information
Aperico-com committed Feb 3, 2021
1 parent 42d5325 commit 907da9c
Show file tree
Hide file tree
Showing 30 changed files with 27 additions and 480 deletions.
2 changes: 1 addition & 1 deletion packages/camera/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ As part of implementing federated architecture and making the interface compatib

Method changes in `CameraController`:
- The `takePicture` method no longer accepts the `path` parameter, but instead returns the captured image as an instance of the `XFile` class;
- The `startVideoRecording` method no longer accepts the `filePath`. Instead the recorded video is now returned as a `XFile` instance when the `stopVideoRecording` method completes;
- The `startVideoRecording` method no longer accepts the `filePath`. Instead the recorded video is now returned as a `XFile` instance when the `stopVideoRecording` method completes;
- The `stopVideoRecording` method now returns the captured video when it completes;
- Added the `buildPreview` method which is now used to implement the CameraPreview widget.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.camera;

import static io.flutter.plugins.camera.CameraUtils.computeBestPreviewSize;
Expand Down Expand Up @@ -50,7 +46,6 @@
import io.flutter.plugins.camera.media.MediaRecorderBuilder;
import io.flutter.plugins.camera.types.ExposureMode;
import io.flutter.plugins.camera.types.FlashMode;
import io.flutter.plugins.camera.types.FocusMode;
import io.flutter.plugins.camera.types.ResolutionPreset;
import io.flutter.view.TextureRegistry.SurfaceTextureEntry;
import java.io.File;
Expand Down Expand Up @@ -98,7 +93,6 @@ public class Camera {
private File videoRecordingFile;
private FlashMode flashMode;
private ExposureMode exposureMode;
private FocusMode focusMode;
private PictureCaptureRequest pictureCaptureRequest;
private CameraRegions cameraRegions;
private int exposureOffset;
Expand Down Expand Up @@ -133,7 +127,6 @@ public Camera(
this.applicationContext = activity.getApplicationContext();
this.flashMode = FlashMode.auto;
this.exposureMode = ExposureMode.auto;
this.focusMode = FocusMode.auto;
this.exposureOffset = 0;

cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraName);
Expand Down Expand Up @@ -166,7 +159,7 @@ private void initFps(CameraCharacteristics cameraCharacteristics) {
int upper = range.getUpper();
Log.i("Camera", "[FPS Range Available] is:" + range);
if (upper >= 10) {
if (fpsRange == null || upper > fpsRange.getUpper()) {
if (fpsRange == null || upper < fpsRange.getUpper()) {
fpsRange = range;
}
}
Expand Down Expand Up @@ -221,9 +214,7 @@ public void onOpened(@NonNull CameraDevice device) {
previewSize.getWidth(),
previewSize.getHeight(),
exposureMode,
focusMode,
isExposurePointSupported(),
isFocusPointSupported());
isExposurePointSupported());
} catch (CameraAccessException e) {
dartMessenger.sendCameraErrorEvent(e.getMessage());
close();
Expand Down Expand Up @@ -313,7 +304,7 @@ public void onConfigured(@NonNull CameraCaptureSession session) {
cameraCaptureSession = session;

updateFpsRange();
updateFocus(focusMode);
updateAutoFocus();
updateFlash(flashMode);
updateExposure(exposureMode);

Expand Down Expand Up @@ -517,7 +508,7 @@ private void runPictureAutoFocus() {
assert (pictureCaptureRequest != null);

pictureCaptureRequest.setState(PictureCaptureRequest.State.focusing);
lockAutoFocus(pictureCaptureCallback);
lockAutoFocus();
}

private void runPicturePreCapture() {
Expand Down Expand Up @@ -585,7 +576,7 @@ public void onCaptureCompleted(
}
}

private void lockAutoFocus(CaptureCallback callback) {
private void lockAutoFocus() {
captureRequestBuilder.set(
CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_START);

Expand All @@ -596,7 +587,7 @@ private void lockAutoFocus(CaptureCallback callback) {
private void unlockAutoFocus() {
captureRequestBuilder.set(
CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
updateFocus(focusMode);
updateAutoFocus();
try {
cameraCaptureSession.capture(captureRequestBuilder.build(), null, null);
} catch (CameraAccessException ignored) {
Expand Down Expand Up @@ -779,72 +770,25 @@ public void setExposurePoint(@NonNull final Result result, Double x, Double y)
"setExposurePointFailed", "Device does not have exposure point capabilities", null);
return;
}
// Check if the current region boundaries are known
if (cameraRegions.getMaxBoundaries() == null) {
// Check if we are doing a reset or not
if (x == null || y == null) {
x = 0.5;
y = 0.5;
}
// Get the current region boundaries.
Size maxBoundaries = getRegionBoundaries();
if (maxBoundaries == null) {
result.error("setExposurePointFailed", "Could not determine max region boundaries", null);
return;
}
// Set the metering rectangle
if (x == null || y == null) cameraRegions.resetAutoExposureMeteringRectangle();
else cameraRegions.setAutoExposureMeteringRectangleFromPoint(x, y);
cameraRegions.setAutoExposureMeteringRectangleFromPoint(x, y);
// Apply it
updateExposure(exposureMode);
refreshPreviewCaptureSession(
() -> result.success(null), (code, message) -> result.error("CameraAccess", message, null));
}

public void setFocusMode(@NonNull final Result result, FocusMode mode)
throws CameraAccessException {
this.focusMode = mode;

updateFocus(mode);

switch (mode) {
case auto:
refreshPreviewCaptureSession(
null, (code, message) -> result.error("setFocusMode", message, null));
break;
case locked:
lockAutoFocus(
new CaptureCallback() {
@Override
public void onCaptureCompleted(
@NonNull CameraCaptureSession session,
@NonNull CaptureRequest request,
@NonNull TotalCaptureResult result) {
unlockAutoFocus();
}
});
break;
}
result.success(null);
}

public void setFocusPoint(@NonNull final Result result, Double x, Double y)
throws CameraAccessException {
// Check if focus point functionality is available.
if (!isFocusPointSupported()) {
result.error("setFocusPointFailed", "Device does not have focus point capabilities", null);
return;
}

// Check if the current region boundaries are known
if (cameraRegions.getMaxBoundaries() == null) {
result.error("setFocusPointFailed", "Could not determine max region boundaries", null);
return;
}

// Set the metering rectangle
if (x == null || y == null) {
cameraRegions.resetAutoFocusMeteringRectangle();
} else {
cameraRegions.setAutoFocusMeteringRectangleFromPoint(x, y);
}

// Apply the new metering rectangle
setFocusMode(result, focusMode);
}

@TargetApi(VERSION_CODES.P)
private boolean supportsDistortionCorrection() throws CameraAccessException {
int[] availableDistortionCorrectionModes =
Expand Down Expand Up @@ -894,14 +838,6 @@ private boolean isExposurePointSupported() throws CameraAccessException {
return supportedRegions != null && supportedRegions > 0;
}

private boolean isFocusPointSupported() throws CameraAccessException {
Integer supportedRegions =
cameraManager
.getCameraCharacteristics(cameraDevice.getId())
.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AF);
return supportedRegions != null && supportedRegions > 0;
}

public double getMinExposureOffset() throws CameraAccessException {
Range<Integer> range =
cameraManager
Expand Down Expand Up @@ -990,7 +926,7 @@ private void updateFpsRange() {
captureRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, fpsRange);
}

private void updateFocus(FocusMode mode) {
private void updateAutoFocus() {
if (useAutoFocus) {
int[] modes = cameraCharacteristics.get(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES);
// Auto focus is not supported
Expand All @@ -1001,25 +937,8 @@ private void updateFocus(FocusMode mode) {
captureRequestBuilder.set(
CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_OFF);
} else {
// Applying auto focus
switch (mode) {
case locked:
captureRequestBuilder.set(
CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO);
break;
case auto:
captureRequestBuilder.set(
CaptureRequest.CONTROL_AF_MODE,
recordingVideo
? CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_VIDEO
: CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
default:
break;
}
MeteringRectangle afRect = cameraRegions.getAFMeteringRectangle();
captureRequestBuilder.set(
CaptureRequest.CONTROL_AF_REGIONS,
afRect == null ? null : new MeteringRectangle[] {afRect});
CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
}
} else {
captureRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_OFF);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.camera;

import android.Manifest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.camera;

import android.hardware.camera2.params.MeteringRectangle;
import android.util.Size;

public final class CameraRegions {
private MeteringRectangle aeMeteringRectangle;
private MeteringRectangle afMeteringRectangle;
private Size maxBoundaries;

public CameraRegions(Size maxBoundaries) {
Expand All @@ -22,10 +17,6 @@ public MeteringRectangle getAEMeteringRectangle() {
return aeMeteringRectangle;
}

public MeteringRectangle getAFMeteringRectangle() {
return afMeteringRectangle;
}

public Size getMaxBoundaries() {
return this.maxBoundaries;
}
Expand All @@ -38,14 +29,6 @@ public void setAutoExposureMeteringRectangleFromPoint(double x, double y) {
this.aeMeteringRectangle = getMeteringRectangleForPoint(maxBoundaries, x, y);
}

public void resetAutoFocusMeteringRectangle() {
this.afMeteringRectangle = null;
}

public void setAutoFocusMeteringRectangleFromPoint(double x, double y) {
this.afMeteringRectangle = getMeteringRectangleForPoint(maxBoundaries, x, y);
}

public MeteringRectangle getMeteringRectangleForPoint(Size maxBoundaries, double x, double y) {
assert (x >= 0 && x <= 1);
assert (y >= 0 && y <= 1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.camera;

import android.app.Activity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.camera;

import android.graphics.Rect;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.camera;

import android.os.Handler;
Expand All @@ -12,7 +8,6 @@
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugins.camera.types.ExposureMode;
import io.flutter.plugins.camera.types.FocusMode;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -61,25 +56,19 @@ void sendCameraInitializedEvent(
Integer previewWidth,
Integer previewHeight,
ExposureMode exposureMode,
FocusMode focusMode,
Boolean exposurePointSupported,
Boolean focusPointSupported) {
Boolean exposurePointSupported) {
assert (previewWidth != null);
assert (previewHeight != null);
assert (exposureMode != null);
assert (focusMode != null);
assert (exposurePointSupported != null);
assert (focusPointSupported != null);
this.send(
CameraEventType.INITIALIZED,
new HashMap<String, Object>() {
{
put("previewWidth", previewWidth.doubleValue());
put("previewHeight", previewHeight.doubleValue());
put("exposureMode", exposureMode.toString());
put("focusMode", focusMode.toString());
put("exposurePointSupported", exposurePointSupported);
put("focusPointSupported", focusPointSupported);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package io.flutter.plugins.camera;

import android.app.Activity;
Expand All @@ -17,7 +13,6 @@
import io.flutter.plugins.camera.CameraPermissions.PermissionsRegistry;
import io.flutter.plugins.camera.types.ExposureMode;
import io.flutter.plugins.camera.types.FlashMode;
import io.flutter.plugins.camera.types.FocusMode;
import io.flutter.view.TextureRegistry;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -212,37 +207,6 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull final Result result)
}
break;
}
case "setFocusMode":
{
String modeStr = call.argument("mode");
FocusMode mode = FocusMode.getValueForString(modeStr);
if (mode == null) {
result.error("setFocusModeFailed", "Unknown focus mode " + modeStr, null);
return;
}
try {
camera.setFocusMode(result, mode);
} catch (Exception e) {
handleException(e, result);
}
break;
}
case "setFocusPoint":
{
Boolean reset = call.argument("reset");
Double x = null;
Double y = null;
if (reset == null || !reset) {
x = call.argument("x");
y = call.argument("y");
}
try {
camera.setFocusPoint(result, x, y);
} catch (Exception e) {
handleException(e, result);
}
break;
}
case "startImageStream":
{
try {
Expand Down
Loading

0 comments on commit 907da9c

Please sign in to comment.