Skip to content

Commit

Permalink
WPE fix: Avoid pruning buffered ranges already enqueued for playback
Browse files Browse the repository at this point in the history
In WPE WebKit, the buffered range of the currentTime has high chances to
have been internally enqueued for playback (an action that can't be
undone, there's no way to unenqueue other than flushing the whole playback
pipeline). If that range is pruned, an internal flush is triggered, but
in order to keep playing from the currentTime onwards, the needed samples
must be enqueued again at least since the previous sync sample. This
can cause a lot of stress to the video decoder and generate stuttering.

This patch solves the problem by avoiding pruning (deleting) ranges
belonging to the same buffered range where the currentTime (or seek
target) is.
  • Loading branch information
eocanha committed Sep 8, 2022
1 parent 931ddf6 commit 8b603b4
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/streaming/controllers/BufferController.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,24 @@ function BufferController(config) {
if (currentTimeRequest) {
rangeStart = Math.max(currentTimeRequest.startTime + currentTimeRequest.duration, rangeStart);
}

// Never remove the contiguous range of targetTime in order to avoid flushes & reenqueues in WebKit based browsers
const ua = navigator.userAgent.toLowerCase();
if (/webkit/.test(ua) && !/chrome/.test(ua) && !/windows phone/.test(ua)) {
for (var i = 0; i < ranges.length; i++) {
if (ranges.start(i) <= targetTime && targetTime <= ranges.end(i)
&& ranges.start(i) <= rangeStart && rangeStart <= ranges.end(i)) {
let oldRangeStart = rangeStart;
if (i + 1 < ranges.length) {
rangeStart = ranges.start(i+1);
} else
rangeStart = ranges.end(i) + 1;
logger.debug("Buffered range [" + ranges.start(i) + ", " + ranges.end(i) + "] overlaps with targetTime " + targetTime + " and range to be pruned [" + oldRangeStart + ", " + endOfBuffer + "], using [" + rangeStart + ", " + endOfBuffer +"] instead");
break;
}
}
}

if (rangeStart < endOfBuffer) {
return {
start: rangeStart,
Expand Down

0 comments on commit 8b603b4

Please sign in to comment.