-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: #4736 Calculate duration for periods without duration field #4746
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
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -215,10 +215,10 @@ function ManifestLoader(config) { | |
| settings.get().streaming.enableManifestDurationMismatchFix && | ||
| manifest.mediaPresentationDuration && | ||
| manifest.Period.length > 1) { | ||
| const sumPeriodDurations = manifest.Period.reduce((totalDuration, period) => totalDuration + period.duration, 0); | ||
| if (!isNaN(sumPeriodDurations) && manifest.mediaPresentationDuration > sumPeriodDurations) { | ||
| const safeDuration = _getSafeDuration(manifest.Period); | ||
| if (!isNaN(safeDuration) && manifest.mediaPresentationDuration > safeDuration) { | ||
| logger.warn('Media presentation duration greater than duration of all periods. Setting duration to total period duration'); | ||
| manifest.mediaPresentationDuration = sumPeriodDurations; | ||
| manifest.mediaPresentationDuration = safeDuration; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -267,6 +267,31 @@ function ManifestLoader(config) { | |
| } | ||
| } | ||
|
|
||
| function _getSegmentDuration(s) { | ||
| return (s.r ? s.d * (s.r + 1) : s.d); | ||
| } | ||
|
|
||
| function _getSafeDuration(periods) { | ||
| const sumPeriodDurations = periods.reduce((totalDuration, period) => totalDuration + period.duration, 0); | ||
| if (isNaN(sumPeriodDurations)) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be |
||
| return sumPeriodDurations; | ||
| } | ||
|
|
||
| const lastPeriod = periods[periods.length - 1]; | ||
| if (lastPeriod.duration) { | ||
| return lastPeriod.start + lastPeriod.duration; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a check to verify that |
||
| } | ||
|
|
||
| const segmentTemplate = lastPeriod.AdaptationSet.filter((set) => set.mimeType === 'video/mp4')[0].Representation[0].SegmentTemplate; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will cause an issue if there is no AdaptationSet with For instance, in this manifest the |
||
| const segments = segmentTemplate.SegmentTimeline.S; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we cover the case in which |
||
| if (Array.isArray(segments)){ | ||
| return lastPeriod.start + | ||
| segments.reduce((segmentsDuration, s) => segmentsDuration + _getSegmentDuration(s), 0) / segmentTemplate.timescale; | ||
| } else { | ||
| return lastPeriod.start + _getSegmentDuration(segments) / segmentTemplate.timescale; | ||
| } | ||
| } | ||
|
|
||
| instance = { | ||
| load: load, | ||
| reset: reset | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not cover the case of negative
rvalues, seeTimelineSegmentsGetter.iterateSegments