Skip to content

Commit

Permalink
Remove TrackGroups from TrackSelectorResult
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ojw28 committed Mar 28, 2018
1 parent 0a4ea1c commit 18df028
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public ExoPlayerImpl(
this.listeners = new CopyOnWriteArraySet<>();
emptyTrackSelectorResult =
new TrackSelectorResult(
TrackGroupArray.EMPTY,
new boolean[renderers.length],
new TrackSelectionArray(new TrackSelection[renderers.length]),
null,
Expand All @@ -108,7 +107,11 @@ public void handleMessage(Message msg) {
}
};
playbackInfo =
new PlaybackInfo(Timeline.EMPTY, /* startPositionUs= */ 0, emptyTrackSelectorResult);
new PlaybackInfo(
Timeline.EMPTY,
/* startPositionUs= */ 0,
TrackGroupArray.EMPTY,
emptyTrackSelectorResult);
internalPlayer =
new ExoPlayerImplInternal(
renderers,
Expand Down Expand Up @@ -512,7 +515,7 @@ public int getRendererType(int index) {

@Override
public TrackGroupArray getCurrentTrackGroups() {
return playbackInfo.trackSelectorResult.groups;
return playbackInfo.trackGroups;
}

@Override
Expand Down Expand Up @@ -616,6 +619,7 @@ private PlaybackInfo getResetPlaybackInfo(
playbackInfo.contentPositionUs,
playbackState,
/* isLoading= */ false,
resetState ? TrackGroupArray.EMPTY : playbackInfo.trackGroups,
resetState ? emptyTrackSelectorResult : playbackInfo.trackSelectorResult);
}

Expand Down Expand Up @@ -648,7 +652,7 @@ private void updatePlaybackInfo(
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
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;
Expand Down Expand Up @@ -146,7 +147,10 @@ public ExoPlayerImplInternal(
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++) {
Expand Down Expand Up @@ -791,6 +795,7 @@ private void resetInternal(
resetPosition ? C.TIME_UNSET : playbackInfo.contentPositionUs,
playbackInfo.playbackState,
/* isLoading= */ false,
resetState ? TrackGroupArray.EMPTY : playbackInfo.trackGroups,
resetState ? emptyTrackSelectorResult : playbackInfo.trackSelectorResult);
if (releaseMediaSource) {
if (mediaSource != null) {
Expand Down Expand Up @@ -999,7 +1004,8 @@ private void reselectTracksInternal() throws ExoPlaybackException {
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,
Expand Down Expand Up @@ -1028,7 +1034,8 @@ private void reselectTracksInternal() throws ExoPlaybackException {
}
}
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.
Expand All @@ -1038,7 +1045,7 @@ private void reselectTracksInternal() throws ExoPlaybackException {
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) {
Expand All @@ -1048,9 +1055,9 @@ private void reselectTracksInternal() throws ExoPlaybackException {
}
}

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) {
Expand Down Expand Up @@ -1493,9 +1500,10 @@ private void handlePeriodPrepared(MediaPeriod mediaPeriod) throws ExoPlaybackExc
// 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();
Expand Down Expand Up @@ -1557,7 +1565,8 @@ private void updatePlayingPeriodRenderers(@Nullable MediaPeriodHolder oldPlaying
}
}
playbackInfo =
playbackInfo.copyWithTrackSelectorResult(newPlayingPeriodHolder.trackSelectorResult);
playbackInfo.copyWithTrackInfo(
newPlayingPeriodHolder.trackGroups, newPlayingPeriodHolder.trackSelectorResult);
enableRenderers(rendererWasEnabledFlags, enabledRendererCount);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;
Expand All @@ -43,6 +44,7 @@
public boolean hasEnabledTracks;
public MediaPeriodInfo info;
public MediaPeriodHolder next;
public TrackGroupArray trackGroups;
public TrackSelectorResult trackSelectorResult;

private final RendererCapabilities[] rendererCapabilities;
Expand Down Expand Up @@ -132,13 +134,13 @@ public long getNextLoadPositionUs() {
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) {
Expand All @@ -154,7 +156,7 @@ public void continueLoading(long rendererPositionUs) {

public boolean selectTracks(float playbackSpeed) throws ExoPlaybackException {
TrackSelectorResult selectorResult =
trackSelector.selectTracks(rendererCapabilities, mediaPeriod.getTrackGroups());
trackSelector.selectTracks(rendererCapabilities, trackGroups);
if (selectorResult.isEquivalent(periodTrackSelectorResult)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
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;

Expand Down Expand Up @@ -168,17 +167,6 @@ public MediaPeriod enqueueNextMediaPeriod(
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2;
package com.google.android.exoplayer2;

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;

/**
Expand All @@ -31,13 +32,17 @@
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,
Expand All @@ -46,6 +51,7 @@ public PlaybackInfo(
/* contentPositionUs =*/ C.TIME_UNSET,
Player.STATE_IDLE,
/* isLoading= */ false,
trackGroups,
trackSelectorResult);
}

Expand All @@ -57,6 +63,7 @@ public PlaybackInfo(
long contentPositionUs,
int playbackState,
boolean isLoading,
TrackGroupArray trackGroups,
TrackSelectorResult trackSelectorResult) {
this.timeline = timeline;
this.manifest = manifest;
Expand All @@ -67,11 +74,12 @@ public PlaybackInfo(
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,
Expand All @@ -80,6 +88,7 @@ public PlaybackInfo fromNewPosition(MediaPeriodId periodId, long startPositionUs
periodId.isAd() ? contentPositionUs : C.TIME_UNSET,
playbackState,
isLoading,
trackGroups,
trackSelectorResult);
}

Expand All @@ -93,6 +102,7 @@ public PlaybackInfo copyWithPeriodIndex(int periodIndex) {
contentPositionUs,
playbackState,
isLoading,
trackGroups,
trackSelectorResult);
copyMutablePositions(this, playbackInfo);
return playbackInfo;
Expand All @@ -108,6 +118,7 @@ public PlaybackInfo copyWithTimeline(Timeline timeline, Object manifest) {
contentPositionUs,
playbackState,
isLoading,
trackGroups,
trackSelectorResult);
copyMutablePositions(this, playbackInfo);
return playbackInfo;
Expand All @@ -123,6 +134,7 @@ public PlaybackInfo copyWithPlaybackState(int playbackState) {
contentPositionUs,
playbackState,
isLoading,
trackGroups,
trackSelectorResult);
copyMutablePositions(this, playbackInfo);
return playbackInfo;
Expand All @@ -138,12 +150,14 @@ public PlaybackInfo copyWithIsLoading(boolean isLoading) {
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,
Expand All @@ -153,6 +167,7 @@ public PlaybackInfo copyWithTrackSelectorResult(TrackSelectorResult trackSelecto
contentPositionUs,
playbackState,
isLoading,
trackGroups,
trackSelectorResult);
copyMutablePositions(this, playbackInfo);
return playbackInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,11 @@ public final TrackSelectorResult selectTracks(RendererCapabilities[] rendererCap
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,13 @@
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;

/**
* The result of a {@link TrackSelector} operation.
*/
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.
*/
Expand All @@ -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;
Expand Down

0 comments on commit 18df028

Please sign in to comment.