diff --git a/doc/lib/rs/moq-audio.md b/doc/lib/rs/moq-audio.md index 40e062bb04e..ba5a7256a3b 100644 --- a/doc/lib/rs/moq-audio.md +++ b/doc/lib/rs/moq-audio.md @@ -34,8 +34,10 @@ policy. Decoding likewise separates low-level `decode::Config`, PCM | `aec` | Acoustic echo cancellation (a port of WebRTC's), so a laptop with no headset doesn't feed itself back | `decode` picks a backend per track the way `moq-video` does: a platform decoder -first, then software. `decode::Config::kind` forces one (`Kind::Software`, or -`Kind::Named` with a name below), and `Decoder::name()` reports what opened. +first, then software. `decode::Config::kind` narrows it: `Kind::Software` skips +the platform tier, and `Kind::Named` requires the track to be a codec, by its +name (`"opus"`, `"pcm"`, or `"aac"`), and refuses any other. Backends are never +named; `Decoder::name()` reports which one opened. | Backend | Decodes | Hosts | | --- | --- | --- | @@ -57,7 +59,8 @@ catalog with neither. A description that is present but malformed (truncated, wrong signature, a new major version, or a channel count its mapping family forbids) is refused rather than falling back to the catalog's fields. -`encode` selects the same way, through `encode::Settings::kind`, and +`encode` selects the same way, through `encode::Settings::kind`, where +`Kind::Named` requires `Settings::codec` to match the codec name, and `Encoder::name()` reports what opened. | Backend | Encodes | Hosts | diff --git a/quest/m1/audio-codecs/README.md b/quest/m1/audio-codecs/README.md index 74b7a30195c..cc301af29ce 100644 --- a/quest/m1/audio-codecs/README.md +++ b/quest/m1/audio-codecs/README.md @@ -43,7 +43,6 @@ its own decode and encode quest so verification stays per host. ## Required -- [Named codecs](/quest/m1/audio-codecs/named-codecs.md) - `decode::Kind::Named` keeps the published codec names and picks backends internally; must land before the line merges - [AudioToolbox decode](/quest/m1/audio-codecs/decode-audiotoolbox.md) - macOS and iOS decode HE-AAC, multichannel AAC, and what else the framework offers - [HE-AAC catalog output](/quest/m1/audio-codecs/he-aac-catalog-output.md) - HE-AAC catalog entries name the output rate and layout, not the LC core - [TS Opus export refusals](/quest/m1/audio-codecs/ts-opus-export-refusals.md) - the TS exporter refuses Opus heads its channel code cannot describe instead of mislabeling them diff --git a/quest/m1/audio-codecs/named-codecs.md b/quest/m1/audio-codecs/named-codecs.md deleted file mode 100644 index 4bba08d514e..00000000000 --- a/quest/m1/audio-codecs/named-codecs.md +++ /dev/null @@ -1,27 +0,0 @@ -# [XS] Kind::Named keeps its codec names - -## Goal - -`moq_audio::decode::Kind::Named` accepts what published moq-audio 0.1.6 -accepts, the codec names (`"opus"`, `"aac"`, `"pcm"`), so the line can merge -to `main` without breaking callers. [#4131](https://github.com/moq-dev/moq/pull/4131) -switched it to backend names (`"libopus"`, `"symphonia"`, `"pcm"`) on the line -branch, which turns every existing `Named("opus")` or `Named("aac")` into -`Error::Unsupported` after an upgrade. This must land before the line PR -[#4081](https://github.com/moq-dev/moq/pull/4081) merges to `main`. - -## Plan - -- Decided: keep codec names; backends are picked internally. Which backend - decodes AAC (AudioToolbox, Media Foundation, symphonia) is the library's - choice through `Auto` and `Software`, not a string a caller has to know and - that changes per platform. This reverses #4131's reasoning on purpose: the - published contract wins over matching moq-video's backend naming. -- Make `encode::Kind` read the same way. It is unpublished, so drop `Named` - there or give it the same codec meaning, whichever leaves the two enums - mirrored; don't keep backend names on one side only. -- Tests that forced a backend by name move to a crate-private seam. -- Docs and the `Kind` doc comments list the codec names. - -Public API: `decode::Kind::Named` returns to its published meaning, so the -line stays additive on `main`. Wire: none. diff --git a/rs/moq-audio/src/decode/backend/mod.rs b/rs/moq-audio/src/decode/backend/mod.rs index f39bb4c170c..6b25cbab5d8 100644 --- a/rs/moq-audio/src/decode/backend/mod.rs +++ b/rs/moq-audio/src/decode/backend/mod.rs @@ -6,7 +6,8 @@ //! //! [`open`] tries the platform decoders before the software ones, skipping any //! that does not advertise the catalog codec, and refuses when none opens the -//! track. The software tier is libopus for Opus, a passthrough for PCM, and +//! track. [`Kind::Named`] names the codec, not a backend, so which backend +//! decodes it stays the library's choice. The software tier is libopus for Opus, a passthrough for PCM, and //! symphonia for AAC-LC mono and stereo (behind the `aac` feature). No platform //! decoder is wired in yet. @@ -42,7 +43,8 @@ pub(crate) trait Backend: Send { 0 } - /// The stable lowercase name [`Kind::Named`] selects this backend by. + /// The stable lowercase name of this backend, as [`Decoder::name`](super::Decoder::name) + /// reports it. Callers never select by it. fn name(&self) -> &str; } @@ -80,9 +82,28 @@ const SOFTWARE: &[Candidate] = &[ }, ]; +/// The name [`Kind::Named`] uses for a catalog codec, `None` for one this crate has no name for. +fn codec_name(codec: &AudioCodec) -> Option<&'static str> { + match codec { + AudioCodec::Opus => Some("opus"), + AudioCodec::Pcm => Some("pcm"), + AudioCodec::AAC(_) => Some("aac"), + _ => None, + } +} + /// Open the first backend that advertises the catalog codec and accepts the track. pub(crate) fn open(catalog: &AudioConfig, config: &Config) -> Result, Error> { - select(catalog, &config.kind, candidates(&config.kind, PLATFORM, SOFTWARE)) + if let Kind::Named(requested) = &config.kind + && codec_name(&catalog.codec) != Some(requested) + { + return Err(Error::Unsupported(format!( + "audio decoder {requested:?} is unavailable for {}", + catalog.codec + ))); + } + + select(catalog, candidates(&config.kind, PLATFORM, SOFTWARE)) } /// The candidates `kind` allows, in the order to try them. @@ -91,13 +112,13 @@ pub(crate) fn open(catalog: &AudioConfig, config: &Config) -> Result(kind: &Kind, platform: &'a [Candidate], software: &'a [Candidate]) -> Vec<&'a Candidate> { match kind { - Kind::Auto => platform.iter().chain(software).collect(), Kind::Software => software.iter().collect(), - Kind::Named(name) => platform.iter().chain(software).filter(|c| c.name == name).collect(), + // `open` has already checked that a name matches the codec. + Kind::Auto | Kind::Named(_) => platform.iter().chain(software).collect(), } } -fn select(catalog: &AudioConfig, kind: &Kind, candidates: Vec<&Candidate>) -> Result, Error> { +fn select(catalog: &AudioConfig, candidates: Vec<&Candidate>) -> Result, Error> { let codec = &catalog.codec; let mut refused = Vec::new(); @@ -122,21 +143,7 @@ fn select(catalog: &AudioConfig, kind: &Kind, candidates: Vec<&Candidate>) -> Re return Err(Error::Unsupported(reasons.join(", "))); } - match kind { - Kind::Named(name) => { - let available: Vec<&str> = PLATFORM - .iter() - .chain(SOFTWARE) - .filter(|c| (c.supports)(codec)) - .map(|c| c.name) - .collect(); - Err(Error::Unsupported(format!( - "no audio decoder named {name:?} for {codec} (this build has: {})", - available.join(", ") - ))) - } - _ => Err(Error::Unsupported(format!("unsupported audio codec: {codec}"))), - } + Err(Error::Unsupported(format!("unsupported audio codec: {codec}"))) } #[cfg(test)] @@ -204,7 +211,7 @@ mod tests { } fn pick(kind: Kind, platform: &[Candidate], software: &[Candidate]) -> Result { - let backend = select(&opus(), &kind, candidates(&kind, platform, software))?; + let backend = select(&opus(), candidates(&kind, platform, software))?; Ok(backend.name().to_owned()) } @@ -226,22 +233,11 @@ mod tests { assert_eq!(name, "software"); } + /// A codec name is not a backend selector: it tries the same tiers as `Auto`. #[test] - fn named_forces_one() { - let name = pick( - Kind::Named("software".into()), - &[PLATFORM_STUB], - &[PCM_ONLY, SOFTWARE_STUB], - ) - .unwrap(); - assert_eq!(name, "software"); - } - - /// A named backend that refuses the track is the answer: nothing else is tried. - #[test] - fn named_refusal_does_not_fall_back() { - let err = pick(Kind::Named("refusing".into()), &[REFUSING], &[SOFTWARE_STUB]).unwrap_err(); - assert!(err.to_string().contains("not this track"), "{err}"); + fn named_codec_picks_like_auto() { + let name = pick(Kind::Named("opus".into()), &[PLATFORM_STUB], &[SOFTWARE_STUB]).unwrap(); + assert_eq!(name, "platform"); } #[test] @@ -259,45 +255,33 @@ mod tests { ); } - /// An unknown name says what this build has for the codec instead. - #[test] - fn unknown_name_lists_the_alternatives() { - let err = open( - &opus(), - &Config { - kind: Kind::Named("opus".into()), - }, - ) - .err() - .expect("no backend is named after its codec"); - let message = err.to_string(); - assert!( - message.contains("\"opus\"") && message.contains(libopus::NAME), - "{message}" - ); + fn named(name: &str) -> Config { + Config { + kind: Kind::Named(name.into()), + } } - /// Asking for a real backend that does not decode the codec is refused, not - /// quietly swapped for one that does. + /// The codec names published moq-audio accepts still open their codec. #[test] - fn named_backend_for_another_codec_is_refused() { - let config = Config { - kind: Kind::Named(pcm::NAME.into()), - }; - assert!(matches!(open(&opus(), &config), Err(Error::Unsupported(_)))); + fn codec_names_open_their_codec() { + let pcm = AudioConfig::new(AudioCodec::Pcm, 48_000, 2); + assert_eq!(open(&pcm, &named("pcm")).unwrap().name(), pcm::NAME); + assert_eq!(open(&opus(), &named("opus")).unwrap().name(), libopus::NAME); } + /// A name for another codec is refused, not quietly swapped for one that decodes. #[test] - fn software_backends_open_by_name() { - let pcm = AudioConfig::new(AudioCodec::Pcm, 48_000, 2); - let config = Config { - kind: Kind::Named(pcm::NAME.into()), - }; - assert_eq!(open(&pcm, &config).unwrap().name(), pcm::NAME); + fn another_codecs_name_is_refused() { + assert!(matches!(open(&opus(), &named("pcm")), Err(Error::Unsupported(_)))); + } - let config = Config { - kind: Kind::Named(libopus::NAME.into()), - }; - assert_eq!(open(&opus(), &config).unwrap().name(), libopus::NAME); + /// Backend names are internal: asking for one is refused like any unknown name. + #[test] + fn backend_names_are_refused() { + let message = open(&opus(), &named(libopus::NAME)) + .err() + .expect("libopus is a backend, not a codec") + .to_string(); + assert!(message.contains("\"libopus\"") && message.contains("opus"), "{message}"); } } diff --git a/rs/moq-audio/src/decode/decoder.rs b/rs/moq-audio/src/decode/decoder.rs index 2a16214a072..ded1fb53dbb 100644 --- a/rs/moq-audio/src/decode/decoder.rs +++ b/rs/moq-audio/src/decode/decoder.rs @@ -17,8 +17,9 @@ pub enum Kind { Auto, /// Require a software backend. Software, - /// Require a backend by its stable lowercase name: `"libopus"`, `"pcm"`, or - /// `"symphonia"`. + /// Require the track to be this codec, by its lowercase name: `"opus"`, + /// `"pcm"`, or `"aac"`. Any other codec is refused. The library still picks + /// the backend, platform first. Named(String), } @@ -371,6 +372,24 @@ pub(crate) mod tests { )); } + /// Published moq-audio accepts the codec's name, not a backend's. + #[cfg(feature = "aac")] + #[test] + fn named_aac_decodes_aac() { + let config = Config { + kind: Kind::Named("aac".into()), + }; + assert!(Decoder::new(&aac_catalog(), &config).is_ok()); + + let config = Config { + kind: Kind::Named("opus".into()), + }; + assert!(matches!( + Decoder::new(&aac_catalog(), &config), + Err(Error::Unsupported(_)) + )); + } + #[test] fn refuses_unavailable_backend() { let catalog = hang::catalog::AudioConfig::new(hang::catalog::AudioCodec::Pcm, 48_000, 2); diff --git a/rs/moq-audio/src/encode/backend/mod.rs b/rs/moq-audio/src/encode/backend/mod.rs index 1879d49f37e..ba277b8eba0 100644 --- a/rs/moq-audio/src/encode/backend/mod.rs +++ b/rs/moq-audio/src/encode/backend/mod.rs @@ -8,7 +8,9 @@ //! read back from the backend. //! //! [`open`] tries the platform encoders before the software ones, skipping any -//! that does not emit the codec, and refuses when none opens. The software tier +//! that does not emit the codec, and refuses when none opens. [`Kind::Named`] +//! names the codec, not a backend, so which backend encodes it stays the +//! library's choice. The software tier //! is libopus for Opus and a passthrough for PCM. AAC has no software encoder, //! so it is only as available as the platform's, and no platform encoder is //! wired in yet. @@ -54,7 +56,8 @@ pub(crate) trait Backend: Send { /// rate: Opus lookahead, AAC encoder delay. fn delay(&self) -> usize; - /// The stable lowercase name [`Kind::Named`] selects this backend by. + /// The stable lowercase name of this backend, as [`Encoder::name`](super::Encoder::name) + /// reports it. Callers never select by it. fn name(&self) -> &str; } @@ -81,21 +84,35 @@ const SOFTWARE: &[Candidate] = &[ }, ]; -/// Test-only backends, in neither tier so `Auto` and `Software` never pick one: -/// they exist to be asked for by name. +/// The platform tier on a test thread that called [`stub::install`], so AAC tests +/// open the same backend on every host and every other test sees the real tiers. #[cfg(test)] -const NAMED_ONLY: &[Candidate] = &[Candidate { +const STUB_PLATFORM: &[Candidate] = &[Candidate { name: stub::NAME, codecs: &[Codec::Aac], open: stub::Stub::open, }]; -#[cfg(not(test))] -const NAMED_ONLY: &[Candidate] = &[]; - /// Open the first backend that emits the codec and accepts the settings. pub(crate) fn open(settings: &Settings) -> Result, Error> { - select(settings, candidates(&settings.kind, PLATFORM, SOFTWARE)) + if let Kind::Named(requested) = &settings.kind + && requested != settings.codec.as_str() + { + return Err(Error::Unsupported(format!( + "audio encoder {requested:?} is unavailable for {}", + settings.codec + ))); + } + + #[cfg(test)] + let platform = match stub::installed() { + true => STUB_PLATFORM, + false => PLATFORM, + }; + #[cfg(not(test))] + let platform = PLATFORM; + + select(settings, candidates(&settings.kind, platform, SOFTWARE)) } /// The candidates `kind` allows, in the order to try them. @@ -104,14 +121,9 @@ pub(crate) fn open(settings: &Settings) -> Result, Error> { /// this host compiles in. fn candidates<'a>(kind: &Kind, platform: &'a [Candidate], software: &'a [Candidate]) -> Vec<&'a Candidate> { match kind { - Kind::Auto => platform.iter().chain(software).collect(), Kind::Software => software.iter().collect(), - Kind::Named(name) => platform - .iter() - .chain(software) - .chain(NAMED_ONLY) - .filter(|c| c.name == name) - .collect(), + // `open` has already checked that a name matches the codec. + Kind::Auto | Kind::Named(_) => platform.iter().chain(software).collect(), } } @@ -150,9 +162,8 @@ fn select(settings: &Settings, candidates: Vec<&Candidate>) -> Result available.join(", "), }; Err(Error::Unsupported(match &settings.kind { - Kind::Named(name) => format!("no audio encoder named {name:?} for {codec} (this build has: {available})"), Kind::Software => format!("no software {codec} audio encoder (this build has: {available})"), - Kind::Auto => format!("no {codec} audio encoder (this build has: {available})"), + Kind::Auto | Kind::Named(_) => format!("no {codec} audio encoder (this build has: {available})"), })) } @@ -245,22 +256,11 @@ mod tests { assert_eq!(name, "software"); } + /// A codec name is not a backend selector: it tries the same tiers as `Auto`. #[test] - fn named_forces_one() { - let name = pick( - Kind::Named("software".into()), - &[PLATFORM_STUB], - &[PCM_ONLY, SOFTWARE_STUB], - ) - .unwrap(); - assert_eq!(name, "software"); - } - - /// A named backend that refuses the settings is the answer: nothing else is tried. - #[test] - fn named_refusal_does_not_fall_back() { - let err = pick(Kind::Named("refusing".into()), &[REFUSING], &[SOFTWARE_STUB]).unwrap_err(); - assert!(err.to_string().contains("not these settings"), "{err}"); + fn named_codec_picks_like_auto() { + let name = pick(Kind::Named("aac".into()), &[PLATFORM_STUB], &[SOFTWARE_STUB]).unwrap(); + assert_eq!(name, "platform"); } #[test] @@ -288,36 +288,47 @@ mod tests { assert!(message.contains("aac") && message.contains("none"), "{message}"); } - /// An unknown name says what this build has for the codec instead. + /// The stub stands in for the platform tier only, so `Software` still refuses + /// AAC with it installed. #[test] - fn unknown_name_lists_the_alternatives() { - let settings = Settings { - kind: Kind::Named("opus".into()), + fn stub_is_not_software() { + let _stub = stub::install(); + assert_eq!(open(&aac(Kind::Auto)).unwrap().name(), stub::NAME); + + let err = open(&aac(Kind::Software)).err().expect("no software AAC encoder"); + assert!(err.to_string().contains("no software aac"), "{err}"); + } + + fn named(codec: Codec, name: &str) -> Settings { + Settings { + codec, + kind: Kind::Named(name.into()), ..Settings::default() - }; - let message = open(&settings) - .err() - .expect("no backend is named after its codec") - .to_string(); - assert!( - message.contains("\"opus\"") && message.contains(libopus::NAME), - "{message}" - ); + } } + /// A codec's own name opens that codec, like `Auto`. #[test] - fn software_backends_open_by_name() { - let settings = Settings { - kind: Kind::Named(libopus::NAME.into()), - ..Settings::default() - }; - assert_eq!(open(&settings).unwrap().name(), libopus::NAME); + fn codec_names_open_their_codec() { + let _stub = stub::install(); + assert_eq!(open(&named(Codec::Opus, "opus")).unwrap().name(), libopus::NAME); + assert_eq!(open(&named(Codec::Pcm, "pcm")).unwrap().name(), pcm::NAME); + assert_eq!(open(&named(Codec::Aac, "aac")).unwrap().name(), stub::NAME); + } - let settings = Settings { - codec: Codec::Pcm, - kind: Kind::Named(pcm::NAME.into()), - ..Settings::default() - }; - assert_eq!(open(&settings).unwrap().name(), pcm::NAME); + /// A name for another codec is refused, not quietly swapped for the settings' codec. + #[test] + fn another_codecs_name_is_refused() { + assert!(matches!(open(&named(Codec::Opus, "pcm")), Err(Error::Unsupported(_)))); + } + + /// Backend names are internal: asking for one is refused like any unknown name. + #[test] + fn backend_names_are_refused() { + let message = open(&named(Codec::Opus, libopus::NAME)) + .err() + .expect("libopus is a backend, not a codec") + .to_string(); + assert!(message.contains("\"libopus\"") && message.contains("opus"), "{message}"); } } diff --git a/rs/moq-audio/src/encode/backend/stub.rs b/rs/moq-audio/src/encode/backend/stub.rs index c581332c156..a64cf664689 100644 --- a/rs/moq-audio/src/encode/backend/stub.rs +++ b/rs/moq-audio/src/encode/backend/stub.rs @@ -1,5 +1,8 @@ //! A stand-in AAC encoder, so the AAC front end is testable on a host with no -//! platform encoder. Selectable only by name, and only in tests. +//! platform encoder. A test opts in with [`install`]; every other test sees the +//! real tiers. + +use std::cell::Cell; use bytes::Bytes; @@ -12,6 +15,30 @@ pub(crate) const NAME: &str = "stub"; /// The AudioToolbox AAC-LC encoder delay, which is what a real backend reports. pub(crate) const DELAY: usize = 2112; +thread_local! { + static INSTALLED: Cell = const { Cell::new(false) }; +} + +/// Stand the stub in for the platform tier on this thread until the guard drops. +pub(crate) fn install() -> Installed { + INSTALLED.set(true); + Installed(()) +} + +/// Whether this thread has the stub installed. +pub(super) fn installed() -> bool { + INSTALLED.get() +} + +/// Uninstalls the stub on drop. +pub(crate) struct Installed(()); + +impl Drop for Installed { + fn drop(&mut self) { + INSTALLED.set(false); + } +} + /// Emits each frame's index as its payload, and cannot retune. pub(crate) struct Stub { bitrate: u64, diff --git a/rs/moq-audio/src/encode/encoder.rs b/rs/moq-audio/src/encode/encoder.rs index 5f908c8b686..95872c644dc 100644 --- a/rs/moq-audio/src/encode/encoder.rs +++ b/rs/moq-audio/src/encode/encoder.rs @@ -80,7 +80,9 @@ pub enum Kind { Auto, /// Require a software backend. Software, - /// Require a backend by its stable lowercase name: `"libopus"` or `"pcm"`. + /// Require [`Settings::codec`] to be this codec, by its lowercase name: + /// `"opus"`, `"pcm"`, or `"aac"`. Any other codec is refused. The library + /// still picks the backend, platform first. Named(String), } @@ -839,18 +841,29 @@ mod tests { assert!(matches!(Encoder::new(&settings), Err(Error::Unsupported(_)))); } - /// AAC settings routed to the test stub, since this host has no AAC encoder. fn aac(layout: Layout) -> Settings { - Settings { - kind: Kind::Named(backend::stub::NAME.into()), - ..Settings::from_input(Codec::Aac, &Input::new(48_000, layout)) - } + Settings::from_input(Codec::Aac, &Input::new(48_000, layout)) + } + + /// Open `settings` on the test stub, since this host has no AAC encoder. + fn stub(settings: &Settings) -> Result { + let _stub = backend::stub::install(); + Encoder::new(settings) + } + + /// Without the stub, the public constructor sees the real tiers and refuses. + #[test] + fn aac_is_refused_without_an_encoder() { + let err = Encoder::new(&aac(Layout::Stereo)) + .err() + .expect("no AAC encoder on this host"); + assert!(matches!(err, Error::Unsupported(_)), "{err}"); } /// The ASC is synthesized from the settings, so it exists before any packet. #[test] fn aac_catalog_carries_the_synthesized_asc() { - let enc = Encoder::new(&aac(Layout::Stereo)).unwrap(); + let enc = stub(&aac(Layout::Stereo)).unwrap(); assert_eq!(enc.name(), backend::stub::NAME); assert_eq!(enc.frame_size(), 1024); @@ -875,7 +888,7 @@ mod tests { (Layout::FivePointOne, 6), (Layout::SevenPointOne, 7), ] { - let catalog = Encoder::new(&aac(layout)).unwrap().catalog(); + let catalog = stub(&aac(layout)).unwrap().catalog(); let description = catalog.description.unwrap(); assert_eq!(description[1] >> 3 & 0xF, config, "{layout:?}"); assert_eq!(catalog.channel_count, layout.channels(), "{layout:?}"); @@ -887,10 +900,7 @@ mod tests { Layout::SixPointOne, Layout::Discrete(2), ] { - assert!( - matches!(Encoder::new(&aac(layout)), Err(Error::Unsupported(_))), - "{layout:?}" - ); + assert!(matches!(stub(&aac(layout)), Err(Error::Unsupported(_))), "{layout:?}"); } } @@ -902,13 +912,13 @@ mod tests { frame_duration: Duration::from_micros(21_333), ..aac(Layout::Stereo) }; - assert_eq!(Encoder::new(&settings).unwrap().frame_size(), 1024); + assert_eq!(stub(&settings).unwrap().frame_size(), 1024); let settings = Settings { frame_duration: Duration::from_millis(20), ..aac(Layout::Stereo) }; - let err = Encoder::new(&settings).err().expect("20 ms is 960 samples"); + let err = stub(&settings).err().expect("20 ms is 960 samples"); assert!(err.to_string().contains("1024"), "{err}"); } @@ -918,13 +928,13 @@ mod tests { dtx: true, ..aac(Layout::Stereo) }; - assert!(matches!(Encoder::new(&settings), Err(Error::Unsupported(_)))); + assert!(matches!(stub(&settings), Err(Error::Unsupported(_)))); } /// A backend that can't retune keeps its opening rate. #[test] fn fixed_rate_backend_keeps_its_opening_rate() { - let mut enc = Encoder::new(&Settings { + let mut enc = stub(&Settings { bitrate: Some(moq_net::bandwidth::Rate::from_bps(96_000)), ..aac(Layout::Stereo) }) @@ -940,7 +950,7 @@ mod tests { /// The drain pushes the encoder delay out through whole silent frames. #[test] fn aac_finish_drains_the_encoder_delay() { - let mut enc = Encoder::new(&aac(Layout::Mono)).unwrap(); + let mut enc = stub(&aac(Layout::Mono)).unwrap(); assert_eq!(enc.folded_delay(), backend::stub::DELAY); enc.encode(&[0.0; 1024]).unwrap(); diff --git a/rs/moq-audio/src/encode/producer.rs b/rs/moq-audio/src/encode/producer.rs index afb0b737221..742f5636793 100644 --- a/rs/moq-audio/src/encode/producer.rs +++ b/rs/moq-audio/src/encode/producer.rs @@ -925,13 +925,12 @@ mod tests { let input = Input::new(48_000, Layout::Mono); let options = Options { track: Some("audio".to_string()), - settings: Settings { - kind: crate::encode::Kind::Named(crate::encode::backend::stub::NAME.into()), - ..Settings::from_input(crate::encode::Codec::Aac, &input) - }, + settings: Settings::from_input(crate::encode::Codec::Aac, &input), ..Options::default() }; + let stub = crate::encode::backend::stub::install(); let mut producer = Producer::new(&mut broadcast, catalog, input, &options).unwrap(); + drop(stub); let track = consumer .track("audio")