Use peak rather than average bitrate for HLS

This is a minor change ahead of merging a full variant of
https://github.com/google/ExoPlayer/pull/6706, to make
re-buffers less likely.

Also remove variable substitution when parsing
AVERAGE-BANDWIDTH (it's not required for integer attributes)

PiperOrigin-RevId: 283554106
This commit is contained in:
olly 2019-12-03 16:51:43 +00:00 committed by bachinger
parent 21dd59badb
commit 14cfb8039f
3 changed files with 16 additions and 10 deletions

View File

@ -126,9 +126,11 @@
fragment) ([#6470](https://github.com/google/ExoPlayer/issues/6470)).
* DASH: Support negative @r values in segment timelines
([#1787](https://github.com/google/ExoPlayer/issues/1787)).
* HLS: Fix issue where streams could get stuck in an infinite buffering state
after a postroll ad
([#6314](https://github.com/google/ExoPlayer/issues/6314)).
* HLS:
* Use peak bitrate rather than average bitrate for adaptive track selection.
* Fix issue where streams could get stuck in an infinite buffering state
after a postroll ad
([#6314](https://github.com/google/ExoPlayer/issues/6314)).
* AV1 extension:
* New in this release. The AV1 extension allows use of the
[libgav1 software decoder](https://chromium.googlesource.com/codecs/libgav1/)

View File

@ -304,12 +304,8 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
} else if (line.startsWith(TAG_STREAM_INF)) {
noClosedCaptions |= line.contains(ATTR_CLOSED_CAPTIONS_NONE);
int bitrate = parseIntAttr(line, REGEX_BANDWIDTH);
String averageBandwidthString =
parseOptionalStringAttr(line, REGEX_AVERAGE_BANDWIDTH, variableDefinitions);
if (averageBandwidthString != null) {
// If available, the average bandwidth attribute is used as the variant's bitrate.
bitrate = Integer.parseInt(averageBandwidthString);
}
// TODO: Plumb this into Format.
int averageBitrate = parseOptionalIntAttr(line, REGEX_AVERAGE_BANDWIDTH, -1);
String codecs = parseOptionalStringAttr(line, REGEX_CODECS, variableDefinitions);
String resolutionString =
parseOptionalStringAttr(line, REGEX_RESOLUTION, variableDefinitions);
@ -869,6 +865,14 @@ public final class HlsPlaylistParser implements ParsingLoadable.Parser<HlsPlayli
return Integer.parseInt(parseStringAttr(line, pattern, Collections.emptyMap()));
}
private static int parseOptionalIntAttr(String line, Pattern pattern, int defaultValue) {
Matcher matcher = pattern.matcher(line);
if (matcher.find()) {
return Integer.parseInt(matcher.group(1));
}
return defaultValue;
}
private static long parseLongAttr(String line, Pattern pattern) throws ParserException {
return Long.parseLong(parseStringAttr(line, pattern, Collections.emptyMap()));
}

View File

@ -243,7 +243,7 @@ public class HlsMasterPlaylistParserTest {
List<HlsMasterPlaylist.Variant> variants = masterPlaylist.variants;
assertThat(variants.get(0).format.bitrate).isEqualTo(1280000);
assertThat(variants.get(1).format.bitrate).isEqualTo(1270000);
assertThat(variants.get(1).format.bitrate).isEqualTo(1280000);
}
@Test