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] Wrap classes to implement resolution configuration for image capture, image analysis, and preview #4523

Merged
merged 29 commits into from
Jul 27, 2023

Conversation

camsim99
Copy link
Contributor

@camsim99 camsim99 commented Jul 19, 2023

Wraps classes to implement resolution configuration for image capture, image analysis, and preview. Also bumps CameraX version to latest and removes the deprecated classes used previously.

No functionality changes. Also thanks to @bparrishMines who did majority of the work here!

Part of flutter/flutter#120462

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

@camsim99 camsim99 marked this pull request as ready for review July 19, 2023 19:39
/// * Update `LiveDataHostApiImpl#getValue` is updated to properly return
/// identifiers for instances of type S.
/// * Update `ObserverFlutterApiWrapper#onChanged` to properly handle receiving
/// calls with instances of type S if a LiveData<S> instance is observed.
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 is unrelated. Pigeon must have carried over my comment I left in camerax_library.dart in a previous PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, pigeon will just keep adding it back since it's part of the source file

@camsim99 camsim99 requested review from bparrishMines, gmackall and a team July 19, 2023 19:40
/// this fallback rule is used.
///
/// See https://developer.android.com/reference/androidx/camera/core/resolutionselector/AspectRatioStrategy#FALLBACK_RULE_NONE().
static const int fallbackRuleNone = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Not a blocker for this PR, but I did want to ask if it would be better for us to make a getter for these constants.

We are essentially relying on the camerax implementations to never change these values, and if they did it might not get caught by our testing because they could still be valid values, but just not actually correspond to what they are named. I know we are doing this in existing camerax and webview wrappings though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My initial thought is that changing them to getters wouldn't be a significant improvement. If the values change, we likely will be quick to find out. Plus, there's the risk that they change the name and a getter would fail there. Not sure which case is more likely but I think it's something to consider. @bparrishMines any thoughts on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's hard to change them to getters since it would require an async call. Which would make it unintuitive to use. You could also add a Java unit test that verifies that these constants stay the same. However, this would still be susceptible to an instance where the constant values are different for different Android versions. Although this case is probably extremely rare.

@immutable
class ResolutionStrategy extends JavaObject {
/// Construct a [ResolutionStrategy].
ResolutionStrategy({
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about making the arguments to this constructor non-null (as they are for the android class) and instead using a private named constructor instead for the creation of the highest available strategy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I love this idea. Changed it and added tests.

Copy link
Member

Choose a reason for hiding this comment

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

I believe as is, it is still nullable (it is required but someone can still pass null).

I think this can be changed to required Size this.boundSize, though, to keep it as an initializing formal but just with a stricter (non-nullable) type.

See the "NOTE: Also note that it is possible to enforce a type that is stricter"... in https://dart.dev/tools/linter-rules/prefer_initializing_formals (can't link sections unfortunately).

@gmackall
Copy link
Member

Left some comments but mostly looks good to me! Main things I'm wondering about are the comment about the constructor for resolution strategy and the question about how we are handling named constants.

Other than that it's just comment nits and requests for detached constructor tests

@camsim99 camsim99 requested a review from gmackall July 24, 2023 21:49
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.

Just one more comment about the ResolutionStrategy constructor, and a couple of comment nits!

@immutable
class ResolutionStrategy extends JavaObject {
/// Construct a [ResolutionStrategy].
ResolutionStrategy({
Copy link
Member

Choose a reason for hiding this comment

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

I believe as is, it is still nullable (it is required but someone can still pass null).

I think this can be changed to required Size this.boundSize, though, to keep it as an initializing formal but just with a stricter (non-nullable) type.

See the "NOTE: Also note that it is possible to enforce a type that is stricter"... in https://dart.dev/tools/linter-rules/prefer_initializing_formals (can't link sections unfortunately).

Copy link
Contributor

@bparrishMines bparrishMines left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -116,10 +116,6 @@ class AndroidCameraCameraX extends CameraPlatform {
@visibleForTesting
CameraSelector? cameraSelector;

/// The resolution preset used to create a camera that should be used for
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a breaking change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it wasn't used before

/// options.
///
/// See https://developer.android.com/reference/androidx/camera/core/resolutionselector/AspectRatioStrategy#FALLBACK_RULE_AUTO().
static const int fallbackRuleAuto = 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider bumping these constants to the top of the class for easier discoverability.

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 would go against the pattern I've been following but if you have strong opinions I can follow this up with another PR moving all static constants to the top of their respective classes

/// * Update `LiveDataHostApiImpl#getValue` is updated to properly return
/// identifiers for instances of type S.
/// * Update `ObserverFlutterApiWrapper#onChanged` to properly handle receiving
/// calls with instances of type S if a LiveData<S> instance is observed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be removed?

@camsim99 camsim99 added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 27, 2023
@auto-submit auto-submit bot merged commit 897f695 into flutter:main Jul 27, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 28, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jul 28, 2023
flutter/packages@f4ae933...10aab44

2023-07-28 [email protected] remove unneeded imports (flutter/packages#4579)
2023-07-27 [email protected] [camerax] Wrap classes to implement resolution configuration for image capture, image analysis, and preview (flutter/packages#4523)
2023-07-27 [email protected] [camera_android] Provides a default exposure point if null. (flutter/packages#3851)
2023-07-27 [email protected] Roll Flutter from 61fd11d to dd9764e (5 revisions) (flutter/packages#4577)

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://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
LouiseHsu pushed a commit to LouiseHsu/flutter that referenced this pull request Jul 31, 2023
flutter/packages@f4ae933...10aab44

2023-07-28 [email protected] remove unneeded imports (flutter/packages#4579)
2023-07-27 [email protected] [camerax] Wrap classes to implement resolution configuration for image capture, image analysis, and preview (flutter/packages#4523)
2023-07-27 [email protected] [camera_android] Provides a default exposure point if null. (flutter/packages#3851)
2023-07-27 [email protected] Roll Flutter from 61fd11d to dd9764e (5 revisions) (flutter/packages#4577)

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://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
vashworth pushed a commit to vashworth/flutter that referenced this pull request Aug 2, 2023
flutter/packages@f4ae933...10aab44

2023-07-28 [email protected] remove unneeded imports (flutter/packages#4579)
2023-07-27 [email protected] [camerax] Wrap classes to implement resolution configuration for image capture, image analysis, and preview (flutter/packages#4523)
2023-07-27 [email protected] [camera_android] Provides a default exposure point if null. (flutter/packages#3851)
2023-07-27 [email protected] Roll Flutter from 61fd11d to dd9764e (5 revisions) (flutter/packages#4577)

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://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
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.

4 participants