http-streaming icon indicating copy to clipboard operation
http-streaming copied to clipboard

For live video number of loaded segments is greater than in native implementations

Open sgrogov opened this issue 8 years ago • 2 comments

Description

While playing live videos http-streaming loads 4 instead of 3 segments on playback start. Could you please explain is it a bug or feature? And if it is feature so could you tell about reasons for that?

HLS spec says that it's safe to request 3 last segments of live video:

The server MUST NOT remove a Media Segment from a Playlist file without an EXT-X-ENDLIST tag if that would produce a Playlist whose duration is less than three times the target duration. Doing so can trigger playback stalls.

That's implemented here. But ceiling in this piece of code produces loading of one (or more in some cases) extra segment. Thereby getMediaInfoForTime returns mediaIndex which is lower by one than index produced by safeLiveIndex. That leads to loading of 4 segments instead of 3 needed.

Sources

Steps to reproduce

Play any live video which media playlist contains 10 segment items.

  1. Watch i returned by safeLiveIndex
  2. Watch i returned by getMediaInfoForTime
  3. Optionally check how many segments has been loaded

Results

Expected

  1. i equals to 7 (8th of 10)
  2. i equals to 7 (8th of 10)
  3. 4 segments have been loaded

Actual

  1. i equals to 7 (8th of 10)
  2. i equals to 6 (7th of 10)
  3. 3 segments have been loaded

Additional Information

videojs-http-streaming version

videojs-http-streaming 1.4.2

videojs version

video.js 7.0.4

Browsers

  • Chrome (and any other browser which does not support native HLS playback)

Platforms

  • Any

Other Plugins and Other JavaScript

  • This behaviour was found while debugging with this example page, only video source url was changed.

sgrogov avatar Nov 15 '18 11:11 sgrogov

👋 Thanks for opening your first issue here! 👋

If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can. To help make it easier for us to investigate your issue, please follow the contributing guidelines.

welcome[bot] avatar Nov 15 '18 11:11 welcome[bot]

Hey @sgrogov , while the spec allows for three segment playlists, it also mentions that when playing a live playlist, the segment chosen should be the end of the playlist - last segment duration - 2 * target duration:

If the EXT-X-ENDLIST tag is not present and the client intends to play the media normally, the client SHOULD NOT choose a segment that starts less than the duration of the last segment in the Playlist plus two target durations from the end of the Playlist file. Doing so can trigger playback stalls. https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-03#section-6.3.3

Since the target duration must be >= each segment's duration listed in the manifest, this means that we'll often have to choose the 4th segment from the end of the playlist. In addition, if right on the edge, it's safer to request the earlier segment, in case the segment's timing is off slightly.

Does this help explain the reasoning?

gesinger avatar Nov 30 '18 19:11 gesinger