Skip to content

fix(player): align mp2 pcm timestamps#594

Merged
stackia merged 2 commits into
mainfrom
codex/fix-mp2-pcm-sync
Jun 27, 2026
Merged

fix(player): align mp2 pcm timestamps#594
stackia merged 2 commits into
mainfrom
codex/fix-mp2-pcm-sync

Conversation

@stackia

@stackia stackia commented Jun 27, 2026

Copy link
Copy Markdown
Owner

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

  • Rebuilt mp2_decoder.wasm with 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.ts
  • Targeted tsc --ignoreConfig ... for the changed TypeScript files
  • pnpm run type-check:tsc
  • pnpm exec vite build web-ui
  • node web-ui/src/mpegts/wasm/minimp3/test-wasm.mjs

@stackia stackia requested a review from Copilot June 27, 2026 17:22
@stackia stackia marked this pull request as ready for review June 27, 2026 17:22
@github-actions

Copy link
Copy Markdown
Contributor

Azure Static Web Apps: Your stage site is ready! Visit it here: https://thankful-water-0a297bf00-594.eastasia.1.azurestaticapps.net

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 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 samplesBeforeInput and plumb it through the TypeScript decoder wrapper.
  • Use samplesBeforeInput in 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.

Comment thread web-ui/src/mpegts/worker/pipeline.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread web-ui/src/mpegts/worker/pipeline.ts Outdated
@github-actions

Copy link
Copy Markdown
Contributor

Azure Static Web Apps: Your stage site is ready! Visit it here: https://thankful-water-0a297bf00-594.eastasia.1.azurestaticapps.net

@stackia stackia merged commit 2896876 into main Jun 27, 2026
10 checks passed
@stackia stackia deleted the codex/fix-mp2-pcm-sync branch June 27, 2026 17:31
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