Skip to content

Commit

Permalink
fix: ignore buffered content less than 1e-4s (shaka-project#6802)
Browse files Browse the repository at this point in the history
On Firefox, in some cases after a period ends, seeking shortly after
will cause playback to fail or stall.
This occurs when the next period has small gaps and we're seeking to
after the gap. Seeking to before the gap succeeds. Even though the seek
requests the soure buffers to be fully cleared, Firefox actually keeps
around less than 1e-4s of content and won't let us forcibly remove this
content. Trying to call flush causes in infinite loop.
This leftover content makes shaka think that the buffer end in where we
used to be even though the presentation time reflects where we seeked
to. This means that playback doesn't continue. The buffer contitues
getting filled and playback will either fail when the SourcBuffer is
filled and triggers a QuotaExceededError or contiue when the buffer will
reach the presentationTime.
  • Loading branch information
gkatsev authored Jun 12, 2024
1 parent 95590ad commit d6fcf66
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions lib/media/time_ranges_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ goog.provide('shaka.media.TimeRangesUtils');
* @summary A set of utility functions for dealing with TimeRanges objects.
*/
shaka.media.TimeRangesUtils = class {
/**
* Returns whether the buffer is small enough to be ignored.
*
* @param {TimeRanges} b
* @return {boolean}
* @private
*/
static isBufferNegligible_(b) {
// Workaround Safari bug: https://bit.ly/2trx6O8
// Firefox may leave <1e-4s of data in buffer after clearing all content
return b.length == 1 && b.end(0) - b.start(0) < 1e-4;
}

/**
* Gets the first timestamp in the buffer.
*
Expand All @@ -22,8 +35,7 @@ shaka.media.TimeRangesUtils = class {
if (!b) {
return null;
}
// Workaround Safari bug: https://bit.ly/2trx6O8
if (b.length == 1 && b.end(0) - b.start(0) < 1e-6) {
if (shaka.media.TimeRangesUtils.isBufferNegligible_(b)) {
return null;
}
// Workaround Edge bug: https://bit.ly/2JYLPeB
Expand All @@ -45,8 +57,7 @@ shaka.media.TimeRangesUtils = class {
if (!b) {
return null;
}
// Workaround Safari bug: https://bit.ly/2trx6O8
if (b.length == 1 && b.end(0) - b.start(0) < 1e-6) {
if (shaka.media.TimeRangesUtils.isBufferNegligible_(b)) {
return null;
}
return b.length ? b.end(b.length - 1) : null;
Expand All @@ -64,8 +75,7 @@ shaka.media.TimeRangesUtils = class {
if (!b || !b.length) {
return false;
}
// Workaround Safari bug: https://bit.ly/2trx6O8
if (b.length == 1 && b.end(0) - b.start(0) < 1e-6) {
if (shaka.media.TimeRangesUtils.isBufferNegligible_(b)) {
return false;
}

Expand All @@ -92,8 +102,7 @@ shaka.media.TimeRangesUtils = class {
if (!b || !b.length) {
return 0;
}
// Workaround Safari bug: https://bit.ly/2trx6O8
if (b.length == 1 && b.end(0) - b.start(0) < 1e-6) {
if (shaka.media.TimeRangesUtils.isBufferNegligible_(b)) {
return 0;
}

Expand Down Expand Up @@ -128,8 +137,7 @@ shaka.media.TimeRangesUtils = class {
if (!b || !b.length) {
return null;
}
// Workaround Safari bug: https://bit.ly/2trx6O8
if (b.length == 1 && b.end(0) - b.start(0) < 1e-6) {
if (shaka.media.TimeRangesUtils.isBufferNegligible_(b)) {
return null;
}

Expand Down

0 comments on commit d6fcf66

Please sign in to comment.