Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix duplicate updates in StreamingEngine #4840

Merged
merged 3 commits into from
Dec 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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