Commit 363b4224 by tonihei Committed by Oliver Woodman

Fix stuck buffering problem caused by target buffer size of 0.

When no tracks are selected (or only tracks of unknown type), the
target buffer size is calculated to be 0. This means the player
won't request to buffer more data, nor can it start playback and
will be stuck forever.

PiperOrigin-RevId: 301374229
parent 71eec8ea
......@@ -84,6 +84,9 @@ public class DefaultLoadControl implements LoadControl {
public static final int DEFAULT_MUXED_BUFFER_SIZE =
DEFAULT_VIDEO_BUFFER_SIZE + DEFAULT_AUDIO_BUFFER_SIZE + DEFAULT_TEXT_BUFFER_SIZE;
/** The buffer size in bytes that will be used as a minimum target buffer in all cases. */
public static final int DEFAULT_MIN_BUFFER_SIZE = 200 * C.DEFAULT_BUFFER_SEGMENT_SIZE;
/** Builder for {@link DefaultLoadControl}. */
public static final class Builder {
......@@ -316,7 +319,7 @@ public class DefaultLoadControl implements LoadControl {
this.targetBufferBytes =
targetBufferBytesOverwrite != C.LENGTH_UNSET
? targetBufferBytesOverwrite
: DEFAULT_MUXED_BUFFER_SIZE;
: DEFAULT_MIN_BUFFER_SIZE;
this.prioritizeTimeOverSizeThresholds = prioritizeTimeOverSizeThresholds;
this.backBufferDurationUs = C.msToUs(backBufferDurationMs);
this.retainBackBufferFromKeyframe = retainBackBufferFromKeyframe;
......@@ -410,13 +413,13 @@ public class DefaultLoadControl implements LoadControl {
targetBufferSize += getDefaultBufferSize(renderers[i].getTrackType());
}
}
return targetBufferSize;
return Math.max(DEFAULT_MIN_BUFFER_SIZE, targetBufferSize);
}
private void reset(boolean resetAllocator) {
targetBufferBytes =
targetBufferBytesOverwrite == C.LENGTH_UNSET
? DEFAULT_MUXED_BUFFER_SIZE
? DEFAULT_MIN_BUFFER_SIZE
: targetBufferBytesOverwrite;
isBuffering = false;
if (resetAllocator) {
......
......@@ -19,6 +19,8 @@ import static com.google.common.truth.Truth.assertThat;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.DefaultLoadControl.Builder;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.upstream.DefaultAllocator;
import org.junit.Before;
import org.junit.Test;
......@@ -145,6 +147,16 @@ public class DefaultLoadControlTest {
.isTrue();
}
@Test
public void shouldContinueLoading_withNoSelectedTracks_returnsTrue() {
loadControl = builder.createDefaultLoadControl();
loadControl.onTracksSelected(new Renderer[0], TrackGroupArray.EMPTY, new TrackSelectionArray());
assertThat(
loadControl.shouldContinueLoading(/* bufferedDurationUs= */ 0, /* playbackSpeed= */ 1f))
.isTrue();
}
private void createDefaultLoadControl() {
builder.setAllocator(allocator).setTargetBufferBytes(TARGET_BUFFER_BYTES);
loadControl = builder.createDefaultLoadControl();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment