diff --git a/libraries/common/src/main/java/androidx/media3/common/VideoSize.java b/libraries/common/src/main/java/androidx/media3/common/VideoSize.java index 502e77e231..2d0a1eeb96 100644 --- a/libraries/common/src/main/java/androidx/media3/common/VideoSize.java +++ b/libraries/common/src/main/java/androidx/media3/common/VideoSize.java @@ -27,7 +27,6 @@ public final class VideoSize { private static final int DEFAULT_WIDTH = 0; private static final int DEFAULT_HEIGHT = 0; - private static final int DEFAULT_UNAPPLIED_ROTATION_DEGREES = 0; private static final float DEFAULT_PIXEL_WIDTH_HEIGHT_RATIO = 1F; public static final VideoSize UNKNOWN = new VideoSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); @@ -76,20 +75,22 @@ public final class VideoSize { * square pixels this will be equal to 1.0. Different values are indicative of anamorphic * content. */ - @SuppressWarnings("deprecation") // Calling through to deprecated constructor + @SuppressWarnings("deprecation") // Setting deprecated field @UnstableApi public VideoSize( @IntRange(from = 0) int width, @IntRange(from = 0) int height, @FloatRange(from = 0, fromInclusive = false) float pixelWidthHeightRatio) { - this(width, height, DEFAULT_UNAPPLIED_ROTATION_DEGREES, pixelWidthHeightRatio); + this.width = width; + this.height = height; + this.unappliedRotationDegrees = 0; + this.pixelWidthHeightRatio = pixelWidthHeightRatio; } /** * @deprecated Use {@link VideoSize#VideoSize(int, int, float)} instead. {@code - * unappliedRotationDegrees} is not needed on API 21+. + * unappliedRotationDegrees} is not needed on API 21+ and is always zero. */ - @SuppressWarnings("deprecation") // Setting deprecate field @Deprecated @UnstableApi public VideoSize( @@ -97,13 +98,9 @@ public final class VideoSize { @IntRange(from = 0) int height, @IntRange(from = 0, to = 359) int unappliedRotationDegrees, @FloatRange(from = 0, fromInclusive = false) float pixelWidthHeightRatio) { - this.width = width; - this.height = height; - this.unappliedRotationDegrees = unappliedRotationDegrees; - this.pixelWidthHeightRatio = pixelWidthHeightRatio; + this(width, height, pixelWidthHeightRatio); } - @SuppressWarnings("deprecation") // Including deprecated field in equality @Override public boolean equals(@Nullable Object obj) { if (this == obj) { @@ -113,50 +110,47 @@ public final class VideoSize { VideoSize other = (VideoSize) obj; return width == other.width && height == other.height - && unappliedRotationDegrees == other.unappliedRotationDegrees && pixelWidthHeightRatio == other.pixelWidthHeightRatio; } return false; } - @SuppressWarnings("deprecation") // Including deprecated field in hashCode @Override public int hashCode() { int result = 7; result = 31 * result + width; result = 31 * result + height; - result = 31 * result + unappliedRotationDegrees; result = 31 * result + Float.floatToRawIntBits(pixelWidthHeightRatio); return result; } private static final String FIELD_WIDTH = Util.intToStringMaxRadix(0); private static final String FIELD_HEIGHT = Util.intToStringMaxRadix(1); - private static final String FIELD_UNAPPLIED_ROTATION_DEGREES = Util.intToStringMaxRadix(2); + // 2 reserved for deprecated 'unappliedRotationDegrees'. private static final String FIELD_PIXEL_WIDTH_HEIGHT_RATIO = Util.intToStringMaxRadix(3); - @SuppressWarnings("deprecation") // Including deprecated field in bundle @UnstableApi public Bundle toBundle() { Bundle bundle = new Bundle(); - bundle.putInt(FIELD_WIDTH, width); - bundle.putInt(FIELD_HEIGHT, height); - bundle.putInt(FIELD_UNAPPLIED_ROTATION_DEGREES, unappliedRotationDegrees); - bundle.putFloat(FIELD_PIXEL_WIDTH_HEIGHT_RATIO, pixelWidthHeightRatio); + if (width != 0) { + bundle.putInt(FIELD_WIDTH, width); + } + if (height != 0) { + bundle.putInt(FIELD_HEIGHT, height); + } + if (pixelWidthHeightRatio != 1f) { + bundle.putFloat(FIELD_PIXEL_WIDTH_HEIGHT_RATIO, pixelWidthHeightRatio); + } return bundle; } /** Restores a {@code VideoSize} from a {@link Bundle}. */ - @SuppressWarnings("deprecation") // Parsing deprecated field from bundle @UnstableApi public static VideoSize fromBundle(Bundle bundle) { int width = bundle.getInt(FIELD_WIDTH, DEFAULT_WIDTH); int height = bundle.getInt(FIELD_HEIGHT, DEFAULT_HEIGHT); - int unappliedRotationDegrees = - bundle.getInt(FIELD_UNAPPLIED_ROTATION_DEGREES, DEFAULT_UNAPPLIED_ROTATION_DEGREES); float pixelWidthHeightRatio = bundle.getFloat(FIELD_PIXEL_WIDTH_HEIGHT_RATIO, DEFAULT_PIXEL_WIDTH_HEIGHT_RATIO); - return new VideoSize(width, height, unappliedRotationDegrees, pixelWidthHeightRatio); + return new VideoSize(width, height, pixelWidthHeightRatio); } - ; } diff --git a/libraries/common/src/test/java/androidx/media3/common/VideoSizeTest.java b/libraries/common/src/test/java/androidx/media3/common/VideoSizeTest.java index 213ad58e20..afbb4fb0cb 100644 --- a/libraries/common/src/test/java/androidx/media3/common/VideoSizeTest.java +++ b/libraries/common/src/test/java/androidx/media3/common/VideoSizeTest.java @@ -32,14 +32,9 @@ public final class VideoSizeTest { } @Test - @SuppressWarnings("deprecation") // Testing bundling of deprecated field. public void roundTripViaBundle_ofArbitraryVideoSize_yieldsEqualInstance() { VideoSize videoSize = - new VideoSize( - /* width= */ 9, - /* height= */ 8, - /* unappliedRotationDegrees= */ 7, - /* pixelWidthHeightRatio= */ 6); + new VideoSize(/* width= */ 9, /* height= */ 8, /* pixelWidthHeightRatio= */ 6); assertThat(roundTripViaBundle(videoSize)).isEqualTo(videoSize); } diff --git a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/analytics/DefaultAnalyticsCollector.java b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/analytics/DefaultAnalyticsCollector.java index 967bb24b37..e91df8cf73 100644 --- a/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/analytics/DefaultAnalyticsCollector.java +++ b/libraries/exoplayer/src/main/java/androidx/media3/exoplayer/analytics/DefaultAnalyticsCollector.java @@ -762,7 +762,7 @@ public class DefaultAnalyticsCollector implements AnalyticsCollector { eventTime, videoSize.width, videoSize.height, - videoSize.unappliedRotationDegrees, + /* unappliedRotationDegrees= */ 0, videoSize.pixelWidthHeightRatio); }); } diff --git a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/video/MediaCodecVideoRendererTest.java b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/video/MediaCodecVideoRendererTest.java index 2c330bbe6a..e1ef97b6b1 100644 --- a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/video/MediaCodecVideoRendererTest.java +++ b/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/video/MediaCodecVideoRendererTest.java @@ -670,11 +670,7 @@ public class MediaCodecVideoRendererTest { verify(eventListener) .onVideoSizeChanged( - new VideoSize( - VIDEO_H264.width, - VIDEO_H264.height, - VIDEO_H264.rotationDegrees, - VIDEO_H264.pixelWidthHeightRatio)); + new VideoSize(VIDEO_H264.width, VIDEO_H264.height, VIDEO_H264.pixelWidthHeightRatio)); } @Test diff --git a/libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaControllerTest.java b/libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaControllerTest.java index 0241765904..f33402c1db 100644 --- a/libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaControllerTest.java +++ b/libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaControllerTest.java @@ -877,11 +877,7 @@ public class MediaControllerTest { @SuppressWarnings("deprecation") // Testing propagation of deprecated unappliedRotationDegrees. public void getVideoSize_returnsVideoSizeOfPlayerInSession() throws Exception { VideoSize testVideoSize = - new VideoSize( - /* width= */ 100, - /* height= */ 42, - /* unappliedRotationDegrees= */ 90, - /* pixelWidthHeightRatio= */ 1.2f); + new VideoSize(/* width= */ 100, /* height= */ 42, /* pixelWidthHeightRatio= */ 1.2f); Bundle playerConfig = new RemoteMediaSession.MockPlayerConfigBuilder().setVideoSize(testVideoSize).build(); remoteSession.setPlayer(playerConfig); diff --git a/libraries/ui/src/main/java/androidx/media3/ui/PlayerView.java b/libraries/ui/src/main/java/androidx/media3/ui/PlayerView.java index 327712ce88..6e44077aa5 100644 --- a/libraries/ui/src/main/java/androidx/media3/ui/PlayerView.java +++ b/libraries/ui/src/main/java/androidx/media3/ui/PlayerView.java @@ -32,8 +32,6 @@ import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; -import android.graphics.Matrix; -import android.graphics.RectF; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.opengl.GLSurfaceView; @@ -335,7 +333,6 @@ public class PlayerView extends FrameLayout implements AdViewProvider { private boolean controllerAutoShow; private boolean controllerHideDuringAds; private boolean controllerHideOnTouch; - private int textureViewRotation; public PlayerView(Context context) { this(context, /* attrs= */ null); @@ -1752,30 +1749,8 @@ public class PlayerView extends FrameLayout implements AdViewProvider { VideoSize videoSize = player != null ? player.getVideoSize() : VideoSize.UNKNOWN; int width = videoSize.width; int height = videoSize.height; - int unappliedRotationDegrees = videoSize.unappliedRotationDegrees; float videoAspectRatio = (height == 0 || width == 0) ? 0 : (width * videoSize.pixelWidthHeightRatio) / height; - - if (surfaceView instanceof TextureView) { - // Try to apply rotation transformation when our surface is a TextureView. - if (videoAspectRatio > 0 - && (unappliedRotationDegrees == 90 || unappliedRotationDegrees == 270)) { - // We will apply a rotation 90/270 degree to the output texture of the TextureView. - // In this case, the output video's width and height will be swapped. - videoAspectRatio = 1 / videoAspectRatio; - } - if (textureViewRotation != 0) { - surfaceView.removeOnLayoutChangeListener(componentListener); - } - textureViewRotation = unappliedRotationDegrees; - if (textureViewRotation != 0) { - // The texture view's dimensions might be changed after layout step. - // So add an OnLayoutChangeListener to apply rotation after layout step. - surfaceView.addOnLayoutChangeListener(componentListener); - } - applyTextureViewRotation((TextureView) surfaceView, textureViewRotation); - } - onContentAspectRatioChanged( contentFrame, surfaceViewIgnoresVideoAspectRatio ? 0 : videoAspectRatio); } @@ -1805,29 +1780,6 @@ public class PlayerView extends FrameLayout implements AdViewProvider { aspectRatioFrame.setResizeMode(resizeMode); } - /** Applies a texture rotation to a {@link TextureView}. */ - private static void applyTextureViewRotation(TextureView textureView, int textureViewRotation) { - Matrix transformMatrix = new Matrix(); - float textureViewWidth = textureView.getWidth(); - float textureViewHeight = textureView.getHeight(); - if (textureViewWidth != 0 && textureViewHeight != 0 && textureViewRotation != 0) { - float pivotX = textureViewWidth / 2; - float pivotY = textureViewHeight / 2; - transformMatrix.postRotate(textureViewRotation, pivotX, pivotY); - - // After rotation, scale the rotated texture to fit the TextureView size. - RectF originalTextureRect = new RectF(0, 0, textureViewWidth, textureViewHeight); - RectF rotatedTextureRect = new RectF(); - transformMatrix.mapRect(rotatedTextureRect, originalTextureRect); - transformMatrix.postScale( - textureViewWidth / rotatedTextureRect.width(), - textureViewHeight / rotatedTextureRect.height(), - pivotX, - pivotY); - } - textureView.setTransform(transformMatrix); - } - @SuppressLint("InlinedApi") private boolean isDpadKey(int keyCode) { return keyCode == KeyEvent.KEYCODE_DPAD_UP @@ -1846,7 +1798,6 @@ public class PlayerView extends FrameLayout implements AdViewProvider { @SuppressWarnings("deprecation") private final class ComponentListener implements Player.Listener, - OnLayoutChangeListener, OnClickListener, PlayerControlView.VisibilityListener, PlayerControlView.OnFullScreenModeChangedListener { @@ -1956,22 +1907,6 @@ public class PlayerView extends FrameLayout implements AdViewProvider { } } - // OnLayoutChangeListener implementation - - @Override - public void onLayoutChange( - View view, - int left, - int top, - int right, - int bottom, - int oldLeft, - int oldTop, - int oldRight, - int oldBottom) { - applyTextureViewRotation((TextureView) view, textureViewRotation); - } - // OnClickListener implementation @Override