-
Notifications
You must be signed in to change notification settings - Fork 425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: better time to first frame for live playlists #1105
Conversation
7477bd8
to
e0d34d4
Compare
@@ -293,13 +293,18 @@ export const playlistEnd = function(playlist, expired, useSafeLiveEnd, liveEdgeP | |||
|
|||
expired = expired || 0; | |||
|
|||
const endSequence = useSafeLiveEnd ? safeLiveIndex(playlist, liveEdgePadding) : playlist.segments.length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't really make sense to get a safe live index, based on how many seconds we want to start behind the playback head. Then get how many seconds that index starts at from behind the end of the playlist. We should instead get the timing information for the end of the playlist. Then subtract the live edge padding from that.
This was causing us to download 3/4 (but it could be any number really, especially for a fast connection.) segments before a frame of video would even be shown, because we were setting seekableEnd to an exact segment end point. We would then download a segment that should start -0.001s before the start of seekable end but when we append it the buffered region is actually +0.001s ahead of seekable end. Eventually playback-watcher would seek us into the buffered range.
This fix is better because:
- The spec stats that we should start 3 target durations behind live
- We will almost always start in the middle of a segment as targetDuration is almost never exact, preventing any rounding errors from stalling playback.
e0d34d4
to
b0adf1a
Compare
b0adf1a
to
3cc24ca
Compare
const getSegmentIndex = (i, playlist, currentTime = 0) => { | ||
const segments = playlist.segments; | ||
|
||
return (playlist.endList || currentTime === 0) ? i : segments.length - (i + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loop from the back of the playlist when looking for a live sync point, as we are much more likely to be closer to the end.
@@ -38,7 +44,8 @@ export const syncPointStrategies = [ | |||
currentTime = currentTime || 0; | |||
|
|||
for (let i = 0; i < segments.length; i++) { | |||
const segment = segments[i]; | |||
const segmentIndex = getSegmentIndex(i, playlist, currentTime); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since ProgramDateTime
is rare to see in VOD, the VOD strategy should be used more often for VOD, and, in theory, this code should not need to run very often for VOD (unless there's heavy rendition switching going on), we may be better off just always starting from the end, and keeping the code simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's that much code and we share this bit between the two loops. I think that we will end up with more code if we change this to looping backwards.
Codecov Report
@@ Coverage Diff @@
## main #1105 +/- ##
==========================================
- Coverage 86.08% 86.06% -0.02%
==========================================
Files 38 38
Lines 8931 8923 -8
Branches 2001 1998 -3
==========================================
- Hits 7688 7680 -8
Misses 1243 1243
Continue to review full report at Codecov.
|
I have to say I'm a bit leery of removing the |
So the reason I removed safeLiveIndex is because we only used it to get the index of a segment based on a period of time that we want to be behind. Then we use that index to calculate the duration at which that segment would start, which will put
With this code just start at the specific distance away from the current end of the playlist that we want to be.
|
assert.equal(playlistEnd, 148.5, 'playlist end at the last segment end'); | ||
} | ||
); | ||
QUnit.test('playlistEnd uses default live edge padding with useSafeLiveEnd true', function(assert) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new tests are here
The test code should be reviewed with whitespace differences turned off as I moved things around so that running all the playlist tests isn't so difficult. |
test/playlist.test.js
Outdated
|
||
QUnit.module('Playlist estimateSegmentRequestTime'); | ||
QUnit.test('playlistEnd uses given live edge padding with useSafeLiveEnd true', function(assert) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this test is included twice.
Does the following:
Fixes some off by 1 errors