videojs / http-streaming

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

fix(live): only reset playlist loader for LLHLS #1410

Closed adrums86 closed 1 year ago

adrums86 commented 1 year ago

Description

After a LOT of debugging with playlist changes against a linear DASH stream, I discovered we're calling resetLoader when setting a new playlist (during a rendition switch), which sets fetchAtBuffer_ to false then calls resyncLoader. This sets the mediaIndex to null, which eventually on the next chooseNextRequest_ call (which as implied, chooses the next segment to request) forces us into the else logic. Because fetchAtBuffer_ is false, we begin requesting segments from the currentTime rather than the end of the buffer. This causes the playback watcher to assume a segment download has stalled, because when we request segments at the currentTime we're either requesting cached segments or overwriting segments that were already buffered, which results in the buffer not changing and an increment of the stalled segment counter.

Specific Changes proposed

Since this logic was originally implemented as an fix for LLHLS playback (see: https://github.com/videojs/http-streaming/pull/1201) we can isolate it to LLHLS streams by checking for a partTargetDuration on the playlist, which is required for LLHLS streams, see: https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis#section-4.4.3.7. This greatly reduces the re-requesting of already buffered and cached segment requests during live playback and in turn the stability of these streams as the buffer isn't being artificially starved during a rendition switch.

Requirements Checklist

codecov[bot] commented 1 year ago

Codecov Report

Merging #1410 (84275c1) into main (2079454) will increase coverage by 0.00%. The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #1410   +/-   ##
=======================================
  Coverage   85.55%   85.56%           
=======================================
  Files          41       41           
  Lines       10145    10146    +1     
  Branches     2351     2352    +1     
=======================================
+ Hits         8680     8681    +1     
  Misses       1465     1465           
Files Changed Coverage Δ
src/segment-loader.js 96.48% <100.00%> (+<0.01%) :arrow_up:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more