Skip to content

Commit

Permalink
Merge pull request #3567 from video-dev/bugfix/fraghint-discontinuity…
Browse files Browse the repository at this point in the history
…-side-effect

Fix issue that causes DISCONTINUITY values to be reassigned incorrectly
  • Loading branch information
robwalch committed Mar 5, 2021
2 parents 8f0fffd + 588d496 commit f3e2e99
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
9 changes: 7 additions & 2 deletions src/controller/level-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,12 @@ export function mergeDetails(
oldDetails,
newDetails,
(oldFrag: Fragment, newFrag: Fragment) => {
ccOffset = oldFrag.cc - newFrag.cc;
if (oldFrag.relurl) {
// Do not compare CC if the old fragment has no url. This is a level.fragmentHint used by LL-HLS parts.
// It maybe be off by 1 if it was created before any parts or discontinuity tags were appended to the end
// of the playlist.
ccOffset = oldFrag.cc - newFrag.cc;
}
if (
Number.isFinite(oldFrag.startPTS) &&
Number.isFinite(oldFrag.endPTS)
Expand Down Expand Up @@ -228,7 +233,7 @@ export function mergeDetails(

const newFragments = newDetails.fragments;
if (ccOffset) {
logger.log('discontinuity sliding from playlist, take drift into account');
logger.warn('discontinuity sliding from playlist, take drift into account');
for (let i = 0; i < newFragments.length; i++) {
newFragments[i].cc += ccOffset;
}
Expand Down
9 changes: 6 additions & 3 deletions src/loader/m3u8-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,12 @@ export default class M3U8Parser {
if (prevFrag && !prevFrag.relurl) {
fragments.pop();
totalduration -= prevFrag.duration;
level.fragmentHint = prevFrag;
} else {
if (level.partList) {
level.fragmentHint = prevFrag;
}
} else if (level.partList) {
assignProgramDateTime(frag, prevFrag);
frag.cc = discontinuityCounter;
level.fragmentHint = frag;
}
const fragmentLength = fragments.length;
Expand Down Expand Up @@ -528,7 +531,7 @@ export default class M3U8Parser {
level.endSN = 0;
level.startCC = 0;
}
if (level.partList) {
if (level.fragmentHint) {
totalduration += level.fragmentHint.duration;
}
level.totalduration = totalduration;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/discontinuities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function alignDiscontinuities(
lastLevel.details,
details
);
if (referenceFrag?.start) {
if (referenceFrag && Number.isFinite(referenceFrag.start)) {
logger.log(
`Adjusting PTS using last level due to CC increase within current level ${details.url}`
);
Expand Down

0 comments on commit f3e2e99

Please sign in to comment.