Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(dash): improve readability and reduce number of loops in dash parser #5768

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 39 additions & 39 deletions lib/dash/dash_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -822,40 +822,29 @@ shaka.dash.DashParser = class {
}
}

const audioSets = this.config_.disableAudio ? [] :
this.getSetsOfType_(normalAdaptationSets, ContentType.AUDIO);
const videoSets = this.config_.disableVideo ? [] :
this.getSetsOfType_(normalAdaptationSets, ContentType.VIDEO);
const textSets = this.config_.disableText ? [] :
this.getSetsOfType_(normalAdaptationSets, ContentType.TEXT);
const imageSets = this.config_.disableThumbnails ? [] :
this.getSetsOfType_(normalAdaptationSets, ContentType.IMAGE);

if (!videoSets.length && !audioSets.length) {
const audioStreams = this.getStreamsFromSets_(
this.config_.disableAudio,
normalAdaptationSets,
ContentType.AUDIO);
const videoStreams = this.getStreamsFromSets_(
this.config_.disableVideo,
normalAdaptationSets,
ContentType.VIDEO);
const textStreams = this.getStreamsFromSets_(
this.config_.disableText,
normalAdaptationSets,
ContentType.TEXT);
const imageStreams = this.getStreamsFromSets_(
this.config_.disableThumbnails,
normalAdaptationSets,
ContentType.IMAGE);

if (videoStreams.length === 0 && audioStreams.length === 0) {
throw new shaka.util.Error(
shaka.util.Error.Severity.CRITICAL,
shaka.util.Error.Category.MANIFEST,
shaka.util.Error.Code.DASH_EMPTY_PERIOD);
}

const audioStreams = [];
for (const audioSet of audioSets) {
audioStreams.push(...audioSet.streams);
}

const videoStreams = [];
for (const videoSet of videoSets) {
videoStreams.push(...videoSet.streams);
}

const textStreams = [];
for (const textSet of textSets) {
textStreams.push(...textSet.streams);
}

const imageStreams = [];
for (const imageSet of imageSets) {
imageStreams.push(...imageSet.streams);
shaka.util.Error.Code.DASH_EMPTY_PERIOD,
);
}

return {
Expand All @@ -868,15 +857,26 @@ shaka.dash.DashParser = class {
}

/**
* Gets the streams from the given sets or returns an empty array if disabled
* or no streams are found.
* @param {boolean} disabled
* @param {!Array.<!shaka.dash.DashParser.AdaptationInfo>} adaptationSets
* @param {string} type
* @return {!Array.<!shaka.dash.DashParser.AdaptationInfo>}
* @private
*/
getSetsOfType_(adaptationSets, type) {
return adaptationSets.filter((as) => {
return as.contentType == type;
});
* @param {string} contentType
@private
*/
getStreamsFromSets_(disabled, adaptationSets, contentType) {
if (disabled || !adaptationSets.length) {
return [];
}

return adaptationSets.reduce((all, part) => {
if (part.contentType != contentType) {
return all;
}

all.push(...part.streams);
return all;
}, []);
}

/**
Expand Down