perf(web-player): reduce transmux and audio processing overhead#639
Merged
Conversation
Contributor
Documentation previewThe documentation preview has been deployed for this pull request. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces avoidable CPU overhead in the MPEG-TS web player worker by batching remux output, tightening demux/remux flush boundaries, optimizing Annex‑B start-code scanning, and skipping unnecessary WSOLA work during stable 1× playback—while keeping timestamp behavior consistent.
Changes:
- Add hard flush boundaries at EOF and per-HLS segment boundaries (plus before TS track discontinuities / codec metadata changes) to avoid mixing samples across boundaries.
- Introduce configurable media-segment batching in the MP4 remuxer (duration/byte thresholds) and preserve “first fragment quickly” startup behavior.
- Optimize H264/H265 Annex‑B scanning via a shared
Uint8Array#indexOf-based start-code finder, and add a WSOLA bypass deadband for stable 1× playback.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| web-ui/src/mpegts/worker/pipeline.ts | Flush demux/remux state at EOF and enforce HLS segment batching boundaries. |
| web-ui/src/mpegts/remux/mp4-remuxer.ts | Add batching thresholds, adjust flush/force behavior, and fix silent AAC timing + negative-DTS byte accounting. |
| web-ui/src/mpegts/remux/media-batch.ts | New helper to decide when pending samples are “batch-ready” by duration/bytes. |
| web-ui/src/mpegts/demux/ts-demuxer.ts | Add explicit flushes before discontinuities and plumb a force flag into data-available callbacks. |
| web-ui/src/mpegts/demux/h265.ts | Switch HEVC Annex‑B scanning to the shared start-code finder. |
| web-ui/src/mpegts/demux/h264.ts | Switch AVC Annex‑B scanning to the shared start-code finder. |
| web-ui/src/mpegts/demux/annexb.ts | New shared Annex‑B start-code scan implementation. |
| web-ui/src/mpegts/audio/pcm-audio-player.ts | Add WSOLA bypass deadband + refactor control tick to avoid redundant pump work. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This reduces avoidable CPU overhead in the web player without changing the media pipeline architecture.
Root cause
Demux and remux are not the dominant tab-level CPU consumers, but byte-by-byte NAL scanning, fragmented remux output, and continuous near-1.0 WSOLA correction created unnecessary work. These changes remove that overhead while preserving startup latency and media timestamps.
Impact
The player emits fewer media fragments at higher bitrates and avoids expensive audio stretching during stable playback. This should reduce worker/MSE churn and improve mobile efficiency, while native decode and rendering remain the primary CPU consumers.
Validation
pnpm run type-check:tscpnpm run lint:biomepnpm exec vite build web-ui