mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
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
This commit is contained in:
parent
0b78837f35
commit
6bd0ba887c
1 changed files with 8 additions and 5 deletions
|
|
@ -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;
|
||||||
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;
|
||||||
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();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue