Skip to content

Commit

Permalink
fix: Unify maxDisabledTime behaviour (#7077)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed Jul 22, 2024
1 parent 1b9435b commit 8ea2560
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
16 changes: 6 additions & 10 deletions lib/media/streaming_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1827,12 +1827,10 @@ shaka.media.StreamingEngine = class {
});

if (!waitingForAnotherStreamToRecover) {
if (this.config_.maxDisabledTime > 0) {
const handled = this.playerInterface_.disableStream(
mediaState.stream, this.config_.maxDisabledTime);
if (handled) {
return;
}
const handled = this.playerInterface_.disableStream(
mediaState.stream, this.config_.maxDisabledTime);
if (handled) {
return;
}
// Reduction schedule: 80%, 60%, 40%, 20%, 16%, 12%, 8%, 4%, fail.
// Note: percentages are used for comparisons to avoid rounding errors.
Expand Down Expand Up @@ -2722,11 +2720,9 @@ shaka.media.StreamingEngine = class {
// use the backoff system to delay and backoff the error handling.
await this.failureCallbackBackoff_.attempt();
this.destroyer_.ensureNotDestroyed();

const maxDisabledTime = this.getDisabledTime_(error);
// Try to recover from network errors
if (error.category === shaka.util.Error.Category.NETWORK &&
maxDisabledTime > 0) {
if (error.category === shaka.util.Error.Category.NETWORK) {
const maxDisabledTime = this.getDisabledTime_(error);
error.handled = this.playerInterface_.disableStream(
mediaState.stream, maxDisabledTime);

Expand Down
4 changes: 4 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -7227,6 +7227,10 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
return false;
}

if (disableTime == 0) {
return false;
}

// It only makes sense to disable a stream if we have an alternative else we
// end up disabling all variants.
const hasAltStream = this.manifest_.variants.some((variant) => {
Expand Down
4 changes: 3 additions & 1 deletion test/media/streaming_engine_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2256,7 +2256,9 @@ describe('StreamingEngine', () => {

onError.and.callFake((error) => {
expect(error.code).toBe(shaka.util.Error.Code.HTTP_ERROR);
expect(error.handled).toBeFalsy();
});
disableStream.and.callFake((stream, disableTime) => disableTime != 0);

// Here we go!
streamingEngine.switchVariant(variant);
Expand All @@ -2265,7 +2267,7 @@ describe('StreamingEngine', () => {
playing = true;

await runTest();
expect(disableStream).not.toHaveBeenCalled();
expect(disableStream).toHaveBeenCalledTimes(1);
});

it('always tries to recover shaka.util.Error.Code.SEGMENT_MISSING',
Expand Down

0 comments on commit 8ea2560

Please sign in to comment.