From 20a703c2359824e2551000c5b1b0eb74266625a2 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 28 Oct 2026 03:41:58 -0700 Subject: [PATCH 1/4] chore(quest): claim quest/m1/gst-max-delay.md Quest-Claim: 9fe2856872b98832 From 17ec61987e5c8ed71194ee138318c25ea7479b34 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 28 Oct 2026 03:54:47 -0700 Subject: [PATCH 2/4] feat(gst): moqsrc takes a max-delay moqsrc subscribed every rendition with a hard-coded 1 s max delay, so a starved pipeline skipped a group with no way to widen the budget. A new max-delay element property (milliseconds, default 1000) sets it, and the gap-checked interop audio cell asks for 5 s like the other readers. Co-Authored-By: Claude Opus 5.5 --- doc/bin/gstreamer.md | 7 +- quest/m1/README.md | 1 - quest/m1/gst-max-delay.md | 18 ---- rs/moq-gst/src/source/imp.rs | 155 +++++++++++++++++++++++++++++++---- test/interop/interop.sh | 5 +- 5 files changed, 146 insertions(+), 40 deletions(-) delete mode 100644 quest/m1/gst-max-delay.md diff --git a/doc/bin/gstreamer.md b/doc/bin/gstreamer.md index 475a64c1892..7c9a92988f8 100644 --- a/doc/bin/gstreamer.md +++ b/doc/bin/gstreamer.md @@ -150,10 +150,15 @@ on its own. Losing the relay connection also holds the pads: `moqsrc` redials without a retry deadline and resumes when the broadcast returns. A refused connection, refused path or catalog, or malformed protocol input or catalog posts an error. Properties: `url`, -`broadcast`, `connect-version` (comma-separated protocol versions to offer, most +`broadcast`, `max-delay`, `connect-version` (comma-separated protocol versions to offer, most preferred first; every stable version by default), `tls-disable-verify`, `quic-idle-timeout`, `quic-keep-alive`, and `quic-keylog`. +`max-delay` is how many milliseconds (default 1000) a group may trail the live +edge before every pad skips it. Raise it to ride out a stalled pipeline or a +congested link without gaps, at the cost of falling further behind live first. The +publisher's max-age caps it. + Debug with `GST_DEBUG=*:4` for GStreamer and `RUST_LOG=debug` for the plugin. To decrypt a capture, set `quic-keylog=true` on either element along with `SSLKEYLOGFILE`; the variable alone writes nothing, and the flag without it fails diff --git a/quest/m1/README.md b/quest/m1/README.md index 3f93058e5c5..44c147d9d4e 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -179,7 +179,6 @@ removed). - [Settled copies versus whole groups](/quest/m1/settled-copies.md) - every model check of whether a group is done means either a settled copy or the whole group, as it needs - [An HLS viewer starts capture](/quest/m1/hls-record-demand.md) - a record-track subscriber counts as demand for its rendition's media - [One moq-ffi build definition](/quest/m1/ffi-build-flags.md) - every binding takes moq-ffi's default features from one place -- [moqsrc max-delay](/quest/m1/gst-max-delay.md) - GStreamer's `moqsrc` takes a `max-delay` property instead of a hard-coded 1 s budget - [JS SETUP rejection ownership](/quest/m1/js-setup-rejection.md) - reproduce an unhandled version-refusal rejection without weakening the refusal - [moq-clock moves into kio::clock](/quest/m1/kio-clock.md) - moq-clock and its test macro become `kio::clock` and `#[kio::test]` before the cut publishes them - [Poll-first async](/quest/m1/poll-first/README.md) - library crates compile no coroutines by default: async wrappers are generated from `poll_*` and gated behind an `async` feature diff --git a/quest/m1/gst-max-delay.md b/quest/m1/gst-max-delay.md deleted file mode 100644 index c283c24cd71..00000000000 --- a/quest/m1/gst-max-delay.md +++ /dev/null @@ -1,18 +0,0 @@ -# [S] moqsrc takes a max-delay - -## Goal - -GStreamer's `moqsrc` has a `max-delay` element property (default 1 s, today's -hard-coded value) that sets every track's delay budget, and `interop.sh` -sets it to 5 s as the other interop readers allow. - -## Plan - -Decided 2026-10-27 (maintainer): a property, not a budget derived from the -track's max-age, since the budget is a latency tradeoff the viewer chooses -and publishers keep 30 s of max-age. Found by -[moq-dev/moq#6990](https://github.com/moq-dev/moq/pull/6990): a starved -GStreamer subscriber fails the gap check with no way to widen it -(`rs/moq-gst/src/source/imp.rs`). Update `doc/bin/gstreamer.md`. - -Public API: a new `moqsrc` property. Wire: none. diff --git a/rs/moq-gst/src/source/imp.rs b/rs/moq-gst/src/source/imp.rs index 075ff496262..8ffc6d844e2 100644 --- a/rs/moq-gst/src/source/imp.rs +++ b/rs/moq-gst/src/source/imp.rs @@ -36,17 +36,33 @@ static RUNTIME: LazyLock = LazyLock::new(|| { static NEXT_VIDEO_PAD_ID: AtomicU64 = AtomicU64::new(0); static NEXT_AUDIO_PAD_ID: AtomicU64 = AtomicU64::new(0); -#[derive(Debug, Clone, Default)] +/// How far a group may trail the live edge before a reader skips it, unless `max-delay` is set. +const DEFAULT_MAX_DELAY: Duration = Duration::from_secs(1); + +#[derive(Debug, Clone)] struct Settings { url: Option, broadcast: Option, + max_delay: Duration, connection: crate::connection::Settings, } +impl Default for Settings { + fn default() -> Self { + Self { + url: None, + broadcast: None, + max_delay: DEFAULT_MAX_DELAY, + connection: Default::default(), + } + } +} + #[derive(Debug, Clone)] struct ResolvedSettings { url: url::Url, broadcast: String, + max_delay: Duration, connect: moq_tokio::connect::Config, quic: moq_tokio::quic::Config, } @@ -63,6 +79,7 @@ impl TryFrom for ResolvedSettings { .as_ref() .context("broadcast property is required")? .clone(), + max_delay: value.max_delay, connect, quic, }) @@ -119,7 +136,15 @@ impl SessionController { let task_connection = connection.clone(); let task_element = element.clone(); Ok(Self::spawn(client, connection, element, move |shutdown| async move { - run_session(&task_connection, origin, settings.broadcast, task_element, shutdown).await + run_session( + &task_connection, + origin, + settings.broadcast, + settings.max_delay, + task_element, + shutdown, + ) + .await })) } @@ -257,6 +282,12 @@ impl ObjectImpl for MoqSrc { .blurb("The broadcast name to subscribe to") .mutable_ready() .build(), + glib::ParamSpecUInt64::builder("max-delay") + .nick("Max delay") + .blurb("How many milliseconds a group may trail the live edge before it is skipped") + .default_value(crate::connection::duration_millis(DEFAULT_MAX_DELAY)) + .mutable_ready() + .build(), ] .into_iter() .chain(crate::connection::properties()) @@ -288,6 +319,7 @@ impl ObjectImpl for MoqSrc { match pspec.name() { "url" => settings.url = value.get().unwrap(), "broadcast" => settings.broadcast = value.get().unwrap(), + "max-delay" => settings.max_delay = Duration::from_millis(value.get().unwrap()), name => settings.connection.set(name, value), } } @@ -297,6 +329,7 @@ impl ObjectImpl for MoqSrc { match pspec.name() { "url" => settings.url.to_value(), "broadcast" => settings.broadcast.to_value(), + "max-delay" => crate::connection::duration_millis(settings.max_delay).to_value(), name => settings.connection.get(name), } } @@ -554,6 +587,7 @@ async fn run_session( connection: &moq_tokio::Connection, origin: moq_net::origin::Consumer, broadcast: String, + max_delay: Duration, element: glib::WeakRef, mut shutdown: watch::Receiver, ) -> Result<()> { @@ -570,15 +604,16 @@ async fn run_session( Err(err) => anyhow::Error::from(err).context("connection closed"), } }; - follow_path(&origin, &broadcast, element, shutdown, lost).await + follow_path(&origin, &broadcast, max_delay, element, shutdown, lost).await } /// Follow the path's announcements for the whole session: play on a start, switch to the new /// broadcast on a restart, and hold the pads from an end until the next start. Returns once -/// `shutdown` fires, `lost` resolves, or the origin closes. +/// `shutdown` fires, `lost` resolves, or the origin closes. Every track is read with `max_delay`. async fn follow_path( origin: &moq_net::origin::Consumer, path: &str, + max_delay: Duration, element: glib::WeakRef, mut shutdown: watch::Receiver, lost: impl Future, @@ -625,6 +660,7 @@ async fn follow_path( latest = Some(play( &mut runs, moq_mux::Source::new(origin.clone(), broadcast), + max_delay, &pads, &element, &shutdown, @@ -645,6 +681,7 @@ async fn follow_path( fn play( runs: &mut tokio::task::JoinSet>, source: moq_mux::Source, + max_delay: Duration, pads: &Pads, element: &glib::WeakRef, shutdown: &watch::Receiver, @@ -653,7 +690,7 @@ fn play( let (pads, task_element, shutdown) = (pads.clone(), element.clone(), shutdown.clone()); runs.spawn_on( STREAMING.scope(element.clone(), async move { - follow_catalog(source, &pads, task_element, &shutdown, &mut cancelled).await + follow_catalog(source, max_delay, &pads, task_element, &shutdown, &mut cancelled).await }), RUNTIME.handle(), ); @@ -693,6 +730,7 @@ fn catalog_lost(err: &moq_mux::Error) -> bool { /// with the session, except those of renditions the catalog retired. async fn follow_catalog( source: moq_mux::Source, + max_delay: Duration, pads: &Pads, element: glib::WeakRef, shutdown: &watch::Receiver, @@ -723,6 +761,7 @@ async fn follow_catalog( let playback = Playback { element, broadcast: broadcast.clone(), + max_delay, pads: pads.clone(), timeline: Arc::default(), shutdown: shutdown.clone(), @@ -970,6 +1009,8 @@ struct Playback { element: glib::WeakRef, /// The catalog's broadcast. A sibling outlives its closed catalog until it ends. broadcast: moq_net::broadcast::Consumer, + /// How far a group may trail the live edge before a reader skips it. + max_delay: Duration, pads: Pads, /// Shared by the catalog's own renditions and the first instance of each sibling. timeline: Arc, @@ -1382,6 +1423,7 @@ impl Reader { } = self; let Playback { element, + max_delay, pads, shutdown, .. @@ -1403,7 +1445,7 @@ impl Reader { subscriber = async { instance .track(&shape.track)? - .subscribe(moq_net::track::Subscription::default().with_max_delay(Duration::from_secs(1))) + .subscribe(moq_net::track::Subscription::default().with_max_delay(max_delay)) .await } => match subscriber { Ok(subscriber) => subscriber, @@ -2021,7 +2063,10 @@ mod session_tests { use hang::catalog::{AudioCodec, AudioConfig, Container, H264, VideoCodec, VideoConfig}; use tokio::sync::watch; - use super::{NEXT_VIDEO_PAD_ID, Pads, ResolvedSettings, SessionController, TrackKind, follow_catalog, follow_path}; + use super::{ + DEFAULT_MAX_DELAY, NEXT_VIDEO_PAD_ID, Pads, ResolvedSettings, SessionController, TrackKind, follow_catalog, + follow_path, + }; /// The pad-id counters are process-global, so a test reading one has to be the only test /// allocating while it runs. `cargo test` shares a process across tests (nextest doesn't), @@ -2048,7 +2093,15 @@ mod session_tests { let stopping = shutdown.clone(); let (origin, _driver) = moq_net::origin::Producer::new(Default::default()); let source = moq_mux::Source::new(origin.consume(), broadcast); - follow_catalog(source, &Pads::default(), element, &stopping, &mut shutdown).await + follow_catalog( + source, + DEFAULT_MAX_DELAY, + &Pads::default(), + element, + &stopping, + &mut shutdown, + ) + .await }) } @@ -2177,8 +2230,9 @@ mod session_tests { let weak = element.downgrade(); let pads = pads.clone(); let source = moq_mux::Source::new(origin().consume(), broadcast.consume()); - let task = super::RUNTIME - .spawn(async move { follow_catalog(source, &pads, weak, &shutdown, &mut cancelled).await }); + let task = super::RUNTIME.spawn(async move { + follow_catalog(source, DEFAULT_MAX_DELAY, &pads, weak, &shutdown, &mut cancelled).await + }); let first = usize::from(audio_first); let other = 1 - first; let mut write = |index: usize, seconds: u64| { @@ -2273,8 +2327,17 @@ mod session_tests { let (stopping, shutdown) = watch::channel(false); let consumer = origin.consume(); let weak = element.downgrade(); - let following = super::RUNTIME - .spawn(async move { follow_path(&consumer, "room/catalog", weak, shutdown, std::future::pending()).await }); + let following = super::RUNTIME.spawn(async move { + follow_path( + &consumer, + "room/catalog", + DEFAULT_MAX_DELAY, + weak, + shutdown, + std::future::pending(), + ) + .await + }); let (path, request) = super::RUNTIME.block_on(async { tokio::select! { request = local.requested_track() => ("catalog", request.unwrap()), @@ -2387,6 +2450,30 @@ mod session_tests { super::RUNTIME.block_on(session).unwrap().unwrap(); } + #[test] + fn a_rendition_subscribes_with_the_session_max_delay() { + let element = element(); + let mut broadcast = moq_net::broadcast::Info::new().produce(); + let mut dynamic = broadcast.requests(); + let mut catalog = moq_mux::catalog::Producer::new(&mut broadcast, moq_mux::catalog::Config::default()).unwrap(); + catalog.modify().unwrap().video.renditions = BTreeMap::from([("video".to_string(), video_rendition())]); + + let max_delay = Duration::from_secs(5); + let (shutdown, mut cancelled) = watch::channel(false); + let weak = element.downgrade(); + let source = moq_mux::Source::new(origin().consume(), broadcast.consume()); + let session = super::RUNTIME.spawn(async move { + let stopping = cancelled.clone(); + follow_catalog(source, max_delay, &Pads::default(), weak, &stopping, &mut cancelled).await + }); + + let request = await_request(&mut dynamic); + assert_eq!(request.subscription().unwrap().max_delay, Some(max_delay)); + + let _ = shutdown.send(true); + super::RUNTIME.block_on(session).unwrap().unwrap(); + } + /// A rendition delisted while its reader is still subscribing ends that reader, and answering /// the subscription afterwards must not resurrect it into a pad. Listing it again starts it /// anew, since the reader that left is no longer the rendition's. @@ -2882,7 +2969,9 @@ mod session_tests { let pads = pads.clone(); let weak = element.downgrade(); let source = moq_mux::Source::new(origin().consume(), broadcast.consume()); - super::RUNTIME.spawn(async move { follow_catalog(source, &pads, weak, &shutdown, &mut cancelled).await }) + super::RUNTIME.spawn(async move { + follow_catalog(source, DEFAULT_MAX_DELAY, &pads, weak, &shutdown, &mut cancelled).await + }) }; let pad = super::RUNTIME.block_on(adds.recv()).unwrap(); assert!(pad.starts_with("video_"), "{pad} was added first"); @@ -2986,6 +3075,7 @@ mod session_tests { ResolvedSettings { url: "https://127.0.0.1:1".parse().unwrap(), broadcast: "test".into(), + max_delay: DEFAULT_MAX_DELAY, connect: crate::connection::Settings::default().resolve().unwrap().0, quic: Default::default(), } @@ -3044,7 +3134,17 @@ mod session_tests { client, connection.clone(), element.downgrade(), - move |shutdown| async move { follow_path(&origin, "room", weak, shutdown, std::future::pending()).await }, + move |shutdown| async move { + follow_path( + &origin, + "room", + DEFAULT_MAX_DELAY, + weak, + shutdown, + std::future::pending(), + ) + .await + }, ); (session, connection) } @@ -3241,6 +3341,7 @@ mod session_tests { playback: super::Playback { element: element.downgrade(), broadcast: instance.clone(), + max_delay: DEFAULT_MAX_DELAY, pads, timeline: Arc::default(), shutdown, @@ -3422,8 +3523,17 @@ mod session_tests { ) -> (watch::Sender, tokio::task::JoinHandle>) { let (shutdown, stopping) = watch::channel(false); let (origin, weak) = (origin.consume(), element.downgrade()); - let task = super::RUNTIME - .spawn(async move { follow_path(&origin, "room", weak, stopping, std::future::pending()).await }); + let task = super::RUNTIME.spawn(async move { + follow_path( + &origin, + "room", + DEFAULT_MAX_DELAY, + weak, + stopping, + std::future::pending(), + ) + .await + }); (shutdown, task) } @@ -3718,8 +3828,17 @@ mod session_tests { let run = { let weak = element.downgrade(); let source = moq_mux::Source::new(origin.consume(), room.broadcast.consume()); - super::RUNTIME - .spawn(async move { follow_catalog(source, &Pads::default(), weak, &shutdown, &mut cancelled).await }) + super::RUNTIME.spawn(async move { + follow_catalog( + source, + DEFAULT_MAX_DELAY, + &Pads::default(), + weak, + &shutdown, + &mut cancelled, + ) + .await + }) }; let mut cam = Publisher::sibling(&origin, Default::default()); diff --git a/test/interop/interop.sh b/test/interop/interop.sh index 7d0d8a41de2..a7c377da24a 100755 --- a/test/interop/interop.sh +++ b/test/interop/interop.sh @@ -1125,7 +1125,8 @@ observe_group() { # gst-launch stop the pipeline and close its session. Not with -e: moqsrc does not end its pads on # an EOS sent into the pipeline. Each pad's log, trimmed to the buffers its file holds, becomes # ..txt beside ..pcm, the layout tone.py reads, the codec named by the -# pad's caps. +# pad's caps. A 5 s max-delay, as the other gap-checked readers ask for, keeps a starved pipeline +# from skipping a group and failing the gap check. # shellcheck disable=SC2329 # reached from run_subscriber, which 'harness_spawn' invokes run_gst_audio() { local url="$1" broadcast="$2" out="$3" tone="$4" codecs="$5" tones renditions pid want deadline version i short @@ -1144,7 +1145,7 @@ run_gst_audio() { done GST_PLUGIN_PATH_1_0="$GST_PLUGIN_DIR" GST_REGISTRY_1_0="$HARNESS_RUN/gst-run-registry.bin" \ GST_TRACERS=log GST_DEBUG=GST_BUFFER:7,GST_EVENT:7 GST_DEBUG_NO_COLOR=1 GST_DEBUG_FILE="$out.trace" \ - gst-launch-1.0 moqsrc name=s url="$url" broadcast="$broadcast" ${version:+connect-version="$version"} \ + gst-launch-1.0 moqsrc name=s url="$url" broadcast="$broadcast" max-delay=5000 ${version:+connect-version="$version"} \ s.video_0 ! filesink location="$out.video" buffer-mode=2 "${pads[@]}" >"$out.gst" 2>&1 & pid=$! while :; do From 098cd30aa174c92256efaec156e201f2f990c520 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 28 Oct 2026 04:10:07 -0700 Subject: [PATCH 3/4] fix(gst): bound moqsrc max-delay to what a SUBSCRIBE can carry Co-Authored-By: Claude Opus 5.5 --- rs/moq-gst/src/source/imp.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rs/moq-gst/src/source/imp.rs b/rs/moq-gst/src/source/imp.rs index 8ffc6d844e2..3b2577c077e 100644 --- a/rs/moq-gst/src/source/imp.rs +++ b/rs/moq-gst/src/source/imp.rs @@ -286,6 +286,8 @@ impl ObjectImpl for MoqSrc { .nick("Max delay") .blurb("How many milliseconds a group may trail the live edge before it is skipped") .default_value(crate::connection::duration_millis(DEFAULT_MAX_DELAY)) + // A SUBSCRIBE carries it as a QUIC varint, which can't hold 2^62 or more. + .maximum((1 << 62) - 1) .mutable_ready() .build(), ] From e318d05ff576fcab607f725b55c296fdd8792d7d Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 29 Oct 2026 11:28:59 -0700 Subject: [PATCH 4/4] fix(gst): initialize max delay in merged selection test Co-Authored-By: GPT-6.1 Sol --- rs/moq-gst/src/source/imp.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rs/moq-gst/src/source/imp.rs b/rs/moq-gst/src/source/imp.rs index 31ce6b8c340..8b03e87cfc9 100644 --- a/rs/moq-gst/src/source/imp.rs +++ b/rs/moq-gst/src/source/imp.rs @@ -2157,6 +2157,7 @@ mod session_tests { let playback = super::Playback { element: element.downgrade(), broadcast: broadcast.consume(), + max_delay: DEFAULT_MAX_DELAY, pads: Pads::default(), timeline: Arc::default(), shutdown: stopped.clone(),