mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 11:29:54 +00:00
* fix(studio): a video with no size of its own keeps its file's size while a lighter copy plays The preview plays a smaller copy of a large video, and a video the film gives no size took the copy's size: a 1920x1080 file in a 1080p film drew at 456x257 at Quality 1/2 and 608x342 at Full, while a render draws it at 1920x1080. While a copy plays, a rule keyed by the copy's address now gives the video its file's shown size (its pixels' aspect and turn included), at zero specificity so any size the film's own CSS sets still wins. Studio's media facts now carry the pixel aspect and turn, read by the same code the engine uses. * fix(studio): size only a video the film leaves unsized while its copy plays, as Chromium lays it out A video whose box is its file's own size (300x150 before the file loads) gets a plain width and height at that size while a smaller copy plays, through a preview-only mark and a rule keyed by mark and copy address. A video the film sizes in either direction is left to the film's CSS, so authored aspect ratios, box sizing, containment and earlier rules lay out as before. The size is the original's decoded size when the browser has it, else its facts with narrow pixels stretching the height as Chromium does. ffprobe is asked for the side data list, which 4.x also knows, in Studio and in the CLI. A video shown with object-fit none or scale-down keeps its file. * fix(studio): an unsized video keeps its size when its copy is made cold behind a still * test(core): a held video gets its file back when waiting for its copy throws * fix(core): a copy wait that throws counts as not served, so a held video gets its file back * test(core): each proxy test resets its own runtime's copy reporting, so none reports into the next * test(core): the stale-runtime test runs past the report throttle, as a finished test does * test(core): a framed proxy test's runtime must not report its copies into the next test * test(core): every proxy test runtime loaded fresh has its copy reporting reset after the test
65 lines
2.2 KiB
TypeScript
65 lines
2.2 KiB
TypeScript
import { wallSetTimeout } from "./wallClock";
|
|
import {
|
|
PREVIEW_PROXY_PRIORITY_HEADER,
|
|
PREVIEW_PROXY_PROGRESS_HEADER,
|
|
PREVIEW_PROXY_RETRY_PARAM,
|
|
} from "../previewProxyBox";
|
|
|
|
const MAX_FAILED_ASKS = 3;
|
|
|
|
function withoutRetryFlag(href: string): string {
|
|
const url = new URL(href, document.baseURI);
|
|
url.searchParams.delete(PREVIEW_PROXY_RETRY_PARAM);
|
|
return url.href;
|
|
}
|
|
|
|
function askHeaders(
|
|
atPlayhead: boolean,
|
|
background: boolean,
|
|
onAsk?: () => void,
|
|
): Record<string, string> {
|
|
onAsk?.();
|
|
const headers: Record<string, string> = { Range: "bytes=0-0" };
|
|
if (atPlayhead) headers[PREVIEW_PROXY_PRIORITY_HEADER] = "1";
|
|
else if (background) headers[PREVIEW_PROXY_PRIORITY_HEADER] = "0";
|
|
return headers;
|
|
}
|
|
|
|
function reportProgress(res: Response | null, onProgress?: (fraction: number) => void): void {
|
|
const reached = res?.status === 202 ? res.headers.get(PREVIEW_PROXY_PROGRESS_HEADER) : null;
|
|
if (reached !== null && Number.isFinite(Number(reached))) {
|
|
onProgress?.(Math.min(1, Math.max(0, Number(reached))));
|
|
}
|
|
}
|
|
|
|
/** Asks for one byte of a `?hf-proxy=` URL until it is served, after each Retry-After: while the
|
|
* server answers 202 (copy being made) or 503 (queue full), after up to 3 failed asks; a throw is not served. */
|
|
export async function waitForServedProxy(
|
|
href: string,
|
|
live: () => boolean,
|
|
onProgress?: (fraction: number) => void,
|
|
atPlayhead: () => boolean = () => false,
|
|
background = false,
|
|
onAsk?: () => void,
|
|
): Promise<boolean> {
|
|
let failed = 0;
|
|
let ask = href;
|
|
try {
|
|
while (live()) {
|
|
const headers = askHeaders(atPlayhead(), background, onAsk);
|
|
const res = await fetch(ask, { headers, cache: "no-store" }).catch(() => null);
|
|
ask = withoutRetryFlag(href);
|
|
void res?.body?.cancel().catch(() => {});
|
|
const pending = res?.status === 202 || res?.status === 503;
|
|
reportProgress(res, onProgress);
|
|
if (!pending && res?.ok) return true;
|
|
if (!pending && ++failed > MAX_FAILED_ASKS) return false;
|
|
const seconds = Math.min(Number(res?.headers.get("Retry-After")) || 2, 30);
|
|
await new Promise((resolveWait) => wallSetTimeout(resolveWait, seconds * 1000));
|
|
}
|
|
} catch {
|
|
return false;
|
|
}
|
|
return false;
|
|
}
|