Skip to content

Commit eafbd98

Browse files
tykus160avelad
authored andcommitted
perf: Close media source only on audio/video updates (#8826)
1 parent ed222f5 commit eafbd98

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
@@ -1285,6 +1285,7 @@ shaka.media.StreamingEngine = class {
12851285
async onUpdate_(mediaState) {
12861286
this.destroyer_.ensureNotDestroyed();
12871287

1288+
const ContentType = shaka.util.ManifestParserUtils.ContentType;
12881289
const logPrefix = shaka.media.StreamingEngine.logPrefix_(mediaState);
12891290

12901291
// Sanity check.
@@ -1361,7 +1362,17 @@ shaka.media.StreamingEngine = class {
13611362
return;
13621363
}
13631364

1364-
const mediaStates = Array.from(this.mediaStates_.values());
1365+
if (mediaState.type === ContentType.TEXT) {
1366+
// MSE endOfStream() closes MediaSource, not TextEngine, so skip here.
1367+
return;
1368+
}
1369+
const mediaStates = [mediaState];
1370+
const otherType = mediaState.type === ContentType.AUDIO ?
1371+
ContentType.VIDEO : ContentType.AUDIO;
1372+
const otherMediaState = this.mediaStates_.get(otherType);
1373+
if (otherMediaState) {
1374+
mediaStates.push(otherMediaState);
1375+
}
13651376

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

0 commit comments

Comments
 (0)