Skip to content

Delay A/V in WebRTC until both tracks have been seen.#1001

Merged
j0sh merged 2 commits intomainfrom
ja/av-gate
Apr 29, 2026
Merged

Delay A/V in WebRTC until both tracks have been seen.#1001
j0sh merged 2 commits intomainfrom
ja/av-gate

Conversation

@j0sh
Copy link
Copy Markdown
Contributor

@j0sh j0sh commented Apr 28, 2026

Delay A/V in WebRTC until both tracks have been seen.
For LTX-2 the cloud runs video VAE decode → audio decode sequentially,
so audio is ready before video is, often several hundred ms.

In aiortc WebRTC, RTCP SR anchors the PTS-to-wallclock mapping based
on the time the first frame was seen. Since both tracks start at
PTS=0, this caused a permanent desync if one track arrived late
relative to the other.

Fix this by waiting until both tracks have been seen.


Then a small refactor to how audio tracks are read:

Wait for audio before starting AV sync
Delay anchoring audio playback until the first buffered frame is available,
so startup and bursty generation do not emit premature silence that can
throw off AV sync.

j0sh added 2 commits April 27, 2026 23:22
For LTX-2 the cloud runs video VAE decode → audio decode sequentially,
so audio is ready before video is, often several hundred ms.

In aiortc WebRTC, RTCP SR anchors the PTS-to-wallclock mapping based
on the time the first frame was seen. Since both tracks start at
PTS=0, this caused a permanent desync if one track arrived late
relative to the other.

Fix this by waiting until both tracks have been seen.
Delay anchoring audio playback until the first buffered frame is available,
so startup and bursty generation do not emit premature silence that can
throw off AV sync.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 28, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b4ebd1ba-93a5-4ad9-b1a6-e8d0d215e68b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ja/av-gate

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

🚀 fal.ai Preview Deployment

Commit c91a852
App ID daydream/scope-livepeer-pr-1001--preview
WebSocket wss://fal.run/daydream/scope-livepeer-pr-1001--preview/ws

Testing on Cloud

SCOPE_CLOUD_APP_ID="daydream/scope-livepeer-pr-1001--preview/ws" uv run daydream-scope

@j0sh j0sh merged commit edac670 into main Apr 29, 2026
6 of 9 checks passed
@j0sh j0sh deleted the ja/av-gate branch April 29, 2026 04:19
leszko added a commit that referenced this pull request Apr 30, 2026
## Summary

- CI test runs were timing out at ~2h (recent runs cancelled at 1h43m /
1h56m / 2h0m). Root cause: PR #1001 ("Delay A/V in WebRTC until both
tracks have been seen.") changed `AudioProcessingTrack.recv()` so the
first call now blocks in `_wait_for_initial_audio()` until enough audio
has been buffered, but three tests in
`tests/test_audio_processing_track.py` still constructed tracks with
`started=False` and fed no / insufficient / paused audio — so `recv()`
looped forever.
- Drop `started=False` from the silence-fallback tests
(`test_no_audio_returns_silence`, `test_paused_returns_silence`,
`test_undersized_chunk_returns_silence`) so they exercise the
post-anchor `recv()` path, which is the path these silence-fallback
assertions actually care about.
- Local `pytest` now completes in ~70s instead of hanging.

## Test plan

- [x] `uv run pytest tests/test_audio_processing_track.py -v` — 30/30
pass in ~1.2s
- [x] `uv run pytest` — full suite completes in ~70s (vs. previously
hanging on `test_no_audio_returns_silence`)
- [x] `uv run ruff check tests/test_audio_processing_track.py` clean
- [x] `uv run ruff format --check tests/test_audio_processing_track.py`
clean

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Rafał Leszko <rafal@livepeer.org>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants