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 31, 2021
1 parent d734f2c commit 1d03457
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/controller/buffer-controller.ts
Expand Up @@ -493,25 +493,27 @@ 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) {
const ended = this.getSourceBufferTypes().reduce((acc, type) => {
const sb = this.sourceBuffer[type];
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`);
}
}
return acc && !!(!sb || sb.ended);
}, true);

if (ended) {
this.blockBuffers(() => {
const { mediaSource } = this;
if (!mediaSource || mediaSource.readyState !== 'open') {
return;
}
// Allow this to throw and be caught by the enqueueing function
mediaSource.endOfStream();
});
}

const endStream = () => {
const { mediaSource } = this;
if (!mediaSource || mediaSource.readyState !== 'open') {
return;
}
// Allow this to throw and be caught by the enqueueing function
mediaSource.endOfStream();
};
this.blockBuffers(endStream);
}

protected onLevelUpdated(
Expand Down

0 comments on commit 1d03457

Please sign in to comment.