From 10d63f004bcdfeb03d41ce9cccb313bdaaec1fe0 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 24 Oct 2026 09:28:46 -0700 Subject: [PATCH 1/2] chore(quest): claim quest/m1/api-audit/frame-rate.md Quest-Claim: 446deeb7fa2f20e4 From 1a2b7320cc2aba5b54bcebdba371f59c136969ed Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 24 Oct 2026 09:32:57 -0700 Subject: [PATCH 2/2] refactor(moq-video)!: rename Rate to FrameRate The bindings already call the type FrameRate (moq_video_frame_rate in C, VideoFrameRate in C++, FrameRate in every wrapper), so the core type takes the same name. RateError becomes FrameRateError alongside it. Co-Authored-By: Claude Opus 5.5 --- demo/carla/bridge/src/stream.rs | 4 +- quest/m1/api-audit/README.md | 1 - quest/m1/api-audit/frame-rate.md | 18 ----- rs/moq-boy/src/video.rs | 3 +- rs/moq-c/src/test.rs | 2 +- rs/moq-c/src/video.rs | 6 +- rs/moq-cli/src/play/media.rs | 2 +- rs/moq-cli/src/publish.rs | 2 +- rs/moq-ffi/src/video.rs | 7 +- rs/moq-transcode/src/active.rs | 4 +- rs/moq-transcode/src/catalog.rs | 16 ++-- rs/moq-transcode/src/error.rs | 2 +- rs/moq-transcode/src/lib.rs | 12 +-- rs/moq-transcode/src/rung.rs | 4 +- rs/moq-video/MIGRATE.md | 5 ++ rs/moq-video/examples/d3d11-resize-probe.rs | 4 +- rs/moq-video/examples/encode-presets.rs | 4 +- rs/moq-video/src/capture/mediafoundation.rs | 4 +- rs/moq-video/src/capture/mod.rs | 16 ++-- rs/moq-video/src/capture/mode.rs | 18 ++--- rs/moq-video/src/capture/pipewire.rs | 4 +- rs/moq-video/src/capture/pipewire/camera.rs | 30 ++++---- rs/moq-video/src/capture/pump.rs | 4 +- rs/moq-video/src/capture/v4l2.rs | 24 +++--- rs/moq-video/src/capture/wgc.rs | 2 +- rs/moq-video/src/capture/wgc/native.rs | 6 +- rs/moq-video/src/capture/x11.rs | 4 +- rs/moq-video/src/decode/backend/mediacodec.rs | 2 +- rs/moq-video/src/decode/backend/nvdec.rs | 10 +-- rs/moq-video/src/decode/backend/vaapi.rs | 6 +- rs/moq-video/src/decode/consumer.rs | 4 +- rs/moq-video/src/decode/decoder.rs | 14 ++-- rs/moq-video/src/decode/vui.rs | 2 +- rs/moq-video/src/encode/backend/mediacodec.rs | 4 +- .../src/encode/backend/mediafoundation.rs | 2 +- rs/moq-video/src/encode/backend/mod.rs | 2 +- rs/moq-video/src/encode/backend/nvenc.rs | 18 ++--- rs/moq-video/src/encode/backend/openh264.rs | 6 +- rs/moq-video/src/encode/backend/v4l2.rs | 2 +- rs/moq-video/src/encode/backend/vaapi.rs | 8 +- .../src/encode/backend/videotoolbox.rs | 2 +- rs/moq-video/src/encode/encoder.rs | 74 +++++++++---------- rs/moq-video/src/encode/producer.rs | 31 ++++---- rs/moq-video/src/encode/sink.rs | 4 +- rs/moq-video/src/frame/cuda_test.rs | 4 +- rs/moq-video/src/{rate.rs => frame_rate.rs} | 58 ++++++++------- rs/moq-video/src/lib.rs | 4 +- rs/moq-video/src/render/renderer.rs | 4 +- rs/moq-video/src/size.rs | 8 +- rs/moq-video/src/v4l2.rs | 2 +- 50 files changed, 238 insertions(+), 241 deletions(-) delete mode 100644 quest/m1/api-audit/frame-rate.md rename rs/moq-video/src/{rate.rs => frame_rate.rs} (74%) diff --git a/demo/carla/bridge/src/stream.rs b/demo/carla/bridge/src/stream.rs index 1cc018eea80..3f5b41da1a9 100644 --- a/demo/carla/bridge/src/stream.rs +++ b/demo/carla/bridge/src/stream.rs @@ -16,7 +16,7 @@ use bytes::Bytes; use moq_mux::codec::annexb; use moq_video::encode::{Encoder, Kind}; use moq_video::frame::vulkan::{self, Device}; -use moq_video::{Color, Frame, I420, Rate, Size, Surface}; +use moq_video::{Color, Frame, FrameRate, I420, Size, Surface}; use parking_lot::Mutex; use crate::protocol::{self, Event, Rendition}; @@ -597,7 +597,7 @@ impl Encoding { } fn config(rendition: &Rendition, device: Device) -> Result { - let framerate = Rate::new(rendition.framerate, 1).context("framerate")?; + let framerate = FrameRate::new(rendition.framerate, 1).context("framerate")?; let mut config = moq_video::encode::Config::new(rendition.width, rendition.height, framerate); config.bitrate = Some(moq_net::bandwidth::Rate::from_bps(rendition.bitrate)); config.kind = Kind::Named("nvenc".into()); diff --git a/quest/m1/api-audit/README.md b/quest/m1/api-audit/README.md index c68d43362f1..5f2f18ecf85 100644 --- a/quest/m1/api-audit/README.md +++ b/quest/m1/api-audit/README.md @@ -73,7 +73,6 @@ Rejected in planning: - [Derived origins borrow](/quest/m1/api-audit/derived-origin-close.md) - closing a JS `scope()` handle releases only that handle - [Bindings read gaps and ends](/quest/m1/api-audit/decode-read-bindings.md) - moq-ffi and every wrapper surface `Gap` and `End` instead of discarding them - [Media surface trim](/quest/m1/api-audit/media-trim.md) - media crate items with no consumer go private, and Rust/JS media names agree -- [One frame rate name](/quest/m1/api-audit/frame-rate.md) - core `moq_video::Rate` becomes `FrameRate`, as the bindings name it - [Pinned consumers adopt the CLI flag names](/quest/m1/api-audit/cli-flags-consumers.md) - pinned downstream deployments move past the flag rename and use its spellings - [Transport config](/quest/m1/api-audit/transport-config.md) - moq-tokio and moq-quic configs have one meaning for unset, enums for modes, no order-dependent setters, and no leftover features - [Session-only items stay private](/quest/m1/api-audit/model-private.md) - model items only the built-in sessions use are private diff --git a/quest/m1/api-audit/frame-rate.md b/quest/m1/api-audit/frame-rate.md deleted file mode 100644 index e064e4d33d8..00000000000 --- a/quest/m1/api-audit/frame-rate.md +++ /dev/null @@ -1,18 +0,0 @@ -# [S] One frame rate name - -## Goal - -Rust's `moq_video::Rate` is `moq_video::FrameRate`, the name the bindings -already use (`moq_video_frame_rate` in C, `VideoFrameRate` in C++), so the -type has one name across Rust, JS, and the bindings. - -## Plan - -The bindings name the type `FrameRate` and leave the core `Rate` -(`rs/moq-video/src/rate.rs`) as is. Rename the core type and its uses in -moq-video, moq-transcode, moq-cli, moq-boy, moq-c, and moq-ffi (about 137 -references); the Impact bullet says how to migrate each published crate. - -Decided 2026-10-23 (maintainer): rename the core type, not the bindings. - -Public API: breaking rename in moq-video. Wire: none. diff --git a/rs/moq-boy/src/video.rs b/rs/moq-boy/src/video.rs index fec0995ac6a..b7c6ab35514 100644 --- a/rs/moq-boy/src/video.rs +++ b/rs/moq-boy/src/video.rs @@ -50,7 +50,8 @@ impl VideoEncoder { // Game Boy is 160x144; force the openh264 software encoder since hardware // encoders can reject such tiny resolutions. - let mut config = moq_video::encode::Config::new(WIDTH, HEIGHT, moq_video::Rate::new(FRAMERATE, 1).unwrap()); + let mut config = + moq_video::encode::Config::new(WIDTH, HEIGHT, moq_video::FrameRate::new(FRAMERATE, 1).unwrap()); config.kind = moq_video::encode::Kind::Software; // Probed from a throwaway encoder, before the emulator has run a frame, so a diff --git a/rs/moq-c/src/test.rs b/rs/moq-c/src/test.rs index bd55cdacc5b..e1775a5041d 100644 --- a/rs/moq-c/src/test.rs +++ b/rs/moq-c/src/test.rs @@ -4767,7 +4767,7 @@ fn video_raw_publish_rejects_invalid_config() { #[test] fn video_raw_decode() { // Encode a few gray frames to Annex-B (avc3, SPS/PPS inline on the keyframe). - let mut config = moq_video::encode::Config::new(320, 240, moq_video::Rate::new(30, 1).unwrap()); + let mut config = moq_video::encode::Config::new(320, 240, moq_video::FrameRate::new(30, 1).unwrap()); config.kind = moq_video::encode::Kind::Software; let mut encoder = moq_video::encode::Encoder::new(&config).expect("openh264 encoder"); let gray = vec![0x80u8; 320 * 240 * 4]; diff --git a/rs/moq-c/src/video.rs b/rs/moq-c/src/video.rs index 1906cefd98d..76962da542f 100644 --- a/rs/moq-c/src/video.rs +++ b/rs/moq-c/src/video.rs @@ -739,7 +739,7 @@ pub unsafe extern "C" fn moq_encode_video( let format = pixel_format_from_u32(raw_input.format)?; - let framerate = moq_video::Rate::new(raw_input.framerate.numerator, raw_input.framerate.denominator) + let framerate = moq_video::FrameRate::new(raw_input.framerate.numerator, raw_input.framerate.denominator) .map_err(|err| Error::InvalidConfig(format!("invalid framerate: {err}")))?; let mut config = moq_video::encode::Config::new(raw_input.width, raw_input.height, framerate); config.codec = codec_from_u32(raw_output.codec)?; @@ -1043,7 +1043,7 @@ mod tests { let catalog = moq_mux::catalog::Producer::new(&mut broadcast, config).unwrap(); let consumer = broadcast.consume(); // Probed rather than hand-built, so the test track carries what a real one would. - let encode = moq_video::encode::Config::new(320, 240, moq_video::Rate::new(30, 1).unwrap()); + let encode = moq_video::encode::Config::new(320, 240, moq_video::FrameRate::new(30, 1).unwrap()); let rendition = encode.probe().await.unwrap(); let reserved = catalog .reserve() @@ -1087,7 +1087,7 @@ mod tests { #[tokio::test] async fn finish_ends_the_track_after_a_rate_follower_panic() { let (producer, mut track) = track_under_test().await; - let mut config = moq_video::encode::Config::new(320, 240, moq_video::Rate::new(30, 1).unwrap()); + let mut config = moq_video::encode::Config::new(320, 240, moq_video::FrameRate::new(30, 1).unwrap()); config.kind = moq_video::encode::Kind::Software; let encoder = moq_video::encode::Sink::open(&config).await.unwrap(); let followed = crate::ffi::Background::new(async { panic!("injected rate follower panic") }); diff --git a/rs/moq-cli/src/play/media.rs b/rs/moq-cli/src/play/media.rs index 691db14fdc2..60b2f8a6cd7 100644 --- a/rs/moq-cli/src/play/media.rs +++ b/rs/moq-cli/src/play/media.rs @@ -1768,7 +1768,7 @@ mod tests { .create_track("video", hang::container::track_info(hang::catalog::PRIORITY.video)) .unwrap(); let mut producer = moq_mux::container::Producer::new(track, Container::Legacy(moq_mux::container::Kind::Data)); - let mut config = moq_video::encode::Config::new(64, 64, moq_video::Rate::new(30, 1).unwrap()); + let mut config = moq_video::encode::Config::new(64, 64, moq_video::FrameRate::new(30, 1).unwrap()); config.kind = moq_video::encode::Kind::Software; config.gop = moq_video::encode::Gop::Keyframe { interval: 120 }; let mut encoder = moq_video::encode::Encoder::new(&config).unwrap(); diff --git a/rs/moq-cli/src/publish.rs b/rs/moq-cli/src/publish.rs index 865f18b44f8..216b027f6d7 100644 --- a/rs/moq-cli/src/publish.rs +++ b/rs/moq-cli/src/publish.rs @@ -748,7 +748,7 @@ impl CaptureArgs { config.height = self.height; config.framerate = self .fps - .map(|fps| moq_video::Rate::new(fps, 1)) + .map(|fps| moq_video::FrameRate::new(fps, 1)) .transpose() .map_err(anyhow::Error::from)?; config.cursor = !self.no_cursor; diff --git a/rs/moq-ffi/src/video.rs b/rs/moq-ffi/src/video.rs index 9da2e33b97c..a462aef35cc 100644 --- a/rs/moq-ffi/src/video.rs +++ b/rs/moq-ffi/src/video.rs @@ -96,7 +96,7 @@ pub struct MoqVideoFrameRate { pub denominator: u32, } -impl TryFrom for moq_video::Rate { +impl TryFrom for moq_video::FrameRate { type Error = MoqError; fn try_from(rate: MoqVideoFrameRate) -> Result { @@ -1108,7 +1108,10 @@ mod finish_tests { &output, ) .unwrap(); - assert_eq!(config.framerate, moq_video::Rate::new(numerator, denominator).unwrap()); + assert_eq!( + config.framerate, + moq_video::FrameRate::new(numerator, denominator).unwrap() + ); assert_eq!(config.framerate.denominator(), 1001); } for (numerator, denominator) in [(0, 1), (30_000, 0), (1_000_001, 1)] { diff --git a/rs/moq-transcode/src/active.rs b/rs/moq-transcode/src/active.rs index 00ac9692941..7a729fdabfa 100644 --- a/rs/moq-transcode/src/active.rs +++ b/rs/moq-transcode/src/active.rs @@ -81,7 +81,7 @@ impl Rendition { } /// The output framerate, inherited from the source. - pub fn framerate(&self) -> Option { + pub fn framerate(&self) -> Option { self.0.rung.framerate } @@ -370,7 +370,7 @@ mod tests { short_side: height, size: moq_video::Size::new(height * 16 / 9, height), bitrate: moq_net::bandwidth::Rate::from_bps(100_000), - framerate: Some(moq_video::Rate::new(30, 1).unwrap()), + framerate: Some(moq_video::FrameRate::new(30, 1).unwrap()), } } diff --git a/rs/moq-transcode/src/catalog.rs b/rs/moq-transcode/src/catalog.rs index e1a9f2ff4d6..9f3d03c1772 100644 --- a/rs/moq-transcode/src/catalog.rs +++ b/rs/moq-transcode/src/catalog.rs @@ -20,7 +20,7 @@ pub(crate) struct Resolved { /// The output resolution, derived from the source aspect ratio. pub size: moq_video::Size, pub bitrate: moq_net::bandwidth::Rate, - pub framerate: Option, + pub framerate: Option, } impl Resolved { @@ -284,7 +284,7 @@ pub(crate) fn resolve_rungs(ladder: &Ladder, source_name: &str, source: &VideoCo let Some((source_width, source_height)) = dimensions(source) else { return Err(Error::SourceDimensions(source_name.to_string())); }; - let framerate = source.framerate.map(moq_video::Rate::from_f64).transpose()?; + let framerate = source.framerate.map(moq_video::FrameRate::from_f64).transpose()?; let mut resolved: Vec = Vec::new(); for rung in ladder.rungs() { @@ -328,13 +328,13 @@ pub(crate) async fn rung_entry( source: &VideoConfig, encoder: &moq_video::encode::Kind, ) -> Result { - let encode_rate = rung.framerate.unwrap_or(moq_video::Rate::new(30, 1).unwrap()); + let encode_rate = rung.framerate.unwrap_or(moq_video::FrameRate::new(30, 1).unwrap()); let mut config = moq_video::encode::Config::new(rung.size.width, rung.size.height, encode_rate); config.bitrate = Some(rung.bitrate); config.kind = encoder.clone(); let mut entry = config.probe().await?; - entry.framerate = rung.framerate.map(moq_video::Rate::as_f64); + entry.framerate = rung.framerate.map(moq_video::FrameRate::as_f64); // A property of the source rather than the ladder: every rung shows the same picture. entry.optimize_for_latency = source.optimize_for_latency; Ok(entry) @@ -443,7 +443,7 @@ mod tests { short_side: 360, size: moq_video::Size::new(640, 360), bitrate: moq_net::bandwidth::Rate::from_bps(600_000), - framerate: Some(moq_video::Rate::new(30, 1).unwrap()), + framerate: Some(moq_video::FrameRate::new(30, 1).unwrap()), }, entry: source(640, 360, Some(600_000)), }]; @@ -474,7 +474,7 @@ mod tests { short_side: 360, size: moq_video::Size::new(640, 360), bitrate: moq_net::bandwidth::Rate::from_bps(600_000), - framerate: Some(moq_video::Rate::new(30, 1).unwrap()), + framerate: Some(moq_video::FrameRate::new(30, 1).unwrap()), }, entry: source(640, 360, Some(600_000)), }]; @@ -509,7 +509,7 @@ mod tests { let resolved = resolve_rungs(&ladder, "video", &fractional).unwrap(); assert_eq!( resolved[0].framerate, - Some(moq_video::Rate::new(30_000, 1_001).unwrap()) + Some(moq_video::FrameRate::new(30_000, 1_001).unwrap()) ); fractional.framerate = None; @@ -706,7 +706,7 @@ mod tests { short_side: 360, size: moq_video::Size::new(640, 360), bitrate: moq_net::bandwidth::Rate::from_bps(600_000), - framerate: Some(moq_video::Rate::new(30, 1).unwrap()), + framerate: Some(moq_video::FrameRate::new(30, 1).unwrap()), }; let mut source = source(1920, 1080, Some(6_000_000)); source.optimize_for_latency = Some(true); diff --git a/rs/moq-transcode/src/error.rs b/rs/moq-transcode/src/error.rs index bb9abb1f7a0..5bc248469fa 100644 --- a/rs/moq-transcode/src/error.rs +++ b/rs/moq-transcode/src/error.rs @@ -32,7 +32,7 @@ pub enum Error { /// The source catalog declared an invalid frame rate. #[error(transparent)] - Framerate(#[from] moq_video::RateError), + Framerate(#[from] moq_video::FrameRateError), /// Timestamp overflow converting to the moq microsecond timescale. #[error(transparent)] diff --git a/rs/moq-transcode/src/lib.rs b/rs/moq-transcode/src/lib.rs index 11a6658c392..19c1a303c05 100644 --- a/rs/moq-transcode/src/lib.rs +++ b/rs/moq-transcode/src/lib.rs @@ -356,7 +356,7 @@ mod tests { /// to decode while the group is still open. fn write_keyframe(group: &mut moq_net::group::Producer) { let mut encoder = moq_video::encode::Encoder::new(&{ - let mut config = moq_video::encode::Config::new(320, 240, moq_video::Rate::new(30, 1).unwrap()); + let mut config = moq_video::encode::Config::new(320, 240, moq_video::FrameRate::new(30, 1).unwrap()); config.kind = moq_video::encode::Kind::Software; config }) @@ -401,7 +401,7 @@ mod tests { let track = broadcast.create_track("video", info).unwrap(); let mut encoder = moq_video::encode::Encoder::new(&{ - let mut config = moq_video::encode::Config::new(320, 240, moq_video::Rate::new(30, 1).unwrap()); + let mut config = moq_video::encode::Config::new(320, 240, moq_video::FrameRate::new(30, 1).unwrap()); config.kind = moq_video::encode::Kind::Software; config }) @@ -468,7 +468,7 @@ mod tests { let task = tokio::spawn(async move { let mut encoder = moq_video::encode::Sink::open(&{ - let mut config = moq_video::encode::Config::new(320, 240, moq_video::Rate::new(30, 1).unwrap()); + let mut config = moq_video::encode::Config::new(320, 240, moq_video::FrameRate::new(30, 1).unwrap()); config.kind = moq_video::encode::Kind::Software; config }) @@ -633,7 +633,7 @@ mod tests { /// with the NVIDIA driver). Probed through the public API so the hardware /// test skips cleanly on GPU-less CI. fn hardware_available() -> bool { - let mut encode = moq_video::encode::Config::new(160, 120, moq_video::Rate::new(30, 1).unwrap()); + let mut encode = moq_video::encode::Config::new(160, 120, moq_video::FrameRate::new(30, 1).unwrap()); encode.kind = moq_video::encode::Kind::Hardware; if moq_video::encode::Encoder::new(&encode).is_err() { return false; @@ -1599,7 +1599,7 @@ mod tests { // Two frames, so the output's largest moves once both are encoded. let mut group = source._track.create_group(0u64.into()).unwrap(); let mut encoder = moq_video::encode::Encoder::new(&{ - let mut config = moq_video::encode::Config::new(320, 240, moq_video::Rate::new(30, 1).unwrap()); + let mut config = moq_video::encode::Config::new(320, 240, moq_video::FrameRate::new(30, 1).unwrap()); config.kind = moq_video::encode::Kind::Software; config }) @@ -1690,7 +1690,7 @@ mod tests { let _source_fetches = source._track.dynamic(); let mut encoder = moq_video::encode::Encoder::new(&{ - let mut config = moq_video::encode::Config::new(320, 240, moq_video::Rate::new(30, 1).unwrap()); + let mut config = moq_video::encode::Config::new(320, 240, moq_video::FrameRate::new(30, 1).unwrap()); config.kind = moq_video::encode::Kind::Software; config }) diff --git a/rs/moq-transcode/src/rung.rs b/rs/moq-transcode/src/rung.rs index 084edac57b9..7bd16820981 100644 --- a/rs/moq-transcode/src/rung.rs +++ b/rs/moq-transcode/src/rung.rs @@ -113,7 +113,7 @@ impl Rung { /// worker's initialization and uninitialize COM on one that never initialized /// it. The sink owns a thread and stays on it. async fn encode(&self, color: Option) -> Result { - let framerate = self.info.framerate.unwrap_or(moq_video::Rate::new(30, 1).unwrap()); + let framerate = self.info.framerate.unwrap_or(moq_video::FrameRate::new(30, 1).unwrap()); let mut config = moq_video::encode::Config::new(self.info.size.width, self.info.size.height, framerate); config.bitrate = Some(self.info.bitrate); config.kind = self.encoder.clone(); @@ -1061,7 +1061,7 @@ mod tests { short_side: 120, size: moq_video::Size::new(160, 120), bitrate: moq_net::bandwidth::Rate::from_bps(100_000), - framerate: Some(moq_video::Rate::new(30, 1).unwrap()), + framerate: Some(moq_video::FrameRate::new(30, 1).unwrap()), }; let active = crate::active::Producer::default(); diff --git a/rs/moq-video/MIGRATE.md b/rs/moq-video/MIGRATE.md index 2ff59bc2932..32dc9dc1359 100644 --- a/rs/moq-video/MIGRATE.md +++ b/rs/moq-video/MIGRATE.md @@ -4,6 +4,11 @@ How to update your code for each breaking change, newest first. ## Unreleased +### `Rate` is `FrameRate` (#6653) + +`Rate` and `RateError` are `FrameRate` and `FrameRateError`, the name the bindings already use. +Rename the imports; the methods and error variants are unchanged. + ### Decoded reads carry gaps and encoder ends (#6475) `decode::Consumer::read()` returns `decode::Read` events instead of bare frames, the same shape as `moq_audio::decode::Read`: `Frame(frame)`, `Gap { timestamp, duration }` for lost media, and `End { end }` where the publisher stopped its encoder; `None` still means the track is finished. diff --git a/rs/moq-video/examples/d3d11-resize-probe.rs b/rs/moq-video/examples/d3d11-resize-probe.rs index d19f4e7dbad..7aa4f306b67 100644 --- a/rs/moq-video/examples/d3d11-resize-probe.rs +++ b/rs/moq-video/examples/d3d11-resize-probe.rs @@ -839,7 +839,7 @@ mod probe { /// inline parameter sets, which is what the MFT wants). fn stream() -> Result>> { let mut config = - moq_video::encode::Config::new(SOURCE.width, SOURCE.height, moq_video::Rate::new(30, 1).unwrap()); + moq_video::encode::Config::new(SOURCE.width, SOURCE.height, moq_video::FrameRate::new(30, 1).unwrap()); config.kind = moq_video::encode::Kind::Software; let mut encoder = moq_video::encode::Encoder::new(&config).context("openh264 encoder")?; @@ -1145,7 +1145,7 @@ mod probe { let mut config = moq_video::encode::Config::new( target.width, target.height, - moq_video::Rate::new(30, 1).unwrap(), + moq_video::FrameRate::new(30, 1).unwrap(), ); config.kind = moq_video::encode::Kind::Named("mediafoundation".into()); let mut encoder = moq_video::encode::Encoder::new(&config) diff --git a/rs/moq-video/examples/encode-presets.rs b/rs/moq-video/examples/encode-presets.rs index 976d5d5300d..bb87ff3de2e 100644 --- a/rs/moq-video/examples/encode-presets.rs +++ b/rs/moq-video/examples/encode-presets.rs @@ -28,7 +28,7 @@ use std::time::{Duration, Instant}; use moq_video::encode::{Codec, Config, Encoder, Kind, Preset}; -use moq_video::{Frame, I420, Rate, Size, Surface}; +use moq_video::{Frame, FrameRate, I420, Size, Surface}; const PRESETS: [(Preset, &str); 3] = [ (Preset::LowLatency, "low-latency"), @@ -73,7 +73,7 @@ fn main() -> anyhow::Result<()> { .into_iter() .filter(|(_, label)| only.is_none_or(|only| only == *label)) { - let mut config = Config::new(size.width, size.height, Rate::new(fps, 1)?); + let mut config = Config::new(size.width, size.height, FrameRate::new(fps, 1)?); config.codec = codec; config.kind = Kind::Named(backend.clone()); config.bitrate = Some(moq_net::bandwidth::Rate::from_bps(bitrate)); diff --git a/rs/moq-video/src/capture/mediafoundation.rs b/rs/moq-video/src/capture/mediafoundation.rs index bf6e2f360ff..d8232b986c9 100644 --- a/rs/moq-video/src/capture/mediafoundation.rs +++ b/rs/moq-video/src/capture/mediafoundation.rs @@ -89,7 +89,7 @@ struct Camera { device: Option, width: u32, height: u32, - framerate: Option, + framerate: Option, device_name: String, // Keep the DXGI manager alive for the reader's lifetime (the reader holds its // own ref, but we own the pairing). Drops before `_com`. @@ -182,7 +182,7 @@ impl Camera { } let framerate = unsafe { current.GetUINT64(&MF_MT_FRAME_RATE).ok() }.and_then(|packed| { let (num, den) = unpack_2x32(packed); - crate::Rate::new(num, den).ok() + crate::FrameRate::new(num, den).ok() }); let (device, manager) = match gpu { diff --git a/rs/moq-video/src/capture/mod.rs b/rs/moq-video/src/capture/mod.rs index 19cb40b3802..5b46d95982f 100644 --- a/rs/moq-video/src/capture/mod.rs +++ b/rs/moq-video/src/capture/mod.rs @@ -13,7 +13,7 @@ use std::sync::Arc; -use crate::{Error, Frame, Rate}; +use crate::{Error, Frame, FrameRate}; mod channel; use channel::FrameChannel; @@ -176,12 +176,12 @@ pub struct Mode { /// /// Empty when the driver describes a continuous range instead of listing /// rates, or cannot enumerate intervals for this size. - pub framerates: Vec, + pub framerates: Vec, } impl Mode { /// The highest rate this mode offers, or `None` when the driver listed none. - pub fn max_framerate(&self) -> Option { + pub fn max_framerate(&self) -> Option { self.framerates.first().copied() } } @@ -263,7 +263,7 @@ pub struct Config { /// Preferred output height in pixels. pub height: Option, /// Preferred exact frame rate. - pub framerate: Option, + pub framerate: Option, /// Draw the mouse cursor into captured frames. Screen/window/app sources /// only; ignored by cameras. Defaults to `true`. pub cursor: bool, @@ -293,7 +293,7 @@ pub struct Stream { chan: Arc, width: u32, height: u32, - framerate: Option, + framerate: Option, color: Option, label: String, /// First frame captured during [`open`] (some backends learn their geometry @@ -310,7 +310,7 @@ impl Stream { chan: Arc, width: u32, height: u32, - framerate: Option, + framerate: Option, label: String, pending: Option, backend: Keepalive, @@ -355,7 +355,7 @@ impl Stream { } /// The negotiated frame rate, or `None` if the source doesn't report one. - pub fn framerate(&self) -> Option { + pub fn framerate(&self) -> Option { self.framerate } @@ -385,7 +385,7 @@ pub(crate) struct Synthetic { #[cfg(all(test, feature = "openh264"))] impl Synthetic { /// Open a synthetic device with the given geometry, returning it and the stream reading it. - pub(crate) fn open(size: crate::Size, framerate: Rate) -> (Self, Stream) { + pub(crate) fn open(size: crate::Size, framerate: FrameRate) -> (Self, Stream) { let chan = FrameChannel::new(); let stream = Stream::new( chan.clone(), diff --git a/rs/moq-video/src/capture/mode.rs b/rs/moq-video/src/capture/mode.rs index 7c8af3d62bd..aa528c062a7 100644 --- a/rs/moq-video/src/capture/mode.rs +++ b/rs/moq-video/src/capture/mode.rs @@ -3,21 +3,21 @@ use std::collections::{BTreeMap, BTreeSet}; -use super::{Mode, Rate}; +use super::{FrameRate, Mode}; use crate::Size; /// What the caller asked the camera for. #[derive(Clone, Copy, Debug)] pub(super) struct Request { pub size: Size, - pub framerate: Option, + pub framerate: Option, } /// One mode a camera can stream, as the selection weighs it. #[derive(Clone, Copy, Debug)] pub(super) struct Candidate { pub size: Size, - pub framerate: Option, + pub framerate: Option, /// What converting the format to I420 costs: lower is cheaper. pub cost: u8, } @@ -42,7 +42,7 @@ pub(super) fn nearest( }) } -fn rate_distance(left: Option, right: Option, want: Option) -> std::cmp::Ordering { +fn rate_distance(left: Option, right: Option, want: Option) -> std::cmp::Ordering { let Some(want) = want else { return std::cmp::Ordering::Equal; }; @@ -65,8 +65,8 @@ fn distance(size: Size, want: Size) -> u64 { /// Merge the sizes and rates a camera reports into [`Mode`]s, largest first /// with each mode's rates highest first. The encoder sees I420 whatever format /// carried a mode, so the format is not something a caller can act on. -pub(super) fn modes(reported: impl IntoIterator)>) -> Vec { - let mut sizes: BTreeMap<(u32, u32), BTreeSet> = BTreeMap::new(); +pub(super) fn modes(reported: impl IntoIterator)>) -> Vec { + let mut sizes: BTreeMap<(u32, u32), BTreeSet> = BTreeMap::new(); for (size, rates) in reported { sizes.entry((size.width, size.height)).or_default().extend(rates); } @@ -88,13 +88,13 @@ pub(super) fn modes(reported: impl IntoIterator)>) -> Ve mod tests { use super::*; - fn rate(fps: u32) -> Rate { - Rate::new(fps, 1).unwrap() + fn rate(fps: u32) -> FrameRate { + FrameRate::new(fps, 1).unwrap() } #[test] fn rate_scoring_preserves_fractional_precision_and_handles_unknown_rates() { - let ntsc = Some(Rate::new(60000, 1001).unwrap()); + let ntsc = Some(FrameRate::new(60000, 1001).unwrap()); let thirty = Some(rate(30)); assert!(rate_distance(ntsc, thirty, Some(rate(60))).is_lt()); assert!(rate_distance(thirty, ntsc, Some(rate(30))).is_lt()); diff --git a/rs/moq-video/src/capture/pipewire.rs b/rs/moq-video/src/capture/pipewire.rs index 2e2b1dbff03..f67d804b16a 100644 --- a/rs/moq-video/src/capture/pipewire.rs +++ b/rs/moq-video/src/capture/pipewire.rs @@ -124,7 +124,7 @@ async fn start(config: &Config, capture: Capture, session: Option) let chan = FrameChannel::new(); let framerate = config .framerate - .unwrap_or(crate::Rate::integer(DEFAULT_FRAMERATE)) + .unwrap_or(crate::FrameRate::integer(DEFAULT_FRAMERATE)) .rounded(); let (geo_tx, geo_rx) = tokio::sync::oneshot::channel(); let (quit_tx, quit_rx) = pw::channel::channel::<()>(); @@ -975,7 +975,7 @@ fn run_loop(args: CaptureLoop) -> Result<(), Error> { // The compositor reports 0/1 for a variable rate; only a real // rate is worth forwarding to the encoder. let fr = state.format.framerate(); - let framerate = crate::Rate::new(fr.num, fr.denom).ok(); + let framerate = crate::FrameRate::new(fr.num, fr.denom).ok(); let _ = tx.send(Ok(Geometry { width, height, diff --git a/rs/moq-video/src/capture/pipewire/camera.rs b/rs/moq-video/src/capture/pipewire/camera.rs index 376b560a2f3..d35cc531d18 100644 --- a/rs/moq-video/src/capture/pipewire/camera.rs +++ b/rs/moq-video/src/capture/pipewire/camera.rs @@ -31,7 +31,7 @@ use super::{Capture, DEFAULT_FRAMERATE, Kind, Target, drm_format, err, linear_mo use crate::capture::mode::{self, Request}; use crate::capture::v4l2::{DEFAULT_HEIGHT, DEFAULT_WIDTH, bounds}; use crate::capture::{Camera, Config, Mode, PIPEWIRE, Stream}; -use crate::{Error, Rate, Size}; +use crate::{Error, FrameRate, Size}; /// How long the PipeWire daemon may take to answer a query. A connected daemon /// answers in milliseconds, so running out means it is stuck. @@ -378,7 +378,7 @@ pub(super) struct Format { /// The sizes on offer. A size range contributes its corners. sizes: Vec, /// The exact rates on offer, highest first. Empty for a rate range. - rates: Vec, + rates: Vec, /// The size range, when the size is one, which also offers the grid size /// nearest the request. ranged: Option, @@ -436,8 +436,8 @@ impl Grid { } /// Whether the rate range `min..=max` holds `rate`, compared as cross products -/// because a range may start at 0/1, which is no valid [`Rate`]. -fn holds(min: spa::utils::Fraction, max: spa::utils::Fraction, rate: Rate) -> bool { +/// because a range may start at 0/1, which is no valid [`FrameRate`]. +fn holds(min: spa::utils::Fraction, max: spa::utils::Fraction, rate: FrameRate) -> bool { let (num, denom) = (u64::from(rate.numerator()), u64::from(rate.denominator())); u64::from(min.num) * denom <= num * u64::from(min.denom) && num * u64::from(max.denom) <= u64::from(max.num) * denom } @@ -448,7 +448,7 @@ pub(super) struct Selected { encoding: Encoding, size: Size, /// `None` when the camera reports a rate range and no rate in it was requested. - framerate: Option, + framerate: Option, } impl Selected { @@ -522,7 +522,7 @@ impl Selected { } } -fn fraction(rate: Rate) -> spa::utils::Fraction { +fn fraction(rate: FrameRate) -> spa::utils::Fraction { spa::utils::Fraction { num: rate.numerator(), denom: rate.denominator(), @@ -625,9 +625,9 @@ fn parse_format(value: &Value) -> Vec { } _ => (Vec::new(), None), }; - let rate = |fraction: &spa::utils::Fraction| Rate::new(fraction.num, fraction.denom).ok(); + let rate = |fraction: &spa::utils::Fraction| FrameRate::new(fraction.num, fraction.denom).ok(); let framerate = property(FormatProperties::VideoFramerate); - let mut rates: Vec = match framerate { + let mut rates: Vec = match framerate { Some(Value::Fraction(fraction)) => rate(fraction).into_iter().collect(), Some(Value::Choice(ChoiceValue::Fraction(choice))) => listed(&choice.1).iter().filter_map(rate).collect(), _ => Vec::new(), @@ -685,7 +685,7 @@ fn select(formats: &[Format], want: Request) -> Option { .and_then(|grid| grid.nearest(want.size)) .into_iter() .chain(format.sizes.iter().copied()); - let rates: Vec> = if format.rates.is_empty() { + let rates: Vec> = if format.rates.is_empty() { let held = want .framerate .filter(|&rate| format.rate_range.is_some_and(|(min, max)| holds(min, max, rate))); @@ -906,7 +906,7 @@ mod tests { assert_eq!(formats.len(), 5); assert_eq!(formats[0].encoding, Encoding::Mjpeg); assert_eq!(formats[0].sizes, [Size::new(1280, 720)]); - assert_eq!(formats[0].rates, [Rate::new(30, 1).unwrap()]); + assert_eq!(formats[0].rates, [FrameRate::new(30, 1).unwrap()]); assert_eq!(formats[3].encoding, Encoding::Raw(VideoFormat::YUY2)); } @@ -979,7 +979,7 @@ mod tests { fn request(width: u32, height: u32, fps: Option) -> Request { Request { size: Size::new(width, height), - framerate: fps.map(|fps| Rate::new(fps, 1).unwrap()), + framerate: fps.map(|fps| FrameRate::new(fps, 1).unwrap()), } } @@ -1084,7 +1084,7 @@ mod tests { (selected.encoding, selected.framerate) }; let nv12 = Encoding::Raw(VideoFormat::NV12); - let rate = |fps| Some(Rate::new(fps, 1).unwrap()); + let rate = |fps| Some(FrameRate::new(fps, 1).unwrap()); assert_eq!(pick(Some(60)), (nv12, rate(60))); assert_eq!(pick(Some(30)), (nv12, rate(30))); // Out of the range, the exact rate elsewhere is the better answer. @@ -1092,8 +1092,8 @@ mod tests { // Nothing requested: the range stays open and the cheaper format wins. assert_eq!(pick(None), (nv12, None)); - assert!(holds(ratio(0, 1), ratio(30, 1), Rate::new(30000, 1001).unwrap())); - assert!(!holds(ratio(0, 1), ratio(30, 1), Rate::new(30001, 1000).unwrap())); + assert!(holds(ratio(0, 1), ratio(30, 1), FrameRate::new(30000, 1001).unwrap())); + assert!(!holds(ratio(0, 1), ratio(30, 1), FrameRate::new(30001, 1000).unwrap())); } /// The offer pins the chosen mode, and only NV12 gets a DMA-BUF offer. @@ -1117,7 +1117,7 @@ mod tests { let mjpeg = Selected { encoding: Encoding::Mjpeg, size: Size::new(1920, 1080), - framerate: Some(Rate::new(30, 1).unwrap()), + framerate: Some(FrameRate::new(30, 1).unwrap()), }; let offers = mjpeg.offers(); assert_eq!(offers.len(), 1); diff --git a/rs/moq-video/src/capture/pump.rs b/rs/moq-video/src/capture/pump.rs index cc19d111c13..fb7c5baae94 100644 --- a/rs/moq-video/src/capture/pump.rs +++ b/rs/moq-video/src/capture/pump.rs @@ -21,7 +21,7 @@ use std::thread::JoinHandle; use super::channel::FrameChannel; use crate::frame::Surface; -use crate::{Error, Rate}; +use crate::{Error, FrameRate}; /// The outcome of one device read. pub(super) enum Read { @@ -41,7 +41,7 @@ pub(super) enum Read { pub(super) struct Geometry { pub width: u32, pub height: u32, - pub framerate: Option, + pub framerate: Option, pub label: String, } diff --git a/rs/moq-video/src/capture/v4l2.rs b/rs/moq-video/src/capture/v4l2.rs index 7f54fa996c6..be1da920665 100644 --- a/rs/moq-video/src/capture/v4l2.rs +++ b/rs/moq-video/src/capture/v4l2.rs @@ -19,7 +19,7 @@ use moq_v4l::{Device, Format, FourCC}; use super::channel::FrameChannel; use super::mode::{self, Request}; use super::pump::{self, Geometry}; -use super::{Config, Mode, Rate, Stream}; +use super::{Config, FrameRate, Mode, Stream}; use crate::frame::{I420, Surface}; use crate::{Error, Size}; @@ -221,7 +221,7 @@ fn enumeration(result: std::io::Result) -> Result, Error> { } /// Exact discrete rates; continuous and stepwise intervals have no finite list. -fn framerates(device: &Device, fourcc: FourCC, size: Size) -> Result, Error> { +fn framerates(device: &Device, fourcc: FourCC, size: Size) -> Result, Error> { let mut rates = Vec::new(); for index in 0..=u32::MAX { // All fields are integers or integer unions; reserved fields must be zero. @@ -249,8 +249,8 @@ fn framerates(device: &Device, fourcc: FourCC, size: Size) -> Result, Err(Error::Codec(anyhow::anyhow!("V4L2 frame interval index overflow"))) } -fn rate(interval: moq_v4l::Fraction) -> Result { - Rate::new(interval.denominator, interval.numerator) +fn rate(interval: moq_v4l::Fraction) -> Result { + FrameRate::new(interval.denominator, interval.numerator) .map_err(|error| Error::Codec(anyhow::anyhow!("invalid V4L2 frame interval: {error}"))) } @@ -335,7 +335,7 @@ pub(crate) struct Camera { height: u32, /// Bytes per row of the YUYV buffer (`bytesperline`); unused for MJPEG. stride: u32, - framerate: Option, + framerate: Option, name: String, } @@ -448,7 +448,7 @@ fn open_error(device: &str, error: std::io::Error) -> Error { /// at small sizes and reach HD through MJPEG alone. Asking such a camera for /// YUYV at 1080p gets 640x480 back, which is a valid YUYV mode and nowhere near /// what the caller asked for. -fn negotiate(device: &Device, name: &str, want: Request) -> Result<(Format, Source, Option), Error> { +fn negotiate(device: &Device, name: &str, want: Request) -> Result<(Format, Source, Option), Error> { let framerate = want.framerate; negotiate_with(name, want, |format| { let format = set_format(device, format)?; @@ -475,8 +475,8 @@ fn negotiate(device: &Device, name: &str, want: Request) -> Result<(Format, Sour fn negotiate_with( name: &str, want: Request, - mut apply: impl FnMut(Format) -> Result<(Format, Option), Error>, -) -> Result<(Format, Source, Option), Error> { + mut apply: impl FnMut(Format) -> Result<(Format, Option), Error>, +) -> Result<(Format, Source, Option), Error> { let mut replies = Vec::with_capacity(Source::ALL.len()); let mut offered = Vec::new(); let mut probe_error = None; @@ -526,9 +526,9 @@ fn negotiate_with( /// Prefer geometry, then the accepted rate nearest the request, then conversion cost. fn closest( - replies: impl IntoIterator)>, + replies: impl IntoIterator)>, want: Request, -) -> Option<(Format, Source, Option)> { +) -> Option<(Format, Source, Option)> { mode::nearest(replies, want, |(format, source, rate)| mode::Candidate { size: Size::new(format.width, format.height), framerate: *rate, @@ -553,7 +553,7 @@ mod tests { } } - fn reply(width: u32, height: u32, source: Source) -> (Format, Source, Option) { + fn reply(width: u32, height: u32, source: Source) -> (Format, Source, Option) { (Format::new(width, height, source.fourcc()), source, None) } @@ -631,7 +631,7 @@ mod tests { let mut formats = Vec::new(); let want = Request { size: Size::new(1280, 720), - framerate: Some(Rate::new(60, 1).unwrap()), + framerate: Some(FrameRate::new(60, 1).unwrap()), }; let (_, source, accepted) = negotiate_with("camera", want, |format| { formats.push(format.fourcc); diff --git a/rs/moq-video/src/capture/wgc.rs b/rs/moq-video/src/capture/wgc.rs index 3a23d8a7844..88166968f58 100644 --- a/rs/moq-video/src/capture/wgc.rs +++ b/rs/moq-video/src/capture/wgc.rs @@ -306,7 +306,7 @@ mod tests { color: None, }; delivery.replace(surface, Timestamp::from_micros(0).unwrap(), now); - let mut config = Config::new(320, 240, crate::Rate::integer(50)); + let mut config = Config::new(320, 240, crate::FrameRate::integer(50)); config.kind = Kind::Software; let mut encoder = Encoder::new(&config).unwrap(); let mut broadcast = moq_net::broadcast::Info::new().produce(); diff --git a/rs/moq-video/src/capture/wgc/native.rs b/rs/moq-video/src/capture/wgc/native.rs index 157493b7919..7ba8aa12c3d 100644 --- a/rs/moq-video/src/capture/wgc/native.rs +++ b/rs/moq-video/src/capture/wgc/native.rs @@ -37,7 +37,7 @@ use super::super::settle::{Settle, Settled}; use super::super::{Config, Display, FrameChannel, Source, Stream, Window}; use super::{Delivery, Event, Signal, Startup, display_index, window_handle}; use crate::frame::{Surface, d3d11}; -use crate::{Error, Rate, Size}; +use crate::{Error, FrameRate, Size}; const BUFFERS: i32 = 2; @@ -45,7 +45,7 @@ pub(in crate::capture) async fn open(config: &Config) -> Result { let chan = FrameChannel::new(); let signal = Arc::new(Signal::default()); let label = config.source.label(); - let rate = config.framerate.unwrap_or(Rate::integer(30)); + let rate = config.framerate.unwrap_or(FrameRate::integer(30)); let handle = std::thread::Builder::new() .name("moq-wgc".into()) .spawn({ @@ -272,7 +272,7 @@ impl Capture { .StartCapture() .map_err(|e| error("start WGC", e))?; let mut startup = Startup::new(Instant::now()); - let rate = config.framerate.unwrap_or(Rate::integer(30)); + let rate = config.framerate.unwrap_or(FrameRate::integer(30)); let interval = Duration::from_nanos(1_000_000_000 * u64::from(rate.denominator()) / u64::from(rate.numerator())); let mut opened = None; diff --git a/rs/moq-video/src/capture/x11.rs b/rs/moq-video/src/capture/x11.rs index d812ea02899..1c296c63405 100644 --- a/rs/moq-video/src/capture/x11.rs +++ b/rs/moq-video/src/capture/x11.rs @@ -184,7 +184,7 @@ struct Capture { shm: Option, rgb: Vec, observed: Observed, - framerate: crate::Rate, + framerate: crate::FrameRate, interval: Duration, next: Instant, name: String, @@ -291,7 +291,7 @@ impl Capture { let format = PixelFormat::new(connection.setup(), depth, visual)?; let shm = SharedMemory::open(connection.clone(), format.required_len(width, height)?)?; tracing::debug!(source = %name, shared_memory = shm.is_some(), "X11 capture opened"); - let framerate = config.framerate.unwrap_or(crate::Rate::integer(DEFAULT_FRAMERATE)); + let framerate = config.framerate.unwrap_or(crate::FrameRate::integer(DEFAULT_FRAMERATE)); let interval = Duration::from_secs_f64(1.0 / framerate.as_f64()); let cursor = config.cursor && connection diff --git a/rs/moq-video/src/decode/backend/mediacodec.rs b/rs/moq-video/src/decode/backend/mediacodec.rs index ec2076c4b66..defc0e30a0d 100644 --- a/rs/moq-video/src/decode/backend/mediacodec.rs +++ b/rs/moq-video/src/decode/backend/mediacodec.rs @@ -545,7 +545,7 @@ mod tests { use crate::encode::{Config as EncodeConfig, Kind as EncodeKind}; let size = crate::Size::new(320, 240); - let mut config = EncodeConfig::new(size.width, size.height, crate::Rate::new(30, 1).unwrap()); + let mut config = EncodeConfig::new(size.width, size.height, crate::FrameRate::new(30, 1).unwrap()); config.kind = EncodeKind::Named(NAME.to_owned()); let mut encoder = crate::encode::Encoder::new(&config).expect("a MediaCodec encoder"); diff --git a/rs/moq-video/src/decode/backend/nvdec.rs b/rs/moq-video/src/decode/backend/nvdec.rs index f594ee4af7e..38b7baabdac 100644 --- a/rs/moq-video/src/decode/backend/nvdec.rs +++ b/rs/moq-video/src/decode/backend/nvdec.rs @@ -578,7 +578,7 @@ mod tests { let (w, h) = (320u32, 240u32); let encoder = Encoder::new(&EncodeConfig { kind: EncodeKind::Software, - ..EncodeConfig::new(w, h, crate::Rate::new(30, 1).unwrap()) + ..EncodeConfig::new(w, h, crate::FrameRate::new(30, 1).unwrap()) }) .unwrap(); let decoder = Nvdec::open(Codec::H264, &decode_config(None)).expect("NVDEC H.264 decoder"); @@ -607,7 +607,7 @@ mod tests { let (w, h) = (320u32, 240u32); let encoder = Encoder::new(&EncodeConfig { kind: EncodeKind::Software, - ..EncodeConfig::new(w, h, crate::Rate::new(30, 1).unwrap()) + ..EncodeConfig::new(w, h, crate::FrameRate::new(30, 1).unwrap()) }) .unwrap(); let decoder = @@ -641,7 +641,7 @@ mod tests { let Ok(encoder) = Encoder::new(&EncodeConfig { codec: EncodeCodec::H265, kind: EncodeKind::Named("nvenc".into()), - ..EncodeConfig::new(w, h, crate::Rate::new(30, 1).unwrap()) + ..EncodeConfig::new(w, h, crate::FrameRate::new(30, 1).unwrap()) }) else { // Driver present but NVENC unusable (e.g. GPU busy); don't fail. return; @@ -671,7 +671,7 @@ mod tests { // Source stream: software-encoded gradient. let source = Encoder::new(&EncodeConfig { kind: EncodeKind::Software, - ..EncodeConfig::new(w, h, crate::Rate::new(30, 1).unwrap()) + ..EncodeConfig::new(w, h, crate::FrameRate::new(30, 1).unwrap()) }) .unwrap(); // Decode at half size so the hardware scaler is in the loop too. @@ -680,7 +680,7 @@ mod tests { let mut nvenc = Encoder::new(&EncodeConfig { kind: EncodeKind::Named("nvenc".into()), - ..EncodeConfig::new(160, 120, crate::Rate::new(30, 1).unwrap()) + ..EncodeConfig::new(160, 120, crate::FrameRate::new(30, 1).unwrap()) }) .expect("NVENC encoder"); diff --git a/rs/moq-video/src/decode/backend/vaapi.rs b/rs/moq-video/src/decode/backend/vaapi.rs index 25b63e81a5c..3ffed8f982f 100644 --- a/rs/moq-video/src/decode/backend/vaapi.rs +++ b/rs/moq-video/src/decode/backend/vaapi.rs @@ -289,7 +289,7 @@ mod tests { let mut encoder = Encoder::new(&EncodeConfig { kind: EncodeKind::Software, - ..EncodeConfig::new(w, h, crate::Rate::new(30, 1).unwrap()) + ..EncodeConfig::new(w, h, crate::FrameRate::new(30, 1).unwrap()) }) .unwrap(); let mut decoder = Vaapi::open(Codec::H264, &decode_config()).expect("VAAPI H.264 decoder"); @@ -342,7 +342,7 @@ mod tests { let mut encoder = Encoder::new(&EncodeConfig { kind: EncodeKind::Software, - ..EncodeConfig::new(w, h, crate::Rate::new(30, 1).unwrap()) + ..EncodeConfig::new(w, h, crate::FrameRate::new(30, 1).unwrap()) }) .unwrap(); let mut exporting = Vaapi::open(Codec::H264, &gpu_decode_config()).expect("VAAPI H.264 decoder"); @@ -432,7 +432,7 @@ mod tests { let mut encoder = Encoder::new(&EncodeConfig { kind: EncodeKind::Software, - ..EncodeConfig::new(w, h, crate::Rate::new(30, 1).unwrap()) + ..EncodeConfig::new(w, h, crate::FrameRate::new(30, 1).unwrap()) }) .unwrap(); let mut decoder = Vaapi::open(Codec::H264, config).expect("VAAPI H.264 decoder"); diff --git a/rs/moq-video/src/decode/consumer.rs b/rs/moq-video/src/decode/consumer.rs index 4bbc5e1948f..75ec32e7c75 100644 --- a/rs/moq-video/src/decode/consumer.rs +++ b/rs/moq-video/src/decode/consumer.rs @@ -468,7 +468,7 @@ mod tests { moq_mux::catalog::Producer::new(&mut source_broadcast, moq_mux::catalog::Config::default()).unwrap(); let config = EncodeConfig { kind: EncodeKind::Software, - ..EncodeConfig::new(320, 240, crate::Rate::new(30, 1).unwrap()) + ..EncodeConfig::new(320, 240, crate::FrameRate::new(30, 1).unwrap()) }; let rendition = config.probe().await.unwrap(); let reserved = source_catalog @@ -1024,7 +1024,7 @@ mod tests { const FRAMES: u64 = 5; let config = EncodeConfig { kind: EncodeKind::Software, - ..EncodeConfig::new(320, 240, crate::Rate::new(30, 1).unwrap()) + ..EncodeConfig::new(320, 240, crate::FrameRate::new(30, 1).unwrap()) }; let catalog = config.probe().await.expect("probe the software encoder"); diff --git a/rs/moq-video/src/decode/decoder.rs b/rs/moq-video/src/decode/decoder.rs index 025831f4980..e04b8018d43 100644 --- a/rs/moq-video/src/decode/decoder.rs +++ b/rs/moq-video/src/decode/decoder.rs @@ -468,7 +468,7 @@ mod tests { fn h264_software_encoder(size: crate::Size) -> Encoder { Encoder::new(&EncodeConfig { kind: EncodeKind::Software, - ..EncodeConfig::new(size.width, size.height, crate::Rate::new(30, 1).unwrap()) + ..EncodeConfig::new(size.width, size.height, crate::FrameRate::new(30, 1).unwrap()) }) .expect("openh264 encoder") } @@ -727,7 +727,7 @@ mod tests { let mut encoder = Encoder::new(&EncodeConfig { kind: EncodeKind::Software, color: Some(color), - ..EncodeConfig::new(size.width, size.height, crate::Rate::new(30, 1).unwrap()) + ..EncodeConfig::new(size.width, size.height, crate::FrameRate::new(30, 1).unwrap()) }) .unwrap(); encoder.cut().unwrap(); @@ -995,7 +995,7 @@ mod tests { let encoder = Encoder::new(&EncodeConfig { kind: EncodeKind::Named("videotoolbox".into()), - ..EncodeConfig::new(160, 120, crate::Rate::new(30, 1).unwrap()) + ..EncodeConfig::new(160, 120, crate::FrameRate::new(30, 1).unwrap()) }); let Ok(mut encoder) = encoder else { eprintln!("skipping: no VideoToolbox H.264 hardware encoder available"); @@ -1024,7 +1024,7 @@ mod tests { let encoder = Encoder::new(&EncodeConfig { kind: EncodeKind::Named("videotoolbox".into()), codec: crate::encode::Codec::H265, - ..EncodeConfig::new(320, 240, crate::Rate::new(30, 1).unwrap()) + ..EncodeConfig::new(320, 240, crate::FrameRate::new(30, 1).unwrap()) }); let Ok(encoder) = encoder else { eprintln!("skipping: no VideoToolbox H.265 hardware encoder available"); @@ -1211,7 +1211,7 @@ mod tests { let encoder = Encoder::new(&EncodeConfig { kind: EncodeKind::Named("mediafoundation".into()), - ..EncodeConfig::new(size.width, size.height, crate::Rate::new(30, 1).unwrap()) + ..EncodeConfig::new(size.width, size.height, crate::FrameRate::new(30, 1).unwrap()) }); let Ok(mut encoder) = encoder else { eprintln!("skipping: no Media Foundation H.264 hardware encoder available"); @@ -1296,7 +1296,7 @@ mod tests { let encoder = Encoder::new(&EncodeConfig { kind: EncodeKind::Named("mediafoundation".into()), - ..EncodeConfig::new(target.width, target.height, crate::Rate::new(30, 1).unwrap()) + ..EncodeConfig::new(target.width, target.height, crate::FrameRate::new(30, 1).unwrap()) }); let Ok(mut encoder) = encoder else { eprintln!("skipping: no Media Foundation H.264 hardware encoder available"); @@ -1325,7 +1325,7 @@ mod tests { let encoder = Encoder::new(&EncodeConfig { kind: EncodeKind::Named("mediafoundation".into()), codec: crate::encode::Codec::H265, - ..EncodeConfig::new(320, 240, crate::Rate::new(30, 1).unwrap()) + ..EncodeConfig::new(320, 240, crate::FrameRate::new(30, 1).unwrap()) }); let Ok(encoder) = encoder else { eprintln!("skipping: no Media Foundation H.265 hardware encoder available"); diff --git a/rs/moq-video/src/decode/vui.rs b/rs/moq-video/src/decode/vui.rs index 93f2c4072e8..169656cb7b4 100644 --- a/rs/moq-video/src/decode/vui.rs +++ b/rs/moq-video/src/decode/vui.rs @@ -184,7 +184,7 @@ mod tests { let mut encoder = Encoder::new(&Config { kind: Kind::Software, color: Some(color), - ..Config::new(size.width, size.height, crate::Rate::new(30, 1).unwrap()) + ..Config::new(size.width, size.height, crate::FrameRate::new(30, 1).unwrap()) }) .unwrap(); encoder.cut().unwrap(); diff --git a/rs/moq-video/src/encode/backend/mediacodec.rs b/rs/moq-video/src/encode/backend/mediacodec.rs index 4a535988a51..55fc1c82fea 100644 --- a/rs/moq-video/src/encode/backend/mediacodec.rs +++ b/rs/moq-video/src/encode/backend/mediacodec.rs @@ -131,7 +131,7 @@ pub(crate) struct MediaCodec { kind: Codec, width: usize, height: usize, - framerate: crate::Rate, + framerate: crate::FrameRate, /// The parameter sets (SPS/PPS, plus VPS for H.265) as the codec-config /// buffer delivered them: Annex-B, ahead of the first picture. Kept because /// every keyframe has to carry them for a subscriber joining there. @@ -689,7 +689,7 @@ mod tests { #[test] #[ignore = "needs an Android device with a MediaCodec H.264 encoder"] fn encodes_a_keyframe_with_parameter_sets_inline() { - let config = Config::new(320, 240, crate::Rate::new(30, 1).unwrap()); + let config = Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()); let mut backend = MediaCodec::open(&config).expect("a MediaCodec encoder"); let size = config.size(); diff --git a/rs/moq-video/src/encode/backend/mediafoundation.rs b/rs/moq-video/src/encode/backend/mediafoundation.rs index ff9eede829a..511a996734f 100644 --- a/rs/moq-video/src/encode/backend/mediafoundation.rs +++ b/rs/moq-video/src/encode/backend/mediafoundation.rs @@ -65,7 +65,7 @@ pub(crate) struct MediaFoundation { codec: Codec, width: u32, height: u32, - framerate: crate::Rate, + framerate: crate::FrameRate, bitrate: u32, /// Keyframe interval in frames. gop: u32, diff --git a/rs/moq-video/src/encode/backend/mod.rs b/rs/moq-video/src/encode/backend/mod.rs index 05613f4e4d0..3e50fa53f4d 100644 --- a/rs/moq-video/src/encode/backend/mod.rs +++ b/rs/moq-video/src/encode/backend/mod.rs @@ -592,7 +592,7 @@ mod tests { }; fn config() -> Config { - Config::new(320, 240, crate::Rate::new(30, 1).unwrap()) + Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()) } /// Only a selection whose every candidate promises cuts may advertise them, and a diff --git a/rs/moq-video/src/encode/backend/nvenc.rs b/rs/moq-video/src/encode/backend/nvenc.rs index 8b2a44f57b5..48b40a9afd0 100644 --- a/rs/moq-video/src/encode/backend/nvenc.rs +++ b/rs/moq-video/src/encode/backend/nvenc.rs @@ -488,7 +488,7 @@ mod tests { if driver_available() { return; // real driver present: open() would legitimately try to run } - let config = Config::new(1920, 1080, crate::Rate::new(30, 1).unwrap()); + let config = Config::new(1920, 1080, crate::FrameRate::new(30, 1).unwrap()); let error = Nvenc::open(&config).err().expect("missing driver must be refused"); assert!( error.to_string().contains("NVENC unavailable"), @@ -501,7 +501,7 @@ mod tests { if driver_available() { return; } - let mut config = Config::new(1920, 1080, crate::Rate::new(30, 1).unwrap()); + let mut config = Config::new(1920, 1080, crate::FrameRate::new(30, 1).unwrap()); config.kind = crate::encode::Kind::Named(NAME.into()); let error = crate::encode::backend::open(&config) .err() @@ -569,7 +569,7 @@ mod tests { } let config = crate::encode::Config { kind: crate::encode::Kind::Named(NAME.into()), - ..crate::encode::Config::new(320, 240, crate::Rate::new(30, 1).unwrap()) + ..crate::encode::Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()) }; let Ok(mut encoder) = crate::encode::Encoder::new(&config) else { // Driver present but NVENC still unusable (e.g. GPU busy); don't fail. @@ -624,7 +624,7 @@ mod tests { kind: crate::encode::Kind::Named(NAME.into()), codec, preset, - ..crate::encode::Config::new(320, 240, crate::Rate::new(30, 1).unwrap()) + ..crate::encode::Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()) }; let Ok(mut encoder) = crate::encode::Encoder::new(&config) else { return; @@ -649,7 +649,7 @@ mod tests { if !driver_available() { return; } - let mut config = crate::encode::Config::new(320, 240, crate::Rate::new(30, 1).unwrap()); + let mut config = crate::encode::Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()); config.kind = crate::encode::Kind::Named(NAME.into()); config.bitrate = Some(moq_net::bandwidth::Rate::from_bps(1_000_000)); let Ok(mut encoder) = crate::encode::Encoder::new(&config) else { @@ -682,7 +682,7 @@ mod tests { let config = crate::encode::Config { codec: crate::encode::Codec::H265, kind: crate::encode::Kind::Named(NAME.into()), - ..crate::encode::Config::new(320, 240, crate::Rate::new(30, 1).unwrap()) + ..crate::encode::Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()) }; let Ok(mut encoder) = crate::encode::Encoder::new(&config) else { return; @@ -729,7 +729,7 @@ mod tests { if !driver_available() { return; } - let mut config = crate::encode::Config::new(320, 240, crate::Rate::new(30, 1).unwrap()); + let mut config = crate::encode::Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()); config.kind = crate::encode::Kind::Named(NAME.into()); config.gop = Gop::Keyframe { interval: 3 }; let Ok(mut encoder) = crate::encode::Encoder::new(&config) else { @@ -784,7 +784,7 @@ mod tests { let (w, h) = (300u32, 240u32); let config = crate::encode::Config { kind: crate::encode::Kind::Named(NAME.into()), - ..crate::encode::Config::new(w, h, crate::Rate::new(30, 1).unwrap()) + ..crate::encode::Config::new(w, h, crate::FrameRate::new(30, 1).unwrap()) }; let Ok(mut encoder) = crate::encode::Encoder::new(&config) else { return; @@ -851,7 +851,7 @@ mod tests { return None; } let (w, h) = (1280u32, 720u32); - let mut config = crate::encode::Config::new(w, h, crate::Rate::new(30, 1).unwrap()); + let mut config = crate::encode::Config::new(w, h, crate::FrameRate::new(30, 1).unwrap()); config.kind = crate::encode::Kind::Named(NAME.into()); config.bitrate = Some(moq_net::bandwidth::Rate::from_bps(4_000_000)); config.gop = Gop::Keyframe { interval: 30 }; diff --git a/rs/moq-video/src/encode/backend/openh264.rs b/rs/moq-video/src/encode/backend/openh264.rs index 01c4a0e355e..7806a9833ab 100644 --- a/rs/moq-video/src/encode/backend/openh264.rs +++ b/rs/moq-video/src/encode/backend/openh264.rs @@ -240,7 +240,7 @@ mod tests { fn config() -> Config { Config { kind: Kind::Software, - ..Config::new(320, 240, crate::Rate::new(30, 1).unwrap()) + ..Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()) } } @@ -343,7 +343,7 @@ mod tests { ] { let config = Config { kind: Kind::Software, - ..Config::new(size.width, size.height, crate::Rate::new(30, 1).unwrap()) + ..Config::new(size.width, size.height, crate::FrameRate::new(30, 1).unwrap()) }; let mut enc = Openh264::new(&config).unwrap(); @@ -368,7 +368,7 @@ mod tests { /// the flag agrees with the bitstream. #[test] fn keyframes_are_flagged_on_the_cadence_and_on_a_cut() { - let framerate = crate::Rate::new(30, 1).unwrap(); + let framerate = crate::FrameRate::new(30, 1).unwrap(); let config = Config { gop: Gop::keyframe_every(std::time::Duration::from_secs(1), framerate), ..config() diff --git a/rs/moq-video/src/encode/backend/v4l2.rs b/rs/moq-video/src/encode/backend/v4l2.rs index 19888642539..4f82dbf5500 100644 --- a/rs/moq-video/src/encode/backend/v4l2.rs +++ b/rs/moq-video/src/encode/backend/v4l2.rs @@ -902,7 +902,7 @@ mod tests { use super::*; fn config(width: u32, height: u32, framerate: u32) -> Config { - Config::new(width, height, crate::Rate::new(framerate, 1).unwrap()) + Config::new(width, height, crate::FrameRate::new(framerate, 1).unwrap()) } fn micros(micros: u64) -> Timestamp { diff --git a/rs/moq-video/src/encode/backend/vaapi.rs b/rs/moq-video/src/encode/backend/vaapi.rs index f1bb1accf81..65d68b311a2 100644 --- a/rs/moq-video/src/encode/backend/vaapi.rs +++ b/rs/moq-video/src/encode/backend/vaapi.rs @@ -238,7 +238,7 @@ mod tests { use crate::decode::backend as decode_backend; use crate::decode::{Codec as DecodeCodec, Config as DecodeConfig, Kind as DecodeKind}; use crate::encode::{Encoder as CrateEncoder, Kind as EncodeKind}; - use crate::{Output, Rate, Size}; + use crate::{FrameRate, Output, Size}; const WIDTH: u32 = 320; const HEIGHT: u32 = 240; @@ -246,7 +246,7 @@ mod tests { fn config() -> Config { Config { kind: EncodeKind::Named(NAME.into()), - ..Config::new(WIDTH, HEIGHT, Rate::new(30, 1).unwrap()) + ..Config::new(WIDTH, HEIGHT, FrameRate::new(30, 1).unwrap()) } } @@ -389,7 +389,7 @@ mod tests { // A software-encoded source stream, decoded by VA-API into DMA-BUFs. let mut source = CrateEncoder::new(&Config { kind: EncodeKind::Software, - ..Config::new(WIDTH, HEIGHT, Rate::new(30, 1).unwrap()) + ..Config::new(WIDTH, HEIGHT, FrameRate::new(30, 1).unwrap()) }) .unwrap(); let mut hardware = decoder(NAME, Output::Native); @@ -553,7 +553,7 @@ mod tests { let config = Config { kind: EncodeKind::Named(NAME.into()), color: Some(color), - ..Config::new(size.width, size.height, Rate::new(30, 1).unwrap()) + ..Config::new(size.width, size.height, FrameRate::new(30, 1).unwrap()) }; let Ok(mut backend) = Vaapi::new(&config) else { eprintln!("skipping: no VA-API H.264 encoder"); diff --git a/rs/moq-video/src/encode/backend/videotoolbox.rs b/rs/moq-video/src/encode/backend/videotoolbox.rs index 3d30ff08de3..099ee768bb0 100644 --- a/rs/moq-video/src/encode/backend/videotoolbox.rs +++ b/rs/moq-video/src/encode/backend/videotoolbox.rs @@ -552,7 +552,7 @@ mod tests { let config = Config { codec, preset, - ..Config::new(320, 240, crate::Rate::new(30, 1).unwrap()) + ..Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()) }; // Determine which controls this host accepts independently of the production fallback. let candidates: &[Preset] = match preset { diff --git a/rs/moq-video/src/encode/encoder.rs b/rs/moq-video/src/encode/encoder.rs index fdd6474655d..46ef621904e 100644 --- a/rs/moq-video/src/encode/encoder.rs +++ b/rs/moq-video/src/encode/encoder.rs @@ -10,7 +10,7 @@ use std::rc::Rc; use super::Encoded; use super::backend::{self, Backend}; -use crate::{Color, Error, Frame, Rate, Size}; +use crate::{Color, Error, Frame, FrameRate, Size}; /// Output video codec. `#[non_exhaustive]` so new codecs can be added without /// breaking external `match`es. @@ -69,14 +69,14 @@ pub enum Gop { impl Gop { /// Keyframes every `interval` of wall time at `framerate`, rounded down to /// whole frames and never below one. - pub fn keyframe_every(interval: std::time::Duration, framerate: Rate) -> Self { + pub fn keyframe_every(interval: std::time::Duration, framerate: FrameRate) -> Self { Self::Keyframe { interval: framerate.frames(interval).max(1), } } /// The nominal time between groups at `framerate`. - pub fn duration(self, framerate: Rate) -> std::time::Duration { + pub fn duration(self, framerate: FrameRate) -> std::time::Duration { match self { Self::Keyframe { interval } => std::time::Duration::from_nanos( (u128::from(interval) * 1_000_000_000 * u128::from(framerate.denominator()) @@ -182,7 +182,7 @@ pub struct Config { /// Encoded height in pixels. pub height: u32, /// Encoded frame rate. - pub framerate: Rate, + pub framerate: FrameRate, /// Target bitrate. `None` derives a sane default /// from resolution and framerate (~0.07 bits per pixel per second). pub bitrate: Option, @@ -216,7 +216,7 @@ pub struct Config { impl Config { /// A config encoding `width` x `height` at `framerate`, with the default /// codec, GOP, and bitrate. - pub fn new(width: u32, height: u32, framerate: Rate) -> Self { + pub fn new(width: u32, height: u32, framerate: FrameRate) -> Self { Self { width, height, @@ -317,7 +317,7 @@ impl Config { /// The bitrate an unconfigured encode resolves to: 0.07 bits per pixel per second, which matches /// the JS publisher's default and lands ~4.4 Mbps for 1080p30. -pub(crate) fn default_bitrate(size: Size, framerate: Rate) -> moq_net::bandwidth::Rate { +pub(crate) fn default_bitrate(size: Size, framerate: FrameRate) -> moq_net::bandwidth::Rate { moq_net::bandwidth::Rate::from_bps((size.pixels() as f64 * framerate.as_f64() * 0.07) as u64) } @@ -599,7 +599,7 @@ mod tests { fn software_encoder_emits_annexb() { let config = Config { kind: Kind::Software, - ..Config::new(320, 240, crate::Rate::new(30, 1).unwrap()) + ..Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()) }; let mut encoder = Encoder::new(&config).expect("openh264 is vendored, always available"); assert_eq!(encoder.name(), "openh264"); @@ -645,7 +645,7 @@ mod tests { fn encode_i420_surface_emits_annexb() { let config = Config { kind: Kind::Software, - ..Config::new(320, 240, crate::Rate::new(30, 1).unwrap()) + ..Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()) }; let mut encoder = Encoder::new(&config).unwrap(); @@ -664,7 +664,7 @@ mod tests { /// top-left corner. #[test] fn encode_rejects_dimension_mismatch() { - let Ok(mut encoder) = Encoder::new(&Config::new(320, 240, crate::Rate::new(30, 1).unwrap())) else { + let Ok(mut encoder) = Encoder::new(&Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap())) else { return; }; assert!(matches!(encoder.encode(&gray_frame(640, 480, 0)), Err(Error::Codec(_)))); @@ -675,7 +675,7 @@ mod tests { /// check alone would accept this and encode garbage. #[test] fn encode_rejects_transposed_frame() { - let Ok(mut encoder) = Encoder::new(&Config::new(320, 240, crate::Rate::new(30, 1).unwrap())) else { + let Ok(mut encoder) = Encoder::new(&Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap())) else { return; }; @@ -692,7 +692,7 @@ mod tests { fn unknown_named_encoder_errors() { let config = Config { kind: Kind::Named("definitely_not_a_codec".into()), - ..Config::new(320, 240, crate::Rate::new(30, 1).unwrap()) + ..Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()) }; // Not `NoEncoder`: that reads "no usable video encoder found (tried: )" // and describes a machine with no encoder rather than a name that is not @@ -712,7 +712,7 @@ mod tests { fn videotoolbox_emits_annexb_keyframe() { let config = Config { kind: Kind::Named("videotoolbox".into()), - ..Config::new(320, 240, crate::Rate::new(30, 1).unwrap()) + ..Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()) }; let mut encoder = Encoder::new(&config).expect("videotoolbox is available on macOS"); assert_eq!(encoder.name(), "videotoolbox"); @@ -759,7 +759,7 @@ mod tests { let config = Config { codec: Codec::H265, kind: Kind::Named("videotoolbox".into()), - ..Config::new(320, 240, crate::Rate::new(30, 1).unwrap()) + ..Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()) }; let mut encoder = Encoder::new(&config).expect("videotoolbox HEVC is available on macOS"); assert_eq!(encoder.name(), "videotoolbox"); @@ -817,7 +817,7 @@ mod tests { fn videotoolbox_encodes_surface_zero_copy() { let config = Config { kind: Kind::Named("videotoolbox".into()), - ..Config::new(320, 240, crate::Rate::new(30, 1).unwrap()) + ..Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()) }; let mut encoder = Encoder::new(&config).unwrap(); @@ -847,7 +847,7 @@ mod tests { fn openh264_downloads_surface() { let config = Config { kind: Kind::Software, - ..Config::new(320, 240, crate::Rate::new(30, 1).unwrap()) + ..Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()) }; let mut encoder = Encoder::new(&config).unwrap(); @@ -925,7 +925,7 @@ mod tests { fn mediafoundation_cpu_rgba() { let config = Config { kind: Kind::Named("mediafoundation".into()), - ..Config::new(640, 480, crate::Rate::new(30, 1).unwrap()) + ..Config::new(640, 480, crate::FrameRate::new(30, 1).unwrap()) }; let mut encoder = Encoder::new(&config).expect("hardware H.264 encoder available"); assert_eq!(encoder.name(), "mediafoundation"); @@ -973,7 +973,7 @@ mod tests { let config = Config { kind: Kind::Named("mediafoundation".into()), - ..Config::new(w, h, camera.framerate().unwrap_or(crate::Rate::integer(30))) + ..Config::new(w, h, camera.framerate().unwrap_or(crate::FrameRate::integer(30))) }; let mut encoder = Encoder::new(&config).expect("hardware H.264 encoder available"); @@ -1015,7 +1015,7 @@ mod tests { fn set_bitrate_retunes_software_encoder() { let config = Config { kind: Kind::Software, - ..Config::new(320, 240, crate::Rate::new(30, 1).unwrap()) + ..Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()) }; let mut encoder = Encoder::new(&config).unwrap(); @@ -1044,7 +1044,7 @@ mod tests { fn set_bitrate_before_the_first_frame_is_deferred() { let config = Config { kind: Kind::Software, - ..Config::new(320, 240, crate::Rate::new(30, 1).unwrap()) + ..Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()) }; let mut encoder = Encoder::new(&config).unwrap(); @@ -1063,8 +1063,8 @@ mod tests { #[test] fn default_bitrate_scales_with_resolution() { - let small = Config::new(320, 240, crate::Rate::new(30, 1).unwrap()).resolved_bitrate(); - let large = Config::new(1920, 1080, crate::Rate::new(30, 1).unwrap()).resolved_bitrate(); + let small = Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()).resolved_bitrate(); + let large = Config::new(1920, 1080, crate::FrameRate::new(30, 1).unwrap()).resolved_bitrate(); assert!(large > small); assert!(small > moq_net::bandwidth::Rate::ZERO); } @@ -1165,7 +1165,7 @@ mod tests { #[test] fn a_cut_waits_for_the_next_frame_then_clears() { let log = std::sync::Arc::new(std::sync::Mutex::new(Vec::new())); - let config = Config::new(320, 240, crate::Rate::new(30, 1).unwrap()); + let config = Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()); let backend = Recorder { log: log.clone(), cuts: true, @@ -1192,7 +1192,7 @@ mod tests { #[test] fn every_cut_reaches_the_codec() { let log = std::sync::Arc::new(std::sync::Mutex::new(Vec::new())); - let config = Config::new(320, 240, crate::Rate::new(30, 1).unwrap()); + let config = Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()); let backend = Recorder { log: log.clone(), cuts: true, @@ -1217,7 +1217,7 @@ mod tests { #[test] fn a_backend_that_cannot_cut_refuses_up_front() { let log = std::sync::Arc::new(std::sync::Mutex::new(Vec::new())); - let config = Config::new(320, 240, crate::Rate::new(30, 1).unwrap()); + let config = Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()); let backend = Recorder { log: log.clone(), cuts: false, @@ -1248,7 +1248,7 @@ mod tests { fn a_zero_keyframe_interval_is_refused() { let config = Config { gop: Gop::Keyframe { interval: 0 }, - ..Config::new(320, 240, crate::Rate::new(30, 1).unwrap()) + ..Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()) }; let Err(err) = Encoder::new(&config) else { panic!("an empty group cannot open"); @@ -1261,7 +1261,7 @@ mod tests { /// to none. #[test] fn a_sub_frame_keyframe_window_rounds_up_to_one_frame() { - let framerate = crate::Rate::new(30, 1).unwrap(); + let framerate = crate::FrameRate::new(30, 1).unwrap(); assert_eq!( Gop::keyframe_every(std::time::Duration::from_millis(1), framerate), Gop::Keyframe { interval: 1 } @@ -1286,7 +1286,7 @@ mod tests { fn a_mid_stream_cut_emits_an_idr() { let config = Config { kind: Kind::Software, - ..Config::new(320, 240, crate::Rate::new(30, 1).unwrap()) + ..Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()) }; // A GOP far longer than the run, so any IDR here was asked for rather than // inserted on schedule. @@ -1361,7 +1361,7 @@ mod tests { /// point the caller already asked for. #[test] fn a_failed_encode_keeps_the_cut() { - let config = Config::new(320, 240, crate::Rate::new(30, 1).unwrap()); + let config = Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()); let mut encoder = encoder_with(Box::new(Failing), &config); encoder.cut().unwrap(); @@ -1386,7 +1386,7 @@ mod tests { /// collapses the drained tail onto a single instant. #[test] fn a_buffering_backend_keeps_each_frames_timestamp() { - let config = Config::new(320, 240, crate::Rate::new(30, 1).unwrap()); + let config = Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()); let mut encoder = encoder_with(Box::new(Delayed { pending: None }), &config); // The packet handed back while frame `i` goes in belongs to frame `i - 1`, so @@ -1427,7 +1427,7 @@ mod tests { /// `finish`: a live track flushes at every group and keeps going. #[test] fn a_flush_empties_a_pipelined_backend_and_leaves_it_running() { - let config = Config::new(320, 240, crate::Rate::new(30, 1).unwrap()); + let config = Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()); let mut encoder = encoder_with(Box::new(Delayed { pending: None }), &config); let mut group = Vec::new(); @@ -1464,7 +1464,7 @@ mod tests { ] { let config = Config { kind: Kind::Named("videotoolbox".into()), - ..Config::new(size.width, size.height, crate::Rate::new(30, 1).unwrap()) + ..Config::new(size.width, size.height, crate::FrameRate::new(30, 1).unwrap()) }; let mut encoder = Encoder::new(&config).expect("videotoolbox is available on macOS"); @@ -1506,7 +1506,7 @@ mod tests { // samples, so it refuses them instead. let config = Config { kind: Kind::Software, - ..Config::new(small.width, small.height, crate::Rate::new(30, 1).unwrap()) + ..Config::new(small.width, small.height, crate::FrameRate::new(30, 1).unwrap()) }; let mut encoder = Encoder::new(&config).unwrap(); encoder.cut().unwrap(); @@ -1526,7 +1526,7 @@ mod tests { let config = Config { kind: Kind::Software, color: Some(Color::BT709), - ..Config::new(small.width, small.height, crate::Rate::new(30, 1).unwrap()) + ..Config::new(small.width, small.height, crate::FrameRate::new(30, 1).unwrap()) }; let mut encoder = Encoder::new(&config).unwrap(); encoder.cut().unwrap(); @@ -1555,7 +1555,7 @@ mod tests { primaries: Primaries::Bt2020, transfer, }; - let rate = crate::Rate::new(30, 1).unwrap(); + let rate = crate::FrameRate::new(30, 1).unwrap(); let red = [255u8, 0, 0]; for (source, rung, color) in [ // The source's own guess, scaled across 576 lines. @@ -1685,7 +1685,7 @@ mod tests { let config = Config { kind: Kind::Named(backend.into()), color: frame.surface.color(), - ..Config::new(size.width, size.height, crate::Rate::new(30, 1).unwrap()) + ..Config::new(size.width, size.height, crate::FrameRate::new(30, 1).unwrap()) }; let mut encoder = Encoder::new(&config).expect("requested encoder must be available"); assert_eq!(encoder.name(), backend); @@ -1719,7 +1719,7 @@ mod external_tests { #[tokio::test] async fn unknown_external_device_is_refused_at_open_and_probe() { - let mut config = Config::new(320, 240, Rate::new(30, 1).unwrap()); + let mut config = Config::new(320, 240, FrameRate::new(30, 1).unwrap()); config.input = Some(device()); let error = match Encoder::new(&config) { Ok(_) => panic!("opened an unrelated device"), @@ -1735,7 +1735,7 @@ mod external_tests { #[test] fn refuses_external_frame_on_an_encoder_without_that_device() { let config = { - let mut config = Config::new(320, 240, Rate::new(30, 1).unwrap()); + let mut config = Config::new(320, 240, FrameRate::new(30, 1).unwrap()); config.kind = Kind::Named("probe".into()); config }; diff --git a/rs/moq-video/src/encode/producer.rs b/rs/moq-video/src/encode/producer.rs index 2f25402417c..c1061c48038 100644 --- a/rs/moq-video/src/encode/producer.rs +++ b/rs/moq-video/src/encode/producer.rs @@ -20,7 +20,7 @@ use moq_net::Timestamp; use crate::Error; #[cfg(feature = "capture")] -use crate::Rate; +use crate::FrameRate; #[cfg(feature = "capture")] use crate::capture; @@ -36,7 +36,7 @@ use super::encoder::Codec; /// Last-resort framerate when neither the caller nor the camera reports one. #[cfg(feature = "capture")] -const DEFAULT_FRAMERATE: Rate = Rate::integer(30); +const DEFAULT_FRAMERATE: FrameRate = FrameRate::integer(30); /// The [`track::Info::refresh`](moq_net::track::Info::refresh) ratio a capture advertises: a /// joiner forces a keyframe once a group's deltas outweigh twice its keyframe, so later joiners @@ -863,7 +863,7 @@ mod tests { let mut broadcast = moq_net::broadcast::Info::new().produce(); let catalog = moq_mux::catalog::Producer::new(&mut broadcast, moq_mux::catalog::Config::default()).unwrap(); - let mut config = Config::new(320, 240, crate::Rate::new(30, 1).unwrap()); + let mut config = Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()); config.codec = codec; config.kind = kind; @@ -938,7 +938,7 @@ mod tests { .unwrap(); let consumer = track.subscribe(moq_net::track::Subscription::default().with_max_delay(replay)); - let mut config = Config::new(320, 240, crate::Rate::new(30, 1).unwrap()); + let mut config = Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()); config.kind = encoder::Kind::Software; let mut producer = Producer::with_track( track, @@ -970,7 +970,7 @@ mod tests { async fn source_resize_updates_the_published_rendition() { let mut broadcast = moq_net::broadcast::Info::new().produce(); let catalog = moq_mux::catalog::Producer::new(&mut broadcast, moq_mux::catalog::Config::default()).unwrap(); - let mut initial = Config::new(320, 240, crate::Rate::new(30, 1).unwrap()); + let mut initial = Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()); initial.kind = encoder::Kind::Software; let mut producer = Producer::new( broadcast, @@ -983,7 +983,7 @@ mod tests { for (timestamp, config) in [ (0, initial), - (33_333, Config::new(640, 360, crate::Rate::new(30, 1).unwrap())), + (33_333, Config::new(640, 360, crate::FrameRate::new(30, 1).unwrap())), ] { let mut config = config; config.kind = encoder::Kind::Software; @@ -1013,7 +1013,7 @@ mod tests { let mut broadcast = moq_net::broadcast::Info::new().produce(); let catalog = moq_mux::catalog::Producer::new(&mut broadcast, moq_mux::catalog::Config::default()).unwrap(); - let mut config = Config::new(320, 240, crate::Rate::new(30, 1).unwrap()); + let mut config = Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()); // Software (openh264) so the test is deterministic and never touches a hardware backend. config.kind = encoder::Kind::Software; let mut selected = config.probe().await.unwrap(); @@ -1041,7 +1041,7 @@ mod tests { let consumer = broadcast.consume(); let catalog = moq_mux::catalog::Producer::new(&mut broadcast, moq_mux::catalog::Config::default()).unwrap(); - let mut config = Config::new(1920, 1080, crate::Rate::new(30, 1).unwrap()); + let mut config = Config::new(1920, 1080, crate::FrameRate::new(30, 1).unwrap()); config.bitrate = Some(moq_net::bandwidth::Rate::from_mbps(6)); // Software (openh264) so the test is deterministic and never touches a hardware backend. config.kind = encoder::Kind::Software; @@ -1087,7 +1087,7 @@ mod tests { async fn abort_after_finish() { let mut broadcast = moq_net::broadcast::Info::new().produce(); let catalog = moq_mux::catalog::Producer::new(&mut broadcast, moq_mux::catalog::Config::default()).unwrap(); - let mut config = Config::new(320, 240, crate::Rate::new(30, 1).unwrap()); + let mut config = Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()); config.kind = encoder::Kind::Software; let track = broadcast .create_track("video", catalog.track_info(hang::catalog::PRIORITY.video)) @@ -1200,7 +1200,7 @@ mod tests { ) .unwrap(); - let mut probe = Config::new(320, 240, crate::Rate::new(30, 1).unwrap()); + let mut probe = Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()); probe.kind = encoder::Kind::Software; let mut producer = Producer::with_track( track, @@ -1269,7 +1269,8 @@ mod tests { /// Plug in the camera the loop opens next. fn camera(&self) -> Synthetic { - let (camera, stream) = Synthetic::open(crate::Size::new(320, 240), crate::Rate::new(30, 1).unwrap()); + let (camera, stream) = + Synthetic::open(crate::Size::new(320, 240), crate::FrameRate::new(30, 1).unwrap()); self.opens.send(stream).unwrap(); camera } @@ -1557,7 +1558,7 @@ mod tests { } fn camera() -> (Synthetic, capture::Stream) { - Synthetic::open(crate::Size::new(320, 240), crate::Rate::new(30, 1).unwrap()) + Synthetic::open(crate::Size::new(320, 240), crate::FrameRate::new(30, 1).unwrap()) } async fn until(done: impl Fn() -> bool) { @@ -1622,7 +1623,7 @@ mod tests { // Ten nominal fps makes the default two-second GOP twenty frames, which every // script below stays inside. - let rate = crate::Rate::new(10, 1).unwrap(); + let rate = crate::FrameRate::new(10, 1).unwrap(); let (_probe, probe) = Synthetic::open(crate::Size::new(320, 240), rate); let (camera, stream) = Synthetic::open(crate::Size::new(320, 240), rate); let run = tokio::task::spawn_local(driver.run_with(Streams::new([probe, stream]))); @@ -1839,7 +1840,7 @@ mod tests { .create_track("video", catalog.track_info(hang::catalog::PRIORITY.video)) .unwrap(); let _subscriber = track.subscribe(None); - let mut rendition = Config::new(320, 240, crate::Rate::new(30, 1).unwrap()); + let mut rendition = Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()); rendition.kind = encoder::Kind::Software; let mut producer = Producer::with_track( track, @@ -1914,7 +1915,7 @@ mod tests { async fn a_quiet_grant_still_recovers_the_ceiling() { let _probe = probe::exclusive(); let ceiling = Rate::from_mbps(4); - let mut config = encoder::Config::new(320, 240, crate::Rate::new(30, 1).unwrap()); + let mut config = encoder::Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()); config.kind = encoder::Kind::Named(probe::NAME.into()); config.bitrate = Some(ceiling); let mut sink = Sink::open(&config).await.unwrap(); diff --git a/rs/moq-video/src/encode/sink.rs b/rs/moq-video/src/encode/sink.rs index eeffb49c18a..dc49637defe 100644 --- a/rs/moq-video/src/encode/sink.rs +++ b/rs/moq-video/src/encode/sink.rs @@ -391,7 +391,7 @@ mod tests { } fn probe_config() -> Config { - let mut config = Config::new(320, 240, crate::Rate::new(30, 1).unwrap()); + let mut config = Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()); config.codec = Codec::H264; config.kind = Kind::Named(probe::NAME.into()); config @@ -451,7 +451,7 @@ mod tests { #[cfg(feature = "openh264")] #[test] fn the_applied_preset_crosses_the_thread() { - let mut config = Config::new(320, 240, crate::Rate::new(30, 1).unwrap()); + let mut config = Config::new(320, 240, crate::FrameRate::new(30, 1).unwrap()); config.kind = Kind::Software; config.preset = super::super::Preset::Quality; let sink = pollster::block_on(Sink::open(&config)).unwrap(); diff --git a/rs/moq-video/src/frame/cuda_test.rs b/rs/moq-video/src/frame/cuda_test.rs index 96ca2d85a07..f5ed076bdc5 100644 --- a/rs/moq-video/src/frame/cuda_test.rs +++ b/rs/moq-video/src/frame/cuda_test.rs @@ -92,7 +92,7 @@ fn nal_types(annexb: &[u8]) -> Vec { } fn nvenc(size: Size, color: Color) -> crate::encode::Encoder { - let mut config = crate::encode::Config::new(size.width, size.height, crate::Rate::new(30, 1).unwrap()); + let mut config = crate::encode::Config::new(size.width, size.height, crate::FrameRate::new(30, 1).unwrap()); config.kind = crate::encode::Kind::Named("nvenc".into()); config.color = Some(color); config.gop = crate::encode::Gop::Keyframe { interval: 30 }; @@ -541,7 +541,7 @@ async fn vulkan_cuda_auto_external_encode() { }; let mut renditions = Vec::new(); for output in [size, Size::new(160, 96)] { - let mut config = crate::encode::Config::new(output.width, output.height, crate::Rate::new(30, 1).unwrap()); + let mut config = crate::encode::Config::new(output.width, output.height, crate::FrameRate::new(30, 1).unwrap()); config.input = Some(device); config.color = Some(color); config diff --git a/rs/moq-video/src/rate.rs b/rs/moq-video/src/frame_rate.rs similarity index 74% rename from rs/moq-video/src/rate.rs rename to rs/moq-video/src/frame_rate.rs index a434a13fc55..b2748cdead9 100644 --- a/rs/moq-video/src/rate.rs +++ b/rs/moq-video/src/frame_rate.rs @@ -10,7 +10,7 @@ pub const MAX_FRAMES_PER_SECOND: u32 = 1_000_000; /// An invalid video frame rate. #[derive(Clone, Copy, Debug, PartialEq, Eq, thiserror::Error)] #[non_exhaustive] -pub enum RateError { +pub enum FrameRateError { /// The numerator or denominator was zero. #[error("frame rate numerator and denominator must be non-zero")] Zero, @@ -24,19 +24,19 @@ pub enum RateError { /// An exact positive video frame rate, in frames per second. #[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)] -pub struct Rate { +pub struct FrameRate { numerator: u32, denominator: u32, } -impl Rate { +impl FrameRate { /// Construct an exact rate from a numerator and denominator. - pub fn new(numerator: u32, denominator: u32) -> Result { + pub fn new(numerator: u32, denominator: u32) -> Result { if numerator == 0 || denominator == 0 { - return Err(RateError::Zero); + return Err(FrameRateError::Zero); } if u64::from(numerator) > u64::from(MAX_FRAMES_PER_SECOND) * u64::from(denominator) { - return Err(RateError::TooLarge); + return Err(FrameRateError::TooLarge); } let divisor = gcd(numerator, denominator); Ok(Self { @@ -46,12 +46,12 @@ impl Rate { } /// Approximate a finite catalog rate using 32-bit rational components. - pub fn from_f64(value: f64) -> Result { + pub fn from_f64(value: f64) -> Result { if !value.is_finite() || value <= 0.0 { - return Err(RateError::InvalidFloat); + return Err(FrameRateError::InvalidFloat); } if value > f64::from(MAX_FRAMES_PER_SECOND) { - return Err(RateError::TooLarge); + return Err(FrameRateError::TooLarge); } // Continued fractions recover conventional rates such as 30000/1001 from // their JSON floating-point representation without inventing a decimal timebase. @@ -118,20 +118,20 @@ impl Rate { } } -impl Ord for Rate { +impl Ord for FrameRate { fn cmp(&self, other: &Self) -> Ordering { (u64::from(self.numerator) * u64::from(other.denominator)) .cmp(&(u64::from(other.numerator) * u64::from(self.denominator))) } } -impl PartialOrd for Rate { +impl PartialOrd for FrameRate { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } -impl fmt::Display for Rate { +impl fmt::Display for FrameRate { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}/{}", self.numerator, self.denominator) } @@ -153,32 +153,38 @@ mod tests { #[test] fn preserves_broadcast_rates() { assert_eq!( - Rate::new(30_000, 1_001).unwrap(), - Rate::from_f64(30_000.0 / 1_001.0).unwrap() + FrameRate::new(30_000, 1_001).unwrap(), + FrameRate::from_f64(30_000.0 / 1_001.0).unwrap() ); assert_eq!( - Rate::new(60_000, 1_001).unwrap(), - Rate::from_f64(60_000.0 / 1_001.0).unwrap() + FrameRate::new(60_000, 1_001).unwrap(), + FrameRate::from_f64(60_000.0 / 1_001.0).unwrap() ); } #[test] fn validates_components_and_range() { - assert_eq!(Rate::new(30, 0), Err(RateError::Zero)); - assert_eq!(Rate::new(0, 1), Err(RateError::Zero)); - assert_eq!(Rate::new(MAX_FRAMES_PER_SECOND + 1, 1), Err(RateError::TooLarge)); + assert_eq!(FrameRate::new(30, 0), Err(FrameRateError::Zero)); + assert_eq!(FrameRate::new(0, 1), Err(FrameRateError::Zero)); + assert_eq!( + FrameRate::new(MAX_FRAMES_PER_SECOND + 1, 1), + Err(FrameRateError::TooLarge) + ); } #[test] fn rejects_invalid_floats() { - assert_eq!(Rate::from_f64(f64::NAN), Err(RateError::InvalidFloat)); - assert_eq!(Rate::from_f64(f64::INFINITY), Err(RateError::InvalidFloat)); - assert_eq!(Rate::from_f64(f64::NEG_INFINITY), Err(RateError::InvalidFloat)); - assert_eq!(Rate::from_f64(0.0), Err(RateError::InvalidFloat)); - assert_eq!(Rate::from_f64(-30.0), Err(RateError::InvalidFloat)); + assert_eq!(FrameRate::from_f64(f64::NAN), Err(FrameRateError::InvalidFloat)); + assert_eq!(FrameRate::from_f64(f64::INFINITY), Err(FrameRateError::InvalidFloat)); + assert_eq!( + FrameRate::from_f64(f64::NEG_INFINITY), + Err(FrameRateError::InvalidFloat) + ); + assert_eq!(FrameRate::from_f64(0.0), Err(FrameRateError::InvalidFloat)); + assert_eq!(FrameRate::from_f64(-30.0), Err(FrameRateError::InvalidFloat)); assert_eq!( - Rate::from_f64(f64::from(MAX_FRAMES_PER_SECOND) + 1.0), - Err(RateError::TooLarge) + FrameRate::from_f64(f64::from(MAX_FRAMES_PER_SECOND) + 1.0), + Err(FrameRateError::TooLarge) ); } } diff --git a/rs/moq-video/src/lib.rs b/rs/moq-video/src/lib.rs index a784605df25..c6be81e650c 100644 --- a/rs/moq-video/src/lib.rs +++ b/rs/moq-video/src/lib.rs @@ -85,8 +85,8 @@ pub mod resize; mod error; pub mod frame; +mod frame_rate; mod output; -mod rate; mod size; // Only the threaded sinks use this, and both are compiled out on macOS and iOS, where // the codecs run inline (no COM apartment to confine). Ungated it is dead code @@ -105,8 +105,8 @@ pub use error::Error; #[cfg(all(target_os = "linux", feature = "dmabuf"))] pub use frame::{DmaBuf, DmaBufExport, DmaBufLayout, DmaBufPlane, DrmFormat}; pub use frame::{Frame, I420, Surface}; +pub use frame_rate::{FrameRate, FrameRateError, MAX_FRAMES_PER_SECOND}; pub use output::Output; -pub use rate::{MAX_FRAMES_PER_SECOND, Rate, RateError}; pub use size::Size; /// The NDK bindings [`frame::android::HardwareBuffer::buffer`] hands back, diff --git a/rs/moq-video/src/render/renderer.rs b/rs/moq-video/src/render/renderer.rs index bf57bc26784..4ece126e31c 100644 --- a/rs/moq-video/src/render/renderer.rs +++ b/rs/moq-video/src/render/renderer.rs @@ -1190,7 +1190,7 @@ mod tests { let mut encoder = crate::encode::Encoder::new(&crate::encode::Config { kind: crate::encode::Kind::Software, - ..crate::encode::Config::new(width, height, crate::Rate::new(30, 1).unwrap()) + ..crate::encode::Config::new(width, height, crate::FrameRate::new(30, 1).unwrap()) }) .expect("a software H.264 encoder"); @@ -1349,7 +1349,7 @@ mod tests { }; let mut encoder = crate::encode::Encoder::new(&crate::encode::Config { kind: crate::encode::Kind::Software, - ..crate::encode::Config::new(width, height, crate::Rate::new(30, 1).unwrap()) + ..crate::encode::Config::new(width, height, crate::FrameRate::new(30, 1).unwrap()) }) .expect("a software H.264 encoder"); diff --git a/rs/moq-video/src/size.rs b/rs/moq-video/src/size.rs index 1633c087a5f..bdcfedd9261 100644 --- a/rs/moq-video/src/size.rs +++ b/rs/moq-video/src/size.rs @@ -1,4 +1,4 @@ -use crate::{Error, Rate}; +use crate::{Error, FrameRate}; /// A frame resolution in pixels. /// @@ -55,7 +55,7 @@ impl Size { /// /// This is arithmetic, not policy: it rejects only what cannot be represented, /// leaving "no encoder handles a frame that large" to the backend. - pub(crate) fn validate_encodable(&self, what: &str, framerate: Rate) -> Result<(), Error> { + pub(crate) fn validate_encodable(&self, what: &str, framerate: FrameRate) -> Result<(), Error> { let pixels = self.pixels(); let representable = u128::from(pixels) .checked_mul(u128::from(framerate.numerator())) @@ -115,7 +115,7 @@ mod tests { fn validate_encodable_rejects_unrepresentable_sizes() { // A frame nobody can encode, but whose arithmetic still fits: the backend // decides, not us. - let rate = Rate::new(30, 1).unwrap(); + let rate = FrameRate::new(30, 1).unwrap(); assert!(Size::new(65534, 65534).validate_encodable("frame", rate).is_ok()); // pixels x framerate overflows u64. @@ -126,7 +126,7 @@ mod tests { ); // ...and it is the product that matters, not either side alone. assert!(Size::new(u32::MAX - 1, 2).validate_encodable("frame", rate).is_ok()); - let extreme = Rate::new(crate::rate::MAX_FRAMES_PER_SECOND, 1).unwrap(); + let extreme = FrameRate::new(crate::frame_rate::MAX_FRAMES_PER_SECOND, 1).unwrap(); assert!( Size::new(u32::MAX - 1, u32::MAX - 1) .validate_encodable("frame", extreme) diff --git a/rs/moq-video/src/v4l2.rs b/rs/moq-video/src/v4l2.rs index e271f819273..b99c4b466bc 100644 --- a/rs/moq-video/src/v4l2.rs +++ b/rs/moq-video/src/v4l2.rs @@ -498,7 +498,7 @@ impl Device { } /// Declare the input framerate, which rate control uses to spend the bitrate. - pub(crate) fn set_framerate(&self, dir: Dir, framerate: crate::Rate) -> Result<(), Error> { + pub(crate) fn set_framerate(&self, dir: Dir, framerate: crate::FrameRate) -> Result<(), Error> { let mut parm = v4l2_streamparm::zeroed(); parm.type_ = dir.buf_type(); // SAFETY: the buffer type just written picks the arm the driver reads, so