Skip to content

Commit

Permalink
Add text stream sequence id
Browse files Browse the repository at this point in the history
  • Loading branch information
willdharris committed Apr 4, 2023
1 parent d4009a1 commit c1cb3d1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ shaka.media.StreamingEngine = class {
/** @private {?shaka.extern.Stream} */
this.currentTextStream_ = null;

/** @private {number} */
this.textStreamSequenceId_ = 0;

/** @private {boolean} */
this.parsedPrftEventRaised_ = false;

Expand Down Expand Up @@ -235,16 +238,18 @@ shaka.media.StreamingEngine = class {
* @param {shaka.extern.Stream} stream
* @private
*/
loadNewTextStream_(stream) {
async loadNewTextStream_(stream) {
const ContentType = shaka.util.ManifestParserUtils.ContentType;
goog.asserts.assert(!this.mediaStates_.has(ContentType.TEXT),
'Should not call loadNewTextStream_ while streaming text!');
this.textStreamSequenceId_++;
const currentSequenceId = this.textStreamSequenceId_;

try {
// Clear MediaSource's buffered text, so that the new text stream will
// properly replace the old buffered text.
// TODO: Should this happen in unloadTextStream() instead?
this.playerInterface_.mediaSourceEngine.clear(ContentType.TEXT);
await this.playerInterface_.mediaSourceEngine.clear(ContentType.TEXT);
} catch (error) {
if (this.playerInterface_) {
this.playerInterface_.onError(error);
Expand All @@ -261,7 +266,7 @@ shaka.media.StreamingEngine = class {
const streamText =
textDisplayer.isTextVisible() || this.config_.alwaysStreamText;

if (streamText) {
if (streamText && (this.textStreamSequenceId_ == currentSequenceId)) {
const state = this.createMediaState_(stream);
this.mediaStates_.set(ContentType.TEXT, state);
this.scheduleUpdate_(state, 0);
Expand Down

0 comments on commit c1cb3d1

Please sign in to comment.