Skip to content

Commit

Permalink
fix: Evict text buffer when unload the text stream (#7360)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad authored Sep 24, 2024
1 parent 43314a1 commit 5b6652f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ shaka.media.StreamingEngine = class {

/** @private {number} */
this.playRangeEnd_ = Infinity;

/** @private {?shaka.media.StreamingEngine.MediaState_} */
this.lastTextMediaStateBeforeUnload_ = null;
}

/** @override */
Expand Down Expand Up @@ -380,6 +383,8 @@ shaka.media.StreamingEngine = class {
if (state) {
this.cancelUpdate_(state);
this.abortOperations_(state).catch(() => {});
this.lastTextMediaStateBeforeUnload_ =
this.mediaStates_.get(ContentType.TEXT);
this.mediaStates_.delete(ContentType.TEXT);
}
this.currentTextStream_ = null;
Expand Down Expand Up @@ -476,6 +481,7 @@ shaka.media.StreamingEngine = class {
* @param {shaka.extern.Stream} textStream
*/
async switchTextStream(textStream) {
this.lastTextMediaStateBeforeUnload_ = null;
this.currentTextStream_ = textStream;

if (!this.startupComplete_) {
Expand Down Expand Up @@ -2539,6 +2545,9 @@ shaka.media.StreamingEngine = class {
const startTime =
this.playerInterface_.mediaSourceEngine.bufferStart(mediaState.type);
if (startTime == null) {
if (this.lastTextMediaStateBeforeUnload_ == mediaState) {
this.lastTextMediaStateBeforeUnload_ = null;
}
shaka.log.v2(logPrefix,
'buffer behind okay because nothing buffered:',
'presentationTime=' + presentationTime,
Expand Down Expand Up @@ -2573,6 +2582,11 @@ shaka.media.StreamingEngine = class {

this.destroyer_.ensureNotDestroyed();
shaka.log.v1(logPrefix, 'evicted ' + overflow + ' seconds');

if (this.lastTextMediaStateBeforeUnload_) {
await this.evict_(this.lastTextMediaStateBeforeUnload_, presentationTime);
this.destroyer_.ensureNotDestroyed();
}
}


Expand Down

0 comments on commit 5b6652f

Please sign in to comment.