forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on 8dbd683068d7f87f21dcc4ed1dfdca786d82c52bFiltered to crates/ec-h264/src/dpb.rsClear filter

2026-08-20

fix(h264): drop leading pictures after a seek's open-GOP recovery pointAhmet Kaan Gümüş · 03dc6e9
fix(h264): drop leading pictures after a seek's open-GOP recovery point

Root cause (crates/ec-h264/src/dpb.rs, crates/ec-h264/src/decoder.rs;
mirrored in crates/ec-hw/src/dec/dpb264.rs, crates/ec-hw/src/dec/h264.rs):
an open-GOP I picture is not an IDR — it is a plain I slice whose
predecessors in decode order can still be referenced by pictures that
follow it. A decoder started fresh at that I (exactly what a seek does)
has none of those earlier references, so `build_ref_lists` pads the
missing entries with whatever it has. The old code decoded and output
those leading pictures anyway, handing back frames predicted from padded
(garbage) references before the stream ever reaches a picture whose
references are all real.

Annex D.2.8 defines a `recovery_point` SEI whose absence (the common
case, and this fixture's case) defaults `recovery_frame_cnt` to 0: the
recovery point is the RAP's own POC, i.e. only pictures with a POC at or
after the leading I's own POC are guaranteed fully referenced. The SEI
itself is deliberately not parsed — the default already gives the
correct threshold for the case that matters (mid-GOP seek), and a real
non-zero `recovery_frame_cnt` is out of scope for this fix.

`build_ref_lists` now returns whether it had to pad a list
((lists, padded)); `Decoder`/`H264Decoder` OR that per-slice into
`cur_ref_padded`/`Current::ref_padded`, latch the first post-reset
picture's POC into `recovery_poc` on `end_picture`/`finish_picture`, and
compute `output_ok = !(ref_padded && poc < recovery_poc)`. `Dpb::store`
takes that flag and marks the picture `Mark::Unused`-eligible for output
gating (`pic.output = output_ok`) — it still joins the DPB as a
reference and for bookkeeping, but a gated picture is never handed to a
caller. `reset_pictures` clears `recovery_poc` so a later seek gets its
own threshold.

New test `h264_seek_matches_linear_open_gop` in both suites drives this
through the real entry surface: fixtures/video/h264-open-gop.mp4
(x264 open-GOP, generated via scripts/gen-fixtures.sh) primes a fresh
decoder with the leading IDR's parameter sets, resets picture state (a
seek's exact contract), feeds it from the open-GOP I access unit before
display frame 30, and asserts the first decoded picture matches a linear
decode of frame 30. Confirmed failing before this fix (forcing
output_ok true reproduces the mismatch) and passing after, on both the
software decoder (crates/ec-h264/tests/conformance.rs) and the VA-API
path (crates/ec-hw/tests/gpu.rs, real hardware).

cargo test -p ec-h264: 70 lib + 23 conformance + 8 encode passed, 0
failed. cargo test -p ec-hw --test gpu -- --test-threads=1: 19 passed
(18 pre-existing + the new one), 0 failed.

2026-08-14

feat(h264): display-order output reaches the packet entry surfaceAhmet Kaan Gümüş · 5a58bb1
feat(h264): display-order output reaches the packet entry surface

A player never touches the NAL-level API, so the reordering has to arrive
at H264Decoder: packets in, frames out, timestamps travelling with their
pictures rather than with the packets that carried them.

packet_entry_surface_reorders_and_carries_timestamps drives exactly that
path — one access unit per packet, frames pulled with receive_frame —
and proves three things at once: every frame is bit-exact against
ffmpeg, the output order is a real permutation of the packet order, and
the tag on each emitted frame identifies the packet whose picture it
actually is (checked against the same stream decoded in decode order).

Also: the crate description now states the scope it reached, the debug
tracing added while chasing the inter defects is gone, and clippy and
rustfmt are clean.
test(h264): B pictures, display order, frame_num gaps, zero-alloc on BAhmet Kaan Gümüş · 6e48da7
test(h264): B pictures, display order, frame_num gaps, zero-alloc on B

- b_pictures_match_ffmpeg_every_frame: spatial and temporal direct,
  B-pyramid and weighted prediction, under both entropy coders, every
  frame bit-exact. The first version of this test measured nothing:
  x264's adaptive decision produced no B slices at all on the synthetic
  source, so the test now counts slice types out of the stream and fails
  if the encoder did not actually emit any.
- output_is_display_order_and_the_reorder_is_real: display order matches
  ffmpeg frame for frame, and the same stream decoded in decode order is
  a genuine permutation of it — 15 of 20 frames move.
- a_frame_num_gap_keeps_decoding: dropping a whole picture leaves the
  remaining 11 decodable, which is what a seek into a GOP looks like.
- The zero-allocation proof now covers a B-slice, multi-reference stream
  and counts a whole second pass over the stream rather than one
  picture, so picture-pool recycling is part of the claim.

Emitting a picture no longer looks its parameter set up: a stored
picture carries its own crop, output size and colour description, which
also removes the per-slice parameter-set clone that made the decode loop
allocate.
fix(h264): reference index spans its whole 8x8, and numbering precedes markingAhmet Kaan Gümüş · 4b8dc73
fix(h264): reference index spans its whole 8x8, and numbering precedes marking

Two more inter-only defects, both found against the JVT reference decoder
traces that ship with the vectors:

- ref_idx_lX covers a whole macroblock partition. Writing it over only
  the first sub-macroblock partition left the rest of an 8x8 marked
  "list unused", so the mvd contexts of 9.3.3.1.1.7 read absMvdComp 0
  for a neighbour that had one, and CABAC desynchronised.
- clause 8.2.4.1 (FrameNumWrap, PicNum) ran only when a slice built a
  reference list. An intra slice builds none, and the picture being
  stored had no FrameNumWrap of its own, so the sliding window of
  8.2.5.3 compared stale numbers and evicted the wrong reference.
  Numbering now runs at the head of `store`, the one point every
  picture passes through.

JVT full-sequence sweep: 18 vectors bit-exact end to end before, 25 now,
of the 26 that are in scope.
feat(h264): inter prediction, decoded picture buffer, display-order outputAhmet Kaan Gümüş · cd996f4
feat(h264): inter prediction, decoded picture buffer, display-order output

P and B slices under both entropy coders, with the clause 8.2 decoded
picture buffer behind them.

- inter.rs: quarter-sample luma interpolation (8.4.2.2.1), eighth-sample
  chroma (8.4.2.2.2) and the weighted combination of 8.4.2.3. Plane
  borders are replicated once per picture, which turns the per-sample
  Clip3 of Equations 8-239/8-240 into a single clamp of the block origin;
  the unit test checks every fractional position, inside the picture and
  far outside it, against the spec's clipped definition written out
  separately.
- mv.rs: macroblock and sub-macroblock partitioning (Tables 7-13, 7-14,
  7-17, 7-18), neighbouring motion data (8.4.1.3.2) and motion vector
  prediction (8.4.1.3) including the directional segmentation shortcuts.
- dpb.rs: picture order count types 0, 1 and 2, sliding-window and
  adaptive (MMCO 1..6, long-term references included) marking, reference
  list initialisation and modification, frame_num gap handling per
  8.2.5.2, and the output bumping of C.4.5.3.
- decoder.rs: P/B macroblock decode, P_Skip, B_Skip and both direct modes
  (spatial and temporal), constrained intra prediction, the inter scaling
  lists, and boundary strength derivation per 8.7.2.1 so deblocking now
  varies across an edge.
- Output is display order by default; OutputOrder::Decode is the escape
  hatch for a caller that reorders itself. Timestamps travel with the
  picture, not the packet.

The tC0 table rows for bS 1 and 2 were transcribed but unexercised by an
intra-only decoder, and both were wrong: whole-row shifts. Re-derived
from Table 8-17; inter edges reach them now.

CABAC initialisation gains the cabac_init_idc columns of Tables 9-13 to
9-21 (ctxIdx 11..59 and the idc columns of 70..275, 399..401), extracted
from the spec text by column alignment.