Skip to content

feat(interop): implement ABI 1.4 encoder telemetry, encode record and motion block size - #250

Merged
lusoris merged 7 commits into
masterfrom
feat/interop-abi-1.4
Oct 9, 2026
Merged

lusoris merged 7 commits into
masterfrom
feat/interop-abi-1.4

Conversation

@lusoris

@lusoris lusoris commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

What & why

This implements interop ABI 1.4 exactly as specified in ADR-0174 and ADR-0175 (#245), so VMAFx can re-pin before its 1.0.0-rc.4 (vidiko/vmafx#2411). The change is append-only: PELORUS_ABI_MINOR goes 3 → 4, and no 1.3 field or bit moves. Closes #218, #220 and #221; part of #86 and #81, whose adapters and option-string parsers stay follow-ups.

  • Sections:
    • PEL_SEC_ENC_TELEMETRY (bit 8, 104 bytes) adds a presence mask, so "not reported" differs from 0, and optional per-block maps capped at 2^20 elements.
    • PEL_SEC_ENCODE_RECORD (bit 9, 48 bytes) carries the digest and a locator.
    • PelorusMotionSection gains block_size_log2 at the tail (32 → 36 bytes; a 1.3 blob is detected by its size).
    • There is a new error code, PEL_ERR_MISMATCH = -8, and a _Static_assert on every new size and offset.
  • New API:
    • telemetry.h is encoder-agnostic, with no FFmpeg types.
    • encode_record.h provides RFC 8785 string-scalar JSON and a SHA-256 digest that matches the worked example in docs/api/encode-record.md byte for byte.
    • New interop functions are pel_blob_pack_into, pel_blob_map and pel_encode_record_digest_text. pel_blob_map refuses a map that overlaps the header or directory.
  • Field registry: libpelorus/schema/telemetry-fields.json holds the 31 keys. Its parity check SKIPs the VMAFx side, with the reason stated, until vmafx#2271 publishes its list.
  • FFmpeg side: mc writes block_size_log2, and the denoise consumer prefers it over inference. Both uses sit behind #if PELORUS_ABI_MINOR >= 4, so the stack still builds against an older libpelorus; the >= 0.2.0 pkg-config minimum is unchanged. Patches 0001, 0003 and 0007 are regenerated on the 20-patch stack.

The ABI commit carries a Migration: footer with before/after C snippets. ADR-0174 and ADR-0175 flip to Accepted.

Reviewer decision: none left. The interop-abi-reviewer and ffmpeg-patch-reviewer approved, and the c-reviewer passed. Every finding is fixed in this branch, each with a test.

Reproducer / smoke-test

make verify-native                                          # fast suite incl. telemetry_test, encode_record_test
FFMPEG_REPO=<n9.0.2 checkout> ffmpeg-patches/test/build-and-run.sh   # 20 patches
python3 scripts/check-telemetry-field-parity.py --self-test

Also green:

  • the ASan/UBSan fast suite;
  • gcc -O2 -Werror;
  • a second generate.sh run that is byte-identical;
  • a guard proof: the filter sources compile against both the 1.3 and the 1.4 headers, and the unguarded version fails against 1.3.

Twelve planted defects plus five for the review fixes each fail a test. The 1.3 compatibility checks pass: a 32-byte motion section reads as "field absent", and a 1.3 consumer reads 32 bytes of a 1.4 blob.

VMAFx re-pin: the mirrored files that change are interop.h, interop.c, pelorus.h, version.c and the conformance fixture. The new telemetry.*, encode_record.* and sha256.* are not mirrored at RC4. VMAFx pins released commits only (ADR-1276), so v0.4.0-rc.1 follows this PR.

Per-PR checklist (ADR-0100 / ADR-0108 — see CONTRIBUTING.md)

  • ADR: ADR-0174, ADR-0175 (now Accepted)
  • Per-surface docs: docs/api/encoder-telemetry.md, docs/api/encode-record.md, docs/api/interop-abi.md
  • Research digest: docs/research/0174-abi-1-4-telemetry-provenance.md
  • Decision matrix = ADR Alternatives tables
  • AGENTS.md invariant note: libpelorus/AGENTS.md
  • Changelog fragments; --check passes
  • Rebase note: entry for patches 0001/0003/0007 and the ABI_MINOR guard
  • Patch-stack sync: canonical sources plus regenerated stack; full 20-patch replay passes
  • Interop ABI: append-only, PELORUS_ABI_MINOR 4, conformance fixture extended
  • Shader source: untouched
  • Touched files lint-clean; new units in .config/clang-tidy/lane-files.txt
  • Conventional Commit subjects; signed and signed off; Migration: footer on the ABI commit

Interop ABI 1.4 lands as ADR-0174 and ADR-0175 specify, so VMAFx can
re-vendor one fixed layout before 1.0.0-rc.4. PEL_SEC_ENC_TELEMETRY (bit
8, 104 bytes) carries one normalised record per coded frame with a
presence bit per optional field. PEL_SEC_ENCODE_RECORD (bit 9, 48 bytes)
carries the SHA-256 of the canonical encode record and a locator.
PelorusMotionSection gains block_size_log2 at its tail (32 -> 36 bytes).
PELORUS_ABI_MINOR goes from 3 to 4, and pel_result gains
PEL_ERR_MISMATCH (-8).

interop.c, the unit VMAFx mirrors, gains the two section bits, the
non-allocating pel_blob_pack_into, pel_blob_map for map bounds and
pel_encode_record_digest_text. The writer side lives in units the mirror
does not carry at RC4: telemetry.c (FFmpeg-free input, validation,
packer, map reader), encode_record.c (canonical JSON, build, hash,
verify) and sha256.c, a port of VMAFx's FIPS 180-4 code. The registry
libpelorus/schema/telemetry-fields.json and
scripts/check-telemetry-field-parity.py hold the field names; the VMAFx
half reports SKIP until vidiko/vmafx#2271 publishes its list.

Verified with the fast suite (44 OK, 1 SKIP with its reason), ASan and
UBSan, gcc -O2 and the clang-tidy lane. Twelve planted defects each fail
a test, and the worked example's digest matches the Python reference.

Migration: PelorusMotionSection grows 32 -> 36 bytes (ABI 1.3 -> 1.4);
two section bits are added (8 enc-telemetry, 9 encode-record).
Before:
  _Static_assert(sizeof(PelorusMotionSection) == 32, "motion section ABI");
  bsize = pelorus_mc_cell_pitch(w, h, grid_cols, grid_rows);
After:
  _Static_assert(sizeof(PelorusMotionSection) == 36, "motion section ABI");
  if (PEL_SD_FIELD_OK(got, PelorusMotionSection, block_size_log2) &&
      mo->block_size_log2 != 0)
      bsize = 1u << mo->block_size_log2;
  else
      bsize = pelorus_mc_cell_pitch(w, h, grid_cols, grid_rows);

Signed-off-by: lusoris <lusoris@proton.me>
vf_pelorus_mc now writes PelorusMotionSection.block_size_log2: 3, 4 or 5
for bsize 8, 16 or 32, and 0 ("not reported") for edges such as 12 that
a log2 cannot carry. vf_pelorus_denoise takes the named edge instead of
inferring it from the frame size and the grid. The inference skipped
motion compensation, or assumed the default edge, on small frames:
bsize=8 on a 64x64 frame fits both 8 and 9 (#218, BUG-035). A 1.3
motion section, detected by its readable size, keeps the inference
through the new pelorus_mc_block_pitch() helper.

The mc entropy proxy moves into mc_motion_entropy() with unchanged
arithmetic, so attach_motion shrinks instead of growing its baselined
size. Patches 0001, 0003 and 0007 are regenerated and byte-stable on a
second run; the full 18-patch replay applies, links FFmpeg and the
static libavfilter consumer. mc-stats and ffmpeg-sidedata-consumers
cover the new helpers in the fast suite.

Signed-off-by: lusoris <lusoris@proton.me>
The encoder-telemetry and encode-record pages move from "specified" to
implemented, and say plainly what is still missing: the per-encoder
adapters and their capability tables, the AV1 and VP9 QP normalisation,
the telemetry JSON writer and the option-string parsers (#86, #81).
interop-abi.md lists the two new sections, the interop.c helpers, the
Migration snippet and PEL_ERR_MISMATCH. docs/metrics/encoder-telemetry.md
states how the VMAFx field-name check runs and that no VMAFx revision is
pinned yet (#220), and the adapter contract for callers outside FFmpeg
(#221).

libpelorus/AGENTS.md records the ABI 1.4 invariants, including that the
shared fixture calls only interop.c because VMAFx does not mirror the new
units at RC4. AGENTS.md names ABI 1.4 on master; the agent projections
are regenerated. The changelog fragment, CHANGELOG.md and the README
status list carry the change.

Signed-off-by: lusoris <lusoris@proton.me>
The configure probes in the patch stack still accept libpelorus >= 0.2.0,
so the filters can build against interop headers older than ABI 1.4,
where PelorusMotionSection has no block_size_log2. The mc producer write
and the reader in pelorus_mc_block_pitch() are now behind
field and the consumer takes the documented inference.

Proved both ways: the mc, denoise, analyze and scenecut sources compile
clean against the ABI 1.3 headers of origin/master and against 1.4, and
the preprocessed mc and denoise sources contain the motion-section field
only with 1.4. The unguarded header fails to compile against 1.3. The
pelorus_sidedata.h comment now states the 1.3 and 1.4 behaviour in
separate sentences, and the rebase note names the guard and the
pkg-config minimum. Patches 0001 and 0007 are regenerated, byte-stable on
a second run, and the full 18-patch replay passes.

Signed-off-by: lusoris <lusoris@proton.me>
Four c-reviewer findings on the ABI 1.4 code, each with a negative test:

- pel_sha256 and pel_sha256_update return pel_result: NULL data with a
  non-zero length is PEL_ERR_INVALID and hashes nothing, instead of
  passing for the empty message. Callers check the result (HISS-07).
- pel_blob_map rejects a map that overlaps the header or the directory
  (offset below header_size + section_count * 16) with PEL_ERR_ABI. The
  fixture plants maps on the header and on dir[0], and accepts one that
  starts right after dir[].
- The canonicaliser and the builder reject empty keys.
- pel_encode_record_canonicalize and pel_encode_record_build take
  buf = NULL with cap = 0 as a size query (PEL_ERR_RANGE, length in
  *out_len), the pel_blob_pack_into convention; NULL with a capacity
  stays PEL_ERR_INVALID.

The API pages and header comments state the new rules. Five planted
defects, one per rule, each fail a test.

Signed-off-by: lusoris <lusoris@proton.me>
This branch implements both ADRs, so they move to Accepted: the Status
lines and the index rows say so, and the pending Implementation lines
are gone. Each Consequences section says in one line what stays a
follow-up: the encoder adapters for #86, the option-string parsers for
#81.

interop-abi.md now says that VMAFx must not call the telemetry packer or
pel_blob_pack_into to emit a blob under the Pelorus UUID; a VMAFx-origin
annotation uses VMAFx's own UUID (VMAFx ADR-1113). The telemetry pages
and the telemetry.h comment describe VMAFx's codec-adapter package as a
caller that fills and validates the input, not one that packs. The re-pin
list in ADR-0174 and on the API page names
libpelorus/include/pelorus/pelorus.h (PEL_ERR_MISMATCH) and
libpelorus/src/version.c among the changed mirrored files. The bump-abi
skill prefers growing a struct over consuming its reserved padding, as
ADR-0174 decided for the motion section.

Signed-off-by: lusoris <lusoris@proton.me>
… stack

The rebase onto master, which added patches 0019 and 0020 (udu_sei for
QSV and Vulkan Video), took master's generated patches at every conflict
stop. This commit regenerates them once at the tip from the canonical
files/ sources: 0001, 0003 and 0007 carry the ABI 1.4 block-size change
again, with the NN/20 subject counters; their content equals the
pre-rebase patches apart from the counter. Two generate.sh runs on a
fresh n9.0.2 worktree are byte-identical. CHANGELOG.md and the agent
context projections regenerate unchanged. The rebase note now says the
replay applies 20 patches.

Signed-off-by: lusoris <lusoris@proton.me>
@lusoris
lusoris merged commit e64962e into master Oct 9, 2026
8 checks passed
@lusoris
lusoris deleted the feat/interop-abi-1.4 branch October 9, 2026 00:03
lusoris added a commit that referenced this pull request Oct 9, 2026
BLUF: the encoder telemetry adapters and encode-record option parsers
are now 0.6 exit criteria, per the maintainer decision of 2026-10-09.

The ABI 1.4 schemas they fill shipped in v0.4.0-rc.1 (#250). #86 and
#81 are closed as complete for that schema part, and the remaining
work is #263, #264 and #265 under epic #196.

Signed-off-by: lusoris <lusoris@proton.me>
lusoris added a commit that referenced this pull request Oct 9, 2026
BLUF: the encoder telemetry adapters and encode-record option parsers
are now 0.6 exit criteria, per the maintainer decision of 2026-10-09.

The ABI 1.4 schemas they fill shipped in v0.4.0-rc.1 (#250). #86 and
#81 are closed as complete for that schema part, and the remaining
work is #263, #264 and #265 under epic #196.

Signed-off-by: lusoris <lusoris@proton.me>
lusoris added a commit that referenced this pull request Oct 9, 2026
BLUF: the encoder telemetry adapters and encode-record option parsers
are now 0.6 exit criteria, per the maintainer decision of 2026-10-09.

The ABI 1.4 schemas they fill shipped in v0.4.0-rc.1 (#250). #86 and
#81 are closed as complete for that schema part, and the remaining
work is #263, #264 and #265 under epic #196.

Signed-off-by: lusoris <lusoris@proton.me>
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.

interop: append block_size_log2 to PelorusMotionSection in ABI 1.4 (BUG-035)

1 participant