Skip to content

Conversation

@ruicraveiro
Copy link
Contributor

Implements getSupportedVideoStabilizationModes() and setVideoStabilizationMode() methods in AVFoundationCamera.

Address issue flutter/flutter#89525.
It is the camera_avfoundation sub-PR for #7108.

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2 3

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for video stabilization, which is a great new feature. The implementation looks solid across Dart, Swift, and Objective-C. I've found a minor issue in the Dart implementation related to a copy-paste error in a comment and a suggestion for a safer fallback value for forward compatibility. The rest of the changes, including the native implementation and tests, are well done.

Comment on lines 543 to 564
/// Returns a [ResolutionPreset]'s Pigeon representation.
PlatformVideoStabilizationMode? _pigeonVideoStabilizationMode(
VideoStabilizationMode videoStabilizationMode,
) {
switch (videoStabilizationMode) {
case VideoStabilizationMode.off:
return PlatformVideoStabilizationMode.off;
case VideoStabilizationMode.level1:
return PlatformVideoStabilizationMode.standard;
case VideoStabilizationMode.level2:
return PlatformVideoStabilizationMode.cinematic;
case VideoStabilizationMode.level3:
return PlatformVideoStabilizationMode.cinematicExtended;
}
// The enum comes from a different package, which could get a new value at
// any time, so provide a fallback that ensures this won't break when used
// with a version that contains new values. This is deliberately outside
// the switch rather than a `default` so that the linter will flag the
// switch as needing an update.
// ignore: dead_code
return PlatformVideoStabilizationMode.cinematic;
}

Choose a reason for hiding this comment

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

medium

There are a couple of improvements that can be made in this method:

  1. The documentation comment appears to be a copy-paste error and refers to ResolutionPreset instead of VideoStabilizationMode.
  2. The fallback return value for unknown VideoStabilizationMode values is PlatformVideoStabilizationMode.cinematic. It would be safer to return null here. The function has a nullable return type, and the calling method _getSupportedVideoStabilizationModeMap already handles null by correctly treating the mode as unsupported. This would prevent new enum values from being incorrectly mapped to cinematic mode.
  /// Returns a [VideoStabilizationMode]'s Pigeon representation.
  PlatformVideoStabilizationMode? _pigeonVideoStabilizationMode(
    VideoStabilizationMode videoStabilizationMode,
  ) {
    switch (videoStabilizationMode) {
      case VideoStabilizationMode.off:
        return PlatformVideoStabilizationMode.off;
      case VideoStabilizationMode.level1:
        return PlatformVideoStabilizationMode.standard;
      case VideoStabilizationMode.level2:
        return PlatformVideoStabilizationMode.cinematic;
      case VideoStabilizationMode.level3:
        return PlatformVideoStabilizationMode.cinematicExtended;
    }
    // The enum comes from a different package, which could get a new value at
    // any time, so provide a fallback that ensures this won't break when used
    // with a version that contains new values. This is deliberately outside
    // the switch rather than a `default` so that the linter will flag the
    // switch as needing an update.
    // ignore: dead_code
    return null;
  }

- Implements getSupportedVideoStabilizationModes() and
  setVideoStabilizationMode() methods in AVFoundationCamera.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant