Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/core/src/runtime/entry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { HF_COLOR_GRADING_ATTR, serializeHfColorGrading } from "../colorGrading"
import {
PLAYER_FRAME_ATTR,
STUDIO_PREVIEW_LAZY_ATTR,
STUDIO_PREVIEW_CAPTURE_MODE,
STUDIO_PREVIEW_MARK_META,
} from "../studioPreviewMark";
import { revealClip } from "./clipReveal";
Expand Down Expand Up @@ -495,6 +496,22 @@ describe("runtime entry", () => {
expect(now.getAttribute("src")).toBe("now.mp4");
});

it("in a hidden capture page only the clip on screen loads, and the one a seek left is freed", async () => {
spyLoad();
servePreview().setAttribute("content", STUDIO_PREVIEW_CAPTURE_MODE);
const [now, soon, later] = videos(mountRoot(), "0", "1.5", "9");

await evaluateRuntime();
expect(armed(now, soon, later)).toEqual([true, false, false]);
expect(loadsOf(now, soon, later)).toEqual([1, 0, 0]);

window.__player?.seek(9.4);
expect(armed(now, soon, later)).toEqual([false, false, true]);
expect(now.preload).toBe("none");
// The clip left is reloaded empty; the one landed on is armed by the seek, not reloaded under it.
expect(loadsOf(now, soon, later)).toEqual([2, 0, 0]);
});

// Three takes of one file, each a picture and a sound, as an edit cut from a single source is.
const takesOfOneFile = () => {
const root = mountRoot();
Expand Down
13 changes: 8 additions & 5 deletions packages/core/src/runtime/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
skipsHiddenImages,
} from "./timedClipHide";
import {
capturePageIn,
inPlayerFrame,
STUDIO_PREVIEW_MARK_META,
PREVIEW_ONLY_ATTRS,
Expand Down Expand Up @@ -3003,6 +3004,7 @@ export function initSandboxRuntimeModular(): void {
const hiddenImagesSkipped = skipsHiddenImages();
const mediaDeferred = defersMedia();
const studioPreview = document.querySelector(`meta[name="${STUDIO_PREVIEW_MARK_META}"]`) !== null;
const loadsAhead = !capturePageIn(document);
const skipFarScenes = createFarSceneSkip((host) =>
runtimeElementWindow(host, {
timelineRegistry: window.__timelines ?? {},
Expand Down Expand Up @@ -3267,7 +3269,7 @@ export function initSandboxRuntimeModular(): void {
// Frees a clip the window armed; on one the parser started, it would only restart the fetch.
if (decided)
withoutOwnTimingRecords(el, () =>
releaseMedia(el, window.__HF_RELEASE_PASSED_MEDIA === true),
releaseMedia(el, !loadsAhead || window.__HF_RELEASE_PASSED_MEDIA === true),
);
}
} else if (!visible || decided === undefined) {
Expand Down Expand Up @@ -3472,11 +3474,12 @@ export function initSandboxRuntimeModular(): void {
preloadNearPlayhead(
rawNode,
isVisibleNow,
playerFrame
? nextTakeClips(currentTime).has(rawNode)
: upcoming || mediaStaysDue(rawNode, visibleAt, currentTime),
loadsAhead &&
(playerFrame
? nextTakeClips(currentTime).has(rawNode)
: upcoming || mediaStaysDue(rawNode, visibleAt, currentTime)),
currentTime,
dueAtLoopStart(rawNode, visibleAt),
loadsAhead && dueAtLoopStart(rawNode, visibleAt),
);
if (!isMediaElement(rawNode) && !isImageElement(rawNode)) decidedTimedClip = true;
if (isVideoElement(rawNode) || isImageElement(rawNode)) {
Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/runtime/timedClipHide.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CLIP_HIDDEN_ATTR, olderShaderBuildOnPage, revealClip } from "./clipReveal";
import {
capturePageIn,
defersMediaIn,
RUNTIME_STAMPED_ATTR,
STUDIO_PREVIEW_CAPTURE_MODE,
STUDIO_PREVIEW_MARK_META,
STUDIO_PREVIEW_UPCOMING_ATTR,
} from "../studioPreviewMark";
Expand Down Expand Up @@ -73,9 +73,8 @@ export function hideTimedClipsUntilFirstPass(): void {
if (typeof document === "undefined") return;
const parent = document.head ?? document.documentElement;
if (!parent) return;
const mark = document.querySelector(STUDIO_PREVIEW_MARK);
const preview = mark !== null;
const capture = mark?.getAttribute("content") === STUDIO_PREVIEW_CAPTURE_MODE;
const preview = document.querySelector(STUDIO_PREVIEW_MARK) !== null;
const capture = capturePageIn(document);
if (preview && !capture && !skipsHiddenImages())
appendStyle(parent, SKIP_ATTR, skipHiddenImages(HIDDEN_CLIP_DOUBLED_FOR_WEIGHT));
if (!document.querySelector(`style[${CONTENTS_ATTR}]`))
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/studioPreviewMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export function defersMediaIn(doc: Document): boolean {
doc.querySelector(`meta[name="${STUDIO_PREVIEW_MARK_META}"]`) !== null || inPlayerFrame(doc)
);
}
export function capturePageIn(doc: Document): boolean {
return (
doc.querySelector(`meta[name="${STUDIO_PREVIEW_MARK_META}"]`)?.getAttribute("content") ===
STUDIO_PREVIEW_CAPTURE_MODE
);
}
export const STUDIO_PREVIEW_UPCOMING_ATTR = "data-hf-upcoming";
export const STUDIO_PREVIEW_LAZY_ATTR = "data-hf-preview-lazy";
export const STUDIO_PREVIEW_ERRORS = "__hfPreviewErrors";
Expand Down
Loading