@Test @SuppressWarnings("deprecation") public void testFactoryUsesInitiallyProvidedBandwidthMeter() { BandwidthMeter initialBandwidthMeter = mock(BandwidthMeter.class); BandwidthMeter injectedBandwidthMeter = mock(BandwidthMeter.class); Format format1 = videoFormat( 500, 320, 240); Format format2 = videoFormat( 1000, 640, 480); TrackSelection[] trackSelections = new AdaptiveTrackSelection.Factory(initialBandwidthMeter) .createTrackSelections( new Definition[] { new Definition(new TrackGroup(format1, format2), 0, 1) }, injectedBandwidthMeter); trackSelections[0].updateSelectedTrack( 0, 0, C.TIME_UNSET, Collections.emptyList(), new MediaChunkIterator[] {MediaChunkIterator.EMPTY}); verify(initialBandwidthMeter, atLeastOnce()).getBitrateEstimate(); verifyZeroInteractions(injectedBandwidthMeter); }
@Override public void updateSelectedTrack( long playbackPositionUs, long bufferedDurationUs, long availableDurationUs, List<? extends MediaChunk> queue, MediaChunkIterator[] mediaChunkIterators) { long nowMs = clock.elapsedRealtime(); trackBitrateEstimator.getBitrates(formats, queue, mediaChunkIterators, trackBitrates); if (reason == C.SELECTION_REASON_UNKNOWN) { reason = C.SELECTION_REASON_INITIAL; selectedIndex = determineIdealSelectedIndex(nowMs, trackBitrates); return; } int currentSelectedIndex = selectedIndex; selectedIndex = determineIdealSelectedIndex(nowMs, trackBitrates); if (selectedIndex == currentSelectedIndex) { return; } if (!isBlacklisted(currentSelectedIndex, nowMs)) { Format currentFormat = getFormat(currentSelectedIndex); Format selectedFormat = getFormat(selectedIndex); if (selectedFormat.bitrate > currentFormat.bitrate && bufferedDurationUs < minDurationForQualityIncreaseUs(availableDurationUs)) { selectedIndex = currentSelectedIndex; } else if (selectedFormat.bitrate < currentFormat.bitrate && bufferedDurationUs >= maxDurationForQualityDecreaseUs) { selectedIndex = currentSelectedIndex; } } if (selectedIndex != currentSelectedIndex) { reason = C.SELECTION_REASON_ADAPTIVE; } }
AdaptiveTrackSelection extends BaseTrackSelection { @Override public void updateSelectedTrack( long playbackPositionUs, long bufferedDurationUs, long availableDurationUs, List<? extends MediaChunk> queue, MediaChunkIterator[] mediaChunkIterators) { long nowMs = clock.elapsedRealtime(); trackBitrateEstimator.getBitrates(formats, queue, mediaChunkIterators, trackBitrates); if (reason == C.SELECTION_REASON_UNKNOWN) { reason = C.SELECTION_REASON_INITIAL; selectedIndex = determineIdealSelectedIndex(nowMs, trackBitrates); return; } int currentSelectedIndex = selectedIndex; selectedIndex = determineIdealSelectedIndex(nowMs, trackBitrates); if (selectedIndex == currentSelectedIndex) { return; } if (!isBlacklisted(currentSelectedIndex, nowMs)) { Format currentFormat = getFormat(currentSelectedIndex); Format selectedFormat = getFormat(selectedIndex); if (selectedFormat.bitrate > currentFormat.bitrate && bufferedDurationUs < minDurationForQualityIncreaseUs(availableDurationUs)) { selectedIndex = currentSelectedIndex; } else if (selectedFormat.bitrate < currentFormat.bitrate && bufferedDurationUs >= maxDurationForQualityDecreaseUs) { selectedIndex = currentSelectedIndex; } } if (selectedIndex != currentSelectedIndex) { reason = C.SELECTION_REASON_ADAPTIVE; } } }
AdaptiveTrackSelection extends BaseTrackSelection { @Override public void updateSelectedTrack( long playbackPositionUs, long bufferedDurationUs, long availableDurationUs, List<? extends MediaChunk> queue, MediaChunkIterator[] mediaChunkIterators) { long nowMs = clock.elapsedRealtime(); trackBitrateEstimator.getBitrates(formats, queue, mediaChunkIterators, trackBitrates); if (reason == C.SELECTION_REASON_UNKNOWN) { reason = C.SELECTION_REASON_INITIAL; selectedIndex = determineIdealSelectedIndex(nowMs, trackBitrates); return; } int currentSelectedIndex = selectedIndex; selectedIndex = determineIdealSelectedIndex(nowMs, trackBitrates); if (selectedIndex == currentSelectedIndex) { return; } if (!isBlacklisted(currentSelectedIndex, nowMs)) { Format currentFormat = getFormat(currentSelectedIndex); Format selectedFormat = getFormat(selectedIndex); if (selectedFormat.bitrate > currentFormat.bitrate && bufferedDurationUs < minDurationForQualityIncreaseUs(availableDurationUs)) { selectedIndex = currentSelectedIndex; } else if (selectedFormat.bitrate < currentFormat.bitrate && bufferedDurationUs >= maxDurationForQualityDecreaseUs) { selectedIndex = currentSelectedIndex; } } if (selectedIndex != currentSelectedIndex) { reason = C.SELECTION_REASON_ADAPTIVE; } } AdaptiveTrackSelection(TrackGroup group, int[] tracks,
      BandwidthMeter bandwidthMeter);  AdaptiveTrackSelection(
      TrackGroup group,
      int[] tracks,
      BandwidthMeter bandwidthMeter,
      long minDurationForQualityIncreaseMs,
      long maxDurationForQualityDecreaseMs,
      long minDurationToRetainAfterDiscardMs,
      float bandwidthFraction,
      float bufferedFractionToLiveEdgeForQualityIncrease,
      long minTimeBetweenBufferReevaluationMs,
      Clock clock); private  AdaptiveTrackSelection(
      TrackGroup group,
      int[] tracks,
      BandwidthProvider bandwidthProvider,
      long minDurationForQualityIncreaseMs,
      long maxDurationForQualityDecreaseMs,
      long minDurationToRetainAfterDiscardMs,
      float bufferedFractionToLiveEdgeForQualityIncrease,
      long minTimeBetweenBufferReevaluationMs,
      Clock clock); }
AdaptiveTrackSelection extends BaseTrackSelection { @Override public void updateSelectedTrack( long playbackPositionUs, long bufferedDurationUs, long availableDurationUs, List<? extends MediaChunk> queue, MediaChunkIterator[] mediaChunkIterators) { long nowMs = clock.elapsedRealtime(); trackBitrateEstimator.getBitrates(formats, queue, mediaChunkIterators, trackBitrates); if (reason == C.SELECTION_REASON_UNKNOWN) { reason = C.SELECTION_REASON_INITIAL; selectedIndex = determineIdealSelectedIndex(nowMs, trackBitrates); return; } int currentSelectedIndex = selectedIndex; selectedIndex = determineIdealSelectedIndex(nowMs, trackBitrates); if (selectedIndex == currentSelectedIndex) { return; } if (!isBlacklisted(currentSelectedIndex, nowMs)) { Format currentFormat = getFormat(currentSelectedIndex); Format selectedFormat = getFormat(selectedIndex); if (selectedFormat.bitrate > currentFormat.bitrate && bufferedDurationUs < minDurationForQualityIncreaseUs(availableDurationUs)) { selectedIndex = currentSelectedIndex; } else if (selectedFormat.bitrate < currentFormat.bitrate && bufferedDurationUs >= maxDurationForQualityDecreaseUs) { selectedIndex = currentSelectedIndex; } } if (selectedIndex != currentSelectedIndex) { reason = C.SELECTION_REASON_ADAPTIVE; } } AdaptiveTrackSelection(TrackGroup group, int[] tracks,
      BandwidthMeter bandwidthMeter);  AdaptiveTrackSelection(
      TrackGroup group,
      int[] tracks,
      BandwidthMeter bandwidthMeter,
      long minDurationForQualityIncreaseMs,
      long maxDurationForQualityDecreaseMs,
      long minDurationToRetainAfterDiscardMs,
      float bandwidthFraction,
      float bufferedFractionToLiveEdgeForQualityIncrease,
      long minTimeBetweenBufferReevaluationMs,
      Clock clock); private  AdaptiveTrackSelection(
      TrackGroup group,
      int[] tracks,
      BandwidthProvider bandwidthProvider,
      long minDurationForQualityIncreaseMs,
      long maxDurationForQualityDecreaseMs,
      long minDurationToRetainAfterDiscardMs,
      float bufferedFractionToLiveEdgeForQualityIncrease,
      long minTimeBetweenBufferReevaluationMs,
      Clock clock); void experimental_setTrackBitrateEstimator(TrackBitrateEstimator trackBitrateEstimator); void experimental_setNonAllocatableBandwidth(long nonAllocatableBandwidth); void experimental_setBandwidthAllocationCheckpoints(long[][] allocationCheckpoints); @Override void enable(); @Override void onPlaybackSpeed(float playbackSpeed); @Override void updateSelectedTrack(
      long playbackPositionUs,
      long bufferedDurationUs,
      long availableDurationUs,
      List<? extends MediaChunk> queue,
      MediaChunkIterator[] mediaChunkIterators); @Override int getSelectedIndex(); @Override int getSelectionReason(); @Override @Nullable Object getSelectionData(); @Override int evaluateQueueSize(long playbackPositionUs, List<? extends MediaChunk> queue); }
AdaptiveTrackSelection extends BaseTrackSelection { @Override public void updateSelectedTrack( long playbackPositionUs, long bufferedDurationUs, long availableDurationUs, List<? extends MediaChunk> queue, MediaChunkIterator[] mediaChunkIterators) { long nowMs = clock.elapsedRealtime(); trackBitrateEstimator.getBitrates(formats, queue, mediaChunkIterators, trackBitrates); if (reason == C.SELECTION_REASON_UNKNOWN) { reason = C.SELECTION_REASON_INITIAL; selectedIndex = determineIdealSelectedIndex(nowMs, trackBitrates); return; } int currentSelectedIndex = selectedIndex; selectedIndex = determineIdealSelectedIndex(nowMs, trackBitrates); if (selectedIndex == currentSelectedIndex) { return; } if (!isBlacklisted(currentSelectedIndex, nowMs)) { Format currentFormat = getFormat(currentSelectedIndex); Format selectedFormat = getFormat(selectedIndex); if (selectedFormat.bitrate > currentFormat.bitrate && bufferedDurationUs < minDurationForQualityIncreaseUs(availableDurationUs)) { selectedIndex = currentSelectedIndex; } else if (selectedFormat.bitrate < currentFormat.bitrate && bufferedDurationUs >= maxDurationForQualityDecreaseUs) { selectedIndex = currentSelectedIndex; } } if (selectedIndex != currentSelectedIndex) { reason = C.SELECTION_REASON_ADAPTIVE; } } AdaptiveTrackSelection(TrackGroup group, int[] tracks,
      BandwidthMeter bandwidthMeter);  AdaptiveTrackSelection(
      TrackGroup group,
      int[] tracks,
      BandwidthMeter bandwidthMeter,
      long minDurationForQualityIncreaseMs,
      long maxDurationForQualityDecreaseMs,
      long minDurationToRetainAfterDiscardMs,
      float bandwidthFraction,
      float bufferedFractionToLiveEdgeForQualityIncrease,
      long minTimeBetweenBufferReevaluationMs,
      Clock clock); private  AdaptiveTrackSelection(
      TrackGroup group,
      int[] tracks,
      BandwidthProvider bandwidthProvider,
      long minDurationForQualityIncreaseMs,
      long maxDurationForQualityDecreaseMs,
      long minDurationToRetainAfterDiscardMs,
      float bufferedFractionToLiveEdgeForQualityIncrease,
      long minTimeBetweenBufferReevaluationMs,
      Clock clock); void experimental_setTrackBitrateEstimator(TrackBitrateEstimator trackBitrateEstimator); void experimental_setNonAllocatableBandwidth(long nonAllocatableBandwidth); void experimental_setBandwidthAllocationCheckpoints(long[][] allocationCheckpoints); @Override void enable(); @Override void onPlaybackSpeed(float playbackSpeed); @Override void updateSelectedTrack(
      long playbackPositionUs,
      long bufferedDurationUs,
      long availableDurationUs,
      List<? extends MediaChunk> queue,
      MediaChunkIterator[] mediaChunkIterators); @Override int getSelectedIndex(); @Override int getSelectionReason(); @Override @Nullable Object getSelectionData(); @Override int evaluateQueueSize(long playbackPositionUs, List<? extends MediaChunk> queue); static final int DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS; static final int DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS; static final int DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS; static final float DEFAULT_BANDWIDTH_FRACTION; static final float DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE; static final long DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS; }