Skip to content

Commit

Permalink
address review
Browse files Browse the repository at this point in the history
  • Loading branch information
camsim99 committed Oct 21, 2024
1 parent fc22ee6 commit 5f2a824
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ android {
unitTests.includeAndroidResources = true
unitTests.returnDefaultValues = true
unitTests.all {
// The org.gradle.jvmargs property that may be set in gradle.properties does not impact
// the Java heap size when running the Android unit tests. The following property here
// sets the heap size to a size large enough to run the robolectric tests across
// multiple SDK levels.
jvmArgs "-Xmx1g"
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,22 @@ private enum RotationDegrees {
private final int degrees;

RotationDegrees(int degrees) {
this.degrees = degrees;
this.degrees = degrees;
}

public static RotationDegrees fromDegrees(int degrees) {
for (RotationDegrees rotationDegrees : RotationDegrees.values()) {
if (rotationDegrees.degrees == degrees) {
return rotationDegrees;
}
for (RotationDegrees rotationDegrees : RotationDegrees.values()) {
if (rotationDegrees.degrees == degrees) {
return rotationDegrees;
}
throw new IllegalArgumentException("Invalid rotation degrees specified: " + degrees);
}
throw new IllegalArgumentException("Invalid rotation degrees specified: " + degrees);
}
}

public int getDegrees() {
return this.degrees;
}
}

ExoPlayerEventListener(ExoPlayer exoPlayer, VideoPlayerCallbacks events) {
this(exoPlayer, events, false);
Expand Down Expand Up @@ -75,14 +79,23 @@ private void sendInitialized() {
int width = videoSize.width;
int height = videoSize.height;
if (width != 0 && height != 0) {
int reportedRotationCorrection = 0;
RotationDegrees reportedRotationCorrection = RotationDegrees.ROTATE_0;

if (Build.VERSION.SDK_INT <= 21) {
// On API 21 and below, Exoplayer may not internally handle rotation correction
// and reports it through VideoSize.unappliedRotationDegrees. We may apply it to
// fix the case of upside-down playback.
reportedRotationCorrection = videoSize.unappliedRotationDegrees;
rotationCorrection = getRotationCorrectionFromUnappliedRotation(RotationDegrees.fromDegrees(reportedRotationCorrection));
try {
reportedRotationCorrection =
RotationDegrees.fromDegrees(videoSize.unappliedRotationDegrees);
rotationCorrection =
getRotationCorrectionFromUnappliedRotation(reportedRotationCorrection);
} catch (IllegalArgumentException e) {
// Unapplied rotation other than 0, 90, 180, 270 reported by VideoSize. Because this is unexpected,
// we apply no rotation correction.
reportedRotationCorrection = RotationDegrees.ROTATE_0;
rotationCorrection = 0;
}
}
// TODO(camsim99): Replace this with a call to `handlesCropAndRotation` when it is
// available in stable. https://github.com/flutter/flutter/issues/157198
Expand All @@ -95,12 +108,21 @@ else if (Build.VERSION.SDK_INT < 29) {
// correct the rotation, so we try to use that to correct the video rotation
// when the ImageReader backend for Impeller is used.
rotationCorrection = getRotationCorrectionFromFormat(exoPlayer);
reportedRotationCorrection = rotationCorrection;

try {
reportedRotationCorrection = RotationDegrees.fromDegrees(rotationCorrection);
} catch (IllegalArgumentException e) {
// Rotation correction other than 0, 90, 180, 270 reported by Format. Because this is unexpected,
// we apply no rotation correction.
reportedRotationCorrection = RotationDegrees.ROTATE_0;
rotationCorrection = 0;
}
}

// Switch the width/height if video was taken in portrait mode and a rotation
// correction was detected.
if (reportedRotationCorrection == 90 || reportedRotationCorrection == 270) {
if (reportedRotationCorrection == RotationDegrees.ROTATE_90
|| reportedRotationCorrection == RotationDegrees.ROTATE_270) {
width = videoSize.height;
height = videoSize.width;
}
Expand All @@ -116,7 +138,7 @@ private int getRotationCorrectionFromUnappliedRotation(RotationDegrees unapplied
// upside-down playback for videos with unappliedRotationDegrees of 180 (other orientations
// work correctly without correction).
if (unappliedRotationDegrees == RotationDegrees.ROTATE_180) {
rotationCorrection = unappliedRotationDegrees.degrees;
rotationCorrection = unappliedRotationDegrees.getDegrees();
}

return rotationCorrection;
Expand Down

0 comments on commit 5f2a824

Please sign in to comment.