Skip to content

Commit

Permalink
Merge pull request #1311 from canalplus/fix/overlapping-first-period
Browse files Browse the repository at this point in the history
DASH: Fix Period overlap resolution logic for when the first Period is removed
  • Loading branch information
peaBerberian authored Nov 13, 2023
2 parents 491945b + ce57b34 commit d1fde0d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
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

0 comments on commit d1fde0d

Please sign in to comment.