Repository navigation
rust: Port obs-avc.c to obs-codec - #90
Conversation
obs-hevc.c and obs-avc.c share the same NAL walk, AVCC-style conversion, priority scan and header split, differing only in how a NAL header byte is classified. - obs-codec::nal holds the walk, to_length_prefixed, packet_priority and split_headers, which take that classification as a function. - obs-codec::ffi::packet holds struct encoder_packet, the bmalloc helpers, the long-refcounted packet output and the three extract-headers outputs. Extracted from b7216309-jpg's AVC refactor so the HEVC port does not depend on the AVC port (obs-rust#90). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Rebased onto #89's head (port/obs-nal, itself on master); depends on #89 and should merge after it. Added |
obs-hevc.c and obs-avc.c share the same NAL walk, AVCC-style conversion, priority scan and header split, differing only in how a NAL header byte is classified. - obs-codec::nal holds the walk, to_length_prefixed, packet_priority and split_headers, which take that classification as a function. - obs-codec::ffi::packet holds struct encoder_packet, the bmalloc helpers, the long-refcounted packet output and the three extract-headers outputs. Extracted from b7216309-jpg's AVC refactor so the HEVC port does not depend on the AVC port (obs-rust#90). Co-Authored-By: Claude Opus 5.5 <[email protected]>
obs-hevc.c and obs-avc.c share the same NAL walk, AVCC-style conversion, priority scan and header split, differing only in how a NAL header byte is classified. - obs-codec::nal holds the walk, to_length_prefixed, packet_priority and split_headers, which take that classification as a function. - obs-codec::ffi::packet holds struct encoder_packet, the bmalloc helpers, the long-refcounted packet output and the three extract-headers outputs. Extracted from b7216309-jpg's AVC refactor so the HEVC port does not depend on the AVC port (obs-rust#90). Co-Authored-By: Claude Opus 5.5 <[email protected]>
921585b to
f608b9d
Compare
f608b9d to
8d9458c
Compare
|
Rebased onto current master, after #98 and #105, and pushed with #98 already landed the shared NAL walk and packet plumbing, so AVC is now built on it instead of carrying its own copy:
Your Commits: C test, RED (Tier 1 fails 7/8 at the Unrelated, found while running clippy for aarch64 Linux: |
2f2c32a to
44cda6f
Compare
test_avc.c compiles its own obs-avc.c for UBSan, so with ENABLE_RUST_LIBOBS=ON it would not reach a port. test_avc_parse.c links libobs only and pins the six exports: keyframe detection by the first slice, Annex B to AVCC conversion with the long reference count in front, priority, the AVCDecoderConfigurationRecord for a High-profile SPS, the 0 / copy cases of obs_parse_avc_header, and the header/SEI/ packet split with NULL outputs when empty. Co-Authored-By: Claude Opus 5.5 <[email protected]>
C ABI shims for the six exports of libobs/obs-avc.c over the shared obs-codec packet helpers (encoder_packet, bytes, bmalloc_concat, parse_packet, write_split), the oracle (obs-avc.c over the oracle copies of obs-nal.c, array-serializer.c and bitstream.c, reusing the encoder_packet oracle), rust-exports entries, and Tier 1 and Tier 3 tests, against a todo!() core: Tier 1 fails 7/8, the parity binary aborts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
obs_avc_keyframe, obs_avc_find_startcode, obs_parse_avc_packet, obs_parse_avc_packet_priority, obs_parse_avc_header and obs_extract_avc_headers move to Rust. With ENABLE_RUST_LIBOBS=ON libobs builds without obs-avc.c. The NAL walk, AVCC conversion, priority scan and header split use the shared helpers in obs-codec::nal; AVC adds its unit rating (IDR is a keyframe, priority header >> 5) and the AVCDecoderConfigurationRecord builder. The SPS reader keeps the C details: emulation-prevention bytes dropped, the Exp-Golomb leading-zero cap from obs-rust#17, uint8_t results, and SPS/PPS sizes written as uint16_t. The one intentional difference is inherited from the obs-nal port: on NULL data with size 0 these functions give empty results, where C reads address 0 in the start-code search. Co-Authored-By: Claude Opus 5.5 <[email protected]>
avc_diff compares every obs-avc C ABI entry point and the safe core with the C oracle, output buffers byte for byte, as tests/avc_parity.rs does. NULL/near-0 ranges (C UB) are excluded and never generated. Co-Authored-By: Claude Opus 5.5 <[email protected]> Local-Gate: v1 tree=7cb32b754174e9516723dce1bba46e08123dfbbb secs=266 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791664929,"gate":"rust/all/fmt","host":"linux-x86_64","key":"59c2e4d9640d08a8a1cf720efde260f91e322e6a898bb30d3ebcc1f47a8d9793","lane":"lint","parents":["db1ba2d9cf11e2a8728cb6073ae91377834753cd"],"secs":86,"stamp":"4e3871acb6985d6bf26b55d687b3fe81","tree":"7cb32b754174e9516723dce1bba46e08123dfbbb","v":1,"via":"run"} Ci-Attestation: {"at":1791664929,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"59c2e4d9640d08a8a1cf720efde260f91e322e6a898bb30d3ebcc1f47a8d9793","lane":"lint","parents":["db1ba2d9cf11e2a8728cb6073ae91377834753cd"],"secs":86,"stamp":"c3c8a03a7e6702158c60a3efa9c10dd3","tree":"7cb32b754174e9516723dce1bba46e08123dfbbb","v":1,"via":"run"} Ci-Attestation: {"at":1791664930,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"e7c176de28b46793d2ca84a7b8b3fbbd14f846ef47e62d78cb56c677277ae25c","lane":"rust-test","parents":["db1ba2d9cf11e2a8728cb6073ae91377834753cd"],"secs":44,"stamp":"051d237c4eb1c148afb7d60cd0439d9d","tree":"7cb32b754174e9516723dce1bba46e08123dfbbb","v":1,"via":"run"} Ci-Attestation: {"at":1791664930,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"b8bda407b3e19d406e9a2eafbeab5856756797649c3272970f0590494ecf8f77","lane":"tier2-linux","parents":["db1ba2d9cf11e2a8728cb6073ae91377834753cd"],"secs":136,"stamp":"78b39a9fdf34cd2badc41a832ab41245","tree":"7cb32b754174e9516723dce1bba46e08123dfbbb","v":1,"via":"run"}
|
Rebased onto master (after #98, #105 and the later ports). It now reuses #98's shared obs-codec helpers (nal walk, packet bytes/bmalloc_concat, the encoder_packet oracle), so the diff is AVC-only: 16 files, no binaries. RED→GREEN, checked with soldr's cache disabled: |
Description
Second step of the parser plan in #45: ports
libobs/obs-avc.ctoobs-codec::avc, all six exports:obs_avc_keyframe,obs_avc_find_startcode,obs_parse_avc_packet,obs_parse_avc_packet_priority,obs_parse_avc_headerandobs_extract_avc_headers. WithENABLE_RUST_LIBOBS=ONlibobs builds withoutobs-avc.c.Kept exactly as in C:
The NAL walk. Every function repeats
while (nal_start < end && !*(nal_start++));. That skips zeros and then one more byte, so units start after the first nonzero byte.nal_unitsreproduces this, including garbage before the first start code and truncated tails.Keyframes and priority. The first slice decides
obs_avc_keyframe. Inobs_parse_avc_packet, an IDR unit setskeyframebut nothing clears it, and priority is the maximum ofheader >> 5, so values up to 7 are possible.The AVCC packet has a
longreference count of 1 in front of the data: 4 bytes on Windows, 8 elsewhere.datapoints past it, as libobs's packet refcounting expects.The header record:
uint16_t, so they wrap above 65535;The SPS reader drops emulation-prevention bytes, keeps the Exp-Golomb leading-zero cap from fix(libobs): get_ue_golomb UB on a truncated SPS (1 << 32) #17, and truncates to
uint8_t.Allocation and outputs. Outputs are
bmalloced like the C serializer andDARRAYbuffers. Empty outputs ofobs_extract_avc_headersare NULL;obs_parse_avc_headerreturns 0 without touching*header.Intentional difference, inherited from #89: on NULL data with size 0 these functions give empty results. C reaches the start-code search's
end - 3wrap and reads address 0. I found it here: the first parity run crashed in the C oracle on an empty input, whose pointer is0x1. #89 now documents it.Oracle.
obs-avc.cis compiled with its calls pointed at the oracle copies ofobs-nal.c,array-serializer.candbitstream.c, so the whole call tree is the original C. It includesobs.h, which pulls in the CMake-generatedobsconfig.h, so the oracle gets a test-only stand-in (oracle/obsconfig/obsconfig.h) with placeholder values the AVC code never uses.Motivation and Context
Plan: #45 (comment). HEVC and AV1 follow.
Refs #45
How Has This Been Tested?
Windows 11, MSVC 14.44, soldr 0.9.31.
Commits:
test/cmocka/test_avc_parse.c(C characterization through libobs only). The existingtest_avc.ccompiles its ownobs-avc.cfor UBSan, so with ON it would still test C on Linux and macOS.todo!()core: Tier 1 fails 7/8, the parity binary aborts, layout passes).Tier 2: layout of
struct encoder_packet, plussizeof(long).Tier 3 (4096 cases): generated Annex B streams with every NAL type, both start-code lengths, garbage prefixes, truncated tails and emulation-prevention bytes; High-profile SPS/PPS pairs with sparse bits that reach the Exp-Golomb cap; arbitrary bytes. Every output is compared byte for byte:
encoder_packetfields, plus the refcount-prefixed data block, also with the packet parsed in place;*headerwas written;Everything is then freed with
bfree. Separate tests cover the fix(libobs): get_ue_golomb UB on a truncated SPS (1 << 32) #17 truncated-SPS case and SPS/PPS over 65535 bytes.Mutation check: 15 mutants. 14 are caught, including the 16-bit size truncation, which needed the oversized test. One survives, and it is equivalent: "skip until
01" instead of "until nonzero", because the walk always lands on a start code.Checks:
soldr cargo test --workspace --locked(42 binaries),python ci/local_gate.py --lane lint, andcargo clippy -p obs-codec -p libobs-rust --lib -- -D warningsfor x86_64/aarch64 Linux and aarch64 macOS.Types of changes
Checklist:
🤖 Generated with Claude Code