Skip to content

Commit

Permalink
chore: Add backwards compatibility for useNativeHlsOnSafari (#6454)
Browse files Browse the repository at this point in the history
Backwards compatibility for
#6188
  • Loading branch information
avelad committed Apr 17, 2024
1 parent ef10f43 commit 7d723e3
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 7 deletions.
14 changes: 7 additions & 7 deletions demo/common/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -1474,9 +1474,6 @@ shakaAssets.testAssets = [
.addFeature(shakaAssets.Feature.LCEVC)
.addDescription('LCEVC Enhanced eSports content selection.')
.setExtraConfig({
mediaSource: {
forceTransmux: true,
},
lcevc: {
enabled: true,
dynamicPerformanceScaling: true,
Expand All @@ -1495,6 +1492,9 @@ shakaAssets.testAssets = [
.addFeature(shakaAssets.Feature.OFFLINE)
.addFeature(shakaAssets.Feature.LCEVC)
.setExtraConfig({
streaming: {
useNativeHlsOnSafari: false,
},
lcevc: {
enabled: true,
dynamicPerformanceScaling: true,
Expand All @@ -1513,8 +1513,8 @@ shakaAssets.testAssets = [
.addFeature(shakaAssets.Feature.OFFLINE)
.addFeature(shakaAssets.Feature.LCEVC)
.setExtraConfig({
mediaSource: {
forceTransmux: true,
streaming: {
useNativeHlsOnSafari: false,
},
lcevc: {
enabled: true,
Expand All @@ -1534,8 +1534,8 @@ shakaAssets.testAssets = [
.addFeature(shakaAssets.Feature.OFFLINE)
.addFeature(shakaAssets.Feature.LCEVC)
.setExtraConfig({
mediaSource: {
forceTransmux: true,
streaming: {
useNativeHlsOnSafari: false,
},
lcevc: {
enabled: true,
Expand Down
2 changes: 2 additions & 0 deletions demo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ shakaDemo.Config = class {
.addBoolInput_('Ignore Text Stream Failures',
'streaming.ignoreTextStreamFailures')
.addBoolInput_('Stall Detector Enabled', 'streaming.stallEnabled')
.addBoolInput_('Use native HLS on Safari (Clear)',
'streaming.useNativeHlsOnSafari')
.addBoolInput_('Use native HLS for FairPlay',
'streaming.useNativeHlsForFairPlay');
this.addRetrySection_('streaming', 'Streaming Retry Parameters');
Expand Down
6 changes: 6 additions & 0 deletions externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,7 @@ shaka.extern.ManifestConfiguration;
* stallEnabled: boolean,
* stallThreshold: number,
* stallSkip: number,
* useNativeHlsOnSafari: boolean,
* useNativeHlsForFairPlay: boolean,
* inaccurateManifestTolerance: number,
* lowLatencyMode: boolean,
Expand Down Expand Up @@ -1278,6 +1279,11 @@ shaka.extern.ManifestConfiguration;
* been detected. If 0, the player will pause and immediately play instead of
* seeking. A value of 0 is recommended and provided as default on TV
* platforms (WebOS, Tizen, Chromecast, etc).
* @property {boolean} useNativeHlsOnSafari
* Desktop Safari has both MediaSource and their native HLS implementation.
* Depending on the application's needs, it may prefer one over the other.
* Only applies to clear streams
* Defaults to <code>true</code>.
* @property {boolean} useNativeHlsForFairPlay
* Desktop Safari has both MediaSource and their native HLS implementation.
* Depending on the application's needs, it may prefer one over the other.
Expand Down
14 changes: 14 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -2040,6 +2040,12 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
this.config_.drm.servers['com.apple.fps.1_0'])) {
return this.config_.streaming.useNativeHlsForFairPlay;
}

// 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.
Expand Down Expand Up @@ -3274,6 +3280,14 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
delete config['streaming']['forceTransmux'];
}

// Deprecate 'streaming.useNativeHlsOnSafari' configuration.
if (config['streaming'] && 'useNativeHlsOnSafari' in config['streaming']) {
shaka.Deprecate.deprecateFeature(5,
'streaming.useNativeHlsOnSafari configuration',
'Please Use streaming.useNativeHlsForFairPlay or ' +
'streaming.preferNativeHls instead.');
}

// If lowLatencyMode is enabled, and inaccurateManifestTolerance and
// rebufferingGoal and segmentPrefetchLimit and baseDelay are not
// specified, set inaccurateManifestTolerance to 0 and rebufferingGoal
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 @@ -206,6 +206,7 @@ shaka.util.PlayerConfiguration = class {
stallEnabled: true,
stallThreshold: 1 /* seconds */,
stallSkip: 0.1 /* seconds */,
useNativeHlsOnSafari: true,
useNativeHlsForFairPlay: true,
// If we are within 2 seconds of the start of a live segment, fetch the
// previous one. This allows for segment drift, but won't download an
Expand Down
2 changes: 2 additions & 0 deletions test/hls/hls_parser_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ describe('HlsParser', () => {
player = new compiledShaka.Player();
await player.attach(video);

player.configure('streaming.useNativeHlsOnSafari', false);

// Disable stall detection, which can interfere with playback tests.
player.configure('streaming.stallEnabled', false);

Expand Down
4 changes: 4 additions & 0 deletions test/player_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ describe('Player', () => {
video.canPlayType.and.returnValue('maybe');
spyOn(shaka.util.Platform, 'anyMediaElement').and.returnValue(video);
spyOn(shaka.util.Platform, 'supportsMediaSource').and.returnValue(true);
spyOn(shaka.util.Platform, 'isApple').and.returnValue(false);
// Make sure player.load() resolves for src=
spyOn(shaka.util.MediaReadyState, 'waitForReadyState').and.callFake(
(mediaElement, readyState, eventManager, callback) => {
Expand All @@ -698,6 +699,7 @@ describe('Player', () => {
player.configure({
streaming: {
preferNativeHls: true,
useNativeHlsOnSafari: false,
},
});

Expand All @@ -709,10 +711,12 @@ describe('Player', () => {
it('does not apply to non-HLS streams', async () => {
video.canPlayType.and.returnValue('maybe');
spyOn(shaka.util.Platform, 'supportsMediaSource').and.returnValue(true);
spyOn(shaka.util.Platform, 'isApple').and.returnValue(false);

player.configure({
streaming: {
preferNativeHls: true,
useNativeHlsOnSafari: false,
},
});

Expand Down
1 change: 1 addition & 0 deletions test/transmuxer/transmuxer_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ describe('Transmuxer Player', () => {
await player.attach(video);

player.configure('mediaSource.forceTransmux', true);
player.configure('streaming.useNativeHlsOnSafari', false);

// Disable stall detection, which can interfere with playback tests.
player.configure('streaming.stallEnabled', false);
Expand Down

0 comments on commit 7d723e3

Please sign in to comment.