Skip to content
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

feat(HLS): Take into account the parsing time for manifest schedule update #5678

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ goog.provide('shaka.hls.HlsParser');

goog.require('goog.Uri');
goog.require('goog.asserts');
goog.require('shaka.abr.Ewma');
goog.require('shaka.hls.ManifestTextParser');
goog.require('shaka.hls.Playlist');
goog.require('shaka.hls.PlaylistType');
Expand Down Expand Up @@ -215,6 +216,13 @@ shaka.hls.HlsParser = class {

/** @private {boolean} */
this.lowLatencyByterangeOptimization_ = false;

/**
* An ewma that tracks how long updates take.
* This is to mitigate issues caused by slow parsing on embedded devices.
* @private {!shaka.abr.Ewma}
*/
this.averageUpdateDuration_ = new shaka.abr.Ewma(5);
}


Expand Down Expand Up @@ -3679,12 +3687,20 @@ shaka.hls.HlsParser = class {
}

try {
const startTime = Date.now();
await this.update();

// Keep track of how long the longest manifest update took.
const endTime = Date.now();

// This may have converted to VOD, in which case we stop updating.
if (this.isLive_()) {
const updateDuration = (endTime - startTime) / 1000.0;
this.averageUpdateDuration_.sample(1, updateDuration);
const delay = this.getUpdatePlaylistDelay_();
this.updatePlaylistTimer_.tickAfter(/* seconds= */ delay);
const finalDelay = Math.max(0,
delay - this.averageUpdateDuration_.getEstimate());
this.updatePlaylistTimer_.tickAfter(/* seconds= */ finalDelay);
}
} catch (error) {
// Detect a call to stop() during this.update()
Expand Down