Skip to content

Commit

Permalink
feat: Support frequent updates during streaming (shaka-project#3483)
Browse files Browse the repository at this point in the history
  • Loading branch information
Álvaro Velad Galván committed Jun 24, 2021
1 parent f9c289e commit 6e69bed
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions demo/common/message_ids.js
Expand Up @@ -235,6 +235,7 @@ shakaDemo.MessageIds = {
TRICK_PLAY_CONTROLS_WARNING: 'DEMO_TRICK_PLAY_CONTROLS_WARNING',
UI_LOCALE: 'DEMO_UI_LOCALE',
UPDATE_EXPIRATION_TIME: 'DEMO_UPDATE_EXPIRATION_TIME',
UPDATE_INTERVAL_SECONDS: 'DEMO_UPDATE_INTERVAL_SECONDS',
USE_NATIVE_HLS_SAFARI: 'DEMO_USE_NATIVE_HLS_SAFARI',
USE_PERSISTENT_LICENSES: 'DEMO_USE_PERSISTENT_LICENSES',
VIDEO_ROBUSTNESS: 'DEMO_VIDEO_ROBUSTNESS',
Expand Down
5 changes: 4 additions & 1 deletion demo/config.js
Expand Up @@ -359,7 +359,10 @@ shakaDemo.Config = class {
.addBoolInput_(MessageIds.FORCE_HTTPS,
'streaming.forceHTTPS')
.addBoolInput_(MessageIds.PREFER_NATIVE_HLS,
'streaming.preferNativeHls');
'streaming.preferNativeHls')
.addNumberInput_(MessageIds.UPDATE_INTERVAL_SECONDS,
'streaming.updateIntervalSeconds',
/* canBeDecimal= */ true);

if (!shakaDemoMain.getNativeControlsEnabled()) {
this.addBoolInput_(MessageIds.ALWAYS_STREAM_TEXT,
Expand Down
1 change: 1 addition & 0 deletions demo/locales/en.json
Expand Up @@ -208,6 +208,7 @@
"DEMO_UNSUPPORTED_NO_LICENSE_SUPPORT": "Your browser does not support offline licenses for the required key systems.",
"DEMO_UNSUPPORTED_NO_OFFLINE": "Your browser does not support offline storage.",
"DEMO_UPDATE_EXPIRATION_TIME": "Update expiration time",
"DEMO_UPDATE_INTERVAL_SECONDS": "Update interval seconds",
"DEMO_UPLYNK": "Verizon Digital Media Services",
"DEMO_USE_FULL_SEGMENTS_FOR_START_TIME": "Use Full Segments For Start Time",
"DEMO_USE_NATIVE_HLS_SAFARI": "Use native HLS on Safari",
Expand Down
4 changes: 4 additions & 0 deletions demo/locales/source.json
Expand Up @@ -839,6 +839,10 @@
"description": "The name of a configuration value.",
"message": "Update expiration time"
},
"DEMO_UPDATE_INTERVAL_SECONDS": {
"description": "The name of a configuration value.",
"message": "Update interval seconds"
},
"DEMO_UPLYNK": {
"description": "Text that describes an asset that comes from the Verizon Digital Media Services asset library.",
"message": "[PROPER_NAME:Verizon Digital Media Services]"
Expand Down
5 changes: 4 additions & 1 deletion externs/shaka/player.js
Expand Up @@ -789,7 +789,8 @@ shaka.extern.ManifestConfiguration;
* lowLatencyMode: boolean,
* autoLowLatencyMode: boolean,
* forceHTTPS: boolean,
* preferNativeHls: boolean
* preferNativeHls: boolean,
* updateIntervalSeconds: number
* }}
*
* @description
Expand Down Expand Up @@ -896,6 +897,8 @@ shaka.extern.ManifestConfiguration;
* If true, if the protocol is HTTP change it to HTTPs.
* @property {boolean} preferNativeHls
* If true, prefer native HLS playback when possible, regardless of platform.
* @property {number} updateIntervalSeconds
* The minimum number of seconds to see if the manifest has changes.
*
* @exportDoc
*/
Expand Down
12 changes: 6 additions & 6 deletions lib/media/streaming_engine.js
Expand Up @@ -1001,10 +1001,10 @@ shaka.media.StreamingEngine = class {
if (bufferedAhead >= scaledBufferingGoal) {
shaka.log.v2(logPrefix, 'buffering goal met');

// Do not try to predict the next update. Just poll twice every second.
// The playback rate can change at any time, so any prediction we make now
// could be terribly invalid soon.
return 0.5;
// Do not try to predict the next update. Just poll according to
// configuration (seconds). The playback rate can change at any time, so
// any prediction we make now could be terribly invalid soon.
return this.config_.updateIntervalSeconds / 2;
}

const bufferEnd =
Expand All @@ -1016,7 +1016,7 @@ shaka.media.StreamingEngine = class {
// In any case just try again... if the manifest is incomplete or is not
// being updated then we'll idle forever; otherwise, we'll end up getting
// a SegmentReference eventually.
return 1;
return this.config_.updateIntervalSeconds;
}

// Do not let any one stream get far ahead of any other.
Expand Down Expand Up @@ -1047,7 +1047,7 @@ shaka.media.StreamingEngine = class {
// For example, let video buffering catch up to audio buffering before
// fetching another audio segment.
shaka.log.v2(logPrefix, 'waiting for other streams to buffer');
return 1;
return this.config_.updateIntervalSeconds;
}

const p = this.fetchAndAppend_(mediaState, presentationTime, reference);
Expand Down
1 change: 1 addition & 0 deletions lib/util/player_configuration.js
Expand Up @@ -162,6 +162,7 @@ shaka.util.PlayerConfiguration = class {
autoLowLatencyMode: false,
forceHTTPS: false,
preferNativeHls: false,
updateIntervalSeconds: 1,
};

// Some browsers will stop earlier than others before a gap (e.g., Edge
Expand Down

0 comments on commit 6e69bed

Please sign in to comment.