diff --git a/lib/dash/dash_parser.js b/lib/dash/dash_parser.js index f1d7d909f6..6e25741b5d 100644 --- a/lib/dash/dash_parser.js +++ b/lib/dash/dash_parser.js @@ -22,7 +22,6 @@ goog.require('shaka.text.TextEngine'); goog.require('shaka.util.CmcdManager'); goog.require('shaka.util.Error'); goog.require('shaka.util.Functional'); -goog.require('shaka.util.Iterables'); goog.require('shaka.util.LanguageUtils'); goog.require('shaka.util.ManifestParserUtils'); goog.require('shaka.util.MimeUtils'); @@ -104,7 +103,7 @@ shaka.dash.DashParser = class { /** * Period IDs seen in previous manifest. - * @private {!Array.} + * @private {!Array.} */ this.lastManifestUpdatePeriodIds_ = []; @@ -556,10 +555,8 @@ shaka.dash.DashParser = class { const periods = []; let prevEnd = 0; const periodNodes = XmlUtils.findChildren(mpd, 'Period'); - // This uses a for-loop rather than a for-of loop because this needs to look - // ahead to the next element. - const enumerate = (it) => shaka.util.Iterables.enumerate(it); - for (const {i, item: elem, next} of enumerate(periodNodes)) { + for (let i = 0; i < periodNodes.length; i++) { + const elem = periodNodes[i]; const start = /** @type {number} */ ( XmlUtils.parseAttr(elem, 'start', XmlUtils.parseDuration, prevEnd)); const periodId = elem.id; @@ -567,12 +564,13 @@ shaka.dash.DashParser = class { XmlUtils.parseAttr(elem, 'duration', XmlUtils.parseDuration); let periodDuration = null; - if (next) { + if (i + 1 < periodNodes.length) { + const nextPeriod = periodNodes[i + 1]; // "The difference between the start time of a Period and the start time // of the following Period is the duration of the media content // represented by this Period." const nextStart = - XmlUtils.parseAttr(next, 'start', XmlUtils.parseDuration); + XmlUtils.parseAttr(nextPeriod, 'start', XmlUtils.parseDuration); if (nextStart != null) { periodDuration = nextStart - start; } @@ -637,7 +635,7 @@ shaka.dash.DashParser = class { start: start, duration: periodDuration, node: elem, - isLastPeriod: periodDuration == null || !next, + isLastPeriod: periodDuration == null || (i + 1 == periodNodes.length), }; const period = this.parsePeriod_(context, baseUris, info); periods.push(period); @@ -647,12 +645,12 @@ shaka.dash.DashParser = class { } if (periodDuration == null) { - if (next) { + if (i + 1 < periodNodes.length) { // If the duration is still null and we aren't at the end, then we // will skip any remaining periods. shaka.log.warning( 'Skipping Period', i + 1, 'and any subsequent Periods:', 'Period', - i + 1, 'does not have a valid start time.', next); + i + 1, 'does not have a valid start time.', periodNodes[i + 1]); } // The duration is unknown, so the end is unknown. diff --git a/lib/dash/mpd_utils.js b/lib/dash/mpd_utils.js index c18200f338..f4f780e1b8 100644 --- a/lib/dash/mpd_utils.js +++ b/lib/dash/mpd_utils.js @@ -12,7 +12,6 @@ goog.require('shaka.net.NetworkingEngine'); goog.require('shaka.util.AbortableOperation'); goog.require('shaka.util.Error'); goog.require('shaka.util.Functional'); -goog.require('shaka.util.Iterables'); goog.require('shaka.util.ManifestParserUtils'); goog.require('shaka.util.XmlUtils'); goog.requireType('shaka.dash.DashParser'); @@ -142,8 +141,8 @@ shaka.dash.MpdUtils = class { const timeline = []; let lastEndTime = -unscaledPresentationTimeOffset; - const enumerate = (it) => shaka.util.Iterables.enumerate(it); - for (const {item: timePoint, next} of enumerate(timePoints)) { + for (let i = 0; i < timePoints.length; ++i) { + const timePoint = timePoints[i]; let t = XmlUtils.parseAttr(timePoint, 't', XmlUtils.parseNonNegativeInt); const d = XmlUtils.parseAttr(timePoint, 'd', XmlUtils.parseNonNegativeInt); @@ -165,9 +164,10 @@ shaka.dash.MpdUtils = class { let repeat = r || 0; if (repeat < 0) { - if (next) { - const nextStartTime = - XmlUtils.parseAttr(next, 't', XmlUtils.parseNonNegativeInt); + if (i + 1 < timePoints.length) { + const nextTimePoint = timePoints[i + 1]; + const nextStartTime = XmlUtils.parseAttr( + nextTimePoint, 't', XmlUtils.parseNonNegativeInt); if (nextStartTime == null) { shaka.log.warning( 'An "S" element cannot have a negative repeat', @@ -225,8 +225,7 @@ shaka.dash.MpdUtils = class { timeline[timeline.length - 1].end = startTime / timescale; } - for (const _ of shaka.util.Iterables.range(repeat + 1)) { - shaka.util.Functional.ignored(_); + for (let j = 0; j <= repeat; ++j) { const endTime = startTime + d; const item = { start: startTime / timescale, diff --git a/lib/dash/segment_template.js b/lib/dash/segment_template.js index f41c120936..d1d2142081 100644 --- a/lib/dash/segment_template.js +++ b/lib/dash/segment_template.js @@ -14,7 +14,6 @@ goog.require('shaka.media.InitSegmentReference'); goog.require('shaka.media.SegmentIndex'); goog.require('shaka.media.SegmentReference'); goog.require('shaka.util.Error'); -goog.require('shaka.util.Iterables'); goog.require('shaka.util.ManifestParserUtils'); goog.require('shaka.util.ObjectUtils'); goog.requireType('shaka.dash.DashParser'); @@ -504,8 +503,11 @@ shaka.dash.SegmentTemplate = class { /** @type {!Array.} */ const references = []; - const enum_ = (it) => shaka.util.Iterables.enumerate(it); - for (const {i, item: {start, unscaledStart, end}} of enum_(info.timeline)) { + for (let i = 0; i < info.timeline.length; i++) { + const start = info.timeline[i].start; + const unscaledStart = info.timeline[i].unscaledStart; + const end = info.timeline[i].end; + // Note: i = k - 1, where k indicates the k'th segment listed in the MPD. // (See section 5.3.9.5.3 of the DASH spec.) const segmentReplacement = i + info.startNumber; diff --git a/lib/util/string_utils.js b/lib/util/string_utils.js index c0539308bf..76f9f834ee 100644 --- a/lib/util/string_utils.js +++ b/lib/util/string_utils.js @@ -158,9 +158,8 @@ shaka.util.StringUtils = class { static toUTF16(str, littleEndian) { const result = new ArrayBuffer(str.length * 2); const view = new DataView(result); - const enumerate = (it) => shaka.util.Iterables.enumerate(it); - for (const {i, item} of enumerate(str)) { - const value = item.charCodeAt(0); + for (let i = 0; i < str.length; ++i) { + const value = str.charCodeAt(i); view.setUint16(/* position= */ i * 2, value, littleEndian); } return result; diff --git a/lib/util/uint8array_utils.js b/lib/util/uint8array_utils.js index 903203daae..0ddcdd1a43 100644 --- a/lib/util/uint8array_utils.js +++ b/lib/util/uint8array_utils.js @@ -74,9 +74,8 @@ shaka.util.Uint8ArrayUtils = class { // byte. const bytes = window.atob(str.replace(/-/g, '+').replace(/_/g, '/')); const result = new Uint8Array(bytes.length); - const enumerate = (it) => shaka.util.Iterables.enumerate(it); - for (const {i, item} of enumerate(bytes)) { - result[i] = item.charCodeAt(0); + for (let i = 0; i < bytes.length; ++i) { + result[i] = bytes.charCodeAt(i); } return result; }