Skip to content

Commit

Permalink
Dispose FreezeResolver on reload
Browse files Browse the repository at this point in the history
  • Loading branch information
peaBerberian committed Sep 5, 2024
1 parent 5f3f3d4 commit 32a235c
Showing 1 changed file with 51 additions and 47 deletions.
98 changes: 51 additions & 47 deletions src/core/main/worker/worker_main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 32a235c

Please sign in to comment.