From 66dcfaa33efa48d8bae2a85b19501348bdc95599 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 28 Oct 2026 23:14:25 -0700 Subject: [PATCH 1/4] chore(quest): claim quest/m1/ts-reliability/step-back.md Quest-Claim: 3fb3ded36f489fdf From 222fa6d11581c952665cab003010c30a2c1c6221 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 1 Nov 2026 15:19:28 -0800 Subject: [PATCH 2/4] fix(mux): a TS export re-acquires on an unmarked step back A source whose timeline steps back by more than the export's delay, mid-group and with no marker, now restarts the track's decode clock and opens a new jitter generation, as a declared marker would. Before, the video decode clock clamped every DTS after the step onto the old timeline, so the video arrived late until it caught up, and audio with slack left decoded before what it had already sent, which failed the export on a missed decode deadline. Finishes quest/m1/ts-reliability/step-back.md. Co-Authored-By: Claude Opus 5.5 --- quest/m1/ts-reliability/README.md | 6 +-- quest/m1/ts-reliability/step-back.md | 34 ------------ rs/moq-mux/src/container/ts/export.rs | 52 +++++++++++++++++-- .../src/container/ts/export_timing_test.rs | 19 +++++-- 4 files changed, 63 insertions(+), 48 deletions(-) delete mode 100644 quest/m1/ts-reliability/step-back.md diff --git a/quest/m1/ts-reliability/README.md b/quest/m1/ts-reliability/README.md index 28aa3e660ea..9c180605685 100644 --- a/quest/m1/ts-reliability/README.md +++ b/quest/m1/ts-reliability/README.md @@ -1,4 +1,4 @@ -# TS fidelity and recovery +# [L] TS fidelity and recovery ## Goal @@ -97,10 +97,6 @@ PMT fragmentation (#5220), initial mux-rate measurement (#5287), and decoder-time admission (#5306) have landed, as have PSI runs (#5606) and catalog linger (#5305). -## Required - -- [A small step back keeps the TS export's video](/quest/m1/ts-reliability/step-back.md) - the export re-acquires on a sub-group step back from any source instead of dropping its video - ## Related - [MSFTS mapping](/quest/m3/msfts-convergence.md) - document the exact equivalence and differences between the carriage modes diff --git a/quest/m1/ts-reliability/step-back.md b/quest/m1/ts-reliability/step-back.md deleted file mode 100644 index d8c65eb6236..00000000000 --- a/quest/m1/ts-reliability/step-back.md +++ /dev/null @@ -1,34 +0,0 @@ -# [S] A small step back keeps the TS export's video - -## Goal - -When a source's decode time steps back by more than the export's delay but -within one group, the TS export re-acquires and keeps rendering video, -instead of dropping nearly every video frame until the next group. - -## Plan - -Decided 2026-10-29 (maintainer), a follow-up of -[moq-dev/moq#7165](https://github.com/moq-dev/moq/pull/7165), which made the -jitter buffer re-acquire on an unmarked step in either direction. - -Found while landing #7165: with 600 ms groups and a 500 ms delay, a −560 ms -step drops 105 of 120 video frames over 8 groups, on main's engine as well. -The export's video decode-time reconstruction clamps DTS to stay -non-decreasing, so only the first frame after the step regresses, and it is -still in time. The rest arrive late without a regression, so the jitter -buffer's backward rule never sees the step. Audio is unaffected. - -The fix belongs where video decode time is reconstructed, not in the jitter -buffer: the step has to reach the jitter buffer as a regression it can act -on. - -Since [moq-dev/moq#7144](https://github.com/moq-dev/moq/pull/7144), a TS or SRT -import turns any rewind into a new epoch, so this remains -for every other source (fMP4, MKV, FLV, RTMP, hang publishers). Kept a -separate quest for that reason. - -Tests: an end-to-end TS export of an H.264 + AAC source with the −560 ms -step, which fails on main and keeps video rendering with the fix. - -Public API: none. Wire: none. diff --git a/rs/moq-mux/src/container/ts/export.rs b/rs/moq-mux/src/container/ts/export.rs index 67eb50234d6..898f3ca9882 100644 --- a/rs/moq-mux/src/container/ts/export.rs +++ b/rs/moq-mux/src/container/ts/export.rs @@ -314,6 +314,11 @@ struct Track { /// The marker, skip and cut counts of the sources the track read before this one, so the /// counts keep rising across a resubscription. base: (u64, u64, u64), + /// How many unmarked steps back the track's timeline took ([`Self::steps_back`]), each + /// counted as a marker of its own. + steps: u64, + /// The highest PTS read on the track's timeline, and the marker count it was read under. + high: Option<(u64, Timestamp)>, finished: bool, pid: u16, /// The PMT lists it: from its first frame out until its last has gone and the catalog has @@ -391,6 +396,8 @@ impl Track { latest: kio::clock::Instant::ZERO, restart: 0, base: (0, 0, 0), + steps: 0, + high: None, finished: false, pid: 0, listed: false, @@ -427,11 +434,15 @@ impl Track { jitter: &mut jitter::Buffer, ) -> anyhow::Result<()> { if pending.restart != self.restart { - // A marker declared a break in the timeline, so the decode clock restarts too. + // A marker declared a break in the timeline, or it stepped back unmarked + // ([`Self::steps_back`]), so the decode clock restarts too, and the last keyframe, + // on the timeline left behind, no longer marks what leads it. self.release(name, jitter, true)?; self.restart = pending.restart; self.clock = DecodeClock::default(); self.declared = None; + self.keyframe = None; + self.leading_floor = None; } // MPEG-1/2 video is placed, so its pictures rather than its timestamps say what leads. let stream_type = match self.kind { @@ -510,6 +521,38 @@ impl Track { self.release(name, jitter, false) } + /// Count a frame that steps the track's timeline back with no marker as a marker of its own: + /// presented further below the highest PTS read on the timeline than the export's `delay`, + /// and than any reordering a video rendition declares. + /// + /// No reordering the export carries explains that, and the jitter buffer would not see it + /// as a step. A video decode clock that went on would hold the frame as reordered and clamp + /// its DTS, and every later frame's, onto the old timeline, so they would only arrive late + /// until it caught up. Audio with slack left would decode before the frames ahead of it on + /// the same clock, which the output's buffers cannot carry. As a marker, the step restarts + /// the decode clock and opens a new generation, as one the source declared would. A placed + /// frame's timestamp is its arrival rather than its decode time, so it never steps. Without + /// a delay nothing is late, so a step costs nothing there. + fn steps_back(&mut self, pending: &mut Pending, delay: Duration) { + if self.kind.placed() { + return; + } + let pts = pending.frame.timestamp; + let high = (self.high).and_then(|(restart, high)| (restart == pending.restart).then_some(high)); + let (_, lookahead) = self.timing.inferred(); + let delay = u64::try_from(delay.as_micros() * 90_000 / 1_000_000).unwrap_or(u64::MAX); + let bound = delay.max(lookahead).max(self.timing.jitter); + let stepped = delay > 0 && high.is_some_and(|high| to_ticks(pts).saturating_add(bound) < to_ticks(high)); + if stepped { + tracing::debug!(track = %self.key.name, ?pts, ?high, "unmarked step back; restarting the timeline"); + self.steps += 1; + pending.restart += 1; + pending.skip += 1; + } + let high = high.filter(|_| !stepped).map_or(pts, |high| high.max(pts)); + self.high = Some((pending.restart, high)); + } + /// Read within the jitter window, or hold the first frame until the program tables are built. fn fill(&mut self, name: &str, waiter: &kio::Waiter, input: &mut Input<'_>) -> crate::Result<()> { if self.key.name.is_empty() { @@ -542,14 +585,15 @@ impl Track { *input.trimmed += 1; continue; } - let pending = Pending { + let mut pending = Pending { frame, - restart: self.base.0 + self.source.markers(), - skip: self.base.1 + self.source.skips(), + restart: self.base.0 + self.source.markers() + self.steps, + skip: self.base.1 + self.source.skips() + self.steps, cut: self.base.2 + self.source.cuts(), arrived, read: kio::clock::now(), }; + self.steps_back(&mut pending, input.jitter.delay()); // A new timeline must reach the reset before tune-in alignment can drop it. if let Some(start) = input.video_start && aligned && pending.restart == self.restart diff --git a/rs/moq-mux/src/container/ts/export_timing_test.rs b/rs/moq-mux/src/container/ts/export_timing_test.rs index 4d39e22c855..b5d11d00330 100644 --- a/rs/moq-mux/src/container/ts/export_timing_test.rs +++ b/rs/moq-mux/src/container/ts/export_timing_test.rs @@ -633,20 +633,29 @@ async fn a_track_sent_later_than_the_delay_loses_nothing() { /// A changeover between two encoders whose clocks started hours apart steps the whole timeline /// forward with no marker, mid-group, as in the field. The export re-acquires its clock as at -/// startup, rather than read the step as drift and end, and renders on without a drop. (A step -/// back further than the group before its own never reaches it: the reader refuses it.) +/// startup, rather than read the step as drift and end, and renders on without a drop. So it +/// does for a step back of more than the delay that lands within the group before its own, +/// whichever decode clock the video runs on, rather than clamp the video onto the old timeline +/// and drop it as late until the timeline catches up, or decode the audio before what it +/// already sent. (A step back further than that never reaches it: the reader refuses it.) #[tokio::test(start_paused = true)] async fn an_unmarked_step_keeps_the_export_rendering() { - for step in [16_844_500_000, 2_000_000] { - for lag in [0, LAGS[0], LAGS[1]] { + let cases = [false, true] + .into_iter() + .flat_map(|declared| [0, LAGS[0], LAGS[1]].map(|lag| (declared, lag))); + for step in [16_844_500_000, 2_000_000, -560_000] { + for (declared, lag) in cases.clone() { let mut live = Live::new(1.0, lag).await; + if declared { + live.reorder(); + } let mut leg = live.join(Duration::ZERO).await; live.run(8 * GOP + GOP / 2, &mut [&mut leg], |_| false).await; live.offset += step; let stepped = kio::clock::now(); live.run(live.tick + 8 * GOP, &mut [&mut leg], |_| false).await; - let case = format!("{} s step, lag {lag}", step as f64 / 1e6); + let case = format!("{} s step, declared {declared}, lag {lag}", step as f64 / 1e6); assert_eq!(leg.export.dropped(), 0, "{case}"); let video = leg .units() From 9752568d8a7ff299cf33d2b9f208231bfff0ada3 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 1 Nov 2026 15:24:51 -0800 Subject: [PATCH 3/4] fix(mux): bound a declared rendition's step back by its reorder depth A rendition that declares its catalog `reorder` bounds reordering by frames, not time, so a low frame rate pyramid can present a frame further below the highest PTS than the delay. Such a frame only steps the timeline when the declared clock would also refuse it as reordered past its depth. The inferred clock's bound also takes the reordering it has seen. Co-Authored-By: Claude Opus 5.5 --- rs/moq-mux/src/container/declared.rs | 10 ++++++++-- rs/moq-mux/src/container/decode.rs | 5 +++++ rs/moq-mux/src/container/ts/export.rs | 12 +++++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/rs/moq-mux/src/container/declared.rs b/rs/moq-mux/src/container/declared.rs index c5aea9039d5..f60fd4e7956 100644 --- a/rs/moq-mux/src/container/declared.rs +++ b/rs/moq-mux/src/container/declared.rs @@ -70,15 +70,21 @@ impl DeclaredClock { self.held.len() } + /// Whether a frame presented at `pts` would follow more than the depth frames read before it + /// in presentation order, which [`Self::push`] refuses. + pub(crate) fn reorders_past(&self, pts: u64) -> bool { + self.highest.len() - self.highest.partition_point(|&prior| prior <= pts) > self.depth + } + /// Hold the group's next frame in decode order, presented at `pts`. pub(crate) fn push(&mut self, item: T, pts: u64) -> crate::Result<()> { if self.held.len() > self.depth { return Err(ClockError::Undrained.into()); } - let at = self.highest.partition_point(|&prior| prior <= pts); - if self.highest.len() - at > self.depth { + if self.reorders_past(pts) { return Err(ClockError::Reordered(self.depth).into()); } + let at = self.highest.partition_point(|&prior| prior <= pts); self.highest.insert(at, pts); if self.highest.len() > self.depth + 1 { self.highest.remove(0); diff --git a/rs/moq-mux/src/container/decode.rs b/rs/moq-mux/src/container/decode.rs index a12813e770f..6d03a30a8f5 100644 --- a/rs/moq-mux/src/container/decode.rs +++ b/rs/moq-mux/src/container/decode.rs @@ -173,6 +173,11 @@ impl DecodeClock { self.held.len() } + /// The furthest a frame was presented below the highest PTS read before it, plus a tick. + pub(crate) fn reach(&self) -> u64 { + self.reach + } + /// How far past a slot the highest PTS must be to settle it, under `lookahead`. fn lookahead(&self, lookahead: u64) -> u64 { lookahead.max(self.reach).min(MAX_REORDER) diff --git a/rs/moq-mux/src/container/ts/export.rs b/rs/moq-mux/src/container/ts/export.rs index 898f3ca9882..8a5eab896d9 100644 --- a/rs/moq-mux/src/container/ts/export.rs +++ b/rs/moq-mux/src/container/ts/export.rs @@ -523,7 +523,9 @@ impl Track { /// Count a frame that steps the track's timeline back with no marker as a marker of its own: /// presented further below the highest PTS read on the timeline than the export's `delay`, - /// and than any reordering a video rendition declares. + /// and than any reordering a video rendition declares or its decode clock has seen. A + /// rendition that declares its catalog `reorder` bounds it by frames rather than time, so + /// there the frame must also follow more frames than that in presentation order. /// /// No reordering the export carries explains that, and the jitter buffer would not see it /// as a step. A video decode clock that went on would hold the frame as reordered and clamp @@ -541,8 +543,12 @@ impl Track { let high = (self.high).and_then(|(restart, high)| (restart == pending.restart).then_some(high)); let (_, lookahead) = self.timing.inferred(); let delay = u64::try_from(delay.as_micros() * 90_000 / 1_000_000).unwrap_or(u64::MAX); - let bound = delay.max(lookahead).max(self.timing.jitter); - let stepped = delay > 0 && high.is_some_and(|high| to_ticks(pts).saturating_add(bound) < to_ticks(high)); + let bound = delay.max(lookahead).max(self.timing.jitter).max(self.clock.reach()); + let reordered = (self.declared) + .as_ref() + .is_none_or(|clock| clock.reorders_past(to_ticks(pts))); + let stepped = + delay > 0 && reordered && high.is_some_and(|high| to_ticks(pts).saturating_add(bound) < to_ticks(high)); if stepped { tracing::debug!(track = %self.key.name, ?pts, ?high, "unmarked step back; restarting the timeline"); self.steps += 1; From 8fb5afc00242e6cefb51727d7e55b5d3f13f3c1e Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 3 Nov 2026 16:24:26 -0800 Subject: [PATCH 4/4] fix(mux): detect an unmarked step back only where a reorder bound proves it A TS export counts an unmarked step back of more than its delay as a restart only where a reorder bound proves the frame falls outside valid reordering: audio, which never reorders, and video that follows more frames than its catalog `reorder` depth declares. Video that declares no depth is left untouched, so a slow, deep B-frame stream is never mistaken for a step (maintainer decision 2026-11-03). Drops the time bounds the inferred clock lent the check (its observed reach, the SPS lookahead and the catalog jitter), which only guessed, and the `DecodeClock::reach` accessor they needed. Co-Authored-By: Claude Opus 5.5 --- quest/m1/ts-reliability/README.md | 7 + quest/m1/ts-small-step-back.md | 9 +- rs/moq-mux/src/container/decode.rs | 5 - rs/moq-mux/src/container/ts/export.rs | 143 +++++++++++++++--- .../src/container/ts/export_timing_test.rs | 18 +-- 5 files changed, 145 insertions(+), 37 deletions(-) diff --git a/quest/m1/ts-reliability/README.md b/quest/m1/ts-reliability/README.md index 1085c82202c..63055af6d8a 100644 --- a/quest/m1/ts-reliability/README.md +++ b/quest/m1/ts-reliability/README.md @@ -93,6 +93,13 @@ measurement (decided 2026-10-28). Re-planned the same day: decode order covers M absorbs the release audit's export-reorder quest, and the shared parser lands before the open stream-routes and PAT drafts, which rebase onto it. +Decided 2026-11-03 (maintainer, #7221): the TS export counts an unmarked step +back as a restart only where a reorder bound proves the frame falls outside +valid reordering: audio, which never reorders, and video that steps back past +its catalog `reorder` depth, in both cases by more than the export's delay. +Video that declares no `reorder` is left untouched: no detection, no rewrite, +no error. + PMT fragmentation (#5220), initial mux-rate measurement (#5287), and decoder-time admission (#5306) have landed, as have PSI runs (#5606) and catalog linger (#5305). diff --git a/quest/m1/ts-small-step-back.md b/quest/m1/ts-small-step-back.md index 839dcdd961a..b03670bfc40 100644 --- a/quest/m1/ts-small-step-back.md +++ b/quest/m1/ts-small-step-back.md @@ -17,14 +17,11 @@ regresses within one clock period, and declared-reorder video fails with declared depth for video. - #7221's `Track::steps_back` (`rs/moq-mux/src/container/ts/export.rs`) is where it goes. -- Check the narrow case #7221 also raised: a slow, deep B-frame stream that - declares no reorder depth must not be mistaken for a step. +- Video that declares no `reorder` stays untouched, so a slow, deep B-frame + stream is never mistaken for a step (decided 2026-11-03, maintainer, in + #7221). - Extend `an_unmarked_step_keeps_the_export_rendering`. -## Required - -- [A small step back keeps the TS export's video](/quest/m1/ts-reliability/step-back.md) - adds `Track::steps_back`, which this extends, in [moq-dev/moq#7221](https://github.com/moq-dev/moq/pull/7221) - ## Related - [TS reliability](/quest/m1/ts-reliability/README.md) - the epic whose step-back fix this extends diff --git a/rs/moq-mux/src/container/decode.rs b/rs/moq-mux/src/container/decode.rs index 6d03a30a8f5..a12813e770f 100644 --- a/rs/moq-mux/src/container/decode.rs +++ b/rs/moq-mux/src/container/decode.rs @@ -173,11 +173,6 @@ impl DecodeClock { self.held.len() } - /// The furthest a frame was presented below the highest PTS read before it, plus a tick. - pub(crate) fn reach(&self) -> u64 { - self.reach - } - /// How far past a slot the highest PTS must be to settle it, under `lookahead`. fn lookahead(&self, lookahead: u64) -> u64 { lookahead.max(self.reach).min(MAX_REORDER) diff --git a/rs/moq-mux/src/container/ts/export.rs b/rs/moq-mux/src/container/ts/export.rs index 00d524af77c..fafe9ba9400 100644 --- a/rs/moq-mux/src/container/ts/export.rs +++ b/rs/moq-mux/src/container/ts/export.rs @@ -525,32 +525,36 @@ impl Track { /// Count a frame that steps the track's timeline back with no marker as a marker of its own: /// presented further below the highest PTS read on the timeline than the export's `delay`, - /// and than any reordering a video rendition declares or its decode clock has seen. A - /// rendition that declares its catalog `reorder` bounds it by frames rather than time, so - /// there the frame must also follow more frames than that in presentation order. + /// where a reorder bound proves no valid reordering explains it. /// - /// No reordering the export carries explains that, and the jitter buffer would not see it - /// as a step. A video decode clock that went on would hold the frame as reordered and clamp - /// its DTS, and every later frame's, onto the old timeline, so they would only arrive late - /// until it caught up. Audio with slack left would decode before the frames ahead of it on - /// the same clock, which the output's buffers cannot carry. As a marker, the step restarts + /// Audio presents in decode order, so any frame below one read before it is out of order. + /// Video reorders within only the catalog `reorder` its rendition declares, so the frame must + /// also follow more frames than that in presentation order ([`DeclaredClock::reorders_past`]). + /// Video that declares none is left as it is: its decode clock infers reordering from the + /// timestamps, so nothing tells a step back from a reorder deeper than any it has seen, and a + /// guess would restart a healthy stream. + /// + /// The jitter buffer would not see the step: the group's declared clock would refuse the frame + /// and fail the export, and audio with slack left would decode before the frames ahead of it + /// on the same clock, which the output's buffers cannot carry. As a marker, the step restarts /// the decode clock and opens a new generation, as one the source declared would. A placed - /// frame's timestamp is its arrival rather than its decode time, so it never steps. Without - /// a delay nothing is late, so a step costs nothing there. + /// frame's timestamp is its arrival rather than its decode time, so it never steps. Without a + /// delay nothing is late, so a step costs nothing there. fn steps_back(&mut self, pending: &mut Pending, delay: Duration) { if self.kind.placed() { return; } let pts = pending.frame.timestamp; let high = (self.high).and_then(|(restart, high)| (restart == pending.restart).then_some(high)); - let (_, lookahead) = self.timing.inferred(); let delay = u64::try_from(delay.as_micros() * 90_000 / 1_000_000).unwrap_or(u64::MAX); - let bound = delay.max(lookahead).max(self.timing.jitter).max(self.clock.reach()); - let reordered = (self.declared) - .as_ref() - .is_none_or(|clock| clock.reorders_past(to_ticks(pts))); - let stepped = - delay > 0 && reordered && high.is_some_and(|high| to_ticks(pts).saturating_add(bound) < to_ticks(high)); + let below = delay > 0 && high.is_some_and(|high| to_ticks(pts).saturating_add(delay) < to_ticks(high)); + let stepped = below + && match self.kind { + Kind::Video(_) => (self.declared) + .as_ref() + .is_some_and(|clock| clock.reorders_past(to_ticks(pts))), + _ => true, + }; if stepped { tracing::debug!(track = %self.key.name, ?pts, ?high, "unmarked step back; restarting the timeline"); self.steps += 1; @@ -5045,6 +5049,111 @@ mod tests { assert_eq!(pat.programs[0].pmt_pid.as_u16(), 0x30); } + /// How many unmarked steps back [`super::Track::steps_back`] counts on video read in decode + /// order, each frame presented at `(ms, keyframe)`, clocked as [`super::Track::queue`] clocks + /// it: on a clock per group at the catalog `reorder` depth, or inferred when it declares none. + async fn video_steps(reorder: Option, frames: &[(u64, bool)]) -> u64 { + use crate::catalog::hang::Container; + use crate::container::{Kind as MediaKind, Producer}; + + let broadcast = moq_net::broadcast::Info::new().produce(); + let publisher = broadcast.create_track("video", hang::container::track_info(0)).unwrap(); + let _publisher = Producer::new(publisher, Container::Legacy(MediaKind::Video)); + let source = crate::source::announced(&broadcast.consume()).await; + let source = super::ExportSource::for_stream(&source, "video", Duration::from_secs(2)).unwrap(); + let mut track = super::Track::new(source, Kind::Video(mpeg2ts::es::StreamType::H264)); + let arrived = kio::clock::now(); + for &(at, keyframe) in frames { + let mut pending = super::Pending { + frame: super::Frame { + timestamp: ms(at), + duration: None, + payload: bytes::Bytes::new(), + keyframe, + }, + restart: track.steps, + skip: track.steps, + cut: 0, + arrived, + read: arrived, + }; + track.steps_back(&mut pending, Duration::from_millis(500)); + if pending.restart != track.restart { + track.restart = pending.restart; + track.clock = DecodeClock::default(); + track.declared = None; + } + if keyframe { + track.declared = reorder.map(super::DeclaredClock::new); + } + let pts = super::to_ticks(ms(at)); + match &mut track.declared { + Some(clock) => { + clock.push(Some((pending, None)), pts).unwrap(); + while clock.pop(false).unwrap().is_some() {} + } + None => track.clock.push((pending, None), pts, arrived, 0), + } + } + track.steps + } + + /// Two groups of a B-pyramid two frames deep, 40 ms a frame, in decode order from `at` ms, its + /// second group stepped back `step` ms after its first `before` frames. + fn pyramid(at: u64, step: u64, before: usize) -> Vec<(u64, bool)> { + const ORDER: [u64; 9] = [0, 4, 2, 1, 3, 8, 6, 5, 7]; + (0..2) + .flat_map(|group| ORDER.map(move |place| (group, place))) + .enumerate() + .map(|(index, (group, place))| { + let pts = at + (group * 9 + place) * 40; + let pts = if index >= 9 + before { pts - step } else { pts }; + (pts, place == 0) + }) + .collect() + } + + /// A rendition that declares its `reorder` proves a frame following more frames than that in + /// presentation order stepped back, while its own reordering is left as it is. + #[tokio::test(start_paused = true)] + async fn a_declared_reorder_bounds_a_step_back() { + assert_eq!( + video_steps(Some(2), &pyramid(10_000, 0, 0)).await, + 0, + "in-bound reordering" + ); + assert_eq!( + video_steps(Some(2), &pyramid(10_000, 560, 4)).await, + 1, + "a step within a group" + ); + assert_eq!( + video_steps(Some(2), &pyramid(10_000, 560, 0)).await, + 1, + "a group stepped whole" + ); + // Two frames back is within the declared depth, however far back they are presented. + let deep = [(10_000, true), (11_000, false), (11_040, false), (10_040, false)]; + assert_eq!( + video_steps(Some(2), &deep).await, + 0, + "in-bound reordering past the delay" + ); + } + + /// Video that declares no `reorder` is left as it is: neither a deep reorder nor a step back + /// can be told apart from the timestamps, so neither restarts the timeline. + #[tokio::test(start_paused = true)] + async fn undeclared_reordering_never_steps_back() { + let slow = [(0, true), (1_600, false), (800, false)]; + assert_eq!(video_steps(None, &slow).await, 0, "reordering past the delay"); + assert_eq!( + video_steps(None, &pyramid(10_000, 560, 4)).await, + 0, + "a step past the delay" + ); + } + /// The same available video/audio backlog must choose the same start in either fill order. #[tokio::test(start_paused = true)] async fn track_fill_observes_every_available_track_before_acquisition() { diff --git a/rs/moq-mux/src/container/ts/export_timing_test.rs b/rs/moq-mux/src/container/ts/export_timing_test.rs index 97c1b742dfc..c21574ca408 100644 --- a/rs/moq-mux/src/container/ts/export_timing_test.rs +++ b/rs/moq-mux/src/container/ts/export_timing_test.rs @@ -741,17 +741,17 @@ async fn a_track_sent_later_than_the_delay_loses_nothing() { /// A changeover between two encoders whose clocks started hours apart steps the whole timeline /// forward with no marker, mid-group, as in the field. The export re-acquires its clock as at /// startup, rather than read the step as drift and end, and renders on without a drop. So it -/// does for a step back of more than the delay that lands within the group before its own, -/// whichever decode clock the video runs on, rather than clamp the video onto the old timeline -/// and drop it as late until the timeline catches up, or decode the audio before what it -/// already sent. (A step back further than that never reaches it: the reader refuses it.) +/// does for a step back of more than the delay that lands within the group before its own, on +/// video that declares its `reorder`, which proves the step is no reordering, rather than clamp +/// the video onto the old timeline and drop it as late until the timeline catches up, or fail on +/// a frame reordered deeper than declared. Video that declares none is left as it is. (A step +/// back further than that never reaches it: the reader refuses it.) #[tokio::test(start_paused = true)] async fn an_unmarked_step_keeps_the_export_rendering() { - let cases = [false, true] - .into_iter() - .flat_map(|declared| [0, LAGS[0], LAGS[1]].map(|lag| (declared, lag))); - for step in [16_844_500_000, 2_000_000, -560_000] { - for (declared, lag) in cases.clone() { + let forward = [16_844_500_000, 2_000_000].map(|step| [(step, false), (step, true)]); + let cases = forward.into_iter().flatten().chain([(-560_000, true)]); + for (step, declared) in cases { + for lag in [0, LAGS[0], LAGS[1]] { let mut live = Live::new(1.0, lag).await; if declared { live.reorder();