Skip to content

Commit

Permalink
feat: Improve performance of setStreamProperties on low-end devices (s…
Browse files Browse the repository at this point in the history
…haka-project#5380)

By reducing the number of promises in the Promises.all array we gain
performance on low-end devices.
  • Loading branch information
avelad committed Jun 29, 2023
1 parent 0e32256 commit ddbc249
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions lib/media/media_source_engine.js
Expand Up @@ -989,10 +989,12 @@ shaka.media.MediaSourceEngine = class {
this.textEngine_.setAppendWindow(appendWindowStart, appendWindowEnd);
return;
}
const operations = [];

const hasChangedCodecs =
await this.codecSwitchIfNecessary_(contentType, stream, streamsByType);

await Promise.all([
if (!hasChangedCodecs) {
// Queue an abort() to help MSE splice together overlapping segments.
// We set appendWindowEnd when we change periods in DASH content, and the
// period transition may result in overlap.
Expand All @@ -1001,17 +1003,21 @@ shaka.media.MediaSourceEngine = class {
// always enter a PARSING_MEDIA_SEGMENT state and we can't change the
// timestamp offset. By calling abort(), we reset the state so we can
// set it.
hasChangedCodecs ? Promise.resolve() : this.enqueueOperation_(
contentType,
() => this.abort_(contentType)),
ignoreTimestampOffset ? Promise.resolve() : this.enqueueOperation_(
operations.push(this.enqueueOperation_(
contentType,
() => this.setTimestampOffset_(contentType, timestampOffset)),
this.enqueueOperation_(
() => this.abort_(contentType)));
}
if (!ignoreTimestampOffset) {
operations.push(this.enqueueOperation_(
contentType,
() => this.setAppendWindow_(
contentType, appendWindowStart, appendWindowEnd)),
]);
() => this.setTimestampOffset_(contentType, timestampOffset)));
}
operations.push(this.enqueueOperation_(
contentType,
() => this.setAppendWindow_(
contentType, appendWindowStart, appendWindowEnd)));

await Promise.all(operations);
}

/**
Expand Down

0 comments on commit ddbc249

Please sign in to comment.