From 5b825b0dda2e946bd49465fae64fafbf94000d8c Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 9 Sep 2026 23:49:58 -0700 Subject: [PATCH 1/2] chore: claim quest/m1/2815-lift-adaptive-stage-refusal From 89378685e5b09b312079f93cc92cb0eb0382a954 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 10 Sep 2026 00:06:19 -0700 Subject: [PATCH 2/2] feat(cli): accept several adaptive import stages on one connection The connection allocator already divides the estimate among encoding stages, so two import capture stages on --connect are valid. Co-Authored-By: grok-4.6 --- quest/m1/2815-lift-adaptive-stage-refusal.md | 49 --------- ...s-reserve-no-bandwidth-so-a-co-resident.md | 1 - quest/m1/README.md | 1 - ...bandwidth-grant-in-moq-audio-instead-of.md | 1 - rs/moq-cli/src/args.rs | 99 +------------------ 5 files changed, 5 insertions(+), 146 deletions(-) delete mode 100644 quest/m1/2815-lift-adaptive-stage-refusal.md diff --git a/quest/m1/2815-lift-adaptive-stage-refusal.md b/quest/m1/2815-lift-adaptive-stage-refusal.md deleted file mode 100644 index e75bfc46ffb..00000000000 --- a/quest/m1/2815-lift-adaptive-stage-refusal.md +++ /dev/null @@ -1,49 +0,0 @@ -# [XS] moq-cli runs several adaptive import stages on one connection - -## Goal - -Two encoding stages over one connection, `moq --connect import capture --- import capture`, are accepted, and both encoders target shares of the -connection's estimate that sum to at most it, surplus left unclaimed when a -ceiling binds. The refusal in `rs/moq-cli/src/args.rs:277-282`, "a stage that -encodes to fit the connection's bandwidth estimate assumes it's the only -publisher", is gone with the test that asserts it. - -## Plan - -The allocator #2854 landed on dev is what the refusal stood in for: -`spawn_moq` mints one `bandwidth::Allocator` per connection -(`rs/moq-cli/src/main.rs:295-319`) and clones it into every import stage -(`main.rs:367`, `:380`), and every encoding sender reserves against it: the -moq-video capture loop (`rs/moq-video/src/encode/producer.rs:467-469`) and -moq-audio's `publish_capture` driver -(`rs/moq-audio/src/encode/capture.rs:471-474`). So the guard refuses a -configuration the allocator already divides by track priority -(`rs/hang/src/catalog/priority.rs:21-26`). - -- Delete the `adaptive` / `imports == 1` ensure and - `an_adaptive_capture_must_be_the_only_import` (`args.rs:1175`). Keep - `audio_only_capture_is_not_bandwidth_adaptive` (`:1233`) only if - `uses_bandwidth` (`:690`) still has a reader; otherwise delete both. -- Acceptance stays at the args and allocator unit level, since two - default-device captures would open the same camera: an args test that runs - `Invocation::validate`, the entry point the CLI uses, and accepts the - combination rather than only parsing it; and a test next to the allocator's - `concurrent_tracks_split_the_estimate` in - `rs/moq-net/src/model/bandwidth.rs` where two video wants on one estimate - get grants summing to at most it and ranked by priority. -- Audio reserves its configured rate and does not follow a smaller grant until - [#2848](/quest/m2/2848-follow-the-bandwidth-grant-in-moq-audio-instead-of.md); - that is the allocator's documented advisory contract and holds for one - capture stage exactly as for two, so it is not a reason to keep the refusal. - -Branch from dev. - -## Closes - -- [#2815](https://github.com/moq-dev/moq/issues/2815) - close this issue when the quest finishes - -## Related - -- [#2848](/quest/m2/2848-follow-the-bandwidth-grant-in-moq-audio-instead-of.md) - audio following its grant -- [#2859](/quest/m1/2859-passthrough-imports-reserve-no-bandwidth-so-a-co-resident.md) - passthrough imports joining the same allocator diff --git a/quest/m1/2859-passthrough-imports-reserve-no-bandwidth-so-a-co-resident.md b/quest/m1/2859-passthrough-imports-reserve-no-bandwidth-so-a-co-resident.md index e464d04de28..109bca3ccb6 100644 --- a/quest/m1/2859-passthrough-imports-reserve-no-bandwidth-so-a-co-resident.md +++ b/quest/m1/2859-passthrough-imports-reserve-no-bandwidth-so-a-co-resident.md @@ -98,6 +98,5 @@ Branch from dev. ## Related -- [#2815](/quest/m1/2815-lift-adaptive-stage-refusal.md) - two capture stages sharing one allocator - [#2709](/quest/m1/2709-per-broadcast-bandwidth-estimates-and-reservation.md) - the same allocator mirrored in js/net - [Ladder](/quest/m2/ladder/README.md) - a transcode ladder dividing the same estimate diff --git a/quest/m1/README.md b/quest/m1/README.md index 58a77faff03..838eff6596c 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -35,7 +35,6 @@ quest here and merged main into dev. - [#2709](/quest/m1/2709-per-broadcast-bandwidth-estimates-and-reservation.md) - js/net mirrors the send-side bandwidth allocator so each publisher encodes against its own share - [Binding rate control](/quest/m1/binding-rate-control.md) - the bindings mirror the allocator and reservation, so a non-Rust publisher follows its bandwidth share - [#2859](/quest/m1/2859-passthrough-imports-reserve-no-bandwidth-so-a-co-resident.md) - passthrough imports claim their peak-hold catalog bitrate on the allocator so a co-resident encoder targets what is left -- [#2815](/quest/m1/2815-lift-adaptive-stage-refusal.md) - moq-cli accepts several adaptive import stages on one connection now that the allocator divides the estimate - [HLS 404](/quest/m1/hls-cache-miss-codes.md) - a relay miss and a disconnected publisher answer 404 over moq-lite; IETF upstreams stay 500 - [HLS sibling restart](/quest/m1/hls-sibling-epoch-identity.md) - a replaced sibling publisher restarts its rendition instead of serving stale rows - [A/V clock](/quest/m1/plan-av-clock.md) - the audio playhead drives Sync.reference while audio plays, through per-track sync handles diff --git a/quest/m2/2848-follow-the-bandwidth-grant-in-moq-audio-instead-of.md b/quest/m2/2848-follow-the-bandwidth-grant-in-moq-audio-instead-of.md index 3c99a50b12a..8f31065fc6d 100644 --- a/quest/m2/2848-follow-the-bandwidth-grant-in-moq-audio-instead-of.md +++ b/quest/m2/2848-follow-the-bandwidth-grant-in-moq-audio-instead-of.md @@ -76,7 +76,6 @@ the dev merge. ## Related -- [#2815](/quest/m1/2815-lift-adaptive-stage-refusal.md) - two capture stages sharing one allocator - [#2859](/quest/m1/2859-passthrough-imports-reserve-no-bandwidth-so-a-co-resident.md) - reserve-only usage for passthrough tracks - [Binding rate control](/quest/m1/binding-rate-control.md) - the bindings consume the same `moq_mux::rate::Control` - [#2709](/quest/m1/2709-per-broadcast-bandwidth-estimates-and-reservation.md) - the JS twin diff --git a/rs/moq-cli/src/args.rs b/rs/moq-cli/src/args.rs index d6e5993dab6..ab5f97351cf 100644 --- a/rs/moq-cli/src/args.rs +++ b/rs/moq-cli/src/args.rs @@ -259,28 +259,6 @@ impl Invocation { ); } - // Rate control assumes it owns the uplink: the encoder targets a fraction of the - // connection's estimate, leaving room for its own audio and transport overhead but - // not for a second publisher. Anything else importing over the same connection - // spends what that encoder already claimed, so refuse rather than congest the link - // the estimate exists to protect. Exports only receive, so they don't count, and - // only an outbound client has an estimate at all. - let imports = self - .stages - .iter() - .filter(|stage| matches!(stage, Command::Import(_))) - .count(); - let adaptive = self - .stages - .iter() - .any(|stage| matches!(stage, Command::Import(import) if import.source.uses_bandwidth())); - anyhow::ensure!( - self.moq.client.url.is_none() || !adaptive || imports == 1, - "a stage that encodes to fit the connection's bandwidth estimate assumes it's the only \ - publisher on that connection, but this runs {imports} import stages; run them as separate \ - processes, or publish over --listen, which has no estimate" - ); - Ok(()) } } @@ -682,18 +660,6 @@ impl ImportSource { _ => return None, }) } - /// Whether this source encodes to fit the connection's bandwidth estimate. - /// - /// Rate control is per-encoder while the estimate is per-connection, so each such - /// source assumes it's the only one on the uplink. Only the video encoder reads - /// the estimate, so an audio-only capture doesn't count. - pub fn uses_bandwidth(&self) -> bool { - match self { - #[cfg(feature = "capture")] - Self::Capture(capture) => !capture.no_video, - _ => false, - } - } } // ------------------------------------------------------------------ export @@ -1141,8 +1107,7 @@ mod tests { assert_eq!(err.kind(), ParseErrorKind::UnknownArgument); } - /// Stages that never read the estimate can share a connection freely, so the guard - /// must not reject them. + /// Passthrough imports share a connection; they never read the estimate. #[test] fn imports_without_rate_control_can_share_a_connection() { let cli = Invocation::try_parse_from([ @@ -1168,78 +1133,24 @@ mod tests { assert!(cli.validate().is_ok()); } - /// An encoder that follows the estimate targets most of it, so a second publisher - /// on the same connection spends what it already claimed. Exports only receive, and - /// a `--listen` publisher has no estimate to oversubscribe. + /// Two encoding stages share the connection's allocator, so they may run + /// together rather than each targeting the whole estimate. #[cfg(feature = "capture")] #[test] - fn an_adaptive_capture_must_be_the_only_import() { - let client: &[&str] = &["--connect", "http://relay"]; - let server: &[&str] = &["--listen", "[::]:4443"]; - - let cases: [(&[&str], &[&str], bool); 3] = [ - // Two video captures follow the same estimate. - (client, &["import", "capture"], false), - // A fixed-rate import spends the same uplink from outside the budget. - (client, &["import", "rtmp", "--listen", "127.0.0.1:1935"], false), - // No outbound client, so there's no estimate to oversubscribe. - (server, &["import", "capture"], true), - ]; - - for (side, second, ok) in cases { - let argv = [&["moq"][..], side, &["import", "capture", "--"], second].concat(); - let cli = Invocation::try_parse_from(argv.clone()).unwrap(); - assert_eq!(cli.validate().is_ok(), ok, "{argv:?}"); - } - - // An audio-only capture never reads the estimate, so it may share the connection. + fn two_encoding_stages_may_share_a_connection() { let cli = Invocation::try_parse_from([ "moq", "--connect", "http://relay", "import", "capture", - "--no-video", "--", "import", - "rtmp", - "--listen", - "127.0.0.1:1935", - ]) - .unwrap(); - assert!(cli.validate().is_ok()); - - // Exports only receive, so they don't compete for the uplink. - let cli = Invocation::try_parse_from([ - "moq", - "--connect", - "http://relay", - "import", "capture", - "--", - "export", - "--broadcast", - "other.hang", - "fmp4", ]) .unwrap(); - assert!(cli.validate().is_ok()); - } - /// Only the video encoder reads the connection's bandwidth estimate, so an - /// audio-only capture doesn't compete for it and isn't counted against the - /// one-adaptive-stage limit. - #[cfg(feature = "capture")] - #[test] - fn audio_only_capture_is_not_bandwidth_adaptive() { - for (args, adaptive) in [(vec!["capture"], true), (vec!["capture", "--no-video"], false)] { - let argv = [vec!["moq", "--connect", "http://relay", "import"], args].concat(); - let cli = Invocation::try_parse_from(argv).unwrap(); - let Command::Import(import) = &cli.stages[0] else { - panic!("expected import") - }; - assert_eq!(import.source.uses_bandwidth(), adaptive); - } + assert!(cli.validate().is_ok()); } #[test]