Skip to content

fix(player): normalize MSE timelines across buffering and discontinuities#588

Merged
stackia merged 14 commits into
mainfrom
codex/fix-mp2-buffering-audio
Jun 26, 2026
Merged

fix(player): normalize MSE timelines across buffering and discontinuities#588
stackia merged 14 commits into
mainfrom
codex/fix-mp2-buffering-audio

Conversation

@stackia

@stackia stackia commented Jun 26, 2026

Copy link
Copy Markdown
Owner

Summary

This PR makes the web player treat MSE video, browser-decoded audio, silent AAC, and MP2 WebAudio output as one continuous playback timeline. It fixes MP2 soft-decoded audio repeating during MSE waiting, removes the old startup stall jumper, and normalizes TS/HLS timestamp discontinuities so packet loss, upstream PTS jumps, fMP4 tfdt offsets, and segment transitions do not create buffered range holes.

What changed

  • PCMAudioPlayer now follows the media element's playable state, stops scheduling PCM while the video is waiting, preserves its PCM cache, and resyncs from video.currentTime when playback resumes or seeks within buffered media.
  • TS demux/remux now starts video output at the first keyframe, detects TS continuity breaks, drops unreliable post-loss video until the next random-access frame, resets audio parser/decoder state, and flushes pre-discontinuity media/stashed samples so decodable content before loss is still emitted.
  • MP4Remuxer maps video, browser-decoded audio, MP2 PCM, and generated silent AAC onto a continuous output timeline, bridges forward timestamp holes without using the removed maxBufferHoleMs, and avoids relying on video.currentTime jumps to skip gaps.
  • HLS handling now keeps normal TS-HLS segment boundaries continuous, re-anchors only on startup/discontinuity/missed segments, and maps fMP4-HLS tfdt values to SegmentMeta.start with SourceBuffer timestampOffset.
  • The startup stall jumper, the MSE buffered-change callback used only by it, and the PCM 0.3s small-forward-jump shortcut were removed. src/embedded_web_data.h is intentionally not included.

Validation

  • pnpm run type-check:tsc
  • pnpm run lint:biome
  • pnpm exec vite build web-ui
  • git diff --check origin/main...HEAD

@github-actions

Copy link
Copy Markdown
Contributor

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

@stackia stackia changed the title fix(player): pause MP2 audio during buffering fix(player): handle MP2 buffering and timestamp holes Jun 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

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

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

Copy link
Copy Markdown
Contributor

Azure Static Web Apps: Your stage site is ready! Visit it here: https://thankful-water-0a297bf00-588.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 updates the web-ui MPEG-TS/fMP4 playback pipeline to prevent stalls by (1) pausing/resyncing software-decoded (PCM/WebAudio) audio during video buffering and (2) making remuxed output timestamps continuous across loader discontinuities to avoid MSE buffered-range holes.

Changes:

  • Remuxer now preserves lightweight per-track timing state across discontinuities and bridges forward timestamp gaps onto a continuous output timeline; silent AAC generation is aligned to corrected video timing.
  • PCM/WebAudio scheduling is gated on video readiness (waiting/stalled/playing/canplay), with buffering-triggered cancel/resync and a buffer-backed refill window.
  • Removes startup “stall jumper” and the public maxBufferHoleMs config (and related small-forward-seek shortcut).

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
web-ui/src/mpegts/worker/pipeline.ts Adds fMP4 timestampOffset derivation (tfdt-based) and maps decoded PCM timestamps via remuxer timing state.
web-ui/src/mpegts/remux/mp4-remuxer.ts Implements per-track timing state to bridge holes across discontinuities and keeps silent AAC aligned with corrected video samples.
web-ui/src/mpegts/remux/mp4-generator.ts Switches trun to version 1 so composition time offsets are encoded as signed values.
web-ui/src/mpegts/player/mse.ts Removes onBufferedChange hook from the MSE abstraction.
web-ui/src/mpegts/player/mpegts-player.ts Removes startup stall-jumper wiring; continues to pass timestampOffset through to MSE append path.
web-ui/src/mpegts/player/live-sync.ts Deletes the StallJumper implementation and related tag constant.
web-ui/src/mpegts/demux/ts-demuxer.ts Adds continuity-counter based discontinuity detection plus “drop until keyframe” gating to avoid emitting video before a usable keyframe.
web-ui/src/mpegts/config.ts Removes maxBufferHoleMs (and maxBufferHoleSec) from config defaults and API surface.
web-ui/src/mpegts/audio/pcm-audio-player.ts Stops scheduling PCM while video is buffering; resyncs from current video time; refills pending scheduling from the internal buffer window.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread web-ui/src/mpegts/demux/ts-demuxer.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: 5abe8be901

ℹ️ 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/demux/ts-demuxer.ts
Comment thread web-ui/src/mpegts/remux/mp4-remuxer.ts
@github-actions

Copy link
Copy Markdown
Contributor

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

@stackia stackia changed the title fix(player): handle MP2 buffering and timestamp holes fix(player): normalize MSE timelines across buffering and discontinuities Jun 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Azure Static Web Apps: Your stage site is ready! Visit it here: https://thankful-water-0a297bf00-588.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

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Comment thread web-ui/src/mpegts/demux/ts-demuxer.ts
Comment on lines +1179 to +1182
0x01,
0x00,
0x0f,
0x01, // version(0) & flags
0x01, // version(1) & flags
@stackia stackia merged commit ab77699 into main Jun 26, 2026
10 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

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

@stackia stackia deleted the codex/fix-mp2-buffering-audio branch June 26, 2026 23:29
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