Make passing BandwidthMeter to TrackSelector and TrackSelection non-optional.

This was only needed temporatily until we could ensure that the player always
provides a BandwidthMeter.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=204903640
This commit is contained in:
tonihei 2018-07-17 06:45:18 -07:00 committed by Oliver Woodman
parent 972fd0ced8
commit 59b18a52d2
9 changed files with 114 additions and 60 deletions

View File

@ -34,7 +34,7 @@
use the default bandwidth meter automatically. This change only works use the default bandwidth meter automatically. This change only works
correctly if the following changes are adopted for custom `BandwidthMeter`s, correctly if the following changes are adopted for custom `BandwidthMeter`s,
`TrackSelection`s, `MediaSource`s and `DataSource`s. `TrackSelection`s, `MediaSource`s and `DataSource`s.
* Pass `BandwidthMeter` to `TrackSelection.Factory` which can be used to * Pass `BandwidthMeter` to `TrackSelection.Factory` which should be used to
obtain bandwidth estimates. obtain bandwidth estimates.
* Add method to `BandwidthMeter` to return the `TransferListener` used to * Add method to `BandwidthMeter` to return the `TransferListener` used to
gather bandwidth information. Also add methods to add and remove event gather bandwidth information. Also add methods to add and remove event

View File

@ -21,7 +21,6 @@ import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.source.TrackGroup; import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.chunk.MediaChunk; import com.google.android.exoplayer2.source.chunk.MediaChunk;
import com.google.android.exoplayer2.upstream.BandwidthMeter; import com.google.android.exoplayer2.upstream.BandwidthMeter;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Clock; import com.google.android.exoplayer2.util.Clock;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.util.List; import java.util.List;
@ -37,7 +36,7 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
*/ */
public static final class Factory implements TrackSelection.Factory { public static final class Factory implements TrackSelection.Factory {
private final BandwidthMeter bandwidthMeter; private final @Nullable BandwidthMeter bandwidthMeter;
private final int minDurationForQualityIncreaseMs; private final int minDurationForQualityIncreaseMs;
private final int maxDurationForQualityDecreaseMs; private final int maxDurationForQualityDecreaseMs;
private final int minDurationToRetainAfterDiscardMs; private final int minDurationToRetainAfterDiscardMs;
@ -46,9 +45,24 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
private final long minTimeBetweenBufferReevaluationMs; private final long minTimeBetweenBufferReevaluationMs;
private final Clock clock; private final Clock clock;
/** Creates an adaptive track selection factory with default parameters. */
public Factory() {
this(
DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
DEFAULT_BANDWIDTH_FRACTION,
DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE,
DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS,
Clock.DEFAULT);
}
/** /**
* @param bandwidthMeter Provides an estimate of the currently available bandwidth. * @deprecated Use {@link #Factory()} instead. Custom bandwidth meter should be directly passed
* to the player in ExoPlayerFactory.
*/ */
@Deprecated
@SuppressWarnings("deprecation")
public Factory(BandwidthMeter bandwidthMeter) { public Factory(BandwidthMeter bandwidthMeter) {
this( this(
bandwidthMeter, bandwidthMeter,
@ -62,7 +76,8 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
} }
/** /**
* @param bandwidthMeter Provides an estimate of the currently available bandwidth. * Creates an adaptive track selection factory.
*
* @param minDurationForQualityIncreaseMs The minimum duration of buffered data required for the * @param minDurationForQualityIncreaseMs The minimum duration of buffered data required for the
* selected track to switch to one of higher quality. * selected track to switch to one of higher quality.
* @param maxDurationForQualityDecreaseMs The maximum duration of buffered data required for the * @param maxDurationForQualityDecreaseMs The maximum duration of buffered data required for the
@ -75,6 +90,27 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
* consider available for use. Setting to a value less than 1 is recommended to account for * consider available for use. Setting to a value less than 1 is recommended to account for
* inaccuracies in the bandwidth estimator. * inaccuracies in the bandwidth estimator.
*/ */
public Factory(
int minDurationForQualityIncreaseMs,
int maxDurationForQualityDecreaseMs,
int minDurationToRetainAfterDiscardMs,
float bandwidthFraction) {
this(
minDurationForQualityIncreaseMs,
maxDurationForQualityDecreaseMs,
minDurationToRetainAfterDiscardMs,
bandwidthFraction,
DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE,
DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS,
Clock.DEFAULT);
}
/**
* @deprecated Use {@link #Factory(int, int, int, float)} instead. Custom bandwidth meter should
* be directly passed to the player in ExoPlayerFactory.
*/
@Deprecated
@SuppressWarnings("deprecation")
public Factory( public Factory(
BandwidthMeter bandwidthMeter, BandwidthMeter bandwidthMeter,
int minDurationForQualityIncreaseMs, int minDurationForQualityIncreaseMs,
@ -93,7 +129,8 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
} }
/** /**
* @param bandwidthMeter Provides an estimate of the currently available bandwidth.. * Creates an adaptive track selection factory.
*
* @param minDurationForQualityIncreaseMs The minimum duration of buffered data required for the * @param minDurationForQualityIncreaseMs The minimum duration of buffered data required for the
* selected track to switch to one of higher quality. * selected track to switch to one of higher quality.
* @param maxDurationForQualityDecreaseMs The maximum duration of buffered data required for the * @param maxDurationForQualityDecreaseMs The maximum duration of buffered data required for the
@ -117,8 +154,33 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
* buffer reevaluation calls. * buffer reevaluation calls.
* @param clock A {@link Clock}. * @param clock A {@link Clock}.
*/ */
@SuppressWarnings("deprecation")
public Factory( public Factory(
BandwidthMeter bandwidthMeter, int minDurationForQualityIncreaseMs,
int maxDurationForQualityDecreaseMs,
int minDurationToRetainAfterDiscardMs,
float bandwidthFraction,
float bufferedFractionToLiveEdgeForQualityIncrease,
long minTimeBetweenBufferReevaluationMs,
Clock clock) {
this(
/* bandwidthMeter= */ null,
minDurationForQualityIncreaseMs,
maxDurationForQualityDecreaseMs,
minDurationToRetainAfterDiscardMs,
bandwidthFraction,
bufferedFractionToLiveEdgeForQualityIncrease,
minTimeBetweenBufferReevaluationMs,
clock);
}
/**
* @deprecated Use {@link #Factory(int, int, int, float, float, long, Clock)} instead. Custom
* bandwidth meter should be directly passed to the player in ExoPlayerFactory.
*/
@Deprecated
public Factory(
@Nullable BandwidthMeter bandwidthMeter,
int minDurationForQualityIncreaseMs, int minDurationForQualityIncreaseMs,
int maxDurationForQualityDecreaseMs, int maxDurationForQualityDecreaseMs,
int minDurationToRetainAfterDiscardMs, int minDurationToRetainAfterDiscardMs,
@ -139,14 +201,14 @@ public class AdaptiveTrackSelection extends BaseTrackSelection {
@Override @Override
public AdaptiveTrackSelection createTrackSelection( public AdaptiveTrackSelection createTrackSelection(
TrackGroup group, @Nullable BandwidthMeter bandwidthMeter, int... tracks) { TrackGroup group, BandwidthMeter bandwidthMeter, int... tracks) {
if (this.bandwidthMeter != null) { if (this.bandwidthMeter != null) {
bandwidthMeter = this.bandwidthMeter; bandwidthMeter = this.bandwidthMeter;
} }
return new AdaptiveTrackSelection( return new AdaptiveTrackSelection(
group, group,
tracks, tracks,
Assertions.checkNotNull(bandwidthMeter), bandwidthMeter,
minDurationForQualityIncreaseMs, minDurationForQualityIncreaseMs,
maxDurationForQualityDecreaseMs, maxDurationForQualityDecreaseMs,
minDurationToRetainAfterDiscardMs, minDurationToRetainAfterDiscardMs,

View File

@ -1056,23 +1056,19 @@ public class DefaultTrackSelector extends MappingTrackSelector {
private static final int[] NO_TRACKS = new int[0]; private static final int[] NO_TRACKS = new int[0];
private static final int WITHIN_RENDERER_CAPABILITIES_BONUS = 1000; private static final int WITHIN_RENDERER_CAPABILITIES_BONUS = 1000;
private final @Nullable TrackSelection.Factory adaptiveTrackSelectionFactory; private final TrackSelection.Factory adaptiveTrackSelectionFactory;
private final AtomicReference<Parameters> parametersReference; private final AtomicReference<Parameters> parametersReference;
/** /** Constructs an instance that uses a default factory to create adaptive track selections. */
* Constructs an instance that does not support adaptive track selection.
*/
public DefaultTrackSelector() { public DefaultTrackSelector() {
this((TrackSelection.Factory) null); this(new AdaptiveTrackSelection.Factory());
} }
/** /**
* Constructs an instance that supports adaptive track selection. Adaptive track selections use * @deprecated Use {@link #DefaultTrackSelector()} instead. Custom bandwidth meter should be
* the provided {@link BandwidthMeter} to determine which individual track should be used during * directly passed to the player in ExoPlayerFactory.
* playback.
*
* @param bandwidthMeter The {@link BandwidthMeter}.
*/ */
@Deprecated
public DefaultTrackSelector(BandwidthMeter bandwidthMeter) { public DefaultTrackSelector(BandwidthMeter bandwidthMeter) {
this(new AdaptiveTrackSelection.Factory(bandwidthMeter)); this(new AdaptiveTrackSelection.Factory(bandwidthMeter));
} }
@ -1080,10 +1076,9 @@ public class DefaultTrackSelector extends MappingTrackSelector {
/** /**
* Constructs an instance that uses a factory to create adaptive track selections. * Constructs an instance that uses a factory to create adaptive track selections.
* *
* @param adaptiveTrackSelectionFactory A factory for adaptive {@link TrackSelection}s, or null if * @param adaptiveTrackSelectionFactory A factory for adaptive {@link TrackSelection}s.
* the selector should not support adaptive tracks.
*/ */
public DefaultTrackSelector(@Nullable TrackSelection.Factory adaptiveTrackSelectionFactory) { public DefaultTrackSelector(TrackSelection.Factory adaptiveTrackSelectionFactory) {
this.adaptiveTrackSelectionFactory = adaptiveTrackSelectionFactory; this.adaptiveTrackSelectionFactory = adaptiveTrackSelectionFactory;
parametersReference = new AtomicReference<>(Parameters.DEFAULT); parametersReference = new AtomicReference<>(Parameters.DEFAULT);
} }
@ -1381,7 +1376,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
int mixedMimeTypeAdaptationSupports, int mixedMimeTypeAdaptationSupports,
Parameters params, Parameters params,
TrackSelection.Factory adaptiveTrackSelectionFactory, TrackSelection.Factory adaptiveTrackSelectionFactory,
@Nullable BandwidthMeter bandwidthMeter) BandwidthMeter bandwidthMeter)
throws ExoPlaybackException { throws ExoPlaybackException {
int requiredAdaptiveSupport = params.allowNonSeamlessAdaptiveness int requiredAdaptiveSupport = params.allowNonSeamlessAdaptiveness
? (RendererCapabilities.ADAPTIVE_NOT_SEAMLESS | RendererCapabilities.ADAPTIVE_SEAMLESS) ? (RendererCapabilities.ADAPTIVE_NOT_SEAMLESS | RendererCapabilities.ADAPTIVE_SEAMLESS)

View File

@ -50,7 +50,7 @@ public final class FixedTrackSelection extends BaseTrackSelection {
@Override @Override
public FixedTrackSelection createTrackSelection( public FixedTrackSelection createTrackSelection(
TrackGroup group, @Nullable BandwidthMeter bandwidthMeter, int... tracks) { TrackGroup group, BandwidthMeter bandwidthMeter, int... tracks) {
Assertions.checkArgument(tracks.length == 1); Assertions.checkArgument(tracks.length == 1);
return new FixedTrackSelection(group, tracks[0], reason, data); return new FixedTrackSelection(group, tracks[0], reason, data);
} }

View File

@ -47,7 +47,7 @@ public final class RandomTrackSelection extends BaseTrackSelection {
@Override @Override
public RandomTrackSelection createTrackSelection( public RandomTrackSelection createTrackSelection(
TrackGroup group, @Nullable BandwidthMeter bandwidthMeter, int... tracks) { TrackGroup group, BandwidthMeter bandwidthMeter, int... tracks) {
return new RandomTrackSelection(group, tracks, random); return new RandomTrackSelection(group, tracks, random);
} }
} }

View File

@ -37,29 +37,17 @@ public interface TrackSelection {
*/ */
interface Factory { interface Factory {
/**
* @deprecated Use and implement {@link
* #createTrackSelection(TrackGroup, BandwidthMeter, int...)} instead.
*/
@Deprecated
default TrackSelection createTrackSelection(TrackGroup group, int... tracks) {
return createTrackSelection(group, /* bandwidthMeter= */ null, tracks);
}
/** /**
* Creates a new selection. * Creates a new selection.
* *
* @param group The {@link TrackGroup}. Must not be null. * @param group The {@link TrackGroup}. Must not be null.
* @param bandwidthMeter A {@link BandwidthMeter} which can be used to select tracks, or null if * @param bandwidthMeter A {@link BandwidthMeter} which can be used to select tracks.
* no such bandwidth meter is available.
* @param tracks The indices of the selected tracks within the {@link TrackGroup}. Must not be * @param tracks The indices of the selected tracks within the {@link TrackGroup}. Must not be
* null or empty. May be in any order. * null or empty. May be in any order.
* @return The created selection. * @return The created selection.
*/ */
default TrackSelection createTrackSelection( TrackSelection createTrackSelection(
TrackGroup group, @Nullable BandwidthMeter bandwidthMeter, int... tracks) { TrackGroup group, BandwidthMeter bandwidthMeter, int... tracks);
return createTrackSelection(group, tracks);
}
} }
/** /**

View File

@ -23,6 +23,7 @@ import com.google.android.exoplayer2.RendererCapabilities;
import com.google.android.exoplayer2.RendererConfiguration; import com.google.android.exoplayer2.RendererConfiguration;
import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.upstream.BandwidthMeter; import com.google.android.exoplayer2.upstream.BandwidthMeter;
import com.google.android.exoplayer2.util.Assertions;
/** /**
* The component of an {@link ExoPlayer} responsible for selecting tracks to be consumed by each of * The component of an {@link ExoPlayer} responsible for selecting tracks to be consumed by each of
@ -103,10 +104,9 @@ public abstract class TrackSelector {
* *
* @param listener An invalidation listener that the selector can call to indicate that selections * @param listener An invalidation listener that the selector can call to indicate that selections
* it has previously made are no longer valid. * it has previously made are no longer valid.
* @param bandwidthMeter A bandwidth meter which can be used by track selections to select tracks, * @param bandwidthMeter A bandwidth meter which can be used by track selections to select tracks.
* or null if no such bandwidth meter is available.
*/ */
public final void init(InvalidationListener listener, @Nullable BandwidthMeter bandwidthMeter) { public final void init(InvalidationListener listener, BandwidthMeter bandwidthMeter) {
this.listener = listener; this.listener = listener;
this.bandwidthMeter = bandwidthMeter; this.bandwidthMeter = bandwidthMeter;
} }
@ -142,10 +142,10 @@ public abstract class TrackSelector {
} }
/** /**
* Returns a bandwidth meter which can be used by track selections to select tracks, or null if no * Returns a bandwidth meter which can be used by track selections to select tracks. Must only be
* such bandwidth meter is available. * called after {@link #init(InvalidationListener, BandwidthMeter)} has been called.
*/ */
protected final @Nullable BandwidthMeter getBandwidthMeter() { protected final BandwidthMeter getBandwidthMeter() {
return bandwidthMeter; return Assertions.checkNotNull(bandwidthMeter);
} }
} }

View File

@ -115,13 +115,16 @@ public final class DefaultTrackSelectorTest {
@Mock @Mock
private InvalidationListener invalidationListener; private InvalidationListener invalidationListener;
@Mock private BandwidthMeter bandwidthMeter;
private DefaultTrackSelector trackSelector; private DefaultTrackSelector trackSelector;
@Before @Before
public void setUp() { public void setUp() {
initMocks(this); initMocks(this);
when(bandwidthMeter.getBitrateEstimate()).thenReturn(1000000L);
trackSelector = new DefaultTrackSelector(); trackSelector = new DefaultTrackSelector();
trackSelector.init(invalidationListener, bandwidthMeter);
} }
/** Tests {@link Parameters} {@link android.os.Parcelable} implementation. */ /** Tests {@link Parameters} {@link android.os.Parcelable} implementation. */
@ -188,6 +191,7 @@ public final class DefaultTrackSelectorTest {
@Test @Test
public void testSelectTracksWithNullOverride() throws ExoPlaybackException { public void testSelectTracksWithNullOverride() throws ExoPlaybackException {
DefaultTrackSelector trackSelector = new DefaultTrackSelector(); DefaultTrackSelector trackSelector = new DefaultTrackSelector();
trackSelector.init(invalidationListener, bandwidthMeter);
trackSelector.setParameters( trackSelector.setParameters(
trackSelector trackSelector
.buildUponParameters() .buildUponParameters()
@ -202,6 +206,7 @@ public final class DefaultTrackSelectorTest {
@Test @Test
public void testSelectTracksWithClearedNullOverride() throws ExoPlaybackException { public void testSelectTracksWithClearedNullOverride() throws ExoPlaybackException {
DefaultTrackSelector trackSelector = new DefaultTrackSelector(); DefaultTrackSelector trackSelector = new DefaultTrackSelector();
trackSelector.init(invalidationListener, bandwidthMeter);
trackSelector.setParameters( trackSelector.setParameters(
trackSelector trackSelector
.buildUponParameters() .buildUponParameters()
@ -217,6 +222,7 @@ public final class DefaultTrackSelectorTest {
@Test @Test
public void testSelectTracksWithNullOverrideForDifferentTracks() throws ExoPlaybackException { public void testSelectTracksWithNullOverrideForDifferentTracks() throws ExoPlaybackException {
DefaultTrackSelector trackSelector = new DefaultTrackSelector(); DefaultTrackSelector trackSelector = new DefaultTrackSelector();
trackSelector.init(invalidationListener, bandwidthMeter);
trackSelector.setParameters( trackSelector.setParameters(
trackSelector trackSelector
.buildUponParameters() .buildUponParameters()
@ -234,6 +240,7 @@ public final class DefaultTrackSelectorTest {
@Test @Test
public void testSelectTracksWithDisabledRenderer() throws ExoPlaybackException { public void testSelectTracksWithDisabledRenderer() throws ExoPlaybackException {
DefaultTrackSelector trackSelector = new DefaultTrackSelector(); DefaultTrackSelector trackSelector = new DefaultTrackSelector();
trackSelector.init(invalidationListener, bandwidthMeter);
trackSelector.setParameters(trackSelector.buildUponParameters().setRendererDisabled(1, true)); trackSelector.setParameters(trackSelector.buildUponParameters().setRendererDisabled(1, true));
TrackSelectorResult result = trackSelector.selectTracks(RENDERER_CAPABILITIES, TRACK_GROUPS); TrackSelectorResult result = trackSelector.selectTracks(RENDERER_CAPABILITIES, TRACK_GROUPS);
assertTrackSelections(result, new TrackSelection[] {TRACK_SELECTIONS[0], null}); assertTrackSelections(result, new TrackSelection[] {TRACK_SELECTIONS[0], null});
@ -245,6 +252,7 @@ public final class DefaultTrackSelectorTest {
@Test @Test
public void testSelectTracksWithClearedDisabledRenderer() throws ExoPlaybackException { public void testSelectTracksWithClearedDisabledRenderer() throws ExoPlaybackException {
DefaultTrackSelector trackSelector = new DefaultTrackSelector(); DefaultTrackSelector trackSelector = new DefaultTrackSelector();
trackSelector.init(invalidationListener, bandwidthMeter);
trackSelector.setParameters( trackSelector.setParameters(
trackSelector trackSelector
.buildUponParameters() .buildUponParameters()
@ -260,6 +268,7 @@ public final class DefaultTrackSelectorTest {
@Test @Test
public void testSelectTracksWithNoSampleRenderer() throws ExoPlaybackException { public void testSelectTracksWithNoSampleRenderer() throws ExoPlaybackException {
DefaultTrackSelector trackSelector = new DefaultTrackSelector(); DefaultTrackSelector trackSelector = new DefaultTrackSelector();
trackSelector.init(invalidationListener, bandwidthMeter);
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks(RENDERER_CAPABILITIES_WITH_NO_SAMPLE_RENDERER, TRACK_GROUPS); trackSelector.selectTracks(RENDERER_CAPABILITIES_WITH_NO_SAMPLE_RENDERER, TRACK_GROUPS);
assertTrackSelections(result, TRACK_SELECTIONS_WITH_NO_SAMPLE_RENDERER); assertTrackSelections(result, TRACK_SELECTIONS_WITH_NO_SAMPLE_RENDERER);
@ -271,6 +280,7 @@ public final class DefaultTrackSelectorTest {
@Test @Test
public void testSelectTracksWithDisabledNoSampleRenderer() throws ExoPlaybackException { public void testSelectTracksWithDisabledNoSampleRenderer() throws ExoPlaybackException {
DefaultTrackSelector trackSelector = new DefaultTrackSelector(); DefaultTrackSelector trackSelector = new DefaultTrackSelector();
trackSelector.init(invalidationListener, bandwidthMeter);
trackSelector.setParameters(trackSelector.buildUponParameters().setRendererDisabled(1, true)); trackSelector.setParameters(trackSelector.buildUponParameters().setRendererDisabled(1, true));
TrackSelectorResult result = TrackSelectorResult result =
trackSelector.selectTracks(RENDERER_CAPABILITIES_WITH_NO_SAMPLE_RENDERER, TRACK_GROUPS); trackSelector.selectTracks(RENDERER_CAPABILITIES_WITH_NO_SAMPLE_RENDERER, TRACK_GROUPS);
@ -357,9 +367,10 @@ public final class DefaultTrackSelectorTest {
Format.createAudioSampleFormat("audio", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE, Format.createAudioSampleFormat("audio", MimeTypes.AUDIO_AAC, null, Format.NO_VALUE,
Format.NO_VALUE, 2, 44100, null, null, 0, "eng"); Format.NO_VALUE, 2, 44100, null, null, 0, "eng");
TrackSelectorResult result = trackSelector.selectTracks( TrackSelectorResult result =
new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES}, trackSelector.selectTracks(
singleTrackGroup(frAudioFormat, enAudioFormat)); new RendererCapabilities[] {ALL_AUDIO_FORMAT_SUPPORTED_RENDERER_CAPABILITIES},
wrapFormats(frAudioFormat, enAudioFormat));
assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(enAudioFormat); assertThat(result.selections.get(0).getSelectedFormat()).isEqualTo(enAudioFormat);
} }
@ -933,8 +944,6 @@ public final class DefaultTrackSelectorTest {
.thenReturn(adaptiveTrackSelection); .thenReturn(adaptiveTrackSelection);
trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory); trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory);
BandwidthMeter bandwidthMeter = mock(BandwidthMeter.class);
trackSelector.init(invalidationListener, bandwidthMeter); trackSelector.init(invalidationListener, bandwidthMeter);
TrackGroupArray trackGroupArray = singleTrackGroup(AUDIO_FORMAT, AUDIO_FORMAT); TrackGroupArray trackGroupArray = singleTrackGroup(AUDIO_FORMAT, AUDIO_FORMAT);
@ -957,8 +966,6 @@ public final class DefaultTrackSelectorTest {
.thenReturn(adaptiveTrackSelection); .thenReturn(adaptiveTrackSelection);
trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory); trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory);
BandwidthMeter bandwidthMeter = mock(BandwidthMeter.class);
trackSelector.init(invalidationListener, bandwidthMeter); trackSelector.init(invalidationListener, bandwidthMeter);
TrackGroupArray trackGroupArray = singleTrackGroup(AUDIO_FORMAT, AUDIO_FORMAT, AUDIO_FORMAT); TrackGroupArray trackGroupArray = singleTrackGroup(AUDIO_FORMAT, AUDIO_FORMAT, AUDIO_FORMAT);
@ -988,8 +995,6 @@ public final class DefaultTrackSelectorTest {
.thenReturn(adaptiveTrackSelection); .thenReturn(adaptiveTrackSelection);
trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory); trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory);
BandwidthMeter bandwidthMeter = mock(BandwidthMeter.class);
trackSelector.init(invalidationListener, bandwidthMeter); trackSelector.init(invalidationListener, bandwidthMeter);
TrackGroupArray trackGroupArray = singleTrackGroup(VIDEO_FORMAT, VIDEO_FORMAT); TrackGroupArray trackGroupArray = singleTrackGroup(VIDEO_FORMAT, VIDEO_FORMAT);
@ -1012,8 +1017,6 @@ public final class DefaultTrackSelectorTest {
.thenReturn(adaptiveTrackSelection); .thenReturn(adaptiveTrackSelection);
trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory); trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory);
BandwidthMeter bandwidthMeter = mock(BandwidthMeter.class);
trackSelector.init(invalidationListener, bandwidthMeter); trackSelector.init(invalidationListener, bandwidthMeter);
TrackGroupArray trackGroupArray = singleTrackGroup(VIDEO_FORMAT, VIDEO_FORMAT, VIDEO_FORMAT); TrackGroupArray trackGroupArray = singleTrackGroup(VIDEO_FORMAT, VIDEO_FORMAT, VIDEO_FORMAT);

View File

@ -16,6 +16,7 @@
package com.google.android.exoplayer2.trackselection; package com.google.android.exoplayer2.trackselection;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.fail;
import com.google.android.exoplayer2.ExoPlaybackException; import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.RendererCapabilities; import com.google.android.exoplayer2.RendererCapabilities;
@ -49,8 +50,13 @@ public class TrackSelectorTest {
} }
@Test @Test
public void getBandwidthMeter_beforeInitialization_returnsNull() { public void getBandwidthMeter_beforeInitialization_throwsException() {
assertThat(trackSelector.getBandwidthMeter()).isNull(); try {
trackSelector.getBandwidthMeter();
fail();
} catch (Exception e) {
// Expected.
}
} }
@Test @Test