Skip to content

Commit 6e171ec

Browse files
aveladjoeyparrish
authored andcommitted
fix: Avoid rebuffering when using big trick play rates (#7988)
Backported to v4.9.x
1 parent 4661d61 commit 6e171ec

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/media/streaming_engine.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,12 +1314,17 @@ shaka.media.StreamingEngine = class {
13141314
this.playerInterface_.mediaSourceEngine.clearSelectedClosedCaptionId();
13151315
}
13161316

1317+
// Update updateIntervalSeconds according to our current playbackrate,
1318+
// and always considering a minimum of 1.
1319+
const updateIntervalSeconds = this.config_.updateIntervalSeconds /
1320+
Math.max(1, Math.abs(this.playerInterface_.getPlaybackRate()));
1321+
13171322
if (!this.playerInterface_.mediaSourceEngine.isStreamingAllowed() &&
13181323
mediaState.type != ContentType.TEXT) {
13191324
// It is not allowed to add segments yet, so we schedule an update to
13201325
// check again later. So any prediction we make now could be terribly
13211326
// invalid soon.
1322-
return this.config_.updateIntervalSeconds / 2;
1327+
return updateIntervalSeconds / 2;
13231328
}
13241329

13251330
const logPrefix = shaka.media.StreamingEngine.logPrefix_(mediaState);
@@ -1393,9 +1398,8 @@ shaka.media.StreamingEngine = class {
13931398
shaka.log.v2(logPrefix, 'buffering goal met');
13941399

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

14011405
// Lack of segment iterator is the best indicator stream has changed.
@@ -1407,7 +1411,7 @@ shaka.media.StreamingEngine = class {
14071411
// In any case just try again... if the manifest is incomplete or is not
14081412
// being updated then we'll idle forever; otherwise, we'll end up getting
14091413
// a SegmentReference eventually.
1410-
return this.config_.updateIntervalSeconds;
1414+
return updateIntervalSeconds;
14111415
}
14121416
// Get media state adaptation and reset this value. By guarding it during
14131417
// actual stream change we ensure it won't be cleaned by accident on regular
@@ -1446,7 +1450,7 @@ shaka.media.StreamingEngine = class {
14461450
// For example, let video buffering catch up to audio buffering before
14471451
// fetching another audio segment.
14481452
shaka.log.v2(logPrefix, 'waiting for other streams to buffer');
1449-
return this.config_.updateIntervalSeconds;
1453+
return updateIntervalSeconds;
14501454
}
14511455

14521456
if (mediaState.segmentPrefetch && mediaState.segmentIterator &&

0 commit comments

Comments
 (0)