@hyperframes/producer 0.9.91 → 0.9.93
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -4
- package/dist/compileWorker.js +3 -3
- package/dist/distributed.js +6 -5
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +69 -69
- package/dist/index.js +301 -151
- package/dist/public-server.js +303 -151
- package/dist/server.d.ts +7 -2
- package/dist/services/hdrCompositor.d.ts +7 -0
- package/dist/services/render/captureCost.d.ts +4 -0
- package/dist/services/renderOrchestrator.d.ts +7 -0
- package/package.json +7 -7
package/dist/public-server.js
CHANGED
|
@@ -31,8 +31,9 @@ import {
|
|
|
31
31
|
rmSync as rmSync14,
|
|
32
32
|
createReadStream as createReadStream4
|
|
33
33
|
} from "node:fs";
|
|
34
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
34
35
|
import { basename as basename8, resolve as resolve11, dirname as dirname19, join as join40 } from "node:path";
|
|
35
|
-
import { tmpdir as tmpdir4 } from "node:os";
|
|
36
|
+
import { homedir, tmpdir as tmpdir4 } from "node:os";
|
|
36
37
|
import { parseArgs } from "node:util";
|
|
37
38
|
import { isIP } from "node:net";
|
|
38
39
|
import crypto from "node:crypto";
|
|
@@ -3093,6 +3094,7 @@ import {
|
|
|
3093
3094
|
import { readSync as readSync2 } from "fs";
|
|
3094
3095
|
import { join as join7 } from "path";
|
|
3095
3096
|
import {
|
|
3097
|
+
TRANSITIONS,
|
|
3096
3098
|
captureAlphaPng,
|
|
3097
3099
|
applyDomLayerMask,
|
|
3098
3100
|
removeDomLayerMask,
|
|
@@ -3129,6 +3131,31 @@ function isAffineMatrix(m) {
|
|
|
3129
3131
|
function resolveBlitOpacity(opacity) {
|
|
3130
3132
|
return opacity < OPAQUE_ALPHA_THRESHOLD ? opacity : void 0;
|
|
3131
3133
|
}
|
|
3134
|
+
var isTime = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0;
|
|
3135
|
+
function sanitizeTransitionMeta(raw, warn) {
|
|
3136
|
+
if (!Array.isArray(raw)) return [];
|
|
3137
|
+
const kept = [];
|
|
3138
|
+
for (const [index, entry] of raw.entries()) {
|
|
3139
|
+
if (typeof entry !== "object" || entry === null || !isTime(entry.time) || !isTime(entry.duration) || typeof entry.fromScene !== "string" || typeof entry.toScene !== "string") {
|
|
3140
|
+
warn("[Render] Ignoring malformed shader transition entry", { index });
|
|
3141
|
+
continue;
|
|
3142
|
+
}
|
|
3143
|
+
const { shader } = entry;
|
|
3144
|
+
const known = typeof shader === "string" && Object.hasOwn(TRANSITIONS, shader);
|
|
3145
|
+
if (shader !== void 0 && !known) {
|
|
3146
|
+
warn("[Render] Unknown shader transition; using crossfade", { index });
|
|
3147
|
+
}
|
|
3148
|
+
kept.push({
|
|
3149
|
+
time: entry.time,
|
|
3150
|
+
duration: entry.duration,
|
|
3151
|
+
ease: typeof entry.ease === "string" ? entry.ease : "",
|
|
3152
|
+
fromScene: entry.fromScene,
|
|
3153
|
+
toScene: entry.toScene,
|
|
3154
|
+
...known ? { shader } : {}
|
|
3155
|
+
});
|
|
3156
|
+
}
|
|
3157
|
+
return kept;
|
|
3158
|
+
}
|
|
3132
3159
|
function cropRgb48le(src, srcW, srcH, cropX, cropY, cropW, cropH) {
|
|
3133
3160
|
const dst = Buffer.alloc(cropW * cropH * RGB48_BYTES_PER_PIXEL);
|
|
3134
3161
|
for (let row = 0; row < cropH; row++) {
|
|
@@ -6009,6 +6036,13 @@ function estimateMeasuredCaptureCostMultiplier(samples) {
|
|
|
6009
6036
|
medianMs
|
|
6010
6037
|
};
|
|
6011
6038
|
}
|
|
6039
|
+
function shouldCalibrateSoftwareGpu(requestedMode, resolvedMode, hardware) {
|
|
6040
|
+
return requestedMode === "auto" && resolvedMode === "hardware" && hardware !== void 0 && hardware.multiplier > 1 && hardware.p95Ms !== void 0;
|
|
6041
|
+
}
|
|
6042
|
+
function pickAutoGpuModeFromCalibration(hardware, software) {
|
|
6043
|
+
if (hardware.p95Ms === void 0 || software?.p95Ms === void 0) return "hardware";
|
|
6044
|
+
return software.p95Ms < hardware.p95Ms ? "software" : "hardware";
|
|
6045
|
+
}
|
|
6012
6046
|
function selectCaptureCalibrationFrames(totalFrames) {
|
|
6013
6047
|
if (totalFrames <= 0) return [];
|
|
6014
6048
|
const lastFrame = totalFrames - 1;
|
|
@@ -9512,7 +9546,7 @@ async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLab
|
|
|
9512
9546
|
}
|
|
9513
9547
|
let result = html;
|
|
9514
9548
|
for (const [url, relPath] of urlToRelPath) {
|
|
9515
|
-
result = result.replaceAll(`"${url}"`, `"${relPath}"`).replaceAll(`'${url}'`, `'${relPath}'`);
|
|
9549
|
+
result = result.replaceAll(`"${url}"`, () => `"${relPath}"`).replaceAll(`'${url}'`, () => `'${relPath}'`);
|
|
9516
9550
|
if (extraRewrite) result = extraRewrite(result, url, relPath);
|
|
9517
9551
|
}
|
|
9518
9552
|
defaultLogger.debug(`[Compiler] ${logLabel} ${urlToLocal.size} to ${REMOTE_MEDIA_SUBDIR}/`);
|
|
@@ -9567,7 +9601,7 @@ async function localizeRemoteBackgroundImages(html, downloadDir, assets) {
|
|
|
9567
9601
|
assets,
|
|
9568
9602
|
// Quoted url('..')/url("..") are rewritten by downloadAndRewriteUrls' default
|
|
9569
9603
|
// replaceAll; this handles the unquoted url(https://..) form.
|
|
9570
|
-
(h, url, rel) => h.replaceAll(`url(${url})`, `url(${rel})`)
|
|
9604
|
+
(h, url, rel) => h.replaceAll(`url(${url})`, () => `url(${rel})`)
|
|
9571
9605
|
);
|
|
9572
9606
|
}
|
|
9573
9607
|
function isGoogleFontsUrl(href) {
|
|
@@ -9734,7 +9768,7 @@ function localizeFontFaceUrls(html, downloadDir, assets) {
|
|
|
9734
9768
|
style,
|
|
9735
9769
|
css,
|
|
9736
9770
|
"</style>".length,
|
|
9737
|
-
css.replaceAll(`url(${url})`, `url("${relPath}")`)
|
|
9771
|
+
css.replaceAll(`url(${url})`, () => `url("${relPath}")`)
|
|
9738
9772
|
)
|
|
9739
9773
|
)
|
|
9740
9774
|
);
|
|
@@ -13575,7 +13609,7 @@ function createHdrImageTransferCache(options = {}) {
|
|
|
13575
13609
|
// src/services/render/stages/captureHdrSequentialLoop.ts
|
|
13576
13610
|
import { join as join30 } from "node:path";
|
|
13577
13611
|
import {
|
|
13578
|
-
TRANSITIONS,
|
|
13612
|
+
TRANSITIONS as TRANSITIONS2,
|
|
13579
13613
|
crossfade
|
|
13580
13614
|
} from "@hyperframes/engine";
|
|
13581
13615
|
async function runSequentialLayeredFrameLoop(input) {
|
|
@@ -13673,7 +13707,7 @@ async function runSequentialLayeredFrameLoop(input) {
|
|
|
13673
13707
|
});
|
|
13674
13708
|
}
|
|
13675
13709
|
const shaderName = activeTransition.shader;
|
|
13676
|
-
const transitionFn = shaderName ?
|
|
13710
|
+
const transitionFn = shaderName ? TRANSITIONS2[shaderName] ?? crossfade : crossfade;
|
|
13677
13711
|
transitionFn(
|
|
13678
13712
|
transitionBuffers.bufferA,
|
|
13679
13713
|
transitionBuffers.bufferB,
|
|
@@ -13732,7 +13766,7 @@ async function runSequentialLayeredFrameLoop(input) {
|
|
|
13732
13766
|
// src/services/render/stages/captureHdrHybridLoop.ts
|
|
13733
13767
|
import { join as join32 } from "node:path";
|
|
13734
13768
|
import {
|
|
13735
|
-
TRANSITIONS as
|
|
13769
|
+
TRANSITIONS as TRANSITIONS3,
|
|
13736
13770
|
closeCaptureSession as closeCaptureSession6,
|
|
13737
13771
|
createCaptureSession as createCaptureSession6,
|
|
13738
13772
|
createFrameReorderBuffer as createFrameReorderBuffer2,
|
|
@@ -14017,6 +14051,15 @@ async function runHybridLayeredFrameLoop(input) {
|
|
|
14017
14051
|
const workerRanges = distributeLayeredHybridFrameRanges(totalFrames, activeWorkerCount);
|
|
14018
14052
|
let framesWritten = 0;
|
|
14019
14053
|
const reorderBuffer = createFrameReorderBuffer2(0, totalFrames);
|
|
14054
|
+
let failure = null;
|
|
14055
|
+
const fail = (err) => {
|
|
14056
|
+
if (failure) return;
|
|
14057
|
+
failure = err instanceof Error ? err : new Error(String(err));
|
|
14058
|
+
reorderBuffer.abort(failure);
|
|
14059
|
+
};
|
|
14060
|
+
const throwIfFailed = () => {
|
|
14061
|
+
if (failure) throw failure;
|
|
14062
|
+
};
|
|
14020
14063
|
const writeEncoded = async (frameIdx, buf) => {
|
|
14021
14064
|
await reorderBuffer.waitForFrame(frameIdx);
|
|
14022
14065
|
const writeStart = Date.now();
|
|
@@ -14043,103 +14086,108 @@ async function runHybridLayeredFrameLoop(input) {
|
|
|
14043
14086
|
if (!session || !canvas || !range) return;
|
|
14044
14087
|
const ringInFlight = ring ? ring.map(() => null) : [];
|
|
14045
14088
|
let nextRingIdx = 0;
|
|
14046
|
-
|
|
14047
|
-
|
|
14048
|
-
|
|
14049
|
-
|
|
14050
|
-
|
|
14051
|
-
const
|
|
14052
|
-
|
|
14053
|
-
|
|
14054
|
-
|
|
14055
|
-
|
|
14056
|
-
|
|
14057
|
-
|
|
14058
|
-
|
|
14059
|
-
|
|
14060
|
-
|
|
14061
|
-
|
|
14062
|
-
|
|
14063
|
-
|
|
14064
|
-
|
|
14065
|
-
|
|
14066
|
-
|
|
14067
|
-
|
|
14068
|
-
|
|
14069
|
-
|
|
14070
|
-
|
|
14071
|
-
|
|
14072
|
-
|
|
14073
|
-
|
|
14074
|
-
|
|
14075
|
-
|
|
14076
|
-
|
|
14077
|
-
|
|
14078
|
-
|
|
14079
|
-
|
|
14080
|
-
|
|
14081
|
-
|
|
14082
|
-
|
|
14083
|
-
|
|
14084
|
-
|
|
14085
|
-
|
|
14086
|
-
|
|
14087
|
-
|
|
14088
|
-
|
|
14089
|
-
|
|
14090
|
-
|
|
14091
|
-
|
|
14092
|
-
|
|
14093
|
-
|
|
14094
|
-
|
|
14095
|
-
|
|
14096
|
-
|
|
14097
|
-
|
|
14098
|
-
|
|
14099
|
-
|
|
14100
|
-
|
|
14101
|
-
|
|
14102
|
-
|
|
14089
|
+
try {
|
|
14090
|
+
for (let i = range.start; i < range.end; i++) {
|
|
14091
|
+
throwIfFailed();
|
|
14092
|
+
assertNotAborted();
|
|
14093
|
+
const time = i * job.config.fps.den / job.config.fps.num;
|
|
14094
|
+
const activeTransition = transitionFramesSet.has(i) ? transitionRanges.find((t) => i >= t.startFrame && i <= t.endFrame) : void 0;
|
|
14095
|
+
if (activeTransition && ring) {
|
|
14096
|
+
const slot = nextRingIdx;
|
|
14097
|
+
nextRingIdx = (nextRingIdx + 1) % TRANSITION_RING_DEPTH;
|
|
14098
|
+
const prev = ringInFlight[slot];
|
|
14099
|
+
if (prev) await prev;
|
|
14100
|
+
throwIfFailed();
|
|
14101
|
+
const buffers = ring[slot];
|
|
14102
|
+
if (!buffers) continue;
|
|
14103
|
+
await captureTransitionFrameOnWorker({
|
|
14104
|
+
session,
|
|
14105
|
+
frameIdx: i,
|
|
14106
|
+
time,
|
|
14107
|
+
transition: activeTransition,
|
|
14108
|
+
buffers,
|
|
14109
|
+
nativeHdrIds,
|
|
14110
|
+
nativeHdrImageIds,
|
|
14111
|
+
sceneElements,
|
|
14112
|
+
hdrCompositeCtx,
|
|
14113
|
+
width,
|
|
14114
|
+
height,
|
|
14115
|
+
compositeTransfer,
|
|
14116
|
+
hdrTargetTransfer,
|
|
14117
|
+
hdrPerf,
|
|
14118
|
+
log
|
|
14119
|
+
});
|
|
14120
|
+
const progress = activeTransition.endFrame === activeTransition.startFrame ? 1 : (i - activeTransition.startFrame) / (activeTransition.endFrame - activeTransition.startFrame);
|
|
14121
|
+
const frameIdx = i;
|
|
14122
|
+
const shaderName = activeTransition.shader;
|
|
14123
|
+
const dispatch = (async () => {
|
|
14124
|
+
if (poolRef && shaderName) {
|
|
14125
|
+
const blendStart = Date.now();
|
|
14126
|
+
const result = await poolRef.run({
|
|
14127
|
+
shader: shaderName,
|
|
14128
|
+
bufferA: buffers.bufferA,
|
|
14129
|
+
bufferB: buffers.bufferB,
|
|
14130
|
+
output: buffers.output,
|
|
14131
|
+
width,
|
|
14132
|
+
height,
|
|
14133
|
+
progress
|
|
14134
|
+
});
|
|
14135
|
+
buffers.bufferA = result.bufferA;
|
|
14136
|
+
buffers.bufferB = result.bufferB;
|
|
14137
|
+
buffers.output = result.output;
|
|
14138
|
+
addHdrTiming(hdrPerf, "transitionCompositeMs", blendStart);
|
|
14139
|
+
} else {
|
|
14140
|
+
const transitionFn = shaderName ? TRANSITIONS3[shaderName] ?? crossfade2 : crossfade2;
|
|
14141
|
+
const blendStart = Date.now();
|
|
14142
|
+
transitionFn(
|
|
14143
|
+
buffers.bufferA,
|
|
14144
|
+
buffers.bufferB,
|
|
14145
|
+
buffers.output,
|
|
14146
|
+
width,
|
|
14147
|
+
height,
|
|
14148
|
+
progress
|
|
14149
|
+
);
|
|
14150
|
+
addHdrTiming(hdrPerf, "transitionCompositeMs", blendStart);
|
|
14151
|
+
}
|
|
14152
|
+
await writeEncoded(frameIdx, buffers.output);
|
|
14153
|
+
})();
|
|
14154
|
+
ringInFlight[slot] = dispatch.then(() => void 0, fail);
|
|
14155
|
+
} else {
|
|
14156
|
+
const stackingInfo = await seekInjectAndQueryStacking(
|
|
14157
|
+
session.page,
|
|
14158
|
+
time,
|
|
14159
|
+
session.onBeforeCapture,
|
|
14160
|
+
nativeHdrIds,
|
|
14161
|
+
hdrPerf,
|
|
14162
|
+
"frameSeekMs",
|
|
14163
|
+
"frameInjectMs",
|
|
14164
|
+
"stackingQueryMs"
|
|
14165
|
+
);
|
|
14166
|
+
canvas.fill(0);
|
|
14167
|
+
const wctx = { ...hdrCompositeCtx, domSession: session };
|
|
14168
|
+
await timeHdrPhaseAsync(
|
|
14169
|
+
hdrPerf,
|
|
14170
|
+
"normalCompositeMs",
|
|
14171
|
+
() => compositeHdrFrame(wctx, canvas, time, stackingInfo, void 0, i)
|
|
14172
|
+
);
|
|
14173
|
+
if (debugDumpEnabled && debugDumpDir && i % 30 === 0) {
|
|
14174
|
+
writeFileExclusiveSync(
|
|
14175
|
+
join32(debugDumpDir, `frame_${String(i).padStart(4, "0")}_final_rgb48le.bin`),
|
|
14176
|
+
canvas
|
|
14103
14177
|
);
|
|
14104
|
-
addHdrTiming(hdrPerf, "transitionCompositeMs", blendStart);
|
|
14105
14178
|
}
|
|
14106
|
-
await writeEncoded(
|
|
14107
|
-
})();
|
|
14108
|
-
ringInFlight[slot] = dispatch.catch((err) => {
|
|
14109
|
-
throw err instanceof Error ? err : new Error(String(err));
|
|
14110
|
-
});
|
|
14111
|
-
} else {
|
|
14112
|
-
const stackingInfo = await seekInjectAndQueryStacking(
|
|
14113
|
-
session.page,
|
|
14114
|
-
time,
|
|
14115
|
-
session.onBeforeCapture,
|
|
14116
|
-
nativeHdrIds,
|
|
14117
|
-
hdrPerf,
|
|
14118
|
-
"frameSeekMs",
|
|
14119
|
-
"frameInjectMs",
|
|
14120
|
-
"stackingQueryMs"
|
|
14121
|
-
);
|
|
14122
|
-
canvas.fill(0);
|
|
14123
|
-
const wctx = { ...hdrCompositeCtx, domSession: session };
|
|
14124
|
-
await timeHdrPhaseAsync(
|
|
14125
|
-
hdrPerf,
|
|
14126
|
-
"normalCompositeMs",
|
|
14127
|
-
() => compositeHdrFrame(wctx, canvas, time, stackingInfo, void 0, i)
|
|
14128
|
-
);
|
|
14129
|
-
if (debugDumpEnabled && debugDumpDir && i % 30 === 0) {
|
|
14130
|
-
writeFileExclusiveSync(
|
|
14131
|
-
join32(debugDumpDir, `frame_${String(i).padStart(4, "0")}_final_rgb48le.bin`),
|
|
14132
|
-
canvas
|
|
14133
|
-
);
|
|
14179
|
+
await writeEncoded(i, canvas);
|
|
14134
14180
|
}
|
|
14135
|
-
await writeEncoded(i, canvas);
|
|
14136
14181
|
}
|
|
14182
|
+
} catch (err) {
|
|
14183
|
+
fail(err);
|
|
14184
|
+
} finally {
|
|
14185
|
+
await Promise.all(ringInFlight);
|
|
14137
14186
|
}
|
|
14138
|
-
|
|
14139
|
-
if (pending) await pending;
|
|
14140
|
-
}
|
|
14187
|
+
throwIfFailed();
|
|
14141
14188
|
};
|
|
14142
|
-
await Promise.
|
|
14189
|
+
await Promise.allSettled(sessions.map((_, w) => workerTaskOf(w)));
|
|
14190
|
+
throwIfFailed();
|
|
14143
14191
|
await reorderBuffer.waitForAllDone();
|
|
14144
14192
|
} finally {
|
|
14145
14193
|
for (const s of workerSessions) {
|
|
@@ -14231,23 +14279,27 @@ async function runCaptureHdrStage(input) {
|
|
|
14231
14279
|
assertNotAborted();
|
|
14232
14280
|
lastBrowserConsole = domSession.browserConsoleBuffer;
|
|
14233
14281
|
await initTransparentBackground2(domSession.page, { clearCompositionRoot: true });
|
|
14234
|
-
const transitionMeta =
|
|
14235
|
-
|
|
14236
|
-
|
|
14237
|
-
|
|
14238
|
-
|
|
14239
|
-
|
|
14240
|
-
|
|
14241
|
-
|
|
14242
|
-
const
|
|
14243
|
-
const
|
|
14244
|
-
|
|
14245
|
-
|
|
14282
|
+
const transitionMeta = sanitizeTransitionMeta(
|
|
14283
|
+
await domSession.page.evaluate(() => window.__hf?.transitions ?? []),
|
|
14284
|
+
(message, meta) => log.warn(message, meta)
|
|
14285
|
+
);
|
|
14286
|
+
const sceneElements = Object.assign(
|
|
14287
|
+
/* @__PURE__ */ Object.create(null),
|
|
14288
|
+
await domSession.page.evaluate(() => {
|
|
14289
|
+
const scenes = document.querySelectorAll(".scene");
|
|
14290
|
+
const map = {};
|
|
14291
|
+
for (const scene of scenes) {
|
|
14292
|
+
if (!scene.id) continue;
|
|
14293
|
+
const ids = /* @__PURE__ */ new Set([scene.id]);
|
|
14294
|
+
const els = scene.querySelectorAll("[id]");
|
|
14295
|
+
for (const el of els) {
|
|
14296
|
+
if (el.id) ids.add(el.id);
|
|
14297
|
+
}
|
|
14298
|
+
map[scene.id] = Array.from(ids);
|
|
14246
14299
|
}
|
|
14247
|
-
map
|
|
14248
|
-
}
|
|
14249
|
-
|
|
14250
|
-
});
|
|
14300
|
+
return map;
|
|
14301
|
+
})
|
|
14302
|
+
);
|
|
14251
14303
|
const fpsDecimal = fpsToNumber7(job.config.fps);
|
|
14252
14304
|
const transitionRanges = transitionMeta.map((t) => ({
|
|
14253
14305
|
...t,
|
|
@@ -15142,6 +15194,13 @@ var RenderCancelledError = class extends Error {
|
|
|
15142
15194
|
this.reason = reason;
|
|
15143
15195
|
}
|
|
15144
15196
|
};
|
|
15197
|
+
var EscapedRejectionError = class extends Error {
|
|
15198
|
+
constructor(cause) {
|
|
15199
|
+
super(cause.message, { cause });
|
|
15200
|
+
Object.assign(this, cause);
|
|
15201
|
+
this.name = cause.name;
|
|
15202
|
+
}
|
|
15203
|
+
};
|
|
15145
15204
|
function createRenderFileLogger(logPath, base = defaultLogger) {
|
|
15146
15205
|
const write = (prefix, args) => {
|
|
15147
15206
|
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -16568,7 +16627,7 @@ async function executeRenderPipeline(input) {
|
|
|
16568
16627
|
updateJobStatus(job, "rendering", "Checking browser GPU", 25, onProgress, {
|
|
16569
16628
|
code: "start_browsers"
|
|
16570
16629
|
});
|
|
16571
|
-
|
|
16630
|
+
let resolvedBrowserGpuMode = await resolveBrowserGpuMode(cfg.browserGpuMode, {
|
|
16572
16631
|
chromePath: resolveHeadlessShellPath(cfg),
|
|
16573
16632
|
browserTimeout: cfg.browserTimeout
|
|
16574
16633
|
});
|
|
@@ -16881,6 +16940,16 @@ async function executeRenderPipeline(input) {
|
|
|
16881
16940
|
"calibration"
|
|
16882
16941
|
) : void 0;
|
|
16883
16942
|
let outcome;
|
|
16943
|
+
let softwareOutcome;
|
|
16944
|
+
const calibrationInput = {
|
|
16945
|
+
fileServer: activeFileServer,
|
|
16946
|
+
log,
|
|
16947
|
+
job,
|
|
16948
|
+
totalFrames,
|
|
16949
|
+
buildCaptureOptions: buildPrepCaptureOptions,
|
|
16950
|
+
createRenderVideoFrameInjector: calibrationFrames ? calibrationFrames.injector : createRenderVideoFrameInjector,
|
|
16951
|
+
assertNotAborted
|
|
16952
|
+
};
|
|
16884
16953
|
try {
|
|
16885
16954
|
outcome = await observeRenderStage(
|
|
16886
16955
|
observability,
|
|
@@ -16893,19 +16962,34 @@ async function executeRenderPipeline(input) {
|
|
|
16893
16962
|
// ts=1784019503.
|
|
16894
16963
|
stagePhase: "calibrating"
|
|
16895
16964
|
}),
|
|
16896
|
-
() =>
|
|
16897
|
-
|
|
16898
|
-
|
|
16899
|
-
|
|
16900
|
-
|
|
16901
|
-
|
|
16902
|
-
|
|
16903
|
-
|
|
16904
|
-
probeSession
|
|
16905
|
-
|
|
16906
|
-
|
|
16907
|
-
|
|
16908
|
-
|
|
16965
|
+
async () => {
|
|
16966
|
+
const result = await runCaptureCalibration({
|
|
16967
|
+
...calibrationInput,
|
|
16968
|
+
cfg: calibrationCaptureConfig(cfg),
|
|
16969
|
+
workDir,
|
|
16970
|
+
forceScreenshot: captureForceScreenshot,
|
|
16971
|
+
probeSession
|
|
16972
|
+
});
|
|
16973
|
+
probeSession = result.probeSession;
|
|
16974
|
+
if (shouldCalibrateSoftwareGpu(
|
|
16975
|
+
cfg.browserGpuMode,
|
|
16976
|
+
resolvedBrowserGpuMode,
|
|
16977
|
+
result.calibration?.estimate
|
|
16978
|
+
)) {
|
|
16979
|
+
softwareOutcome = await runCaptureCalibration({
|
|
16980
|
+
...calibrationInput,
|
|
16981
|
+
cfg: calibrationCaptureConfig({ ...cfg, browserGpuMode: "software" }),
|
|
16982
|
+
workDir: join35(workDir, "software-gpu"),
|
|
16983
|
+
forceScreenshot: applyConcreteGpuScreenshotClamp(
|
|
16984
|
+
captureForceScreenshot,
|
|
16985
|
+
"software",
|
|
16986
|
+
cfg
|
|
16987
|
+
),
|
|
16988
|
+
probeSession: null
|
|
16989
|
+
});
|
|
16990
|
+
}
|
|
16991
|
+
return result;
|
|
16992
|
+
},
|
|
16909
16993
|
{ heartbeatMessage: "browser calibrating (frames not started)" }
|
|
16910
16994
|
);
|
|
16911
16995
|
} finally {
|
|
@@ -16916,15 +17000,41 @@ async function executeRenderPipeline(input) {
|
|
|
16916
17000
|
calibrationEvaluateTimedOut = outcome.calibrationEvaluateTimedOut;
|
|
16917
17001
|
captureForceScreenshot = outcome.forceScreenshot;
|
|
16918
17002
|
updateCaptureObservability({ forceScreenshot: captureForceScreenshot });
|
|
16919
|
-
probeSession = outcome.probeSession;
|
|
16920
17003
|
if (outcome.lastBrowserConsole.length > 0) {
|
|
16921
17004
|
lastBrowserConsole = outcome.lastBrowserConsole;
|
|
16922
17005
|
}
|
|
17006
|
+
if (softwareOutcome && outcome.calibration && pickAutoGpuModeFromCalibration(
|
|
17007
|
+
outcome.calibration.estimate,
|
|
17008
|
+
softwareOutcome.calibration?.estimate
|
|
17009
|
+
) === "software") {
|
|
17010
|
+
log.warn(
|
|
17011
|
+
"[Render] Auto GPU mode: software capture measured faster than the hardware GPU, rendering in software.",
|
|
17012
|
+
{
|
|
17013
|
+
hardwareP95Ms: outcome.calibration.estimate.p95Ms,
|
|
17014
|
+
softwareP95Ms: softwareOutcome.calibration?.estimate.p95Ms
|
|
17015
|
+
}
|
|
17016
|
+
);
|
|
17017
|
+
cfg.browserGpuMode = "software";
|
|
17018
|
+
resolvedBrowserGpuMode = "software";
|
|
17019
|
+
captureCalibration = softwareOutcome.calibration;
|
|
17020
|
+
captureForceScreenshot = softwareOutcome.forceScreenshot;
|
|
17021
|
+
if (probeSession) {
|
|
17022
|
+
lastBrowserConsole = probeSession.browserConsoleBuffer;
|
|
17023
|
+
await closeCaptureSession8(probeSession).catch(() => {
|
|
17024
|
+
});
|
|
17025
|
+
probeSession = null;
|
|
17026
|
+
}
|
|
17027
|
+
updateCaptureObservability({
|
|
17028
|
+
browserGpuMode: resolvedBrowserGpuMode,
|
|
17029
|
+
forceScreenshot: captureForceScreenshot
|
|
17030
|
+
});
|
|
17031
|
+
}
|
|
16923
17032
|
observability.checkpoint("capture_calibration", "resolved", {
|
|
16924
17033
|
forceScreenshot: captureForceScreenshot,
|
|
16925
|
-
|
|
16926
|
-
|
|
16927
|
-
|
|
17034
|
+
browserGpuMode: resolvedBrowserGpuMode,
|
|
17035
|
+
multiplier: captureCalibration?.estimate.multiplier ?? null,
|
|
17036
|
+
p95Ms: captureCalibration?.estimate.p95Ms ?? null,
|
|
17037
|
+
medianMs: captureCalibration?.estimate.medianMs ?? null
|
|
16928
17038
|
});
|
|
16929
17039
|
} else {
|
|
16930
17040
|
observability.checkpoint("capture_calibration", "skipped", {
|
|
@@ -18106,11 +18216,12 @@ async function executeRenderPipeline(input) {
|
|
|
18106
18216
|
framesRendered: job.framesRendered ?? 0,
|
|
18107
18217
|
error: caught
|
|
18108
18218
|
});
|
|
18219
|
+
const escapedRejection = executionSignal.reason instanceof EscapedRejectionError ? executionSignal.reason : void 0;
|
|
18109
18220
|
const error = surfaceScriptFailure(
|
|
18110
|
-
tooSlowError ?? audioFailure ?? pageNeverReady ?? caught,
|
|
18221
|
+
tooSlowError ?? audioFailure ?? escapedRejection ?? pageNeverReady ?? caught,
|
|
18111
18222
|
job
|
|
18112
18223
|
);
|
|
18113
|
-
if (!tooSlowError && !audioFailure && (error instanceof RenderCancelledError || executionSignal.aborted)) {
|
|
18224
|
+
if (!tooSlowError && !audioFailure && !escapedRejection && (error instanceof RenderCancelledError || executionSignal.aborted)) {
|
|
18114
18225
|
job.error = error instanceof Error ? error.message : "render_cancelled";
|
|
18115
18226
|
updateJobStatus(job, "cancelled", "Render cancelled", job.progress, onProgress);
|
|
18116
18227
|
await eventPublisher.flush();
|
|
@@ -19528,11 +19639,16 @@ function createRenderHandlers(options = {}) {
|
|
|
19528
19639
|
quality: input.quality
|
|
19529
19640
|
});
|
|
19530
19641
|
try {
|
|
19531
|
-
await
|
|
19532
|
-
|
|
19533
|
-
|
|
19534
|
-
|
|
19535
|
-
|
|
19642
|
+
await runInRenderScope(
|
|
19643
|
+
requestId,
|
|
19644
|
+
new AbortController(),
|
|
19645
|
+
(signal) => executeRenderJob(
|
|
19646
|
+
job,
|
|
19647
|
+
input.projectDir,
|
|
19648
|
+
absoluteOutputPath,
|
|
19649
|
+
createBlockingProgressReporter(log, requestId),
|
|
19650
|
+
signal
|
|
19651
|
+
)
|
|
19536
19652
|
);
|
|
19537
19653
|
const fileSize = outputFileSize(absoluteOutputPath);
|
|
19538
19654
|
const durationMs = Date.now() - t0;
|
|
@@ -19629,12 +19745,10 @@ function createRenderHandlers(options = {}) {
|
|
|
19629
19745
|
}, SSE_KEEPALIVE_MS);
|
|
19630
19746
|
const release = await renderSemaphore.acquire();
|
|
19631
19747
|
try {
|
|
19632
|
-
await
|
|
19633
|
-
|
|
19634
|
-
|
|
19635
|
-
absoluteOutputPath,
|
|
19636
|
-
reportProgress,
|
|
19637
|
-
abortController.signal
|
|
19748
|
+
await runInRenderScope(
|
|
19749
|
+
requestId,
|
|
19750
|
+
abortController,
|
|
19751
|
+
(signal) => executeRenderJob(job, input.projectDir, absoluteOutputPath, reportProgress, signal)
|
|
19638
19752
|
).finally(release);
|
|
19639
19753
|
clearInterval(keepalive);
|
|
19640
19754
|
const fileSize = outputFileSize(absoluteOutputPath);
|
|
@@ -19802,19 +19916,53 @@ function createProducerApp(options = {}) {
|
|
|
19802
19916
|
app.get("/outputs/:token", handlers.outputs);
|
|
19803
19917
|
return app;
|
|
19804
19918
|
}
|
|
19805
|
-
|
|
19806
|
-
|
|
19807
|
-
const
|
|
19808
|
-
|
|
19809
|
-
|
|
19919
|
+
var renderScope = new AsyncLocalStorage();
|
|
19920
|
+
function runInRenderScope(requestId, abortController, run) {
|
|
19921
|
+
const fail = (err) => abortController.abort(new EscapedRejectionError(err));
|
|
19922
|
+
return renderScope.run({ requestId, fail }, () => run(abortController.signal));
|
|
19923
|
+
}
|
|
19924
|
+
function onEscapedRejection(reason, log) {
|
|
19925
|
+
const err = reason instanceof Error ? reason : new Error(String(reason));
|
|
19926
|
+
const scope = renderScope.getStore();
|
|
19927
|
+
log.error("Unhandled promise rejection", {
|
|
19928
|
+
requestId: scope?.requestId ?? null,
|
|
19929
|
+
error: err.message,
|
|
19930
|
+
stack: err.stack
|
|
19931
|
+
});
|
|
19932
|
+
scope?.fail(err);
|
|
19933
|
+
}
|
|
19934
|
+
function serverAuth(options, hostname2, port) {
|
|
19935
|
+
const configured = resolveAuthToken(options);
|
|
19936
|
+
if (configured) return { token: configured };
|
|
19937
|
+
if (!isLoopbackHostname(hostname2)) {
|
|
19810
19938
|
throw new Error(
|
|
19811
19939
|
`Refusing to listen on ${hostname2} without an auth token. Set authToken or PRODUCER_AUTH_TOKEN, or listen on a loopback address.`
|
|
19812
19940
|
);
|
|
19813
19941
|
}
|
|
19814
|
-
const
|
|
19942
|
+
const file = resolve11(
|
|
19943
|
+
options.authTokenFile?.trim() || process.env.PRODUCER_AUTH_TOKEN_FILE?.trim() || join40(homedir(), ".hyperframes", "producer", `${port}.token`)
|
|
19944
|
+
);
|
|
19945
|
+
const token = crypto.randomBytes(32).toString("base64url");
|
|
19946
|
+
mkdirSync13(dirname19(file), { recursive: true, mode: 448 });
|
|
19947
|
+
rmSync14(file, { force: true });
|
|
19948
|
+
writeFileSync7(file, `${token}
|
|
19949
|
+
`, { flag: "wx", mode: 384 });
|
|
19950
|
+
return { token, generatedFile: file };
|
|
19951
|
+
}
|
|
19952
|
+
function startServer(options = {}) {
|
|
19953
|
+
const port = options.port ?? parseInt(process.env.PRODUCER_PORT ?? "9847", 10);
|
|
19954
|
+
const hostname2 = options.hostname || process.env.PRODUCER_HOST || "127.0.0.1";
|
|
19955
|
+
const log = options.logger ?? defaultLogger;
|
|
19956
|
+
const auth = serverAuth(options, hostname2, port);
|
|
19957
|
+
const app = createProducerApp({ ...options, authToken: auth.token });
|
|
19815
19958
|
const server = serve2({ fetch: app.fetch, port, hostname: hostname2 }, (info) => {
|
|
19816
19959
|
const address = info.family === "IPv6" ? `[${info.address}]` : info.address;
|
|
19817
19960
|
log.info(`Listening on http://${address}:${info.port}`);
|
|
19961
|
+
if (auth.generatedFile) {
|
|
19962
|
+
log.info(
|
|
19963
|
+
`No auth token was set, so this run made one: send "Authorization: Bearer <token>" with the token in ${auth.generatedFile}`
|
|
19964
|
+
);
|
|
19965
|
+
}
|
|
19818
19966
|
});
|
|
19819
19967
|
server.setTimeout(0);
|
|
19820
19968
|
server.requestTimeout = 0;
|
|
@@ -19825,6 +19973,7 @@ function startServer(options = {}) {
|
|
|
19825
19973
|
});
|
|
19826
19974
|
async function shutdown(signal) {
|
|
19827
19975
|
log.info(`Received ${signal}, shutting down`);
|
|
19976
|
+
if (auth.generatedFile) rmSync14(auth.generatedFile, { force: true });
|
|
19828
19977
|
const { drainBrowserPool } = await import("@hyperframes/engine");
|
|
19829
19978
|
await drainBrowserPool().catch(() => {
|
|
19830
19979
|
});
|
|
@@ -19846,6 +19995,7 @@ function startServer(options = {}) {
|
|
|
19846
19995
|
}, 3e4).unref();
|
|
19847
19996
|
}
|
|
19848
19997
|
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
|
19998
|
+
process.on("unhandledRejection", (reason) => onEscapedRejection(reason, log));
|
|
19849
19999
|
process.on("SIGINT", () => shutdown("SIGINT"));
|
|
19850
20000
|
return server;
|
|
19851
20001
|
}
|
|
@@ -19864,7 +20014,9 @@ export {
|
|
|
19864
20014
|
createRenderHandlers,
|
|
19865
20015
|
extractSafeRenderErrorCode,
|
|
19866
20016
|
extractSafeRenderErrorMetadata,
|
|
20017
|
+
onEscapedRejection,
|
|
19867
20018
|
parseRenderOptions,
|
|
19868
20019
|
prepareRenderBody,
|
|
20020
|
+
runInRenderScope,
|
|
19869
20021
|
startServer
|
|
19870
20022
|
};
|