Change default video buffer size to 32MB.

The current max video buffer is 13MB which is too small for high quality
streams and doesn't allow the DefaultLoadControl to buffer up to its default
max buffer time of 50 seconds.

Also move util method and constants only used by DefaultLoadControl into this
class.

PiperOrigin-RevId: 263328088
This commit is contained in:
tonihei 2019-08-14 13:09:21 +01:00 committed by Andrew Lewis
parent a572fb3f22
commit 6dd3d49093
4 changed files with 43 additions and 49 deletions

View File

@ -32,6 +32,8 @@
different channel counts different channel counts
([#6257](https://github.com/google/ExoPlayer/issues/6257)). ([#6257](https://github.com/google/ExoPlayer/issues/6257)).
* Reset `DefaultBandwidthMeter` to initial values on network change. * Reset `DefaultBandwidthMeter` to initial values on network change.
* Increase maximum buffer size for video in `DefaultLoadControl` to ensure high
quality video can be loaded up to the full default buffer duration.
### 2.10.4 ### ### 2.10.4 ###

View File

@ -685,25 +685,6 @@ public final class C {
/** A default size in bytes for an individual allocation that forms part of a larger buffer. */ /** A default size in bytes for an individual allocation that forms part of a larger buffer. */
public static final int DEFAULT_BUFFER_SEGMENT_SIZE = 64 * 1024; public static final int DEFAULT_BUFFER_SEGMENT_SIZE = 64 * 1024;
/** A default size in bytes for a video buffer. */
public static final int DEFAULT_VIDEO_BUFFER_SIZE = 200 * DEFAULT_BUFFER_SEGMENT_SIZE;
/** A default size in bytes for an audio buffer. */
public static final int DEFAULT_AUDIO_BUFFER_SIZE = 54 * DEFAULT_BUFFER_SEGMENT_SIZE;
/** A default size in bytes for a text buffer. */
public static final int DEFAULT_TEXT_BUFFER_SIZE = 2 * DEFAULT_BUFFER_SEGMENT_SIZE;
/** A default size in bytes for a metadata buffer. */
public static final int DEFAULT_METADATA_BUFFER_SIZE = 2 * DEFAULT_BUFFER_SEGMENT_SIZE;
/** A default size in bytes for a camera motion buffer. */
public static final int DEFAULT_CAMERA_MOTION_BUFFER_SIZE = 2 * DEFAULT_BUFFER_SEGMENT_SIZE;
/** A default size in bytes for a muxed buffer (e.g. containing video, audio and text). */
public static final int DEFAULT_MUXED_BUFFER_SIZE =
DEFAULT_VIDEO_BUFFER_SIZE + DEFAULT_AUDIO_BUFFER_SIZE + DEFAULT_TEXT_BUFFER_SIZE;
/** "cenc" scheme type name as defined in ISO/IEC 23001-7:2016. */ /** "cenc" scheme type name as defined in ISO/IEC 23001-7:2016. */
@SuppressWarnings("ConstantField") @SuppressWarnings("ConstantField")
public static final String CENC_TYPE_cenc = "cenc"; public static final String CENC_TYPE_cenc = "cenc";

View File

@ -67,6 +67,25 @@ public class DefaultLoadControl implements LoadControl {
/** The default for whether the back buffer is retained from the previous keyframe. */ /** The default for whether the back buffer is retained from the previous keyframe. */
public static final boolean DEFAULT_RETAIN_BACK_BUFFER_FROM_KEYFRAME = false; 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;
/** A default size in bytes for an audio buffer. */
public static final int DEFAULT_AUDIO_BUFFER_SIZE = 54 * 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;
/** A default size in bytes for a metadata buffer. */
public static final int DEFAULT_METADATA_BUFFER_SIZE = 2 * C.DEFAULT_BUFFER_SEGMENT_SIZE;
/** A default size in bytes for a camera motion buffer. */
public static final int DEFAULT_CAMERA_MOTION_BUFFER_SIZE = 2 * C.DEFAULT_BUFFER_SEGMENT_SIZE;
/** A default size in bytes for a muxed buffer (e.g. containing video, audio and text). */
public static final int DEFAULT_MUXED_BUFFER_SIZE =
DEFAULT_VIDEO_BUFFER_SIZE + DEFAULT_AUDIO_BUFFER_SIZE + DEFAULT_TEXT_BUFFER_SIZE;
/** Builder for {@link DefaultLoadControl}. */ /** Builder for {@link DefaultLoadControl}. */
public static final class Builder { public static final class Builder {
@ -404,7 +423,7 @@ public class DefaultLoadControl implements LoadControl {
int targetBufferSize = 0; int targetBufferSize = 0;
for (int i = 0; i < renderers.length; i++) { for (int i = 0; i < renderers.length; i++) {
if (trackSelectionArray.get(i) != null) { if (trackSelectionArray.get(i) != null) {
targetBufferSize += Util.getDefaultBufferSize(renderers[i].getTrackType()); targetBufferSize += getDefaultBufferSize(renderers[i].getTrackType());
} }
} }
return targetBufferSize; return targetBufferSize;
@ -418,6 +437,27 @@ public class DefaultLoadControl implements LoadControl {
} }
} }
private static int getDefaultBufferSize(int trackType) {
switch (trackType) {
case C.TRACK_TYPE_DEFAULT:
return DEFAULT_MUXED_BUFFER_SIZE;
case C.TRACK_TYPE_AUDIO:
return DEFAULT_AUDIO_BUFFER_SIZE;
case C.TRACK_TYPE_VIDEO:
return DEFAULT_VIDEO_BUFFER_SIZE;
case C.TRACK_TYPE_TEXT:
return DEFAULT_TEXT_BUFFER_SIZE;
case C.TRACK_TYPE_METADATA:
return DEFAULT_METADATA_BUFFER_SIZE;
case C.TRACK_TYPE_CAMERA_MOTION:
return DEFAULT_CAMERA_MOTION_BUFFER_SIZE;
case C.TRACK_TYPE_NONE:
return 0;
default:
throw new IllegalArgumentException();
}
}
private static boolean hasVideo(Renderer[] renderers, TrackSelectionArray trackSelectionArray) { private static boolean hasVideo(Renderer[] renderers, TrackSelectionArray trackSelectionArray) {
for (int i = 0; i < renderers.length; i++) { for (int i = 0; i < renderers.length; i++) {
if (renderers[i].getTrackType() == C.TRACK_TYPE_VIDEO && trackSelectionArray.get(i) != null) { if (renderers[i].getTrackType() == C.TRACK_TYPE_VIDEO && trackSelectionArray.get(i) != null) {

View File

@ -1545,35 +1545,6 @@ public final class Util {
: formatter.format("%02d:%02d", minutes, seconds).toString(); : formatter.format("%02d:%02d", minutes, seconds).toString();
} }
/**
* Maps a {@link C} {@code TRACK_TYPE_*} constant to the corresponding {@link C} {@code
* DEFAULT_*_BUFFER_SIZE} constant.
*
* @param trackType The track type.
* @return The corresponding default buffer size in bytes.
* @throws IllegalArgumentException If the track type is an unrecognized or custom track type.
*/
public static int getDefaultBufferSize(int trackType) {
switch (trackType) {
case C.TRACK_TYPE_DEFAULT:
return C.DEFAULT_MUXED_BUFFER_SIZE;
case C.TRACK_TYPE_AUDIO:
return C.DEFAULT_AUDIO_BUFFER_SIZE;
case C.TRACK_TYPE_VIDEO:
return C.DEFAULT_VIDEO_BUFFER_SIZE;
case C.TRACK_TYPE_TEXT:
return C.DEFAULT_TEXT_BUFFER_SIZE;
case C.TRACK_TYPE_METADATA:
return C.DEFAULT_METADATA_BUFFER_SIZE;
case C.TRACK_TYPE_CAMERA_MOTION:
return C.DEFAULT_CAMERA_MOTION_BUFFER_SIZE;
case C.TRACK_TYPE_NONE:
return 0;
default:
throw new IllegalArgumentException();
}
}
/** /**
* Escapes a string so that it's safe for use as a file or directory name on at least FAT32 * Escapes a string so that it's safe for use as a file or directory name on at least FAT32
* filesystems. FAT32 is the most restrictive of all filesystems still commonly used today. * filesystems. FAT32 is the most restrictive of all filesystems still commonly used today.