From 667918f0d01ca5d16354af4f9de1d332d4d16f47 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 28 Oct 2026 20:49:53 -0700 Subject: [PATCH 1/3] chore(quest): claim quest/m1/eager-encode/cli.md Quest-Claim: 4497eb8e0d5518b3 From 9462f8970c7c8325970c56e253923a5f82470ae1 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 28 Oct 2026 20:53:06 -0700 Subject: [PATCH 2/3] feat(moq-cli)!: capture encodes while publishing, --on-demand as an opt-in `import capture` follows the moq-video and moq-audio defaults, keeping the camera and microphone open and encoding for the whole publish so a late subscriber can fetch the recent past. `--on-demand` selects both libraries' `Capture::on_demand`, opening each source only while its track has a subscriber. Co-Authored-By: Claude Opus 5.5 --- doc/bin/cli.md | 8 +++-- quest/m1/eager-encode/README.md | 1 - quest/m1/eager-encode/cli.md | 22 ------------- rs/moq-cli/src/publish.rs | 58 ++++++++++++++++++++++++--------- 4 files changed, 48 insertions(+), 41 deletions(-) delete mode 100644 quest/m1/eager-encode/cli.md diff --git a/doc/bin/cli.md b/doc/bin/cli.md index 3e227ba50b5..38e4a4ac038 100644 --- a/doc/bin/cli.md +++ b/doc/bin/cli.md @@ -246,12 +246,16 @@ moq ... import capture --display --system-audio # share a screen with i moq ... import capture --window 39193 --no-audio # one window (macOS, Windows, X11) moq ... import capture --window --no-audio # system window picker (Linux Portal) moq ... import capture --camera 0 --width 1280 --height 720 --fps 30 --bitrate 3000000 --codec h265 +moq ... import capture --on-demand # open devices only while someone watches ``` Video goes through the platform hardware encoder, with an H.264 software fallback when built with `openh264`, and audio is Opus; [moq-video](/lib/rs/moq-video) lists the -backends. The camera stays open while publishing, and `--bitrate` is a -ceiling that backends with live bitrate control lower to fit the connection. +backends. The camera and microphone stay open and encode while publishing, +so a late subscriber can fetch the recent past. `--on-demand` opens and +encodes each source only while its track has a subscriber, and leaves nothing +to fetch from before the first viewer. `--bitrate` is a ceiling that backends +with live bitrate control lower to fit the connection. `moq devices` prints every source id. On Windows, `display:N` is an enumeration index rather than a stable monitor id, so re-run `moq devices` if a saved selector picks the wrong screen. diff --git a/quest/m1/eager-encode/README.md b/quest/m1/eager-encode/README.md index 07f3f1ececf..64a29d37dd8 100644 --- a/quest/m1/eager-encode/README.md +++ b/quest/m1/eager-encode/README.md @@ -50,7 +50,6 @@ The epic's own work, once the children land: ## Required - [@moq/publish encodes while enabled](/quest/m1/eager-encode/js.md) - audio and video encoders drop the demand gate, with an on-demand opt-in -- [moq-cli on-demand flag](/quest/m1/eager-encode/cli.md) - `moq publish` capture encodes always, unless `--on-demand` - [Raw audio on demand](/quest/m1/eager-encode/raw-audio.md) - audio encodes on demand again, from raw frames kept up to `maxAge` ## Related diff --git a/quest/m1/eager-encode/cli.md b/quest/m1/eager-encode/cli.md deleted file mode 100644 index e096761024d..00000000000 --- a/quest/m1/eager-encode/cli.md +++ /dev/null @@ -1,22 +0,0 @@ -# [S] moq-cli capture encodes always unless --on-demand - -## Goal - -`moq publish` capture of a camera, display or microphone encodes from start -to finish by default. `--on-demand` opens and encodes only while subscribed, -as today. - -## Plan - -Decided 2026-10-28 (maintainer); see the [epic](/quest/m1/eager-encode/README.md). -`rs/moq-cli/src/publish.rs:592` calls both `publish_capture`s, so the default -follows the libraries. The flag selects their on-demand option -(`moq_video::encode::Capture::on_demand` and -`moq_audio::encode::Capture::on_demand`). The comment there and -`doc/bin/cli.md:250` describe the always-on camera; add the flag and the -microphone. Name the flag under the repository's CLI rule. - -Tests: the CLI's capture args parse `--on-demand`, and the default publishes -without a subscriber. - -Public API: CLI default change, plus a new flag. Wire: none. diff --git a/rs/moq-cli/src/publish.rs b/rs/moq-cli/src/publish.rs index 7f9915fc947..c7471767fed 100644 --- a/rs/moq-cli/src/publish.rs +++ b/rs/moq-cli/src/publish.rs @@ -134,6 +134,12 @@ pub struct CaptureArgs { /// Capture video only (no microphone). #[usage(long, conflicts("--microphone", "--system-audio"))] pub no_audio: bool, + + /// Open and encode each source only while its track has a subscriber, + /// releasing it when the last one leaves. By default capture runs for the + /// whole publish, so a late subscriber can fetch the recent past. + #[usage(long)] + pub on_demand: bool, } enum PublishDecoder { @@ -295,7 +301,7 @@ enum Source { broadcast: moq_net::broadcast::Producer, catalog: moq_mux::catalog::Producer, video: Option, - audio: Option<(moq_audio::capture::Config, moq_audio::encode::Options)>, + audio: Option, }, } @@ -488,7 +494,7 @@ impl Publish { } else { Some(args.video_capture(bandwidth.clone())?) }; - let audio = (!args.no_audio).then(|| (args.audio_config(), args.audio_encode(bandwidth))); + let audio = (!args.no_audio).then(|| args.audio_capture(bandwidth)); anyhow::ensure!(video.is_some() || audio.is_some(), "nothing to capture"); Ok(Self { @@ -589,9 +595,10 @@ impl Publish { // Each enabled medium publishes its own track onto the shared // broadcast + catalog. Both stamp frames on the catalog's // advertised clock, so HLS/DASH wall times match the mapping on - // the wire. Video captures for the whole run. Both run on this - // task rather than a spawn: on macOS the audio future holds ObjC - // handles across an await, so it is `!Send`. + // the wire. Both capture for the whole run, or only while + // subscribed with `--on-demand`. Both run on this task rather + // than a spawn: on macOS the audio future holds ObjC handles + // across an await, so it is `!Send`. let video_fut = { let broadcast = broadcast.clone(); let catalog = catalog.clone(); @@ -606,14 +613,9 @@ impl Publish { }; let audio_fut = async move { match audio { - Some((config, encode)) => { - let mut options = moq_audio::encode::Capture::default(); - options.capture = config; - options.encode = encode; - moq_audio::encode::publish_capture(broadcast, catalog, options) - .await - .map_err(anyhow::Error::from) - } + Some(options) => moq_audio::encode::publish_capture(broadcast, catalog, options) + .await + .map_err(anyhow::Error::from), None => Ok(()), } }; @@ -824,6 +826,7 @@ impl CaptureArgs { moq_video::encode::Kind::Auto }; options.bandwidth = bandwidth; + options.on_demand = self.on_demand; Ok(options) } @@ -845,9 +848,9 @@ impl CaptureArgs { config } - /// The audio counterpart to [`video_encode`](Self::video_encode). `track` is - /// left unset so the name derives from the codec, the way the video side - /// names its track; consumers find it through the catalog either way. + /// The audio encode settings. `track` is left unset so the name derives + /// from the codec, the way the video side names its track; consumers find + /// it through the catalog either way. fn audio_encode(&self, bandwidth: moq_net::bandwidth::Allocator) -> moq_audio::encode::Options { let mut options = moq_audio::encode::Options::default(); options.config.bitrate = self @@ -856,6 +859,15 @@ impl CaptureArgs { options.bandwidth = bandwidth; options } + + /// The audio counterpart to [`video_capture`](Self::video_capture). + fn audio_capture(&self, bandwidth: moq_net::bandwidth::Allocator) -> moq_audio::encode::Capture { + let mut options = moq_audio::encode::Capture::default(); + options.capture = self.audio_config(); + options.encode = self.audio_encode(bandwidth); + options.on_demand = self.on_demand; + options + } } #[cfg(test)] @@ -899,6 +911,20 @@ pub(crate) mod tests { assert_eq!(capture_args(&["--window"]).window, Some(None)); } + #[cfg(feature = "capture")] + #[test] + fn capture_runs_always_unless_on_demand() { + use moq_net::bandwidth::Allocator; + + let args = capture_args(&[]); + assert!(!args.video_capture(Allocator::unlimited()).unwrap().on_demand); + assert!(!args.audio_capture(Allocator::unlimited()).on_demand); + + let args = capture_args(&["--on-demand"]); + assert!(args.video_capture(Allocator::unlimited()).unwrap().on_demand); + assert!(args.audio_capture(Allocator::unlimited()).on_demand); + } + #[cfg(feature = "capture")] #[test] fn capture_window_id_preserves_native_selection() { From e0c6ba1aa3c8b15d8e9d572c6f62a05b3d927e45 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 28 Oct 2026 20:59:10 -0700 Subject: [PATCH 3/3] docs(moq-cli): --on-demand still probes the video source at startup Co-Authored-By: Claude Opus 5.5 --- doc/bin/cli.md | 9 +++++---- rs/moq-cli/src/publish.rs | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/doc/bin/cli.md b/doc/bin/cli.md index 38e4a4ac038..af7a2515717 100644 --- a/doc/bin/cli.md +++ b/doc/bin/cli.md @@ -246,16 +246,17 @@ moq ... import capture --display --system-audio # share a screen with i moq ... import capture --window 39193 --no-audio # one window (macOS, Windows, X11) moq ... import capture --window --no-audio # system window picker (Linux Portal) moq ... import capture --camera 0 --width 1280 --height 720 --fps 30 --bitrate 3000000 --codec h265 -moq ... import capture --on-demand # open devices only while someone watches +moq ... import capture --on-demand # capture only while someone watches ``` Video goes through the platform hardware encoder, with an H.264 software fallback when built with `openh264`, and audio is Opus; [moq-video](/lib/rs/moq-video) lists the backends. The camera and microphone stay open and encode while publishing, -so a late subscriber can fetch the recent past. `--on-demand` opens and +so a late subscriber can fetch the recent past. `--on-demand` captures and encodes each source only while its track has a subscriber, and leaves nothing -to fetch from before the first viewer. `--bitrate` is a ceiling that backends -with live bitrate control lower to fit the connection. +to fetch from before the first viewer; video still opens its source once at +startup to probe the mode it negotiates. `--bitrate` is a ceiling that +backends with live bitrate control lower to fit the connection. `moq devices` prints every source id. On Windows, `display:N` is an enumeration index rather than a stable monitor id, so re-run `moq devices` if a saved selector picks the wrong screen. diff --git a/rs/moq-cli/src/publish.rs b/rs/moq-cli/src/publish.rs index c7471767fed..a66ce30f1ee 100644 --- a/rs/moq-cli/src/publish.rs +++ b/rs/moq-cli/src/publish.rs @@ -135,9 +135,10 @@ pub struct CaptureArgs { #[usage(long, conflicts("--microphone", "--system-audio"))] pub no_audio: bool, - /// Open and encode each source only while its track has a subscriber, - /// releasing it when the last one leaves. By default capture runs for the - /// whole publish, so a late subscriber can fetch the recent past. + /// Capture and encode each source only while its track has a subscriber, + /// releasing it when the last one leaves. Video still opens its source once + /// at startup to probe the mode. By default capture runs for the whole + /// publish, so a late subscriber can fetch the recent past. #[usage(long)] pub on_demand: bool, }