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
7 changes: 5 additions & 2 deletions doc/bin/webrtc.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ the highest-bitrate enabled Opus rendition (then sample rate, then channels). It
follows the catalog: a peer whose rendition is disabled moves to the next best at
that rendition's first keyframe, a better one that re-enables wins the peer back,
and with none enabled the peer receives nothing until one is. `--cors-origin`
opens the endpoint to browsers on other origins, and `--udp-bind` plus
`--public-addr` pin one media port for firewalls. The listener is plain HTTP;
opens the endpoint to browsers on other origins. Every session shares one UDP
media port, `--udp-bind` (OS-picked by default), bound at startup so a taken port
fails before the listener reports ready. Behind NAT, `--public-addr` advertises
the public address as written, so `--public-addr 203.0.113.1:5000` reaches a port
the NAT forwards to `--udp-bind`; port 0 advertises the bound port. The listener is plain HTTP;
put a TLS-terminating proxy in front for WHIP clients that require HTTPS. A fresh WHEP peer joins at the current group, so it
starts at a keyframe without waiting for the next one. `DELETE` on the
resource URL tears a session down per the RFC. Each WHIP session publishes
Expand Down
1 change: 0 additions & 1 deletion quest/m2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ removal, a rename, or a wire, catalog, or format change that is free until
[device and cursor](/quest/m2/native-media-config.md),
[sink names](/quest/m2/audio-sink-names.md),
[moq-vaapi's exports](/quest/m2/vaapi-exports.md),
[the WebRTC bind](/quest/m2/webrtc-bind.md),
[the WHEP pull's announcement](/quest/m2/whep-pull-announce.md), and
[upstream str0m](https://github.com/moq-dev/moq/pull/8963), which reverses the
2026-10-30 vendoring.
Expand Down
79 changes: 0 additions & 79 deletions quest/m2/webrtc-bind.md

This file was deleted.

19 changes: 11 additions & 8 deletions quest/m3/one-port/rtc-feed.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ read loop: moq-webrtc's `ice::Socket`'s `udp: Arc<UdpSocket>` becomes
implements it, so the bound case behaves as today), and a fed mux routes
datagrams from the demux hook instead of reading a bound socket. Adapt the
sketch above to that: `advertised` is `ice_candidates`, and `recv` feeds
the mux's existing router. Address-family mapping follows the real socket,
the mux's existing router; the `Socket` enum is replaced by a second
constructor (below). Address-family mapping follows the real socket,
not the advertisement: a dual-stack socket bound to `[::]` may advertise a
public IPv4 address, so the `Transmit` impl owns the IPv4-mapped conversion
moq-webrtc's ICE module applies today. Received and pinned addresses use the same
Expand All @@ -78,13 +79,15 @@ returns a guard that releases the pin on drop. So the fed `Socket` takes a
selected pair, dropped when its session ends or ICE moves. A feed's `recv`
returns `None` once the listener is gone.

Things to watch: the server config is `Clone` today and a receiver is not, so
the fed socket may belong in the server's constructor rather than the
config. Since 2026-11-16 (maintainer, /quest-plan of the pre-cut audit)
[the bind at startup](/quest/m2/webrtc-bind.md) settles this before the cut:
the server becomes `Server::bind(config)`, and that PR picks where the
socket lives and writes it here, so the feed is an addition, not a break. The fed mux has nothing to bind lazily, and a dropped feed should
fail the server loudly rather than idle.
Settled 2026-11-16 by the bind at startup: the socket is the constructor's,
not the config's. `Server::bind(addr, config).await` binds its own socket, and
`server::Config` holds only `ice_candidates` and stays `Clone`; there is no
`Socket` enum. The feed adds a second constructor, such as
`Server::feed(webrtc, config)`, taking the `WebRtc` handle by value, so it is
an addition, not a break. Its `ice_candidates` are the shared address to
advertise, sent as given (port 0 takes the socket's port). The fed mux has
nothing to bind, and a dropped feed should fail the server loudly rather than
idle.

Noted 2026-10-31 from [moq-dev/moq#7095](https://github.com/moq-dev/moq/pull/7095):
its demux `Datagram` carries no ECN marks or kernel receive timestamp. If
Expand Down
12 changes: 12 additions & 0 deletions rs/moq-cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1814,6 +1814,18 @@ mod tests {
}
}

/// The WebRTC media socket flags configure the listener, so a dialer refuses them.
#[test]
fn webrtc_media_flags_need_the_listener() {
for flag in [["--udp-bind", "[::]:5000"], ["--public-addr", "203.0.113.1:5000"]] {
let listen = [&["webrtc", "--listen", "127.0.0.1:8443"][..], &flag].concat();
export(&listen).unwrap().validate().unwrap();
let connect = [&["webrtc", "--connect", "http://remote/whip"][..], &flag].concat();
let err = export(&connect).err().expect("a dialer took a listener flag");
assert!(err.to_string().contains("--listen"), "{flag:?}: {err}");
}
}

/// `--report` and `--echo-path` go where the CLI builds the one catalog they add a section to.
#[test]
fn catalog_sections_need_a_catalog_the_cli_builds() {
Expand Down
17 changes: 10 additions & 7 deletions rs/moq-cli/src/webrtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ pub struct Args {
#[usage(name = "webrtc-listen", long = "listen", value_name = "ADDR", group = "webrtc-mode")]
pub listen: Option<SocketAddr>,

/// Shared UDP socket for ICE/media (one port for all sessions).
/// Shared UDP socket for ICE/media (one port for all sessions), bound at startup.
#[usage(long, requires = "--listen", default = "[::]:0")]
pub udp_bind: SocketAddr,

/// Public UDP address(es) advertised as ICE host candidates (repeatable).
/// Public UDP address(es) advertised as ICE host candidates, as given (repeatable).
/// Port 0 advertises the `--udp-bind` port.
#[usage(long, requires = "--listen")]
pub public_addr: Vec<SocketAddr>,

Expand All @@ -57,7 +58,7 @@ pub struct Listen {
/// WHIP server: accept incoming WebRTC publishes into the Origin as `target.name` (import).
pub async fn listen_import(target: ImportTarget, listen: Listen) -> anyhow::Result<()> {
let publisher = scope_producer(&target.origin, &target.name)?;
let server = moq_webrtc::Server::new(server_config(&listen));
let server = bind(&listen).await?;
serve(server.publish_router(publisher, target.ingest), "WHIP", listen).await
}

Expand All @@ -69,7 +70,7 @@ pub async fn listen_export(origin: moq_net::origin::Consumer, name: String, list
let subscriber = origin
.scope("", &scope)
.with_context(|| format!("failed to scope origin to broadcast `{name}`"))?;
let server = moq_webrtc::Server::new(server_config(&listen));
let server = bind(&listen).await?;
serve(server.subscribe_router(subscriber), "WHEP", listen).await
}

Expand Down Expand Up @@ -127,11 +128,13 @@ pub async fn connect_export(origin: moq_net::origin::Consumer, url: Url, name: S
Ok(())
}

fn server_config(listen: &Listen) -> moq_webrtc::server::Config {
/// Bind the shared media socket, so a bad `--udp-bind` fails startup.
async fn bind(listen: &Listen) -> anyhow::Result<moq_webrtc::Server> {
let mut config = moq_webrtc::server::Config::default();
config.socket = moq_webrtc::server::Socket::Bind(listen.udp_bind);
config.ice_candidates.clone_from(&listen.public_addr);
config
moq_webrtc::Server::bind(listen.udp_bind, config)
.await
.with_context(|| format!("failed to bind --udp-bind {}", listen.udp_bind))
}

async fn serve(router: axum::Router, role: &str, listen: Listen) -> anyhow::Result<()> {
Expand Down
19 changes: 6 additions & 13 deletions rs/moq-webrtc/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,22 @@
mod whep;
mod whip;

use std::net::SocketAddr;

use url::Url;

/// Configuration shared by both `client publish` and `client pull`.
///
/// No options yet; it is where a later one, such as a dial policy, goes without
/// changing [`Client::new`].
#[derive(Clone, Debug, Default)]
#[non_exhaustive]
pub struct Config {
/// Public UDP socket addresses to advertise as ICE host candidates in
/// our outbound offer. Same semantics as [`crate::server::Config::ice_candidates`].
pub ice_candidates: Vec<SocketAddr>,
}
pub struct Config {}

/// Outbound WHIP/WHEP dialer.
///
/// Owns a [`reqwest::Client`] reused across calls so connection pooling and
/// rustls config survive between resources.
#[derive(Clone)]
pub struct Client {
config: Config,
http: reqwest::Client,
}

Expand All @@ -40,19 +36,16 @@ impl Client {
/// Fails with [`Error::UnsupportedCpu`](crate::Error::UnsupportedCpu) on a CPU
/// rind can't run on.
pub fn new(config: Config) -> crate::Result<Self> {
// Destructured so a new option cannot compile without being used.
let Config {} = config;
// reqwest reads rustls's process default and panics without one, so install rind's
// unless the host already chose a provider.
moq_crypto::provider::install_default()?;
Ok(Self {
config,
http: reqwest::Client::builder().build()?,
})
}

pub(crate) fn config(&self) -> &Config {
&self.config
}

pub(crate) fn http(&self) -> &reqwest::Client {
&self.http
}
Expand Down
2 changes: 1 addition & 1 deletion rs/moq-webrtc/src/client/whep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub(crate) async fn dial(
) -> Result<()> {
let sink = Box::new(IngestSink::new(broadcast, catalog)?);

let socket = session::bind_udp(&client.config().ice_candidates).await?;
let socket = session::bind_udp().await?;
let mut rtc = session::rtc_config()?.build(kio::clock::now().into_std());
for addr in socket.locals() {
let cand = Candidate::host(*addr, "udp").map_err(Error::rtc)?;
Expand Down
2 changes: 1 addition & 1 deletion rs/moq-webrtc/src/client/whip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub(crate) async fn dial(client: &Client, url: Url, source: moq_mux::Source) ->
return Err(Error::NoRenditions);
}

let socket = session::bind_udp(&client.config().ice_candidates).await?;
let socket = session::bind_udp().await?;
// Restrict to codecs the catalog can actually source so the remote
// answer doesn't pick a codec we have no rendition for.
let mut rtc = session::rtc_with_codecs(&codecs)?;
Expand Down
16 changes: 12 additions & 4 deletions rs/moq-webrtc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ mod tests {
let (old_route, mut old, old_catalog) = publish_opus(&origin, moq_net::Instance::random());
push(&mut *old, 20_000, OPUS_PACKET);

let server = Server::new(server::Config::default());
let server = Server::bind("127.0.0.1:0".parse().unwrap(), server::Config::default())
.await
.unwrap();
let whep_origin = origin.consume();
let (sessions_tx, mut sessions) = tokio::sync::mpsc::channel(1);
let app = Router::new().route(
Expand Down Expand Up @@ -258,7 +260,9 @@ mod tests {
let (old_route, mut old, old_catalog) = publish_opus(&origin, moq_net::Instance::random());
push(&mut *old, 20_000, OPUS_PACKET);

let server = Server::new(server::Config::default());
let server = Server::bind("127.0.0.1:0".parse().unwrap(), server::Config::default())
.await
.unwrap();
let ingest_origin = moq_tokio::origin::spawn();
let whip_origin = ingest_origin.clone();
let app = Router::new().route(
Expand Down Expand Up @@ -323,7 +327,9 @@ mod tests {
tokio::task::JoinHandle<()>,
tokio::sync::mpsc::Receiver<tokio::task::JoinHandle<crate::Result<()>>>,
) {
let server = Server::new(server::Config::default());
let server = Server::bind("127.0.0.1:0".parse().unwrap(), server::Config::default())
.await
.unwrap();
let origin = moq_tokio::origin::spawn();
let (sessions_tx, sessions) = tokio::sync::mpsc::channel(1);
let app = Router::new().route(
Expand Down Expand Up @@ -466,7 +472,9 @@ mod tests {
drop(announcements);

let server_origin = moq_tokio::origin::spawn();
let server = Server::new(server::Config::default());
let server = Server::bind("127.0.0.1:0".parse().unwrap(), server::Config::default())
.await
.unwrap();
let (sources_tx, mut sources_rx) = tokio::sync::mpsc::channel(2);
let whip_server = server.clone();
let whip_origin = server_origin.clone();
Expand Down
Loading