Commit 656556b8 by andrewlewis Committed by Oliver Woodman

Clean up naming for GLSurfaceViews

PiperOrigin-RevId: 277896757
parent 242a0053
......@@ -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
......
......@@ -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) {
......
......@@ -24,7 +24,7 @@
</style>
<style name="PlayerTheme.Spherical">
<item name="surface_type">spherical_view</item>
<item name="surface_type">spherical_gl_surface_view</item>
</style>
</resources>
......@@ -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`
......
......@@ -47,8 +47,8 @@ import com.google.android.exoplayer2.video.VideoRendererEventListener;
* <ul>
* <li>Message with type {@link C#MSG_SET_SURFACE} to set the output surface. The message payload
* should be the target {@link Surface}, or null.
* <li>Message with type {@link C#MSG_SET_OUTPUT_BUFFER_RENDERER} to set the output buffer
* renderer. The message payload should be the target {@link
* <li>Message with type {@link C#MSG_SET_VIDEO_DECODER_OUTPUT_BUFFER_RENDERER} to set the output
* buffer renderer. The message payload should be the target {@link
* VideoDecoderOutputBufferRenderer}, or null.
* </ul>
*/
......@@ -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);
......
......@@ -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`
......
......@@ -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);
......
......@@ -47,8 +47,8 @@ import com.google.android.exoplayer2.video.VideoRendererEventListener;
* <ul>
* <li>Message with type {@link C#MSG_SET_SURFACE} to set the output surface. The message payload
* should be the target {@link Surface}, or null.
* <li>Message with type {@link C#MSG_SET_OUTPUT_BUFFER_RENDERER} to set the output buffer
* renderer. The message payload should be the target {@link
* <li>Message with type {@link C#MSG_SET_VIDEO_DECODER_OUTPUT_BUFFER_RENDERER} to set the output
* buffer renderer. The message payload should be the target {@link
* VideoDecoderOutputBufferRenderer}, or null.
* </ul>
*/
......@@ -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;
......
......@@ -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.
*
* <p>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
......
......@@ -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}. */
......
......@@ -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();
}
}
......
......@@ -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.
*
* <p>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;
}
}
......@@ -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) {
......
......@@ -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;
* <li>Default: {@code fit}
* </ul>
* <li><b>{@code surface_type}</b> - 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.
* <ul>
* <li>Corresponding method: None
* <li>Default: {@code surface_view}
......@@ -276,8 +276,8 @@ public class PlayerView extends FrameLayout implements AdsLoader.AdViewProvider
private static final int SURFACE_TYPE_NONE = 0;
private static final int SURFACE_TYPE_SURFACE_VIEW = 1;
private static final int SURFACE_TYPE_TEXTURE_VIEW = 2;
private static final int SURFACE_TYPE_MONO360_VIEW = 3;
private static final int SURFACE_TYPE_VIDEO_GL_SURFACE_VIEW = 4;
private static final int SURFACE_TYPE_SPHERICAL_GL_SURFACE_VIEW = 3;
private static final int SURFACE_TYPE_VIDEO_DECODER_GL_SURFACE_VIEW = 4;
// LINT.ThenChange(../../../../../../res/values/attrs.xml)
@Nullable private final AspectRatioFrameLayout contentFrame;
......@@ -409,13 +409,13 @@ public class PlayerView extends FrameLayout implements AdsLoader.AdViewProvider
case SURFACE_TYPE_TEXTURE_VIEW:
surfaceView = new TextureView(context);
break;
case SURFACE_TYPE_MONO360_VIEW:
SphericalSurfaceView sphericalSurfaceView = new SphericalSurfaceView(context);
sphericalSurfaceView.setSingleTapListener(componentListener);
surfaceView = sphericalSurfaceView;
case SURFACE_TYPE_SPHERICAL_GL_SURFACE_VIEW:
SphericalGLSurfaceView sphericalGLSurfaceView = new SphericalGLSurfaceView(context);
sphericalGLSurfaceView.setSingleTapListener(componentListener);
surfaceView = sphericalGLSurfaceView;
break;
case SURFACE_TYPE_VIDEO_GL_SURFACE_VIEW:
surfaceView = new VideoDecoderSurfaceView(context);
case SURFACE_TYPE_VIDEO_DECODER_GL_SURFACE_VIEW:
surfaceView = new VideoDecoderGLSurfaceView(context);
break;
default:
surfaceView = new SurfaceView(context);
......@@ -547,10 +547,10 @@ public class PlayerView extends FrameLayout implements AdsLoader.AdViewProvider
oldVideoComponent.removeVideoListener(componentListener);
if (surfaceView instanceof TextureView) {
oldVideoComponent.clearVideoTextureView((TextureView) surfaceView);
} else if (surfaceView instanceof SphericalSurfaceView) {
((SphericalSurfaceView) surfaceView).setVideoComponent(null);
} else if (surfaceView instanceof VideoDecoderSurfaceView) {
oldVideoComponent.setOutputBufferRenderer(null);
} else if (surfaceView instanceof SphericalGLSurfaceView) {
((SphericalGLSurfaceView) surfaceView).setVideoComponent(null);
} else if (surfaceView instanceof VideoDecoderGLSurfaceView) {
oldVideoComponent.setVideoDecoderOutputBufferRenderer(null);
} else if (surfaceView instanceof SurfaceView) {
oldVideoComponent.clearVideoSurfaceView((SurfaceView) surfaceView);
}
......@@ -575,11 +575,11 @@ public class PlayerView extends FrameLayout implements AdsLoader.AdViewProvider
if (newVideoComponent != null) {
if (surfaceView instanceof TextureView) {
newVideoComponent.setVideoTextureView((TextureView) surfaceView);
} else if (surfaceView instanceof SphericalSurfaceView) {
((SphericalSurfaceView) surfaceView).setVideoComponent(newVideoComponent);
} else if (surfaceView instanceof VideoDecoderSurfaceView) {
newVideoComponent.setOutputBufferRenderer(
((VideoDecoderSurfaceView) surfaceView).getOutputBufferRenderer());
} else if (surfaceView instanceof SphericalGLSurfaceView) {
((SphericalGLSurfaceView) surfaceView).setVideoComponent(newVideoComponent);
} else if (surfaceView instanceof VideoDecoderGLSurfaceView) {
newVideoComponent.setVideoDecoderOutputBufferRenderer(
((VideoDecoderGLSurfaceView) surfaceView).getVideoDecoderOutputBufferRenderer());
} else if (surfaceView instanceof SurfaceView) {
newVideoComponent.setVideoSurfaceView((SurfaceView) surfaceView);
}
......@@ -1049,12 +1049,15 @@ public class PlayerView extends FrameLayout implements AdsLoader.AdViewProvider
* <li>{@link SurfaceView} by default, or if the {@code surface_type} attribute is set to {@code
* surface_view}.
* <li>{@link TextureView} if {@code surface_type} is {@code texture_view}.
* <li>{@link SphericalSurfaceView} if {@code surface_type} is {@code spherical_view}.
* <li>{@link SphericalGLSurfaceView} if {@code surface_type} is {@code
* spherical_gl_surface_view}.
* <li>{@link VideoDecoderGLSurfaceView} if {@code surface_type} is {@code
* video_decoder_gl_surface_view}.
* <li>{@code null} if {@code surface_type} is {@code none}.
* </ul>
*
* @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()}.
*
* <p>This method should typically be called in {@code Activity.onStart()}, or {@code
* Activity.onResume()} for API versions &lt;= 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()}.
*
* <p>This method should typically be called in {@code Activity.onStop()}, or {@code
* Activity.onPause()} for API versions &lt;= 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);
}
}
......
......@@ -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());
......
......@@ -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) {
......
......@@ -29,8 +29,8 @@
<enum name="none" value="0"/>
<enum name="surface_view" value="1"/>
<enum name="texture_view" value="2"/>
<enum name="spherical_view" value="3"/>
<enum name="video_decoder_surface_view" value="4"/>
<enum name="spherical_gl_surface_view" value="3"/>
<enum name="video_decoder_gl_surface_view" value="4"/>
</attr>
<!-- Must be kept in sync with RepeatModeUtil -->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment