fix(moq-mux): confirm a TS audio frame joined out of a carried tail - #2823
fix(moq-mux): confirm a TS audio frame joined out of a carried tail#2823kixelated wants to merge 1 commit into
Conversation
At a splice (a looping file wrapping mid-frame, or a dropped PES), the TS importer published one frame of pre-splice bytes joined onto post-splice bytes as if it were real audio, and swallowed the real frame under it. The confirm-before-publish rule from #2751 keyed on `Resync::unconfirmed`, which a published frame clears. What that frame vouched for is where the tail begins, not the bytes the next PES joins onto it, so the join was trusted; the stale tail still opens with an intact header declaring a plausible length, so nothing else caught it either. Confirmation now also covers a frame beginning in a carried tail, which is where a splice lands. A frame that begins inside a PES is whole by the time it is parsed, so the common path pays no latency. Closes #2802 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
WalkthroughAudio resynchronization now tracks unconfirmed frames and separate end-of-stream draining state. Carried PES-tail frames require endpoint confirmation before publication. AAC and legacy audio paths use the shared confirmation logic and re-anchor recovered frames to the current PES timestamp. Finishing drains complete joined tail frames without accepting an unconfirmed first frame. Tests cover splice handling, stale tails, seeks, delayed delivery, budget exhaustion, timestamps, payload preservation, and final-frame draining. Mergeability Score: ⚪ Minimal · up to The change narrowly improves TS audio resynchronization at splice boundaries while preserving existing capture output, and no actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a64dc4d127
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| }); | ||
| Err(None) | ||
| } else if !self.resync.unconfirmed() { | ||
| } else if !confirm { |
There was a problem hiding this comment.
Reject aligned variable-length tail splices
When an AAC frame is cut after p bytes and the first frame after the wrap has length old_frame_len - p, the stale header's declared end lands exactly on the next real header. The confirmation therefore succeeds, and the importer still publishes a frame made from the stale prefix plus the entire wrapped frame, swallowing that real frame. The new tests use equal-sized frames, which guarantee misalignment for every nonzero cut and miss this variable-bitrate case. Do not treat one aligned successor as proof across a known splice, and add a variable-sized ADTS regression case. (Written by GPT-5.6 Sol)
AGENTS.md reference: AGENTS.md:L121-L121
Useful? React with 👍 / 👎.
|
Ran this against real broadcast content, because the four in-tree captures show the fix costs nothing on a well-formed mux but none of them contains a splice. The unit-level change looks right and both new tests pass on my build — but on a looped real broadcast TS the mixed-bytes frame is still published, and the audio is byte-identical before and after the fix. The reason is that a real loop wrap doesn't land where the fix looks. Setup
Result
Each alien frame begins with exactly the source's trailing partial frame (554 B for MP2, 282 B for AC-3), so these are the splice frames, not some unrelated artefact. The frame-count difference is only that the post capture ran ~0.2 s longer; over the common length the audio is byte-identical — 1,486,080 B of MP2 and 1,472,454 B of AC-3, covering all three wraps. Why the fix doesn't fireTwo properties of real broadcast muxing, neither present in the synthetic fixtures: 1. This mux never splits a frame across a PES boundary. Every audio PES payload is exactly 5184 B = 9 × 576 B MP2 frames (AC-3: 6912 B = 9 × 768). 0 of 91 interior MP2 PES ends and 0 of 68 AC-3 PES ends fall mid-frame. So 2. At the wrap, the foreign bytes join the same PES, not the next one. The clip was cut out of a longer stream, so it begins with 16 continuation packets on the MP2 PID (2806 B, no PUSI) — the tail of a frame that started before the clip did. The final PES before the wrap is truncated by the cut, so it is still open and short of its declared So the demuxer is handed a single PES whose payload is Worth stressing: the confirmation rule itself would have caught this. At the mixed frame's declared end the bytes are A suggestion, from precedent in the same fileThe signal that these bytes are not contiguous with what preceded them is available one layer down, and it is free. Our wrap breaks continuity on every PID: MP2 goes That looks complementary to what this PR does rather than a replacement: confirmation still covers a genuine mid-frame PES split in a mux that does align that way, where continuity is intact and nothing is wrong. Secondary, and weaker than I first thoughtAC-3 carries a mandatory But it is not a general answer, and the same clip shows why: 0 of its 826 MP2 frames carry a CRC at all ( Why the unit tests couldn't have caught thisThe new tests build PES payloads and hand them to the stream directly, so there is no TS packet layer, no continuity counter to break, and a splice can only be expressed as a carried tail. That is exactly the shape the fix covers, and it's a different shape from the one a looping file actually produces. Might be worth a fixture that splices at the TS-packet layer. Happy to share the reproducer or run any variant — the harness is a single script and the audit is decidable, so a "does the capture contain a frame the source never had" check would drop into CI against a real capture if that's useful. (Written by Opus 5) |
Summary
moq import tspublished one frame of mixed bytes as if it were real audio, and swallowed the real frame underneath it. The resync from fix(moq-mux): resync TS audio instead of aborting the broadcast #2751 recovered on the frame after, so the damage was bounded, but that frame was silently wrong rather than dropped.Resync::unconfirmed, which a published frame clears. The frame after it starts at an offset the previous frame vouched for, so a carried tail joined at that offset was trusted. What the previous frame vouched for is where the tail begins, not the bytes the next PES joins onto it, and at a splice the two halves are unrelated. Nothing else catches it: the stale tail still opens with an intact header declaring a plausible length.Resync::accept_unconfirmedbecomesResync::drain, which marks end of stream rather than just clearing the flag, so the existing drain still publishes a final whole frame that no successor can ever confirm.legacy_resyncs_past_stale_tail_at_a_splice, which the issue cites as pinning the gap, did not reproduce it. Its splice lands on an offset nothing had vouched for (the stream published no frame before the cut), so confirmation already caught it, and it published three clean frames. Comment corrected and the assertion tightened to all three payloads.Public API changes
None.
Resync,AacStream, andLegacyStreamare private to moq-mux's TS importer.Test plan
legacy_confirms_a_frame_joined_out_of_a_carried_tailand its AAC mirror: both fail without the fix, publishing a frame of pre-splice bytes spliced onto post-splice bytes and losing the real frame under it.legacy_drains_a_joined_frame_at_end_of_streamand its AAC mirror: guard the end-of-stream drain, and both fail ifdrain()does not override the new rule.container/ts/test_data/(ac3, eac3, kyrion MPEG-2/AC-3, bbb) publish byte-for-byte identical audio before and after: 16/16/64/3 frames, same totals. The confirmation costs nothing on a well-formed mux.just fix,just check,just testall green.Cross-package sync
No row applies: no wire format, catalog, or public API change, and nothing under
/docdescribes the resync rule.Closes #2802.
(written by Opus 5)