Skip to content

Commit

Permalink
Optimize processXlinks.
Browse files Browse the repository at this point in the history
- Only traverse children once.
- Avoid traversing into SegmentTimeline, which is usually large and
  won't contain xlinks.

Issue #1640

Backported to v2.4.x

Change-Id: I8a7a05d580740f9a9953b0a8aec89a06cc7e33f2
  • Loading branch information
TheModMaker authored and joeyparrish committed Nov 8, 2018
1 parent a6a03b1 commit a425754
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
22 changes: 10 additions & 12 deletions lib/dash/mpd_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ shaka.dash.MpdUtils.processXlinks =
return handled;
}

// Filter out any children that should be nulled.
let childOperations = [];
for (let i = 0; i < element.childNodes.length; i++) {
let child = element.childNodes[i];
if (child instanceof Element) {
Expand All @@ -622,21 +622,19 @@ shaka.dash.MpdUtils.processXlinks =
// be removed, as specified by the mpeg-dash rules for xlink.
element.removeChild(child);
i -= 1;
} else if (child.tagName != 'SegmentTimeline') {
// Don't recurse into a SegmentTimeline since xlink attributes aren't
// valid in there and looking at each segment can take a long time with
// larger manifests.

// Replace the child with its processed form.
childOperations.push(shaka.dash.MpdUtils.processXlinks(
/** @type {!Element} */ (child), retryParameters, failGracefully,
baseUri, networkingEngine, opt_linkDepth));
}
}
}

let childOperations = [];
for (let i = 0; i < element.childNodes.length; i++) {
let child = element.childNodes[i];
if (child.nodeType == Node.ELEMENT_NODE) {
// Replace the child with its processed form.
childOperations.push(shaka.dash.MpdUtils.processXlinks(
/** @type {!Element} */ (child), retryParameters, failGracefully,
baseUri, networkingEngine, opt_linkDepth));
}
}

return shaka.util.AbortableOperation.all(childOperations).chain(() => {
return element;
});
Expand Down
9 changes: 9 additions & 0 deletions test/dash/mpd_utils_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,15 @@ describe('MpdUtils', function() {
operation.finally(done);
});

it('ignores SegmentTimeline children', (done) => {
let baseXMLString = inBaseContainer(
'<SegmentTimeline>' +
' <ToReplace xlink:href="https://xlink1" ' +
' xlink:actuate="onRequest" />' +
'</SegmentTimeline>');
testSucceeds(baseXMLString, baseXMLString, 0, done);
});

function testSucceeds(
baseXMLString, desiredXMLString, desiredNetCalls, done) {
let desiredXML = parser.parseFromString(desiredXMLString, 'text/xml')
Expand Down

0 comments on commit a425754

Please sign in to comment.