Commits
Commits on
cd996f4051d004f8d0474490a8e9067a1ed7bb8aFiltered to crates/ec-h264/src/decoder.rsClear filter2026-08-14
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.
feat(h264): CABAC entropy decoding for I slicesAhmet Kaan Gümüş · 7cdaf34
feat(h264): CABAC entropy decoding for I slices Clause 9.3, transcribed from Rec. ITU-T H.264 (V15): - arithmetic decoding engine (9.3.3.2) with the spec's exact integer steps — DecodeDecision over rangeTabLPS, DecodeBypass, DecodeTerminate, RenormD; - context variable initialisation (9.3.1.1) from SliceQPY, and the engine restart after I_PCM samples (9.3.1.2); - binarizations: the I-slice mb_type tree (Table 9-36), TU, FL and the UEG0 suffix of coeff_abs_level_minus1 (9.3.2.1 to 9.3.2.7); - context selection including the neighbour-derived increments of 9.3.3.1.1 for mb_type, intra_chroma_pred_mode, coded_block_pattern, mb_qp_delta and coded_block_flag, plus the significance-map positions of 9.3.3.1.3; - the CABAC slice-data loop: cabac_alignment_one_bit, then a macroblock and an end_of_slice_flag per iteration. The picture state grows the two neighbour facts CABAC needs and CAVLC did not: the coded block pattern per macroblock, and the DC coded_block_flags. The macroblock loop is otherwise untouched — parse and reconstruction stay fused. Only the values an I slice of a frame-coded 4:2:0 8-bit stream reads are transcribed. The cabac_init_idc columns, the field-coded significance contexts and the 8x8 transform block categories belong to slices this decoder still refuses by name; a later release adds them against its own oracle rather than shipping numbers no test can reach. Inter slices under CABAC keep the existing inter-slice refusal, and transform_size_8x8_flag is now refused as a decoded bin rather than a raw one.
refactor(h264): entropy seat between the macroblock loop and CAVLCAhmet Kaan Gümüş · 6480b8e
refactor(h264): entropy seat between the macroblock loop and CAVLC The slice-data syntax reader becomes an enum seam (`Entropy`) covering every element the macroblock loop reads: mb_type, the intra prediction modes, coded_block_pattern, mb_qp_delta, the residual blocks, the I_PCM samples and the end-of-slice test. CABAC (clause 9.3) codes all of those differently, so the seam has to sit there rather than around residual_block alone; the parse-and-reconstruct loop stays fused. Enum dispatch, not a generic: the variant is constant for a whole slice, so the branches predict perfectly and the macroblock loop is monomorphised once. The neighbour derivations now hand out the raw (left, above) pair instead of a CAVLC nC, because CABAC reduces the same pair a different way. CAVLC ns/MB, median of three runs, before -> after: BA1_Sony_D 1331 -> 1328, CI_MW_D 1137 -> 1126, NL1_Sony_D 948 -> 933.
feat(h264): registry Decoder entry, avcC extradata, mechanism-named refusalsAhmet Kaan Gümüş · 19f3903
feat(h264): registry Decoder entry, avcC extradata, mechanism-named refusals The NAL-level Decoder is what a bitstream tool wants; a demuxer wants packets. H264Decoder implements ec_core::registry::Decoder over the same decode core and adds the two things a container brings with it: parameter sets carried out of band in an avcC record (14496-15 clause 5.3.3.1), and NAL units framed by a length prefix instead of Annex B start codes. The framing is decided once, by whether extradata held an avcC, and the SPS inside it publishes the picture size before the first packet arrives. Every refusal's why-text now names the syntax element that fired and the machinery it would need, not just "not implemented" — the conformance suite proves each one against a stream that really uses the feature, so the text is the capability statement a caller reads.
feat(h264): CAVLC intra decoder, bit-exact on 18 JVT streamsAhmet Kaan Gümüş · f985e44
feat(h264): CAVLC intra decoder, bit-exact on 18 JVT streams I-slice scope: I_4x4 / I_16x16 / I_PCM, full CAVLC residual decode, all intra prediction modes, 4x4 inverse transform + DC Hadamard, dequant with scaling-list support, and the complete in-loop deblocking filter. Everything outside scope (CABAC, FMO, interlace, non-I slices, 8x8 transform, 4:2:2/4:4:4, >8-bit) refuses with a named Unsupported error backed by tests on real conformance streams - never wrong pixels. Perf-first layout: padded planes sized for future inter overreach; per-MB state in flat struct-of-arrays (nz counts, intra modes, QP, slice ids) with no per-MB heap objects; a register-cached BitCursor for slice data; residual parse fused with reconstruction so empty blocks cost one coeff_token read; wide i16x16 SIMD for horizontal deblock edges (a gather/scatter vertical variant measured slower and stayed scalar). Steady-state decode loop is zero-alloc, proven by a counting allocator in the conformance harness. Conformance: first IDR bit-exact vs the JVT reference YUV and ffmpeg on 18 CAVLC streams incl. multi-slice and I_PCM; 6 CABAC/FMO/interlaced streams verified to refuse by name; deterministic corrupt-input sweep (truncations + 2000 single-byte mutations) never panics. Measured on this machine, single thread, deblock included: 1324 ns/MB (193 Mpx/s) on BA1_Sony_D at idle; 1007 ns/MB (254 Mpx/s) on the no-deblock NL1_Sony_D even under background load.