diff --git a/RELEASENOTES.md b/RELEASENOTES.md index e787bb1777..e2713f16bf 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -85,6 +85,7 @@ `C.MSG_SET_OUTPUT_BUFFER_RENDERER`. * Use `VideoDecoderRenderer` as an implementation of `VideoDecoderOutputBufferRenderer`, instead of `VideoDecoderSurfaceView`. +* Rename `spherical_view` surface type to `spherical_gl_surface_view`. * Add automatic audio becoming noisy handling to `SimpleExoPlayer`, available through `SimpleExoPlayer.setHandleAudioBecomingNoisy`. * Post `AudioFocusManager.onAudioFocusChange` events to eventHandler, avoiding diff --git a/demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java b/demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java index 361e829d66..74e919293d 100644 --- a/demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java +++ b/demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java @@ -69,7 +69,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.ui.DebugTextViewHelper; import com.google.android.exoplayer2.ui.PlayerControlView; import com.google.android.exoplayer2.ui.PlayerView; -import com.google.android.exoplayer2.ui.spherical.SphericalSurfaceView; +import com.google.android.exoplayer2.ui.spherical.SphericalGLSurfaceView; import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.HttpDataSource; import com.google.android.exoplayer2.util.ErrorMessageProvider; @@ -193,7 +193,7 @@ public class PlayerActivity extends AppCompatActivity finish(); return; } - ((SphericalSurfaceView) playerView.getVideoSurfaceView()).setDefaultStereoMode(stereoMode); + ((SphericalGLSurfaceView) playerView.getVideoSurfaceView()).setDefaultStereoMode(stereoMode); } if (savedInstanceState != null) { diff --git a/demos/main/src/main/res/values/styles.xml b/demos/main/src/main/res/values/styles.xml index 04c5b90edc..a2ebde37bd 100644 --- a/demos/main/src/main/res/values/styles.xml +++ b/demos/main/src/main/res/values/styles.xml @@ -24,7 +24,7 @@ diff --git a/extensions/av1/README.md b/extensions/av1/README.md index 8197a7ab2b..fb7bc4bde8 100644 --- a/extensions/av1/README.md +++ b/extensions/av1/README.md @@ -96,9 +96,10 @@ gets from the libgav1 decoder: * GL rendering using GL shader for color space conversion * If you are using `SimpleExoPlayer` with `PlayerView`, enable this option by - setting `surface_type` of `PlayerView` to be `video_decoder_surface_view`. + setting `surface_type` of `PlayerView` to be + `video_decoder_gl_surface_view`. * Otherwise, enable this option by sending `Libgav1VideoRenderer` a message - of type `C.MSG_SET_OUTPUT_BUFFER_RENDERER` with an instance of + of type `C.MSG_SET_VIDEO_DECODER_OUTPUT_BUFFER_RENDERER` with an instance of `VideoDecoderOutputBufferRenderer` as its object. * Native rendering using `ANativeWindow` diff --git a/extensions/av1/src/main/java/com/google/android/exoplayer2/ext/av1/Libgav1VideoRenderer.java b/extensions/av1/src/main/java/com/google/android/exoplayer2/ext/av1/Libgav1VideoRenderer.java index 1ae972477d..81cfec29fd 100644 --- a/extensions/av1/src/main/java/com/google/android/exoplayer2/ext/av1/Libgav1VideoRenderer.java +++ b/extensions/av1/src/main/java/com/google/android/exoplayer2/ext/av1/Libgav1VideoRenderer.java @@ -47,8 +47,8 @@ import com.google.android.exoplayer2.video.VideoRendererEventListener; * */ @@ -186,7 +186,7 @@ public class Libgav1VideoRenderer extends SimpleDecoderVideoRenderer { public void handleMessage(int messageType, @Nullable Object message) throws ExoPlaybackException { if (messageType == C.MSG_SET_SURFACE) { setOutputSurface((Surface) message); - } else if (messageType == C.MSG_SET_OUTPUT_BUFFER_RENDERER) { + } else if (messageType == C.MSG_SET_VIDEO_DECODER_OUTPUT_BUFFER_RENDERER) { setOutputBufferRenderer((VideoDecoderOutputBufferRenderer) message); } else { super.handleMessage(messageType, message); diff --git a/extensions/vp9/README.md b/extensions/vp9/README.md index a2e8736f82..1377f74f2a 100644 --- a/extensions/vp9/README.md +++ b/extensions/vp9/README.md @@ -114,9 +114,10 @@ gets from the libvpx decoder: * GL rendering using GL shader for color space conversion * If you are using `SimpleExoPlayer` with `PlayerView`, enable this option by - setting `surface_type` of `PlayerView` to be `video_decoder_surface_view`. + setting `surface_type` of `PlayerView` to be + `video_decoder_gl_surface_view`. * Otherwise, enable this option by sending `LibvpxVideoRenderer` a message of - type `C.MSG_SET_OUTPUT_BUFFER_RENDERER` with an instance of + type `C.MSG_SET_VIDEO_DECODER_OUTPUT_BUFFER_RENDERER` with an instance of `VideoDecoderOutputBufferRenderer` as its object. * Native rendering using `ANativeWindow` diff --git a/extensions/vp9/src/androidTest/java/com/google/android/exoplayer2/ext/vp9/VpxPlaybackTest.java b/extensions/vp9/src/androidTest/java/com/google/android/exoplayer2/ext/vp9/VpxPlaybackTest.java index 85ceabc909..4fc23c300e 100644 --- a/extensions/vp9/src/androidTest/java/com/google/android/exoplayer2/ext/vp9/VpxPlaybackTest.java +++ b/extensions/vp9/src/androidTest/java/com/google/android/exoplayer2/ext/vp9/VpxPlaybackTest.java @@ -32,7 +32,7 @@ import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.source.ProgressiveMediaSource; import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; import com.google.android.exoplayer2.util.Log; -import com.google.android.exoplayer2.video.VideoDecoderSurfaceView; +import com.google.android.exoplayer2.video.VideoDecoderGLSurfaceView; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -123,8 +123,8 @@ public class VpxPlaybackTest { .createMediaSource(uri); player .createMessage(videoRenderer) - .setType(C.MSG_SET_OUTPUT_BUFFER_RENDERER) - .setPayload(new VideoDecoderSurfaceView(context).getOutputBufferRenderer()) + .setType(C.MSG_SET_VIDEO_DECODER_OUTPUT_BUFFER_RENDERER) + .setPayload(new VideoDecoderGLSurfaceView(context).getVideoDecoderOutputBufferRenderer()) .send(); player.prepare(mediaSource); player.setPlayWhenReady(true); diff --git a/extensions/vp9/src/main/java/com/google/android/exoplayer2/ext/vp9/LibvpxVideoRenderer.java b/extensions/vp9/src/main/java/com/google/android/exoplayer2/ext/vp9/LibvpxVideoRenderer.java index 31195a3070..31c663c6eb 100644 --- a/extensions/vp9/src/main/java/com/google/android/exoplayer2/ext/vp9/LibvpxVideoRenderer.java +++ b/extensions/vp9/src/main/java/com/google/android/exoplayer2/ext/vp9/LibvpxVideoRenderer.java @@ -47,8 +47,8 @@ import com.google.android.exoplayer2.video.VideoRendererEventListener; * */ @@ -267,7 +267,7 @@ public class LibvpxVideoRenderer extends SimpleDecoderVideoRenderer { public void handleMessage(int messageType, @Nullable Object message) throws ExoPlaybackException { if (messageType == C.MSG_SET_SURFACE) { setOutputSurface((Surface) message); - } else if (messageType == C.MSG_SET_OUTPUT_BUFFER_RENDERER) { + } else if (messageType == C.MSG_SET_VIDEO_DECODER_OUTPUT_BUFFER_RENDERER) { setOutputBufferRenderer((VideoDecoderOutputBufferRenderer) message); } else if (messageType == C.MSG_SET_VIDEO_FRAME_METADATA_LISTENER) { frameMetadataListener = (VideoFrameMetadataListener) message; diff --git a/library/core/src/main/java/com/google/android/exoplayer2/C.java b/library/core/src/main/java/com/google/android/exoplayer2/C.java index a86d927acb..567ce98b1a 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/C.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/C.java @@ -834,8 +834,12 @@ public final class C { * The type of a message that can be passed to a {@link SimpleDecoderVideoRenderer} via {@link * ExoPlayer#createMessage(Target)}. The message payload should be the target {@link * VideoDecoderOutputBufferRenderer}, or null. + * + *

This message is intended only for use with extension renderers that expect a {@link + * VideoDecoderOutputBufferRenderer}. For other use cases, an output surface should be passed via + * {@link #MSG_SET_SURFACE} instead. */ - public static final int MSG_SET_OUTPUT_BUFFER_RENDERER = 8; + public static final int MSG_SET_VIDEO_DECODER_OUTPUT_BUFFER_RENDERER = 8; /** * Applications or extensions may define custom {@code MSG_*} constants that can be passed to diff --git a/library/core/src/main/java/com/google/android/exoplayer2/Player.java b/library/core/src/main/java/com/google/android/exoplayer2/Player.java index a91396f77a..fa0caeb92d 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/Player.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/Player.java @@ -283,11 +283,16 @@ public interface Player { void clearVideoTextureView(TextureView textureView); /** - * Sets the output buffer renderer. + * Sets the video decoder output buffer renderer. This is intended for use only with extension + * renderers that accept {@link C#MSG_SET_VIDEO_DECODER_OUTPUT_BUFFER_RENDERER}. For most use + * cases, an output surface or view should be passed via {@link #setVideoSurface(Surface)} or + * {@link #setVideoSurfaceView(SurfaceView)} instead. * - * @param outputBufferRenderer The output buffer renderer. + * @param videoDecoderOutputBufferRenderer The video decoder output buffer renderer, or {@code + * null} to clear the output buffer renderer. */ - void setOutputBufferRenderer(VideoDecoderOutputBufferRenderer outputBufferRenderer); + void setVideoDecoderOutputBufferRenderer( + @Nullable VideoDecoderOutputBufferRenderer videoDecoderOutputBufferRenderer); } /** The text component of a {@link Player}. */ diff --git a/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java b/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java index b77e8a4150..78d6f1d9d8 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java @@ -610,15 +610,16 @@ public class SimpleExoPlayer extends BasePlayer } @Override - public void setOutputBufferRenderer(VideoDecoderOutputBufferRenderer outputBufferRenderer) { + public void setVideoDecoderOutputBufferRenderer( + @Nullable VideoDecoderOutputBufferRenderer videoDecoderOutputBufferRenderer) { verifyApplicationThread(); setVideoSurface(null); for (Renderer renderer : renderers) { if (renderer.getTrackType() == C.TRACK_TYPE_VIDEO) { player .createMessage(renderer) - .setType(C.MSG_SET_OUTPUT_BUFFER_RENDERER) - .setPayload(outputBufferRenderer) + .setType(C.MSG_SET_VIDEO_DECODER_OUTPUT_BUFFER_RENDERER) + .setPayload(videoDecoderOutputBufferRenderer) .send(); } } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/video/VideoDecoderSurfaceView.java b/library/core/src/main/java/com/google/android/exoplayer2/video/VideoDecoderGLSurfaceView.java similarity index 59% rename from library/core/src/main/java/com/google/android/exoplayer2/video/VideoDecoderSurfaceView.java rename to library/core/src/main/java/com/google/android/exoplayer2/video/VideoDecoderGLSurfaceView.java index 0436c919a0..99f3d07b65 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/video/VideoDecoderSurfaceView.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/video/VideoDecoderGLSurfaceView.java @@ -20,27 +20,28 @@ import android.opengl.GLSurfaceView; import android.util.AttributeSet; import androidx.annotation.Nullable; -/** A GLSurfaceView extension that scales itself to the given aspect ratio. */ -public class VideoDecoderSurfaceView extends GLSurfaceView { +/** + * GLSurfaceView for rendering video output. To render video in this view, call {@link + * #getVideoDecoderOutputBufferRenderer()} to get a {@link VideoDecoderOutputBufferRenderer} that + * will render video decoder output buffers in this view. + * + *

This view is intended for use only with extension renderers. For other use cases a {@link + * android.view.SurfaceView} or {@link android.view.TextureView} should be used instead. + */ +public class VideoDecoderGLSurfaceView extends GLSurfaceView { private final VideoDecoderRenderer renderer; - /** - * Creates VideoDecoderSurfaceView. - * - * @param context A {@link Context}. - */ - public VideoDecoderSurfaceView(Context context) { + /** @param context A {@link Context}. */ + public VideoDecoderGLSurfaceView(Context context) { this(context, /* attrs= */ null); } /** - * Creates VideoDecoderSurfaceView. - * * @param context A {@link Context}. * @param attrs Custom attributes. */ - public VideoDecoderSurfaceView(Context context, @Nullable AttributeSet attrs) { + public VideoDecoderGLSurfaceView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); renderer = new VideoDecoderRenderer(this); setPreserveEGLContextOnPause(true); @@ -49,12 +50,8 @@ public class VideoDecoderSurfaceView extends GLSurfaceView { setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); } - /** - * Returns the output buffer renderer used. - * - * @return {@link VideoDecoderOutputBuffer}. - */ - public VideoDecoderOutputBufferRenderer getOutputBufferRenderer() { + /** Returns the {@link VideoDecoderOutputBufferRenderer} that will render frames in this view. */ + public VideoDecoderOutputBufferRenderer getVideoDecoderOutputBufferRenderer() { return renderer; } } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/video/VideoDecoderRenderer.java b/library/core/src/main/java/com/google/android/exoplayer2/video/VideoDecoderRenderer.java index 25c0742310..cb9c4eb59b 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/video/VideoDecoderRenderer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/video/VideoDecoderRenderer.java @@ -17,6 +17,7 @@ package com.google.android.exoplayer2.video; import android.opengl.GLES20; import android.opengl.GLSurfaceView; +import androidx.annotation.Nullable; import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.GlUtil; import java.nio.FloatBuffer; @@ -97,6 +98,7 @@ import javax.microedition.khronos.opengles.GL10; private int[] previousWidths; private int[] previousStrides; + @Nullable private VideoDecoderOutputBuffer renderedOutputBuffer; // Accessed only from the GL thread. public VideoDecoderRenderer(GLSurfaceView surfaceView) { diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java index 3c6f6e1d9a..2e29dd3388 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java @@ -59,12 +59,12 @@ import com.google.android.exoplayer2.trackselection.TrackSelection; import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.ui.AspectRatioFrameLayout.ResizeMode; import com.google.android.exoplayer2.ui.spherical.SingleTapListener; -import com.google.android.exoplayer2.ui.spherical.SphericalSurfaceView; +import com.google.android.exoplayer2.ui.spherical.SphericalGLSurfaceView; import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.ErrorMessageProvider; import com.google.android.exoplayer2.util.RepeatModeUtil; import com.google.android.exoplayer2.util.Util; -import com.google.android.exoplayer2.video.VideoDecoderSurfaceView; +import com.google.android.exoplayer2.video.VideoDecoderGLSurfaceView; import com.google.android.exoplayer2.video.VideoListener; import java.lang.annotation.Documented; import java.lang.annotation.Retention; @@ -131,11 +131,11 @@ import java.util.List; *

  • Default: {@code fit} * *
  • {@code surface_type} - The type of surface view used for video playbacks. Valid - * values are {@code surface_view}, {@code texture_view}, {@code spherical_view} and {@code - * none}. Using {@code none} is recommended for audio only applications, since creating the - * surface can be expensive. Using {@code surface_view} is recommended for video applications. - * Note, TextureView can only be used in a hardware accelerated window. When rendered in - * software, TextureView will draw nothing. + * values are {@code surface_view}, {@code texture_view}, {@code spherical_gl_surface_view}, + * {@code video_decoder_gl_surface_view} and {@code none}. Using {@code none} is recommended + * for audio only applications, since creating the surface can be expensive. Using {@code + * surface_view} is recommended for video applications. Note, TextureView can only be used in + * a hardware accelerated window. When rendered in software, TextureView will draw nothing. * * - * @return The {@link SurfaceView}, {@link TextureView}, {@link SphericalSurfaceView} or {@code - * null}. + * @return The {@link SurfaceView}, {@link TextureView}, {@link SphericalGLSurfaceView}, {@link + * VideoDecoderGLSurfaceView} or {@code null}. */ @Nullable public View getVideoSurfaceView() { @@ -1122,34 +1125,34 @@ public class PlayerView extends FrameLayout implements AdsLoader.AdViewProvider /** * Should be called when the player is visible to the user and if {@code surface_type} is {@code - * spherical_view}. It is the counterpart to {@link #onPause()}. + * spherical_gl_surface_view}. It is the counterpart to {@link #onPause()}. * *

    This method should typically be called in {@code Activity.onStart()}, or {@code * Activity.onResume()} for API versions <= 23. */ public void onResume() { - if (surfaceView instanceof SphericalSurfaceView) { - ((SphericalSurfaceView) surfaceView).onResume(); + if (surfaceView instanceof SphericalGLSurfaceView) { + ((SphericalGLSurfaceView) surfaceView).onResume(); } } /** * Should be called when the player is no longer visible to the user and if {@code surface_type} - * is {@code spherical_view}. It is the counterpart to {@link #onResume()}. + * is {@code spherical_gl_surface_view}. It is the counterpart to {@link #onResume()}. * *

    This method should typically be called in {@code Activity.onStop()}, or {@code * Activity.onPause()} for API versions <= 23. */ public void onPause() { - if (surfaceView instanceof SphericalSurfaceView) { - ((SphericalSurfaceView) surfaceView).onPause(); + if (surfaceView instanceof SphericalGLSurfaceView) { + ((SphericalGLSurfaceView) surfaceView).onPause(); } } /** * Called when there's a change in the aspect ratio of the content being displayed. The default * implementation sets the aspect ratio of the content frame to that of the content, unless the - * content view is a {@link SphericalSurfaceView} in which case the frame's aspect ratio is + * content view is a {@link SphericalGLSurfaceView} in which case the frame's aspect ratio is * cleared. * * @param contentAspectRatio The aspect ratio of the content. @@ -1162,7 +1165,7 @@ public class PlayerView extends FrameLayout implements AdsLoader.AdViewProvider @Nullable View contentView) { if (contentFrame != null) { contentFrame.setAspectRatio( - contentView instanceof SphericalSurfaceView ? 0 : contentAspectRatio); + contentView instanceof SphericalGLSurfaceView ? 0 : contentAspectRatio); } } diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/spherical/SphericalSurfaceView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/spherical/SphericalGLSurfaceView.java similarity index 98% rename from library/ui/src/main/java/com/google/android/exoplayer2/ui/spherical/SphericalSurfaceView.java rename to library/ui/src/main/java/com/google/android/exoplayer2/ui/spherical/SphericalGLSurfaceView.java index d2089759f6..c01fccf54b 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/spherical/SphericalSurfaceView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/spherical/SphericalGLSurfaceView.java @@ -51,7 +51,7 @@ import javax.microedition.khronos.opengles.GL10; * apply the touch and sensor rotations in the correct order or the user's touch manipulations won't * match what they expect. */ -public final class SphericalSurfaceView extends GLSurfaceView { +public final class SphericalGLSurfaceView extends GLSurfaceView { // Arbitrary vertical field of view. private static final int FIELD_OF_VIEW_DEGREES = 90; @@ -73,11 +73,11 @@ public final class SphericalSurfaceView extends GLSurfaceView { @Nullable private Surface surface; @Nullable private Player.VideoComponent videoComponent; - public SphericalSurfaceView(Context context) { + public SphericalGLSurfaceView(Context context) { this(context, null); } - public SphericalSurfaceView(Context context, @Nullable AttributeSet attributeSet) { + public SphericalGLSurfaceView(Context context, @Nullable AttributeSet attributeSet) { super(context, attributeSet); mainHandler = new Handler(Looper.getMainLooper()); diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/spherical/TouchTracker.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/spherical/TouchTracker.java index 66a0f20091..20b7dc0319 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/spherical/TouchTracker.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/spherical/TouchTracker.java @@ -75,7 +75,7 @@ import androidx.annotation.Nullable; this.listener = listener; this.pxPerDegrees = pxPerDegrees; gestureDetector = new GestureDetector(context, this); - roll = SphericalSurfaceView.UPRIGHT_ROLL; + roll = SphericalGLSurfaceView.UPRIGHT_ROLL; } public void setSingleTapListener(@Nullable SingleTapListener listener) { diff --git a/library/ui/src/main/res/values/attrs.xml b/library/ui/src/main/res/values/attrs.xml index b342d5d888..535bf320fb 100644 --- a/library/ui/src/main/res/values/attrs.xml +++ b/library/ui/src/main/res/values/attrs.xml @@ -29,8 +29,8 @@ - - + +