Skip to content

Commit

Permalink
feat(hls): Add config to prefer native HLS playback
Browse files Browse the repository at this point in the history
Closes shaka-project#3077

Change-Id: Ib49270c17656e50cd68806836d7b71ee8e0bc148
  • Loading branch information
joeyparrish committed Jan 9, 2021
1 parent 4ace439 commit 6c012aa
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions demo/common/message_ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ shakaDemo.MessageIds = {
NUMBER_NONZERO_INTEGER_WARNING: 'DEMO_NUMBER_NONZERO_INTEGER_WARNING',
OFFLINE_SECTION_HEADER: 'DEMO_OFFLINE_SECTION_HEADER',
PREFER_FORCED_SUBS: 'DEMO_PREFER_FORCED_SUBS',
PREFER_NATIVE_HLS: 'DEMO_PREFER_NATIVE_HLS',
REBUFFERING_GOAL: 'DEMO_REBUFFERING_GOAL',
RESTRICTIONS_SECTION_HEADER: 'DEMO_RESTRICTIONS_SECTION_HEADER',
SAFE_SEEK_OFFSET: 'DEMO_SAFE_SEEK_OFFSET',
Expand Down
4 changes: 3 additions & 1 deletion demo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,9 @@ shakaDemo.Config = class {
.addBoolInput_(MessageIds.AUTO_LOW_LATENCY,
'streaming.autoLowLatencyMode')
.addBoolInput_(MessageIds.FORCE_HTTPS,
'streaming.forceHTTPS');
'streaming.forceHTTPS')
.addBoolInput_(MessageIds.PREFER_NATIVE_HLS,
'streaming.preferNativeHls');

if (!shakaDemoMain.getNativeControlsEnabled()) {
this.addBoolInput_(MessageIds.ALWAYS_STREAM_TEXT,
Expand Down
1 change: 1 addition & 0 deletions demo/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"DEMO_PLAY": "Play",
"DEMO_PLAYREADY": "PlayReady DRM",
"DEMO_PREFER_FORCED_SUBS": "Prefer Forced Subs",
"DEMO_PREFER_NATIVE_HLS": "Prefer native HLS playback when available",
"DEMO_PROJECT_LINKS_HEADER": "PROJECT LINKS",
"DEMO_PROMPT_NO": "No",
"DEMO_PROMPT_YES": "Yes",
Expand Down
4 changes: 4 additions & 0 deletions demo/locales/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,10 @@
"description": "The name of a configuration value.",
"message": "Prefer Forced Subs"
},
"DEMO_PREFER_NATIVE_HLS": {
"description": "The name of a configuration value.",
"message": "Prefer native HLS playback when available"
},
"DEMO_PROJECT_LINKS_HEADER": {
"description": "A header for a section of the footer, that contains links to various project-related things.",
"message": "PROJECT LINKS"
Expand Down
5 changes: 4 additions & 1 deletion externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,8 @@ shaka.extern.ManifestConfiguration;
* inaccurateManifestTolerance: number,
* lowLatencyMode: boolean,
* autoLowLatencyMode: boolean,
* forceHTTPS: boolean
* forceHTTPS: boolean,
* preferNativeHls: boolean
* }}
*
* @description
Expand Down Expand Up @@ -831,6 +832,8 @@ shaka.extern.ManifestConfiguration;
* activate the lowLatencyMode. Defaults to false.
* @property {boolean} forceHTTPS
* 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.
*
* @exportDoc
*/
Expand Down
18 changes: 15 additions & 3 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1175,9 +1175,21 @@ shaka.Player = class extends shaka.util.FakeEventTarget {

// We would prefer MediaSource in some cases, and src= in others. For
// example, Android has native HLS, but we'd prefer our own MediaSource
// version there. For Safari, the choice is governed by the
// useNativeHlsOnSafari setting of the streaming config.
return Platform.isApple() && this.config_.streaming.useNativeHlsOnSafari;
// version there.

// Native HLS can be preferred on any platform via this flag:
if (this.config_.streaming.preferNativeHls) {
return true;
}

// For Safari, we have an older flag which only applies to this one
// browser:
if (Platform.isApple()) {
return this.config_.streaming.useNativeHlsOnSafari;
}

// In all other cases, we prefer MediaSource.
return false;
}

// Unless there are good reasons to use src= (single-file playback or native
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 @@ -137,6 +137,7 @@ shaka.util.PlayerConfiguration = class {
lowLatencyMode: false,
autoLowLatencyMode: false,
forceHTTPS: false,
preferNativeHls: false,
};

// WebOS, Tizen, and Chromecast have long hardware pipelines that respond
Expand Down

0 comments on commit 6c012aa

Please sign in to comment.