Skip to content
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

Merged
merged 32 commits into from
Mar 19, 2024
Merged

Conversation

camsim99
Copy link
Contributor

@camsim99 camsim99 commented Feb 21, 2024

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: #6110 Done :)

Pre-launch Checklist

/// 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].
Copy link
Contributor Author

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!);
Copy link
Contributor Author

@camsim99 camsim99 Feb 27, 2024

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);
}
Copy link
Contributor Author

@camsim99 camsim99 Feb 27, 2024

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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming for consistency.

@camsim99 camsim99 marked this pull request as ready for review February 27, 2024 23:19
@camsim99 camsim99 requested a review from gmackall February 27, 2024 23:19
@camsim99
Copy link
Contributor Author

camsim99 commented Mar 4, 2024

@stuartmorgan This PR will bring camera_android_camerax to feature parity with camera_android. Should we bump the version to 1.0.0 here?

@stuartmorgan
Copy link
Contributor

We aren't at 1.0 for any camera packages, so I would suggest leaving it at 0.x.

Copy link
Member

@gmackall gmackall left a 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

disableAutoCancel: true);
}
// Update current focus mode.
_currentFocusMode = mode;
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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).

@@ -524,27 +637,42 @@ class AndroidCameraCameraX extends CameraPlatform {
(offset / exposureOffsetStepSize).round();

try {
Copy link
Contributor Author

@camsim99 camsim99 Mar 11, 2024

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.

@camsim99 camsim99 requested a review from gmackall March 11, 2024 22:14
Copy link
Member

@gmackall gmackall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

packages/camera/camera_android_camerax/CHANGELOG.md Outdated Show resolved Hide resolved
@camsim99 camsim99 added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 19, 2024
@auto-submit auto-submit bot merged commit 3be3ec1 into flutter:main Mar 19, 2024
78 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 20, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Mar 20, 2024
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
arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
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 :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: camera platform-android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[camerax] Implement focus mode configuration
3 participants