-
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?
fix: #4736 Calculate duration for periods without duration field #4746
Conversation
|
||
function _getSafeDuration(periods) { | ||
const sumPeriodDurations = periods.reduce((totalDuration, period) => totalDuration + period.duration, 0); | ||
if (isNaN(sumPeriodDurations)) { |
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.
Should this be !sNaN(sumPeriodDurations)
to return the value in case it is not NaN
|
||
const lastPeriod = periods[periods.length - 1]; | ||
if (lastPeriod.duration) { | ||
return lastPeriod.start + lastPeriod.duration; |
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.
Add a check to verify that lastPeriod.start
is not undefined
or null
or NaN
return lastPeriod.start + lastPeriod.duration; | ||
} | ||
|
||
const segmentTemplate = lastPeriod.AdaptationSet.filter((set) => set.mimeType === 'video/mp4')[0].Representation[0].SegmentTemplate; |
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.
This will cause an issue if there is no AdaptationSet with mimeType
set to video/mp4
. Please add some checks if the attributes are accessible. Please also add a try...catch
statement in the function and return NaN
in the catch block.
For instance, in this manifest the mimeType
is on Representation
level: https://dash.akamaized.net/dash264/TestCases/5a/nomor/1.mpd
} | ||
|
||
const segmentTemplate = lastPeriod.AdaptationSet.filter((set) => set.mimeType === 'video/mp4')[0].Representation[0].SegmentTemplate; | ||
const segments = segmentTemplate.SegmentTimeline.S; |
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.
Can we cover the case in which SegmentTemplate
is used without SegmentTimeline
} | ||
|
||
function _getSegmentDuration(s) { | ||
return (s.r ? s.d * (s.r + 1) : s.d); |
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 r
values, see TimelineSegmentsGetter.iterateSegments
@KimmyWFox Did you have the chance to check my comments? |
This fixes issue #4736.
If the sum of periods is
NaN
, calculate the duration using segment information from the last period.