Skip to content

Commit

Permalink
Eagerly match segments without tolerance offset (video-dev#5084)
Browse files Browse the repository at this point in the history
* Eagerly match segments without tolerance offset
Fixes video-dev#4919

* Maintain expected `fragPrevious` behavior
  • Loading branch information
robwalch authored Dec 8, 2022
1 parent fc72c94 commit 5428731
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/controller/fragment-finders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export function findFragmentByPTS(
fragments,
fragmentWithinToleranceTest.bind(null, bufferEnd, maxFragLookUpTolerance)
);
if (foundFragment) {
if (foundFragment && (foundFragment !== fragPrevious || !fragNext)) {
return foundFragment;
}
// If no match was found return the next fragment after fragPrevious, or null
Expand All @@ -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
27 changes: 26 additions & 1 deletion tests/unit/controller/fragment-finders.js
Original file line number Diff line number Diff line change
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 5428731

Please sign in to comment.