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
8 changes: 5 additions & 3 deletions js/e2ee/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ video.finish();
video.close();
```

A subscriber resolves `credential.path(semantic)`, takes the epoch from the announced
route (or from the application's channel on a wire without route epochs), binds it with
`credential.consume(epoch)`, and wraps the broadcast in a `Broadcast.Consumer`. Its
A subscriber follows `credential.path(semantic)` with `origin.follow(path)`. It takes each
instance's epoch from the broadcast it resolved, `broadcast.epoch` (or from the application's
channel on a wire without route epochs), so the key always matches the instance it reads. It
binds the epoch with `credential.consume(epoch)` and wraps the broadcast in a
`Broadcast.Consumer`. Its
`subscribe(semantic)` opens the track a decrypted catalog names, and `close()` releases the
wrapped broadcast. A consuming generation
cannot produce. Nothing survives a publisher instance: a restart mints a new epoch.
Expand Down
6 changes: 3 additions & 3 deletions js/e2ee/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*
* A {@link Credential} is what the application distributes out of band. Each publisher instance
* calls {@link Credential.produce} to mint a {@link Generation.Producer} and wraps its `@moq/net`
* broadcast in a {@link Broadcast.Producer}. Subscribers discover the epoch from the broadcast
* route, bind a {@link Generation.Consumer} with {@link Credential.consume}, and wrap the broadcast
* in a {@link Broadcast.Consumer}. Both sides name tracks by their semantic names; only the
* broadcast in a {@link Broadcast.Producer}. Subscribers follow the path, take each instance's
* epoch from the broadcast it resolved, bind a {@link Generation.Consumer} with
* {@link Credential.consume}, and wrap the broadcast in a {@link Broadcast.Consumer}. Both sides name tracks by their semantic names; only the
* derived physical names reach `@moq/net`.
*
* ```ts
Expand Down
4 changes: 2 additions & 2 deletions js/wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Moq.setup(); // install panic/tracing hooks for readable errors

const session = await Moq.Session.connect("https://relay.example.com/anon");
const broadcast = await session.consume("room/alice");
const track = await broadcast?.subscribe("video");
for (let group = await track?.recvGroup(); group; group = await track?.recvGroup()) {
const track = await broadcast.subscribe("video");
for (let group = await track.recvGroup(); group; group = await track.recvGroup()) {
for (let frame = await group.readFrame(); frame; frame = await group.readFrame()) {
// frame: Uint8Array
}
Expand Down
2 changes: 1 addition & 1 deletion quest/m1/api-audit/resolve/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Wire: none.
## Required

- [Bindings request and follow](/quest/m1/api-audit/resolve/bindings.md) - moq-ffi, the C ABI, and every wrapper mirror `request` and `follow` with an optional epoch
- [Callers resolve once](/quest/m1/api-audit/resolve/callers.md) - no caller hand-rolls synced resolution or decides table absence by wall clock
- [The carla demo pins its driver epoch](/quest/m1/api-audit/resolve/callers.md) - the demo's driver watcher requests each run pinned to its announced epoch

## Related

Expand Down
40 changes: 20 additions & 20 deletions quest/m1/api-audit/resolve/callers.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# [M] Callers resolve once
# [XS] The carla demo pins its driver epoch

## Goal

No caller hand-rolls synced resolution or relies on a wall clock to decide a
broadcast is absent. Each first-party caller resolves with `request` or
`follow`.
The carla demo's driver watcher resolves each driver run pinned to the epoch it
was announced under, so a lease never reads a newer run's commands.

## Plan

Split from [Two broadcast resolutions](/quest/m1/api-audit/resolve/README.md)
on 2026-10-28 (maintainer).

- Remove the hidden error in moq-wasm's resolve, which follows the path but
still discards why it failed.
- Replace moq-cli's resolve-and-drop waits before its stdout, RTMP, and WHIP
exports, which follow the path only to wait for its announcement and then
resolve it again.
- Review SRT, transcode, the benchmark connections, relay HTTP fetch
deadlines, the moq-hls server's `RESOLVE_TIMEOUT` handler-stall bound, the
e2ee epoch advice, and the demo's announce-derived epoch pin; fix each that
hand-rolls resolution or decides absence by time.

List every caller in the PR with what it now uses. Run the affected packages'
tests and `just test interop --all`.

Public API: none beyond the callers' own surfaces. Wire: none.
on 2026-10-28 (maintainer). Every other first-party caller now resolves once
with `request` or `follow`; see
[moq-dev/moq#7192](https://github.com/moq-dev/moq/pull/7192).

`watch_drivers` in `demo/carla/sim/moq_carla_sim/publish.py` takes each
driver's epoch from its announcement, then `_pump_driver` requests the path
unpinned. A newer run that took over in between is read under the old run's
lease until its own announcement cancels the task. Pass the announced epoch
to the Python wrapper's `request(path, epoch)` once the bindings expose it.

Run the demo's sim tests (`demo/carla/sim`).

Public API: none. Wire: none.

## Required

- [Bindings request and follow](/quest/m1/api-audit/resolve/bindings.md) - the Python wrapper's `request` takes an epoch
9 changes: 4 additions & 5 deletions rs/moq-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -920,16 +920,15 @@ async fn run_stdout(
) -> anyhow::Result<()> {
let catalog = args.catalog_format(&name);

// Confirm the broadcast is reachable and wait for it to be announced; `Subscribe` then
// resolves it, and any sibling broadcast a rendition's `broadcast` field references
// (e.g. "./source") through the same origin.
consumer
// Wait for the broadcast to be announced; the export resolves any sibling broadcast a
// rendition's `broadcast` field references (e.g. "./source") through the same origin.
let broadcast = consumer
.follow(name.as_str(), None)?
.available()
.await
.with_context(|| format!("failed to resolve broadcast `{name}`"))?;

let subscribe = Subscribe::new(consumer, &name, catalog, args).await?;
let subscribe = Subscribe::new(moq_mux::Source::new(consumer, broadcast), catalog, args);
let Some(echo) = echo else {
return subscribe.run().await;
};
Expand Down
13 changes: 3 additions & 10 deletions rs/moq-cli/src/report/echo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,8 @@ async fn export_echo_reports_where_the_import_solicits() {
let mut import = ts::Import::new(broadcast, catalog.reserve());
import.decode(&CLIP[..HALF]).unwrap();
publication.announce(Default::default()).unwrap();
origin
.consume()
.follow("demo", None)
.unwrap()
.available()
.await
.unwrap();
let consumer = origin.consume();
let resolved = consumer.follow("demo", None).unwrap().available().await.unwrap();

let args = SubscribeArgs {
format: SubscribeFormat::Ts,
Expand All @@ -48,9 +43,7 @@ async fn export_echo_reports_where_the_import_solicits() {
catalog: None,
select: SelectArgs::default(),
};
let subscribe = Subscribe::new(origin.consume(), "demo", CatalogFormat::Hang, args)
.await
.unwrap();
let subscribe = Subscribe::new(moq_mux::Source::new(consumer, resolved), CatalogFormat::Hang, args);
let target = EchoTarget {
origin: origin.clone(),
name: "alice".parse().unwrap(),
Expand Down
9 changes: 5 additions & 4 deletions rs/moq-cli/src/rtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,20 @@ pub async fn connect_import(target: ImportTarget, url: Url, epoch: moq_net::Epoc

/// WHIP client: push a broadcast from the Origin to a remote (export).
pub async fn connect_export(origin: moq_net::origin::Consumer, url: Url, name: String) -> anyhow::Result<()> {
// Confirm the broadcast is reachable (and wait for it to be announced) before dialing;
// the egress re-resolves it (and any referenced sibling broadcast) through the origin.
origin
// Wait for the broadcast to be announced before dialing; the egress resolves any
// referenced sibling broadcast through the same origin.
let broadcast = origin
.follow(name.as_str(), None)?
.available()
.await
.with_context(|| format!("failed to resolve broadcast `{name}`"))?;
let source = moq_mux::Source::new(origin, broadcast);

tracing::info!(url = %RedactedUrl::new(&url), %name, "WHIP client pushing");
notify_ready();

let client = moq_rtc::Client::new(moq_rtc::client::Config::default());
client.publish(url, origin, &name).await?;
client.publish(url, source).await?;
Ok(())
}

Expand Down
9 changes: 5 additions & 4 deletions rs/moq-cli/src/rtmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,21 @@ pub async fn connect_export(
) -> anyhow::Result<()> {
let name = moq_net::Path::new(&name)?;
let (addr, app, key) = parse_url(&url).await?;
// Confirm the broadcast is reachable (and wait for it to be announced) before dialing;
// the FLV export re-resolves it (and any referenced sibling broadcast) through the origin.
origin
// Wait for the broadcast to be announced before dialing; the FLV export resolves any
// referenced sibling broadcast through the same origin.
let broadcast = origin
.follow(&name, None)?
.available()
.await
.with_context(|| format!("failed to resolve broadcast `{name}`"))?;
let source = moq_mux::Source::new(origin, broadcast);

// The stream key is the ingest credential, so log the dial target and app instead.
tracing::info!(%addr, %app, %name, "RTMP client pushing");
notify_ready();

let client = Client::connect(addr, &app).await?.with_max_delay(max_delay);
Ok(client.publish(&key, origin, &name).await?)
Ok(client.publish(&key, source).await?)
}

/// Parse `rtmp://host[:1935]/<app>/<key>` into a resolved address, app, and stream key.
Expand Down
23 changes: 5 additions & 18 deletions rs/moq-cli/src/subscribe.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::time::Duration;

use anyhow::Context;
use hang::catalog::{AudioCodecKind, VideoCodecKind};
use hang::moq_net;
use moq_mux::catalog::{self, CatalogFormat, Stream};
use moq_mux::select;
use tokio::io::AsyncWriteExt;
Expand Down Expand Up @@ -268,26 +266,15 @@ fn log_release(release: &moq_mux::container::ts::stats::Release, message: &'stat
}

impl Subscribe {
/// Resolve the broadcast at `path` on `origin` to export it with the resolved settings;
/// [`run`](Self::run) drives it.
pub async fn new(
origin: moq_net::origin::Consumer,
path: &str,
catalog: CatalogFormat,
args: SubscribeArgs,
) -> anyhow::Result<Self> {
let path = moq_net::Path::new(path)?;
let broadcast = origin
.request(&path, None)
.await
.with_context(|| format!("failed to resolve broadcast `{path}`"))?;
let source = moq_mux::Source::new(origin, broadcast);
Ok(Self {
/// Export the resolved broadcast `source` with the resolved settings; [`run`](Self::run)
/// drives it.
pub fn new(source: moq_mux::Source, catalog: CatalogFormat, args: SubscribeArgs) -> Self {
Self {
source,
catalog,
args,
sections: None,
})
}
}

/// The resolved broadcast, whose [`stats`](moq_mux::Source::stats) count what the export reads.
Expand Down
7 changes: 4 additions & 3 deletions rs/moq-e2ee/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ let video = protected.create_track("video", None)?;
broadcast.announce(Route::default().with_epoch(generation.epoch().clone()))?;
```

A subscriber discovers the broadcast at `credential.path(semantic)`, takes the epoch from the
announced `Route::epoch` (or from the application's channel on a wire older than lite-07),
binds it with `credential.consume(epoch)`, and wraps the broadcast in a
A subscriber follows `credential.path(semantic)` with `origin.follow(path, None)`. It takes
each instance's epoch from the broadcast it resolved, `broadcast.info().epoch` (or from the
application's channel on a wire older than lite-07), so the key always matches the instance
it reads. It binds the epoch with `credential.consume(epoch)` and wraps the broadcast in a
`broadcast::Consumer`. Its `subscribe(semantic, subscription)` opens the track a decrypted
catalog names. A consuming generation cannot produce. Nothing survives a publisher instance: a restart mints a new epoch.

Expand Down
6 changes: 3 additions & 3 deletions rs/moq-e2ee/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
//!
//! A [`Credential`] is what the application distributes out of band. Each publisher
//! instance calls [`Credential::produce`] to mint a [`generation::Producer`] and wraps its
//! `moq-net` broadcast in a [`broadcast::Producer`]. Subscribers discover the epoch from the
//! broadcast route, bind a [`generation::Consumer`] with [`Credential::consume`], and wrap the
//! broadcast in a [`broadcast::Consumer`]. Both sides name tracks by their semantic names; only
//! `moq-net` broadcast in a [`broadcast::Producer`]. Subscribers follow the path, take each
//! instance's epoch from the broadcast it resolved, bind a [`generation::Consumer`] with
//! [`Credential::consume`], and wrap the broadcast in a [`broadcast::Consumer`]. Both sides name tracks by their semantic names; only
//! the derived physical names reach `moq-net`.
//!
//! A caller cannot reopen an explicit epoch for production:
Expand Down
2 changes: 1 addition & 1 deletion rs/moq-rtc/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ How to update your code for each breaking change, newest first.

### `moq_net::Path` has no lifetime

`Client::publish` and `client::whip::dial` take `impl TryInto<moq_net::Path, Error: Into<moq_net::Error>>`, so `&str`, `String`, and `&Path` still work. `server::{whip, whep}::accept` take `impl Into<moq_net::Path>`: pass a `Path`, from `moq_net::Path::new(s)?` or `moq_net::Path::from_static`. See moq-net's migration for the rest.
`server::{whip, whep}::accept` take `impl Into<moq_net::Path>`: pass a `Path`, from `moq_net::Path::new(s)?` or `moq_net::Path::from_static`. See moq-net's migration for the rest.

### Client calls run the session

Expand Down
22 changes: 7 additions & 15 deletions rs/moq-rtc/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,14 @@ impl Client {
whep::dial(self, url, broadcast).await
}

/// `client publish`: pull the broadcast at `path` from `origin` and push it to a
/// remote WHIP endpoint, until the session ends.
/// `client publish`: push the broadcast `source` resolved to a remote WHIP endpoint,
/// until the session ends.
///
/// It stays on the publisher instance it resolved, and fails once that instance's
/// route dies.
///
/// Taking the origin plus path (rather than a resolved [`moq_net::broadcast::Consumer`])
/// lets the egress resolve a rendition whose catalog `broadcast` field references a
/// sibling broadcast, against the same origin.
pub async fn publish(
&self,
url: Url,
origin: moq_net::origin::Consumer,
path: impl TryInto<moq_net::Path, Error: Into<moq_net::Error>>,
) -> crate::Result<()> {
whip::dial(self, url, origin, path).await
/// It stays on that publisher instance, and fails once the instance's route dies.
/// The source's origin resolves a rendition whose catalog `broadcast` field references
/// a sibling broadcast.
pub async fn publish(&self, url: Url, source: moq_mux::Source) -> crate::Result<()> {
whip::dial(self, url, source).await
}
}

Expand Down
10 changes: 2 additions & 8 deletions rs/moq-rtc/src/client/whip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@ use url::Url;

use crate::{Error, Result, client::Client, egress::EgressSource, session};

pub(crate) async fn dial(
client: &Client,
url: Url,
origin: moq_net::origin::Consumer,
path: impl TryInto<moq_net::Path, Error: Into<moq_net::Error>>,
) -> Result<()> {
let broadcast = origin.request(path, None).await?;
let source = EgressSource::new(moq_mux::Source::new(origin, broadcast)).await?;
pub(crate) async fn dial(client: &Client, url: Url, source: moq_mux::Source) -> Result<()> {
let source = EgressSource::new(source).await?;
let codecs = source.catalog_codecs();
if codecs.is_empty() {
return Err(Error::NoRenditions);
Expand Down
11 changes: 9 additions & 2 deletions rs/moq-rtc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ mod tests {
let client = Client::new(client::Config::default());
let url = format!("http://{address}/whip/ingested").parse().expect("WHIP URL");
let source = origin.consume();
let pushed = tokio::spawn(async move { client.publish(url, source, "source").await });
let broadcast = source.request("source", None).await.unwrap();
let source = moq_mux::Source::new(source, broadcast);
let pushed = tokio::spawn(async move { client.publish(url, source).await });
let ingested = ingest_origin.consume();
let ingested = ingested.follow("ingested", None).unwrap().available().await.unwrap();
let mut played = opus_output(&ingested).await;
Expand Down Expand Up @@ -395,7 +397,12 @@ mod tests {
// Each client call resolves once its session ends, so the test drives them aside.
let whip_client = tokio::spawn({
let client = client.clone();
async move { client.publish(whip, source_consumer, "source").await }
async move {
let broadcast = source_consumer.request("source", None).await?;
client
.publish(whip, moq_mux::Source::new(source_consumer, broadcast))
.await
}
});
let (whip_id, whip_task) = tokio::time::timeout(TIMEOUT, sources_rx.recv())
.await
Expand Down
Loading
Loading