@hyperframes/producer 0.9.92 → 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/dist/index.js CHANGED
@@ -5998,6 +5998,13 @@ function estimateMeasuredCaptureCostMultiplier(samples) {
5998
5998
  medianMs
5999
5999
  };
6000
6000
  }
6001
+ function shouldCalibrateSoftwareGpu(requestedMode, resolvedMode, hardware) {
6002
+ return requestedMode === "auto" && resolvedMode === "hardware" && hardware !== void 0 && hardware.multiplier > 1 && hardware.p95Ms !== void 0;
6003
+ }
6004
+ function pickAutoGpuModeFromCalibration(hardware, software) {
6005
+ if (hardware.p95Ms === void 0 || software?.p95Ms === void 0) return "hardware";
6006
+ return software.p95Ms < hardware.p95Ms ? "software" : "hardware";
6007
+ }
6001
6008
  function selectCaptureCalibrationFrames(totalFrames) {
6002
6009
  if (totalFrames <= 0) return [];
6003
6010
  const lastFrame = totalFrames - 1;
@@ -16638,7 +16645,7 @@ async function executeRenderPipeline(input) {
16638
16645
  updateJobStatus(job, "rendering", "Checking browser GPU", 25, onProgress, {
16639
16646
  code: "start_browsers"
16640
16647
  });
16641
- const resolvedBrowserGpuMode = await resolveBrowserGpuMode(cfg.browserGpuMode, {
16648
+ let resolvedBrowserGpuMode = await resolveBrowserGpuMode(cfg.browserGpuMode, {
16642
16649
  chromePath: resolveHeadlessShellPath(cfg),
16643
16650
  browserTimeout: cfg.browserTimeout
16644
16651
  });
@@ -16951,6 +16958,16 @@ async function executeRenderPipeline(input) {
16951
16958
  "calibration"
16952
16959
  ) : void 0;
16953
16960
  let outcome;
16961
+ let softwareOutcome;
16962
+ const calibrationInput = {
16963
+ fileServer: activeFileServer,
16964
+ log,
16965
+ job,
16966
+ totalFrames,
16967
+ buildCaptureOptions: buildPrepCaptureOptions,
16968
+ createRenderVideoFrameInjector: calibrationFrames ? calibrationFrames.injector : createRenderVideoFrameInjector,
16969
+ assertNotAborted
16970
+ };
16954
16971
  try {
16955
16972
  outcome = await observeRenderStage(
16956
16973
  observability,
@@ -16963,19 +16980,34 @@ async function executeRenderPipeline(input) {
16963
16980
  // ts=1784019503.
16964
16981
  stagePhase: "calibrating"
16965
16982
  }),
16966
- () => runCaptureCalibration({
16967
- cfg: calibrationCaptureConfig(cfg),
16968
- fileServer: activeFileServer,
16969
- workDir,
16970
- log,
16971
- job,
16972
- totalFrames,
16973
- forceScreenshot: captureForceScreenshot,
16974
- probeSession,
16975
- buildCaptureOptions: buildPrepCaptureOptions,
16976
- createRenderVideoFrameInjector: calibrationFrames ? calibrationFrames.injector : createRenderVideoFrameInjector,
16977
- assertNotAborted
16978
- }),
16983
+ async () => {
16984
+ const result = await runCaptureCalibration({
16985
+ ...calibrationInput,
16986
+ cfg: calibrationCaptureConfig(cfg),
16987
+ workDir,
16988
+ forceScreenshot: captureForceScreenshot,
16989
+ probeSession
16990
+ });
16991
+ probeSession = result.probeSession;
16992
+ if (shouldCalibrateSoftwareGpu(
16993
+ cfg.browserGpuMode,
16994
+ resolvedBrowserGpuMode,
16995
+ result.calibration?.estimate
16996
+ )) {
16997
+ softwareOutcome = await runCaptureCalibration({
16998
+ ...calibrationInput,
16999
+ cfg: calibrationCaptureConfig({ ...cfg, browserGpuMode: "software" }),
17000
+ workDir: join35(workDir, "software-gpu"),
17001
+ forceScreenshot: applyConcreteGpuScreenshotClamp(
17002
+ captureForceScreenshot,
17003
+ "software",
17004
+ cfg
17005
+ ),
17006
+ probeSession: null
17007
+ });
17008
+ }
17009
+ return result;
17010
+ },
16979
17011
  { heartbeatMessage: "browser calibrating (frames not started)" }
16980
17012
  );
16981
17013
  } finally {
@@ -16986,15 +17018,41 @@ async function executeRenderPipeline(input) {
16986
17018
  calibrationEvaluateTimedOut = outcome.calibrationEvaluateTimedOut;
16987
17019
  captureForceScreenshot = outcome.forceScreenshot;
16988
17020
  updateCaptureObservability({ forceScreenshot: captureForceScreenshot });
16989
- probeSession = outcome.probeSession;
16990
17021
  if (outcome.lastBrowserConsole.length > 0) {
16991
17022
  lastBrowserConsole = outcome.lastBrowserConsole;
16992
17023
  }
17024
+ if (softwareOutcome && outcome.calibration && pickAutoGpuModeFromCalibration(
17025
+ outcome.calibration.estimate,
17026
+ softwareOutcome.calibration?.estimate
17027
+ ) === "software") {
17028
+ log.warn(
17029
+ "[Render] Auto GPU mode: software capture measured faster than the hardware GPU, rendering in software.",
17030
+ {
17031
+ hardwareP95Ms: outcome.calibration.estimate.p95Ms,
17032
+ softwareP95Ms: softwareOutcome.calibration?.estimate.p95Ms
17033
+ }
17034
+ );
17035
+ cfg.browserGpuMode = "software";
17036
+ resolvedBrowserGpuMode = "software";
17037
+ captureCalibration = softwareOutcome.calibration;
17038
+ captureForceScreenshot = softwareOutcome.forceScreenshot;
17039
+ if (probeSession) {
17040
+ lastBrowserConsole = probeSession.browserConsoleBuffer;
17041
+ await closeCaptureSession8(probeSession).catch(() => {
17042
+ });
17043
+ probeSession = null;
17044
+ }
17045
+ updateCaptureObservability({
17046
+ browserGpuMode: resolvedBrowserGpuMode,
17047
+ forceScreenshot: captureForceScreenshot
17048
+ });
17049
+ }
16993
17050
  observability.checkpoint("capture_calibration", "resolved", {
16994
17051
  forceScreenshot: captureForceScreenshot,
16995
- multiplier: outcome.calibration?.estimate.multiplier ?? null,
16996
- p95Ms: outcome.calibration?.estimate.p95Ms ?? null,
16997
- medianMs: outcome.calibration?.estimate.medianMs ?? null
17052
+ browserGpuMode: resolvedBrowserGpuMode,
17053
+ multiplier: captureCalibration?.estimate.multiplier ?? null,
17054
+ p95Ms: captureCalibration?.estimate.p95Ms ?? null,
17055
+ medianMs: captureCalibration?.estimate.medianMs ?? null
16998
17056
  });
16999
17057
  } else {
17000
17058
  observability.checkpoint("capture_calibration", "skipped", {
@@ -6036,6 +6036,13 @@ function estimateMeasuredCaptureCostMultiplier(samples) {
6036
6036
  medianMs
6037
6037
  };
6038
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
+ }
6039
6046
  function selectCaptureCalibrationFrames(totalFrames) {
6040
6047
  if (totalFrames <= 0) return [];
6041
6048
  const lastFrame = totalFrames - 1;
@@ -16620,7 +16627,7 @@ async function executeRenderPipeline(input) {
16620
16627
  updateJobStatus(job, "rendering", "Checking browser GPU", 25, onProgress, {
16621
16628
  code: "start_browsers"
16622
16629
  });
16623
- const resolvedBrowserGpuMode = await resolveBrowserGpuMode(cfg.browserGpuMode, {
16630
+ let resolvedBrowserGpuMode = await resolveBrowserGpuMode(cfg.browserGpuMode, {
16624
16631
  chromePath: resolveHeadlessShellPath(cfg),
16625
16632
  browserTimeout: cfg.browserTimeout
16626
16633
  });
@@ -16933,6 +16940,16 @@ async function executeRenderPipeline(input) {
16933
16940
  "calibration"
16934
16941
  ) : void 0;
16935
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
+ };
16936
16953
  try {
16937
16954
  outcome = await observeRenderStage(
16938
16955
  observability,
@@ -16945,19 +16962,34 @@ async function executeRenderPipeline(input) {
16945
16962
  // ts=1784019503.
16946
16963
  stagePhase: "calibrating"
16947
16964
  }),
16948
- () => runCaptureCalibration({
16949
- cfg: calibrationCaptureConfig(cfg),
16950
- fileServer: activeFileServer,
16951
- workDir,
16952
- log,
16953
- job,
16954
- totalFrames,
16955
- forceScreenshot: captureForceScreenshot,
16956
- probeSession,
16957
- buildCaptureOptions: buildPrepCaptureOptions,
16958
- createRenderVideoFrameInjector: calibrationFrames ? calibrationFrames.injector : createRenderVideoFrameInjector,
16959
- assertNotAborted
16960
- }),
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
+ },
16961
16993
  { heartbeatMessage: "browser calibrating (frames not started)" }
16962
16994
  );
16963
16995
  } finally {
@@ -16968,15 +17000,41 @@ async function executeRenderPipeline(input) {
16968
17000
  calibrationEvaluateTimedOut = outcome.calibrationEvaluateTimedOut;
16969
17001
  captureForceScreenshot = outcome.forceScreenshot;
16970
17002
  updateCaptureObservability({ forceScreenshot: captureForceScreenshot });
16971
- probeSession = outcome.probeSession;
16972
17003
  if (outcome.lastBrowserConsole.length > 0) {
16973
17004
  lastBrowserConsole = outcome.lastBrowserConsole;
16974
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
+ }
16975
17032
  observability.checkpoint("capture_calibration", "resolved", {
16976
17033
  forceScreenshot: captureForceScreenshot,
16977
- multiplier: outcome.calibration?.estimate.multiplier ?? null,
16978
- p95Ms: outcome.calibration?.estimate.p95Ms ?? null,
16979
- medianMs: outcome.calibration?.estimate.medianMs ?? null
17034
+ browserGpuMode: resolvedBrowserGpuMode,
17035
+ multiplier: captureCalibration?.estimate.multiplier ?? null,
17036
+ p95Ms: captureCalibration?.estimate.p95Ms ?? null,
17037
+ medianMs: captureCalibration?.estimate.medianMs ?? null
16980
17038
  });
16981
17039
  } else {
16982
17040
  observability.checkpoint("capture_calibration", "skipped", {
@@ -62,6 +62,10 @@ export declare function resolveRenderWorkerCount(totalFrames: number, requestedW
62
62
  onSizing?: (sizing: WorkerSizing) => void): number;
63
63
  export declare function createCaptureCalibrationConfig(cfg: EngineConfig): EngineConfig;
64
64
  export declare function estimateMeasuredCaptureCostMultiplier(samples: CaptureCalibrationSample[]): CaptureCostEstimate;
65
+ /** Auto mode chose the hardware GPU and calibration measured it slow: worth timing software too. */
66
+ export declare function shouldCalibrateSoftwareGpu(requestedMode: EngineConfig["browserGpuMode"], resolvedMode: "software" | "hardware", hardware: CaptureCostEstimate | undefined): boolean;
67
+ /** Auto mode keeps the hardware GPU unless software measured strictly faster. */
68
+ export declare function pickAutoGpuModeFromCalibration(hardware: CaptureCostEstimate, software: CaptureCostEstimate | undefined): "software" | "hardware";
65
69
  export declare function selectCaptureCalibrationFrames(totalFrames: number): number[];
66
70
  export declare function measureCaptureCostFromSession(session: CaptureSession, totalFrames: number, fps: number, log?: ProducerLogger): Promise<{
67
71
  estimate: CaptureCostEstimate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/producer",
3
- "version": "0.9.92",
3
+ "version": "0.9.93",
4
4
  "description": "HTML-to-video rendering engine using Chrome's BeginFrame API",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,11 +35,11 @@
35
35
  "postcss": "^8.4.0",
36
36
  "puppeteer": "~25.13.0",
37
37
  "puppeteer-core": "^25.13.0",
38
- "@hyperframes/core": "0.9.92",
39
- "@hyperframes/engine": "0.9.92",
40
- "@hyperframes/studio-server": "0.9.92",
41
- "@hyperframes/lint": "0.9.92",
42
- "@hyperframes/parsers": "0.9.92"
38
+ "@hyperframes/core": "0.9.93",
39
+ "@hyperframes/engine": "0.9.93",
40
+ "@hyperframes/parsers": "0.9.93",
41
+ "@hyperframes/lint": "0.9.93",
42
+ "@hyperframes/studio-server": "0.9.93"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/node": "^25.0.10",
@@ -48,7 +48,7 @@
48
48
  "tsx": "^4.21.0",
49
49
  "typescript": "^5.7.2",
50
50
  "vitest": "^4.1.12",
51
- "@hyperframes/aws-lambda": "0.9.92"
51
+ "@hyperframes/aws-lambda": "0.9.93"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">=22"