Commit f633e76c by tonihei

Plumb PlayerId to renderers.

We can rename the existing setIndex method to a more generic init
as this method is only called by EPII and implemented by BaseRenderer
anyway.

PiperOrigin-RevId: 408616055
parent 30c77e8e
...@@ -15,9 +15,11 @@ ...@@ -15,9 +15,11 @@
*/ */
package com.google.android.exoplayer2; package com.google.android.exoplayer2;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static java.lang.Math.max; import static java.lang.Math.max;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.analytics.PlayerId;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer; import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer.InsufficientCapacityException; import com.google.android.exoplayer2.decoder.DecoderInputBuffer.InsufficientCapacityException;
import com.google.android.exoplayer2.source.SampleStream; import com.google.android.exoplayer2.source.SampleStream;
...@@ -26,6 +28,7 @@ import com.google.android.exoplayer2.source.SampleStream.ReadFlags; ...@@ -26,6 +28,7 @@ import com.google.android.exoplayer2.source.SampleStream.ReadFlags;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.MediaClock; import com.google.android.exoplayer2.util.MediaClock;
import java.io.IOException; import java.io.IOException;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/** An abstract base class suitable for most {@link Renderer} implementations. */ /** An abstract base class suitable for most {@link Renderer} implementations. */
public abstract class BaseRenderer implements Renderer, RendererCapabilities { public abstract class BaseRenderer implements Renderer, RendererCapabilities {
...@@ -35,6 +38,7 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities { ...@@ -35,6 +38,7 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
@Nullable private RendererConfiguration configuration; @Nullable private RendererConfiguration configuration;
private int index; private int index;
private @MonotonicNonNull PlayerId playerId;
private int state; private int state;
@Nullable private SampleStream stream; @Nullable private SampleStream stream;
@Nullable private Format[] streamFormats; @Nullable private Format[] streamFormats;
...@@ -65,8 +69,9 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities { ...@@ -65,8 +69,9 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
} }
@Override @Override
public final void setIndex(int index) { public final void init(int index, PlayerId playerId) {
this.index = index; this.index = index;
this.playerId = playerId;
} }
@Override @Override
...@@ -328,12 +333,25 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities { ...@@ -328,12 +333,25 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
return Assertions.checkNotNull(configuration); return Assertions.checkNotNull(configuration);
} }
/** Returns the index of the renderer within the player. */ /**
* Returns the index of the renderer within the player.
*
* <p>Must only be used after the renderer has been initialized by the player.
*/
protected final int getIndex() { protected final int getIndex() {
return index; return index;
} }
/** /**
* Returns the {@link PlayerId} of the player using this renderer.
*
* <p>Must only be used after the renderer has been initialized by the player.
*/
protected final PlayerId getPlayerId() {
return checkNotNull(playerId);
}
/**
* Creates an {@link ExoPlaybackException} of type {@link ExoPlaybackException#TYPE_RENDERER} for * Creates an {@link ExoPlaybackException} of type {@link ExoPlaybackException#TYPE_RENDERER} for
* this renderer. * this renderer.
* *
......
...@@ -22,6 +22,7 @@ import static java.lang.Math.max; ...@@ -22,6 +22,7 @@ import static java.lang.Math.max;
import static java.lang.Math.min; import static java.lang.Math.min;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.media.metrics.LogSessionId;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.util.Pair; import android.util.Pair;
...@@ -30,9 +31,11 @@ import android.view.SurfaceHolder; ...@@ -30,9 +31,11 @@ import android.view.SurfaceHolder;
import android.view.SurfaceView; import android.view.SurfaceView;
import android.view.TextureView; import android.view.TextureView;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import com.google.android.exoplayer2.ExoPlayer.AudioOffloadListener; import com.google.android.exoplayer2.ExoPlayer.AudioOffloadListener;
import com.google.android.exoplayer2.PlayerMessage.Target; import com.google.android.exoplayer2.PlayerMessage.Target;
import com.google.android.exoplayer2.analytics.AnalyticsCollector; import com.google.android.exoplayer2.analytics.AnalyticsCollector;
import com.google.android.exoplayer2.analytics.PlayerId;
import com.google.android.exoplayer2.audio.AudioAttributes; import com.google.android.exoplayer2.audio.AudioAttributes;
import com.google.android.exoplayer2.metadata.Metadata; import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.source.MediaSource;
...@@ -246,6 +249,7 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -246,6 +249,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
addListener(analyticsCollector); addListener(analyticsCollector);
bandwidthMeter.addEventListener(new Handler(applicationLooper), analyticsCollector); bandwidthMeter.addEventListener(new Handler(applicationLooper), analyticsCollector);
} }
PlayerId playerId = Util.SDK_INT < 31 ? new PlayerId() : Api31.createPlayerId();
internalPlayer = internalPlayer =
new ExoPlayerImplInternal( new ExoPlayerImplInternal(
renderers, renderers,
...@@ -262,7 +266,8 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -262,7 +266,8 @@ import java.util.concurrent.CopyOnWriteArraySet;
pauseAtEndOfMediaItems, pauseAtEndOfMediaItems,
applicationLooper, applicationLooper,
clock, clock,
playbackInfoUpdateListener); playbackInfoUpdateListener,
playerId);
} }
/** /**
...@@ -1856,4 +1861,14 @@ import java.util.concurrent.CopyOnWriteArraySet; ...@@ -1856,4 +1861,14 @@ import java.util.concurrent.CopyOnWriteArraySet;
return timeline; return timeline;
} }
} }
@RequiresApi(31)
private static final class Api31 {
private Api31() {}
public static PlayerId createPlayerId() {
// TODO: Create a MediaMetricsListener and obtain LogSessionId from it.
return new PlayerId(LogSessionId.LOG_SESSION_ID_NONE);
}
}
} }
...@@ -35,6 +35,7 @@ import com.google.android.exoplayer2.Player.PlayWhenReadyChangeReason; ...@@ -35,6 +35,7 @@ import com.google.android.exoplayer2.Player.PlayWhenReadyChangeReason;
import com.google.android.exoplayer2.Player.PlaybackSuppressionReason; import com.google.android.exoplayer2.Player.PlaybackSuppressionReason;
import com.google.android.exoplayer2.Player.RepeatMode; import com.google.android.exoplayer2.Player.RepeatMode;
import com.google.android.exoplayer2.analytics.AnalyticsCollector; import com.google.android.exoplayer2.analytics.AnalyticsCollector;
import com.google.android.exoplayer2.analytics.PlayerId;
import com.google.android.exoplayer2.drm.DrmSession; import com.google.android.exoplayer2.drm.DrmSession;
import com.google.android.exoplayer2.metadata.Metadata; import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.source.BehindLiveWindowException; import com.google.android.exoplayer2.source.BehindLiveWindowException;
...@@ -229,7 +230,8 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -229,7 +230,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
boolean pauseAtEndOfWindow, boolean pauseAtEndOfWindow,
Looper applicationLooper, Looper applicationLooper,
Clock clock, Clock clock,
PlaybackInfoUpdateListener playbackInfoUpdateListener) { PlaybackInfoUpdateListener playbackInfoUpdateListener,
PlayerId playerId) {
this.playbackInfoUpdateListener = playbackInfoUpdateListener; this.playbackInfoUpdateListener = playbackInfoUpdateListener;
this.renderers = renderers; this.renderers = renderers;
this.trackSelector = trackSelector; this.trackSelector = trackSelector;
...@@ -252,7 +254,7 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -252,7 +254,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
playbackInfoUpdate = new PlaybackInfoUpdate(playbackInfo); playbackInfoUpdate = new PlaybackInfoUpdate(playbackInfo);
rendererCapabilities = new RendererCapabilities[renderers.length]; rendererCapabilities = new RendererCapabilities[renderers.length];
for (int i = 0; i < renderers.length; i++) { for (int i = 0; i < renderers.length; i++) {
renderers[i].setIndex(i); renderers[i].init(/* index= */ i, playerId);
rendererCapabilities[i] = renderers[i].getCapabilities(); rendererCapabilities[i] = renderers[i].getCapabilities();
} }
mediaClock = new DefaultMediaClock(this, clock); mediaClock = new DefaultMediaClock(this, clock);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package com.google.android.exoplayer2; package com.google.android.exoplayer2;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.analytics.PlayerId;
import com.google.android.exoplayer2.source.SampleStream; import com.google.android.exoplayer2.source.SampleStream;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.MediaClock; import com.google.android.exoplayer2.util.MediaClock;
...@@ -45,7 +46,7 @@ public abstract class NoSampleRenderer implements Renderer, RendererCapabilities ...@@ -45,7 +46,7 @@ public abstract class NoSampleRenderer implements Renderer, RendererCapabilities
} }
@Override @Override
public final void setIndex(int index) { public final void init(int index, PlayerId playerId) {
this.index = index; this.index = index;
} }
......
...@@ -20,6 +20,7 @@ import android.view.Surface; ...@@ -20,6 +20,7 @@ import android.view.Surface;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.PlayerMessage.Target; import com.google.android.exoplayer2.PlayerMessage.Target;
import com.google.android.exoplayer2.analytics.PlayerId;
import com.google.android.exoplayer2.audio.AudioAttributes; import com.google.android.exoplayer2.audio.AudioAttributes;
import com.google.android.exoplayer2.audio.AuxEffectInfo; import com.google.android.exoplayer2.audio.AuxEffectInfo;
import com.google.android.exoplayer2.source.SampleStream; import com.google.android.exoplayer2.source.SampleStream;
...@@ -248,11 +249,12 @@ public interface Renderer extends PlayerMessage.Target { ...@@ -248,11 +249,12 @@ public interface Renderer extends PlayerMessage.Target {
RendererCapabilities getCapabilities(); RendererCapabilities getCapabilities();
/** /**
* Sets the index of this renderer within the player. * Initializes the renderer for playback with a player.
* *
* @param index The renderer index. * @param index The renderer index within the player.
* @param playerId The {@link PlayerId} of the player.
*/ */
void setIndex(int index); void init(int index, PlayerId playerId);
/** /**
* If the renderer advances its own playback position then this method returns a corresponding * If the renderer advances its own playback position then this method returns a corresponding
......
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