From 310e48f8cc2fe5ef4efac808716a93bfb9a2091d Mon Sep 17 00:00:00 2001 From: Jacob Trimble Date: Wed, 5 Jul 2017 16:53:38 -0700 Subject: [PATCH] Fix rounding issues with multi-Period content. Closes #882 Closes #909 Closes #911 Change-Id: Id31567137860b6bd683169b5b68ca83d6f14473d --- lib/dash/dash_parser.js | 5 ++++- lib/util/stream_utils.js | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/dash/dash_parser.js b/lib/dash/dash_parser.js index f21900ec9d..3ed1a90717 100644 --- a/lib/dash/dash_parser.js +++ b/lib/dash/dash_parser.js @@ -601,7 +601,10 @@ shaka.dash.DashParser.prototype.parsePeriods_ = function( periodDuration = presentationDuration - start; } - if (periodDuration && givenDuration && periodDuration != givenDuration) { + var threshold = + shaka.util.ManifestParserUtils.GAP_OVERLAP_TOLERANCE_SECONDS; + if (periodDuration && givenDuration && + Math.abs(periodDuration - givenDuration) > threshold) { shaka.log.warning('There is a gap/overlap between Periods', elem); } // Only use the @duration in the MPD if we can't calculate it. We should diff --git a/lib/util/stream_utils.js b/lib/util/stream_utils.js index b96da8dd19..d8efcfb366 100644 --- a/lib/util/stream_utils.js +++ b/lib/util/stream_utils.js @@ -575,9 +575,12 @@ shaka.util.StreamUtils.getFullMimeType = function(mimeType, opt_codecs) { * @return {number} */ shaka.util.StreamUtils.findPeriodContainingTime = function(manifest, time) { + var threshold = shaka.util.ManifestParserUtils.GAP_OVERLAP_TOLERANCE_SECONDS; for (var i = manifest.periods.length - 1; i > 0; --i) { var period = manifest.periods[i]; - if (time >= period.startTime) + // The last segment may end right before the end of the Period because of + // rounding issues. + if (time + threshold >= period.startTime) return i; } return 0;