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
20 changes: 20 additions & 0 deletions packages/core/src/runtime/entry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,26 @@ describe("runtime entry", () => {
expect(loadsOf(now, soon, later)).toEqual([2, 0, 0]);
});

it("in a hidden capture page a clip with no authored length waits until due, and keeps its length once loaded", async () => {
spyLoad();
servePreview().setAttribute("content", STUDIO_PREVIEW_CAPTURE_MODE);
const clips = videos(mountRoot(), "0", "1.5", "9");
for (const clip of clips) clip.removeAttribute("data-duration");
const [now, soon, later] = clips;

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

Object.defineProperty(now!, "readyState", { value: 1 });
Object.defineProperty(now!, "duration", { value: 2 });
window.__player?.seek(9.4);
// The loaded clip is never reloaded, which would drop the length it is timed by; one with no length
// known that started before the playhead may still be on screen, so it loads.
expect(armed(now!, soon!, later!)).toEqual([true, true, true]);
expect(loadsOf(now!)).toEqual([1]);
});

// 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
8 changes: 5 additions & 3 deletions packages/core/src/runtime/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3111,10 +3111,12 @@ export function initSandboxRuntimeModular(): void {
};
// Where Studio's loop wraps to (window.__hf.setLoopStart); null when it does not loop.
let loopStartSeconds: number | null = null;
// A clip with no authored length loads as in a render: a reload would drop the duration it is
// timed by.
// An unauthored length stays loaded (a reload drops it); on a capture page an unloaded one waits
// until due, or a thousand such clips run the renderer out of memory.
const inPreloadWindow = (el: HTMLMediaElement) =>
mediaDeferred && el.hasAttribute("data-start") && lengthIsAuthored(el);
mediaDeferred &&
el.hasAttribute("data-start") &&
(lengthIsAuthored(el) || (!loadsAhead && el.readyState === HTMLMediaElement.HAVE_NOTHING));

// Media on screen or due within the look-ahead loads; the rest stops holding a connection to
// the origin that also serves Studio's thumbnails.
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/runtime/preloadMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { createRuntimeStartTimeResolver } from "./startResolver";
import { readMediaRenderId } from "./renderFrameSibling";
import { defersMedia } from "./timedClipHide";
import { inPlayerFrame } from "../studioPreviewMark";
import { capturePageIn, inPlayerFrame } from "../studioPreviewMark";
import { swallow } from "./diagnostics";
import { isWebKit, mediaElementTime } from "./mediaClock";

Expand Down Expand Up @@ -216,7 +216,7 @@ export function deferMediaUntilDue(): void {
if (!defersMedia()) return;
const defer = (el: Element, startInFilm: (el: Element) => number, parsedEarly = false) => {
const start = parseStrictFiniteTimingNumber(el.getAttribute("data-start"));
if (start == null || !lengthIsAuthored(el)) return;
if (start == null || (!lengthIsAuthored(el) && !capturePageIn(document))) return;
const media = el as HTMLMediaElement;
const authoredPreload = media.preload;
const later = startInFilm(el) > 0;
Expand Down
Loading