rivet/encoder_worker/config.rs
1//! Worker configuration + output types.
2
3use std::path::PathBuf;
4use std::sync::Arc;
5use std::sync::RwLock;
6use codec::frame::{ColorMetadata, PixelFormat, VideoCodec};
7use container::cmaf::SegmentInfo;
8use super::RungCodecInvariant;
9
10#[derive(Clone)]
11pub struct EncoderWorkerConfig {
12 pub rung_idx: usize,
13 /// Output video codec (AV1 / H.264 / H.265) — drives the encoder dispatch
14 /// and the per-rung codec invariant parse.
15 pub codec: VideoCodec,
16 pub width: u32,
17 pub height: u32,
18 pub frame_rate: f64,
19 /// Legacy CRF escape hatch (`u8::MAX` = derive from `target`).
20 pub quality: u8,
21 /// Speed preset escape hatch (`u8::MAX` = derive from `tier`).
22 pub speed_preset: u8,
23 /// Perceptual quality target (used when `quality` is the sentinel).
24 pub target: codec::encode::tuning::QualityTarget,
25 /// Speed tier (used when `speed_preset` is the sentinel).
26 pub tier: codec::encode::tuning::SpeedTier,
27 pub threads: usize,
28 pub gpu_index: Option<u32>,
29 pub gpu_vendor: Option<codec::gpu::GpuVendor>,
30 /// Resolved **output** color metadata + pixel format (the encoder's input
31 /// format and bitstream signaling). The engine computes these from the
32 /// `OutputSpec`'s `ColorPolicy` / `BitDepth` via `resolve_output`, so the
33 /// worker no longer folds HDR→SDR itself — it just encodes to this format.
34 pub output_color_metadata: ColorMetadata,
35 pub output_pixel_format: PixelFormat,
36 /// Prefer constant-QP rate control (seam-flat chunked single-file under
37 /// `ChunkSeamMode::ParallelConstQp`). Forwarded to `EncoderConfig.constant_qp`.
38 pub constant_qp: bool,
39 pub timescale: u32,
40 pub per_frame_ticks: u32,
41 pub keyframe_interval: u32,
42 pub segment_target_ticks: u64,
43 pub output_dir: PathBuf,
44 /// Shared per-rung codec invariant slot. First worker on the rung
45 /// SETS it; helpers (any vendor) COMPARE on their first packet.
46 /// On mismatch the helper requeues its chunk and exits cleanly so
47 /// the run continues without it — never aborts mission-critical
48 /// jobs. See `validate_or_set_rung_invariant` + the requeue path
49 /// in `run_encoder_worker_blocking`.
50 pub rung_invariant: Arc<RwLock<Option<RungCodecInvariant>>>,
51}
52
53#[derive(Debug, Clone)]
54pub struct WorkerOutput {
55 pub gpu_index: Option<u32>,
56 pub segments: Vec<SegmentInfo>,
57}