Skip to main content

moq_transcode/
config.rs

1//! Transcoder configuration: the rung ladder and catalog wiring.
2
3use moq_net::path::RelativeOwned;
4
5use crate::Ladder;
6
7/// Transcoder configuration for [`run`](crate::run).
8///
9/// `#[non_exhaustive]`: build via `Config::default()` and set fields, so future
10/// knobs don't break callers.
11#[derive(Clone, Debug, Default)]
12#[non_exhaustive]
13pub struct Config {
14	/// Candidate output renditions, lowest first. Only rungs strictly below the
15	/// source survive: a rung is dropped when its height exceeds the source, when
16	/// its bitrate is not below the source bitrate (when known), or when it
17	/// matches the source height without a known source bitrate to undercut. A
18	/// 480p source is never transcoded up to 720p.
19	///
20	/// Filtering drops rungs but never reorders them, so the surviving ladder is
21	/// still ascending. Build it with [`Ladder::new`](crate::Ladder::new), which
22	/// takes the rungs in any order and refuses an ambiguous ladder.
23	pub ladder: Ladder,
24
25	/// Where the source broadcast lives relative to the output broadcast, e.g.
26	/// `"."` when the output is published at `<source>/transcode.hang`. When
27	/// set, the derivative catalog references the source renditions (all video
28	/// and audio) through this path so players fetch them from the source
29	/// directly; the transcoder never proxies or subscribes them. `None` omits
30	/// them from the derivative catalog.
31	pub source: Option<RelativeOwned>,
32
33	/// Which video encoder implementation encodes the rungs. The default
34	/// prefers hardware (NVENC on Linux, VideoToolbox on macOS, Media
35	/// Foundation on Windows) and falls back to OpenH264 when enabled.
36	pub encoder: moq_video::encode::Kind,
37
38	/// Which video decoder implementation decodes the source. The default
39	/// prefers hardware and falls back to OpenH264 when enabled (H.264 only;
40	/// H.265 sources need a hardware decoder).
41	pub decoder: moq_video::decode::Kind,
42
43	/// Where decoded and resized frames live. Native output keeps GPU-backed
44	/// frames on the GPU from decode through encode; CPU output downloads at
45	/// the decoder and scales on the CPU.
46	pub resize: moq_video::resize::Config,
47}
48
49impl Config {
50	/// The decoder the shared live feed opens: the configured implementation,
51	/// delivering frames where the resize expects them. No scale hint, since
52	/// the feed decodes once at native size for every rung.
53	pub(crate) fn feed_decoder(&self) -> moq_video::decode::Config {
54		let mut decoder = moq_video::decode::Config::new();
55		decoder.kind = self.decoder.clone();
56		decoder.output = self.resize.output;
57		decoder
58	}
59}