-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[camerax] Implements setFocusMode
#6176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
b915f7d
0b33c78
03b2095
f1bdb1f
bd1f1ba
24dd03b
f73c2fb
d4d1588
dd4f6b3
b902c04
81a5170
72d2d5f
32118bc
da114ab
2965929
861ae64
211962d
23d23ed
49392ae
faa61c5
d025a79
f8d1a6d
d4b4998
7b2fb39
7ff3bc6
81d0453
1ec2045
92123c3
94622d0
b3d72cb
54e8fd3
9568190
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ import 'device_orientation_manager.dart'; | |
| import 'exposure_state.dart'; | ||
| import 'fallback_strategy.dart'; | ||
| import 'focus_metering_action.dart'; | ||
| import 'focus_metering_result.dart'; | ||
| import 'image_analysis.dart'; | ||
| import 'image_capture.dart'; | ||
| import 'image_proxy.dart'; | ||
|
|
@@ -517,6 +518,8 @@ class AndroidCameraCameraX extends CameraPlatform { | |
| /// * Locked focus mode is unset by setting [FocusMode.auto]. | ||
| @override | ||
| Future<void> setFocusMode(int cameraId, FocusMode mode) async { | ||
| MeteringPoint? autoFocusPoint; | ||
| bool? disableAutoCancel; | ||
| switch (mode) { | ||
| case FocusMode.auto: | ||
| if (_currentFocusMode == FocusMode.auto) { | ||
|
|
@@ -527,7 +530,7 @@ class AndroidCameraCameraX extends CameraPlatform { | |
|
|
||
| // Determine auto-focus point to restore, if any. We do not restore | ||
| // default auto-focus point if set previously to lock focus. | ||
| final MeteringPoint? autoFocusPoint = _defaultFocusPointLocked | ||
| final MeteringPoint? unLockedFocusPoint = _defaultFocusPointLocked | ||
| ? null | ||
| : currentFocusMeteringAction!.meteringPointInfos | ||
| .where(((MeteringPoint, int?) meteringPointInfo) => | ||
|
|
@@ -536,10 +539,8 @@ class AndroidCameraCameraX extends CameraPlatform { | |
| .first | ||
| .$1; | ||
| _defaultFocusPointLocked = false; | ||
|
|
||
| await _startFocusAndMeteringFor( | ||
| meteringPoint: autoFocusPoint, | ||
| meteringMode: FocusMeteringAction.flagAf); | ||
| autoFocusPoint = unLockedFocusPoint; | ||
| disableAutoCancel = false; | ||
| case FocusMode.locked: | ||
| MeteringPoint? lockedFocusPoint; | ||
|
|
||
|
|
@@ -562,11 +563,20 @@ class AndroidCameraCameraX extends CameraPlatform { | |
| _defaultFocusPointLocked = true; | ||
| } | ||
|
|
||
| await _startFocusAndMeteringFor( | ||
| meteringPoint: lockedFocusPoint, | ||
| meteringMode: FocusMeteringAction.flagAf, | ||
| disableAutoCancel: true); | ||
| autoFocusPoint = lockedFocusPoint; | ||
| disableAutoCancel = true; | ||
| } | ||
| // Start appropriate focus and metering action. | ||
| final bool focusAndMeteringWasSuccessful = await _startFocusAndMeteringFor( | ||
| meteringPoint: autoFocusPoint, | ||
| meteringMode: FocusMeteringAction.flagAf, | ||
| disableAutoCancel: disableAutoCancel); | ||
|
|
||
| if (!focusAndMeteringWasSuccessful) { | ||
| // Do not update current focus mode. | ||
| return; | ||
| } | ||
|
|
||
| // Update current focus mode. | ||
| _currentFocusMode = mode; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to check my understanding, if we call this method I know we return a success value of null, and then add an 'error' to the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah this is a good catch--thank you! I actually need to utilize the FocusMeteringResult here to make sure we don't get out of sync in cases like this.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed this logic to depend on the result of the |
||
|
|
||
|
|
@@ -1200,11 +1210,11 @@ class AndroidCameraCameraX extends CameraPlatform { | |
|
|
||
| // Methods for configuring auto-focus and auto-exposure: | ||
|
|
||
| Future<void> _startFocusAndMeteringForPoint( | ||
| Future<bool> _startFocusAndMeteringForPoint( | ||
| {required Point<double>? point, | ||
| required int meteringMode, | ||
| bool disableAutoCancel = false}) async { | ||
| await _startFocusAndMeteringFor( | ||
| return _startFocusAndMeteringFor( | ||
| meteringPoint: point == null | ||
| ? null | ||
| : proxy.createMeteringPoint( | ||
|
|
@@ -1213,7 +1223,8 @@ class AndroidCameraCameraX extends CameraPlatform { | |
| disableAutoCancel: disableAutoCancel); | ||
| } | ||
|
|
||
| /// Starts a focus and metering action. | ||
| /// Starts a focus and metering action and returns whether or not it was | ||
| /// successful. | ||
| /// | ||
| /// This method will modify and start the current action's [MeteringPoint]s | ||
| /// overriden with the [meteringPoint] provided for the specified | ||
|
|
@@ -1233,7 +1244,7 @@ class AndroidCameraCameraX extends CameraPlatform { | |
| /// to [currentFocusMeteringAction] that do not share a metering mode with | ||
| /// [meteringPoint]. If [meteringPoint] and [currentFocusMeteringAction] are | ||
| /// null, then focus and metering will be canceled. | ||
| Future<void> _startFocusAndMeteringFor( | ||
| Future<bool> _startFocusAndMeteringFor( | ||
| {required MeteringPoint? meteringPoint, | ||
| required int meteringMode, | ||
| bool disableAutoCancel = false}) async { | ||
|
|
@@ -1243,7 +1254,7 @@ class AndroidCameraCameraX extends CameraPlatform { | |
| if (currentFocusMeteringAction == null) { | ||
| // Attempting to clear a metering point from a previous action, but no | ||
| // such action exists. | ||
| return; | ||
| return false; | ||
| } | ||
|
|
||
| // Remove metering point with specified meteringMode from current focus | ||
|
|
@@ -1264,7 +1275,7 @@ class AndroidCameraCameraX extends CameraPlatform { | |
| // started focus and metering actions. | ||
| await cameraControl.cancelFocusAndMetering(); | ||
| currentFocusMeteringAction = null; | ||
| return; | ||
| return true; | ||
| } | ||
| currentFocusMeteringAction = proxy.createFocusMeteringAction( | ||
| newMeteringPointInfos, disableAutoCancel); | ||
|
|
@@ -1296,6 +1307,8 @@ class AndroidCameraCameraX extends CameraPlatform { | |
| newMeteringPointInfos, disableAutoCancel); | ||
| } | ||
|
|
||
| await cameraControl.startFocusAndMetering(currentFocusMeteringAction!); | ||
| final FocusMeteringResult? result = | ||
| await cameraControl.startFocusAndMetering(currentFocusMeteringAction!); | ||
| return await result?.isFocusSuccessful() ?? false; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This maps to
camera_android's behavior.