Skip to content

H.264: bound frame_num gap work and reject gaps the SPS forbids (#427) - #465

Merged
h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
NikitkaRa:h264-gap-bounds
Oct 14, 2026
Merged

h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
NikitkaRa:h264-gap-bounds

Conversation

@NikitkaRa

Copy link
Copy Markdown
Contributor

Closes #427.

What was wrong. Dpb::fill_frame_num_gap (crates/h264/src/dpb.rs) inserted one "non-existing" frame per missing frame_num, and the decoder callback allocated and copied a full picture for each one. With log2_max_frame_num = 16, one small slice could set off ~65 535 full-frame allocations and copies. gaps_in_frame_num_value_allowed_flag was parsed but this path never checked it.

Fix.

  • Forbidden gaps are rejected. If the active SPS has gaps_in_frame_num_allowed = 0, start_picture now returns an error for a picture with a frame_num gap, so it no longer fills the gap (7.4.2.1.1 / 8.2.5.2).
  • Allowed gaps cost bounded work. The sliding window keeps at most max_num_ref_frames short-term references (≤ 16). When the gap is longer than that, inserting the whole gap would push out every earlier short-term reference and every non-existing frame except the last max_num_ref_frames. So the earlier short-term references are now marked unused up front, and only the tail of the gap is built as frames. The POC state (update_gap_frame) still walks every missing frame_num in order, so FrameNumOffset wraparound comes out the same. Long-term references are left alone, as before.

Tests.

  • dpb.rs unit tests: a 65 533-frame gap builds only 4 frames, walks the POC state over every missing number, and leaves exactly the last 4 non-existing frames as references. Also covered: a gap that wraps around MaxFrameNum, a short gap that keeps earlier references, and a huge gap with a long-term reference.
  • synth_tests.rs: tiny CAVLC streams with a frame_num gap. When the SPS forbids gaps, the error is reported and the gap is not filled. When it allows them, the gap is filled and both pictures are output.
  • The existing pcm_long_term_mmco_gaps_* bit-exact tests still pass.

cargo xtask ci is green: fmt, clippy -D warnings, tests, assets, layers, wasm.

@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit 3335ee0 into storytold:main Oct 14, 2026
h-a-n-a-s-h-i pushed a commit that referenced this pull request Oct 14, 2026
- #178: ToUnicode ranges looked up without indexing
- #465: frame_num gaps are concealed (bounded) even when the SPS forbids them; cut streams keep playing
- #471: control request lines up to 256 MB so picture/media inserts still fit
- #473: a merge that loses its only row or column is removed, with regression tests
- #521: AutoCorrect no longer rewrites real words (cant, wont, im)
- #654: inherit_placeholder_geometry's doc comment back on its function

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

echelon commented Oct 14, 2026

Copy link
Copy Markdown
Member

Thank you for this contribution, @NikitkaRa! It has landed on main and will ship in the next DeckCraft release.

If you haven't already, please come join us on Discord: https://discord.gg/artcraft

anishguduru pushed a commit to anishguduru/deckcraft that referenced this pull request Oct 16, 2026
* Print: Windows lists its printers and spools jobs (storytold#756)

The Print dialog's printer list comes from Win32_Printer through PowerShell's
CIM (wmic is gone from Windows 11), and jobs are spooled by the embedded
windows_print.ps1: the in-box Windows.Data.Pdf renders each sheet at the
printer's own resolution and System.Drawing.Printing carries copies,
collation, duplex and colour as the job's settings. Both run through
powershell, so the Rust code touches no Win32 API. Fixes storytold#756, with the
printer-not-showing duplicates storytold#160, storytold#244, storytold#293, storytold#465 and storytold#644; CIM approach
from storytold#452. On CI a paused Generic / Text Only test printer catches the job in
its queue; a parser test keeps the script valid PowerShell.

* Print: fix the Windows await helper and render the job on CI (dry run)

Real-machine testing found [System.WindowsRuntimeSystemExtensions]::GetMethods()
failing with 'does not contain a method named GetMethods': GetMethods is an
instance method of [Type], so it is called with '.', the form the canonical
WinRT-await snippets use, not '::'. The first CI run missed it because the
end-to-end test skipped silently when the runner refused the test printer, so
the script had never actually run.

The script now honours PDFCRAFT_PRINT_DRYRUN=1: render every sheet with
Windows.Data.Pdf to PNGs in the temporary folder and print nothing. The test
runs that half unconditionally, so CI exercises the whole WinRT path —
projection, await helpers, render — on any machine, while the paused-printer
half stays best-effort and prints why it skipped. Win32_Printer enumeration
asks only for Name and Default, so a machine with nine printers waits less.

* Tests: the find-options wait in the viewer test is a deadline too

4280f83 converted the frame-count waits in this test to deadlines after the
same 12-of-15 race under a full workspace test run, but left the first wait —
the one for the 'page' matches — on the old 60-frame loop, and it flaked the
same way on PR storytold#847's CI. Same fix: wait up to 20 s for the 15 matches, then
assert.
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.

[Audit] H.264 frame-number gap handling repeatedly allocates and copies full frames

4 participants