Skip to content

Commit

Permalink
Eagerly match segments without tolerance offset
Browse files Browse the repository at this point in the history
Fixes #4919
  • Loading branch information
robwalch committed Dec 7, 2022
1 parent 98464cf commit fd73057
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/controller/fragment-finders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ export function fragmentWithinToleranceTest(
maxFragLookUpTolerance = 0,
candidate: Fragment
) {
// eagerly accept an accurate match (no tolerance)
if (
candidate.start <= bufferEnd &&
candidate.start + candidate.duration > bufferEnd
) {
return 0;
}
// offset should be within fragment boundary - config.maxFragLookUpTolerance
// this is to cope with situations like
// bufferEnd = 9.991
Expand Down
29 changes: 27 additions & 2 deletions tests/unit/controller/fragment-finders.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('Fragment finders', function () {
{
deltaPTS: 0,
cc: 2,
duration: 0.033,
duration: 5,
start: 60.234398412698226,
sn: 12,
level: 0,
Expand Down Expand Up @@ -192,7 +192,7 @@ describe('Fragment finders', function () {
expect(actual).to.equal(-1);
});

it('does not skip very small fragments', function () {
it('does not skip very small fragments at the start', function () {
const frag = {
start: 0.2,
duration: 0.1,
Expand All @@ -201,6 +201,31 @@ describe('Fragment finders', function () {
const actual = fragmentWithinToleranceTest(0, tolerance, frag);
expect(actual).to.equal(0);
});
it('does not skip very small fragments', function () {
const frag = {
start: 5,
duration: 0.1,
deltaPTS: 0.1,
};
const actual = fragmentWithinToleranceTest(5, tolerance, frag);
expect(actual).to.equal(0);
});
it('does not skip very small fragments without deltaPTS', function () {
const frag = {
start: 5,
duration: 0.1,
};
const actual = fragmentWithinToleranceTest(5, tolerance, frag);
expect(actual).to.equal(0);
});
it('does not skip fragments when searching near boundaries', function () {
const frag = {
start: 19.96916,
duration: 9.98458,
};
const actual = fragmentWithinToleranceTest(29, 0.25, frag);
expect(actual).to.equal(0);
});
});

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

0 comments on commit fd73057

Please sign in to comment.