diff --git a/doc/bin/gstreamer.md b/doc/bin/gstreamer.md index c6f3812ec53..fb079c9b183 100644 --- a/doc/bin/gstreamer.md +++ b/doc/bin/gstreamer.md @@ -168,10 +168,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 1b1baba4c58..83a8810e5b4 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -168,7 +168,6 @@ removed). - [HLS and DASH segment conformance](/quest/m1/hls-conformance.md) - nightly ffprobe checks that advertised timing, sync flags, and bytes match the media served - [Unbounded groups](/quest/m1/unbounded-groups/README.md) - groups and frames lose their size caps; a group keeps a 32 MB tail, and readers behind it replay through paced flights or refresh - [Legacy lite close drain](/quest/m1/lite-legacy-close-drain.md) - a lite-01..06 graceful close never cuts a final group the subscriber has not read -- [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 join tests cover draft 20](/quest/m1/join-tests-draft20.md) - join.test.ts runs on every supported draft, not just 18 and 22 - [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 - [Audit retention defaults](/quest/m1/max-age-defaults.md) - every max-age default listed, with a proposed finite default for the maintainer 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 d700fe4db13..51023cf9340 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,14 @@ 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)) + // A SUBSCRIBE carries it as a QUIC varint, which can't hold 2^62 or more. + .maximum((1 << 62) - 1) + .mutable_ready() + .build(), ] .into_iter() .chain(crate::connection::properties()) @@ -288,6 +321,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 +331,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), } } @@ -744,6 +779,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<()> { @@ -760,15 +796,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, @@ -815,6 +852,7 @@ async fn follow_path( latest = Some(play( &mut runs, moq_mux::Source::new(origin.clone(), broadcast), + max_delay, &pads, &element, &shutdown, @@ -836,6 +874,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, @@ -844,7 +883,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(), ); @@ -884,6 +923,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, @@ -914,6 +954,7 @@ async fn follow_catalog( let playback = Playback { element, broadcast: broadcast.clone(), + max_delay, pads: pads.clone(), timeline: Arc::default(), shutdown: shutdown.clone(), @@ -1177,6 +1218,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, @@ -1590,6 +1633,7 @@ impl Reader { } = self; let Playback { element, + max_delay, pads, shutdown, .. @@ -1611,7 +1655,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, @@ -2245,7 +2289,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), @@ -2282,7 +2329,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 }) } @@ -2317,6 +2372,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(), @@ -2484,8 +2540,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| { @@ -2580,8 +2637,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()), @@ -2694,6 +2760,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. @@ -3189,7 +3279,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"); @@ -3290,6 +3382,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(), } @@ -3348,7 +3441,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) } @@ -3545,6 +3648,7 @@ mod session_tests { playback: super::Playback { element: element.downgrade(), broadcast: instance.clone(), + max_delay: DEFAULT_MAX_DELAY, pads, timeline: Arc::default(), shutdown, @@ -3726,8 +3830,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) } @@ -4027,8 +4140,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 7b8f91949ba..f113695ef0f 100755 --- a/test/interop/interop.sh +++ b/test/interop/interop.sh @@ -1188,7 +1188,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 @@ -1207,7 +1208,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