Skip to content

Commit

Permalink
Improve end-of-stream handling in Firefox and Safari with multi-track…
Browse files Browse the repository at this point in the history
… streams
  • Loading branch information
Rob Walch committed Mar 30, 2021
1 parent d734f2c commit f261ac8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/controller/buffer-controller.ts
Expand Up @@ -493,15 +493,17 @@ export default class BufferController implements ComponentAPI {
// on BUFFER_EOS mark matching sourcebuffer(s) as ended and trigger checkEos()
// an undefined data.type will mark all buffers as EOS.
protected onBufferEos(event: Events.BUFFER_EOS, data: BufferEOSData) {
for (const type in this.sourceBuffer) {
let ended = true;
this.getSourceBufferTypes().forEach((type) => {
const sb = this.sourceBuffer[type as SourceBufferName];
if (!data.type || data.type === type) {
const sb = this.sourceBuffer[type as SourceBufferName];
if (sb && !sb.ended) {
sb.ended = true;
logger.log(`[buffer-controller]: ${type} sourceBuffer now EOS`);
}
}
}
ended = ended && !!(!sb || sb.ended);
});

const endStream = () => {
const { mediaSource } = this;
Expand All @@ -511,7 +513,9 @@ export default class BufferController implements ComponentAPI {
// Allow this to throw and be caught by the enqueueing function
mediaSource.endOfStream();
};
this.blockBuffers(endStream);
if (ended) {
this.blockBuffers(endStream);
}
}

protected onLevelUpdated(
Expand Down

0 comments on commit f261ac8

Please sign in to comment.