Skip to content

Commit

Permalink
fix: Evict the buffer against seekRangeStart (#8026)
Browse files Browse the repository at this point in the history
This avoid keep in the buffer content that is not necessary.
  • Loading branch information
avelad authored Feb 6, 2025
1 parent 0efdd2b commit 44748b4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/media/media_source_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
19 changes: 15 additions & 4 deletions lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions test/media/streaming_engine_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 44748b4

Please sign in to comment.