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
1 change: 0 additions & 1 deletion demo/carla/bridge/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions doc/lib/rs/moq-mux.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ identity changes, such as an SPS with a new profile or level or an audio header
with a new sample rate, continues under a new track name
(`<name>/<n>` for the codec importers) while the old track ends; everything else,
such as the coded size, updates the rendition in place. A
timeline that rewinds ends the import. The MPEG-TS import ends at a clock step
onto another timeline with `ts::Restart`, which carries the input from the step
for the caller to publish as a new broadcast. fMP4 export fixes its track
timeline that rewinds ends the import. The MPEG-TS import ends with an error at
a clock step onto another timeline, or a PAT naming another program;
`ts::Republish` carries on past it, publishing what follows as a new instance of
the broadcast. fMP4 export fixes its track
set at the init segment, so a new rendition or a changed configuration ends the
export. The [MPEG-TS guide](/bin/ts) covers the MPEG-TS specifics: one program
per broadcast, private PES, passthrough, acquisition, and loss.
Expand Down
8 changes: 4 additions & 4 deletions nix/Cargo.nix

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions quest/m2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ removal, a rename, or a wire, catalog, or format change that is free until
`mpegts`, one strict rule);
[the archive as version 2](/quest/m2/archive-v2.md);
[declared ends](/quest/m2/time-addressing/consumers.md), back from m3;
[finish](/quest/m2/finish-sweep.md), [TS outcomes](/quest/m2/ts-typed-outcomes.md),
and [moq-json writes](/quest/m2/json-write-at.md).
[finish](/quest/m2/finish-sweep.md), and
[moq-json writes](/quest/m2/json-write-at.md).
- **Native media and gateways.** [The video producer](/quest/m2/video-producer.md),
[the hole wait](/quest/m2/delay-hole-wait.md),
[device and cursor](/quest/m2/native-media-config.md),
Expand Down
1 change: 0 additions & 1 deletion quest/m2/finish-sweep.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,3 @@ importers, `moq_mux::import::{Track, TrackStream}`, and
## Related

- [The frame-taking video producer](/quest/m2/video-producer.md) - renames the video type this changes
- [TS import reports typed outcomes](/quest/m2/ts-typed-outcomes.md) - changes the TS importers' `finish` error type
78 changes: 0 additions & 78 deletions quest/m2/ts-typed-outcomes.md

This file was deleted.

27 changes: 27 additions & 0 deletions quest/m3/rtsp-final-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# [S] An RTSP failure says whether redialing can fix it

## Goal

`moq import rtsp` stops redialing a camera that refused access or offers
nothing publishable, without matching `moq_rtsp::Error` variants. moq-rtsp
reports whether a failure is final, and the CLI's redial loop
(`rs/moq-cli/src/rtsp.rs`) asks it rather than listing variants itself, per
AGENTS.md's "never match on errors". Which failures redial stays as today.

## Plan

Decided 2026-11-16 (maintainer, on
[moq-dev/moq#8939](https://github.com/moq-dev/moq/pull/8939)): the CLI's
`retries` helper, which matches `Unauthorized` and `NoSupportedStream`, goes.

- Add `moq_rtsp::Error::is_final`, shaped like `moq_auth::Error::is_final_grant`
(from [moq-dev/moq#8933](https://github.com/moq-dev/moq/pull/8933)): the one
list of failures that asking again cannot fix, kept next to the variants so
a new one is classified where it is added. It lists `Unauthorized`,
`NoSupportedStream` and `InvalidUrl`: no redial fixes a URL, though
`Client::new` already refuses one before the loop, so the loop's behavior
does not change.
- The CLI redials on `!err.is_final()`, and its `session_failures_retry` test
moves to moq-rtsp as a test of `is_final`.

Public API: additive on moq-rtsp (`Error::is_final`). Wire: none.
15 changes: 10 additions & 5 deletions quest/m5/ts-multi-program-restart.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ import.
rules for PAT changes that aren't a source switch (a moved PMT PID, a
program added or removed) as they are.

[Typed TS outcomes](/quest/m2/ts-typed-outcomes.md) makes `Import`'s restart
a returned value; give `Programs` the same shape, not a second one.

Public API: possibly additive on `Programs` (a restart result like
`Import`'s). Wire: none.
The restart stays out of the public API (maintainer, 2026-11-16, on
[moq-dev/moq#8939](https://github.com/moq-dev/moq/pull/8939)): the public
`ts::Import::decode` fails at a step with `ts::Error::Restarted`, and only
`ts::Republish` sees the restart as a value, through the `pub(super)`
`Import::decode_or_restart`. Give `Programs` the same shape, not a second one:
it reads the restart through a private method and follows it itself, never by
matching the error.

Public API: possibly additive on `Programs` (a report of each program it
republished, like `ts::Republished`). Wire: none.
11 changes: 6 additions & 5 deletions rs/moq-cli/src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,12 @@ impl FinishedDecoder {
}

/// Point a multi-program refusal at the flag that resolves it.
fn suggest_program(err: anyhow::Error) -> anyhow::Error {
if err.is::<ts::MultipleProgramsError>() {
err.context("choose one with `--program <n>`, or publish each with `--program all`")
} else {
err
fn suggest_program(err: ts::Error) -> anyhow::Error {
let multiplex = matches!(err, ts::Error::MultiplePrograms { .. });
let err = anyhow::Error::from(err);
match multiplex {
true => err.context("choose one with `--program <n>`, or publish each with `--program all`"),
false => err,
}
}

Expand Down
61 changes: 39 additions & 22 deletions rs/moq-cli/src/rtsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ pub async fn connect_import(target: ImportTarget, url: Url) -> anyhow::Result<()
Ok(moq_rtsp::End::Jumped) if published => continue,
Ok(moq_rtsp::End::Jumped) => tracing::warn!(%url, "RTSP timeline jumped before publishing"),
Ok(_) => tracing::info!(%url, "RTSP session ended"),
Err(err) if is_fatal(&err) => return Err(err),
Err(err) => tracing::warn!(%url, "RTSP session failed: {err:#}"),
Err(Failure::Session(err)) if retries(&err) => tracing::warn!(%url, "RTSP session failed: {err}"),
Err(Failure::Session(err)) => return Err(err.into()),
Err(Failure::Local(err)) => return Err(err),
}

tracing::info!(%url, ?backoff, "RTSP reconnecting");
Expand All @@ -56,24 +57,41 @@ pub async fn connect_import(target: ImportTarget, url: Url) -> anyhow::Result<()
}
}

/// Retrying cannot fix these: refused access, nothing publishable, or a local failure (such as
/// an invalid broadcast name) rather than one from the RTSP session.
fn is_fatal(err: &anyhow::Error) -> bool {
/// Why a run failed: its RTSP session, or something local such as an invalid broadcast name, which
/// a redial cannot fix.
enum Failure {
Session(moq_rtsp::Error),
Local(anyhow::Error),
}

impl std::fmt::Display for Failure {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Session(err) => write!(f, "{err}"),
Self::Local(err) => write!(f, "{err:#}"),
}
}
}

/// Whether redialing can fix a session failure: anything but refused access or nothing publishable.
fn retries(err: &moq_rtsp::Error) -> bool {
!matches!(
err.downcast_ref::<moq_rtsp::Error>(),
Some(err) if !matches!(err, moq_rtsp::Error::Unauthorized(_) | moq_rtsp::Error::NoSupportedStream(_))
err,
moq_rtsp::Error::Unauthorized(_) | moq_rtsp::Error::NoSupportedStream(_)
)
}

/// Publish one session as one broadcast, announced once its catalog names a track, setting
/// `published` then.
async fn run(target: &ImportTarget, client: &moq_rtsp::Client, published: &mut bool) -> anyhow::Result<moq_rtsp::End> {
async fn run(target: &ImportTarget, client: &moq_rtsp::Client, published: &mut bool) -> Result<moq_rtsp::End, Failure> {
// Each run is a new route under a fresh instance, so a redial replaces the last run.
let route = target
.origin
.route(&target.name, moq_net::origin::RouteOptions::hidden())
.context("failed to create broadcast")?;
let mut catalog = moq_mux::catalog::Producer::new(&mut route.broadcast().clone(), target.ingest.catalog())?;
.context("failed to create broadcast")
.map_err(Failure::Local)?;
let mut catalog = moq_mux::catalog::Producer::new(&mut route.broadcast().clone(), target.ingest.catalog())
.map_err(|err| Failure::Local(err.into()))?;

// A relay asks for a broadcast's tracks the moment it is announced, so wait for the
// first keyframe to put them in the catalog.
Expand All @@ -90,36 +108,35 @@ async fn run(target: &ImportTarget, client: &moq_rtsp::Client, published: &mut b
};

let end = tokio::select! {
end = client.pull(route.broadcast(), &catalog) => end.map_err(anyhow::Error::from),
err = announce => err,
end = client.pull(route.broadcast(), &catalog) => end.map_err(Failure::Session),
err = announce => err.map_err(Failure::Local),
};
// Closed at once even after a clean end: the pull redials and publishes the next run under a
// new instance, so a run's end is not the content's, and a retained run's finished catalog
// would tell readers to stop if the next run dropped.
let finished = match &end {
Ok(_) => catalog.finish(),
Err(err) => {
catalog.abort(moq_net::Error::Transport(format!("{err:#}")));
catalog.abort(moq_net::Error::Transport(err.to_string()));
Ok(())
}
};
route.broadcast().close();
finished?;
finished.map_err(|err| Failure::Local(err.into()))?;
end
}

#[cfg(test)]
mod tests {
use super::*;

/// Only a failure of the RTSP session itself is worth redialing.
/// A session failure is worth redialing unless the server refused access or offers nothing
/// publishable.
#[test]
fn only_session_failures_retry() {
let retry = |err: anyhow::Error| !is_fatal(&err);
assert!(retry(moq_rtsp::Error::Rtsp("connection reset".into()).into()));
assert!(retry(moq_rtsp::Error::Stalled(Duration::from_secs(10)).into()));
assert!(!retry(moq_rtsp::Error::Unauthorized("401".into()).into()));
assert!(!retry(moq_rtsp::Error::NoSupportedStream("audio/pcmu".into()).into()));
assert!(!retry(anyhow::anyhow!("failed to create broadcast")));
fn session_failures_retry() {
assert!(retries(&moq_rtsp::Error::Rtsp("connection reset".into())));
assert!(retries(&moq_rtsp::Error::Stalled(Duration::from_secs(10))));
assert!(!retries(&moq_rtsp::Error::Unauthorized("401".into())));
assert!(!retries(&moq_rtsp::Error::NoSupportedStream("audio/pcmu".into())));
}
}
8 changes: 6 additions & 2 deletions rs/moq-cli/src/srt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ impl ImportArgs {

/// Point a multi-program refusal at the flag that resolves it.
fn suggest_program(err: moq_srt::Error) -> anyhow::Error {
let multiplex = matches!(&err, moq_srt::Error::Mux(moq_mux::Error::Other(inner))
if inner.is::<moq_mux::container::ts::MultipleProgramsError>());
let multiplex = matches!(
err,
moq_srt::Error::Mux(moq_mux::Error::Ts(
moq_mux::container::ts::Error::MultiplePrograms { .. }
))
);
let err = anyhow::Error::from(err);
if multiplex {
err.context("choose one with `--program <n>`, or publish each with `--program all`")
Expand Down
2 changes: 1 addition & 1 deletion rs/moq-mux/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ async = ["kio/async", "moq-net/async"]
fuzz = []

[dependencies]
anyhow = { workspace = true }
base64 = { workspace = true }
bitstream-io = { workspace = true }
bytes = { workspace = true }
Expand Down Expand Up @@ -55,6 +54,7 @@ url = { workspace = true }
webm-iterable = "0.7"

[dev-dependencies]
anyhow = { workspace = true }
criterion = { package = "bench-harness", path = "../bench-harness" }
futures = { workspace = true }
# The tests await hang's catalog subscription.
Expand Down
Loading