Repository navigation
feat(dovi): dual-layer Profile 7 FEL decoder (not routed) - #769
Merged
superuser404notfound merged 14 commits intoOct 15, 2026
Merged
Conversation
libdovi is built panic=abort, so a single panic ends the host process. A CRC-valid but hostile Dolby Vision RPU could reach one on the native Profile 7 -> 8.1 conversion. Adds DoviRpuGuard: it checks the RPU CRC and pre-scans the payload for the inputs that make libdovi 3.4 panic or allocate without bound (linear interpolation pieces, polynomial/MMR mixes that break the writer, pivot and block counts the payload cannot hold, undefined display-management block lengths). The existing paths now check each RPU with it before parsing: the Profile 8.1 conversion in DoviRpuConverter (convertPacketToProfile81), the enhancement-layer-type probe, and the DolbyVisionRecordAudit RPU read. The mode 2 convert -> write pair on a parsed RPU is factored into DoviRpuConverter.convertedUnspec62 so the tests drive production's own entry point. A rejected RPU degrades the frame to the HDR10 base exactly as a libdovi failure already did (superuser404notfound#135). This hardens the existing native 8.1 conversion; it changes no routing and adds no Dolby Vision FEL code. The guard knows the paths listed above; it does not prove there are no others. Tests: DoviRpuGuardTests (crafted RPUs, verdicts, conversion round trip) and a DolbyVisionRecordAudit case. The CRC-valid mutation fuzz and the real-file guard test arrive with the composer, whose parameter walk they also exercise.
…or reordered streams Adds the SampleBufferRenderer pieces the dual-layer Dolby Vision path needs for pacing, as inert, opt-in additions: - felVideoLookaheadFrames (9) and mayEnqueueVideoFrame / setFELLookahead: a gate that runs BEFORE decode and refuses a compressed frame more than nine frame intervals ahead of the playback clock, so composed 4K frames (about 25 MB each) cannot pile up behind Apple's readiness gate alone. - displayOrderPTS: estimates a packet's display-order PTS in decode order from the largest amount a later packet fell below the highest PTS seen, so B-frame streams do not swing the cap with the position in the GOP. A gap larger than HEVC's 16-picture reorder ceiling is treated as a timestamp discontinuity and does not poison the learned lead. Nothing calls the gate yet and it is off unless setFELLookahead(enabled:) is called, so non-FEL pacing is unchanged. The decoder and the host wiring come in later PRs; the composer-side pool sizing that follows this cap (DoviFelComposer.outputPoolAllocationThreshold) is pinned in the composer PR. Tests: SampleBufferRendererLookaheadTests, SampleBufferRendererReorderDepthTests.
… routed) Adds the pieces that rebuild a Profile 7 FEL picture, with nothing selecting them yet. - DoviFelComposer (Metal): rebuilds the 12-bit picture from base layer, enhancement layer and RPU: reshaping curves (polynomial and MMR), inverse NLQ, MMR chroma, bilinear EL upsampling, ordered dither down to 10-bit, output in a pooled P010 buffer, composeAsync bounded at maxFramesInFlight. DoviMetalParams is the parameter ABI, DoviShaderSource the kernels. The output pool survives a seek flush (flush() trims idle buffers, releaseOutputPool() drops it on teardown): dropping it made post-seek frames allocate a second full pool beside the buffers the renderer still held, about +260 MB at 4K for ~0.6 s per seek; measured end to end with the decoder in the next PRs, peak 674 -> 500 MB over 12 seeks. - DoviDisplayMetadata: attaches the Profile 8.1 RPU as DolbyVisionRPUData plus DolbyCompatibilityID (a CFString: a CFNumber aborts the render server). Both keys are undocumented; they are defined in this one file and UndocumentedDolbyVisionKeysTests fails if either literal appears in another source file. - DoviRpuConverter.separateDualLayers splits one packet into base layer, enhancement-layer packet, converted RPU and composer parameters; convertPacketToProfile81 is now that walk with the EL dropped. The RPU attached to composed frames is converted with mode 2 (the composer has already applied the reshaping and added the residual, so the display side must not reshape again); DoviComposedFrameRpuTests pins this. Nothing calls the composer, so no behaviour changes for any source. Public API: none. Not in this PR: the dual-layer decoder, the routing flag and host wiring, the aetherctl tooling, and dolby-vision-fel.md (comments here cite its section numbers; the document arrives with the route PR). Tests: GPU curve sweep, edge cases and adversarial inputs, layout probe (the GPU reads each parameter sub-block back at the offset Swift wrote it), shader/ABI sync, dither, enhancement upsampler, FEL math, FEL and CRC-valid-mutation fuzzers, converter and guard tests, async compose, look-ahead pool sizing. The real-clip tests skip without DV_FEL_TESTS_DIR.
…e dual-layer decoder Four self-contained pieces the dual-layer Profile 7 decoder is built from, none of them wired to anything yet: - HEVCPictureOrderCount: the H.265 picture order count (§8.3.1) of one layer, read from the parameter sets and each picture's first slice segment header. No decoding. Anything it cannot follow (unknown PPS/SPS, truncated header, pictures before the first IRAP) answers nil rather than a guess. - DualLayerPictureAlignment: derives each layer's display slot from its POC and gives each enhancement-layer packet the presentation time of the base-layer picture in the same slot, so a stream whose enhancement layer has B-frames over a base layer without them pairs the right pictures. Falls back to access-unit pairing when a layer's POC is unavailable or the slots disagree by more than 16. - FrameSideDataRing: fixed-capacity (32) ring of per-frame side data keyed by PTS, looked up within +-300 ticks. - OrderedDelivery: hands composed frames across the VideoToolbox / Metal queue boundary in decode order. Also exposes A53SEIParser.unescapeRBSP and parseHVCCParameterSets (DoviRpuConverter+Probe) at module scope, which the POC reader and its test use. No behaviour change: nothing calls these types. Not in this PR: the decoder that uses them, the routing, the docs. Tests: DualLayerPictureAlignmentTests, FrameSideDataRingTests, OrderedDeliveryTests.
DualLayerVideoDecoder: the decoder half of the dual-layer route. It splits each packet into base layer, enhancement layer and RPU (DoviRpuConverter.separateDualLayers), decodes both layers on VideoToolbox through two HardwareVideoDecoder sessions, pairs them by HEVC picture order, composes with DoviFelComposer and delivers the frames in decode order with the Profile 8.1 RPU attached per frame. - Pairing: DualLayerPictureAlignment restamps each enhancement-layer packet with the time of the base picture in the same display slot, so an enhancement layer coded with B-frames over a base layer without them is no longer paired with a neighbouring frame's residual. A layer keeps access-unit pairing until its next sequence-opening IRAP after a seek. - Bounded memory: base-layer skew K = 3 frames, at most 10 waiting enhancement frames, output pool 15 plus a reserve of 3. A late or broken EL falls back to the base layer for that frame. - Seeks: a seek flushes every stage. A stale EL is never paired with a post-seek base layer and a stale BL is never delivered. The composer's output pool is kept across the flush instead of being dropped (it made the frames after a seek allocate a second pool beside the buffers the renderer still held): peak footprint on a 12-seek run of one test clip went from 674 MB to 500 MB. The pool is dropped on close. - HardwareVideoDecoder gains an opt-in no-copy block source and a parameter-set open for the enhancement layer; both are off for every existing caller. FelResidualMeasure (the AETHER_FEL_MEASURE diagnostic, off by default) is here because the decoder calls it. Nothing constructs the decoder yet: no host code selects it until the route PR, so no source plays differently after this one. Public API: none. Not in this PR: the capability gate, the preferDualLayerDolbyVision flag, host wiring, dolby-vision-fel.md. Tests: decoder, GPU slot wait, seek realignment (flush of both sessions and the composer, stale EL not composed, waiting BL dropped at the seek, seek during an in-flight composition), stream classification and packet balance, CPU model, output-pool-across-flush, real-clip tests (gated on DV_FEL_TESTS_DIR, skipped without), and a subtitle compositor test that the Dolby Vision attachments survive compositing.
This was referenced Oct 13, 2026
Merged
Merged
Merged
Merged
DoviFelComposer.swift, recordGPUTime: the "[DoviFelComposer] gpu X ms/frame over N frames" line repeats every 120 composed frames (about every 5 s at 24 fps) for the whole session. Moved from the default level to .verbose, so it reaches OSLog's debug level only and no longer the host handler or a default log stream. Kept at the default level, unchanged: the shader compilation error (once per process), the command buffer errors (real failures), the logOnce parse-time rejections (bounded to 64 distinct lines), and the one-shot non-zero linear_deadzone_threshold notice.
A GPU that keeps failing would otherwise log the same line for every frame. The decoder's per-second summary still counts each failed compose.
… Hz summary at verbose DualLayerVideoDecoder.swift (and its tests): - Prefix: the per-frame and summary lines said "[DualLayer]" while the lifecycle lines said "[DualLayerVideoDecoder]". All use the type name now, as "[HardwareVideoDecoder]" does. - Shouting tags to phrases, all still .verbose: "QUEUE BL" -> "queued base layer", "QUEUE EL" -> "queued enhancement layer", "DROP stale EL" -> "dropped stale enhancement layer", "PRUNED EL" -> "pruned enhancement layer", "BYPASS no-EL" -> "bypass, no enhancement layer arrived", "Bypass: ..." -> "bypass, <reason>: ...", "COMPOSE FAILED (BL arrived)" -> "compose failed (base layer arrived last)". - The 1 Hz "summary:" line goes from the default level to .verbose, except for a second whose counters include a compose failure, which stays at the default level so a failure is visible without enabling debug output. Healthy playback now writes nothing per second to the host handler. - "S1:" in two comments next to the missing-RPU bypass is dropped; it named nothing a maintainer can look up. - Tests: the summary tests read the line and its level through a DEBUG-only summarySinkForTesting, because .verbose never reaches EngineLog.handler; the per-frame-at-info test checks the new texts; a test pins that a summary with a compose failure goes out at the default level. Kept at the default level, unchanged: no composer, FEL/MEL detected, primary and secondary decoder opened, the two decoder open failures, and the one-time "reordered against the base layer" notice. Each fires once per open or per detection. Not changed: the verbose lines still build their text eagerly (String(format:) of the pts, queue counts) in the pairing paths, under the decoder lock, because EngineLog.emit takes a String and not an autoclosure.
…dual The composer floored the prediction at 0 before adding the enhancement-layer residual but did not cap it at the top. A prediction above full scale (seen in chroma MMR on saturated colours) plus a negative residual then stayed at vdr_max instead of landing below it. DoViBaker caps the polynomial and the MMR result at full scale before the residual as well. Against DoViBaker's integer pipeline on a real FEL RPU (fel_orig.bin from dovi_tool's test assets, 200,000 random base and enhancement samples), Cr differed by up to 199 12-bit codes on 1.2% of samples before this change and by at most 1 code after it, the same as Y and Cb. dovi_denormalize now clamps to [0, vdr_max]. Test: a prediction of 1.1 with a -100 EL code residual lands on 3996, through the luma table and through chroma MMR.
…DoViBaker does N3 asserted that a prediction above the VDR range keeps its overshoot until the residual is added (3979). DoViBaker caps the mapping result at 0xffff first (polynompialMapping and mmrMapping return uint16_t), which for N3's inputs is (65535 - 3192 + 8) >> 4 = 3896, the value the previous commit produces. The test's own header names DoViBaker as the oracle.
…ediction before the residual)
…diction before the residual)
superuser404notfound
marked this pull request as ready for review
October 15, 2026 09:08
superuser404notfound
pushed a commit
that referenced
this pull request
Oct 15, 2026
… races - The dual-layer decoder suites and DoviCpuModelTests block on VideoToolbox and Metal; they run under .offCooperativePoolOneLane like the other DoVi compute suites, so the one-thread CI step keeps its pool thread. - The packet balance check compared the process-wide PacketBalanceTracker against an exact baseline while other suites allocate packets; it now decodes 256 packets and bounds the drift, which a per-decode leak exceeds. - Issue220 readAtEOFDoesNotConnect counted requests, and under load the open's speculative tail fetch landed after the settle window. It now asserts that no request starts at the file size. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WJcXkGQrMiBPixVEFTSBJS
Owner
|
Merged, thank you @pkajaba. The lock reasoning around GitHub could not merge it because
Points for #770, where the decoder gets routed. None of them can bite before that:
On the two open questions from #768: the ±300-tick window is in 90 kHz on both sides via |
superuser404notfound
pushed a commit
that referenced
this pull request
Oct 15, 2026
The one-lane trait's wait counts against .timeLimit, and on the main CI run after #770 a one-line classifyStream test waited 71 s for the lane against a one-minute suite limit. The four DualLayer suites that took the trait in the #769 follow-up go to five minutes; the trait's doc says so. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WJcXkGQrMiBPixVEFTSBJS
1 task done
neurekadev
pushed a commit
to neurekadev/silo-aether-engine
that referenced
this pull request
Nov 3, 2026
Takes upstream main through fc6b412: 7.37.0, 7.38.0 and 7.38.1, plus the LillyPlayer used-by entry (superuser404notfound#804). Notable upstream changes for hosts: - LoadOptions.preferDualLayerDolbyVision routes Profile 7 FEL to the dual-layer decoder (superuser404notfound#769, superuser404notfound#770), which applies the enhancement layer. - objectAudioRendering covers DTS:X as well as TrueHD Atmos, and TrackInfo.isDTSX flags DTS:X tracks. LibTrueHD and LibDTSX sit behind the TrueHDObjectAudio and DTSXObjectAudio package traits, on by default. LibTrueHD moves to 2.3.1 and LibDTSX to 2.0.0 (LGPL). - Live sessions can rotate request headers without a rebuild (superuser404notfound#792), and a refused credential mid-session is typed and heals on renewal. - A software start holds the clock until its first frames are queued (superuser404notfound#800), and a software live join starts near the newest media (superuser404notfound#797). Conflicts resolved: - CHANGELOG: the fork's Unreleased entries stay under Unreleased; the live-playlist renewal entry (superuser404notfound#748) moves to upstream's 7.37.0 section. - SessionOptionCorrection.knownFields keeps the fork's httpRequestAuthorization beside upstream's preferDualLayerDolbyVision. - SoftwarePlaybackHost.play() takes upstream's stopped/failed guard first, then the fork's held end-of-media release (Silo-Server#15). seek() clears the fork's paused-frame gate and upstream's resident-range publication. - DocumentedConstantsTests keeps both the fork's authorized-resource deadline check and upstream's 30 s positioning budget check. - docs/api.md takes upstream's objectAudioRendering row, with its package trait note, and keeps the `ObjectAudioRendering` reference that PublicAPIDocumentationTests requires. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SmKM2DtjCuccTfuQwQo7DF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 5/10 of #702, stacked on #768. It targets
mainand carries the commits of PRs 1 to 4, so review only the top commit; the diff shrinks to it as the earlier PRs merge.Summary
The decoder half of the request in #702:
DualLayerVideoDecodersplits each packet into base layer, enhancement layer and RPU, decodes both layers on VideoToolbox, pairs them by picture order, composes with the #767 composer and delivers frames in decode order with the 8.1 RPU attached. Nothing constructs it yet, so no source plays differently after this PR.What's in it
DualLayerVideoDecoder: packet split, twoHardwareVideoDecodersessions, pairing, composition hand-off.onFatalDecodeError(and kept infatalDecodeError);decodethen refuses packets, instead of retrying the same sets on every keyframe and leaving a black screen with one log line per keyframe. The host wiring of the callback is in feat(dovi): route Profile 7 FEL to the dual-layer decoder behind preferDualLayerDolbyVision #770. Extradata of more than 23 bytes that is not an hvcC record (an Annex B parameter-set blob, say) now takes the in-band path instead of throwing out ofopen.close()closes the VideoToolbox sessions first, which drains the frames they still owe and which can still be holding or about to take pool buffers, and only then flushes the composer and releases its pool. The in-band session is installed under the decoder'slock, becausedecode,flushandcloseread it from other threads. That session does not enable VideoToolbox's per-frame HDR display metadata propagation: the dual-layer decoder attaches its own Dolby Vision RPU to every frame it delivers, and a second, possibly different attachment on a bypassed base-layer buffer would conflict.flush()critical section. The host feeds the demux thread's packets concurrently with a seek's flush and hands each packet the new epoch the moment it is published. Before, the twoHardwareVideoDecoders moved to it only when their ownflush()ran later in the same call, so a post-seek packet fed in that window passed the dual decoder's gate and was refused by a sub-decoder still on the old epoch: the post-seek keyframe was dropped and the picture was garbage until the next one.adoptFeedEpochmoves the epoch under a leafepochLock(held only for a read or write of the integer, neverlock, so it cannot nest against the VideoToolbox callbacks that wait on the owner's lock; the lock order is unchanged), andflushKeepingEpochthen drains without bumping it again. A pre-seek packet is still refused from that point on.maxBackwardRestamp = K - 1, so an EL restamped further back than the base layer waits for falls back to access-unit pairing instead of being lost.flushKeepsOutputPool.close()clears the latch.HardwareVideoDecoder.makeBlockBuffer(wrapping:size:)is the one place a packet's payload is wrapped in a CMBlockBuffer, so its cleanup-on-failure path is tested by calling it.HardwareVideoDecoder: an opt-in no-copy block source and a parameter-set open for the EL, both off for every existing caller.VideoDecoderTypes: two new error cases.FelResidualMeasure(AETHER_FEL_MEASURE, off by default, environment diagnostic, not API) because the decoder calls it.AETHER_FEL_MEASUREand the picture-order pairing.docs/architecture.mdentry forDualLayerVideoDecoder.How it was tested
swift testfiltered to every test file the stack adds or changes up to this PR (cumulative:git diff --name-only --diff-filter=AM origin/main HEAD -- Tests/AetherEngineTests, one suite per file): 321 tests in 31 suites pass on this commit alone. Real-clip tests skip withoutDV_FEL_TESTS_DIR.DualLayerSeekRealignmentTests: flush of both sessions and the composer, stale EL not composed, waiting BL dropped at the seek, per-frame layer pairing in either arrival order, seek during an in-flight composition.quiesceForTesting), not a sleep.DV_FEL_TESTS_DIR) skip without the clips; run them alone, not inside the full suite, where they starve timing-sensitive tests. The wall-clock tests (DoviComposeAsync,DualLayerGpuSlotWaitTests) can hit their 60 s limit under heavy load when run together with the real-file tests; each passes alone.swift build --build-testsandaetherctlbuild at this commit.What it does not do
flush()discards the last composed frames still in flight; separating "drain at EOF" from "discard on seek" touches the flush invariants and is left for a follow-up.OrderedDeliverybacklog has no cap of its own; it is limited indirectly by the demux thread's readiness gate.FEL stack for #702, merge in order: #765 → #766 → #767 → #768 → #769 → #770 → #771 → #772 → #773 → #774. Standalone read-ahead fixes: #775, #776.