Files
punktfunk/crates/pf-bitstream
enricobuehler 669176982d fix(h264): name the DPB cliff #96 left standing in the other codec
H.264 derives its DPB size the same way HEVC did before #96 — from a level
ceiling that says what a stream MAY use, not what it needs — and the ceiling
saturates at 16 frames, which is 17 hardware slots with the picture in flight.
That is the exact arithmetic that cost 720p and 1080p their HEVC.

Measured on real encoders (2026-08-07) rather than assumed: H.264 escapes it
twice over, and both escapes belong to the encoders, not to the format.

  encoder                              level picked        VUI restriction
  NVENC (RTX 5070 Ti, 610.57.04)       3.2/4.2/5.1/5.2     present, buffering 3
  VAAPI via libavcodec (RDNA3, 26.0.3) 4.1/4.2/5.1/5.2     present, buffering 1
  openh264 (the software rung)         3.2/4.2/5.1/5.2     present, buffering 1

Every one picks a level proportionate to the picture AND states its real need
in the VUI bitstream restriction, so the ceiling is never reached and never
consulted. Nothing is broken today, and clamping would be wrong: with the
restriction present the number IS the stream's own statement, and a stream that
genuinely asked for a deep DPB would decode wrong if we shrank it.

So this does not change what any stream decodes. It gives the arithmetic one
named home (`dpb_limit`, the twin of `h265::dpb_limit`) carrying the evidence
and the reasoning, and it adds the signal that was missing: when an SPS carries
no restriction AND its level ceiling would demand more slots than mainstream
hardware provides, the plan now says so with `PlanWarning::LevelDerivedDpb`
instead of a user silently losing the codec the way #96's users silently lost
HEVC. It is not an integrity warning — the picture is intact; what fails is
opening a session — so `is_integrity_warning` classifies it false.

One thing the sweep corrects about how the follow-up was framed: it is SMALL
pictures that saturate the ceiling most easily, not 720p specifically. 640x360
at level 3.1 computes 16 as readily as 720p at level 5.0, because the ceiling
is MaxDpbMbs divided by the picture's macroblocks. The authored 64x64 test
fixtures land there too, which is why they now assert through `picture_warnings`.

Guards, as the missing consumer-end half of pf-encode's
`rfi_dpb_fits_a_mainstream_vulkan_decoder`:

  * every_reachable_h264_stream_fits_a_mainstream_slot_pool — the measured
    (picture, level, declaration) pairs, asserting slots <= 16
  * the_level_ceiling_alone_would_reproduce_96_and_is_warned_about — the same
    resolutions at levels that saturate, pinned WITH the warning
  * a_proportionate_level_fits_even_without_a_vui_restriction — so neither
    escape looks like it is doing all the work alone

Gates: fmt + clippy -D warnings clean; pf-client-core 167/167; pf-bitstream
84/84; and gpu_parity 8/8 bit-identical to libavcodec on the RTX 5070 Ti, which
is the gate that matters for anything touching the bitstream layer.
2026-08-07 19:15:53 +02:00
..