Skip to content

Commit

Permalink
feat(DASH): Parse and use target latency
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed May 28, 2024
2 parents e7040dc + c541515 commit 0cc9f1b
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 14 deletions.
8 changes: 7 additions & 1 deletion demo/common/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -1492,7 +1492,13 @@ shakaAssets.testAssets = [
.addFeature(shakaAssets.Feature.DASH)
.addFeature(shakaAssets.Feature.HIGH_DEFINITION)
.addFeature(shakaAssets.Feature.MP4)
.addFeature(shakaAssets.Feature.LIVE),
.addFeature(shakaAssets.Feature.LIVE)
.addFeature(shakaAssets.Feature.LOW_LATENCY)
.setExtraConfig({
streaming: {
lowLatencyMode: true,
},
}),
// }}}

// EZDRM assets {{{
Expand Down
2 changes: 1 addition & 1 deletion externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,7 @@ shaka.extern.ManifestConfiguration;
* @property {number} liveSyncMinPlaybackRate
* Minimum playback rate used for latency chasing. It is recommended to use a
* value between 0 and 1. Effective only if liveSync is true. Defaults to
* <code>1</code>.
* <code>0.95</code>.
* @property {boolean} liveSyncPanicMode
* If <code>true</code>, panic mode for live sync is enabled. When enabled,
* will set the playback rate to the <code>liveSyncMinPlaybackRate</code>
Expand Down
12 changes: 6 additions & 6 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -6219,12 +6219,12 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
// liveSync configuration is not set.
if (this.manifest_ && this.manifest_.serviceDescription) {
liveSyncMaxLatency = this.config_.streaming.liveSyncMaxLatency;
if (this.manifest_.serviceDescription.maxLatency != null) {
liveSyncMaxLatency = this.manifest_.serviceDescription.maxLatency;
} else if (this.manifest_.serviceDescription.targetLatency != null) {
if (this.manifest_.serviceDescription.targetLatency != null) {
liveSyncMaxLatency =
this.manifest_.serviceDescription.targetLatency +
this.config_.streaming.liveSyncTargetLatencyTolerance;
} else if (this.manifest_.serviceDescription.maxLatency != null) {
liveSyncMaxLatency = this.manifest_.serviceDescription.maxLatency;
}
liveSyncPlaybackRate =
this.manifest_.serviceDescription.maxPlaybackRate ||
Expand All @@ -6242,12 +6242,12 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
// liveSync configuration is not set.
if (this.manifest_ && this.manifest_.serviceDescription) {
liveSyncMinLatency = this.config_.streaming.liveSyncMinLatency;
if (this.manifest_.serviceDescription.minLatency != null) {
liveSyncMinLatency = this.manifest_.serviceDescription.minLatency;
} else if (this.manifest_.serviceDescription.targetLatency != null) {
if (this.manifest_.serviceDescription.targetLatency != null) {
liveSyncMinLatency =
this.manifest_.serviceDescription.targetLatency -
this.config_.streaming.liveSyncTargetLatencyTolerance;
} else if (this.manifest_.serviceDescription.minLatency != null) {
liveSyncMinLatency = this.manifest_.serviceDescription.minLatency;
}
liveSyncMinPlaybackRate =
this.manifest_.serviceDescription.minPlaybackRate ||
Expand Down
22 changes: 20 additions & 2 deletions lib/util/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,24 @@ shaka.util.Platform = class {
return shaka.util.Platform.userAgentContains_('Tizen');
}

/**
* Check if the current platform is a Tizen 6 TV.
*
* @return {boolean}
*/
static isTizen6() {
return shaka.util.Platform.userAgentContains_('Tizen 6');
}

/**
* Check if the current platform is a Tizen 5 TV.
*
* @return {boolean}
*/
static isTizen5() {
return shaka.util.Platform.userAgentContains_('Tizen 5');
}

/**
* Check if the current platform is a Tizen 4 TV.
*
Expand Down Expand Up @@ -588,8 +606,8 @@ shaka.util.Platform = class {
*/
static supportsSmoothCodecSwitching() {
const Platform = shaka.util.Platform;
if (Platform.isTizen2() || Platform.isTizen3() ||
Platform.isTizen4() || Platform.isWebOS3() ||
if (Platform.isTizen2() || Platform.isTizen3() || Platform.isTizen4() ||
Platform.isTizen5() || Platform.isTizen6() || Platform.isWebOS3() ||
Platform.isWebOS4() || Platform.isWebOS5()) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/util/player_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ shaka.util.PlayerConfiguration = class {
liveSyncMaxLatency: 1,
liveSyncPlaybackRate: 1.1,
liveSyncMinLatency: 0,
liveSyncMinPlaybackRate: 1,
liveSyncMinPlaybackRate: 0.95,
liveSyncPanicMode: false,
liveSyncPanicThreshold: 60,
allowMediaSourceRecoveries: true,
Expand Down
48 changes: 45 additions & 3 deletions test/util/platform_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,57 @@
describe('Platform', () => {
const originalUserAgent = navigator.userAgent;

/* eslint-disable max-len */
// See: https://developer.samsung.com/smarttv/develop/guides/fundamentals/retrieving-platform-information.html
const tizen50 = 'Mozilla/5.0 (SMART-TV; LINUX; Tizen 5.0) AppleWebKit/537.36 (KHTML, like Gecko) Version/5.0 TV Safari/537.36';
const tizen55 = 'Mozilla/5.0 (SMART-TV; LINUX; Tizen 5.5) AppleWebKit/537.36 (KHTML, like Gecko) 69.0.3497.106.1/5.5 TV Safari/537.36';
const tizen60 = 'Mozilla/5.0 (SMART-TV; LINUX; Tizen 6.0) AppleWebKit/537.36 (KHTML, like Gecko) 76.0.3809.146/6.0 TV Safari/537.36';
const tizen65 = 'Mozilla/5.0 (SMART-TV; LINUX; Tizen 6.5) AppleWebKit/537.36 (KHTML, like Gecko) 85.0.4183.93/6.5 TV Safari/537.36';
const tizen70 = 'Mozilla/5.0 (SMART-TV; LINUX; Tizen 7.0) AppleWebKit/537.36 (KHTML, like Gecko) 94.0.4606.31/7.0 TV Safari/537.36';

// See: https://webostv.developer.lge.com/develop/specifications/web-api-and-web-engine#useragent-string
// eslint-disable-next-line max-len
const webOs3 = 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.2.1 Chrome/38.0.2125.122 Safari/537.36 WebAppManager';
// eslint-disable-next-line max-len
const webOs4 = 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.34 Safari/537.36 WebAppManager';
// eslint-disable-next-line max-len
const webOs5 = 'Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36 WebAppManager';
/* eslint-enable max-len */

afterEach(() => {
setUserAgent(originalUserAgent);
});

it('checks is Tizen 5', () => {
setUserAgent(webOs3);
expect(shaka.util.Platform.isTizen5()).toBe(false);
setUserAgent(tizen50);
expect(shaka.util.Platform.isTizen5()).toBe(true);
setUserAgent(tizen55);
expect(shaka.util.Platform.isTizen5()).toBe(true);
setUserAgent(tizen60);
expect(shaka.util.Platform.isTizen5()).toBe(false);
setUserAgent(tizen65);
expect(shaka.util.Platform.isTizen5()).toBe(false);
setUserAgent(tizen70);
expect(shaka.util.Platform.isTizen5()).toBe(false);
});

it('checks is Tizen 6', () => {
setUserAgent(webOs3);
expect(shaka.util.Platform.isTizen6()).toBe(false);
setUserAgent(tizen50);
expect(shaka.util.Platform.isTizen6()).toBe(false);
setUserAgent(tizen55);
expect(shaka.util.Platform.isTizen6()).toBe(false);
setUserAgent(tizen60);
expect(shaka.util.Platform.isTizen6()).toBe(true);
setUserAgent(tizen65);
expect(shaka.util.Platform.isTizen6()).toBe(true);
setUserAgent(tizen70);
expect(shaka.util.Platform.isTizen6()).toBe(false);
});

it('checks is webOS 3', () => {
setUserAgent(tizen50);
expect(shaka.util.Platform.isWebOS3()).toBe(false);
setUserAgent(webOs3);
expect(shaka.util.Platform.isWebOS3()).toBe(true);
setUserAgent(webOs4);
Expand All @@ -29,6 +67,8 @@ describe('Platform', () => {
});

it('checks is webOS 4', () => {
setUserAgent(tizen50);
expect(shaka.util.Platform.isWebOS4()).toBe(false);
setUserAgent(webOs3);
expect(shaka.util.Platform.isWebOS4()).toBe(false);
setUserAgent(webOs4);
Expand All @@ -38,6 +78,8 @@ describe('Platform', () => {
});

it('checks is webOS 5', () => {
setUserAgent(tizen50);
expect(shaka.util.Platform.isWebOS5()).toBe(false);
setUserAgent(webOs3);
expect(shaka.util.Platform.isWebOS5()).toBe(false);
setUserAgent(webOs4);
Expand Down

0 comments on commit 0cc9f1b

Please sign in to comment.