fix: ignore non-pes packets in the rollover stream #440
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The rollover stream expects data from the elementary stream.
The elementary stream can push forward two types of data
The rollover stream expects PTS/DTS info to be available since it stores the last DTS.
We should ignore non-PES packets since they may override lastDTS to undefined.
The last DTS is important to signal the next segments about rollover from the previous segments.
Let's review the following example:
we have segment-1 which is the first segment from a new timeline(disc):
with pts starting from 0
and “negative” dts (rolled back by dtsPtsOffset)
PTS = 0
DTS = 2^33 - dtsPtsOffset
we rollover values using the rollover stream:
PTS = 2^33
DTS = 2^33 - dtsPtsOffset or we can say that DTS = PTS - dtsPtsOffset
So we rolled over these values for each packet, and everything is fine, we report
timingInfos
andtransmuxed
data.since this is a new timeline (disc) we calculate timestmapOffset which will be:
timestampOffset = bufferedEnd - startPts
in our case it will be
timestampOffset = bufferedEnd - 2^33
so somewhere internally in the browser will un-pack transmuxed mp4 and read frames:
startTime = startPts + offset
which can be expanded to startTime = startPts + (bufferedEnd - startPts)
which can be simplified to the startTime = bufferedEnd
So everything is fine so far, but we start loading the next segment
Assume that:
PTS = last-packet-pts-of-the-last-segment + last-packet-duration-of-the-last-segment
DTS = PTS - dtsPtsOffset
so, for example:
our last packet rolled over values for segment-1:
PTS: 8590114770
DTS: 8590107264
if we convert it back to original values, it would be:
PTS = 8590114770 - 2^33 = 180178
DTS = 8590107264 - 2^33 = 172672
assuming the duration of the packet is 3840, segment-2 will have the following starting values:
PTS = 180178 + 3840 = 184018
DTS = 172672 + 3840 = 176512
so since the last DTS is undefined, we do not roll over PTS and DTS values for a second segment and all further segments of the same timeline.
so we report back
timingInfos
andtransmuxed
data.since it is the same timeline (no disc), we do not update timestampOffset
so we append data as is
next, when the browser calculates startTime it will use the previous offset, which was calculated based on rolled-over values.