Skip to content

Commit

Permalink
Overwrite manifest mediaPresentationDuration if duration mismatch (#3971
Browse files Browse the repository at this point in the history
)

* Overwrite manifest mediaPresentationDuration attribute with the sum of all period durations if there is a mismatch between the two

* Created config option to disable automatically overwriting mediaPresentationDuration when there is a mismatch between it and the sum of all period durations in a multi-period manifest

* Changed type from number to boolean for settings flag

* Corrected settings type in typings file and added setting to example jsdoc
  • Loading branch information
alkerway committed Jul 15, 2022
1 parent b98673e commit 66501e1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ declare namespace dashjs {
applyServiceDescription?: boolean,
cacheInitSegments?: boolean,
eventControllerRefreshDelay?: number,
enableManifestDurationMismatchFix?: boolean,
capabilities?: {
filterUnsupportedEssentialProperties?: boolean,
useMediaCapabilitiesApi?: boolean
Expand Down
4 changes: 4 additions & 0 deletions src/core/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import Events from './events/Events';
* applyServiceDescription: true,
* applyProducerReferenceTime: true,
* eventControllerRefreshDelay: 100,
* enableManifestDurationMismatchFix: true,
* capabilities: {
* filterUnsupportedEssentialProperties: true,
* useMediaCapabilitiesApi: false
Expand Down Expand Up @@ -665,6 +666,8 @@ import Events from './events/Events';
* @property {boolean} [applyProducerReferenceTime=true]
* Set to true if dash.js should use the parameters defined in ProducerReferenceTime elements in combination with ServiceDescription elements.
* @property {number} [eventControllerRefreshDelay=100]
* For multi-period streams, overwrite the manifest mediaPresentationDuration attribute with the sum of period durations if the manifest mediaPresentationDuration is greater than the sum of period durations
* @property {boolean} [enableManifestDurationMismatchFix=true]
* Defines the delay in milliseconds between two consecutive checks for events to be fired.
* @property {module:Settings~Metrics} metrics Metric settings
* @property {module:Settings~LiveDelay} delay Live Delay settings
Expand Down Expand Up @@ -768,6 +771,7 @@ function Settings() {
applyServiceDescription: true,
applyProducerReferenceTime: true,
eventControllerRefreshDelay: 100,
enableManifestDurationMismatchFix: true,
capabilities: {
filterUnsupportedEssentialProperties: true,
useMediaCapabilitiesApi: false
Expand Down
15 changes: 15 additions & 0 deletions src/streaming/ManifestLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function ManifestLoader(config) {
config = config || {};
const context = this.context;
const debug = config.debug;
const settings = config.settings;
const eventBus = EventBus(context).getInstance();
const urlUtils = URLUtils(context).getInstance();

Expand Down Expand Up @@ -194,6 +195,20 @@ function ManifestLoader(config) {
logger.debug('BaseURI set by Location to: ' + baseUri);
}

// If there is a mismatch between the manifest's specified duration and the total duration of all periods,
// and the specified duration is greater than the total duration of all periods,
// overwrite the manifest's duration attribute. This is a patch for if a manifest is generated incorrectly.
if (settings &&
settings.get().streaming.enableManifestDurationMismatchFix &&
manifest.mediaPresentationDuration &&
manifest.Period_asArray.length > 1) {
const sumPeriodDurations = manifest.Period_asArray.reduce((totalDuration, period) => totalDuration + period.duration, 0);
if (manifest.mediaPresentationDuration > sumPeriodDurations) {
logger.warn('Media presentation duration greater than duration of all periods. Setting duration to total period duration');
manifest.mediaPresentationDuration = sumPeriodDurations;
}
}

manifest.baseUri = baseUri;
manifest.loadedTime = new Date();
xlinkController.resolveManifestOnLoad(manifest);
Expand Down

0 comments on commit 66501e1

Please sign in to comment.