Skip to content

Commit

Permalink
feat(HLS): Add the update period for HLS manifest (#7498)
Browse files Browse the repository at this point in the history
Create the update period for hls parse

Close #7505
  • Loading branch information
Iragne authored Oct 25, 2024
1 parent b980f67 commit 7b38ca8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
4 changes: 3 additions & 1 deletion demo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ shakaDemo.Config = class {
.addBoolInput_('Disable closed caption detection',
'manifest.hls.disableClosedCaptionsDetection')
.addBoolInput_('Allow LL-HLS byterange optimization',
'manifest.hls.allowLowLatencyByteRangeOptimization');
'manifest.hls.allowLowLatencyByteRangeOptimization')
.addNumberInput_('override the Update time of the manifest',
'manifest.hls.updatePeriod');
}

/** @private */
Expand Down
19 changes: 14 additions & 5 deletions externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1179,10 +1179,10 @@ shaka.extern.xml.Node;
* <br>
* Defaults to <code>false</code>.
* @property {number} updatePeriod
* Override the minimumUpdatePeriod of the manifest. The value is in second
* if the value is greater than the minimumUpdatePeriod, it will update the
* manifest less frequently. if you update the value during for a dynamic
* manifest, it will directly trigger a new download of the manifest
* Override the minimumUpdatePeriod of the manifest. The value is in seconds.
* If the value is greater than the minimumUpdatePeriod, it will update the
* manifest less frequently. If you update the value during for a dynamic
* manifest, it will directly trigger a new download of the manifest.
* <br>
* Defaults to <code>-1</code>.
* @property {boolean} enableFastSwitching
Expand All @@ -1208,7 +1208,8 @@ shaka.extern.DashManifestConfiguration;
* ignoreManifestTimestampsInSegmentsMode: boolean,
* disableCodecGuessing: boolean,
* disableClosedCaptionsDetection: boolean,
* allowLowLatencyByteRangeOptimization: boolean
* allowLowLatencyByteRangeOptimization: boolean,
* updatePeriod: number
* }}
*
* @property {boolean} ignoreTextStreamFailures
Expand Down Expand Up @@ -1294,6 +1295,14 @@ shaka.extern.DashManifestConfiguration;
* https://www.akamai.com/blog/performance/-using-ll-hls-with-byte-range-addressing-to-achieve-interoperabi
* <br>
* Defaults to <code>true</code>.
* @property {number} updatePeriod
* Override the update period of the playlist. The value is in seconds.
* If the value is less than 0, the period will be determined based on the
* segment length. If the value is greater than 0, it will update the target
* duration. If you update the value during the live, it will directly
* trigger a new download of the manifest.
* <br>
* Defaults to <code>-1</code>.
* @exportDoc
*/
shaka.extern.HlsManifestConfiguration;
Expand Down
11 changes: 10 additions & 1 deletion lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ shaka.hls.HlsParser = class {
* @exportInterface
*/
configure(config, isPreloadFn) {
const needFireUpdate = this.playerInterface_ &&
config.hls.updatePeriod != this.config_.hls.updatePeriod &&
config.hls.updatePeriod >= 0;
this.config_ = config;
if (isPreloadFn) {
this.isPreloadFn_ = isPreloadFn;
Expand All @@ -301,6 +304,11 @@ shaka.hls.HlsParser = class {
if (this.contentSteeringManager_) {
this.contentSteeringManager_.configure(this.config_);
}

if (needFireUpdate && this.manifest_ &&
this.manifest_.presentationTimeline.isLive()) {
this.updatePlaylistTimer_.tickNow();
}
}

/**
Expand Down Expand Up @@ -4587,7 +4595,8 @@ shaka.hls.HlsParser = class {
if (this.isLive_()) {
const updateDuration = (endTime - startTime) / 1000.0;
this.averageUpdateDuration_.sample(1, updateDuration);
const delay = this.getUpdatePlaylistDelay_();
const delay = this.config_.hls.updatePeriod > 0 ?
this.config_.hls.updatePeriod : this.getUpdatePlaylistDelay_();
const finalDelay = Math.max(0,
delay - this.averageUpdateDuration_.getEstimate());
this.updatePlaylistTimer_.tickAfter(/* seconds= */ finalDelay);
Expand Down
1 change: 1 addition & 0 deletions lib/util/player_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ shaka.util.PlayerConfiguration = class {
ignoreManifestTimestampsInSegmentsMode: false,
disableCodecGuessing: false,
disableClosedCaptionsDetection: false,
updatePeriod: -1,
allowLowLatencyByteRangeOptimization: true,
},
mss: {
Expand Down

0 comments on commit 7b38ca8

Please sign in to comment.