Skip to content

Dolby Vision: clear active-area offsets that cannot describe the picture - #1391

Merged
GLinnik21 merged 2 commits into
mainfrom
fix/dv-active-area
Nov 14, 2026
Merged

GLinnik21 merged 2 commits into
mainfrom
fix/dv-active-area

Conversation

@GLinnik21

Copy link
Copy Markdown
Collaborator

Closes #1367

What

ff::packet_to_annexb now checks every HEVC Dolby Vision RPU it feeds against the picture it travels with: the raster the demuxer reports (codecpar width and height, the displayed raster, not the coded one). An RPU whose Level 5 active-area offsets are foreign to that picture has the four offsets zeroed (DoviRpu::crop, what dovi_tool --crop does) and is written again, every other field kept. The Profile 7 to 8.1 conversion's output goes through the same check.

A wrong keep cuts real picture; a wrong clear only shows the black bars the encode itself carries. So the rule (ff::dv_active_area_is_foreign) leans to clear:

  1. All-zero offsets, or an unknown raster: nothing to do.
  2. A raster that is not 16:9 (width * 9 != height * 16) was cropped and has no bars for an active area to describe, so any nonzero offsets are cleared. That covers 1920x802, 1920x1038, 1920x960, 3840x1600 and 4096x2160. This is what the area's shape alone cannot do: a 1.85:1 master (top=bottom=42) cropped to 1920x1038 leaves a plausible 2.01:1 and would still blank 84 rows; a 2.00:1 master (120 / 120) cropped to 1920x960 leaves 2.67:1.
  3. A 16:9 raster keeps offsets that can describe it (ff::dv_active_area_fits: l + r < W, t + b < H, and an area no wider than 3:1 (DV_AREA_WIDEST) and no narrower than 1:2 (DV_AREA_NARROWEST); no released picture is wider than 2.76:1, Ultra Panavision 70, or narrower than 9:16 portrait). A genuine 1920x1080 letterbox (138 / 139, 2.39:1) and a 3840x2160 master's own 276 / 277 are kept. Plus a per-stream latch: once one RPU of the stream has been cleared, every later RPU with nonzero offsets is cleared too. That catches a variable-aspect 4K master downscaled to 1080p, whose 1.90:1 scenes (69 / 70) look plausible alone.

The latch is ff::DvActiveArea { raster, foreign_seen }, owned by the demux loop beside the stream's other per-open values and passed &mut to packet_to_annexb in place of a bare raster. No new global state. The counter for the log is a static beside the neighbouring DV counters in ff.rs; ci/check-deps.sh accepts it, so there is no ledger line.

Any other RPU is fed as it reached the check, not re-serialised: the original bytes, or for a converted Profile 7 the conversion's output. That covers offsets that are kept, no L5 block, an RPU that does not parse (a Profile 7 one is still dropped, as before) and a raster the demuxer did not report.

The first three clears and every 5000th are logged: ff: DV RPU #n active area l=0 r=0 t=276 b=277 cannot describe 1920x802; cleared.

docs/dolby-vision.md gets a short subsection, 1a: the bug class, the rule and its three branches, what is fed, the firmware evidence and the limits.

Why

An LG C8 (webOS 4.4.3, Feed path) played a 1920x802 HEVC Dolby Vision Profile 8.1 file as a strip 249 rows high. The file is a re-encode of a 3840x2160 master with the letterbox bars cropped off, and its RPUs still carry the master's Level 5 offsets (dovi_tool info -s: L5 offsets: top=276, bottom=277, left=0, right=0). The TV's DV engine blanks everything outside that area: 802 - 553 = 249 rows. With Dolby Vision off the RPU NALs are still fed, but the pipeline is built without Dolby Vision, so nothing applies them and the HDR10 base layer plays whole. Firmware evidence: W18O libkadaptor.so.2.0.1, dolbyGenerateRegNLuts_IP at 0xe620c writes the L5 offsets into the DM registers Active_area_*.

Tests

In rust-modules/play-feed/src/ff_packet_framing_tests.rs, RPUs built in the test with the dolby_vision crate from dovi_tool's own fixtures (tests/fixtures/dovi-p7-*), not from new binary files:

  • the reporter's case, P8.1 with L5 t=276 b=277 at 1920x802: all four offsets come out 0, and the profile, header, mapping and the rest of the DM data are unchanged (compared with the offsets zeroed through the crate), L1 still there;
  • cropped rasters: 1920x1038 with 42 / 42, 1920x960 with 120 / 120, 3840x1600 with 100 / 100 and 4096x2160 with 138 / 139 are cleared, each with an area that passes dv_active_area_fits alone;
  • genuine letterboxes kept byte for byte: 1920x1080 with 138 / 139 and 3840x2160 with 276 / 277, both directly and through packet_to_annexb;
  • the latch: on 1920x1080 a 276 / 277 RPU is cleared, then a 69 / 70 RPU on the same state is cleared too, while 69 / 70 alone on a fresh state is byte-equal; also through the feed, one packet each;
  • no L5 block, unknown raster, an unparsable RPU and all-zero offsets on a very wide picture: untouched;
  • pillarbox, 1440x1080 with l=r=480: cleared;
  • the P7 to 8.1 path: a P7 RPU with foreign L5 comes out profile 8 and cleared; with no raster reported the offsets are carried through unchanged;
  • dv_active_area_fits bounds (2.76:1 and 3.0:1 kept, 3.1:1 cleared, 0.5625 and 0.5 kept, 0.44 cleared, t+b >= H and l+r >= W cleared) and a table for dv_active_area_is_foreign.

Red first, twice. First change: with the parameter threaded and the two functions stubbed to the old behaviour, make test-crate C=plx_play_feed read test result: FAILED. 310 passed; 5 failed, then ok. 315 passed with the implementation. Second change (the widened rule), with dv_active_area_is_foreign set to the old bounds-only logic: test result: FAILED. 316 passed; 3 failed (the cropped-raster, latch and rule-table tests; the genuine-4K keep passes on the old rule by design), then test result: ok. 319 passed; 0 failed with the new rule.

Gates on the committed tree: make test-crate C=plx_play_feed, make check-nodef, bash ci/check-deps.sh (check-deps: all gates green), python3 ci/check-module-layers.py (green). CI runs make check and the ARM build.

Not verified

No television has shown this fix. Our dev set (W19H) has no active_area string in its libkadaptor, so it cannot reproduce the strip, and the reporter's C8 is the only set the failure was seen on; the fix has not been run on a C8 or on any other set.

Also not covered or not measured:

  • Residual limit. A 16:9 picture whose first foreign offsets still leave a plausible area is kept, because nothing in the file says the offsets are not its own: a 1080p downscale of a 1.85:1 master that kept its 4K offsets (top=bottom=42, 1.93:1 left) passes and blanks 21 rows of picture at each edge.
  • The URI engine (the TV reads the file itself, nothing passes through this app) is not covered.
  • AV1 Profile 10 on the Feed path carries its RPU through av1_packet_to_tu, not packet_to_annexb, and is not checked.
  • The per-frame cost: every HEVC RPU on a Dolby Vision stream is now parsed once on the demux thread to read its L5 block (a converted Profile 7 stream parses a second time after the conversion), which is not measured on the ARM set.
  • The raster is read once when the stream is opened; a mid-stream raster change is not re-read.

🤖 Generated with Claude Code

GLinnik21 and others added 2 commits November 14, 2026 13:44
…cture

An encode cropped from a letterboxed master keeps the master's Level 5
active-area offsets in every RPU. The TV's Dolby Vision engine blanks
everything outside that area, so an LG C8 played a 1920x802 Profile 8.1
file (L5 top=276 bottom=277, left of a 3840x2160 master) as a strip 249
rows high; with Dolby Vision off the HDR10 base layer played whole.

packet_to_annexb now checks every HEVC RPU, the Profile 7 conversion's
output included, against the raster the demuxer reports. Offsets that
leave nothing, or an area wider than 3:1 or narrower than 1:2 (no
released picture is outside that range), can only have been authored for
another raster: they are zeroed through the dolby_vision crate and the
RPU is written again with every other field kept. An RPU whose offsets
fit, with no L5 block, that does not parse, or on a stream with no
reported raster goes out byte for byte as it came.

The URI engine, where the TV reads the file itself, is not covered, and
no television has shown the fix: our dev set's libkadaptor cannot
reproduce the strip.

Closes #1367

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… stream

Review of the first change found that an aspect-bounds-only rule keeps
foreign offsets in real cases: a 1.85:1 master (t=b=42) cropped to
1920x1038 leaves 2.01:1 and a 2.00:1 master (t=b=120) cropped to
1920x960 leaves 2.67:1, both plausible, both still blanking picture; and
a variable-aspect 4K master downscaled to 1080p has 1.90:1 scenes whose
69/70 look fine alone.

A wrong keep cuts real picture and a wrong clear only shows the black
bars the encode carries, so the rule now leans to clear. A raster that
is not 16:9 was cropped and has no bars for an active area to describe:
any nonzero offsets are cleared. On a 16:9 raster the offsets must still
be able to describe it, and once one RPU of the stream has been cleared
every later RPU with nonzero offsets is cleared too. The latch is the
demux loop's per-stream DvActiveArea, passed to packet_to_annexb, which
replaces the bare raster parameter; no new global.

The docs and rustdoc said t=138/b=139 on 1920x802 leaves 7.7:1; it
leaves 3.66:1, and 7.7:1 is the reporter's 276/277. Fixed, along with
the claims that the HDR10 path carries no RPU (it is fed, nothing
applies it) and that kept RPUs go out byte for byte (a converted
Profile 7's is the conversion's output). AV1 Profile 10 on the Feed
path is named as not covered.

Closes #1367

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@GLinnik21 GLinnik21 added bug Something isn't working playback Playback, the player and its controls labels Nov 14, 2026
@GLinnik21
GLinnik21 merged commit 8859e4b into main Nov 14, 2026
19 checks passed
@GLinnik21
GLinnik21 deleted the fix/dv-active-area branch November 14, 2026 11:18
@GLinnik21 GLinnik21 mentioned this pull request Nov 14, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working playback Playback, the player and its controls

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolution Bug

1 participant