-
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: Keep media update timeout alive so live playlists can recover #1176
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1176 +/- ##
==========================================
+ Coverage 86.51% 86.54% +0.03%
==========================================
Files 39 39
Lines 9602 9619 +17
Branches 2219 2222 +3
==========================================
+ Hits 8307 8325 +18
+ Misses 1295 1294 -1
Continue to review full report at Codecov.
|
const media = this.media(); | ||
|
||
if (shouldDelay) { | ||
const delay = media ? ((media.partTargetDuration || media.targetDuration) / 2) * 1000 : 5 * 1000; | ||
|
||
this.mediaUpdateTimeout = window.setTimeout(() => this.load(), delay); | ||
this.mediaUpdateTimeout = window.setTimeout(() => { |
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.
imo this should be called something else, but I think we should save it for the playlist-loader base class refactor as dash-playlist-loader does the same thing.
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.
Haven't tested yet but changes make sense to me.
src/master-playlist-controller.js
Outdated
@@ -67,7 +67,7 @@ const shouldSwitchToMedia = function({ | |||
// This is because in LIVE, the player plays 3 segments from the end of the | |||
// playlist, and if `BUFFER_LOW_WATER_LINE` is greater than the duration availble | |||
// in those segments, a viewer will never experience a rendition upswitch. | |||
if (!currentPlaylist || !currentPlaylist.endList) { | |||
if (!currentPlaylist) { | |||
log(`${sharedLogLine} as current playlist ` + (!currentPlaylist ? 'is not set' : 'is live')); |
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.
Per the comment above, will this mean that we should have a way of ignoring the low water for live in the rest of this function?
And we may need to update this line and the comment above
@@ -619,6 +613,8 @@ export default class PlaylistLoader extends EventTarget { | |||
return; | |||
} | |||
|
|||
this.updateMediaUpdateTimeout_(refreshDelay(playlist, true)); |
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.
May be worth a comment above here saying why we update the timeout even if it's switching to the active playlist
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.
added
endList = false; | ||
currentTime = 100; | ||
currentPlaylistBandwidth = 1000; | ||
nextPlaylistBandwidth = 1001; | ||
buffered = []; | ||
this.masterPlaylistController.mainSegmentLoader_.trigger('bandwidthupdate'); | ||
assert.equal( | ||
mediaChanges.length, | ||
1, | ||
'changes live media when no buffer and higher bandwidth playlist' | ||
); | ||
buffered = [[0, 100], [100, 109]]; | ||
this.masterPlaylistController.mainSegmentLoader_.trigger('bandwidthupdate'); | ||
assert.equal( | ||
mediaChanges.length, | ||
2, | ||
'changes live media when insufficient forward buffer and higher ' + | ||
'bandwidth playlist' | ||
); | ||
buffered = [[0, 100], [100, 130]]; | ||
this.masterPlaylistController.mainSegmentLoader_.trigger('bandwidthupdate'); | ||
assert.equal( | ||
mediaChanges.length, | ||
3, | ||
'changes live media when sufficient forward buffer and higher ' + | ||
'bandwidth playlist' | ||
); | ||
|
||
mediaChanges.length = 0; | ||
|
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.
Do we want to remove these tests?
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.
These only tested that live content always switches as far as I could tell. We might have to add one more back in depending on changes that I have to make in shouldSwitchToMedia.
@@ -351,7 +356,7 @@ export class MasterPlaylistController extends videojs.EventTarget { | |||
checkABR_() { | |||
const nextPlaylist = this.selectPlaylist(); | |||
|
|||
if (this.shouldSwitchToMedia_(nextPlaylist)) { | |||
if (nextPlaylist && this.shouldSwitchToMedia_(nextPlaylist)) { |
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.
minor fix here. I saw that we throw an error if nextPlaylist
is undefined.
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.
Can confirm that this fixes the issue of going offline and coming back!
Description
Right now for live hls streams we can be stuck buffering even though we should have recovered because we don't attempt to retry requests. You can reproduce this:
Unified Streaming Live HLS
This happens because we exclude and pause the current playlist loader when it fails a request. Then we switch to same playlist again and since it is the same playlist we don't try to request it again. So now we have no mediaUpdateTimeout and we did not request the playlist again.
The fix
media
true
inshouldSwitchToMedia
for live playlists if the playlist is the same. This gave us state we have now as we were relying on abr to refresh live playlists in some scenarios.