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(DASH): Add support for service descriptions #5394

Merged
merged 9 commits into from
Jul 5, 2023
24 changes: 24 additions & 0 deletions lib/dash/dash_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,29 @@ shaka.dash.DashParser = class {
this.updatePeriod_ = this.minTotalAvailabilityTimeOffset_;
}

const serviceDescriptionNode = XmlUtils.findChild(mpd,
'ServiceDescription');
const serviceDescription = {};

const latencyNode = XmlUtils.findChild(serviceDescriptionNode, 'Latency');
if (latencyNode) {
serviceDescription.latency = {
target: parseInt(latencyNode.getAttribute('target'), 10) / 1000,
max: parseInt(latencyNode.getAttribute('max'), 10) / 1000,
min: parseInt(latencyNode.getAttribute('min'), 10) / 1000,
referenceId: parseInt(latencyNode.getAttribute('referenceId'), 10),
};
}

const playbackRateNode = XmlUtils.findChild(serviceDescriptionNode,
'PlaybackRate');
if (playbackRateNode) {
serviceDescription.playbackRate = {
max: parseFloat(playbackRateNode.getAttribute('max'), 10),
min: parseFloat(playbackRateNode.getAttribute('min'), 10),
};
}

// These steps are not done on manifest update.
if (!this.manifest_) {
this.manifest_ = {
Expand All @@ -509,6 +532,7 @@ shaka.dash.DashParser = class {
sequenceMode: this.config_.dash.sequenceMode,
ignoreManifestTimestampsInSegmentsMode: false,
type: shaka.media.ManifestParser.DASH,
serviceDescription: serviceDescription,
};

// We only need to do clock sync when we're using presentation start
Expand Down
17 changes: 14 additions & 3 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -2278,7 +2278,8 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
'arbitrary language initially');
}

if (this.isLive() && this.config_.streaming.liveSync) {
if (this.isLive() && (this.config_.streaming.liveSync ||
this.manifest_.serviceDescription)) {
avelad marked this conversation as resolved.
Show resolved Hide resolved
const onTimeUpdate = () => this.onTimeUpdate_();
this.loadEventManager_.listen(mediaElement, 'timeupdate', onTimeUpdate);
}
Expand Down Expand Up @@ -5728,8 +5729,15 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
// Bad stream?
return;
}
const liveSyncMaxLatency = this.config_.streaming.liveSyncMaxLatency;
const liveSyncPlaybackRate = this.config_.streaming.liveSyncPlaybackRate;

// Should use serviceDescription if they exist.
const liveSyncMaxLatency = this.manifest_.serviceDescription.latency ?
avelad marked this conversation as resolved.
Show resolved Hide resolved
this.manifest_.serviceDescription.latency.max :
this.config_.streaming.liveSyncMaxLatency;
const liveSyncPlaybackRate =
this.manifest_.serviceDescription.playbackRate ?
this.manifest_.serviceDescription.playbackRate.max :
this.config_.streaming.liveSyncPlaybackRate;
const playbackRate = this.video_.playbackRate;
const latency = seekRange.end - this.video_.currentTime;
let offset = 0;
Expand All @@ -5747,6 +5755,9 @@ shaka.Player = class extends shaka.util.FakeEventTarget {

if ((latency - offset) > liveSyncMaxLatency) {
if (playbackRate != liveSyncPlaybackRate) {
shaka.log.debug('Latency (' + latency +
's) is greater than liveSyncMaxLatency. ' +
avelad marked this conversation as resolved.
Show resolved Hide resolved
'Updating playbackRate to ' + liveSyncPlaybackRate);
this.trickPlay(liveSyncPlaybackRate);
}
} else if (playbackRate !== 1 && playbackRate !== 0) {
Expand Down