Skip to content

perf(web-player): reduce transmux and audio processing overhead#639

Merged
stackia merged 2 commits into
mainfrom
codex/demuxremux
Jul 9, 2026
Merged

perf(web-player): reduce transmux and audio processing overhead#639
stackia merged 2 commits into
mainfrom
codex/demuxremux

Conversation

@stackia

@stackia stackia commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Summary

This reduces avoidable CPU overhead in the web player without changing the media pipeline architecture.

  • use the native Uint8Array search path for Annex-B start code scanning
  • batch small remuxed media fragments to reduce worker messages and MSE append operations
  • flush pending media at HLS segment, metadata, discontinuity, and EOF boundaries
  • bypass WSOLA correlation work when 1x playback is already synchronized
  • preserve silent AAC timing and correct skipped negative-DTS audio byte accounting

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:tsc
  • pnpm run lint:biome
  • pnpm exec vite build web-ui
  • local browser playback with H264/MP2, HEVC/AAC, HLS TS, and continuous multicast TS

@stackia stackia marked this pull request as ready for review July 9, 2026 21:43
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Documentation preview

The documentation preview has been deployed for this pull request.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@stackia stackia merged commit b70a33d into main Jul 9, 2026
12 checks passed
@stackia stackia deleted the codex/demuxremux branch July 9, 2026 22:02
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