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

[video_player_android] Correct rotation of videos recorded by the camera #7846

Merged
merged 16 commits into from
Oct 21, 2024

Conversation

camsim99
Copy link
Contributor

@camsim99 camsim99 commented Oct 10, 2024

Hopefully 🤞 corrects the calculation used to determine the rotation correction of the video being played. These are the different cases this addresses:

  1. Strictly below Android API 22: Kept this calculation the same as before because I was not able to test it. For context, it uses an unapplied rotation degrees reported by the video's size to correct the rotation. Note that this is always 0 after Android API 22+ (see its docs)
  2. Above Android API 22, strictly below Android API 29: The SurfaceTexture Impeller backend is used. From my testing, I see the preview is correctly rotated and sized without any further intervention, so the correction is set 0.
  3. Android API 29+: The ImageReader Impelled backend is used and a preview correction was noticed by the community (see [video_player_android] Incorrect orientation when previewing captured videos flutter#154696). To fix this, we now use the rotation correction reported by the video's format. We also now use this rotation to make the fix for a swapped = width and height when the correction is 90 or 270 degrees (indicating that the video is landscape) as the logic did before but instead with the unapplied rotation degrees (see case 1 for context).

Tested this on Android APIs 28, 30, 32, and 35.

A fix attempt for flutter/flutter#154696.

Pre-launch Checklist

@camsim99 camsim99 marked this pull request as ready for review October 17, 2024 19:47
@camsim99 camsim99 requested a review from matanlurey as a code owner October 17, 2024 19:47
@camsim99 camsim99 requested a review from a team October 17, 2024 19:47
}
events.onInitialized(width, height, exoPlayer.getDuration(), rotationCorrection);
}

private int getRotationCorrectionFromUnappliedRotation(int unappliedRotationDegrees) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using an enum instead of an int since our code does not actually handle in between values.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 enum

}

@OptIn(markerClass = androidx.media3.common.util.UnstableApi.class)
// The annotation is used to enable using a Format to determine the rotation
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this comment should instead of explaining what an unstable api annotation does should instead explain why it is ok to use an unstable api and what the failure modes are that we can expect. (for example should we expect the signature to possibly change across minor versions).

@@ -33,7 +35,7 @@
* ({@link VideoPlayerCallbacks} and/or interface with the player instance as expected.
*/
@RunWith(RobolectricTestRunner.class)
public final class ExoPlayerEventListenerTests {
public final class ExoPlayerEventListenerTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean to remove the "s" in tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes to make it consistent with the other tests in this plugin (and across plugins).

}
events.onInitialized(width, height, exoPlayer.getDuration(), rotationCorrection);
}

private int getRotationCorrectionFromUnappliedRotation(int unappliedRotationDegrees) {
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 enum

@camsim99
Copy link
Contributor Author

camsim99 commented Oct 21, 2024

cc @matanlurey the video_player_android test can pause that we added is flaking pretty badly. I can file an issue but I think we should revisit it.

@camsim99 camsim99 requested a review from reidbaker October 21, 2024 18:31
@camsim99
Copy link
Contributor Author

cc @matanlurey the video_player_android test can pause that we added is flaking pretty badly. I can file an issue but I think we should revisit it.

Filed flutter/flutter#157307

@camsim99 camsim99 added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 21, 2024
@auto-submit auto-submit bot merged commit 5e03bb1 into flutter:main Oct 21, 2024
76 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 22, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Oct 22, 2024
flutter/packages@b6f7e47...5e03bb1

2024-10-21 43054281+camsim99@users.noreply.github.com [video_player_android] Correct rotation of videos recorded by the camera (flutter/packages#7846)
2024-10-21 gspencergoog@users.noreply.github.com Allow custom blocks to be something other than `Column` or `SizedBox` (flutter/packages#7859)
2024-10-21 49699333+dependabot[bot]@users.noreply.github.com [camera]: Bump androidx.annotation:annotation from 1.8.2 to 1.9.0 in /packages/camera/camera_android/android (flutter/packages#7905)

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 flutter-ecosystem@google.com 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
M97Chahboun pushed a commit to M97Chahboun/flutter that referenced this pull request Oct 30, 2024
…r#157349)

flutter/packages@b6f7e47...5e03bb1

2024-10-21 43054281+camsim99@users.noreply.github.com [video_player_android] Correct rotation of videos recorded by the camera (flutter/packages#7846)
2024-10-21 gspencergoog@users.noreply.github.com Allow custom blocks to be something other than `Column` or `SizedBox` (flutter/packages#7859)
2024-10-21 49699333+dependabot[bot]@users.noreply.github.com [camera]: Bump androidx.annotation:annotation from 1.8.2 to 1.9.0 in /packages/camera/camera_android/android (flutter/packages#7905)

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 flutter-ecosystem@google.com 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
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: video_player platform-android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants