Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add liveSyncTargetLatency option and deprecate liveSyncMinLatency and liveSyncMaxLatency options #6822

Merged
merged 5 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions demo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,10 @@ shakaDemo.Config = class {
.addBoolInput_('Disable Video Prefetch',
'streaming.disableVideoPrefetch')
.addBoolInput_('Live Sync', 'streaming.liveSync')
.addNumberInput_('Target latency for live sync',
'streaming.liveSyncTargetLatency',
/* canBeDecimal= */ true,
/* canBeZero= */ true)
.addNumberInput_('Target latency tolerance',
'streaming.liveSyncTargetLatencyTolerance',
/* canBeDecimal= */ true,
Expand Down
3 changes: 3 additions & 0 deletions docs/tutorials/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ application:
`shaka.util.StringUtils.htmlUnescape` for this purpose.
- `streaming.useNativeHlsOnSafari` has removed. Now we have another config to do the same for FairPlay `streaming.useNativeHlsForFairPlay` or for HLS (any browser) `streaming.preferNativeHls`.
- `mediaSource.sourceBufferExtraFeatures` has been replaced with `mediaSource.addExtraFeaturesToSourceBuffer` callback.
- `streaming.liveSyncMinLatency` and `streaming.liveSyncMaxLatency` have
been removed in favor of `streaming.liveSyncTargetLatency`. (deprecated
in v4.10.0)

- Plugin changes:
- `TextDisplayer` plugins must implement the `configure()` method.
Expand Down
12 changes: 4 additions & 8 deletions externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1300,10 +1300,9 @@ shaka.extern.ManifestConfiguration;
* disableTextPrefetch: boolean,
* disableVideoPrefetch: boolean,
* liveSync: boolean,
* liveSyncTargetLatency: number,
* liveSyncTargetLatencyTolerance: number,
* liveSyncMaxLatency: number,
* liveSyncPlaybackRate: number,
* liveSyncMinLatency: number,
* liveSyncMinPlaybackRate: number,
* liveSyncPanicMode: boolean,
* liveSyncPanicThreshold: number,
Expand Down Expand Up @@ -1466,19 +1465,16 @@ shaka.extern.ManifestConfiguration;
* rate. Defaults to <code>false</code>.
* Note: on some SmartTVs, if this is activated, it may not work or the sound
* may be lost when activated.
* @property {number} liveSyncTargetLatency
* Preferred latency, in seconds. Effective only if liveSync is true.
* Defaults to <code>0.5</code>.
* @property {number} liveSyncTargetLatencyTolerance
* Latency tolerance for target latency, in seconds. Effective only if
* liveSync is true. Defaults to <code>0.5</code>.
* @property {number} liveSyncMaxLatency
* Maximum acceptable latency, in seconds. Effective only if liveSync is
* true. Defaults to <code>1</code>.
* @property {number} liveSyncPlaybackRate
* Playback rate used for latency chasing. It is recommended to use a value
* between 1 and 2. Effective only if liveSync is true. Defaults to
* <code>1.1</code>.
* @property {number} liveSyncMinLatency
* Minimum acceptable latency, in seconds. Effective only if liveSync is
* true. Defaults to <code>0</code>.
* @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
Expand Down
70 changes: 49 additions & 21 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -3646,6 +3646,37 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
'streaming.preferNativeHls instead.');
}

// map liveSyncMinLatency and liveSyncMaxLatency to liveSyncTargetLatency
// if liveSyncTargetLatency isn't set.
avelad marked this conversation as resolved.
Show resolved Hide resolved
if (config['streaming'] &&
!('liveSyncTargetLatency' in config['streaming']) &&
('liveSyncMinLatency' in config['streaming'] ||
'liveSyncMaxLatency' in config['streaming'])) {
const min = config['streaming']['liveSyncMinLatency'] || 0;
const max = config['streaming']['liveSyncMaxLatency'] || 1;
const mid = Math.abs(max - min) / 2;
config['streaming']['liveSyncTargetLatency'] = min + mid;
config['streaming']['liveSyncTargetLatencyTolerance'] = mid;
}
// Deprecate 'streaming.liveSyncMaxLatency' configuration.
if (config['streaming'] && 'liveSyncMaxLatency' in config['streaming']) {
shaka.Deprecate.deprecateFeature(5,
'streaming.liveSyncMaxLatency',
'Please Use streaming.liveSyncTargetLatency and ' +
'streaming.liveSyncTargetLatencyTolerance instead. ' +
'Or, set the values in your DASH manifest');
delete config['streaming']['liveSyncMaxLatency'];
avelad marked this conversation as resolved.
Show resolved Hide resolved
}
// Deprecate 'streaming.liveSyncMinLatency' configuration.
if (config['streaming'] && 'liveSyncMinLatency' in config['streaming']) {
shaka.Deprecate.deprecateFeature(5,
'streaming.liveSyncMinLatency',
'Please Use streaming.liveSyncTargetLatency and ' +
'streaming.liveSyncTargetLatencyTolerance instead. ' +
'Or, set the values in your DASH manifest');
delete config['streaming']['liveSyncMinLatency'];
avelad marked this conversation as resolved.
Show resolved Hide resolved
}

// Deprecate 'mediaSource.sourceBufferExtraFeatures' configuration.
if (config['mediaSource'] &&
'sourceBufferExtraFeatures' in config['mediaSource']) {
Expand Down Expand Up @@ -6321,44 +6352,41 @@ shaka.Player = class extends shaka.util.FakeEventTarget {

let liveSyncMaxLatency;
let liveSyncPlaybackRate;
let liveSyncMinLatency;
let liveSyncMinPlaybackRate;
const liveSyncTargetLatencyTolerance =
this.config_.streaming.liveSyncTargetLatencyTolerance;

if (this.config_.streaming.liveSync) {
liveSyncMaxLatency = this.config_.streaming.liveSyncMaxLatency;
const liveSyncTargetLatency =
this.config_.streaming.liveSyncTargetLatency;
liveSyncMaxLatency =
liveSyncTargetLatency + liveSyncTargetLatencyTolerance;
liveSyncMinLatency = Math.max(0,
liveSyncTargetLatency - liveSyncTargetLatencyTolerance);
liveSyncPlaybackRate = this.config_.streaming.liveSyncPlaybackRate;
liveSyncMinPlaybackRate = this.config_.streaming.liveSyncMinPlaybackRate;
} else {
// serviceDescription must override if it is defined in the MPD and
// liveSync configuration is not set.
if (this.manifest_ && this.manifest_.serviceDescription) {
liveSyncMaxLatency = this.config_.streaming.liveSyncMaxLatency;
if (this.manifest_.serviceDescription.targetLatency != null) {
liveSyncMaxLatency =
this.manifest_.serviceDescription.targetLatency +
this.config_.streaming.liveSyncTargetLatencyTolerance;
liveSyncTargetLatencyTolerance;
} else if (this.manifest_.serviceDescription.maxLatency != null) {
liveSyncMaxLatency = this.manifest_.serviceDescription.maxLatency;
}
liveSyncPlaybackRate =
this.manifest_.serviceDescription.maxPlaybackRate ||
this.config_.streaming.liveSyncPlaybackRate;
}
}

let liveSyncMinLatency;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is mostly to consolidate into a single if block for both.

let liveSyncMinPlaybackRate;
if (this.config_.streaming.liveSync) {
liveSyncMinLatency = this.config_.streaming.liveSyncMinLatency;
liveSyncMinPlaybackRate = this.config_.streaming.liveSyncMinPlaybackRate;
} else {
// serviceDescription must override if it is defined in the MPD and
// liveSync configuration is not set.
if (this.manifest_ && this.manifest_.serviceDescription) {
liveSyncMinLatency = this.config_.streaming.liveSyncMinLatency;
if (this.manifest_.serviceDescription.targetLatency != null) {
liveSyncMinLatency =
liveSyncMinLatency = Math.max(0,
this.manifest_.serviceDescription.targetLatency -
this.config_.streaming.liveSyncTargetLatencyTolerance;
liveSyncTargetLatencyTolerance);
} else if (this.manifest_.serviceDescription.minLatency != null) {
liveSyncMinLatency = this.manifest_.serviceDescription.minLatency;
}
liveSyncPlaybackRate =
this.manifest_.serviceDescription.maxPlaybackRate ||
this.config_.streaming.liveSyncPlaybackRate;
liveSyncMinPlaybackRate =
this.manifest_.serviceDescription.minPlaybackRate ||
this.config_.streaming.liveSyncMinPlaybackRate;
Expand Down
3 changes: 1 addition & 2 deletions lib/util/player_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,9 @@ shaka.util.PlayerConfiguration = class {
disableTextPrefetch: false,
disableVideoPrefetch: false,
liveSync: false,
liveSyncTargetLatency: 0.5,
liveSyncTargetLatencyTolerance: 0.5,
liveSyncMaxLatency: 1,
liveSyncPlaybackRate: 1.1,
liveSyncMinLatency: 0,
liveSyncMinPlaybackRate: 0.95,
liveSyncPanicMode: false,
liveSyncPanicThreshold: 60,
Expand Down
Loading