Commit 6bd0ba88 by olly Committed by Oliver Woodman

Allow more aggressive switching for HLS with independent segments

We currently switch without downloading overlapping segments, but
we do not actually switch more aggressively. This change fixes
this. Note there's an implicit assumption made that if one media
playlist declares independent segments, the others will too. This
is almost certainly true in practice, and if it's not the penalty
isn't too bad (the player may try and switch to a higher quality
variant one segment's worth of buffer too soon).

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=167120992
parent 0b78837f
...@@ -92,6 +92,7 @@ import java.util.List; ...@@ -92,6 +92,7 @@ import java.util.List;
private byte[] scratchSpace; private byte[] scratchSpace;
private IOException fatalError; private IOException fatalError;
private HlsUrl expectedPlaylistUrl; private HlsUrl expectedPlaylistUrl;
private boolean independentSegments;
private Uri encryptionKeyUri; private Uri encryptionKeyUri;
private byte[] encryptionKey; private byte[] encryptionKey;
...@@ -206,10 +207,11 @@ import java.util.List; ...@@ -206,10 +207,11 @@ import java.util.List;
int oldVariantIndex = previous == null ? C.INDEX_UNSET int oldVariantIndex = previous == null ? C.INDEX_UNSET
: trackGroup.indexOf(previous.trackFormat); : trackGroup.indexOf(previous.trackFormat);
expectedPlaylistUrl = null; expectedPlaylistUrl = null;
// Use start time of the previous chunk rather than its end time because switching format will // Unless segments are known to be independent, switching variant will require downloading
// require downloading overlapping segments. // overlapping segments. Hence we use the start time of the previous chunk rather than its end
long bufferedDurationUs = previous == null ? 0 // time for this case.
: Math.max(0, previous.startTimeUs - playbackPositionUs); long bufferedDurationUs = previous == null ? 0 : Math.max(0,
(independentSegments ? previous.endTimeUs : previous.startTimeUs) - playbackPositionUs);
// Select the variant. // Select the variant.
trackSelection.updateSelectedTrack(bufferedDurationUs); trackSelection.updateSelectedTrack(bufferedDurationUs);
...@@ -224,12 +226,13 @@ import java.util.List; ...@@ -224,12 +226,13 @@ import java.util.List;
return; return;
} }
HlsMediaPlaylist mediaPlaylist = playlistTracker.getPlaylistSnapshot(selectedUrl); HlsMediaPlaylist mediaPlaylist = playlistTracker.getPlaylistSnapshot(selectedUrl);
independentSegments = mediaPlaylist.hasIndependentSegmentsTag;
// Select the chunk. // Select the chunk.
int chunkMediaSequence; int chunkMediaSequence;
if (previous == null || switchingVariant) { if (previous == null || switchingVariant) {
long targetPositionUs = previous == null ? playbackPositionUs long targetPositionUs = previous == null ? playbackPositionUs
: mediaPlaylist.hasIndependentSegmentsTag ? previous.endTimeUs : previous.startTimeUs; : independentSegments ? previous.endTimeUs : previous.startTimeUs;
if (!mediaPlaylist.hasEndTag && targetPositionUs >= mediaPlaylist.getEndTimeUs()) { if (!mediaPlaylist.hasEndTag && targetPositionUs >= mediaPlaylist.getEndTimeUs()) {
// If the playlist is too old to contain the chunk, we need to refresh it. // If the playlist is too old to contain the chunk, we need to refresh it.
chunkMediaSequence = mediaPlaylist.mediaSequence + mediaPlaylist.segments.size(); chunkMediaSequence = mediaPlaylist.mediaSequence + mediaPlaylist.segments.size();
......
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