Skip to main content

Module encoder_worker

Module encoder_worker 

Source
Expand description

Per-segment encoder worker: pop a chunk → encode K frames → emit one CMAF segment file → repeat.

v2 multi-GPU model (2026-05-11): each worker owns one GPU lease and one encoder for its lifetime, but builds a fresh CmafVideoMuxer per claimed segment. The muxer is configured with the segment’s index + base decode time so the on-disk filename + tfdt match what a single-encoder pipeline would produce. Helpers attaching mid-flight just start popping from the queue’s current head; no decode-and-discard.

Workers exit when queue.pop() returns None (pump closed + queue drained). The returned WorkerOutput lists every segment the worker wrote so the orchestrator can merge contributions into the per-rung manifest.

Structs§

ChunkPackets
One chunk’s encoded packets, in encode (= display, no B-frames) order.
EncoderWorkerConfig
RungCodecInvariant
Mandatory AV1 sequence-header fields that every encoder contributing segments to a single rendition MUST agree on.
WorkerOutput

Enums§

InvariantCheck
Outcome of comparing a worker’s first packet against the rung’s codec invariant. The caller — run_encoder_worker_blocking — branches on this to decide whether to keep encoding, soft-fail (requeue the chunk for another worker), or hard-fail (parse error from a malformed bitstream).

Functions§

run_chunk_encoder_worker_blocking
Encoder worker that COLLECTS packets per chunk (single-file path). Each chunk is encoded by a fresh encoder (first frame an IDR); the cross-vendor codec invariant is enforced on the first packet (mismatch → requeue + exit, exactly like the CMAF worker). Ordered ChunkPackets are pushed to out.
run_encoder_worker_blocking
Run the encoder loop until the chunk queue is closed and drained. Designed to be wrapped in tokio::task::spawn_blocking.
validate_or_set_rung_invariant
Parse a worker’s first packet, derive the codec invariant, and compare-or-set it against the per-rung slot. Returns InvariantCheck on a successful parse; an Err only on malformed bitstream (the encoder failed to emit an OBU_SEQUENCE_HEADER at all, which is a configuration bug that nothing downstream can recover from).