Skip to content

Support CM v4.0 extension metadata levels 15-18 (rebase + C-FFI completion of #362) - #412

Closed
MeeeetRain wants to merge 2 commits into
quietvoid:mainfrom
MeeeetRain:dv2-level15-18-capi
Closed

Support CM v4.0 extension metadata levels 15-18 (rebase + C-FFI completion of #362)#412
MeeeetRain wants to merge 2 commits into
quietvoid:mainfrom
MeeeetRain:dv2-level15-18-capi

Conversation

@MeeeetRain

Copy link
Copy Markdown

Rebases and completes #362 (cc @quietvoid) onto current main.

Context

#362 implements the four DV2 / CM v4.0 extension metadata blocks (L15/L16/L17/L18) but has been dormant and was ~39 commits behind main, and the libdovi C-FFI mapping for the new blocks was left as // TODO stubs. This PR rebases the block implementations onto main, completes the C-FFI, and wires the new blocks into features added on main after #362 forked.

Changes

Blocks (L15-L18, struct definitions unchanged from #362):

  • Level15 — Dolby Image Engine (Standard mode): confidence / precision_rendering_strength / d_local_contrast / d_brightness / d_saturation / d_contrast (+ *_no_pr variants). 11 B / 88 bits.
  • Level16 — Reference mode Image Engine: variable length, revision + count + Level16Params[].
  • Level17 — up-mapping metadata (10 B / 80 bits). Kept for forward compatibility; DM ignores it (Metadata Spec v1.5.1 removed the L17 grammar, superseded by L18).
  • Level18 — Precision Black / creative environment: 4× 12-bit PQ luminance. 7 B / 56 bits.

Wiring:

  • cmv40.rs: ALLOWED_BLOCK_LEVELS + parse dispatch.
  • blocks/mod.rs: enum variants + trait match arms.
  • vdr_dm_data.rs: replace_metadata_block path.
  • commands/export.rs + src/dovi/exporter.rs: --levels level15/16/17/18 CLI option + CSV/JSON exporter arms (new on main).

libdovi C-FFI completion (c_structs/extension_metadata.rs):

  • Filled the four // TODO stubs so L15-L18 are exposed through the C ABI (DmData struct fields + set_blocks + drop + Default), unblocking FFmpeg / Kodi / CoreELEC consumers. L16 (variable length) is boxed whole; its Vec<Level16Params> is owned by Rust and round-trips correctly, though the nested params are not yet individually exposed across the C boundary (same limitation as the existing L8/L10 block lists).

L11 Authentic Motion (separate commit):

  • The reserved_byte3 == 0 validation (left after dovi/level11: improve byte1 parsing and remove byte2 validation #384 relaxed byte 2) rejected every DV2 stream carrying L11 motion metadata. Per Metadata Spec v1.5.1 / HDMI Transmission Spec v5.1.1 PB[13], byte 3 carries frc_strength[3:0] + frc_type[4]. Relaxed the check and added frc_strength() / frc_type() accessors.

Validation

Verified every field against the Dolby Vision TV SDK v6.0 official test vectors (MFV-L15/L16/L18, CST-DV2, Profile 5 HEVC VES) cross-referenced with Metadata Spec v1.5.1:

  • L15 and L16 round-trip byte-identically.
  • All four blocks parse to spec-correct values (e.g. L18 max_preserved_luminance_pq = 4095, L16 count == params.len(), L15/L18 reserved == 0).
  • --levels level15/16/17/18 export (CSV + JSON) verified against the official samples.
  • Full upstream suite passes: 110 tests, 0 failures. cargo fmt clean; no new clippy warnings. cargo build --features capi succeeds.

Notes

MeeeetRain and others added 2 commits August 6, 2026 10:49
Rebases and completes quietvoid#362 on top of current main:

- Add ExtMetadataBlockLevel15 (Dolby Image Engine, Standard mode):
  confidence / precision_rendering_strength / d_local_contrast /
  d_brightness / d_saturation / d_contrast (+ *_no_pr variants).
  11 bytes / 88 bits.
- Add ExtMetadataBlockLevel16 (Reference mode Image Engine): variable
  length, revision + count + Level16Params[] (contrast_target /
  precision_rendering_strength / d_local_contrast / max_d_brightness /
  max_d_saturation_plus_one).
- Add ExtMetadataBlockLevel17 (up-mapping metadata): 10 bytes / 80 bits.
  Kept for forward compatibility; DM ignores it (Metadata Spec v1.5.1
  removed the L17 grammar, superseded by L18).
- Add ExtMetadataBlockLevel18 (Precision Black / creative environment):
  4x 12-bit PQ luminance (surround / min_preserved / adaptation /
  max_preserved) + revision. 7 bytes / 56 bits.
- Wire dispatch in cmv40.rs (ALLOWED_BLOCK_LEVELS + parse arms),
  ExtMetadataBlock enum + trait match arms, vdr_dm_data replace path,
  and the CSV/JSON exporter.
- Complete the libdovi C-FFI mapping (c_structs/extension_metadata.rs)
  that was left as // TODO stubs, so FFmpeg/Kodi/CoreELEC can read the
  new blocks through the C ABI.
- Add a round-trip test against a real DV2 sample (l15_to_l18.bin).
The third byte of the Level 11 block is not reserved in DV2: per
Dolby Vision Metadata Spec v1.5.1 and HDMI Transmission Spec v5.1.1
(PB[13]), bits [3:0] carry frc_strength (0..=15) and bit 4 carries
frc_type (0 = De-judder, 1 = Smoothness), used by the DV2 Max
Authentic Motion feature.

The existing reserved_byte3 == 0 validation (left in place after quietvoid#384
relaxed byte 2) rejected every DV2 stream carrying L11 motion metadata
(e.g. the official MFV-L18 and CST-DV2 test vectors, where byte3 = 8).

- Drop the byte3 == 0 ensure (byte is still stored for round-trip).
- Add frc_strength() and frc_type() accessors documenting the layout.
MeeeetRain added a commit to MeeeetRain/MediaInfoLib that referenced this pull request Aug 6, 2026
PR MediaArea#2392 leaves L15/L16 as Skip_BS stubs and L18 is missing entirely.
This implements proper bitstream parsing for the three DV2 (CMv4.0)
blocks. Field layouts cross-validated against three independent sources:
Dolby Vision Metadata Spec v1.5.1, quietvoid/dovi_tool (PR
quietvoid/dovi_tool#412), and the official Dolby Vision TV SDK v6.0
test vectors (MFV-L15/L16/L18, CST-DV2; Profile 5 HEVC VES).

This C++ impl and the Rust dovi_tool produce bit-identical values on
the official samples, e.g. CST-DV2 frame 0: L15 confidence=255,
L16 contrast_target=64, L18 adaptation_luminance_PQ=1741.

L17 intentionally left as Skip_BS (Spec v1.5.1 removed its grammar,
superseded by L18). Also fixes a missing break in case 17.

Values surface in Trace/Details output; Fill() wiring is future work.
MeeeetRain added a commit to MeeeetRain/MediaInfoLib that referenced this pull request Aug 6, 2026
Adds Dolby Vision RPU (Reference Processing Unit, NAL type 62) parsing
for HEVC streams, including the DV2 / CMv4.0 extension metadata blocks
L15, L16 and L18 that are not yet handled anywhere.

## Provenance

This is a focused slice of cjee21's PR MediaArea#2392 ('Dolby Vision: Parse RPU
in HEVC and AV1'), restricted to the HEVC path, plus L15/L16/L18 field
parsing that MediaArea#2392 leaves as Skip_BS stubs (L15, L16) or misses (L18).

The AV1/EMDF portion of MediaArea#2392 is intentionally omitted here, per
@JeromeMartinez's request in MediaArea#2392 to defer AV1 until a File_T35.cpp
parser exists. Once MediaArea#2392 lands, this PR should be rebased onto it and
reduced to just the L15/L16/L18 delta.

## Files (5, source only — no CI/CMake/project changes)

- File__Analyze.h / File__Analyze_MinimizeSize.h: DV_RPU struct + parser decl
- File__Analyze_Streams.cpp: Get_DolbyVision_ReferenceProcessingUnit() —
  the RPU parser, including the CMv4.0 ext_metadata_block switch with:
    - L15 (11 B): confidence, precision_rendering_strength, d_local_contrast,
      d_brightness, d_saturation_plus_one, d_contrast_plus_one,
      {confidence,d_brightness,d_saturation,d_contrast}_no_pr,
      revision, reserved
    - L16 (variable): revision, count, count x Level16Params
    - L18 (7 B): surround/min/adaptation/max_preserved_luminance_PQ,
      revision, reserved
  (L17 stays Skip_BS: Spec v1.5.1 removed its grammar, superseded by L18.)
- File_Hevc.cpp / File_Hevc.h: HEVC NAL type 62 dispatch + member

## Validation — three independent sources agree

Field layouts cross-validated against Dolby Vision Metadata Spec v1.5.1,
quietvoid/dovi_tool (PR quietvoid/dovi_tool#412), and the official
Dolby Vision TV SDK v6.0 test vectors (MFV-L15/L16/L18, CST-DV2).
This C++ impl and the Rust dovi_tool produce bit-identical values, e.g.
CST-DV2 frame 0: L15 confidence=255, L16 contrast_target=64,
L18 adaptation_luminance_PQ=1741.

Built on macOS arm64 (MEDIAINFO_HEVC=ON). Values surface in Trace output;
Fill() wiring is future work.

cc @cjee21 @JeromeMartinez
MeeeetRain added a commit to MeeeetRain/MediaInfoLib that referenced this pull request Aug 6, 2026
Adds Dolby Vision RPU (Reference Processing Unit, NAL type 62) parsing
for HEVC streams, including the DV2 / CMv4.0 extension metadata blocks
L15, L16 and L18 that are not yet handled anywhere.

## Provenance

A focused slice of cjee21's PR MediaArea#2392 ('Dolby Vision: Parse RPU in HEVC
and AV1'), restricted to the HEVC path, plus L15/L16/L18 field parsing
that MediaArea#2392 leaves as Skip_BS stubs (L15, L16) or misses (L18).

The AV1/EMDF portion of MediaArea#2392 is intentionally omitted, per
@JeromeMartinez's request in MediaArea#2392 to defer AV1 until a File_T35.cpp
parser exists. Once MediaArea#2392 lands, this PR should be rebased onto it and
reduced to just the L15/L16/L18 delta.

## Files (5, source only — no CI/CMake/project changes)

- File__Analyze.h / File__Analyze_MinimizeSize.h: DV_RPU struct + parser decl
- File__Analyze_Streams.cpp: Get_DolbyVision_ReferenceProcessingUnit() —
  the RPU parser, with the CMv4.0 ext_metadata_block switch handling:
    - L15 (11 B): confidence, precision_rendering_strength, d_local_contrast,
      d_brightness, d_saturation_plus_one, d_contrast_plus_one,
      {confidence,d_brightness,d_saturation,d_contrast}_no_pr,
      revision, reserved
    - L16 (variable): revision, count, count x Level16Params
    - L18 (7 B): surround/min/adaptation/max_preserved_luminance_PQ,
      revision, reserved
  (L17 stays Skip_BS: Spec v1.5.1 removed its grammar, superseded by L18.
  Each new case has its own break; the existing case 17 already had one.)
- File_Hevc.cpp / File_Hevc.h: HEVC NAL type 62 dispatch + member

Also fixes signed/unsigned comparison warnings (C4018) in the imported
DV code so it passes the current -warnaserror CI standard.

## Validation — three independent sources agree

Field layouts cross-validated against Dolby Vision Metadata Spec v1.5.1,
quietvoid/dovi_tool (PR quietvoid/dovi_tool#412), and the official
Dolby Vision TV SDK v6.0 test vectors (MFV-L15/L16/L18, CST-DV2).
This C++ impl and the Rust dovi_tool produce bit-identical values, e.g.
CST-DV2 frame 0: L15 confidence=255, L16 contrast_target=64,
L18 adaptation_luminance_PQ=1741.

cc @cjee21 @JeromeMartinez
@quietvoid

Copy link
Copy Markdown
Owner

What are you doing? There is already #362.

@quietvoid quietvoid closed this Aug 6, 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