Skip to content

Commit

Permalink
fix: Fix duplicate updates in StreamingEngine (shaka-project#4840)
Browse files Browse the repository at this point in the history
There were several places where certain StreamingEngine events and
timing could result in duplicate update requests for streams. This
caused some inconsistent test failures, in particular on Chromecast.

This change adds some additional checks before scheduling and cancelling
updates, to ensure that the proper conditions are maintained.

Closes shaka-project#4831
  • Loading branch information
joeyparrish authored Dec 14, 2022
1 parent 4955814 commit 224207b
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ shaka.media.StreamingEngine = class {

/**
* Clear the buffer for a given stream. Unlike clearBuffer_, this will handle
* cases where a MediaState is performing an update. After this runs, every
* cases where a MediaState is performing an update. After this runs, the
* MediaState will have a pending update.
* @param {!shaka.media.StreamingEngine.MediaState_} mediaState
* @private
Expand Down Expand Up @@ -793,9 +793,9 @@ shaka.media.StreamingEngine = class {
for (const type of streamsByType.keys()) {
const stream = streamsByType.get(type);
if (!this.mediaStates_.has(type)) {
const state = this.createMediaState_(stream);
this.mediaStates_.set(type, state);
this.scheduleUpdate_(state, 0);
const mediaState = this.createMediaState_(stream);
this.mediaStates_.set(type, mediaState);
this.scheduleUpdate_(mediaState, 0);
}
}
}
Expand Down Expand Up @@ -907,7 +907,7 @@ shaka.media.StreamingEngine = class {
'mediastate.stream should not have segmentIndex yet.');
thisStream.closeSegmentIndex();
}
if (mediaState.updateTimer == null) {
if (!mediaState.performingUpdate && !mediaState.updateTimer) {
this.scheduleUpdate_(mediaState, 0);
}
return;
Expand Down Expand Up @@ -1392,7 +1392,7 @@ shaka.media.StreamingEngine = class {
// If the network slows down, abort the current fetch request and start
// a new one, and ignore the error message.
mediaState.performingUpdate = false;
mediaState.updateTimer = null;
this.cancelUpdate_(mediaState);
this.scheduleUpdate_(mediaState, 0);
} else if (mediaState.type == ContentType.TEXT &&
this.config_.ignoreTextStreamFailures) {
Expand Down Expand Up @@ -1465,7 +1465,10 @@ shaka.media.StreamingEngine = class {

for (const mediaState of this.mediaStates_.values()) {
const logPrefix = shaka.media.StreamingEngine.logPrefix_(mediaState);
if (mediaState.hasError) {
// Only schedule an update if it has an error, but it's not mid-update
// and there is not already an update scheduled.
if (mediaState.hasError && !mediaState.performingUpdate &&
!mediaState.updateTimer) {
shaka.log.info(logPrefix, 'Retrying after failure...');
mediaState.hasError = false;
this.scheduleUpdate_(mediaState, delaySeconds);
Expand Down Expand Up @@ -2088,7 +2091,11 @@ shaka.media.StreamingEngine = class {
shaka.log.debug(logPrefix, 'cleared buffer');
mediaState.clearingBuffer = false;
mediaState.endOfStream = false;
this.scheduleUpdate_(mediaState, 0);
// Since the clear operation was async, check to make sure we're not doing
// another update and we don't have one scheduled yet.
if (!mediaState.performingUpdate && !mediaState.updateTimer) {
this.scheduleUpdate_(mediaState, 0);
}
}


Expand Down

0 comments on commit 224207b

Please sign in to comment.