Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve end-of-stream handling #3704

Merged
merged 3 commits into from Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
22 changes: 11 additions & 11 deletions tests/functional/auto/setup.js
Expand Up @@ -267,17 +267,7 @@ async function testSeekOnVOD(url, config) {
logs: self.logString,
});
}
}, 3000);
self.setTimeout(function () {
const { currentTime, paused } = video;
callback({
code: 'timeout-waiting-for-ended-event',
currentTime,
duration,
paused,
logs: self.logString,
});
}, 10000);
}, 5000);
};
const seekToTime = video.seekable.end(0) - 3;
console.log(
Expand All @@ -287,6 +277,16 @@ async function testSeekOnVOD(url, config) {
seekToTime
);
video.currentTime = seekToTime;
self.setTimeout(function () {
const { currentTime, paused } = video;
callback({
code: 'timeout-waiting-for-ended-event',
currentTime,
duration,
paused,
logs: self.logString,
});
}, 12000);
}, 3000);
};
// Fail test early if more than 2 buffered ranges are found (with configured exceptions)
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/auto/testbench.js
Expand Up @@ -72,7 +72,7 @@ function objectAssign(target) {
) {
var nextKey = keysArray[nextIndex];
var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
if (desc?.enumerable) {
if (desc !== undefined && desc.enumerable) {
to[nextKey] = nextSource[nextKey];
}
}
Expand Down