Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align live playlist updates to end of last when there is no overlap #6692

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/utils/discontinuities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function alignStream(
// Try to align on sn so that we pick a better start fragment.
// Do not perform this on playlists with delta updates as this is only to align levels on switch
// and adjustSliding only adjusts fragments after skippedSegments.
adjustSliding(switchDetails, details);
adjustSliding(switchDetails, details, false);
}
}

Expand Down
19 changes: 17 additions & 2 deletions src/utils/level-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,29 @@ export function mapFragmentIntersection(
export function adjustSliding(
oldDetails: LevelDetails,
newDetails: LevelDetails,
matchingStableVariantOrRendition: boolean = true,
): void {
const delta =
newDetails.startSN + newDetails.skippedSegments - oldDetails.startSN;
const oldFragments = oldDetails.fragments;
if (delta < 0 || delta >= oldFragments.length) {
const advancedOrStable = delta >= 0;
let sliding = 0;
if (advancedOrStable && delta < oldFragments.length) {
sliding = oldFragments[delta].start;
} else if (advancedOrStable && matchingStableVariantOrRendition) {
// align new start with old end (updated playlist start sequence is past end sequence of last update)
sliding = oldDetails.edge;
} else if (
!newDetails.skippedSegments &&
newDetails.fragments[0].start === 0
) {
// align new start with old (playlist switch has a sequence with no overlap and should not be used for alignment)
sliding = oldDetails.fragments[0].start;
} else {
// new details already has a sliding offset or has skipped segments
return;
}
addSliding(newDetails, oldFragments[delta].start);
addSliding(newDetails, sliding);
}

export function addSliding(details: LevelDetails, start: number) {
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/controller/level-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,20 @@ describe('LevelHelper Tests', function () {
expect(actual).to.deep.equal([10, 15, 20]);
});

it('does not apply sliding if no common segments exist', function () {
it('applies minimal sliding when no common segments exist', function () {
const oldPlaylist = generatePlaylist([1, 2, 3]);
const newPlaylist = generatePlaylist([5, 6, 7]);
adjustSliding(oldPlaylist, newPlaylist);
const actual = newPlaylist.fragments.map((f) => f.start);
expect(actual).to.deep.equal([0, 5, 10]);
expect(actual).to.deep.equal([15, 20, 25]);
});

it('does not apply sliding when segments meet but do not overlap', function () {
it('applies minimal sliding when segments meet but do not overlap', function () {
const oldPlaylist = generatePlaylist([1, 2, 3]);
const newPlaylist = generatePlaylist([4, 5, 6]);
adjustSliding(oldPlaylist, newPlaylist);
const actual = newPlaylist.fragments.map((f) => f.start);
expect(actual).to.deep.equal([0, 5, 10]);
expect(actual).to.deep.equal([15, 20, 25]);
});
});

Expand All @@ -164,23 +164,23 @@ describe('LevelHelper Tests', function () {
expect(actual).to.deep.equal([5, 10, 15, 20]);
});

it('does not change start times when there is no segment overlap', function () {
it('applies minimal sliding when there is no segment overlap', function () {
const oldPlaylist = generatePlaylist([1, 2, 3]);
const newPlaylist = generatePlaylist([5, 6, 7]);
mergeDetails(oldPlaylist, newPlaylist);
const actual = newPlaylist.fragments.map((f) => f.start);
expect(actual).to.deep.equal([0, 5, 10]);
expect(actual).to.deep.equal([15, 20, 25]);
});

it('does not extrapolate if the new playlist starts before the old', function () {
it('matches start when the new playlist starts before the old', function () {
const oldPlaylist = generatePlaylist([3, 4, 5]);
oldPlaylist.fragments.forEach((f) => {
f.start += 10;
});
const newPlaylist = generatePlaylist([1, 2, 3]);
mergeDetails(oldPlaylist, newPlaylist);
const actual = newPlaylist.fragments.map((f) => f.start);
expect(actual).to.deep.equal([0, 5, 10]);
expect(actual).to.deep.equal([10, 15, 20]);
});

it('merges delta playlist updates', function () {
Expand Down
Loading