mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-03 04:38:33 +00:00
fix(producer): pass streaming encoder config (#1147)
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
import { describe, expect, it, mock } from "bun:test";
|
||||
|
||||
type MinimalEngineConfig = {
|
||||
forceScreenshot: boolean;
|
||||
ffmpegStreamingTimeout: number;
|
||||
};
|
||||
|
||||
const writeFrame = mock((_buffer: Buffer) => true);
|
||||
const closeEncoder = mock(async () => ({ success: true, durationMs: 123, fileSize: 42 }));
|
||||
const spawnStreamingEncoder = mock(async () => ({
|
||||
writeFrame,
|
||||
close: closeEncoder,
|
||||
getExitStatus: () => "success",
|
||||
}));
|
||||
|
||||
mock.module("@hyperframes/engine", () => ({
|
||||
captureFrameToBuffer: async () => ({ buffer: Buffer.from("frame"), captureTimeMs: 1 }),
|
||||
closeCaptureSession: async () => {},
|
||||
createCaptureSession: async () => ({ isInitialized: false, browserConsoleBuffer: [] }),
|
||||
createFrameReorderBuffer: () => ({
|
||||
waitForFrame: async () => {},
|
||||
advanceTo: () => {},
|
||||
}),
|
||||
distributeFrames: () => [],
|
||||
executeParallelCapture: async () => {},
|
||||
initializeSession: async (session: { isInitialized: boolean }) => {
|
||||
session.isInitialized = true;
|
||||
},
|
||||
prepareCaptureSessionForReuse: () => {},
|
||||
spawnStreamingEncoder,
|
||||
}));
|
||||
|
||||
mock.module("@hyperframes/core", () => ({
|
||||
CANVAS_DIMENSIONS: {},
|
||||
}));
|
||||
|
||||
function createInput(cfg: MinimalEngineConfig) {
|
||||
return {
|
||||
fileServer: {
|
||||
url: "http://127.0.0.1:4173",
|
||||
port: 4173,
|
||||
close: () => {},
|
||||
addPreHeadScript: () => {},
|
||||
},
|
||||
workDir: "/tmp/hf-test-work",
|
||||
framesDir: "/tmp/hf-test-frames",
|
||||
videoOnlyPath: "/tmp/hf-test-video-only.mp4",
|
||||
job: {
|
||||
id: "streaming-config-test",
|
||||
config: { fps: { num: 30, den: 1 }, quality: "draft" },
|
||||
status: "queued",
|
||||
progress: 0,
|
||||
currentStage: "Streaming",
|
||||
createdAt: new Date(0),
|
||||
duration: 0,
|
||||
},
|
||||
totalFrames: 0,
|
||||
cfg,
|
||||
forceScreenshot: false,
|
||||
log: {
|
||||
error: () => {},
|
||||
warn: () => {},
|
||||
info: () => {},
|
||||
debug: () => {},
|
||||
},
|
||||
workerCount: 1,
|
||||
probeSession: null,
|
||||
outputFormat: "mp4",
|
||||
streamingEncoderOptions: { fps: { num: 30, den: 1 }, width: 1920, height: 1080 },
|
||||
buildCaptureOptions: () => ({}),
|
||||
createRenderVideoFrameInjector: () => null,
|
||||
abortSignal: undefined,
|
||||
assertNotAborted: () => {},
|
||||
};
|
||||
}
|
||||
|
||||
describe("runCaptureStreamingStage", () => {
|
||||
it("passes the resolved engine config to spawnStreamingEncoder", async () => {
|
||||
const { runCaptureStreamingStage } = await import("./captureStreamingStage.js");
|
||||
const cfg = { forceScreenshot: false, ffmpegStreamingTimeout: 3_600_000 };
|
||||
const input = createInput(cfg);
|
||||
|
||||
const result = await runCaptureStreamingStage(input);
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
expect(spawnStreamingEncoder.mock.calls[0]?.[3]).toBe(cfg);
|
||||
});
|
||||
});
|
||||
@@ -160,6 +160,7 @@ export async function runCaptureStreamingStage(
|
||||
videoOnlyPath,
|
||||
streamingEncoderOptions,
|
||||
abortSignal,
|
||||
cfg,
|
||||
);
|
||||
assertNotAborted();
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user