Repository navigation
fix(watch): decode a reordered subscription head in timestamp order - #6523
Conversation
A subscription's head groups can arrive newest-first. Chrome's AudioDecoder stamps every output contiguously from its first input, so decoding the older frames after the newest shifts the whole track forward by the reorder. With a fixed 100 ms delay that pushes the gate past the ring's capacity and overflows it on every frame. Skip frames older than the newest one already decoded: the ring, anchored at the first insert, drops them anyway. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 24 minutes. View limit details
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 |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1f8701db0b
ℹ️ 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".
| // alongside them, and the ring, anchored at the first decoded frame, cannot place audio | ||
| // before it. Chrome's AudioDecoder would also stamp every later output from its first | ||
| // input, shifting the rest of the track by the reorder and overflowing a buffered ring. | ||
| if (newest !== undefined && frame.timestamp < newest) continue; |
There was a problem hiding this comment.
Retain playable history when the ring is reused
When a replacement subscription reuses the existing ring, such as after a rendition swap or temporary absence, its playhead can still precede the older head frames that arrive after the live edge. The ring is explicitly preserved across these replacements and can place such frames by timestamp (decoder.ts:400-404), but this check permanently discards every frame older than the first replacement frame, producing an avoidable audio hole. The comment's anchoring premise applies only to a new ring; the initial subscription head needs to be reordered before decoding, or filtered against the reused ring's playhead rather than the decoder's newest timestamp. The duplicated CMAF check has the same problem.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Real, but narrow, and decoding those frames doesn't fill the hole on Chrome either: its AudioDecoder stamps every output from its first input, so before this change the older head frames landed after the newest one, in the wrong slots, and shifted everything after them. Skipping them trades that misplacement for a gap.
On a rendition swap the predecessor was live through that span, so its audio already covers the slots below the replacement's first frame. The hole appears only on a return from an absence, where the predecessor stopped short of the new head. Even then it is bounded by the head's span, and only non-Chrome decoders (which keep input timestamps) placed those frames correctly before.
Reordering the head before decoding would hold the live edge until the older groups arrive, which defeats delivering it first. Resetting the decoder on every backward frame to make Chrome restamp would cost an Opus state reset per head frame. Neither seems worth it for this case, so I'm keeping the skip.
(Written by Claude Opus 5.5)
Summary
The moq.dev Voice demo still clipped the first reply intermittently on
@moq/watch0.6.4, after #6425.A subscription's head groups can reach the decoder newest-first. A trace of a clipped run showed decoder inputs at 140, 120, ... 0, then 160 ms. Chrome's
AudioDecoderstamps outputs contiguously from its first input, so every output landed 140 ms late. Backpressure then admitted 140 ms past the floor. With #6217's fixed 100 ms delay, the ring holds 200 ms, so it overflowed on every frame. 0.6.2 hid this because its floor grew to about 400 ms.Both decode loops now skip a frame older than the newest one already sent to the decoder since its last reset. The ring anchors at its first insert and drops those frames anyway, so playback loses nothing it would have kept.
Testing
decoder.test.tscases (legacy and CMAF) feed the reversed head; both fail without this change and pass with it.just js checkpasses.(Written by Claude Opus 5.5)
🤖 Generated with Claude Code