Skip to content
Open
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
24 changes: 24 additions & 0 deletions packages/producer/src/services/render/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type { AudioElement, EngineConfig, ImageElement, VideoElement } from "@hy
import type { CompiledComposition } from "../htmlCompiler.js";
import { defaultLogger, type ProducerLogger } from "../../logger.js";
import { isPathInside } from "../../utils/paths.js";
import type { ProgressCallback, RenderJob, RenderStatus } from "../renderOrchestrator.js";

export interface CompositionMetadata {
duration: number;
Expand Down Expand Up @@ -202,3 +203,26 @@ export function applyRenderModeHints(
reasons: compiled.renderModeHints.reasons.map((reason) => reason.message),
});
}

/**
* Mutate the `RenderJob` view of the pipeline's progress and fire the
* caller's `onProgress` callback. Hoisted here (out of `renderOrchestrator.ts`)
* so the stage modules can call it without forming a runtime cycle.
*
* `completedAt` is stamped on the terminal `"failed"` / `"complete"`
* transitions so callers that poll the job state can tell when the
* pipeline finished.
*/
export function updateJobStatus(
job: RenderJob,
status: RenderStatus,
stage: string,
progress: number,
onProgress?: ProgressCallback,
): void {
job.status = status;
job.currentStage = stage;
job.progress = progress;
if (status === "failed" || status === "complete") job.completedAt = new Date();
if (onProgress) onProgress(job, stage);
}
7 changes: 2 additions & 5 deletions packages/producer/src/services/render/stages/assembleStage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
*/

import { applyFaststart, muxVideoWithAudio } from "@hyperframes/engine";
import {
updateJobStatus,
type ProgressCallback,
type RenderJob,
} from "../../renderOrchestrator.js";
import type { ProgressCallback, RenderJob } from "../../renderOrchestrator.js";
import { updateJobStatus } from "../shared.js";

export interface AssembleStageInput {
job: RenderJob;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ import {
compositeHdrFrame,
createHdrPerfCollector,
resolveCompositeTransfer,
updateJobStatus,
} from "../../renderOrchestrator.js";
import { type CompositionMetadata } from "../shared.js";
import { updateJobStatus, type CompositionMetadata } from "../shared.js";

export interface CaptureHdrStageInput {
job: RenderJob;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ import type { FileServerHandle } from "../../fileServer.js";
import type { ProducerLogger } from "../../../logger.js";
import {
executeDiskCaptureWithAdaptiveRetry,
updateJobStatus,
type CaptureAttemptSummary,
type ProgressCallback,
type RenderJob,
} from "../../renderOrchestrator.js";
import { updateJobStatus } from "../shared.js";

export interface CaptureStageInput {
fileServer: FileServerHandle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,8 @@ import {
} from "@hyperframes/engine";
import type { FileServerHandle } from "../../fileServer.js";
import type { ProducerLogger } from "../../../logger.js";
import {
updateJobStatus,
type ProgressCallback,
type RenderJob,
} from "../../renderOrchestrator.js";
import type { ProgressCallback, RenderJob } from "../../renderOrchestrator.js";
import { updateJobStatus } from "../shared.js";

/**
* Pre-built ffmpeg streaming-encoder options, exactly matching the
Expand Down
7 changes: 2 additions & 5 deletions packages/producer/src/services/render/stages/encodeStage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ import {
getEncoderPreset,
} from "@hyperframes/engine";
import type { ProducerLogger } from "../../../logger.js";
import {
updateJobStatus,
type ProgressCallback,
type RenderJob,
} from "../../renderOrchestrator.js";
import type { ProgressCallback, RenderJob } from "../../renderOrchestrator.js";
import { updateJobStatus } from "../shared.js";

export interface EncodeStageInput {
job: RenderJob;
Expand Down
15 changes: 1 addition & 14 deletions packages/producer/src/services/renderOrchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import { type CompiledComposition } from "./htmlCompiler.js";
import { defaultLogger, type ProducerLogger } from "../logger.js";
import { isPathInside } from "../utils/paths.js";
import { type HdrImageTransferCache } from "./hdrImageTransferCache.js";
import { updateJobStatus } from "./render/shared.js";
import { runCompileStage } from "./render/stages/compileStage.js";
import { runProbeStage } from "./render/stages/probeStage.js";
import { runExtractVideosStage } from "./render/stages/extractVideosStage.js";
Expand Down Expand Up @@ -544,20 +545,6 @@ export class RenderCancelledError extends Error {
}
}

export function updateJobStatus(
job: RenderJob,
status: RenderStatus,
stage: string,
progress: number,
onProgress?: ProgressCallback,
): void {
job.status = status;
job.currentStage = stage;
job.progress = progress;
if (status === "failed" || status === "complete") job.completedAt = new Date();
if (onProgress) onProgress(job, stage);
}

function installDebugLogger(logPath: string, log: ProducerLogger = defaultLogger): () => void {
const origLog = console.log;
const origError = console.error;
Expand Down
Loading