DefaultLoadControl implements LoadControl { @Override public boolean shouldContinueLoading(long bufferedDurationUs, float playbackSpeed) { boolean targetBufferSizeReached = allocator.getTotalBytesAllocated() >= targetBufferSize; long minBufferUs = hasVideo ? minBufferVideoUs : minBufferAudioUs; if (playbackSpeed > 1) { long mediaDurationMinBufferUs = Util.getMediaDurationForPlayoutDuration(minBufferUs, playbackSpeed); minBufferUs = Math.min(mediaDurationMinBufferUs, maxBufferUs); } if (bufferedDurationUs < minBufferUs) { isBuffering = prioritizeTimeOverSizeThresholds || !targetBufferSizeReached; } else if (bufferedDurationUs >= maxBufferUs || targetBufferSizeReached) { isBuffering = false; } return isBuffering; } @SuppressWarnings("deprecation")  DefaultLoadControl(); @Deprecated  DefaultLoadControl(DefaultAllocator allocator); @Deprecated  DefaultLoadControl(
      DefaultAllocator allocator,
      int minBufferMs,
      int maxBufferMs,
      int bufferForPlaybackMs,
      int bufferForPlaybackAfterRebufferMs,
      int targetBufferBytes,
      boolean prioritizeTimeOverSizeThresholds); protected  DefaultLoadControl(
      DefaultAllocator allocator,
      int minBufferAudioMs,
      int minBufferVideoMs,
      int maxBufferMs,
      int bufferForPlaybackMs,
      int bufferForPlaybackAfterRebufferMs,
      int targetBufferBytes,
      boolean prioritizeTimeOverSizeThresholds,
      int backBufferDurationMs,
      boolean retainBackBufferFromKeyframe); @Override void onPrepared(); @Override void onTracksSelected(Renderer[] renderers, TrackGroupArray trackGroups,
      TrackSelectionArray trackSelections); @Override void onStopped(); @Override void onReleased(); @Override Allocator getAllocator(); @Override long getBackBufferDurationUs(); @Override boolean retainBackBufferFromKeyframe(); @Override boolean shouldContinueLoading(long bufferedDurationUs, float playbackSpeed); @Override boolean shouldStartPlayback(
      long bufferedDurationUs, float playbackSpeed, boolean rebuffering); static final int DEFAULT_MIN_BUFFER_MS; static final int DEFAULT_MAX_BUFFER_MS; static final int DEFAULT_BUFFER_FOR_PLAYBACK_MS; static final int DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS; static final int DEFAULT_TARGET_BUFFER_BYTES; static final boolean DEFAULT_PRIORITIZE_TIME_OVER_SIZE_THRESHOLDS; static final int DEFAULT_BACK_BUFFER_DURATION_MS; static final boolean DEFAULT_RETAIN_BACK_BUFFER_FROM_KEYFRAME; static final int DEFAULT_VIDEO_BUFFER_SIZE; static final int DEFAULT_AUDIO_BUFFER_SIZE; static final int DEFAULT_TEXT_BUFFER_SIZE; static final int DEFAULT_METADATA_BUFFER_SIZE; static final int DEFAULT_CAMERA_MOTION_BUFFER_SIZE; static final int DEFAULT_MUXED_BUFFER_SIZE; }
@Test public void testShouldContinueLoading_untilMaxBufferExceeded() { createDefaultLoadControl(); assertThat(loadControl.shouldContinueLoading( 0, SPEED)).isTrue(); assertThat(loadControl.shouldContinueLoading(MIN_BUFFER_US, SPEED)).isTrue(); assertThat(loadControl.shouldContinueLoading(MAX_BUFFER_US - 1, SPEED)).isTrue(); assertThat(loadControl.shouldContinueLoading(MAX_BUFFER_US, SPEED)).isFalse(); }
@Test public void testShouldNotContinueLoadingOnceBufferingStopped_untilBelowMinBuffer() { createDefaultLoadControl(); assertThat(loadControl.shouldContinueLoading(MAX_BUFFER_US, SPEED)).isFalse(); assertThat(loadControl.shouldContinueLoading(MAX_BUFFER_US - 1, SPEED)).isFalse(); assertThat(loadControl.shouldContinueLoading(MIN_BUFFER_US, SPEED)).isFalse(); assertThat(loadControl.shouldContinueLoading(MIN_BUFFER_US - 1, SPEED)).isTrue(); }
@Test public void testShouldContinueLoadingWithTargetBufferBytesReached_untilMinBufferReached() { createDefaultLoadControl(); makeSureTargetBufferBytesReached(); assertThat(loadControl.shouldContinueLoading( 0, SPEED)).isTrue(); assertThat(loadControl.shouldContinueLoading(MIN_BUFFER_US - 1, SPEED)).isTrue(); assertThat(loadControl.shouldContinueLoading(MIN_BUFFER_US, SPEED)).isFalse(); assertThat(loadControl.shouldContinueLoading(MAX_BUFFER_US, SPEED)).isFalse(); }
@Test public void testShouldNeverContinueLoading_ifMaxBufferReachedAndNotPrioritizeTimeOverSize() { builder.setPrioritizeTimeOverSizeThresholds(false); createDefaultLoadControl(); assertThat(loadControl.shouldContinueLoading( 0, SPEED)).isTrue(); makeSureTargetBufferBytesReached(); assertThat(loadControl.shouldContinueLoading( 0, SPEED)).isFalse(); assertThat(loadControl.shouldContinueLoading(MIN_BUFFER_US, SPEED)).isFalse(); assertThat(loadControl.shouldContinueLoading(MAX_BUFFER_US, SPEED)).isFalse(); }
@Test public void testShouldContinueLoadingWithMinBufferReached_inFastPlayback() { createDefaultLoadControl(); assertThat(loadControl.shouldContinueLoading(MIN_BUFFER_US, SPEED)).isFalse(); assertThat(loadControl.shouldContinueLoading(MIN_BUFFER_US, 2f)).isTrue(); }
@Test public void testShouldNotContinueLoadingWithMaxBufferReached_inFastPlayback() { createDefaultLoadControl(); assertThat(loadControl.shouldContinueLoading(MAX_BUFFER_US, 100f)) .isFalse(); }