Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions doc/bin/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +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 # 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 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` captures and
encodes each source only while its track has a subscriber, and leaves nothing
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.
Expand Down
1 change: 0 additions & 1 deletion quest/m1/eager-encode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 0 additions & 22 deletions quest/m1/eager-encode/cli.md

This file was deleted.

59 changes: 43 additions & 16 deletions rs/moq-cli/src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ pub struct CaptureArgs {
/// Capture video only (no microphone).
#[usage(long, conflicts("--microphone", "--system-audio"))]
pub no_audio: bool,

/// 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,
}

enum PublishDecoder {
Expand Down Expand Up @@ -295,7 +302,7 @@ enum Source {
broadcast: moq_net::broadcast::Producer,
catalog: moq_mux::catalog::Producer,
video: Option<moq_video::encode::Capture>,
audio: Option<(moq_audio::capture::Config, moq_audio::encode::Options)>,
audio: Option<moq_audio::encode::Capture>,
},
}

Expand Down Expand Up @@ -488,7 +495,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 {
Expand Down Expand Up @@ -589,9 +596,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();
Expand All @@ -606,14 +614,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(()),
}
};
Expand Down Expand Up @@ -824,6 +827,7 @@ impl CaptureArgs {
moq_video::encode::Kind::Auto
};
options.bandwidth = bandwidth;
options.on_demand = self.on_demand;
Ok(options)
}

Expand All @@ -845,9 +849,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
Expand All @@ -856,6 +860,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)]
Expand Down Expand Up @@ -899,6 +912,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() {
Expand Down
Loading