Further unapplied rotation clean-up
Now the value is guaranteed to be zero (see bb9ff30c3a
), we can
remove the rotation handling for it in the UI module. We can also
enforce the documentation more clearly by not even setting the
value to anything other than zero.
PiperOrigin-RevId: 652772091
This commit is contained in:
parent
104fcc1c76
commit
d4c6e39dfb
@ -27,7 +27,6 @@ public final class VideoSize {
|
|||||||
|
|
||||||
private static final int DEFAULT_WIDTH = 0;
|
private static final int DEFAULT_WIDTH = 0;
|
||||||
private static final int DEFAULT_HEIGHT = 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;
|
private static final float DEFAULT_PIXEL_WIDTH_HEIGHT_RATIO = 1F;
|
||||||
|
|
||||||
public static final VideoSize UNKNOWN = new VideoSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
|
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
|
* square pixels this will be equal to 1.0. Different values are indicative of anamorphic
|
||||||
* content.
|
* content.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation") // Calling through to deprecated constructor
|
@SuppressWarnings("deprecation") // Setting deprecated field
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
public VideoSize(
|
public VideoSize(
|
||||||
@IntRange(from = 0) int width,
|
@IntRange(from = 0) int width,
|
||||||
@IntRange(from = 0) int height,
|
@IntRange(from = 0) int height,
|
||||||
@FloatRange(from = 0, fromInclusive = false) float pixelWidthHeightRatio) {
|
@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
|
* @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
|
@Deprecated
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
public VideoSize(
|
public VideoSize(
|
||||||
@ -97,13 +98,9 @@ public final class VideoSize {
|
|||||||
@IntRange(from = 0) int height,
|
@IntRange(from = 0) int height,
|
||||||
@IntRange(from = 0, to = 359) int unappliedRotationDegrees,
|
@IntRange(from = 0, to = 359) int unappliedRotationDegrees,
|
||||||
@FloatRange(from = 0, fromInclusive = false) float pixelWidthHeightRatio) {
|
@FloatRange(from = 0, fromInclusive = false) float pixelWidthHeightRatio) {
|
||||||
this.width = width;
|
this(width, height, pixelWidthHeightRatio);
|
||||||
this.height = height;
|
|
||||||
this.unappliedRotationDegrees = unappliedRotationDegrees;
|
|
||||||
this.pixelWidthHeightRatio = pixelWidthHeightRatio;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation") // Including deprecated field in equality
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
@ -113,50 +110,47 @@ public final class VideoSize {
|
|||||||
VideoSize other = (VideoSize) obj;
|
VideoSize other = (VideoSize) obj;
|
||||||
return width == other.width
|
return width == other.width
|
||||||
&& height == other.height
|
&& height == other.height
|
||||||
&& unappliedRotationDegrees == other.unappliedRotationDegrees
|
|
||||||
&& pixelWidthHeightRatio == other.pixelWidthHeightRatio;
|
&& pixelWidthHeightRatio == other.pixelWidthHeightRatio;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation") // Including deprecated field in hashCode
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = 7;
|
int result = 7;
|
||||||
result = 31 * result + width;
|
result = 31 * result + width;
|
||||||
result = 31 * result + height;
|
result = 31 * result + height;
|
||||||
result = 31 * result + unappliedRotationDegrees;
|
|
||||||
result = 31 * result + Float.floatToRawIntBits(pixelWidthHeightRatio);
|
result = 31 * result + Float.floatToRawIntBits(pixelWidthHeightRatio);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String FIELD_WIDTH = Util.intToStringMaxRadix(0);
|
private static final String FIELD_WIDTH = Util.intToStringMaxRadix(0);
|
||||||
private static final String FIELD_HEIGHT = Util.intToStringMaxRadix(1);
|
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);
|
private static final String FIELD_PIXEL_WIDTH_HEIGHT_RATIO = Util.intToStringMaxRadix(3);
|
||||||
|
|
||||||
@SuppressWarnings("deprecation") // Including deprecated field in bundle
|
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
public Bundle toBundle() {
|
public Bundle toBundle() {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
|
if (width != 0) {
|
||||||
bundle.putInt(FIELD_WIDTH, width);
|
bundle.putInt(FIELD_WIDTH, width);
|
||||||
|
}
|
||||||
|
if (height != 0) {
|
||||||
bundle.putInt(FIELD_HEIGHT, height);
|
bundle.putInt(FIELD_HEIGHT, height);
|
||||||
bundle.putInt(FIELD_UNAPPLIED_ROTATION_DEGREES, unappliedRotationDegrees);
|
}
|
||||||
|
if (pixelWidthHeightRatio != 1f) {
|
||||||
bundle.putFloat(FIELD_PIXEL_WIDTH_HEIGHT_RATIO, pixelWidthHeightRatio);
|
bundle.putFloat(FIELD_PIXEL_WIDTH_HEIGHT_RATIO, pixelWidthHeightRatio);
|
||||||
|
}
|
||||||
return bundle;
|
return bundle;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Restores a {@code VideoSize} from a {@link Bundle}. */
|
/** Restores a {@code VideoSize} from a {@link Bundle}. */
|
||||||
@SuppressWarnings("deprecation") // Parsing deprecated field from bundle
|
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
public static VideoSize fromBundle(Bundle bundle) {
|
public static VideoSize fromBundle(Bundle bundle) {
|
||||||
int width = bundle.getInt(FIELD_WIDTH, DEFAULT_WIDTH);
|
int width = bundle.getInt(FIELD_WIDTH, DEFAULT_WIDTH);
|
||||||
int height = bundle.getInt(FIELD_HEIGHT, DEFAULT_HEIGHT);
|
int height = bundle.getInt(FIELD_HEIGHT, DEFAULT_HEIGHT);
|
||||||
int unappliedRotationDegrees =
|
|
||||||
bundle.getInt(FIELD_UNAPPLIED_ROTATION_DEGREES, DEFAULT_UNAPPLIED_ROTATION_DEGREES);
|
|
||||||
float pixelWidthHeightRatio =
|
float pixelWidthHeightRatio =
|
||||||
bundle.getFloat(FIELD_PIXEL_WIDTH_HEIGHT_RATIO, DEFAULT_PIXEL_WIDTH_HEIGHT_RATIO);
|
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);
|
||||||
}
|
}
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
@ -32,14 +32,9 @@ public final class VideoSizeTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("deprecation") // Testing bundling of deprecated field.
|
|
||||||
public void roundTripViaBundle_ofArbitraryVideoSize_yieldsEqualInstance() {
|
public void roundTripViaBundle_ofArbitraryVideoSize_yieldsEqualInstance() {
|
||||||
VideoSize videoSize =
|
VideoSize videoSize =
|
||||||
new VideoSize(
|
new VideoSize(/* width= */ 9, /* height= */ 8, /* pixelWidthHeightRatio= */ 6);
|
||||||
/* width= */ 9,
|
|
||||||
/* height= */ 8,
|
|
||||||
/* unappliedRotationDegrees= */ 7,
|
|
||||||
/* pixelWidthHeightRatio= */ 6);
|
|
||||||
assertThat(roundTripViaBundle(videoSize)).isEqualTo(videoSize);
|
assertThat(roundTripViaBundle(videoSize)).isEqualTo(videoSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -762,7 +762,7 @@ public class DefaultAnalyticsCollector implements AnalyticsCollector {
|
|||||||
eventTime,
|
eventTime,
|
||||||
videoSize.width,
|
videoSize.width,
|
||||||
videoSize.height,
|
videoSize.height,
|
||||||
videoSize.unappliedRotationDegrees,
|
/* unappliedRotationDegrees= */ 0,
|
||||||
videoSize.pixelWidthHeightRatio);
|
videoSize.pixelWidthHeightRatio);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -670,11 +670,7 @@ public class MediaCodecVideoRendererTest {
|
|||||||
|
|
||||||
verify(eventListener)
|
verify(eventListener)
|
||||||
.onVideoSizeChanged(
|
.onVideoSizeChanged(
|
||||||
new VideoSize(
|
new VideoSize(VIDEO_H264.width, VIDEO_H264.height, VIDEO_H264.pixelWidthHeightRatio));
|
||||||
VIDEO_H264.width,
|
|
||||||
VIDEO_H264.height,
|
|
||||||
VIDEO_H264.rotationDegrees,
|
|
||||||
VIDEO_H264.pixelWidthHeightRatio));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -877,11 +877,7 @@ public class MediaControllerTest {
|
|||||||
@SuppressWarnings("deprecation") // Testing propagation of deprecated unappliedRotationDegrees.
|
@SuppressWarnings("deprecation") // Testing propagation of deprecated unappliedRotationDegrees.
|
||||||
public void getVideoSize_returnsVideoSizeOfPlayerInSession() throws Exception {
|
public void getVideoSize_returnsVideoSizeOfPlayerInSession() throws Exception {
|
||||||
VideoSize testVideoSize =
|
VideoSize testVideoSize =
|
||||||
new VideoSize(
|
new VideoSize(/* width= */ 100, /* height= */ 42, /* pixelWidthHeightRatio= */ 1.2f);
|
||||||
/* width= */ 100,
|
|
||||||
/* height= */ 42,
|
|
||||||
/* unappliedRotationDegrees= */ 90,
|
|
||||||
/* pixelWidthHeightRatio= */ 1.2f);
|
|
||||||
Bundle playerConfig =
|
Bundle playerConfig =
|
||||||
new RemoteMediaSession.MockPlayerConfigBuilder().setVideoSize(testVideoSize).build();
|
new RemoteMediaSession.MockPlayerConfigBuilder().setVideoSize(testVideoSize).build();
|
||||||
remoteSession.setPlayer(playerConfig);
|
remoteSession.setPlayer(playerConfig);
|
||||||
|
@ -32,8 +32,6 @@ import android.content.res.TypedArray;
|
|||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Matrix;
|
|
||||||
import android.graphics.RectF;
|
|
||||||
import android.graphics.drawable.BitmapDrawable;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.opengl.GLSurfaceView;
|
import android.opengl.GLSurfaceView;
|
||||||
@ -335,7 +333,6 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
|
|||||||
private boolean controllerAutoShow;
|
private boolean controllerAutoShow;
|
||||||
private boolean controllerHideDuringAds;
|
private boolean controllerHideDuringAds;
|
||||||
private boolean controllerHideOnTouch;
|
private boolean controllerHideOnTouch;
|
||||||
private int textureViewRotation;
|
|
||||||
|
|
||||||
public PlayerView(Context context) {
|
public PlayerView(Context context) {
|
||||||
this(context, /* attrs= */ null);
|
this(context, /* attrs= */ null);
|
||||||
@ -1752,30 +1749,8 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
|
|||||||
VideoSize videoSize = player != null ? player.getVideoSize() : VideoSize.UNKNOWN;
|
VideoSize videoSize = player != null ? player.getVideoSize() : VideoSize.UNKNOWN;
|
||||||
int width = videoSize.width;
|
int width = videoSize.width;
|
||||||
int height = videoSize.height;
|
int height = videoSize.height;
|
||||||
int unappliedRotationDegrees = videoSize.unappliedRotationDegrees;
|
|
||||||
float videoAspectRatio =
|
float videoAspectRatio =
|
||||||
(height == 0 || width == 0) ? 0 : (width * videoSize.pixelWidthHeightRatio) / height;
|
(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(
|
onContentAspectRatioChanged(
|
||||||
contentFrame, surfaceViewIgnoresVideoAspectRatio ? 0 : videoAspectRatio);
|
contentFrame, surfaceViewIgnoresVideoAspectRatio ? 0 : videoAspectRatio);
|
||||||
}
|
}
|
||||||
@ -1805,29 +1780,6 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
|
|||||||
aspectRatioFrame.setResizeMode(resizeMode);
|
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")
|
@SuppressLint("InlinedApi")
|
||||||
private boolean isDpadKey(int keyCode) {
|
private boolean isDpadKey(int keyCode) {
|
||||||
return keyCode == KeyEvent.KEYCODE_DPAD_UP
|
return keyCode == KeyEvent.KEYCODE_DPAD_UP
|
||||||
@ -1846,7 +1798,6 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
|
|||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
private final class ComponentListener
|
private final class ComponentListener
|
||||||
implements Player.Listener,
|
implements Player.Listener,
|
||||||
OnLayoutChangeListener,
|
|
||||||
OnClickListener,
|
OnClickListener,
|
||||||
PlayerControlView.VisibilityListener,
|
PlayerControlView.VisibilityListener,
|
||||||
PlayerControlView.OnFullScreenModeChangedListener {
|
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
|
// OnClickListener implementation
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user