From 1c64e209097714e88956f4053d037dc7060813b9 Mon Sep 17 00:00:00 2001 From: Enson Choy Date: Wed, 25 Aug 2021 15:21:11 +0800 Subject: [PATCH] Fix: Discard only invalid overlapping periods Discard only invalid and/or overlapping periods to fulfil the requirements --- lib/dash/dash_parser.js | 14 ++++++++++++-- test/dash/dash_parser_manifest_unit.js | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/dash/dash_parser.js b/lib/dash/dash_parser.js index d1ed81fc05..5731631878 100644 --- a/lib/dash/dash_parser.js +++ b/lib/dash/dash_parser.js @@ -101,6 +101,12 @@ shaka.dash.DashParser = class { */ this.largestPeriodStartTime_ = null; + /** + * Period IDs that have seen before. + * @private {!Array.} + */ + this.seenPeriodIds_ = []; + /** * The minimum of the availabilityTimeOffset values among the adaptation * sets. @@ -581,11 +587,15 @@ shaka.dash.DashParser = class { // the last period in manifest if (this.largestPeriodStartTime_ !== null && start !== null && start < this.largestPeriodStartTime_ && + !this.seenPeriodIds_.includes(start) && i + 1 != periodNodes.length) { shaka.log.debug( - 'Skipping Period', i + 1, ' as its start time is smaller than ' + - 'the largest period start time that has been seen.'); + `Skipping Period ${i+1} as its start time is smaller than ` + + 'the largest period start time that has been seen, and start ' + + 'time is unseen before'); continue; + } else if (!this.seenPeriodIds_.includes(start)) { + this.seenPeriodIds_.push(start); } // Save maximum period start time if it is the last period diff --git a/test/dash/dash_parser_manifest_unit.js b/test/dash/dash_parser_manifest_unit.js index 2c9ca6f4bc..92ad5c52b7 100644 --- a/test/dash/dash_parser_manifest_unit.js +++ b/test/dash/dash_parser_manifest_unit.js @@ -2198,7 +2198,8 @@ describe('DashParser Manifest', () => { it('skip periods that are earlier than max period start time', async () => { const sources = [ buildManifestWithPeriodStartTime([5, 15]), - buildManifestWithPeriodStartTime([4, 15]), // simulate out-of-sync of -1s + buildManifestWithPeriodStartTime([6, 15]), // simulate out-of-sync of -1s + buildManifestWithPeriodStartTime([4, 15]), // simulate out-of-sync of +1s ]; const segments = [];