Skip to content

Commit

Permalink
Merge pull request video-dev#3704 from video-dev/bugfix/seek-to-end-s…
Browse files Browse the repository at this point in the history
…tall

Improve end-of-stream handling
  • Loading branch information
robwalch authored Mar 31, 2021
2 parents d734f2c + 4a3b11b commit 324cac1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
26 changes: 14 additions & 12 deletions src/controller/buffer-controller.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 324cac1

Please sign in to comment.