Skip to content

Commit

Permalink
fix: Avoid rebuffering when using big trick play rates (#7988)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed Feb 5, 2025
1 parent 269b540 commit 1b778bb
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1368,12 +1368,17 @@ shaka.media.StreamingEngine = class {
return null;
}

// Update updateIntervalSeconds according to our current playbackrate,
// and always considering a minimum of 1.
const updateIntervalSeconds = this.config_.updateIntervalSeconds /
Math.max(1, Math.abs(this.playerInterface_.getPlaybackRate()));

if (!this.playerInterface_.mediaSourceEngine.isStreamingAllowed() &&
mediaState.type != ContentType.TEXT) {
// It is not allowed to add segments yet, so we schedule an update to
// check again later. So any prediction we make now could be terribly
// invalid soon.
return this.config_.updateIntervalSeconds / 2;
return updateIntervalSeconds / 2;
}

const logPrefix = shaka.media.StreamingEngine.logPrefix_(mediaState);
Expand Down Expand Up @@ -1445,9 +1450,8 @@ shaka.media.StreamingEngine = class {
shaka.log.v2(logPrefix, 'buffering goal met');

// Do not try to predict the next update. Just poll according to
// configuration (seconds). The playback rate can change at any time, so
// any prediction we make now could be terribly invalid soon.
return this.config_.updateIntervalSeconds / 2;
// configuration (seconds).
return updateIntervalSeconds / 2;
}

// Lack of segment iterator is the best indicator stream has changed.
Expand All @@ -1459,7 +1463,7 @@ shaka.media.StreamingEngine = class {
// In any case just try again... if the manifest is incomplete or is not
// being updated then we'll idle forever; otherwise, we'll end up getting
// a SegmentReference eventually.
return this.config_.updateIntervalSeconds;
return updateIntervalSeconds;
}
// Get media state adaptation and reset this value. By guarding it during
// actual stream change we ensure it won't be cleaned by accident on regular
Expand Down Expand Up @@ -1498,7 +1502,7 @@ shaka.media.StreamingEngine = class {
// For example, let video buffering catch up to audio buffering before
// fetching another audio segment.
shaka.log.v2(logPrefix, 'waiting for other streams to buffer');
return this.config_.updateIntervalSeconds;
return updateIntervalSeconds;
}

if (mediaState.segmentPrefetch && mediaState.segmentIterator &&
Expand Down

0 comments on commit 1b778bb

Please sign in to comment.