Skip to content

Commit

Permalink
Improve subtitle fragment finder for gaps in live playlists
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Walch committed May 29, 2021
1 parent 35bc1d7 commit 702447e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/controller/fragment-finders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ export function findFragmentByPTS(
let fragNext: Fragment | null = null;
if (fragPrevious) {
fragNext =
fragments[(fragPrevious.sn as number) - (fragments[0].sn as number) + 1];
fragments[
(fragPrevious.sn as number) - (fragments[0].sn as number) + 1
] || null;
} else if (bufferEnd === 0 && fragments[0].start === 0) {
fragNext = fragments[0];
}
Expand Down
19 changes: 11 additions & 8 deletions src/controller/subtitle-stream-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,17 @@ export class SubtitleStreamController
fragPrevious.endProgramDateTime,
maxFragLookUpTolerance
);
}
if (!foundFrag) {
foundFrag = findFragmentByPTS(
fragPrevious,
fragments,
targetBufferTime,
maxFragLookUpTolerance
);
if (!foundFrag) {
foundFrag = findFragmentByPTS(
fragPrevious,
fragments,
targetBufferTime,
maxFragLookUpTolerance
);
if (!foundFrag && fragPrevious.start < fragments[0].start) {
foundFrag = fragments[0];
}
}
}
} else {
foundFrag = fragments[fragLen - 1];
Expand Down
46 changes: 46 additions & 0 deletions tests/unit/controller/fragment-finders.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,52 @@ describe('Fragment finders', function () {
findFragmentByPTS(fragments[0], fragments, bufferEnd, tolerance);
expect(binarySearchSpy).to.have.been.calledOnce;
});

it('returns null when there is a gap in sn and start-end time', function () {
const bufferEnd = 49;
const fragments = [
{
deltaPTS: 0,
cc: 0,
duration: 5,
start: 54,
sn: 5,
level: 0,
},
{
deltaPTS: 0,
cc: 0,
duration: 5,
start: 59,
sn: 5,
level: 0,
},
{
deltaPTS: 0,
cc: 0,
duration: 5,
start: 64,
sn: 5,
level: 0,
},
];
// sn is not contiguous, and there is a gap between start and end
const fragPrevious = {
deltaPTS: 0,
cc: 0,
duration: 5,
start: 44,
sn: 1,
level: 0,
};
const actual = findFragmentByPTS(
fragPrevious,
fragments,
bufferEnd,
tolerance
);
expect(actual).to.equal(null);
});
});

describe('fragmentWithinToleranceTest', function () {
Expand Down

0 comments on commit 702447e

Please sign in to comment.