Skip to content

Commit b1579eb

Browse files
authored
perf: Close media source only on audio/video updates (#8826)
1 parent f512b3a commit b1579eb

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/media/streaming_engine.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,7 @@ shaka.media.StreamingEngine = class {
13121312
async onUpdate_(mediaState) {
13131313
this.destroyer_.ensureNotDestroyed();
13141314

1315+
const ContentType = shaka.util.ManifestParserUtils.ContentType;
13151316
const logPrefix = shaka.media.StreamingEngine.logPrefix_(mediaState);
13161317

13171318
// Sanity check.
@@ -1388,7 +1389,17 @@ shaka.media.StreamingEngine = class {
13881389
return;
13891390
}
13901391

1391-
const mediaStates = Array.from(this.mediaStates_.values());
1392+
if (mediaState.type === ContentType.TEXT) {
1393+
// MSE endOfStream() closes MediaSource, not TextEngine, so skip here.
1394+
return;
1395+
}
1396+
const mediaStates = [mediaState];
1397+
const otherType = mediaState.type === ContentType.AUDIO ?
1398+
ContentType.VIDEO : ContentType.AUDIO;
1399+
const otherMediaState = this.mediaStates_.get(otherType);
1400+
if (otherMediaState) {
1401+
mediaStates.push(otherMediaState);
1402+
}
13921403

13931404
// Check if we've buffered to the end of the presentation. We delay adding
13941405
// the audio and video media states, so it is possible for the text stream

0 commit comments

Comments
 (0)