Skip to content

feat(player): Dolby Atmos passthrough on the DV loopback route - #64

Closed
raiden202 wants to merge 3 commits into
Silo-Server:mainfrom
raiden202:pr/dolby-atmos-passthrough
Closed

raiden202 wants to merge 3 commits into
Silo-Server:mainfrom
raiden202:pr/dolby-atmos-passthrough

Conversation

@raiden202

@raiden202 raiden202 commented Jul 4, 2026 •

Copy link
Copy Markdown

Summary

Makes DDP-Atmos (E-AC-3 + JOC) actually reach the AVR/soundbar as Dolby Atmos on the local Dolby Vision loopback route. Previously these tracks stream-copied bit-exact but AVFoundation classified them as plain E-AC-3 5.1, so Atmos never engaged. Device-verified end to end: an AVR reports "Dolby Atmos" for a streaming WEB-DL DDP-Atmos episode.

Five stacked defects had to be fixed; each was necessary, none sufficient alone:

  1. dec3 JOC signalling — the vendored FFmpeg 7.1 mp4 muxer writes dec3 without the ETSI TS 103 420 JOC extension (flag_ec3_extension_type_a + complexity_index_type_a), the field AVFoundation keys on for Atmos. It also emits a non-ETSI 5-reserved-bit substream layout where the spec has 3. ISOBoxSurgery now rewrites dec3 into the ETSI layout with the extension, gated on codecpar.profile == AV_PROFILE_EAC3_DDP_ATMOS. Ground truth: byte-identical to what FFmpeg 8.1 emits for the same stream (pinned in tests).
  2. Start from the master playlist — Apple grants premium-format claims (Atmos MAT output) at master-variant level; media-direct start never gets them.
  3. FRAME-RATE on the PQ variant — AVFoundation silently drops a VIDEO-RANGE=PQ variant with no FRAME-RATE (-1002 before the variant playlist is even fetched; isolated via AVAsset.variants).
  4. Main-tier CODECS — a faithful High-tier hvc1.2.4.H150.B0 is also variant-filtered; declaring L150 is accepted (declaration only feeds selection; bitstream untouched).
  5. Wait for the panel mode switch — tvOS 26.5 validates a variant's VIDEO-RANGE against the panel's current mode; creating the item mid-switch fails -11868. Two-stage settle wait before item creation.

Verification

Builds clean on SiloTV; ISOBoxSurgeryDec3Tests (7) pin the dec3 rewrite bit-for-bit. On-device: DV Profile 8 + E-AC-3 JOC through the loopback → AVR shows Dolby Atmos; DV picture unaffected.

Touches the DV loopback files #52 renames to LoopbackSegment* — I'll rebase onto that structure whenever #52 lands.

Authored with Claude Code.

DDP-Atmos (E-AC-3 + JOC) tracks stream-copy bit-exact through the
loopback, but presented as plain E-AC-3 5.1: the vendored FFmpeg 7.1
muxer records the dependent substream in dec3 (num_dep_sub, chan_loc)
yet never writes the ETSI TS 103 420 JOC extension
(flag_ec3_extension_type_a + complexity_index_type_a) — the field
AVFoundation keys on to classify a track as Dolby Atmos. FFmpeg gained
the extension write in a later release, which is why the identical
copy path works in engines shipping FFmpeg 8.x. Net effect today: no
Atmos over HDMI/eARC from any DDP-Atmos source.

The writer now detects the source condition at stream selection
(codecpar.profile == AV_PROFILE_EAC3_DDP_ATMOS) and writeInitSegment
patches the extension into the dec3 via ISOBoxSurgery, next to the
existing dvvC surgery. The extension is bit-packed after the substream
loop — before the alignment padding, not byte-appended — so the
payload is re-emitted through a small bit reader/writer, with ancestor
box sizes fixed the way injectDvvC does. complexity_index_type_a=16
(the standard streaming-Atmos object count; 7.1's parser does not
expose the true value). The surgery no-ops on non-JOC streams and on
already-extended dec3 boxes, so a future FFmpeg >= 8 bump degrades it
to a no-op automatically.

Covered by ISOBoxSurgeryDec3Tests with hand-computed bit vectors.
@coderabbitai

coderabbitai Bot commented Jul 4, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@raiden202, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 54 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8e8c4817-e281-4833-946f-d2c2b7064779

📥 Commits

Reviewing files that changed from the base of the PR and between d840145 and d214cdc.

📒 Files selected for processing (4)
  • iosApp/Tests/ISOBoxSurgeryDec3Tests.swift
  • iosApp/iosApp/Screens/Player/AVPlayerRoute/AVPlayerBackend.swift
  • iosApp/iosApp/Screens/Player/AVPlayerRoute/DVSegmentWriter.swift
  • iosApp/iosApp/Screens/Player/AVPlayerRoute/ISOBoxSurgery.swift
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@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: 3deee184a9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +3431 to +3433
if let fps = sessionSpec.sourceVideoFrameRate, fps > 0 {
inf += ",FRAME-RATE=\(String(format: "%.3f", fps))"
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Emit fallback FRAME-RATE when fps metadata is missing

For PQ/Dolby Vision loopback sessions where the server does not provide a parsable video frameRate, sourceVideoFrameRate is nil (ApplePlaybackRoutePlanner.loopbackSourceFrameRate and the PlayerViewModel equivalent both return nil in that case), so this conditional omits FRAME-RATE from the master variant. This commit now starts AVPlayer from master.m3u8, and the surrounding comments note that VIDEO-RANGE=PQ variants without FRAME-RATE are rejected before the media playlist is fetched; those files will therefore fall back/fail even though playback could use the same 24 fps default already used for display criteria.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in the latest push: FRAME-RATE is now always emitted on the master variant, defaulting to 23.976 (the same film cadence the display-criteria path uses) when the server provides no parsable frame rate.

raiden202 added 2 commits July 4, 2026 09:20
Media-direct start was a historical retreat from a master rejection,
but Apple grants premium format claims (Dolby Atmos MAT output for
EAC3-JOC) at master-variant level — media-direct start meant Atmos
could never engage regardless of sample-entry signalling. Three fixes
make the master surface acceptable:

1. Start from master.m3u8 (the multivariant manifest was already
   emitted for artifact inspection).
2. Emit RESOLUTION and FRAME-RATE in the stream-inf. FRAME-RATE is
   load-bearing: AVFoundation's variant filter silently drops a
   VIDEO-RANGE=PQ variant with no FRAME-RATE (isolated locally via
   AVAsset.variants against on-device artifacts: PQ without FRAME-RATE
   = zero variants = NSURLError -1002 before the variant playlist is
   ever fetched — the actual mechanism behind the historical master
   rejection).
3. Declare Main tier in the CODECS string ("hvc1.2.4.L150"), never
   High tier with constraint bytes: the variant filter also drops a
   faithful "hvc1.2.4.H150.B0" declaration. Declaration only feeds
   variant selection; the bitstream is untouched.

Device-verified end to end: master accepted, variant fetched, AVPlayer
owns the session, and with the dec3 JOC extension in place the AVR reports Dolby Atmos for a streaming WEB-DL DDP-Atmos episode.
tvOS 26.5 validates a variant's VIDEO-RANGE against the panel's current
mode synchronously, before fetching the init segment. Display criteria
were applied but the AVPlayerItem was created while the panel was still
mid-switch (isDisplayModeSwitchInProgress=1 at item-ready on every
measured session; the panel takes ~2.9 s to settle), so the
master-start path failed with -11868 (underlying -17223) and silently
dropped to the PlayerCore fallback. Two-stage settle wait: up to 1 s
for the switch to begin (the handshake starts asynchronously after
preferredDisplayCriteria is written), then up to 5 s for it to clear.
Media-direct start never tripped this because with no master there is
no variant validation — which is also why the retreat to media-direct
"worked" while quietly costing Atmos.
@raiden202 raiden202 closed this by deleting the head repository Jul 4, 2026
Quick104 added a commit that referenced this pull request Jul 5, 2026
DDP-Atmos (E-AC-3 + JOC) stream-copied bit-exact through the loopback
was classified by AVFoundation as plain E-AC-3 5.1, so Atmos never
engaged. Five stacked fixes, adapted from the retracted PR #64 after
validating each against FFmpeg sources and AetherEngine's shipping
Atmos path:

- Rewrite the init segment's dec3 box into the ETSI TS 102 366 layout
  and append the TS 103 420 JOC extension AVFoundation keys on. The
  vendored FFmpeg 7.1 muxer writes 5 reserved bits where the spec has
  3 and no extension (verified against n7.1 vs n8.1 mov_write_eac3_tag;
  output pinned byte-identical to FFmpeg 8.1's). Gated on copy-mode
  E-AC-3 with codecpar.profile == AV_PROFILE_EAC3_DDP_ATMOS.
- Start AVPlayer from the master playlist: Atmos MAT output is a
  master-variant-level grant. Kill switch back to media-direct:
  player.apple.loopback_master_start_enabled = NO.
- Emit RESOLUTION and always emit FRAME-RATE on the master variant
  (AVFoundation drops a PQ variant with no FRAME-RATE, -1002).
- Clamp the HEVC CODECS declaration to Main tier with no constraint
  suffix; a faithful High-tier string is variant-filtered.
- Extend the pre-item display-mode settle wait to fresh DV criteria
  applies: tvOS 26.5 validates the master's VIDEO-RANGE against the
  panel's current mode synchronously (-11868 mid-switch).

Also declares setSupportsMultichannelContent(true) on the playback
audio session (AetherEngine parity; PlayerCore already does).

7 new tests pin the dec3 rewrite bit-for-bit, including the FFmpeg 8.1
ground-truth vector for the on-device streaming-Atmos payload.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RdnjmQmP9WuJdCKa4yKt6L
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.

1 participant