diff --git a/lib/media/media_source_engine.js b/lib/media/media_source_engine.js index f7a53d8989..09665609a7 100644 --- a/lib/media/media_source_engine.js +++ b/lib/media/media_source_engine.js @@ -1424,7 +1424,7 @@ shaka.media.MediaSourceEngine = class { const ContentType = shaka.util.ManifestParserUtils.ContentType; if (contentType == ContentType.TEXT) { await this.textEngine_.remove(startTime, endTime); - } else { + } else if (endTime > startTime) { await this.enqueueOperation_( contentType, () => this.remove_(contentType, startTime, endTime), diff --git a/lib/media/streaming_engine.js b/lib/media/streaming_engine.js index c09d9396a9..49d5ff933c 100644 --- a/lib/media/streaming_engine.js +++ b/lib/media/streaming_engine.js @@ -2430,15 +2430,26 @@ shaka.media.StreamingEngine = class { } const bufferedBehind = presentationTime - startTime; - const overflow = bufferedBehind - bufferBehind; + const evictionGoal = this.config_.evictionGoal; + + const seekRangeStart = + this.manifest_.presentationTimeline.getSeekRangeStart(); + const seekRangeEnd = + this.manifest_.presentationTimeline.getSeekRangeEnd(); + + let overflow = bufferedBehind - bufferBehind; + if (seekRangeEnd - seekRangeStart > evictionGoal) { + overflow = Math.max(bufferedBehind - bufferBehind, + seekRangeStart - evictionGoal - startTime); + } // See: https://github.com/shaka-project/shaka-player/issues/6240 - if (overflow <= this.config_.evictionGoal) { + if (overflow <= evictionGoal) { shaka.log.v2(logPrefix, 'buffer behind okay:', 'presentationTime=' + presentationTime, 'bufferedBehind=' + bufferedBehind, 'bufferBehind=' + bufferBehind, - 'evictionGoal=' + this.config_.evictionGoal, + 'evictionGoal=' + evictionGoal, 'underflow=' + Math.abs(overflow)); return; } @@ -2448,7 +2459,7 @@ shaka.media.StreamingEngine = class { 'presentationTime=' + presentationTime, 'bufferedBehind=' + bufferedBehind, 'bufferBehind=' + bufferBehind, - 'evictionGoal=' + this.config_.evictionGoal, + 'evictionGoal=' + evictionGoal, 'overflow=' + overflow); await this.playerInterface_.mediaSourceEngine.remove(mediaState.type, diff --git a/test/media/streaming_engine_unit.js b/test/media/streaming_engine_unit.js index 296988ea11..0f979e9c48 100644 --- a/test/media/streaming_engine_unit.js +++ b/test/media/streaming_engine_unit.js @@ -456,6 +456,9 @@ describe('StreamingEngine', () => { config.bufferingGoal = 5; config.bufferBehind = Infinity; config.maxDisabledTime = 0; // Do not disable stream by default + // We don't want to evict segments in tests where there is no need to + // test them. + config.evictionGoal = 30; } if (defaultConfig.segmentPrefetchLimit == config.segmentPrefetchLimit) {