-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[camerax] Implements setFocusMode
#6176
Conversation
/// center of entire sensor area if not and will stay locked until either: | ||
/// * Another focus point is set via [setFocusPoint] (which will then become | ||
/// the locked focus point), or | ||
/// * Locked focus mode is unset by setting [FocusMode.auto]. |
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.
|
||
// If there isn't, lock center of entire sensor area by default. | ||
if (lockedAfPoint == null) { | ||
lockedAfPoint = proxy.createMeteringPoint(0.5, 0.5, 1, cameraInfo!); |
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 point will center focus on entire sensor area and was recommended to me to use in this case to maintain current focus.
if (_currentExposureMode == ExposureMode.auto && | ||
_currentFocusMode == FocusMode.locked) { | ||
await setExposureMode(cameraId, _currentExposureMode); | ||
} |
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.
Disabling auto-cancel impacts the entire focus & metering action, so we have to make sure exposure mode does not get impacted by locking focus mode (which disables auto-cancel).
this.createFocusMeteringAction = _createFocusMeteringAction, | ||
this.createCaptureRequestOptions = _createAttachedCaptureRequestOptions, | ||
this.createMeteringPoint = _createAttachedMeteringPoint, | ||
this.createFocusMeteringAction = _createAttachedFocusMeteringAction, |
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.
Renaming for consistency.
@stuartmorgan This PR will bring |
We aren't at 1.0 for any camera packages, so I would suggest leaving it at 0.x. |
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.
Mostly lgtm, just one main question about _currentFocusMode
getting out of sync with the actually set focus mode
...camerax/android/src/main/java/io/flutter/plugins/camerax/FocusMeteringActionHostApiImpl.java
Outdated
Show resolved
Hide resolved
packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart
Outdated
Show resolved
Hide resolved
packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart
Outdated
Show resolved
Hide resolved
disableAutoCancel: true); | ||
} | ||
// Update current focus mode. | ||
_currentFocusMode = mode; |
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.
Just to check my understanding, if we call this method setFocusMode
with FocusMode.locked
, and then we get an OperationCancelledException
in the java code, do we currently still update the _currentFocusMode
here to locked, even though it isn't set?
I know we return a success value of null, and then add an 'error' to the cameraErrorStreamController
, but I don't know what the exact consequence of doing that are and if it would prevent us getting into a state here where _currentFocusMode
doesn't align with the current actual focus mode.
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.
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.
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.
Changed this logic to depend on the result of the FocusMeteringResult
and added tests to make sure that the current focus mode doesn't update when the call failed (tested by making calls to setFocusPoint
/setExposurePoint
to see if auto-canceled was enabled/disabled as we'd expect).
packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart
Outdated
Show resolved
Hide resolved
packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart
Outdated
Show resolved
Hide resolved
@@ -524,27 +637,42 @@ class AndroidCameraCameraX extends CameraPlatform { | |||
(offset / exposureOffsetStepSize).round(); | |||
|
|||
try { |
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.
Small fix here: Before I was returning a value based on my own computations, but we should actually just use the value that directly comes from CameraX to be most correct. Added a test for a null return value, as well.
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.
LGTM!
Co-authored-by: Gray Mackall <[email protected]>
flutter/packages@a2f4ce0...23e56af 2024-03-19 [email protected] [camerax] Update README to encourage users to opt in (flutter/packages#6352) 2024-03-19 [email protected] [flutter_markdown] Allow for custom block element (flutter/packages#5815) 2024-03-19 [email protected] [pigeon] Adds Dart implementation of ProxyApi (flutter/packages#6043) 2024-03-19 [email protected] [camerax] Implements `setFocusMode` (flutter/packages#6176) 2024-03-19 [email protected] Roll Flutter from f217fc1 to d31a85b (23 revisions) (flutter/packages#6356) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Implements `setFocusMode` (also adds support for disabling auto-cancel to `FocusMeteringAction` host API implementation to accomplish this) + some minor documentation improvements based on discoveries I made while working on this :) Fixes flutter/flutter#120467. ~To be landed after: flutter#6110 Done :)
Implements
setFocusMode
(also adds support for disabling auto-cancel toFocusMeteringAction
host API implementation to accomplish this) + some minor documentation improvements based on discoveries I made while working on this :)Fixes flutter/flutter#120467.
To be landed after: #6110Done :)Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).