Skip to content

Commit

Permalink
Fix bug which causes multiperiod stream to stall after internal seek …
Browse files Browse the repository at this point in the history
…in previous period. Preloading not triggered again. (#4163)
  • Loading branch information
dsilhavy committed Mar 30, 2023
1 parent 389c145 commit 27017ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 10 additions & 3 deletions src/streaming/StreamProcessor.js
Expand Up @@ -285,6 +285,10 @@ function StreamProcessor(config) {
const hasBufferAtTargetTime = bufferController.hasBufferAtTime(e.seekTime);
if (hasBufferAtTargetTime) {
bufferController.pruneBuffer();
const continuousBufferTime = bufferController.getContinuousBufferTimeForTargetTime(e.seekTime);
if (_shouldSetBufferingComplete(continuousBufferTime)) {
bufferController.setIsBufferingCompleted(true);
}
resolve();
return;
}
Expand All @@ -306,7 +310,7 @@ function StreamProcessor(config) {
const continuousBufferTime = bufferController.getContinuousBufferTimeForTargetTime(e.seekTime);

// If the buffer is continuous and exceeds the duration of the period we are still done buffering. We need to trigger the buffering completed event in order to start prebuffering upcoming periods again
if (!isNaN(continuousBufferTime) && !isNaN(streamInfo.duration) && isFinite(streamInfo.duration) && continuousBufferTime >= streamInfo.start + streamInfo.duration) {
if (_shouldSetBufferingComplete(continuousBufferTime)) {
bufferController.setIsBufferingCompleted(true);
resolve();
} else {
Expand Down Expand Up @@ -342,6 +346,10 @@ function StreamProcessor(config) {
})
}

function _shouldSetBufferingComplete(continuousBufferTime) {
return !isNaN(continuousBufferTime) && !isNaN(streamInfo.duration) && isFinite(streamInfo.duration) && continuousBufferTime >= streamInfo.start + streamInfo.duration
}

/**
* Seek outside of the current period.
* @return {Promise<unknown>}
Expand Down Expand Up @@ -1022,8 +1030,7 @@ function StreamProcessor(config) {
const currentRepresentation = getRepresentationInfo(quality);
const voRepresentation = representationController && currentRepresentation ? representationController.getRepresentationForQuality(currentRepresentation.quality) : null;
if (currentRepresentation && voRepresentation) {
const timescale = boxParser.getMediaTimescaleFromMoov(bytes);
voRepresentation.timescale = timescale;
voRepresentation.timescale = boxParser.getMediaTimescaleFromMoov(bytes);
}
}

Expand Down
4 changes: 0 additions & 4 deletions src/streaming/controllers/BufferController.js
Expand Up @@ -1099,10 +1099,6 @@ function BufferController(config) {
}

function setIsBufferingCompleted(value) {
if (isBufferingCompleted === value) {
return;
}

isBufferingCompleted = value;

if (isBufferingCompleted) {
Expand Down

0 comments on commit 27017ac

Please sign in to comment.