diff --git a/quest/m1/README.md b/quest/m1/README.md index 94843c6f595..b8aa3acc4dc 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -180,7 +180,6 @@ removed). - [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 - [Binding announcements always carry captures](/quest/m1/ffi-required-captures.md) - moq-ffi and its generated bindings make `captures` a required list, as #7266 always sets it - [HLS export follows a resolution change](/quest/m1/hls-reinit-same-codec.md) - a decoder-identity change under the same codec string starts a new init and segment tag -- [The last AAC segment advertises its full duration](/quest/m1/hls-final-aac-segment.md) - a TS import's final audio segment's EXTINF matches what decodes - [A JS reader finishes after a clean close](/quest/m1/js-close-range-finish.md) - a range ending below the cache delivers what's held and then ends - [fMP4 decode times keep increasing](/quest/m1/fmp4-bframe-decode-time.md) - fragments shorter than a GOP of B-frame video never step `tfdt` backwards - [A JS relay floors an unresolved copy at its newest group](/quest/m1/js-early-latest.md) - lite-01..05 subscribes without a start don't replay the cache from group 0 diff --git a/quest/m1/hls-conformance.md b/quest/m1/hls-conformance.md index b0d21709e1a..72a06a67c69 100644 --- a/quest/m1/hls-conformance.md +++ b/quest/m1/hls-conformance.md @@ -36,7 +36,6 @@ with both checks intact. ## Required - [HLS export follows a resolution change](/quest/m1/hls-reinit-same-codec.md) - the conformance test's same-codec switch fails until it lands -- [The last AAC segment advertises its full duration](/quest/m1/hls-final-aac-segment.md) - the conformance test's audio check fails until it lands ## Related diff --git a/quest/m1/hls-final-aac-segment.md b/quest/m1/hls-final-aac-segment.md deleted file mode 100644 index 43b3a4505a1..00000000000 --- a/quest/m1/hls-final-aac-segment.md +++ /dev/null @@ -1,17 +0,0 @@ -# [S] The last AAC segment after a TS import advertises its full duration - -## Goal - -After an MPEG-TS import ends, the final AAC segment's `EXTINF` and DASH `S@d` match what decodes, as they already do for the plain producer path. - -## Plan - -Found by the conformance test in [moq-dev/moq#7387](https://github.com/moq-dev/moq/pull/7387): the last audio segment advertises 1.365 s but 1.387 s decodes, one AAC frame short. The plain producer path gets it right, so the gap is somewhere in the TS import's end handling (likely the last frame's duration, which the importer infers from the next timestamp and has none for at the end). - -Decided 2026-10-30 (maintainer, follow-up planning after the /quest-afk run). Find the root cause before changing anything; fix it at the source rather than padding the advertised duration. The conformance test's audio check is the regression test. - -Public API: none. Wire: none. - -## Related - -- [HLS and DASH segment conformance](/quest/m1/hls-conformance.md) - the test that found it, which waits on this diff --git a/rs/moq-mux/src/container/ts/import.rs b/rs/moq-mux/src/container/ts/import.rs index cc7c23cfccc..3b1ba1e2c7b 100644 --- a/rs/moq-mux/src/container/ts/import.rs +++ b/rs/moq-mux/src/container/ts/import.rs @@ -3948,15 +3948,14 @@ impl AacStream { // Count only completed frames; input gaps and unfinished tails are not a media burst. burst += std::time::Duration::from_nanos((1024_u64 * 1_000_000_000).div_ceil(header.sample_rate as u64)); // The importer accumulates; cut each ADTS frame into its own group (one QUIC stream) - // so the relay forwards it without waiting for the next. - import.cut(None)?; + // so the relay forwards it without waiting for the next. Its known endpoint also + // bounds the final HLS segment, since a one-frame group has no measured cadence. + pts = advance_pts(pts, 1024, header.sample_rate)?; + import.cut(pts)?; self.resync.published(unvouched); published += 1; // Offsets behind the published frame are spent; carrying one would republish it. fallback = None; - - // Every ADTS frame is 1024 samples. - pts = advance_pts(pts, 1024, header.sample_rate)?; offset = end; } @@ -4057,23 +4056,16 @@ impl OpusStream { // 48 kHz samples elapsed since this PES's PTS, advancing each packet after the first. let mut elapsed: u64 = 0; for packet in packets { - let pts = match base { - Some(base) if elapsed > 0 => { - let advance = Timestamp::from_scale(elapsed, 48_000)?; - // `base` is a 90 kHz PTS; rescale the sample advance to match before - // adding (the scale-aware Timestamp rejects mixed scales). - Some(base.checked_add(advance.convert(base.scale())?)?) - } - other => other, - }; - self.import.decode(packet, pts)?; - // The importer accumulates; cut each Opus packet into its own group (one QUIC stream) - // so the relay forwards it without waiting for the next. - self.import.cut(None)?; - + let pts = advance_pts(base, elapsed, 48_000)?; // Default to 20 ms (960 samples) if the TOC can't be read, so a malformed packet // doesn't stall the timeline for the rest of the PES. elapsed += opus::packet_samples(packet).unwrap_or(960) as u64; + let end = advance_pts(base, elapsed, 48_000)?; + self.import.decode(packet, pts)?; + // The importer accumulates; cut each Opus packet into its own group (one QUIC stream) + // so the relay forwards it without waiting for the next. Its known endpoint also + // bounds the final HLS segment, since a one-packet group has no measured cadence. + self.import.cut(end)?; published += 1; } Ok(published) @@ -4559,14 +4551,14 @@ impl LegacyStream { import.decode(&data[offset..end], pts)?; // The importer accumulates; cut each frame into its own group (one QUIC stream) - // so the relay forwards it without waiting for the next. - import.cut(None)?; + // so the relay forwards it without waiting for the next. Its known endpoint also + // bounds the final HLS segment, since a one-frame group has no measured cadence. + pts = advance_pts(pts, header.samples, header.sample_rate)?; + import.cut(pts)?; self.resync.published(unvouched); published += 1; // Offsets behind the published frame are spent; carrying one would republish it. fallback = None; - - pts = advance_pts(pts, header.samples, header.sample_rate)?; offset = end; } @@ -6043,6 +6035,26 @@ pub(super) mod test { ); } + /// Where the only audio rendition's HLS records end, once the catalog finishes. + async fn hls_audio_end( + consumer: &moq_net::broadcast::Consumer, + catalog: &mut crate::catalog::Producer, + ) -> Option { + catalog.finish().unwrap(); + let snapshot = catalog.snapshot(); + let hls = snapshot.audio.renditions.values().next().unwrap().hls.as_ref().unwrap(); + let mut records = crate::hls::Consumer::subscribe(consumer, hls).await.unwrap(); + let mut end = None; + while let Some(event) = records.next().await.unwrap() { + if let crate::hls::Event::Push { entry, .. } = event + && entry.is_stop() + { + end = Some(entry.pts); + } + } + end + } + /// Read every retained frame of the single audio rendition in `catalog`. async fn read_audio_frames( consumer: &moq_net::broadcast::Consumer, @@ -6397,7 +6409,7 @@ pub(super) mod test { let mut broadcast = moq_net::broadcast::Info::new().produce(); let consumer = broadcast.consume(); - let catalog = crate::catalog::Producer::new(&mut broadcast, crate::catalog::Config::default()).unwrap(); + let mut catalog = crate::catalog::Producer::new(&mut broadcast, crate::catalog::Config::default()).unwrap(); let mut import = super::Import::new(broadcast, catalog.reserve()); let pmt = synth_pmt(&[(StreamType::AdtsAac, AAC_PID)], false); @@ -6422,6 +6434,11 @@ pub(super) mod test { [0xAA, 0xBB].map(|fill| adts_frame(40, fill)[7..].to_vec()).to_vec(), "the last frame was held for a confirmation that could never arrive" ); + // Both 1024-sample frames at 48 kHz, including the one completed by the EOF drain. + assert_eq!( + hls_audio_end(&consumer, &mut catalog).await, + Some(Timestamp::from_millis(1_042).unwrap()) + ); } /// One whole MPEG-2 Layer II frame (8 kbps, 16 kHz, mono = 72 bytes), filled with @@ -6785,7 +6802,7 @@ pub(super) mod test { let mut broadcast = moq_net::broadcast::Info::new().produce(); let consumer = broadcast.consume(); - let catalog = crate::catalog::Producer::new(&mut broadcast, crate::catalog::Config::default()).unwrap(); + let mut catalog = crate::catalog::Producer::new(&mut broadcast, crate::catalog::Config::default()).unwrap(); let mut import = super::Import::new(broadcast, catalog.reserve()); let pmt = synth_pmt(&[(StreamType::Mpeg1Audio, MP2_PID)], false); @@ -6829,6 +6846,11 @@ pub(super) mod test { )]), "the drained frame was published without a trace" ); + // Both 1152-sample frames at 16 kHz, including the one completed by the EOF drain. + assert_eq!( + hls_audio_end(&consumer, &mut catalog).await, + Some(Timestamp::from_millis(1_144).unwrap()) + ); } // A sync word is short enough to turn up by chance in compressed payload (a valid-looking @@ -9700,7 +9722,7 @@ pub(super) mod test { async fn damaged_opus_pes_is_not_half_published() { let mut broadcast = moq_net::broadcast::Info::new().produce(); let consumer = broadcast.consume(); - let catalog = crate::catalog::Producer::new(&mut broadcast, crate::catalog::Config::default()).unwrap(); + let mut catalog = crate::catalog::Producer::new(&mut broadcast, crate::catalog::Config::default()).unwrap(); let mut import = super::Import::new(broadcast, catalog.reserve()); import .ensure_stream( @@ -9726,6 +9748,11 @@ pub(super) mod test { let name = catalog.snapshot().audio.renditions.keys().next().unwrap().clone(); let frames = read_track(&consumer, &name, crate::container::Kind::Audio).await; assert_eq!(frames.len(), 2, "no packet from the damaged PES is published"); + // The last PES starts at 1.0667 s and holds one 20 ms packet, recorded in milliseconds. + assert_eq!( + hls_audio_end(&consumer, &mut catalog).await, + Some(Timestamp::from_millis(1_086).unwrap()) + ); } /// An aborted track is a feed-wide publishing failure, never a damaged media unit.