diff --git a/src/core/main/worker/worker_main.ts b/src/core/main/worker/worker_main.ts index d8dda5ef1e..8f66d06fbf 100644 --- a/src/core/main/worker/worker_main.ts +++ b/src/core/main/worker/worker_main.ts @@ -515,57 +515,61 @@ function loadOrReloadPreparedContent( segmentQueueCreator, } = preparedContent; const { drmSystemId, enableFastSwitching, initialTime, onCodecSwitch } = val; - playbackObservationRef.onUpdate((observation) => { - // Synchronize SegmentSinks with what has been buffered. - ["video" as const, "audio" as const, "text" as const].forEach((tType) => { - const segmentSinkStatus = segmentSinksStore.getStatus(tType); - if (segmentSinkStatus.type === "initialized") { - segmentSinkStatus.value.synchronizeInventory(observation.buffered[tType] ?? []); - } - }); - - const freezeResolution = preparedContent.freezeResolver.onNewObservation(observation); - if (freezeResolution !== null) { - switch (freezeResolution.type) { - case "reload": { - log.info("WP: Planning reload due to freeze"); - handleMediaSourceReload({ - timeOffset: 0, - minimumPosition: 0, - maximumPosition: Infinity, - }); - break; - } - case "flush": { - log.info("WP: Flushing buffer due to freeze"); - sendMessage({ - type: WorkerMessageType.NeedsBufferFlush, - contentId, - value: { - relativeResumingPosition: freezeResolution.value.relativeSeek, - relativePosHasBeenDefaulted: false, - }, - }); - break; + playbackObservationRef.onUpdate( + (observation) => { + // Synchronize SegmentSinks with what has been buffered. + ["video" as const, "audio" as const, "text" as const].forEach((tType) => { + const segmentSinkStatus = segmentSinksStore.getStatus(tType); + if (segmentSinkStatus.type === "initialized") { + segmentSinkStatus.value.synchronizeInventory(observation.buffered[tType] ?? []); } - case "deprecate-representations": { - log.info("WP: Planning Representation deprecation due to freeze"); - const content = freezeResolution.value; - if (enableRepresentationDeprecation) { - manifest.deprecateRepresentations(content); + }); + + const freezeResolution = + preparedContent.freezeResolver.onNewObservation(observation); + if (freezeResolution !== null) { + switch (freezeResolution.type) { + case "reload": { + log.info("WP: Planning reload due to freeze"); + handleMediaSourceReload({ + timeOffset: 0, + minimumPosition: 0, + maximumPosition: Infinity, + }); + break; } - handleMediaSourceReload({ - timeOffset: 0, - minimumPosition: 0, - maximumPosition: Infinity, - }); - break; + case "flush": { + log.info("WP: Flushing buffer due to freeze"); + sendMessage({ + type: WorkerMessageType.NeedsBufferFlush, + contentId, + value: { + relativeResumingPosition: freezeResolution.value.relativeSeek, + relativePosHasBeenDefaulted: false, + }, + }); + break; + } + case "deprecate-representations": { + log.info("WP: Planning Representation deprecation due to freeze"); + const content = freezeResolution.value; + if (enableRepresentationDeprecation) { + manifest.deprecateRepresentations(content); + } + handleMediaSourceReload({ + timeOffset: 0, + minimumPosition: 0, + maximumPosition: Infinity, + }); + break; + } + default: + assertUnreachable(freezeResolution); } - default: - assertUnreachable(freezeResolution); } - } - }); + }, + { clearSignal: currentLoadCanceller.signal }, + ); const initialPeriod = manifest.getPeriodForTime(initialTime) ?? manifest.getNextPeriod(initialTime);