fix: issues with live playback timing #1553
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes 2 issues:
Issue 1:
If you wait to start playback of a sliding window livestream, playback will not start from the live edge. This is because the seekable range does not update correctly on playlist refreshes before playback starts. For a sliding window livestream, here's an example of how the seekable range should update on playlist refreshes:
But before playback starts, what we get now is this:
So when playback starts, we seek to 1000 thinking it is the seekable end, but that puts us behind the true seekable end of 1010.
This happens because before we fetch the first segment, what we do now is calculate the seekable end as the duration of the segments in the playlist without updating the base start time when segments expire off the start of the playlist.
Solution:
Calculate the seekable start and end using
MediaSequenceSync
start
andend
times, which are already accurately updated whenever a new playlist is loaded. By using these values that are already available we can bypass all the complexity of the current calculations.Issue 2:
Occasionally, when switching renditions, playback will not continue from the same place in the stream but will jump way back. This is caused by a race condition-- it is possible to switch to a new media playlist that has a Media Sequence value less than the current Media Sequence value, which presumably can result from delays on the media server updating playlists across renditions.
Solution:
If we switch to a media playlist with an older/lower mediaSequence value, we now calculate the base time by extrapolating backwards from a known segment start time rather than falling back to the currentTime.
Requirements Checklist