From c16d0f6c5df57b12091c6da1dcbc3ed7c23a3d20 Mon Sep 17 00:00:00 2001 From: tonihei Date: Fri, 13 Mar 2020 09:46:01 +0000 Subject: [PATCH] Default prioritizeTimeOverSizeThresholds to false. This prevents OOM errors for high bitrate streams that attempt to fill the buffer regardless of the memory usage. Also change the max buffer sizes to ensure this is a no-op for video streams < 20Mbps and audio streams < 260kbps. Issue:#6647 Issue:#7006 PiperOrigin-RevId: 300720299 --- RELEASENOTES.md | 3 +++ .../com/google/android/exoplayer2/DefaultLoadControl.java | 6 +++--- .../google/android/exoplayer2/DefaultLoadControlTest.java | 7 ++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index b15baee3cf..0b4d419d8c 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -265,6 +265,9 @@ ([#5749](https://github.com/google/ExoPlayer/issues/5749)). * Add option to set preferred text role flags using `DefaultTrackSelector.ParametersBuilder.setPreferredTextRoleFlags`. +* LoadControl: + * Default `prioritizeTimeOverSizeThresholds` to false to prevent OOM errors + ([#6647](https://github.com/google/ExoPlayer/issues/6647)). * Android 10: * Set `compileSdkVersion` to 29 to enable use of Android 10 APIs. * Expose new `isHardwareAccelerated`, `isSoftwareOnly` and `isVendor` flags diff --git a/library/core/src/main/java/com/google/android/exoplayer2/DefaultLoadControl.java b/library/core/src/main/java/com/google/android/exoplayer2/DefaultLoadControl.java index 9fc72152e3..ae7cb9d64e 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/DefaultLoadControl.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/DefaultLoadControl.java @@ -57,7 +57,7 @@ public class DefaultLoadControl implements LoadControl { public static final int DEFAULT_TARGET_BUFFER_BYTES = C.LENGTH_UNSET; /** The default prioritization of buffer time constraints over size constraints. */ - public static final boolean DEFAULT_PRIORITIZE_TIME_OVER_SIZE_THRESHOLDS = true; + public static final boolean DEFAULT_PRIORITIZE_TIME_OVER_SIZE_THRESHOLDS = false; /** The default back buffer duration in milliseconds. */ public static final int DEFAULT_BACK_BUFFER_DURATION_MS = 0; @@ -66,10 +66,10 @@ public class DefaultLoadControl implements LoadControl { public static final boolean DEFAULT_RETAIN_BACK_BUFFER_FROM_KEYFRAME = false; /** A default size in bytes for a video buffer. */ - public static final int DEFAULT_VIDEO_BUFFER_SIZE = 500 * C.DEFAULT_BUFFER_SEGMENT_SIZE; + public static final int DEFAULT_VIDEO_BUFFER_SIZE = 2000 * C.DEFAULT_BUFFER_SEGMENT_SIZE; /** A default size in bytes for an audio buffer. */ - public static final int DEFAULT_AUDIO_BUFFER_SIZE = 54 * C.DEFAULT_BUFFER_SEGMENT_SIZE; + public static final int DEFAULT_AUDIO_BUFFER_SIZE = 200 * C.DEFAULT_BUFFER_SEGMENT_SIZE; /** A default size in bytes for a text buffer. */ public static final int DEFAULT_TEXT_BUFFER_SIZE = 2 * C.DEFAULT_BUFFER_SEGMENT_SIZE; diff --git a/library/core/src/test/java/com/google/android/exoplayer2/DefaultLoadControlTest.java b/library/core/src/test/java/com/google/android/exoplayer2/DefaultLoadControlTest.java index 221950f5af..ff8caacd9c 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/DefaultLoadControlTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/DefaultLoadControlTest.java @@ -68,8 +68,7 @@ public class DefaultLoadControlTest { } @Test - public void - testContinueLoadingOnceBufferingStopped_andBufferAlmostEmpty_evenIfMinBufferNotReached() { + public void continueLoadingOnceBufferingStopped_andBufferAlmostEmpty_evenIfMinBufferNotReached() { builder.setBufferDurationsMs( /* minBufferMs= */ 0, /* maxBufferMs= */ (int) C.usToMs(MAX_BUFFER_US), @@ -84,6 +83,7 @@ public class DefaultLoadControlTest { @Test public void shouldContinueLoadingWithTargetBufferBytesReached_untilMinBufferReached() { + builder.setPrioritizeTimeOverSizeThresholds(true); builder.setBufferDurationsMs( /* minBufferMs= */ (int) C.usToMs(MIN_BUFFER_US), /* maxBufferMs= */ (int) C.usToMs(MAX_BUFFER_US), @@ -99,7 +99,8 @@ public class DefaultLoadControlTest { } @Test - public void shouldNeverContinueLoading_ifMaxBufferReachedAndNotPrioritizeTimeOverSize() { + public void + shouldContinueLoading_withTargetBufferBytesReachedAndNotPrioritizeTimeOverSize_returnsTrueAsSoonAsTargetBufferReached() { builder.setPrioritizeTimeOverSizeThresholds(false); createDefaultLoadControl();