Remove TrackGroups from TrackSelectorResult
They don't really belong there; it was basically a convenience thing where one of the arguments to the track selector was being packaged up in the result to avoid having to hold a separate reference to it. This change is being made as a precursor to a subsequent change where creating the TrackSelectorResult will move from MappingTrackSelector to DefaultTrackSelector. DefaultTrackSelector doesn't currently have access to the un-mapped tracks, and so is unable to create a TrackSelectorResult. It's IMO preferable to keep it that way rather than passing them down just so they can be included in the result. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=190640594
This commit is contained in:
parent
0a4ea1cd3e
commit
18df028ce2
@ -92,7 +92,6 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||
this.listeners = new CopyOnWriteArraySet<>();
|
||||
emptyTrackSelectorResult =
|
||||
new TrackSelectorResult(
|
||||
TrackGroupArray.EMPTY,
|
||||
new boolean[renderers.length],
|
||||
new TrackSelectionArray(new TrackSelection[renderers.length]),
|
||||
null,
|
||||
@ -108,7 +107,11 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||
}
|
||||
};
|
||||
playbackInfo =
|
||||
new PlaybackInfo(Timeline.EMPTY, /* startPositionUs= */ 0, emptyTrackSelectorResult);
|
||||
new PlaybackInfo(
|
||||
Timeline.EMPTY,
|
||||
/* startPositionUs= */ 0,
|
||||
TrackGroupArray.EMPTY,
|
||||
emptyTrackSelectorResult);
|
||||
internalPlayer =
|
||||
new ExoPlayerImplInternal(
|
||||
renderers,
|
||||
@ -512,7 +515,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
@Override
|
||||
public TrackGroupArray getCurrentTrackGroups() {
|
||||
return playbackInfo.trackSelectorResult.groups;
|
||||
return playbackInfo.trackGroups;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -616,6 +619,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||
playbackInfo.contentPositionUs,
|
||||
playbackState,
|
||||
/* isLoading= */ false,
|
||||
resetState ? TrackGroupArray.EMPTY : playbackInfo.trackGroups,
|
||||
resetState ? emptyTrackSelectorResult : playbackInfo.trackSelectorResult);
|
||||
}
|
||||
|
||||
@ -648,7 +652,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||
trackSelector.onSelectionActivated(playbackInfo.trackSelectorResult.info);
|
||||
for (Player.EventListener listener : listeners) {
|
||||
listener.onTracksChanged(
|
||||
playbackInfo.trackSelectorResult.groups, playbackInfo.trackSelectorResult.selections);
|
||||
playbackInfo.trackGroups, playbackInfo.trackSelectorResult.selections);
|
||||
}
|
||||
}
|
||||
if (isLoadingChanged) {
|
||||
|
@ -31,6 +31,7 @@ import com.google.android.exoplayer2.source.MediaPeriod;
|
||||
import com.google.android.exoplayer2.source.MediaSource;
|
||||
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
|
||||
import com.google.android.exoplayer2.source.SampleStream;
|
||||
import com.google.android.exoplayer2.source.TrackGroupArray;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelection;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelector;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelectorResult;
|
||||
@ -146,7 +147,10 @@ import java.util.Collections;
|
||||
seekParameters = SeekParameters.DEFAULT;
|
||||
playbackInfo =
|
||||
new PlaybackInfo(
|
||||
Timeline.EMPTY, /* startPositionUs= */ C.TIME_UNSET, emptyTrackSelectorResult);
|
||||
Timeline.EMPTY,
|
||||
/* startPositionUs= */ C.TIME_UNSET,
|
||||
TrackGroupArray.EMPTY,
|
||||
emptyTrackSelectorResult);
|
||||
playbackInfoUpdate = new PlaybackInfoUpdate();
|
||||
rendererCapabilities = new RendererCapabilities[renderers.length];
|
||||
for (int i = 0; i < renderers.length; i++) {
|
||||
@ -791,6 +795,7 @@ import java.util.Collections;
|
||||
resetPosition ? C.TIME_UNSET : playbackInfo.contentPositionUs,
|
||||
playbackInfo.playbackState,
|
||||
/* isLoading= */ false,
|
||||
resetState ? TrackGroupArray.EMPTY : playbackInfo.trackGroups,
|
||||
resetState ? emptyTrackSelectorResult : playbackInfo.trackSelectorResult);
|
||||
if (releaseMediaSource) {
|
||||
if (mediaSource != null) {
|
||||
@ -999,7 +1004,8 @@ import java.util.Collections;
|
||||
long periodPositionUs =
|
||||
playingPeriodHolder.applyTrackSelection(
|
||||
playbackInfo.positionUs, recreateStreams, streamResetFlags);
|
||||
updateLoadControlTrackSelection(playingPeriodHolder.trackSelectorResult);
|
||||
updateLoadControlTrackSelection(
|
||||
playingPeriodHolder.trackGroups, playingPeriodHolder.trackSelectorResult);
|
||||
if (playbackInfo.playbackState != Player.STATE_ENDED
|
||||
&& periodPositionUs != playbackInfo.positionUs) {
|
||||
playbackInfo = playbackInfo.fromNewPosition(playbackInfo.periodId, periodPositionUs,
|
||||
@ -1028,7 +1034,8 @@ import java.util.Collections;
|
||||
}
|
||||
}
|
||||
playbackInfo =
|
||||
playbackInfo.copyWithTrackSelectorResult(playingPeriodHolder.trackSelectorResult);
|
||||
playbackInfo.copyWithTrackInfo(
|
||||
playingPeriodHolder.trackGroups, playingPeriodHolder.trackSelectorResult);
|
||||
enableRenderers(rendererWasEnabledFlags, enabledRendererCount);
|
||||
} else {
|
||||
// Release and re-prepare/buffer periods after the one whose selection changed.
|
||||
@ -1038,7 +1045,7 @@ import java.util.Collections;
|
||||
Math.max(
|
||||
periodHolder.info.startPositionUs, periodHolder.toPeriodTime(rendererPositionUs));
|
||||
periodHolder.applyTrackSelection(loadingPeriodPositionUs, false);
|
||||
updateLoadControlTrackSelection(periodHolder.trackSelectorResult);
|
||||
updateLoadControlTrackSelection(periodHolder.trackGroups, periodHolder.trackSelectorResult);
|
||||
}
|
||||
}
|
||||
if (playbackInfo.playbackState != Player.STATE_ENDED) {
|
||||
@ -1048,9 +1055,9 @@ import java.util.Collections;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateLoadControlTrackSelection(TrackSelectorResult trackSelectorResult) {
|
||||
loadControl.onTracksSelected(
|
||||
renderers, trackSelectorResult.groups, trackSelectorResult.selections);
|
||||
private void updateLoadControlTrackSelection(
|
||||
TrackGroupArray trackGroups, TrackSelectorResult trackSelectorResult) {
|
||||
loadControl.onTracksSelected(renderers, trackGroups, trackSelectorResult.selections);
|
||||
}
|
||||
|
||||
private void updateTrackSelectionPlaybackSpeed(float playbackSpeed) {
|
||||
@ -1493,9 +1500,10 @@ import java.util.Collections;
|
||||
// Stale event.
|
||||
return;
|
||||
}
|
||||
TrackSelectorResult trackSelectorResult =
|
||||
queue.handleLoadingPeriodPrepared(mediaClock.getPlaybackParameters().speed);
|
||||
updateLoadControlTrackSelection(trackSelectorResult);
|
||||
MediaPeriodHolder loadingPeriodHolder = queue.getLoadingPeriod();
|
||||
loadingPeriodHolder.handlePrepared(mediaClock.getPlaybackParameters().speed);
|
||||
updateLoadControlTrackSelection(
|
||||
loadingPeriodHolder.trackGroups, loadingPeriodHolder.trackSelectorResult);
|
||||
if (!queue.hasPlayingPeriod()) {
|
||||
// This is the first prepared period, so start playing it.
|
||||
MediaPeriodHolder playingPeriodHolder = queue.advancePlayingPeriod();
|
||||
@ -1557,7 +1565,8 @@ import java.util.Collections;
|
||||
}
|
||||
}
|
||||
playbackInfo =
|
||||
playbackInfo.copyWithTrackSelectorResult(newPlayingPeriodHolder.trackSelectorResult);
|
||||
playbackInfo.copyWithTrackInfo(
|
||||
newPlayingPeriodHolder.trackGroups, newPlayingPeriodHolder.trackSelectorResult);
|
||||
enableRenderers(rendererWasEnabledFlags, enabledRendererCount);
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ import com.google.android.exoplayer2.source.EmptySampleStream;
|
||||
import com.google.android.exoplayer2.source.MediaPeriod;
|
||||
import com.google.android.exoplayer2.source.MediaSource;
|
||||
import com.google.android.exoplayer2.source.SampleStream;
|
||||
import com.google.android.exoplayer2.source.TrackGroupArray;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelection;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelector;
|
||||
@ -43,6 +44,7 @@ import com.google.android.exoplayer2.util.Assertions;
|
||||
public boolean hasEnabledTracks;
|
||||
public MediaPeriodInfo info;
|
||||
public MediaPeriodHolder next;
|
||||
public TrackGroupArray trackGroups;
|
||||
public TrackSelectorResult trackSelectorResult;
|
||||
|
||||
private final RendererCapabilities[] rendererCapabilities;
|
||||
@ -132,13 +134,13 @@ import com.google.android.exoplayer2.util.Assertions;
|
||||
return !prepared ? 0 : mediaPeriod.getNextLoadPositionUs();
|
||||
}
|
||||
|
||||
public TrackSelectorResult handlePrepared(float playbackSpeed) throws ExoPlaybackException {
|
||||
public void handlePrepared(float playbackSpeed) throws ExoPlaybackException {
|
||||
prepared = true;
|
||||
trackGroups = mediaPeriod.getTrackGroups();
|
||||
selectTracks(playbackSpeed);
|
||||
long newStartPositionUs = applyTrackSelection(info.startPositionUs, false);
|
||||
rendererPositionOffsetUs += info.startPositionUs - newStartPositionUs;
|
||||
info = info.copyWithStartPositionUs(newStartPositionUs);
|
||||
return trackSelectorResult;
|
||||
}
|
||||
|
||||
public void reevaluateBuffer(long rendererPositionUs) {
|
||||
@ -154,7 +156,7 @@ import com.google.android.exoplayer2.util.Assertions;
|
||||
|
||||
public boolean selectTracks(float playbackSpeed) throws ExoPlaybackException {
|
||||
TrackSelectorResult selectorResult =
|
||||
trackSelector.selectTracks(rendererCapabilities, mediaPeriod.getTrackGroups());
|
||||
trackSelector.selectTracks(rendererCapabilities, trackGroups);
|
||||
if (selectorResult.isEquivalent(periodTrackSelectorResult)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ import com.google.android.exoplayer2.source.MediaPeriod;
|
||||
import com.google.android.exoplayer2.source.MediaSource;
|
||||
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelector;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelectorResult;
|
||||
import com.google.android.exoplayer2.upstream.Allocator;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
|
||||
@ -168,17 +167,6 @@ import com.google.android.exoplayer2.util.Assertions;
|
||||
return newPeriodHolder.mediaPeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the loading media period being prepared.
|
||||
*
|
||||
* @param playbackSpeed The current playback speed.
|
||||
* @return The result of selecting tracks on the newly prepared loading media period.
|
||||
*/
|
||||
public TrackSelectorResult handleLoadingPeriodPrepared(float playbackSpeed)
|
||||
throws ExoPlaybackException {
|
||||
return loading.handlePrepared(playbackSpeed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the loading period holder which is at the end of the queue, or null if the queue is
|
||||
* empty.
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
|
||||
import com.google.android.exoplayer2.source.TrackGroupArray;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelectorResult;
|
||||
|
||||
/**
|
||||
@ -31,13 +32,17 @@ import com.google.android.exoplayer2.trackselection.TrackSelectorResult;
|
||||
public final long contentPositionUs;
|
||||
public final int playbackState;
|
||||
public final boolean isLoading;
|
||||
public final TrackGroupArray trackGroups;
|
||||
public final TrackSelectorResult trackSelectorResult;
|
||||
|
||||
public volatile long positionUs;
|
||||
public volatile long bufferedPositionUs;
|
||||
|
||||
public PlaybackInfo(
|
||||
Timeline timeline, long startPositionUs, TrackSelectorResult trackSelectorResult) {
|
||||
Timeline timeline,
|
||||
long startPositionUs,
|
||||
TrackGroupArray trackGroups,
|
||||
TrackSelectorResult trackSelectorResult) {
|
||||
this(
|
||||
timeline,
|
||||
/* manifest= */ null,
|
||||
@ -46,6 +51,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelectorResult;
|
||||
/* contentPositionUs =*/ C.TIME_UNSET,
|
||||
Player.STATE_IDLE,
|
||||
/* isLoading= */ false,
|
||||
trackGroups,
|
||||
trackSelectorResult);
|
||||
}
|
||||
|
||||
@ -57,6 +63,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelectorResult;
|
||||
long contentPositionUs,
|
||||
int playbackState,
|
||||
boolean isLoading,
|
||||
TrackGroupArray trackGroups,
|
||||
TrackSelectorResult trackSelectorResult) {
|
||||
this.timeline = timeline;
|
||||
this.manifest = manifest;
|
||||
@ -67,11 +74,12 @@ import com.google.android.exoplayer2.trackselection.TrackSelectorResult;
|
||||
this.bufferedPositionUs = startPositionUs;
|
||||
this.playbackState = playbackState;
|
||||
this.isLoading = isLoading;
|
||||
this.trackGroups = trackGroups;
|
||||
this.trackSelectorResult = trackSelectorResult;
|
||||
}
|
||||
|
||||
public PlaybackInfo fromNewPosition(MediaPeriodId periodId, long startPositionUs,
|
||||
long contentPositionUs) {
|
||||
public PlaybackInfo fromNewPosition(
|
||||
MediaPeriodId periodId, long startPositionUs, long contentPositionUs) {
|
||||
return new PlaybackInfo(
|
||||
timeline,
|
||||
manifest,
|
||||
@ -80,6 +88,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelectorResult;
|
||||
periodId.isAd() ? contentPositionUs : C.TIME_UNSET,
|
||||
playbackState,
|
||||
isLoading,
|
||||
trackGroups,
|
||||
trackSelectorResult);
|
||||
}
|
||||
|
||||
@ -93,6 +102,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelectorResult;
|
||||
contentPositionUs,
|
||||
playbackState,
|
||||
isLoading,
|
||||
trackGroups,
|
||||
trackSelectorResult);
|
||||
copyMutablePositions(this, playbackInfo);
|
||||
return playbackInfo;
|
||||
@ -108,6 +118,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelectorResult;
|
||||
contentPositionUs,
|
||||
playbackState,
|
||||
isLoading,
|
||||
trackGroups,
|
||||
trackSelectorResult);
|
||||
copyMutablePositions(this, playbackInfo);
|
||||
return playbackInfo;
|
||||
@ -123,6 +134,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelectorResult;
|
||||
contentPositionUs,
|
||||
playbackState,
|
||||
isLoading,
|
||||
trackGroups,
|
||||
trackSelectorResult);
|
||||
copyMutablePositions(this, playbackInfo);
|
||||
return playbackInfo;
|
||||
@ -138,12 +150,14 @@ import com.google.android.exoplayer2.trackselection.TrackSelectorResult;
|
||||
contentPositionUs,
|
||||
playbackState,
|
||||
isLoading,
|
||||
trackGroups,
|
||||
trackSelectorResult);
|
||||
copyMutablePositions(this, playbackInfo);
|
||||
return playbackInfo;
|
||||
}
|
||||
|
||||
public PlaybackInfo copyWithTrackSelectorResult(TrackSelectorResult trackSelectorResult) {
|
||||
public PlaybackInfo copyWithTrackInfo(
|
||||
TrackGroupArray trackGroups, TrackSelectorResult trackSelectorResult) {
|
||||
PlaybackInfo playbackInfo =
|
||||
new PlaybackInfo(
|
||||
timeline,
|
||||
@ -153,6 +167,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelectorResult;
|
||||
contentPositionUs,
|
||||
playbackState,
|
||||
isLoading,
|
||||
trackGroups,
|
||||
trackSelectorResult);
|
||||
copyMutablePositions(this, playbackInfo);
|
||||
return playbackInfo;
|
||||
|
@ -597,8 +597,11 @@ public abstract class MappingTrackSelector extends TrackSelector {
|
||||
maybeConfigureRenderersForTunneling(rendererCapabilities, rendererTrackGroupArrays,
|
||||
rendererFormatSupports, rendererConfigurations, trackSelections, tunnelingAudioSessionId);
|
||||
|
||||
return new TrackSelectorResult(trackGroups, rendererEnabled,
|
||||
new TrackSelectionArray(trackSelections), mappedTrackInfo, rendererConfigurations);
|
||||
return new TrackSelectorResult(
|
||||
rendererEnabled,
|
||||
new TrackSelectionArray(trackSelections),
|
||||
mappedTrackInfo,
|
||||
rendererConfigurations);
|
||||
}
|
||||
|
||||
private boolean[] determineEnabledRenderers(RendererCapabilities[] rendererCapabilities,
|
||||
|
@ -16,7 +16,6 @@
|
||||
package com.google.android.exoplayer2.trackselection;
|
||||
|
||||
import com.google.android.exoplayer2.RendererConfiguration;
|
||||
import com.google.android.exoplayer2.source.TrackGroupArray;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
|
||||
/**
|
||||
@ -24,10 +23,6 @@ import com.google.android.exoplayer2.util.Util;
|
||||
*/
|
||||
public final class TrackSelectorResult {
|
||||
|
||||
/**
|
||||
* The track groups that were provided to the {@link TrackSelector}.
|
||||
*/
|
||||
public final TrackGroupArray groups;
|
||||
/**
|
||||
* An array containing whether each renderer is enabled after the track selection operation.
|
||||
*/
|
||||
@ -47,19 +42,19 @@ public final class TrackSelectorResult {
|
||||
public final RendererConfiguration[] rendererConfigurations;
|
||||
|
||||
/**
|
||||
* @param groups The track groups provided to the {@link TrackSelector}.
|
||||
* @param renderersEnabled An array containing whether each renderer is enabled after the track
|
||||
* selection operation.
|
||||
* @param selections A {@link TrackSelectionArray} containing the selection for each renderer.
|
||||
* @param info An opaque object that will be returned to
|
||||
* {@link TrackSelector#onSelectionActivated(Object)} should the selection be activated.
|
||||
* @param rendererConfigurations A {@link RendererConfiguration} for each enabled renderer,
|
||||
* to be used with the selections.
|
||||
* @param info An opaque object that will be returned to {@link
|
||||
* TrackSelector#onSelectionActivated(Object)} should the selection be activated.
|
||||
* @param rendererConfigurations A {@link RendererConfiguration} for each enabled renderer, to be
|
||||
* used with the selections.
|
||||
*/
|
||||
public TrackSelectorResult(TrackGroupArray groups, boolean[] renderersEnabled,
|
||||
TrackSelectionArray selections, Object info,
|
||||
public TrackSelectorResult(
|
||||
boolean[] renderersEnabled,
|
||||
TrackSelectionArray selections,
|
||||
Object info,
|
||||
RendererConfiguration[] rendererConfigurations) {
|
||||
this.groups = groups;
|
||||
this.renderersEnabled = renderersEnabled;
|
||||
this.selections = selections;
|
||||
this.info = info;
|
||||
|
Loading…
x
Reference in New Issue
Block a user