videojs / http-streaming

HLS, DASH, and future HTTP streaming protocols library for video.js
https://videojs-http-streaming.netlify.app/
Other
2.53k stars 425 forks source link

fix: issues with live playback timing #1553

Closed alex-barstow closed 4 days ago

alex-barstow commented 1 week ago

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:

// segment duration of 5s
Initial range: 0 -> 1000
1st refresh: 5 -> 1005
2nd refresh: 10 -> 1010

But before playback starts, what we get now is this:

Initial range: 0 -> 1000
1st refresh: 0 -> 1000
2nd refresh: 0 -> 1000

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 and end 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

codecov[bot] commented 1 week ago

Codecov Report

Attention: Patch coverage is 94.44444% with 3 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@9f1c4ad). Learn more about missing BASE report. Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/playlist-controller.js 93.02% 3 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1553 +/- ## ======================================= Coverage ? 84.11% ======================================= Files ? 43 Lines ? 11646 Branches ? 2604 ======================================= Hits ? 9796 Misses ? 1850 Partials ? 0 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.


🚨 Try these New Features: