From 6031f89fe96e20bbf4107a299acd4c40b42856e7 Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Thu, 23 Jun 2016 11:30:56 -0700 Subject: [PATCH] Limit the maximum number of sources to buffer. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=125698923 --- .../android/exoplayer/ExoPlayerImplInternal.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer/ExoPlayerImplInternal.java b/library/src/main/java/com/google/android/exoplayer/ExoPlayerImplInternal.java index 855b4dc3f5..062d888f5b 100644 --- a/library/src/main/java/com/google/android/exoplayer/ExoPlayerImplInternal.java +++ b/library/src/main/java/com/google/android/exoplayer/ExoPlayerImplInternal.java @@ -82,6 +82,13 @@ import java.util.ArrayList; private static final int RENDERING_INTERVAL_MS = 10; private static final int IDLE_INTERVAL_MS = 1000; + /** + * Limits the maximum number of sources to buffer ahead of the current source in the timeline. The + * source buffering policy normally prevents buffering too far ahead, but the policy could allow + * too many very small sources to be buffered if the buffered source count were not limited. + */ + private static final int MAXIMUM_BUFFER_AHEAD_SOURCES = 100; + private final TrackSelector trackSelector; private final StandaloneMediaClock standaloneMediaClock; private final long minBufferUs; @@ -601,10 +608,9 @@ import java.util.ArrayList; // TODO[playlists]: Let sample source providers invalidate sources that are already buffering. int sourceCount = sampleSourceProvider.getSourceCount(); - // TODO: There should probably be some kind of read ahead limit here to prevent the number of - // sources between the playing source and the buffering source from growing excessively large - // (e.g. >100)? - if (bufferingSource == null || bufferingSource.isFullyBuffered()) { + if (bufferingSource == null + || (bufferingSource.isFullyBuffered() && bufferingSource.index + - (playingSource != null ? playingSource.index : 0) < MAXIMUM_BUFFER_AHEAD_SOURCES)) { // Try and obtain the next source to start buffering. int sourceIndex = bufferingSource == null ? pendingSourceIndex : bufferingSource.index + 1; if (sourceCount == SampleSourceProvider.UNKNOWN_SOURCE_COUNT || sourceIndex < sourceCount) {