Skip to content

feat(kodecs-h264)!: parse 0.1's scope again and check decoder scope apart - #118

Merged
kixelated merged 9 commits into
mainfrom
quest/m1/kodecs-h264/relicense
Dec 4, 2026
Merged

kixelated merged 9 commits into
mainfrom
quest/m1/kodecs-h264/relicense

Conversation

@kixelated

@kixelated kixelated commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Brings kodecs-h264's parser back to 0.1's scope, written clean-room, and moves the decoders' narrower scope into Sps::check_decoder_scope, which a decoder checks on the Arc<Sps> each slice now carries. This applies the maintainer decisions on scope and the parser API. The relicense quest becomes moq-dev/moq moving onto the kodecs-h264 release that carries this.

Changes

  • Parser scope (kodecs-h264):
    • SPS: chroma_format_idc (4:0:0 through 4:4:4), separate_colour_plane, luma and chroma bit depth up to 14, qpprime_y_zero_transform_bypass, frame_mbs_only and mb_adaptive_frame_field. Also covers 4:4:4's twelve scaling lists with their fall-back rule, and crop units by ChromaArrayType.
    • Slice header: colour_plane_id, field_pic and bottom_field. delta_pic_order_cnt_bottom and delta_pic_order_cnt[1] are read only for frames. The first_mb_in_slice limit is halved for fields and MBAFF, up to 32 references per list in fields, and MaxPicNum is doubled. MMCO counts are bounded for fields, slice_qp by QpBdOffsetY, and SP/SI slices read sp_for_switch and slice_qs. There is no chroma in the weight table when ChromaArrayType is 0.
    • Data partition A parses as a slice. Partitions B and C, slice groups, SVC and MVC still return Unsupported.
    • Levels: the parser still bounds its own work by the level's MaxFS and NAL (CPB) budget, as 0.1 did, using level 6.2's limits for a level Table A-1 lacks. The DPB, side-length and max_dec_frame_buffering limits move to check_decoder_scope.
    • The writer emits all of the above. Verus specs and proofs are updated.
  • Parser API (kodecs-h264): one full-syntax Parser with no scope mode stores every parameter set it parses, so its NAL budget follows the SPS the stream sent. Unit::Sps/Unit::Pps carry the stored Arc<Sps>/Arc<Pps>, and Unit::Slice { nal, header, sps, pps } its NAL header and the Arcs its header parsed against. Parser::sps(id)/pps(id) stay read-only. A PPS the replacing SPS can't read (such as 4:2:0 scaling lists under a 4:4:4 SPS) keeps its RBSP until an SPS that reads it arrives, so a stream returning to its earlier sequence needn't resend it. The Verus proofs cover the Arc storage on the pinned Verus as is.
  • Decoder scope: Sps::check_decoder_scope returns Unsupported outside progressive 8-bit 4:2:0 without transform bypass, and Level/Range outside its level. kodecs-vaapi checks it on each slice's Arc<Sps>, caching the last passing SPS by pointer, and refuses the slice; decoding resumes once the stream sends an in-scope SPS. It also refuses data partitioning and SP/SI slices, so it still decodes only what it did. It drops its Sps::parse pre-check, its refused bitmask, its per-slice pps(header.pps_id).sps_id lookup, parameter_sets() and its per-slice deep clones of the SPS and PPS.
  • Tests:
    • Eight new fixtures:
      • x264: 4:0:0, High 10, interlaced 4:2:2 10-bit, 4:4:4 with custom matrices, 4:4:4 lossless, MBAFF, and an over-level stream.
      • Headers only: a 1080i broadcast capture's SPS, PPS and slice headers (PAFF and MBAFF), cut from moq's MPEG-TS test data with the picture data dropped.
    • tests/scope.rs checks 210 slice headers against ffmpeg's trace_headers reading (tests/data/slices.tsv), to the bit.
    • The fuzz round-trip runs over every fixture, and checks each unit's Arcs are the stored sets.
    • Parser tests (no GPU): an out-of-scope Level 4 4:2:2 SPS replacing a Main Level 1 one is stored, the budget follows it so a 32 KiB SEI passes, and check_decoder_scope fails on that slice's SPS; switching back parses slices without a resent PPS. A PPS a 4:4:4 SPS can't read returns with its sequence.
    • kodecs-vaapi hardware tests: interlaced and High 10 slices are refused; a 4:2:2 stream is refused, then the 4:2:0 stream resumes; a PPS outlasts a 4:4:4 SPS that can't read it.
  • Quests:

Public API impact

Breaking for kodecs-h264 (!). Details are in kodecs-h264/MIGRATE.md ("kodecs-h264 0.2 -> 0.3").

  • Unit::Sps(Arc<Sps>), Unit::Pps(Arc<Pps>) and Unit::Slice { nal, header, sps, pps } replace the id-carrying variants and Unit::Slice(SliceHeader). Parser::sps/pps return Option<&Arc<_>>.
  • New public fields on Sps and SliceHeader, and new SliceType::Sp/Si variants. Exhaustive matches and struct literals need updating.
  • SPSs that used to fail with Unsupported or Level now parse. Call Sps::check_decoder_scope on each slice's SPS to keep refusing them.
  • scaling::Matrix::lists_8x8 holds 6 lists in 4:4:4.

kodecs-vaapi's API is unchanged, and so is the behavior it decodes. No wire format changes.

Decisions

  • Maintainer (2026-12-03, comment): ✅ extend kodecs-h264's parser to 0.1 parity, clean-room, keeping the decoder progressive 8-bit 4:2:0 (rejected: accepting the narrower scope; keeping a slice-header parser in moq-mux). This supersedes the 2026-12-01 scope line and settles chore(mux,video): move to kodecs-h264 0.2 and kodecs-vaapi 0.2.1 moq#10499 open question: MPEG-TS keeps deriving interlaced timestamps.
  • Maintainer (via /quest-run, 2026-12-03): don't yank kodecs-vaapi 0.2.1 despite encode::probe's signature change.
  • Maintainer (via /quest-run, 2026-12-03): kodecs-vaapi 0.2.1 satisfies the kodecs-vaapi release wait.
  • Agent: the parser keeps the level's MaxFS and NAL budget, as 0.1 did, because both bound hostile input. The DPB, side and buffering limits only constrain decoders, so they move to check_decoder_scope. Unknown levels parse under level 6.2's limits rather than failing.
  • Agent: parse data partition A, for 0.1 parity (it carries the slice header). kodecs-vaapi refuses it explicitly.
  • Agent: scaling::Matrix::lists_8x8 changes length (128 or 384) rather than Pps::write taking the SPS.
  • Agent: no direct_8x8_inference "shall" check for field-capable SPSs, matching 0.1.
  • Agent: no version bump. release-plz bumps kodecs-h264 (expected 0.3.0) and kodecs-vaapi.
  • Agent: commit the fixtures. The broadcast capture is cut to SPS, PPS and the first 40 bytes of each slice, with no picture data.
  • Agent: keep the quest until chore(mux,video): move to kodecs-h264 0.2 and kodecs-vaapi 0.2.1 moq#10499 merges, so kodecs still tracks the move if it stalls.
  • Maintainer (2026-12-04, comment): ✅ one full-syntax Parser that always stores what it parses, Unit::Slice carrying its Arc<Sps>/Arc<Pps> (and Unit::Sps/Unit::Pps theirs), read-only sps(id)/pps(id), and decoders checking check_decoder_scope per slice SPS cached by Arc pointer (rejected: Parser::forget_sps(id); a Scope enum or check fn in Parser::new; two parser types; accepting Codex's stale-budget finding as is). This settles the former ## Waiting item and supersedes the round-1 agent decision that kept refused SPSs out of the parser.
  • Agent: Unit::Slice is a struct variant { nal, header, sps, pps } rather than a new Slice type, so a decoder destructures it without another public name. It keeps the NaluHeader so a decoder using Parser::next can refuse data partition A (review round 1, Codex).
  • Agent: kodecs-vaapi gives the parser's errors a neutral parse a {type} NAL unit context, keeping the decoder-scope text for check_decoder_scope refusals, since the parser's remaining Unsupported cases are slice groups, partitions B/C and extensions (review note).
  • Agent: left as notes, not fixed: check_decoder_scope's u32 multiply on a hand-built Sps past the parser's 1055-macroblock bound, its use of the stored max_dpb_frames on an edited Sps, the writers not bounding colour_plane_id/chroma_format_idc/bit depths, and Pps::write sizing 8x8 lists from the matrix. Each needs a caller hand-building out-of-spec values.
  • Agent: a PPS the replacing SPS can't read keeps its RBSP (stored with its seq_parameter_set_id) and reports Missing for its slices, rather than being dropped. Without it, a 4:4:4 SPS would cost the 4:2:0 sequence it interrupts its scaled PPS, which the hardware test a_pps_outlasts_a_sequence_that_cant_read_it covers.
  • Agent: #[allow(clippy::large_enum_variant)] on Unit with a reason, rather than boxing the header, since a unit is moved out as soon as it's returned.
  • Agent: the Verus Arc concern was a non-issue: vstd at the pinned version specifies Arc::new and Arc::clone, and the proofs verify with no helper. Only Unit's derived Clone needed verifier::allow(autoderive_clone_without_spec), as no proof clones a unit.

Validation

  • nix develop --command just ci on fedora (Linux) at 171a24b: lint, format, tests, and Verus (130 verified, 0 errors).
  • just vaapi on fedora (AMD renderD128) at 171a24b: 35 passed, including sequences_outside_the_scope_are_refused, a_refused_sequence_resumes_once_sent_again, and a_pps_outlasts_a_sequence_that_cant_read_it.
  • cargo test -p kodecs-h264 on Windows passed.
  • The ffmpeg oracle (slice_headers_match_ffmpeg) fails when the !field_pic gating of the bottom POC fields is removed (earlier round; the slice parser is unchanged here).
  • chore(mux,video): move to kodecs-h264 0.2 and kodecs-vaapi 0.2.1 moq#10499 head (7f36edbfc) against this branch through an uncommitted [patch.crates-io] for kodecs-h264 and kodecs-vaapi: cargo clippy -p moq-mux -p moq-video --all-targets --features moq-video/vaapi -- -D warnings clean, and cargo nextest run 2522 passed, 9 skipped. That needed two local changes, held until kodecs-h264 publishes: moq-mux's MPEG-TS clock takes the SPS from Unit::Slice { header, sps, .. } instead of two id lookups, and moq-video's VA-API encoder builds encode::Config through Config::new, since main's unreleased kodecs-vaapi made it #[non_exhaustive].
  • quest check: ok.
  • quest review (level L, run on fedora since Codex's sandbox can't run on native Windows), two rounds to 171a24b. Round 1: Codex gpt-6.2-sol xhigh scored 6 with one finding (keep the NAL type on parsed slices), fixed; Claude Opus 5.5 high scored 8 with notes only. Round 2: Codex 10, Claude 9, no findings.

Follow-ups

None. moq-side work (restoring field POC on top of the release) is tracked by quest/m1/kodecs-h264/relicense.md.

Models

Size: M
Implementer: claude, claude-opus-5-5, high (writer A/B arm A, cohort m-writer-effort)
Implementer: claude, claude-opus-5-5, high (iterate, M, arm A, cohort m-writer-effort)
Implementer: claude, claude-opus-5-5, high (iterate, M, arm A, cohort m-writer-effort)

🤖 Generated with Claude Code

(Written by Claude Opus 5.5 with high)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title moq-dev/moq moves to kodecs-h264 0.2 quest: finish the kodecs-h264 relicense with moq-dev/moq#10499 Dec 3, 2026
…erges

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title quest: finish the kodecs-h264 relicense with moq-dev/moq#10499 quest: move the kodecs-h264 relicense quest onto moq-dev/moq#10499 Dec 3, 2026
@kixelated
kixelated marked this pull request as ready for review December 3, 2026 23:36
@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 17 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d4b25d70-3d47-4626-9698-407c6f8d466f
Commits

Reviewing files that changed from the base of the PR and between a8cc7b5 and 171a24b.

Files ignored due to path filters: 1

  • kodecs-h264/tests/data/slices.tsv is excluded by !**/*.tsv
Files selected for processing: 28

  • kodecs-h264/CHANGELOG.md
  • kodecs-h264/MIGRATE.md
  • kodecs-h264/README.md
  • kodecs-h264/src/fuzz.rs
  • kodecs-h264/src/lib.rs
  • kodecs-h264/src/syntax/bits.rs
  • kodecs-h264/src/syntax/mod.rs
  • kodecs-h264/src/syntax/parser.rs
  • kodecs-h264/src/syntax/pps.rs
  • kodecs-h264/src/syntax/scaling.rs
  • kodecs-h264/src/syntax/slice.rs
  • kodecs-h264/src/syntax/sps.rs
  • kodecs-h264/src/syntax/write.rs
  • kodecs-h264/tests/data/gray_64x64_4f.h264
  • kodecs-h264/tests/data/high10_64x64_6f.h264
  • kodecs-h264/tests/data/high422_interlaced_64x64_6f.h264
  • kodecs-h264/tests/data/high444_cqm_64x64_6f.h264
  • kodecs-h264/tests/data/high444_lossless_64x64_2f.h264
  • kodecs-h264/tests/data/kyrion_1080i_headers.h264
  • kodecs-h264/tests/data/mbaff_64x64_8f.h264
  • kodecs-h264/tests/data/overlevel_512x16_4f.h264
  • kodecs-h264/tests/scope.rs
  • kodecs-h264/tests/syntax.rs
  • kodecs-vaapi/CHANGELOG.md
  • kodecs-vaapi/src/decode.rs
  • kodecs-vaapi/src/encode.rs
  • quest/m1/kodecs-h264/README.md
  • quest/m1/kodecs-h264/relicense.md

No actionable comments were generated in the recent review.

Walkthrough

The kodecs-h264 relicense entry changes its size label from [M] to [XS]. It records PR #10499, listed dependency versions, passing CI and VA-API hardware tests, clean review, and the decision to drop interlaced decode. The waiting condition now depends on the maintainer settling the MPEG-TS timestamp decision before PR #10499 merges.

Merge Risk: Minimal · previous review a8cc7

This documentation-only update records the status of the kodecs-h264 relicense work and has no runtime impact. It is safe to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title names the main change: kodecs-h264 parser scope is restored to 0.1 parity, and decoder scope checks move to Sps::check_decoder_scope. It is specific and matches the summary and description. …
Description check Passed The description is specific and on-topic. It names the kodecs-h264 parser scope changes, the Sps::check_decoder_scope API, the kodecs-vaapi decoder changes, the new fixtures and tests, the public API …
Full details: Title check

Explanation

The title names the main change: kodecs-h264 parser scope is restored to 0.1 parity, and decoder scope checks move to Sps::check_decoder_scope. It is specific and matches the summary and description. The title is long (73 characters) and uses the breaking-change marker, but it is still on-topic.

Full details: Description check

Explanation

The description is specific and on-topic. It names the kodecs-h264 parser scope changes, the Sps::check_decoder_scope API, the kodecs-vaapi decoder changes, the new fixtures and tests, the public API impact, and the quest relicense.md update that waits on moq-dev/moq PR #10499. It is not vague or unrelated to the changeset.

Finishing Touches

Simplify code

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1d774dbb-b5bd-4efa-b43d-9fadf05887be
Commits

Reviewing files that changed from the base of the PR and between 9b9f28d and a8cc7b5.

Files selected for processing: 1

  • quest/m1/kodecs-h264/relicense.md

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@kixelated

Copy link
Copy Markdown
Collaborator Author

Maintainer decision (via /quest-run, 2026-12-03): extend kodecs-h264 instead of narrowing MPEG-TS import. kodecs-h264's parser regains everything the 0.1 (cros-codecs-derived) parser parsed, including interlaced/field slice headers and picture order count, so moq-mux keeps deriving H.264 timestamps for those streams (rejected: accepting the narrower scope; keeping a slice-header parser in moq-mux). The decoder scope stays progressive 8-bit 4:2:0, and VA-API H.264 decode still refuses interlaced. This PR waits for the kodecs-h264 release carrying that, then moves onto it.

(Written by Claude Opus 5.5)

@kixelated
kixelated marked this pull request as draft December 3, 2026 23:47
…part

The parser takes interlaced and MBAFF sequences (field_pic, bottom_field,
the per-field picture order count fields), 4:0:0 through 4:4:4 with the
4:4:4 scaling lists, bit depths up to 14, transform bypass, SP and SI
slices, data partition A, and streams over their level's DPB and side
limits. It still bounds its own work by the level's frame size and NAL
budget, using level 6.2's for levels Table A-1 lacks.

Sps::check_decoder_scope holds what the decoders take: progressive 8-bit
4:2:0 within its level. kodecs-vaapi runs it on every SPS and slice and
refuses data partitioning and SP/SI slices.

Slice headers are checked against ffmpeg's trace_headers reading of each
fixture, to the bit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title quest: move the kodecs-h264 relicense quest onto moq-dev/moq#10499 feat(kodecs-h264)!: parse 0.1's scope again and check decoder scope apart Dec 4, 2026
@kixelated

Copy link
Copy Markdown
Collaborator Author

Applied at 96f39d9:

  • kodecs-h264's parser is back at 0.1's scope, written clean-room. It covers field and MBAFF slice headers with their per-field POC fields, 4:0:0 through 4:4:4, bit depths up to 14, SP/SI, data partition A, and streams over their level's DPB and side limits.
  • Sps::check_decoder_scope now holds the progressive 8-bit 4:2:0 limit, and kodecs-vaapi runs it on every SPS and slice, so kodecs-vaapi still refuses interlaced streams.
  • The epic's scope line now separates parser scope from decoder scope. The relicense quest waits on this release, then on chore(mux,video): move to kodecs-h264 0.2 and kodecs-vaapi 0.2.1 moq#10499 moving onto it.

The PR body's Decisions and Validation sections have the details.

(Written by Claude Opus 5.5 with high)

kixelated and others added 2 commits December 3, 2026 16:32
…s it

Storing a 4:4:4 SPS made the parser read each PPS naming its id again
with twelve scaling lists and drop those coded for 4:2:0, so a stream
coming back to its sequence without resending its PPS failed. The
decoder now checks scope first and remembers the refused id.

Also corrects docs the review found stale: the field MMCO bound, the
level 6.2 fallback's reach, pic_init_qp's range, partition A's slice_id,
and data partitions B and C among what the parsers refuse.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated

Copy link
Copy Markdown
Collaborator Author

Maintainer decision (via /quest-run, 2026-12-04): resolve the open review finding (stale NAL budget after a refused SPS) by redesigning instead of patching. kodecs-h264 keeps one full-syntax Parser that always stores what it parses, so its budget follows the SPS the stream actually sent. Unit::Slice carries the Arc<Sps> and Arc<Pps> it parsed against (likewise Unit::Sps/Unit::Pps), and read-only sps(id)/pps(id) stay for inspection. A decoder checks Sps::check_decoder_scope() on each slice's SPS (cached by Arc pointer) and refuses the slice; decoding resumes when the stream returns to an in-scope SPS. kodecs-vaapi drops its SPS pre-parse, its refused bitmask and its per-slice id lookups. Rejected: a public Parser::forget_sps(id), a Scope enum or a check fn in Parser::new (parser modes), two parser types, and accepting the finding as is.

(Written by Claude Opus 5.5)

kixelated and others added 2 commits December 3, 2026 17:40
…d against

The parser stores every SPS it reads, in a decoder's scope or not, so its NAL
budget follows the sequence the stream sent. Unit::Sps and Unit::Pps carry the
stored Arcs, and Unit::Slice { header, sps, pps } the ones its header used. A
PPS the replacing SPS can't read keeps its RBSP for the next SPS that can.

kodecs-vaapi checks Sps::check_decoder_scope on each slice's SPS, cached by Arc
pointer, and drops its SPS pre-parse, refused-id bitmask, per-slice id lookups
and deep clones of the parameter sets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Unit::Slice carries the slice's NaluHeader, so a decoder using Parser::next
can refuse data partition A. kodecs-vaapi gives parser errors a neutral
context instead of the decoder-scope text, and the changelog marks the new
public fields breaking.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review December 4, 2026 01:51
@kixelated
kixelated added this pull request to the merge queue Dec 4, 2026
Merged via the queue into main with commit 2716a24 Dec 4, 2026
4 checks passed
@moq-bot moq-bot Bot mentioned this pull request Dec 4, 2026
kixelated added a commit that referenced this pull request Dec 4, 2026
…p its slices.tsv

#118 added streams beyond the decoder's scope to the tests/data the corpus replay reads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant