Skip to content

Commit

Permalink
Add FREEZING_FOR_TOO_LONG_DELAY constant
Browse files Browse the repository at this point in the history
  • Loading branch information
peaBerberian committed Dec 18, 2024
1 parent be34d40 commit 062f509
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/core/main/common/FreezeResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ import type { IBufferedChunk } from "../../segment_sinks";
*/
const MINIMUM_BUFFER_GAP_AT_READY_STATE_1_BEFORE_FREEZING = 6;

/**
* The amount of milliseconds since a freeze was detected from which we consider
* that the freeze should be worked around: either by flushing buffers,
* reloading, or any other kind of strategies.
*
* Before that delay, will continue to wait to see if the browser succeeds to
* un-freeze by itself.
*/
const FREEZING_FOR_TOO_LONG_DELAY = 4000;

/**
* To avoid handling freezes (e.g. "reloading" or "seeking") in a loop when
* things go wrong, we have a security delay in milliseconds, this
Expand Down Expand Up @@ -291,12 +301,13 @@ export default class FreezeResolver {
const { readyState, rebuffering, freezing, fullyLoaded } = observation;
const bufferGap = normalizeBufferGap(observation.bufferGap);
const rebufferingForTooLong =
rebuffering !== null && now - rebuffering.timestamp > 4000;
const frozenForTooLong = freezing !== null && now - freezing.timestamp > 4000;
rebuffering !== null && now - rebuffering.timestamp > FREEZING_FOR_TOO_LONG_DELAY;
const frozenForTooLong =
freezing !== null && now - freezing.timestamp > FREEZING_FOR_TOO_LONG_DELAY;

const hasDecipherabilityFreezePotential =
(rebufferingForTooLong || frozenForTooLong) &&
(bufferGap >= 6 || fullyLoaded) &&
(bufferGap >= MINIMUM_BUFFER_GAP_AT_READY_STATE_1_BEFORE_FREEZING || fullyLoaded) &&
readyState <= 1;

if (!hasDecipherabilityFreezePotential) {
Expand All @@ -308,7 +319,8 @@ export default class FreezeResolver {

const shouldHandleDecipherabilityFreeze =
this._decipherabilityFreezeStartingTimestamp !== null &&
getMonotonicTimeStamp() - this._decipherabilityFreezeStartingTimestamp > 4000;
getMonotonicTimeStamp() - this._decipherabilityFreezeStartingTimestamp >
FREEZING_FOR_TOO_LONG_DELAY;

let hasOnlyDecipherableSegments = true;
let isClear = true;
Expand Down

0 comments on commit 062f509

Please sign in to comment.