Commit be103106 by Oliver Woodman

HLS: Better stream selection at start of playback.

- Correctly handle bandwidth NO_ESTIMATE case.
- Don't consider switching without a previous chunk.
parent 489e9915
...@@ -387,16 +387,24 @@ public class HlsChunkSource { ...@@ -387,16 +387,24 @@ public class HlsChunkSource {
private int getNextVariantIndex(TsChunk previousTsChunk, long playbackPositionUs) { private int getNextVariantIndex(TsChunk previousTsChunk, long playbackPositionUs) {
clearStaleBlacklistedPlaylists(); clearStaleBlacklistedPlaylists();
if (previousTsChunk == null) {
// Don't consider switching if we don't have a previous chunk.
return variantIndex;
}
long bitrateEstimate = bandwidthMeter.getBitrateEstimate();
if (bitrateEstimate == BandwidthMeter.NO_ESTIMATE) {
// Don't consider switching if we don't have a bandwidth estimate.
return variantIndex;
}
int idealVariantIndex = getVariantIndexForBandwdith( int idealVariantIndex = getVariantIndexForBandwdith(
(int) (bandwidthMeter.getBitrateEstimate() * BANDWIDTH_FRACTION)); (int) (bitrateEstimate * BANDWIDTH_FRACTION));
if (idealVariantIndex == variantIndex) { if (idealVariantIndex == variantIndex) {
// We're already using the ideal variant. // We're already using the ideal variant.
return variantIndex; return variantIndex;
} }
// We're not using the ideal variant for the available bandwidth, but only switch if the // We're not using the ideal variant for the available bandwidth, but only switch if the
// conditions are appropriate. // conditions are appropriate.
long bufferedPositionUs = previousTsChunk == null ? playbackPositionUs long bufferedPositionUs = adaptiveMode == ADAPTIVE_MODE_SPLICE ? previousTsChunk.startTimeUs
: adaptiveMode == ADAPTIVE_MODE_SPLICE ? previousTsChunk.startTimeUs
: previousTsChunk.endTimeUs; : previousTsChunk.endTimeUs;
long bufferedUs = bufferedPositionUs - playbackPositionUs; long bufferedUs = bufferedPositionUs - playbackPositionUs;
if (mediaPlaylistBlacklistTimesMs[variantIndex] != 0 if (mediaPlaylistBlacklistTimesMs[variantIndex] != 0
......
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