Skip to content

Commit

Permalink
feat(HLS): Take into account the parsing time for manifest schedule u…
Browse files Browse the repository at this point in the history
…pdate (#5678)
  • Loading branch information
avelad committed Sep 25, 2023
1 parent 83b34a2 commit f7e33a3
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/hls/hls_parser.js
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

0 comments on commit f7e33a3

Please sign in to comment.