Forward Timeline and period id to TrackSelection.Factory

This information is already available in the MappingTrackSelector,
but not currently forwarded to the TrackSelection.Factory.

This makes it more complicated (or impossible) to depend on period
or manifest information in the track selection (for example to only
select tracks which are cached for the current format).

PiperOrigin-RevId: 340605886
This commit is contained in:
tonihei 2020-11-04 09:42:57 +00:00 committed by Andrew Lewis
parent c04dd8b328
commit ae17e6d6f8
10 changed files with 64 additions and 17 deletions

View File

@ -25,6 +25,7 @@
([#8103](https://github.com/google/ExoPlayer/issues/8103)).
* Track selection:
* Add option to specify multiple preferred audio or text languages.
* Forward `Timeline` and `MediaPeriodId` to `TrackSelection.Factory`.
* UI:
* Show overflow button in `StyledPlayerControlView` only when there is not
enough space.

View File

@ -1070,7 +1070,10 @@ public final class DownloadHelper {
@Override
public @NullableType TrackSelection[] createTrackSelections(
@NullableType Definition[] definitions, BandwidthMeter bandwidthMeter) {
@NullableType Definition[] definitions,
BandwidthMeter bandwidthMeter,
MediaPeriodId mediaPeriodId,
Timeline timeline) {
@NullableType TrackSelection[] selections = new TrackSelection[definitions.length];
for (int i = 0; i < definitions.length; i++) {
selections[i] =

View File

@ -21,6 +21,8 @@ import androidx.annotation.CallSuper;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.chunk.MediaChunk;
import com.google.android.exoplayer2.source.chunk.MediaChunkIterator;
@ -129,7 +131,10 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
@Override
public final @NullableType TrackSelection[] createTrackSelections(
@NullableType Definition[] definitions, BandwidthMeter bandwidthMeter) {
@NullableType Definition[] definitions,
BandwidthMeter bandwidthMeter,
MediaPeriodId mediaPeriodId,
Timeline timeline) {
TrackSelection[] selections = new TrackSelection[definitions.length];
int totalFixedBandwidth = 0;
for (int i = 0; i < definitions.length; i++) {

View File

@ -34,6 +34,8 @@ import com.google.android.exoplayer2.RendererCapabilities.AdaptiveSupport;
import com.google.android.exoplayer2.RendererCapabilities.Capabilities;
import com.google.android.exoplayer2.RendererCapabilities.FormatSupport;
import com.google.android.exoplayer2.RendererConfiguration;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.util.Assertions;
@ -1603,7 +1605,9 @@ public class DefaultTrackSelector extends MappingTrackSelector {
selectTracks(
MappedTrackInfo mappedTrackInfo,
@Capabilities int[][][] rendererFormatSupports,
@AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupports)
@AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupports,
MediaPeriodId mediaPeriodId,
Timeline timeline)
throws ExoPlaybackException {
Parameters params = parametersReference.get();
int rendererCount = mappedTrackInfo.getRendererCount();
@ -1636,7 +1640,8 @@ public class DefaultTrackSelector extends MappingTrackSelector {
@NullableType
TrackSelection[] rendererTrackSelections =
trackSelectionFactory.createTrackSelections(definitions, getBandwidthMeter());
trackSelectionFactory.createTrackSelections(
definitions, getBandwidthMeter(), mediaPeriodId, timeline);
// Initialize the renderer configurations to the default configuration for all renderers with
// selections, and null otherwise.
@ -1665,8 +1670,9 @@ public class DefaultTrackSelector extends MappingTrackSelector {
// Track selection prior to overrides and disabled flags being applied.
/**
* Called from {@link #selectTracks(MappedTrackInfo, int[][][], int[])} to make a track selection
* for each renderer, prior to overrides and disabled flags being applied.
* Called from {@link #selectTracks(MappedTrackInfo, int[][][], int[], MediaPeriodId, Timeline)}
* to make a track selection for each renderer, prior to overrides and disabled flags being
* applied.
*
* <p>The implementation should not account for overrides and disabled flags. Track selections
* generated by this method will be overridden to account for these properties.

View File

@ -17,6 +17,8 @@ package com.google.android.exoplayer2.trackselection;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.chunk.MediaChunk;
import com.google.android.exoplayer2.source.chunk.MediaChunkIterator;
@ -57,7 +59,10 @@ public final class FixedTrackSelection extends BaseTrackSelection {
@Override
public @NullableType TrackSelection[] createTrackSelections(
@NullableType Definition[] definitions, BandwidthMeter bandwidthMeter) {
@NullableType Definition[] definitions,
BandwidthMeter bandwidthMeter,
MediaPeriodId mediaPeriodId,
Timeline timeline) {
return TrackSelectionUtil.createTrackSelectionsForDefinitions(
definitions,
definition ->

View File

@ -355,7 +355,7 @@ public abstract class MappingTrackSelector extends TrackSelector {
public final TrackSelectorResult selectTracks(
RendererCapabilities[] rendererCapabilities,
TrackGroupArray trackGroups,
MediaPeriodId periodId,
MediaPeriodId mediaPeriodId,
Timeline timeline)
throws ExoPlaybackException {
// Structures into which data will be written during the selection. The extra item at the end
@ -431,7 +431,11 @@ public abstract class MappingTrackSelector extends TrackSelector {
Pair<@NullableType RendererConfiguration[], @NullableType TrackSelection[]> result =
selectTracks(
mappedTrackInfo, rendererFormatSupports, rendererMixedMimeTypeAdaptationSupports);
mappedTrackInfo,
rendererFormatSupports,
rendererMixedMimeTypeAdaptationSupports,
mediaPeriodId,
timeline);
return new TrackSelectorResult(result.first, result.second, mappedTrackInfo);
}
@ -443,6 +447,9 @@ public abstract class MappingTrackSelector extends TrackSelector {
* renderer, track group and track (in that order).
* @param rendererMixedMimeTypeAdaptationSupport The {@link AdaptiveSupport} for mixed MIME type
* adaptation for the renderer.
* @param mediaPeriodId The {@link MediaPeriodId} of the period for which tracks are to be
* selected.
* @param timeline The {@link Timeline} holding the period for which tracks are to be selected.
* @return A pair consisting of the track selections and configurations for each renderer. A null
* configuration indicates the renderer should be disabled, in which case the track selection
* will also be null. A track selection may also be null for a non-disabled renderer if {@link
@ -453,7 +460,9 @@ public abstract class MappingTrackSelector extends TrackSelector {
selectTracks(
MappedTrackInfo mappedTrackInfo,
@Capabilities int[][][] rendererFormatSupports,
@AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupport)
@AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupport,
MediaPeriodId mediaPeriodId,
Timeline timeline)
throws ExoPlaybackException;
/**

View File

@ -18,6 +18,8 @@ package com.google.android.exoplayer2.trackselection;
import android.os.SystemClock;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.chunk.MediaChunk;
import com.google.android.exoplayer2.source.chunk.MediaChunkIterator;
@ -51,7 +53,10 @@ public final class RandomTrackSelection extends BaseTrackSelection {
@Override
public @NullableType TrackSelection[] createTrackSelections(
@NullableType Definition[] definitions, BandwidthMeter bandwidthMeter) {
@NullableType Definition[] definitions,
BandwidthMeter bandwidthMeter,
MediaPeriodId mediaPeriodId,
Timeline timeline) {
return TrackSelectionUtil.createTrackSelectionsForDefinitions(
definitions,
definition -> new RandomTrackSelection(definition.group, definition.tracks, random));

View File

@ -18,6 +18,8 @@ package com.google.android.exoplayer2.trackselection;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.chunk.Chunk;
import com.google.android.exoplayer2.source.chunk.MediaChunk;
@ -84,12 +86,18 @@ public interface TrackSelection {
*
* @param definitions A {@link Definition} array. May include null values.
* @param bandwidthMeter A {@link BandwidthMeter} which can be used to select tracks.
* @param mediaPeriodId The {@link MediaPeriodId} of the period for which tracks are to be
* selected.
* @param timeline The {@link Timeline} holding the period for which tracks are to be selected.
* @return The created selections. Must have the same length as {@code definitions} and may
* include null values.
*/
@NullableType
TrackSelection[] createTrackSelections(
@NullableType Definition[] definitions, BandwidthMeter bandwidthMeter);
@NullableType Definition[] definitions,
BandwidthMeter bandwidthMeter,
MediaPeriodId mediaPeriodId,
Timeline timeline);
}
/**

View File

@ -131,7 +131,7 @@ public final class MappingTrackSelectorTest {
/**
* A {@link MappingTrackSelector} that stashes the {@link MappedTrackInfo} passed to {@link
* #selectTracks(MappedTrackInfo, int[][][], int[])}.
* #selectTracks(MappedTrackInfo, int[][][], int[], MediaPeriodId, Timeline)}.
*/
private static final class FakeMappingTrackSelector extends MappingTrackSelector {
@ -141,8 +141,9 @@ public final class MappingTrackSelectorTest {
protected Pair<RendererConfiguration[], TrackSelection[]> selectTracks(
MappedTrackInfo mappedTrackInfo,
@Capabilities int[][][] rendererFormatSupports,
@AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupports)
throws ExoPlaybackException {
@AdaptiveSupport int[] rendererMixedMimeTypeAdaptationSupports,
MediaPeriodId mediaPeriodId,
Timeline timeline) {
int rendererCount = mappedTrackInfo.getRendererCount();
lastMappedTrackInfo = mappedTrackInfo;
return Pair.create(
@ -156,7 +157,6 @@ public final class MappingTrackSelectorTest {
assertThat(rendererTrackGroupArray.get(i)).isEqualTo(expected[i]);
}
}
}
/**

View File

@ -18,6 +18,8 @@ package com.google.android.exoplayer2.testutil;
import androidx.test.core.app.ApplicationProvider;
import com.google.android.exoplayer2.RendererCapabilities.AdaptiveSupport;
import com.google.android.exoplayer2.RendererCapabilities.Capabilities;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.MediaSource.MediaPeriodId;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
@ -85,7 +87,10 @@ public class FakeTrackSelector extends DefaultTrackSelector {
@Override
public TrackSelection[] createTrackSelections(
TrackSelection.@NullableType Definition[] definitions, BandwidthMeter bandwidthMeter) {
TrackSelection.@NullableType Definition[] definitions,
BandwidthMeter bandwidthMeter,
MediaPeriodId mediaPeriodId,
Timeline timeline) {
TrackSelection[] selections = new TrackSelection[definitions.length];
for (int i = 0; i < definitions.length; i++) {
TrackSelection.Definition definition = definitions[i];