Skip to content

Commit 213b2b7

Browse files
authored
fix: Avoid rebuffering when using big trick play rates (#7988)
1 parent 8816086 commit 213b2b7

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/media/streaming_engine.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -1368,12 +1368,17 @@ shaka.media.StreamingEngine = class {
13681368
return null;
13691369
}
13701370

1371+
// Update updateIntervalSeconds according to our current playbackrate,
1372+
// and always considering a minimum of 1.
1373+
const updateIntervalSeconds = this.config_.updateIntervalSeconds /
1374+
Math.max(1, Math.abs(this.playerInterface_.getPlaybackRate()));
1375+
13711376
if (!this.playerInterface_.mediaSourceEngine.isStreamingAllowed() &&
13721377
mediaState.type != ContentType.TEXT) {
13731378
// It is not allowed to add segments yet, so we schedule an update to
13741379
// check again later. So any prediction we make now could be terribly
13751380
// invalid soon.
1376-
return this.config_.updateIntervalSeconds / 2;
1381+
return updateIntervalSeconds / 2;
13771382
}
13781383

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

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

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

15041508
if (mediaState.segmentPrefetch && mediaState.segmentIterator &&

0 commit comments

Comments
 (0)