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

fix(DASH): Fix transitions from 'dynamic' to 'static' #7029

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Changes from all 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
39 changes: 29 additions & 10 deletions lib/dash/dash_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ shaka.dash.DashParser = class {

/** @private {HTMLMediaElement} */
this.mediaElement_ = null;

/** @private {boolean} */
this.isTransitionFromDynamicToStatic_ = false;
}

/**
Expand Down Expand Up @@ -644,6 +647,11 @@ shaka.dash.DashParser = class {
}
const mpdType = mpd.attributes['type'] || 'static';

if (this.manifest_ && this.manifest_.presentationTimeline) {
this.isTransitionFromDynamicToStatic_ =
this.manifest_.presentationTimeline.isLive() && mpdType == 'static';
}

this.manifestPatchContext_.type = mpdType;

/** @type {!shaka.media.PresentationTimeline} */
Expand Down Expand Up @@ -730,7 +738,7 @@ shaka.dash.DashParser = class {
const duration = periodsAndDuration.duration;
const periods = periodsAndDuration.periods;

if (mpdType == 'static' ||
if ((mpdType == 'static' && !this.isTransitionFromDynamicToStatic_) ||
!periodsAndDuration.durationDerivedFromPeriods) {
// Ignore duration calculated from Period lengths if this is dynamic.
presentationTimeline.setDuration(duration || Infinity);
Expand All @@ -756,7 +764,7 @@ shaka.dash.DashParser = class {

// Use @maxSegmentDuration to override smaller, derived values.
presentationTimeline.notifyMaxSegmentDuration(maxSegmentDuration || 1);
if (goog.DEBUG) {
if (goog.DEBUG && !this.isTransitionFromDynamicToStatic_) {
presentationTimeline.assertIsValid();
}

Expand Down Expand Up @@ -1268,8 +1276,14 @@ shaka.dash.DashParser = class {
presentationDuration;
}

let seekRangeStart = 0;
if (this.manifest_ && this.manifest_.presentationTimeline &&
this.isTransitionFromDynamicToStatic_) {
seekRangeStart = this.manifest_.presentationTimeline.getSeekRangeStart();
}

const periods = [];
let prevEnd = 0;
let prevEnd = seekRangeStart;
const periodNodes = TXml.findChildren(mpd, 'Period');
for (let i = 0; i < periodNodes.length; i++) {
const elem = periodNodes[i];
Expand All @@ -1294,7 +1308,7 @@ shaka.dash.DashParser = class {
// "The Period extends until the Period.start of the next Period, or
// until the end of the Media Presentation in the case of the last
// Period."
periodDuration = presentationDuration - start;
periodDuration = presentationDuration - start + seekRangeStart;
}

const threshold =
Expand Down Expand Up @@ -1387,15 +1401,20 @@ shaka.dash.DashParser = class {
this.lastManifestUpdatePeriodIds_ = periods.map((el) => el.id);

if (presentationDuration != null) {
if (prevEnd != presentationDuration) {
shaka.log.warning(
'@mediaPresentationDuration does not match the total duration of ',
'all Periods.');
// Assume @mediaPresentationDuration is correct.
if (prevEnd != null) {
const threshold =
shaka.util.ManifestParserUtils.GAP_OVERLAP_TOLERANCE_SECONDS;
const diference = prevEnd - seekRangeStart - presentationDuration;
if (Math.abs(diference) > threshold) {
shaka.log.warning(
'@mediaPresentationDuration does not match the total duration ',
'of all Periods.');
// Assume @mediaPresentationDuration is correct.
}
}
return {
periods: periods,
duration: presentationDuration,
duration: presentationDuration + seekRangeStart,
durationDerivedFromPeriods: false,
};
} else {
Expand Down
Loading