Skip to content

feat(dovi): join a split enhancement layer, add the layer probe and passthrough digest behind the dual-layer trait - #969

Merged
superuser404notfound merged 5 commits into
superuser404notfound:mainfrom
pkajaba:pr/fel-inputs-tools
Nov 3, 2026
Merged

superuser404notfound merged 5 commits into
superuser404notfound:mainfrom
pkajaba:pr/fel-inputs-tools

Conversation

@pkajaba

@pkajaba pkajaba commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Three Profile 7 FEL additions that all sit behind the DualLayerDolbyVision trait, which is off by default:

  • Dual-track input. A title whose enhancement layer is on its own track (two-track MKV or MP4) or its own PID (two-PID M2TS) is joined into the dual-layer composer. The 8.1 fold pairs enhancement units and RPUs with the base frame by time in microseconds (2 ms tolerance). The join queues are bounded by time, and a lost unit costs at most one GOP of wrong pairs.
  • Enhancement-layer probe, composer prewarm and tools. AetherEngine.probeDolbyVisionEnhancementLayer reports FEL or MEL off the first RPU. prewarmDualLayerDolbyVision() compiles the composer shaders before the first frame. aetherctl gains eltype, elsurvey and elframe. Adapted from TheFireKahuna's fork, with fixes on top.
  • Display-metadata passthrough digest. A per-frame digest of the RPU attached at hand-off against the source RPU, switched on with AETHER_DM_DIGEST, plus aetherctl dmpass.

One behaviour change is not behind the trait: a two-track MKV or MP4 is now detected and its RPUs are folded into the base layer (Profile 8.1), where it used to play the base layer alone. The CHANGELOG says so.

The Annex B chroma upsampling is not in this PR. It builds on the integer EL path from the compose-queue work and is in #970 and is not part of this PR.

Tested on Mac

  • swift build passes with and without the trait.
  • Filtered suites with the trait on: 74 tests in 9 suites pass (layer join, dual-track files, separate layers, Blu-ray fold, EL probe, DM digest, FEL math, shader sync). The dual-track file tests skip without their fixtures.
  • Fixture-free tests (in-memory format context) for two-track detection, the extradata swap and restore, and the pairing hold across a whole chunk; 51 + 34 tests in the focused run pass.
  • Dual-track input against the single-track reference: 0 differing frames on five layouts and on a real P7 FEL segment, full plays and seeks.
  • CI runs the full suite, the strict run and the tvOS and iOS builds.

Still needs Apple TV

  • Dual-track (two-track MKV) and two-PID inputs played on the Apple TV, picture and drops against the single-track remux.
  • The 8.1 fold on a chunk-interleaved two-track MP4 (every picture keeps its RPU).
  • A real disc with a separate enhancement PID.
  • AETHER_DM_DIGEST on a TV run, to confirm the hand-off check costs nothing measurable.

… track or pid

A Profile 7 title can carry its enhancement layer on a separate track (two-track MKV or MP4) or a
separate PID (two-PID M2TS) instead of inside the base layer's access units. The demuxer now joins
such a layer into the dual-layer composer.

- The 8.1 fold pairs each enhancement unit and its RPU with the base frame by time in
  microseconds, with a 2 ms tolerance.
- The join queues are bounded by time (2 s locked, 4 s searching, 6 s for the enhancement layer),
  so a missing or late layer cannot grow memory.
- NAL length sizes the join cannot parse are refused, and the title plays as base
  layer only.
- A lost unit costs at most one GOP of wrong pairs: the join waits a bounded look-ahead for the
  next base IRAP and repairs the pairing from there.

Tested on the Mac: 0 differing frames against the single-track reference on five layouts and on a
real P7 FEL segment, full plays and seeks. Still needs a real disc with a separate enhancement PID
and an Apple TV run.

Source: fel/dual-track-input @ 1284d691
Each frame handed to the decoder now gets a digest of the RPU attached at
hand-off compared with the source RPU: every display-management level and
the CM version (v2.9 or v4.0) are read from both and must match. For the
dual-layer mode-2 path, header fields and mapping fields that mode 2 is
expected to rewrite are checked against an allow-list, and any other
difference fails the frame. The matrix is compared by normalised category
so equivalent signalling does not count as a change.

The digest exists only with the DualLayerDolbyVision trait; with the trait
off nothing is built, and with it on but the digest not enabled the hand-off
costs one check per frame. It is switched on with AETHER_DM_DIGEST (1, log or
hex), optionally appending JSON lines to AETHER_DM_DIGEST_FILE.

aetherctl gains a dmpass command that feeds N packets of a clip through the
decoder, prints a per-frame result and exits 0 only when every frame passes;
--out writes both readings and both RPU byte strings per frame.

Source: fel/dm-passthrough @ 0b9641dc
…ltype/elsurvey/elframe

probeDolbyVisionEnhancementLayer reads whether a source's enhancement layer is FEL or MEL off the first RPU, and AetherEngine.prewarmDualLayerDolbyVision() compiles the composer shaders ahead of the first dual-layer frame, off the cooperative pool. aetherctl gains three commands: eltype classifies many sources as FEL or MEL in parallel, elsurvey measures what a FEL title's enhancement layer does to the picture (its per-code inverse NLQ is pinned to the composer by a test), and elframe dumps one frame composed with and without its residual at full precision. A frame whose RPU disables the residual is dumped without it in both pictures and reports residualDisabledByRpu. docs/api.md, docs/cli.md and docs/dolby-vision-fel.md describe them.

The probe, the prewarm and the three commands come from FireKahuna's fork (TheFireKahuna/AetherEngine); they were adapted to this composer, with fixes on top for the Sendable row emitter, the prewarm queue and the elframe dump.

Source: fork-picks/fel-tools @ 9486840c
… counts and trait notes

Adds the missing changelog entry for the enhancement-layer probe, the prewarm and the new aetherctl commands, corrects the subcommand count and the eltype trait note, lists the new diagnostics in the SPI bullet, says the probe handles single-track sources only, and words the route log and a test comment without private paths.

Source: pr/fel-inputs-tools review nits
@pkajaba
pkajaba marked this pull request as ready for review November 3, 2026 09:39

@quint-aether quint-aether 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.

Automated review

Status: 🟠 Needs changes. Real issues to fix before merge.

The PR joins a Profile 7 enhancement layer that sits on its own PID or track into the single-track unit the dual-layer composer reads. It also folds the enhancement layer's RPUs into the base layer for two-track Matroska / MP4 files (8.1 path, not behind the trait), and adds an el_type probe, a shader prewarm and a display-metadata digest. The direction is right. The join is done in the demuxer, gated on the route decision and undone when the route is not taken, and the trait-only files stay behind #if DualLayerDolbyVision.

Findings

  • Should fix: The new 8.1 fold for two-track MP4 still releases a base picture without its RPU once more than 8 are held. This PR's own join notes say libavformat's mov reader hands out each track in chunks of up to a second. In a chunk-interleaved MP4 (MP4Box defaults to 0.5 s, so 12 pictures at 23.976), the pictures past the eighth go out with no Dolby Vision metadata. (Sources/AetherEngine/Demuxer/Demuxer.swift:566)
  • Should fix: The change outside the trait (two-track detection in SeparateDolbyVisionLayers.detectTracks, plus the demuxer's enable/disable round trip that rewrites and restores the base extradata) only has tests that need fixtures which are not checked in. CI never runs that path. (Sources/AetherEngine/Disc/SeparateDolbyVisionLayers.swift:39)
  • Nit: The feltest section of docs/cli.md now says it "does not need" the trait and, in the same sentence, that it exits 64 without it. (docs/cli.md:521)
  • Nit: "sixteen units" in docs/dolby-vision-fel.md quotes DolbyVisionLayerJoin.agreeingRunForRepair without a pin in DocumentedConstantsTests, unlike the neighbouring "16 slots" bound. (docs/dolby-vision-fel.md:329)

Checklist: CHANGELOG yes, docs yes, tests partly (the join logic and unit bytes are covered; detection and the demuxer wiring are not), traits both ways yes

Needs a device run: On Apple TV: two-track MKV and two-PID inputs on the dual-layer route against their single-track remux (picture and drops), a real disc with a separate enhancement PID, and the 8.1 fold on a chunk-interleaved two-track MP4. Whether AETHER_DM_DIGEST costs anything measurable on the TV also needs a device.

Thanks for a substantial and carefully documented piece of work.

Automated review by Quint (Claude) of fe73203. It reads the code, it does not build or run it; a maintainer reviews and merges.

/// Base-layer packets waiting for the enhancement-layer unit with their PTS, and RPUs that came before their
/// picture. The enhancement unit usually follows its base unit, sometimes a picture or two later.
private var doviPairing = DolbyVisionLayerPairing<UnsafeMutablePointer<AVPacket>>()
private var doviPairing = DolbyVisionLayerPairing<UnsafeMutablePointer<AVPacket>>(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The fold now also serves two-track Matroska / MP4 files, which is the behaviour change outside the trait. But DolbyVisionLayerPairing still releases the oldest base picture without an RPU as soon as more than holdLimit (8) wait, and drops early RPUs past 16. That bound was sized for a Blu-ray transport stream, where the enhancement unit follows a picture or two behind.

DolbyVisionLayerJoin.queueTimeLimitMicros documents why that does not hold for MP4: libavformat's mov reader hands out each track in chunks of up to a second. Take an MP4 interleaved at 0.5 s (MP4Box's default), so 12 pictures at 23.976, or one muxed in 1 s chunks. Each chunk has 4 to 16 base pictures with no Dolby Vision metadata, and the RPUs that arrive later are kept as early RPUs and then evicted. If the enhancement chunk comes first, the first 8 RPUs are evicted instead.

foldsWithoutTheJoin would only catch this if its dual.mp4 fixture were chunk-interleaved; an ffmpeg-muxed file interleaves sample by sample. Suggested fix: for .track carriage, give the pairing the same time bound the join uses (with the count as a memory backstop), and add a chunk-interleaved MP4 to the fixture set.

/// One HEVC track declaring the enhancement layer only, one declaring the base layer, the enhancement layer no
/// larger than the base layer. Anything ambiguous (several candidates) or unlinked is left alone: a file with two
/// unrelated HEVC video tracks is not a dual-layer source.
static func detectTracks(_ ctx: UnsafeMutablePointer<AVFormatContext>) -> SeparateDolbyVisionLayers? {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This detection now runs in every build, trait or not, and changes what a two-track MKV / MP4 plays. Neither it nor the demuxer wiring has a test CI runs. DolbyVisionDualTrackFilesTests skips without DV_FEL_DUAL_TRACK_DIR, and SeparateDolbyVisionLayersTests covers only the byte helpers.

Two tests could run without a device or media:

  • detectTracks on a context built with avformat_alloc_context + av_find_input_format("matroska") + two HEVC streams carrying AV_PKT_DATA_DOVI_CONF. Cover the accepted pair, a larger enhancement layer, two base candidates, and a non-Matroska/MP4 format.
  • enableDolbyVisionEnhancementLayerJoin / disableDolbyVisionEnhancementLayerJoin restoring the base layer's original extradata byte for byte. This is what keeps the 8.1 path unchanged when the load does not take the route.

Comment thread docs/cli.md Outdated
## feltest

Needs the `DualLayerDolbyVision` trait; without it the subcommand exits 64 and says so. Runs the Dolby Vision Profile 7 FEL dual-layer pipeline over a real clip: demuxes, splits each packet into the base layer, the enhancement layer (typically 1080p) and the RPU, decodes both layers in hardware `VTDecompressionSession`s, composes each frame with `DoviFelComposer` on Metal, and audits the output twice. The pixel audit reports mean and standard deviation of Y / Cb / Cr, so a black picture or collapsed chroma fails. The metadata audit checks that every delivered frame carries a `DolbyVisionRPUData` attachment, and warns (without failing) when the payload never changes, since a static-metadata clip is valid. The verdict also requires at least one frame the composer actually reconstructed: a bypassed frame comes out as its base layer and counts as output but not as composed. Exit codes: `0` verified, `1` probe error, `2` no frames output, `3` chroma collapsed to a flat 64, `4` frames emitted without per-frame Dolby Vision metadata, `5` no frame was composed. See [dolby-vision-fel.md](dolby-vision-fel.md).
Does not need the `DualLayerDolbyVision` trait; without it the subcommand exits 64 and says so. Runs the Dolby Vision Profile 7 FEL dual-layer pipeline over a real clip: demuxes, splits each packet into the base layer, the enhancement layer (typically 1080p) and the RPU, decodes both layers in hardware `VTDecompressionSession`s, composes each frame with `DoviFelComposer` on Metal, and audits the output twice. The pixel audit reports mean and standard deviation of Y / Cb / Cr, so a black picture or collapsed chroma fails. The metadata audit checks that every delivered frame carries a `DolbyVisionRPUData` attachment, and warns (without failing) when the payload never changes, since a static-metadata clip is valid. The verdict also requires at least one frame the composer actually reconstructed: a bypassed frame comes out as its base layer and counts as output but not as composed. Exit codes: `0` verified, `1` probe error, `2` no frames output, `3` chroma collapsed to a flat 64, `4` frames emitted without per-frame Dolby Vision metadata, `5` no frame was composed. See [dolby-vision-fel.md](dolby-vision-fel.md).

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit: this sentence now reads "Does not need the DualLayerDolbyVision trait; without it the subcommand exits 64", which contradicts itself. feltest still needs the trait. The edit looks like it was meant for the new eltype section; please restore "Needs" here.

Comment thread docs/dolby-vision-fel.md
demuxer joins the two (`Demuxer.enableDolbyVisionEnhancementLayerJoin`, `DolbyVisionLayerJoin`) into the unit a
single-track remux carries: the n-th base access unit and the n-th enhancement access unit, each layer in its own
decode order, anchored at an IRAP the layers share (after a seek, units before it are retired). A missing or extra
enhancement unit is repaired by presentation time once sixteen units agreed; a source whose layers never share an

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit: "once sixteen units agreed" quotes DolbyVisionLayerJoin.agreeingRunForRepair. The neighbouring "more than 16 slots off its unit" bound is pinned in DocumentedConstantsTests (testPictureOrderPairingBoundMatchesDocumentation). A matching pin (writing the number as 16 makes it easy to assert) would keep the doc from drifting if the constant changes.

…d, and test track detection without fixtures

The 8.1 fold released a base picture without its RPU once more than 8 were held, so a chunk-interleaved MP4 (up to a second per track chunk) lost the metadata of every picture past the eighth. The hold is now bounded by 128 pictures or a 2 s span. Adds fixture-free tests for the chunk case, the span release, two-track detection, the Profile 7 declaration, framing and the extradata swap and restore, pins the 16-unit repair run in the documented constants, and restores the feltest trait note.

Source: pr/fel-inputs-tools review round 1
@pkajaba

pkajaba commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Pushed 12d0f99 for the automated review: the two-track fold now holds a whole chunk of base pictures (128 pictures or a 2 s span, was 8), with fixture-free tests for the chunk case, track detection and the extradata swap; the feltest trait note is restored and the 16-unit repair run is pinned in DocumentedConstantsTests.

@quint-aether quint-aether 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.

Automated review

Status: 🟢 Clean. Nothing left to fix, ready for a maintainer.

I re-checked the PR at 12d0f99. It joins a split Profile 7 enhancement layer (its own track or PID) for the dual-layer composer, folds the enhancement layer's RPUs into the base layer for two-track MKV / MP4, and adds the el_type probe, the shader prewarm and the display-metadata digest. The direction is still right, and every finding from the last review is fixed.

Findings

  • Fixed: the fold now holds 128 pictures or 2 s of base pictures (it held 8), so a chunk-interleaved MP4 keeps every RPU. chunkInterleavedPairsAll and spanReleasesUnpaired cover this.
  • Fixed: SeparateDolbyVisionTrackDetectionTests runs without fixtures. It covers two-track detection (accepted pair, either track order, two bases, two enhancement layers, an enhancement layer larger than the base, a non-P7 base, mpegts), the framing and join gate, and the extradata swap and restore.
  • Fixed: the feltest trait note in docs/cli.md is restored, and agreeingRunForRepair is now pinned in DocumentedConstantsTests.

No new findings.

Checklist: CHANGELOG yes, docs yes, tests yes, traits both ways yes

Needs a device run: On Apple TV: two-track MKV and two-PID inputs on the dual-layer route, compared with their single-track remux (picture and drops). Also a real disc with a separate enhancement PID, the 8.1 fold on a chunk-interleaved two-track MP4, and whether AETHER_DM_DIGEST costs anything measurable. One more thing to watch: Blu-ray PIDs share the pairing bound, which grew from 8 pictures to 2 s. When an enhancement unit is missing, video packets can now lag audio and subtitles by up to 2 s in the demuxer's output. A disc with a gap in its enhancement layer would show whether that matters.

Thanks for the quick and thorough follow-up.

Automated review by Quint (Claude) of 12d0f99. It reads the code, it does not build or run it; a maintainer reviews and merges.

superuser404notfound pushed a commit that referenced this pull request Nov 3, 2026
…969)

The fold now waits up to 128 pictures or 2 s for a base picture's RPU (was 8),
Blu-ray PIDs included; the entry said nothing about it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SeT6NgupsgTSme7g6RFnE5
@superuser404notfound
superuser404notfound merged commit 84eaeb1 into superuser404notfound:main Nov 3, 2026
6 checks passed
@superuser404notfound

Copy link
Copy Markdown
Owner

Thanks, merged into main as 84eaeb1a together with a small follow-up, 9b43ec02. Nothing is released yet.

Before the merge, the full suite was green on top of main, both with and without DualLayerDolbyVision (XCTest 828 / 830, Swift Testing 5606 / 5933). The standalone CI scripts were green too.

The follow-up only adds a sentence to the CHANGELOG entry. The longer hold in DolbyVisionLayerPairing (128 pictures or 2 s, was 8) is not behind the trait, so it applies to the Blu-ray PID fold as well. When a source's enhancement layer is missing or broken, its video now comes out up to 2 s behind the other streams. That is fine for the chunk case, it is just worth stating.

One request for the Apple TV round: please play the trait-off case first. A two-track MKV or MP4 now plays as 8.1, where it used to play the base layer alone. That is the only part of this PR that reaches hosts which never set the trait, so it matters most to verify.

@superuser404notfound

Copy link
Copy Markdown
Owner

Released in 7.56.0 (76ad51a7).

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