From f81127175a7d63b3ef7ee340c1c1b4debc8e81cc Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 7 Nov 2026 23:47:50 -0800 Subject: [PATCH 1/4] chore(quest): claim quest/m2/bus-minus-several.md Quest-Claim: 054e6565f597502a From 0d54778a653d65946351ed6d161649c122fe0208 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 7 Nov 2026 23:49:38 -0800 Subject: [PATCH 2/4] feat(moq-audio)!: a mix-minus removes several sources Co-Authored-By: Claude Opus 5.5 --- quest/m2/README.md | 1 - quest/m2/bus-minus-several.md | 15 ------ rs/moq-audio/CHANGELOG.md | 4 +- rs/moq-audio/benches/bus.rs | 2 +- rs/moq-audio/src/bus.rs | 92 +++++++++++++++++------------------ 5 files changed, 49 insertions(+), 65 deletions(-) delete mode 100644 quest/m2/bus-minus-several.md diff --git a/quest/m2/README.md b/quest/m2/README.md index fa75bcb69f3..9e0f504482a 100644 --- a/quest/m2/README.md +++ b/quest/m2/README.md @@ -207,7 +207,6 @@ quests that require them. - [Public constructors spawn nothing, or say why](/quest/m2/spawn-constructors.md) - each public library entry point that spawns returns a driver its caller polls, or is listed as kept - [moq-audio codecs return zero or more outputs](/quest/m2/audio-codec-seam.md) - `encode` and `decode` return any number of outputs and gain `flush`, as moq-video's do - [Bus writes land at a bus position](/quest/m2/bus-positioned-write.md) - callers sync audio to video without copying the bus's private latency, before the cut first publishes `bus` -- [A mix-minus removes several sources](/quest/m2/bus-minus-several.md) - a guest's return feed drops every copy of their own sound - [Drop moq-auth's iroh transport](/quest/m2/auth-drop-iroh.md) - this breaking moq-auth release drops `Transport::Iroh` and the JS `"iroh"` value - [Plan: recovery boundaries](/quest/m2/intra-refresh-boundary.md) - the catalog's new `warmup` contract is settled before the cut publishes it - [MoQ on rind](/quest/m1/rind/README.md) - every MoQ crate takes its crypto from rind, a pure-Rust graviola fork, so no build compiles C crypto (held in m1 by an open claim) diff --git a/quest/m2/bus-minus-several.md b/quest/m2/bus-minus-several.md deleted file mode 100644 index 46d3fc5c16a..00000000000 --- a/quest/m2/bus-minus-several.md +++ /dev/null @@ -1,15 +0,0 @@ -# [S] A mix-minus removes several sources - -## Goal - -A `bus` mix-minus takes out any number of sources, so a guest's return feed -can drop every copy of that guest's own sound. - -## Plan - -Decided 2026-11-05 (maintainer, on moq-dev/studio's /quest-plan): m3, since the studio is a named consumer that is not urgent. Moved to m2: Decided 2026-11-07 (maintainer, /quest-plan from the API sweep of open PRs and remaining quests). `moq_audio::bus` is new since `release`, so changing `minus` after the cut would cost another moq-audio major. - -`Mix::minus` (`rs/moq-audio/src/bus.rs`) takes one `Strip`. A studio guest -with a camera and a screen share has two sources of their own sound, so their -return feed echoes one of them ([moq-dev/studio#37](https://github.com/moq-dev/studio/pull/37)). Change `minus` -itself rather than adding a second method. diff --git a/rs/moq-audio/CHANGELOG.md b/rs/moq-audio/CHANGELOG.md index 6be0942208f..0b1038bf567 100644 --- a/rs/moq-audio/CHANGELOG.md +++ b/rs/moq-audio/CHANGELOG.md @@ -15,8 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **Breaking:** the bus routes sources into several mixes. `Bus::new` returns the bus and the one `Driver` that advances it on the caller's clock; each mix has its own meter and independent readers whose blocks carry their clock - position, and a mix-minus drops one source. A strip carries a per-source sync - delay. See `MIGRATE.md`. + position, and a mix-minus drops any set of its sources. A strip carries a + per-source sync delay. See `MIGRATE.md`. - **Breaking:** open one `capture::Producer` and pass its independent consumers to the bus and encoder. Samples, timestamps, source gaps, and terminal failures are shared; slow readers lose only their own expired buffers. See `MIGRATE.md`. diff --git a/rs/moq-audio/benches/bus.rs b/rs/moq-audio/benches/bus.rs index b0438c7d506..3e473cc9668 100644 --- a/rs/moq-audio/benches/bus.rs +++ b/rs/moq-audio/benches/bus.rs @@ -106,7 +106,7 @@ fn bench_minus(c: &mut Criterion) { for (_, strip) in &sources { program.route(strip); } - let minuses: Vec<_> = sources.iter().map(|(_, strip)| program.minus(strip)).collect(); + let minuses: Vec<_> = sources.iter().map(|(_, strip)| program.minus([strip])).collect(); group.bench_function(BenchmarkId::from_parameter(count), |b| { b.iter(|| run(&mut driver, &mut sources, &block)); diff --git a/rs/moq-audio/src/bus.rs b/rs/moq-audio/src/bus.rs index a93e277aeb0..a7502586106 100644 --- a/rs/moq-audio/src/bus.rs +++ b/rs/moq-audio/src/bus.rs @@ -3,7 +3,7 @@ //! A [`Bus`] holds sources, each a [`Channel`] fed with PCM and controlled by a //! [`Strip`] of gain, mute, pan, sync delay, and level meter, and [`Mix`]es, each //! the sum of the sources routed into it. A [`Minus`] is a mix-minus: one mix -//! with one of its sources taken out, for a guest's return feed. Every mix +//! with some of its sources taken out, for a guest's return feed. Every mix //! publishes interleaved `f32` at the bus's [`Config`] to any number of //! independent [`Reader`]s. //! @@ -202,7 +202,8 @@ struct Routed { struct MinusState { id: u64, parent: usize, - excluded: Strip, + /// Deduplicated, so each is subtracted at most once. + excluded: Vec, output: Output, } @@ -444,7 +445,8 @@ impl Driver { /// Call it as the clock advances, with exactly that much time's worth of /// frames: the bus has no clock of its own, so this is what paces every /// source. A source with nothing buffered contributes silence. Each mix - /// costs only the sources routed into it, and a mix-minus one more. + /// costs only the sources routed into it, and a mix-minus one more per + /// source it removes. pub fn advance(&mut self, frames: usize) { if frames == 0 { return; @@ -487,12 +489,14 @@ impl Driver { let buffer = &mut minus.output.buffer; buffer.clear(); buffer.extend_from_slice(&parent.output.buffer); - let excluded = key(&minus.excluded); - if parent.routed.contains(&excluded) - && let Some(source) = sources.get(&excluded) - { - for (out, sample) in buffer.iter_mut().zip(&source.block) { - *out -= *sample; + for strip in &minus.excluded { + let excluded = key(strip); + if parent.routed.contains(&excluded) + && let Some(source) = sources.get(&excluded) + { + for (out, sample) in buffer.iter_mut().zip(&source.block) { + *out -= *sample; + } } } minus.output.publish(*position, channels, self.retention); @@ -706,21 +710,24 @@ impl Mix { routes } - /// A mix-minus: this mix without `strip`'s source, for that source's own - /// return feed. + /// A mix-minus: this mix without the sources of `strips`, such as every + /// source carrying one guest's sound, for that guest's return feed. /// - /// It follows this mix's routing, and costs one subtraction per block - /// rather than a second sum. Keeps this mix alive while it lives. - pub fn minus(&self, strip: &Strip) -> Minus { + /// It follows this mix's routing, and costs one subtraction per removed + /// source per block rather than a second sum. A strip listed twice is + /// removed once. Keeps this mix alive while it lives. + pub fn minus<'a>(&self, strips: impl IntoIterator) -> Minus { let (id, history, level) = match self.shared.bus.upgrade() { Some(bus) => { let id = bus.next.fetch_add(1, Ordering::Relaxed); let mut mixer = bus.mixer.lock().unwrap(); let (output, history, level) = Output::new(mixer.closed); + let mut seen = HashSet::new(); + let excluded = strips.into_iter().filter(|strip| seen.insert(key(strip))).cloned().collect(); mixer.minuses.push(MinusState { id, parent: self.shared.slot, - excluded: strip.clone(), + excluded, output, }); (id, history, level) @@ -761,7 +768,7 @@ impl Mix { } } -/// A mix-minus, built by [`Mix::minus`]: a mix without one of its sources. +/// A mix-minus, built by [`Mix::minus`]: a mix without some of its sources. /// /// Cheap to clone. It ends when its last handle drops. #[derive(Clone)] @@ -1262,50 +1269,43 @@ mod tests { assert!(all_near(&last[1], 0.125)); } - /// A mix-minus is its parent without one source, and follows the parent's - /// routing as it changes. + /// A mix-minus is its parent without each of its sources, and follows the + /// parent's routing as it changes. #[test] - fn a_mix_minus_drops_one_source() { + fn a_mix_minus_drops_its_sources() { let (bus, mut driver) = Bus::new(Config::default()).unwrap(); let (mut host, host_strip) = source(&bus); - let (mut guest, guest_strip) = source(&bus); + let (mut camera, camera_strip) = source(&bus); + let (mut screen, screen_strip) = source(&bus); let (mut music, music_strip) = source(&bus); let program = bus.mix(); - for strip in [&host_strip, &guest_strip, &music_strip] { + for strip in [&host_strip, &camera_strip, &screen_strip, &music_strip] { program.route(strip); } - let guest_return = program.minus(&guest_strip); + // Listing a strip twice removes it once. + let guest_return = program.minus([&camera_strip, &screen_strip, &camera_strip]); let mut minus_reader = guest_return.reader(); let mut program_reader = program.reader(); - let mut sources = [(&mut host, 0.25), (&mut guest, 0.125), (&mut music, 0.0625)]; - let last = feed( - &mut driver, - &mut sources, - &mut [&mut program_reader, &mut minus_reader], - 20, - ); - assert!(all_near(&last[0], 0.4375)); + let mut sources = [ + (&mut host, 0.25), + (&mut camera, 0.125), + (&mut screen, 0.03125), + (&mut music, 0.0625), + ]; + let mut readers = [&mut program_reader, &mut minus_reader]; + let last = feed(&mut driver, &mut sources, &mut readers, 20); + assert!(all_near(&last[0], 0.46875)); assert!(all_near(&last[1], 0.3125)); program.unroute(&music_strip); - let last = feed( - &mut driver, - &mut sources, - &mut [&mut program_reader, &mut minus_reader], - 5, - ); + let last = feed(&mut driver, &mut sources, &mut readers, 5); assert!(all_near(&last[1], 0.25)); - // Excluding a source the parent does not route leaves the parent as is. - program.unroute(&guest_strip); - let last = feed( - &mut driver, - &mut sources, - &mut [&mut program_reader, &mut minus_reader], - 5, - ); - assert!(all_near(&last[0], 0.25)); + // Excluding a source the parent does not route leaves the rest removed. + program.unroute(&camera_strip); + let last = feed(&mut driver, &mut sources, &mut readers, 5); + assert!(all_near(&last[0], 0.28125)); assert!(all_near(&last[1], 0.25)); // The mix-minus keeps its parent mixed after the parent's handle drops. @@ -1549,7 +1549,7 @@ mod tests { ready(&mut bus.mix().reader()).is_none(), "a mix made after the driver ends at once" ); - assert!(ready(&mut kept.minus(&Strip::default()).reader()).is_none()); + assert!(ready(&mut kept.minus([&Strip::default()]).reader()).is_none()); } /// The bus runs on whatever clock its caller owns. Paced by `kio::clock` on From da224ee136ab9b861e4312f1953295163688402e Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sat, 7 Nov 2026 23:56:00 -0800 Subject: [PATCH 3/4] style: rustfmt --- rs/moq-audio/src/bus.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rs/moq-audio/src/bus.rs b/rs/moq-audio/src/bus.rs index a7502586106..a2f9ac57aa9 100644 --- a/rs/moq-audio/src/bus.rs +++ b/rs/moq-audio/src/bus.rs @@ -723,7 +723,11 @@ impl Mix { let mut mixer = bus.mixer.lock().unwrap(); let (output, history, level) = Output::new(mixer.closed); let mut seen = HashSet::new(); - let excluded = strips.into_iter().filter(|strip| seen.insert(key(strip))).cloned().collect(); + let excluded = strips + .into_iter() + .filter(|strip| seen.insert(key(strip))) + .cloned() + .collect(); mixer.minuses.push(MinusState { id, parent: self.shared.slot, From b2df562a09d49944d31336a3dcad769497819927 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 8 Nov 2026 00:01:40 -0800 Subject: [PATCH 4/4] fix(moq-audio): collect a mix-minus's strips before locking the mixer Co-Authored-By: Claude Opus 5.5 --- rs/moq-audio/src/bus.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/rs/moq-audio/src/bus.rs b/rs/moq-audio/src/bus.rs index a2f9ac57aa9..106dfb98499 100644 --- a/rs/moq-audio/src/bus.rs +++ b/rs/moq-audio/src/bus.rs @@ -717,17 +717,18 @@ impl Mix { /// source per block rather than a second sum. A strip listed twice is /// removed once. Keeps this mix alive while it lives. pub fn minus<'a>(&self, strips: impl IntoIterator) -> Minus { + // Collected before locking the mixer, since the caller's iterator may lock it. + let mut seen = HashSet::new(); + let excluded: Vec = strips + .into_iter() + .filter(|strip| seen.insert(key(strip))) + .cloned() + .collect(); let (id, history, level) = match self.shared.bus.upgrade() { Some(bus) => { let id = bus.next.fetch_add(1, Ordering::Relaxed); let mut mixer = bus.mixer.lock().unwrap(); let (output, history, level) = Output::new(mixer.closed); - let mut seen = HashSet::new(); - let excluded = strips - .into_iter() - .filter(|strip| seen.insert(key(strip))) - .cloned() - .collect(); mixer.minuses.push(MinusState { id, parent: self.shared.slot, @@ -1286,8 +1287,13 @@ mod tests { for strip in [&host_strip, &camera_strip, &screen_strip, &music_strip] { program.route(strip); } - // Listing a strip twice removes it once. - let guest_return = program.minus([&camera_strip, &screen_strip, &camera_strip]); + // Listing a strip twice removes it once, and the strips may come from an + // iterator that reads the bus. + let guest_return = program.minus( + [&camera_strip, &screen_strip, &camera_strip] + .into_iter() + .filter(|strip| program.routes(strip)), + ); let mut minus_reader = guest_return.reader(); let mut program_reader = program.reader();