fix(player): align mp2 pcm timestamps#594
Conversation
|
Azure Static Web Apps: Your stage site is ready! Visit it here: https://thankful-water-0a297bf00-594.eastasia.1.azurestaticapps.net |
There was a problem hiding this comment.
Pull request overview
This PR improves MP2 software-decoded PCM timestamp alignment in the MPEG-TS worker pipeline when the WASM decoder emits audio frames that started in a previous PES payload. It does this by having the decoder report how many decoded samples began before the current input buffer, then adjusting the anchor PTS accordingly and preserving “initial trim” behavior so audio before the first video presentation point is dropped/clipped rather than forced onto time 0.
Changes:
- Extend the MP2 WASM decoder info array to include
samplesBeforeInputand plumb it through the TypeScript decoder wrapper. - Use
samplesBeforeInputin the worker pipeline to shift the decoded PCM start timestamp earlier before anchoring/extrapolating audio PTS. - Change PCM-to-MSE timeline mapping to support “drop” or “emit with trimStartMs”, and apply trimming in the worker before emitting PCM to the main thread.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| web-ui/src/mpegts/worker/pipeline.ts | Adjusts MP2 PCM anchoring using samplesBeforeInput; updates pending PCM mapping/queueing; trims PCM when required by remuxer mapping. |
| web-ui/src/mpegts/wasm/minimp3/test-wasm.mjs | Updates the smoke test to read/print the new samplesBeforeInput info field. |
| web-ui/src/mpegts/wasm/minimp3/mp2_decoder.c | Adds samples_before_input accounting to the WASM decoder output info. |
| web-ui/src/mpegts/remux/mp4-remuxer.ts | Changes mapPcmTimestamp to return an action-based mapping (drop/emit + trim) and preserves initial audio floor logic. |
| web-ui/src/mpegts/decoder/mpeg-audio-decoder.ts | Updates the WASM wrapper to allocate/read the expanded info array and expose samplesBeforeInput. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e88bb8e801
ℹ️ 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".
|
Azure Static Web Apps: Your stage site is ready! Visit it here: https://thankful-water-0a297bf00-594.eastasia.1.azurestaticapps.net |
Summary
Fixes MP2 software-decoded PCM alignment when the WASM decoder emits frames carried over from the previous PES payload. The decoder now reports how many output samples started before the current input, and the worker subtracts that duration before anchoring PCM timestamps.
This also keeps the initial PCM trim behavior so audio before the first video presentation point is dropped or clipped instead of being compressed onto timeline zero.
Validation
mp2_decoder.wasmwith Docker Emscripten release build (emcc -O2).pnpm exec biome check web-ui/src/mpegts/decoder/mpeg-audio-decoder.ts web-ui/src/mpegts/worker/pipeline.ts web-ui/src/mpegts/wasm/minimp3/test-wasm.mjs web-ui/src/mpegts/remux/mp4-remuxer.tstsc --ignoreConfig ...for the changed TypeScript filespnpm run type-check:tscpnpm exec vite build web-uinode web-ui/src/mpegts/wasm/minimp3/test-wasm.mjs