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

DASH: Fix Period overlap resolution logic for when the first Period is removed #1311

Merged
merged 1 commit into from
Nov 13, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,24 @@ describe("flattenOverlappingPeriods", function() {
expect(mockLog).toHaveBeenCalledTimes(99);
mockLog.mockRestore();
});

// [ Period 1 ][ Period 2 ] ------> [ Period 3 ]
// [ Period 3 ]
it("should handle when a Period overlaps all previous periods", () => {
const mockLog = jest.spyOn(log, "warn").mockImplementation(jest.fn());

const periods = [
{ id: "1", start: 40, duration: 20, adaptations: {} },
{ id: "2", start: 60, duration: 20, adaptations: {} },
{ id: "3", start: 20, duration: 100, adaptations: {} },
];

const flattenPeriods = flattenOverlappingPeriods(periods);
expect(flattenPeriods.length).toBe(1);
expect(flattenPeriods[0].start).toBe(20);
expect(flattenPeriods[0].duration).toBe(100);
expect(flattenPeriods[0].id).toBe("3");
expect(mockLog).toHaveBeenCalledTimes(2);
mockLog.mockRestore();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ export default function flattenOverlappingPeriods(
// `lastFlattenedPeriod` has now a negative or `0` duration.
// Remove it, consider the next Period in its place, and re-start the loop.
flattenedPeriods.pop();
if (flattenedPeriods.length === 0) {
// There's no remaining Period to compare to `parsedPeriod`
break;
}
// Take the previous Period as reference and compare it now to `parsedPeriod`
lastFlattenedPeriod = flattenedPeriods[flattenedPeriods.length - 1];
}
}
Expand Down
Loading