Skip to content

Commit 87f24e7

Browse files
author
Alvaro Velad
committed
fix(dash): Fix performance regression
1 parent 89409ce commit 87f24e7

File tree

5 files changed

+24
-25
lines changed

5 files changed

+24
-25
lines changed

lib/dash/dash_parser.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ goog.require('shaka.text.TextEngine');
2222
goog.require('shaka.util.CmcdManager');
2323
goog.require('shaka.util.Error');
2424
goog.require('shaka.util.Functional');
25-
goog.require('shaka.util.Iterables');
2625
goog.require('shaka.util.LanguageUtils');
2726
goog.require('shaka.util.ManifestParserUtils');
2827
goog.require('shaka.util.MimeUtils');
@@ -104,7 +103,7 @@ shaka.dash.DashParser = class {
104103

105104
/**
106105
* Period IDs seen in previous manifest.
107-
* @private {!Array.<number>}
106+
* @private {!Array.<string>}
108107
*/
109108
this.lastManifestUpdatePeriodIds_ = [];
110109

@@ -556,23 +555,22 @@ shaka.dash.DashParser = class {
556555
const periods = [];
557556
let prevEnd = 0;
558557
const periodNodes = XmlUtils.findChildren(mpd, 'Period');
559-
// This uses a for-loop rather than a for-of loop because this needs to look
560-
// ahead to the next element.
561-
const enumerate = (it) => shaka.util.Iterables.enumerate(it);
562-
for (const {i, item: elem, next} of enumerate(periodNodes)) {
558+
for (let i = 0; i < periodNodes.length; i++) {
559+
const elem = periodNodes[i];
563560
const start = /** @type {number} */ (
564561
XmlUtils.parseAttr(elem, 'start', XmlUtils.parseDuration, prevEnd));
565562
const periodId = elem.id;
566563
const givenDuration =
567564
XmlUtils.parseAttr(elem, 'duration', XmlUtils.parseDuration);
568565

569566
let periodDuration = null;
570-
if (next) {
567+
if (i + 1 < periodNodes.length) {
568+
const nextPeriod = periodNodes[i + 1];
571569
// "The difference between the start time of a Period and the start time
572570
// of the following Period is the duration of the media content
573571
// represented by this Period."
574572
const nextStart =
575-
XmlUtils.parseAttr(next, 'start', XmlUtils.parseDuration);
573+
XmlUtils.parseAttr(nextPeriod, 'start', XmlUtils.parseDuration);
576574
if (nextStart != null) {
577575
periodDuration = nextStart - start;
578576
}
@@ -637,7 +635,7 @@ shaka.dash.DashParser = class {
637635
start: start,
638636
duration: periodDuration,
639637
node: elem,
640-
isLastPeriod: periodDuration == null || !next,
638+
isLastPeriod: periodDuration == null || (i + 1 == periodNodes.length),
641639
};
642640
const period = this.parsePeriod_(context, baseUris, info);
643641
periods.push(period);
@@ -647,12 +645,12 @@ shaka.dash.DashParser = class {
647645
}
648646

649647
if (periodDuration == null) {
650-
if (next) {
648+
if (i + 1 < periodNodes.length) {
651649
// If the duration is still null and we aren't at the end, then we
652650
// will skip any remaining periods.
653651
shaka.log.warning(
654652
'Skipping Period', i + 1, 'and any subsequent Periods:', 'Period',
655-
i + 1, 'does not have a valid start time.', next);
653+
i + 1, 'does not have a valid start time.', periodNodes[i + 1]);
656654
}
657655

658656
// The duration is unknown, so the end is unknown.

lib/dash/mpd_utils.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ shaka.dash.MpdUtils = class {
142142
const timeline = [];
143143
let lastEndTime = -unscaledPresentationTimeOffset;
144144

145-
const enumerate = (it) => shaka.util.Iterables.enumerate(it);
146-
for (const {item: timePoint, next} of enumerate(timePoints)) {
145+
for (let i = 0; i < timePoints.length; ++i) {
146+
const timePoint = timePoints[i];
147147
let t = XmlUtils.parseAttr(timePoint, 't', XmlUtils.parseNonNegativeInt);
148148
const d =
149149
XmlUtils.parseAttr(timePoint, 'd', XmlUtils.parseNonNegativeInt);
@@ -165,9 +165,10 @@ shaka.dash.MpdUtils = class {
165165

166166
let repeat = r || 0;
167167
if (repeat < 0) {
168-
if (next) {
169-
const nextStartTime =
170-
XmlUtils.parseAttr(next, 't', XmlUtils.parseNonNegativeInt);
168+
if (i + 1 < timePoints.length) {
169+
const nextTimePoint = timePoints[i + 1];
170+
const nextStartTime = XmlUtils.parseAttr(
171+
nextTimePoint, 't', XmlUtils.parseNonNegativeInt);
171172
if (nextStartTime == null) {
172173
shaka.log.warning(
173174
'An "S" element cannot have a negative repeat',

lib/dash/segment_template.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ goog.require('shaka.media.InitSegmentReference');
1414
goog.require('shaka.media.SegmentIndex');
1515
goog.require('shaka.media.SegmentReference');
1616
goog.require('shaka.util.Error');
17-
goog.require('shaka.util.Iterables');
1817
goog.require('shaka.util.ManifestParserUtils');
1918
goog.require('shaka.util.ObjectUtils');
2019
goog.requireType('shaka.dash.DashParser');
@@ -504,8 +503,11 @@ shaka.dash.SegmentTemplate = class {
504503

505504
/** @type {!Array.<!shaka.media.SegmentReference>} */
506505
const references = [];
507-
const enum_ = (it) => shaka.util.Iterables.enumerate(it);
508-
for (const {i, item: {start, unscaledStart, end}} of enum_(info.timeline)) {
506+
for (let i = 0; i < info.timeline.length; i++) {
507+
const start = info.timeline[i].start;
508+
const unscaledStart = info.timeline[i].unscaledStart;
509+
const end = info.timeline[i].end;
510+
509511
// Note: i = k - 1, where k indicates the k'th segment listed in the MPD.
510512
// (See section 5.3.9.5.3 of the DASH spec.)
511513
const segmentReplacement = i + info.startNumber;

lib/util/string_utils.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,8 @@ shaka.util.StringUtils = class {
158158
static toUTF16(str, littleEndian) {
159159
const result = new ArrayBuffer(str.length * 2);
160160
const view = new DataView(result);
161-
const enumerate = (it) => shaka.util.Iterables.enumerate(it);
162-
for (const {i, item} of enumerate(str)) {
163-
const value = item.charCodeAt(0);
161+
for (let i = 0; i < str.length; ++i) {
162+
const value = str.charCodeAt(i);
164163
view.setUint16(/* position= */ i * 2, value, littleEndian);
165164
}
166165
return result;

lib/util/uint8array_utils.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ shaka.util.Uint8ArrayUtils = class {
7474
// byte.
7575
const bytes = window.atob(str.replace(/-/g, '+').replace(/_/g, '/'));
7676
const result = new Uint8Array(bytes.length);
77-
const enumerate = (it) => shaka.util.Iterables.enumerate(it);
78-
for (const {i, item} of enumerate(bytes)) {
79-
result[i] = item.charCodeAt(0);
77+
for (let i = 0; i < bytes.length; ++i) {
78+
result[i] = bytes.charCodeAt(i);
8079
}
8180
return result;
8281
}

0 commit comments

Comments
 (0)