Skip to content

Commit

Permalink
Add supplementary security for decipherability reload
Browse files Browse the repository at this point in the history
  • Loading branch information
peaBerberian committed Jul 4, 2023
1 parent 599032b commit 1d32519
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/core/init/utils/rebuffering_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ export default class RebufferingController

private _canceller : TaskCanceller;

/**
* If set to something else than `null`, this is the DOMHighResTimestamp as
* outputed by `performance.now()` when playback begin to seem to not start
* despite having decipherable data in the buffer(s).
*
* If enough time in that condition is spent, special considerations are
* taken at which point `_currentFreezeTimestamp` is reset to `null`.
*
* It is also reset to `null` when and if there is no such issue anymore.
*/
private _currentFreezeTimestamp : number | null;

/**
* @param {object} playbackObserver - emit the current playback conditions.
* @param {Object} manifest - The Manifest of the currently-played content.
Expand All @@ -85,6 +97,7 @@ export default class RebufferingController
this._discontinuitiesStore = [];
this._isStarted = false;
this._canceller = new TaskCanceller();
this._currentFreezeTimestamp = null;
}

public start() : void {
Expand Down Expand Up @@ -367,8 +380,8 @@ export default class RebufferingController
}

/**
* Support of contents with DRM on all the platforms out there is a pain
* considering all the DRM-related bugs there are.
* Support of contents with DRM on all the platforms out there is a pain in
* the *ss considering all the DRM-related bugs there are.
*
* We found out a frequent issue which is to be unable to play despite having
* all the decryption keys to play what is currently buffered.
Expand Down Expand Up @@ -401,16 +414,23 @@ export default class RebufferingController
(rebuffering === null && freezing === null) ||
readyState > 1
) {
this._currentFreezeTimestamp = null;
return false;
}

const now = performance.now();
if (this._currentFreezeTimestamp === null) {
this._currentFreezeTimestamp = now;
}
const rebufferingForTooLong =
rebuffering !== null && now - rebuffering.timestamp > 4000;
const frozenForTooLong =
freezing !== null && now - freezing.timestamp > 4000;

if (rebufferingForTooLong || frozenForTooLong) {
if (
(rebufferingForTooLong || frozenForTooLong) &&
performance.now() - this._currentFreezeTimestamp > 4000
) {
const statusAudio = this._segmentBuffersStore.getStatus("audio");
const statusVideo = this._segmentBuffersStore.getStatus("video");
let hasOnlyDecipherableSegments = true;
Expand All @@ -423,6 +443,7 @@ export default class RebufferingController
log.warn(
"Init: we have undecipherable segments left in the buffer, reloading"
);
this._currentFreezeTimestamp = null;
this.trigger("needsReload", null);
return true;
} else if (representation.contentProtections !== undefined) {
Expand All @@ -440,6 +461,7 @@ export default class RebufferingController
"Init: we are frozen despite only having decipherable " +
"segments left in the buffer, reloading"
);
this._currentFreezeTimestamp = null;
this.trigger("needsReload", null);
return true;
}
Expand Down

0 comments on commit 1d32519

Please sign in to comment.