fix(video): load the H.264 bootstrap cache without statx
Targets master because the bug is there: loadBootstrap has used getEndPos() since the early commits, and the GeForce NOW branch carries the same code. The branch name follows the fix/<kebab-case> pattern of your fix/gfn-atomics-* branch, and the commit uses the conventional prefixes from #2-#4. The change is independent of #8 and #9.
What does this change?
loadBootstrap in src/media/video/video_pipeline.zig sized the H.264 parameter-set cache with file.getEndPos(). That goes through File.stat(), which uses statx, and statx only exists from Linux 4.11. On the 4.9 kernels H700 devices ship, the call fails, catch return 0 swallows the error, and the cache is never loaded, even though persistBootstrap writes it after every session. This is the limitation src/platform/linux/stat_compat.zig already documents.
The fix reads the file into a buffer one byte larger than bootstrap_capacity and uses the byte count as the size. Empty and oversized files are rejected exactly as before, and no stat call is involved. Read errors are now logged in debug mode, like the existing open errors.
How did you test it?
On an Anbernic RG35XX-H (H700, muOS, kernel 4.9.170):
-
Proving the bug. A small static aarch64 probe on the device, against the real cache file:
getEndPos: error.Unexpected raw fstat: 42 bytesDebug logs from earlier streaming sessions never contain
H.264 bootstrap loaded, althoughh264-parameter-sets.bin(42 bytes, starting00 00 00 01 67) was present. -
With the fix (built on the GeForce NOW branch, where I can stream), one GFN session:
H.264 bootstrap loaded (42 bytes) ... Video output active: 1024x768 format=23 decoder=cedar-h616 ... H.264 bootstrap updated H.264 bootstrap loaded (40 bytes)The whole cycle works: the cache is loaded at startup, rewritten after the session, and loaded again. The stream showed 0 decode errors, 0 corruption and 1 keyframe in the first second.
-
On
master,tools/zig.sh build testandtools/zig.sh build fmt-checkpass.I could not run
build releaseonmasterin my environment. Without the pkg-config isolation from3724080(onfeat/geforce-now), host headers leak into the SDL2 dependency build (L_tmpnamerrors instdio.h). That is unrelated to this change. Onfeat/geforce-now, the same change builds for release and has 0__aarch64_outline-atomics imports.
Not measured: how much this speeds up the first picture. Without the cache the decoder waits for the server's parameter sets. In one session the first second presented 55 of 57 decoded frames, against 39 of 57 in an earlier session without the cache. That is a single comparison, not a benchmark. Xbox Cloud uses the same pipeline, but I have not tested it.
video_pipeline.zig has no host unit tests and needs FFmpeg and SDL headers, so I didn't add new build wiring for a one-function fix. I'm happy to add a test if you'd prefer a particular setup.
AI disclosure
Per CONTRIBUTING: this was found and written with AI assistance (Claude). I reviewed the diff and verified the bug and the fix on hardware myself.
🤖 Generated with Claude Code
Summary by cubic
Fixes H.264 bootstrap cache loading on kernels older than 4.11, where File.getEndPos() failed because it relies on statx. The cache is now sized by reading the file directly, so saved SPS/PPS data loads correctly on H700 devices running kernel 4.9.
- Extracts cache loading into
bootstrap_cache.zig, covered by unit tests, including one that blocksstatxvia seccomp to prove the fix on kernel 4.9. - Continues rejecting empty and oversized caches; oversized files and read failures are logged in debug mode.
Summary by CodeRabbit
- Bug Fixes
- Bootstrap cache loading now ignores empty or invalid cache data and stops when a cache cannot be read. In debug mode, oversized caches are distinguished from other unreadable caches.
- Cache files larger than the supported capacity are rejected, while files within the limit can be read without relying on file-size metadata.