Skip to content

feat(player): support selectable HLS and TS audio tracks#674

Merged
stackia merged 7 commits into
mainfrom
codex/hls-audio-tracks
Jul 14, 2026
Merged

feat(player): support selectable HLS and TS audio tracks#674
stackia merged 7 commits into
mainfrom
codex/hls-audio-tracks

Conversation

@stackia

@stackia stackia commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Summary

  • support alternate HLS audio renditions declared through EXT-X-MEDIA for MPEG-TS and fMP4 sources
  • discover and switch audio PIDs inside HLS or continuous MPEG-TS programs without rebuilding video playback
  • expose a multi-audio selector, pending state, localized accessibility labels, and per-channel track preferences
  • keep MP2 software decoding and PTS/DTS normalization working across initial selection and track switches
  • add devlab scenarios for manual coverage across codec and delivery combinations

Why

The custom HLS/MSE pipeline previously selected only the variant playlist and ignored separately declared audio renditions. It also treated one PMT audio PID as authoritative, so programs with multiple elementary audio streams could not expose or switch tracks.

Track changes now prepare the replacement audio at a playable boundary, preserve the video pipeline, and anchor the new audio timeline at the current playback position. Unsupported codecs or failed switches leave the previous track active and surface a non-blocking warning.

Validation

  • pnpm run type-check:tsc
  • pnpm run lint:biome
  • Ruff check and format verification for devlab and e2e
  • HTTP proxy M3U e2e suite (39 passed)
  • production Web UI build
  • C binary build
  • manual browser coverage for HLS-TS, HLS-fMP4, HLS internal multi-PID TS, continuous TS, AAC/MP2 switching, unsupported AC-3 fallback, and preference restoration

@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Documentation preview

The documentation preview has been deployed for this pull request.

@stackia
stackia marked this pull request as ready for review July 14, 2026 12:11
@stackia
stackia marked this pull request as draft July 14, 2026 12:12
@stackia
stackia requested a review from Copilot July 14, 2026 12:12
@stackia
stackia marked this pull request as ready for review July 14, 2026 12:12

@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: a537b40326

ℹ️ 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/playback-engine/hls/m3u8.ts Outdated
Comment thread web-ui/src/playback-engine/hls/m3u8.ts Outdated

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 adds end-to-end support for selectable audio tracks across the custom HLS/MSE playback pipeline, covering both (1) alternate HLS audio renditions via #EXT-X-MEDIA and (2) multiple elementary audio streams (PIDs) inside MPEG-TS, while preserving video continuity during audio switches.

Changes:

  • Extend the HLS stack to parse/select EXT-X-MEDIA audio renditions and use EXT-X-PROGRAM-DATE-TIME for cross-rendition alignment.
  • Rework the transmux worker/pipeline to support a video pipeline plus separate/replaceable audio pipelines, with switching handshakes and state/events.
  • Add UI + persistence for audio track selection (including a “switching” pending state and i18n strings), plus devlab scenarios for manual validation.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
web-ui/src/playback-engine/worker/transmux-worker.ts Split worker into primary + audio pipelines; add audio track state + switching protocol.
web-ui/src/playback-engine/worker/pipeline.ts Add PipelineOptions (forced track, selected TS audio PID), TS PID switching, and forced-track filtering.
web-ui/src/playback-engine/worker/messages.ts Add worker commands/events for audio track selection + switch results.
web-ui/src/playback-engine/types.ts Introduce audio track types/state + load options + preference key helper.
web-ui/src/playback-engine/remux/mp4-remuxer.ts Add audio-only reset and silent-audio occupancy helpers for switching/timeline continuity.
web-ui/src/playback-engine/mse/playback-controller.ts Handle new worker events; coordinate audio switch with MSE/PCM replacement.
web-ui/src/playback-engine/mse/media-source.ts Support “preserve existing” init handling; add replaceAudioFrom() and MIME checks.
web-ui/src/playback-engine/index.ts Re-export new audio track/load option types.
web-ui/src/playback-engine/hls/m3u8.ts Parse EXT-X-MEDIA audio renditions + PROGRAM-DATE-TIME; add selection helpers.
web-ui/src/playback-engine/hls/hls-source.ts Expose audio renditions in HlsInfo; add options for switch alignment and start positions.
web-ui/src/playback-engine/demux/ts-demuxer.ts Track multiple audio streams in PMT; allow selecting/switching audio PID; emit audio track list.
web-ui/src/playback-engine/demux/pat-pmt-pes.ts Add PMT audio stream model to carry codec/language and mapping metadata.
web-ui/src/playback-engine/backends/native-playback-backend.ts Surface native audioTracks as audio-tracks-change events and allow selecting them.
web-ui/src/playback-engine/backends/mse-playback-backend.ts Plumb new load options and audio track selection through MSE backend.
web-ui/src/playback-engine/audio/pcm-audio-player.ts Add replaceFrom() to cut scheduled/queued PCM at a switch boundary.
web-ui/src/lib/player-storage.ts Persist per-channel preferred audio track key.
web-ui/src/i18n/player.ts Add localized strings for audio track UI + switch failure warnings.
web-ui/src/components/player/video-player.tsx Wire audio track state/events, persistence, and error messaging into the player.
web-ui/src/components/player/player-controls.tsx Add audio track selector UI with pending/switching state and accessibility attributes.
tools/devlab/README.md Document new devlab scenarios for alternate/internal multi-audio coverage.
tools/devlab/devlab.py Add devlab generators for alternate audio HLS masters and multi-audio TS scenarios.

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

Comment thread web-ui/src/playback-engine/hls/hls-source.ts Outdated
Comment thread web-ui/src/playback-engine/mse/playback-controller.ts Outdated
Comment thread web-ui/src/playback-engine/worker/transmux-worker.ts

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 21 out of 21 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

tools/devlab/devlab.py:710

  • Invalid Python exception syntax: except BrokenPipeError, ConnectionError: is a syntax error in Python 3 (comma-separated exceptions are not allowed). This will prevent devlab.py from running.
                elif parts == ["multi-audio.ts"]:
                    self._multi_ts()
                else:
                    self._send(404, "text/plain", b"not found")
            except BrokenPipeError, ConnectionError:
                pass

Comment thread tools/devlab/devlab.py
Comment thread web-ui/src/playback-engine/mse/media-source.ts
@stackia
stackia requested a review from Copilot July 14, 2026 15:26

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@stackia

stackia commented Jul 14, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@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: fd2eedea3d

ℹ️ 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/playback-engine/hls/hls-source.ts Outdated
@stackia
stackia merged commit e391e89 into main Jul 14, 2026
11 checks passed
@stackia
stackia deleted the codex/hls-audio-tracks branch July 14, 2026 16:09
stackia added a commit that referenced this pull request Jul 14, 2026
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