Repository navigation
rust: Port obs-nal.c to a new obs-codec crate - #89
Merged
Merged
Conversation
This was referenced Oct 10, 2026
Pins obs-nal.c before the Rust port: the first 00 00 01 is returned, moved back over one preceding zero (the 4-byte form), or end when there is none. A start code in the last three bytes is not reported, and the result does not depend on the buffer's alignment, which the FFmpeg word-at-a-time search could get wrong. Co-Authored-By: Claude Opus 5.5 <[email protected]>
New crate for the libobs codec bitstream helpers (obs-nal.c, then obs-avc.c, obs-hevc.c and obs-av1.c, obs-rust#45), linked into libobs-rust and scanned by the export-list test. This adds the obs_nal_find_startcode shim, the oracle wrapper, the rust-exports.txt entry, and Tier 1 and Tier 3 tests, against a todo!() core: Tier 1 fails 0/6 and the parity binary aborts on its first call. Co-Authored-By: Claude Opus 5.5 <[email protected]>
obs_nal_find_startcode moves to Rust. With ENABLE_RUST_LIBOBS=ON libobs builds without obs-nal.c; obs-avc.c, obs-hevc.c and the outputs call the Rust shim. The C search is FFmpeg's ff_avc_find_startcode_internal, which reads a word at a time after an alignment prologue. It reports the earliest 00 00 01 at an index i with i + 3 < len, so the port is a byte scan over those positions with the same result at any alignment. One preceding zero is then folded in for the 4-byte form, as in C. No intentional differences. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Found while testing obs-avc.c: with fewer than three bytes, ff_avc_find_startcode_internal computes end - 3 before the start of the range. For a pointer within 3 bytes of address 0, such as obs_nal_find_startcode(NULL, NULL), that wraps around and the C code reads address 0. The port returns end for any empty or short range; this records that as an intentional difference and tests the NULL case on the Rust side. Co-Authored-By: Claude Opus 5.5 <[email protected]> Local-Gate: v1 tree=ae1fda2792e439ac5e5d1a01f01e3a612ccfc279 secs=41 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791648241,"gate":"rust/all/fmt","host":"linux-x86_64","key":"2d109f93b2e31ffe0d1dd999a15ccb9b998281648722ee2878384780361a4a03","lane":"lint","parents":["55a68c589c0d6294722dbddbb573fb577dd417ba"],"secs":11,"stamp":"ce654f2dc5209b6fe1ff31703867009a","tree":"ae1fda2792e439ac5e5d1a01f01e3a612ccfc279","v":1,"via":"run"} Ci-Attestation: {"at":1791648241,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"2d109f93b2e31ffe0d1dd999a15ccb9b998281648722ee2878384780361a4a03","lane":"lint","parents":["55a68c589c0d6294722dbddbb573fb577dd417ba"],"secs":11,"stamp":"3b36e936ade3537043a1bb3a477c5dca","tree":"ae1fda2792e439ac5e5d1a01f01e3a612ccfc279","v":1,"via":"run"} Ci-Attestation: {"at":1791648241,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"9dbc6bf572a59a51c76bd693698a242161f8963470386f826ae5cc7c11582301","lane":"rust-test","parents":["55a68c589c0d6294722dbddbb573fb577dd417ba"],"secs":7,"stamp":"7a08955471126c471000a8750127f16a","tree":"ae1fda2792e439ac5e5d1a01f01e3a612ccfc279","v":1,"via":"run"} Ci-Attestation: {"at":1791648241,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"757c21262fdaa3c63aed638e5bbad8da49f2e27116583a3bb7a927fdfc026a4c","lane":"tier2-linux","parents":["55a68c589c0d6294722dbddbb573fb577dd417ba"],"secs":23,"stamp":"8fc39a7ad429c3c4326320c17b41ee88","tree":"ae1fda2792e439ac5e5d1a01f01e3a612ccfc279","v":1,"via":"run"}
Member
|
Rebased onto master (after #75 and #103). The only conflict was |
6 tasks done
zackees
added a commit
that referenced
this pull request
Oct 10, 2026
…43) Phase 3 ports of libobs/util into the obs-util crate, each with a safe core, a C ABI shim, Tier 1 tests, a layout test where a struct crosses the ABI, and a proptest parity suite against the original C built as an oracle. ENABLE_RUST_LIBOBS=ON drops the matching C sources from libobs. - utf8: hidden and non-Windows only (Windows keeps the C utf8.c). - lexer.c: follows master's C, including the #48 strref ordering. - text-lookup: no longer crashes on an opening quote at end of line; the shim returns false for a NULL lookup. - dstr: follows master's #46/#47 fixes; strlist_split takes a NUL separator. Wide-char and printf helpers stay in dstr-libc.c. - bmem: Windows _aligned_* branch and the allocation counter. The oracle vendors uthash 2.3.0 (BSD-1-Clause) for text-lookup.c, since the Rust test runners have no uthash package. Refs #43 Rebased onto master after #61 (base), #66 (file-serializer) and #85 (real utf8.c in the oracle): the oracle's utf8.c/platform_conv_host.c now use oracle_* utf8 names so they no longer clash with the Rust shims; the dstr-conversion oracle test moved to obs-util and calls oracle_dstr_*; duplicate bcrash/os_fopen/bmemdup/os_*_ptr stand-ins were dropped in favour of master's base-variadic.c, file_serializer_host.c and platform_conv_host.c; utf8 shims are listed in rust-hidden.txt; the vendored uthash is excluded from clang-format. Rebased again onto master after #82/#83/#87/#97/#89: oracle build.rs keeps video_fourcc.c/task.c and drops the direct util/utf8.c (oracle/utf8.c already compiles it under oracle_* names, which platform_conv_host.c and #82's file_serializer_host.c use). Co-Authored-By: Claude Opus 5.5 <[email protected]> Local-Gate: v1 tree=21926a8ffae3e3de7be0daaa6a529723f7497869 secs=50 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791654631,"gate":"rust/all/fmt","host":"linux-x86_64","key":"6277551b1197bae61a0a3563f9047b17c1e6d651b5cab860d7def119d1cbc569","lane":"lint","parents":["5502191074629b7f2e51dda6d89fa601ce22a01d"],"secs":12,"stamp":"92e0f34f8074164ecb0208cbd6f8ab26","tree":"21926a8ffae3e3de7be0daaa6a529723f7497869","v":1,"via":"run"} Ci-Attestation: {"at":1791654631,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"6277551b1197bae61a0a3563f9047b17c1e6d651b5cab860d7def119d1cbc569","lane":"lint","parents":["5502191074629b7f2e51dda6d89fa601ce22a01d"],"secs":12,"stamp":"4d3ace010dbaab4ed252006d22ec59aa","tree":"21926a8ffae3e3de7be0daaa6a529723f7497869","v":1,"via":"run"} Ci-Attestation: {"at":1791654631,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"c6b1b608fc16817859a28490ada2b38a926103a0094ec23e3bb7d594979793d7","lane":"rust-test","parents":["5502191074629b7f2e51dda6d89fa601ce22a01d"],"secs":18,"stamp":"d73d3c14d2d133a677293234ca581902","tree":"21926a8ffae3e3de7be0daaa6a529723f7497869","v":1,"via":"run"} Ci-Attestation: {"at":1791654631,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"d05a3c8a53e501ee21ca4d301b5ba053c0dccd6b86b39d46af0486606d1d851e","lane":"tier2-linux","parents":["5502191074629b7f2e51dda6d89fa601ce22a01d"],"secs":20,"stamp":"7dedfefe7e32a22a666716a1fd3efcb5","tree":"21926a8ffae3e3de7be0daaa6a529723f7497869","v":1,"via":"run"}
zackees
added a commit
that referenced
this pull request
Oct 10, 2026
…43) Phase 3 ports of libobs/util into the obs-util crate, each with a safe core, a C ABI shim, Tier 1 tests, a layout test where a struct crosses the ABI, and a proptest parity suite against the original C built as an oracle. ENABLE_RUST_LIBOBS=ON drops the matching C sources from libobs. - utf8: hidden and non-Windows only (Windows keeps the C utf8.c). - lexer.c: follows master's C, including the #48 strref ordering. - text-lookup: no longer crashes on an opening quote at end of line; the shim returns false for a NULL lookup. - dstr: follows master's #46/#47 fixes; strlist_split takes a NUL separator. Wide-char and printf helpers stay in dstr-libc.c. - bmem: Windows _aligned_* branch and the allocation counter. The oracle vendors uthash 2.3.0 (BSD-1-Clause) for text-lookup.c, since the Rust test runners have no uthash package. Refs #43 Rebased onto master after #61 (base), #66 (file-serializer) and #85 (real utf8.c in the oracle): the oracle's utf8.c/platform_conv_host.c now use oracle_* utf8 names so they no longer clash with the Rust shims; the dstr-conversion oracle test moved to obs-util and calls oracle_dstr_*; duplicate bcrash/os_fopen/bmemdup/os_*_ptr stand-ins were dropped in favour of master's base-variadic.c, file_serializer_host.c and platform_conv_host.c; utf8 shims are listed in rust-hidden.txt; the vendored uthash is excluded from clang-format. Rebased again onto master after #82/#83/#87/#97/#89/#98: oracle build.rs keeps video_fourcc.c/task.c and drops the direct util/utf8.c (oracle/utf8.c already compiles it under oracle_* names, which platform_conv_host.c and #82's file_serializer_host.c use). Co-Authored-By: Claude Opus 5.5 <[email protected]> Local-Gate: v1 tree=1b426910df018155f8be2a2ed4dc5fd8b42d68a0 secs=17 lanes=lint:reused@12a747713c0b,rust-test:reused@8f0383f521c9,tier2-linux:run Ci-Attestation: {"at":1791655075,"gate":"rust/all/fmt","host":"linux-x86_64","key":"12a747713c0b7b727bbfb48e33e2c7c1aa431a3c77062fee88a56e5821c8b6c5","lane":"lint","parents":["84c80bce3c20e772d563e2c85b32ed5ac51020b4"],"secs":null,"stamp":"58719f015cf7d13d7f971c86c36023dd","tree":"1b426910df018155f8be2a2ed4dc5fd8b42d68a0","v":1,"via":"reused"} Ci-Attestation: {"at":1791655075,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"12a747713c0b7b727bbfb48e33e2c7c1aa431a3c77062fee88a56e5821c8b6c5","lane":"lint","parents":["84c80bce3c20e772d563e2c85b32ed5ac51020b4"],"secs":null,"stamp":"42c3a2e402903d1da67f91e332763625","tree":"1b426910df018155f8be2a2ed4dc5fd8b42d68a0","v":1,"via":"reused"} Ci-Attestation: {"at":1791655075,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"8f0383f521c9857941f5429d53f8403e48869775747f8ce4edeee1af4e935da8","lane":"rust-test","parents":["84c80bce3c20e772d563e2c85b32ed5ac51020b4"],"secs":null,"stamp":"814d385ae14911c99b750eff7d8faa6a","tree":"1b426910df018155f8be2a2ed4dc5fd8b42d68a0","v":1,"via":"reused"} Ci-Attestation: {"at":1791655401,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"2e94b41fc041e0c98bd1709f7ab30cb7f5b5b835b799b4c3abb2c5414d4b62ec","lane":"tier2-linux","parents":["84c80bce3c20e772d563e2c85b32ed5ac51020b4"],"secs":17,"stamp":"e6e3337d94f8a4dbafc4a9892b369084","tree":"1b426910df018155f8be2a2ed4dc5fd8b42d68a0","v":1,"via":"run"}
zackees
added a commit
that referenced
this pull request
Oct 10, 2026
…43) Phase 3 ports of libobs/util into the obs-util crate, each with a safe core, a C ABI shim, Tier 1 tests, a layout test where a struct crosses the ABI, and a proptest parity suite against the original C built as an oracle. ENABLE_RUST_LIBOBS=ON drops the matching C sources from libobs. - utf8: hidden and non-Windows only (Windows keeps the C utf8.c). - lexer.c: follows master's C, including the #48 strref ordering. - text-lookup: no longer crashes on an opening quote at end of line; the shim returns false for a NULL lookup. - dstr: follows master's #46/#47 fixes; strlist_split takes a NUL separator. Wide-char and printf helpers stay in dstr-libc.c. - bmem: Windows _aligned_* branch and the allocation counter. The oracle vendors uthash 2.3.0 (BSD-1-Clause) for text-lookup.c, since the Rust test runners have no uthash package. Refs #43 Rebased onto master after #61 (base), #66 (file-serializer) and #85 (real utf8.c in the oracle): the oracle's utf8.c/platform_conv_host.c now use oracle_* utf8 names so they no longer clash with the Rust shims; the dstr-conversion oracle test moved to obs-util and calls oracle_dstr_*; duplicate bcrash/os_fopen/bmemdup/os_*_ptr stand-ins were dropped in favour of master's base-variadic.c, file_serializer_host.c and platform_conv_host.c; utf8 shims are listed in rust-hidden.txt; the vendored uthash is excluded from clang-format. Rebased again onto master after #82/#83/#87/#97/#89/#98/#88: oracle build.rs keeps video_fourcc.c/task.c and drops the direct util/utf8.c (oracle/utf8.c already compiles it under oracle_* names, which platform_conv_host.c and #82's file_serializer_host.c use). Co-Authored-By: Claude Opus 5.5 <[email protected]> Local-Gate: v1 tree=44ac22e2f9bf9093f2a87bc1c0860393942c7f05 secs=31 lanes=lint:reused@9b0282a9e1c3,rust-test:reused@e3680ff66806,tier2-linux:run Ci-Attestation: {"at":1791656844,"gate":"rust/all/fmt","host":"linux-x86_64","key":"9b0282a9e1c35c80eae0d4f0c7540b1c3b1c9f193daad522570bc7b20e609cdc","lane":"lint","parents":["07223a5abc85d40d9b7c016092ce37a672aca501"],"secs":null,"stamp":"ed3cee40895adfa7780a781e7ead1f4d","tree":"44ac22e2f9bf9093f2a87bc1c0860393942c7f05","v":1,"via":"reused"} Ci-Attestation: {"at":1791656844,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"9b0282a9e1c35c80eae0d4f0c7540b1c3b1c9f193daad522570bc7b20e609cdc","lane":"lint","parents":["07223a5abc85d40d9b7c016092ce37a672aca501"],"secs":null,"stamp":"9bde047cbb6c054fa18fa8143826c0c7","tree":"44ac22e2f9bf9093f2a87bc1c0860393942c7f05","v":1,"via":"reused"} Ci-Attestation: {"at":1791656844,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"e3680ff66806191a1385606c7996530d1becc162ef5a3444eeefce614a7d0c02","lane":"rust-test","parents":["07223a5abc85d40d9b7c016092ce37a672aca501"],"secs":null,"stamp":"46cf777b2d672af2f62536e2d4132bf2","tree":"44ac22e2f9bf9093f2a87bc1c0860393942c7f05","v":1,"via":"reused"} Ci-Attestation: {"at":1791657116,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"99939507781ddefb1aa7855e1a0c9b4af9092524f38999d7db36a74a20f1ccce","lane":"tier2-linux","parents":["07223a5abc85d40d9b7c016092ce37a672aca501"],"secs":31,"stamp":"8164638665d4208fabc4b0a768fbc870","tree":"44ac22e2f9bf9093f2a87bc1c0860393942c7f05","v":1,"via":"run"}
zackees
added a commit
that referenced
this pull request
Oct 10, 2026
…43) Phase 3 ports of libobs/util into the obs-util crate, each with a safe core, a C ABI shim, Tier 1 tests, a layout test where a struct crosses the ABI, and a proptest parity suite against the original C built as an oracle. ENABLE_RUST_LIBOBS=ON drops the matching C sources from libobs. - utf8: hidden and non-Windows only (Windows keeps the C utf8.c). - lexer.c: follows master's C, including the #48 strref ordering. - text-lookup: no longer crashes on an opening quote at end of line; the shim returns false for a NULL lookup. - dstr: follows master's #46/#47 fixes; strlist_split takes a NUL separator. Wide-char and printf helpers stay in dstr-libc.c. - bmem: Windows _aligned_* branch and the allocation counter. The oracle vendors uthash 2.3.0 (BSD-1-Clause) for text-lookup.c, since the Rust test runners have no uthash package. Refs #43 Rebased onto master after #61 (base), #66 (file-serializer) and #85 (real utf8.c in the oracle): the oracle's utf8.c/platform_conv_host.c now use oracle_* utf8 names so they no longer clash with the Rust shims; the dstr-conversion oracle test moved to obs-util and calls oracle_dstr_*; duplicate bcrash/os_fopen/bmemdup/os_*_ptr stand-ins were dropped in favour of master's base-variadic.c, file_serializer_host.c and platform_conv_host.c; utf8 shims are listed in rust-hidden.txt; the vendored uthash is excluded from clang-format. Rebased again onto master after #82/#83/#87/#97/#89/#98/#88/#105: oracle build.rs keeps video_fourcc.c/task.c and drops the direct util/utf8.c (oracle/utf8.c already compiles it under oracle_* names, which platform_conv_host.c and #82's file_serializer_host.c use). Co-Authored-By: Claude Opus 5.5 <[email protected]> Local-Gate: v1 tree=58f2156a689831720a1e6ad9004041e400917579 secs=135 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791658556,"gate":"rust/all/fmt","host":"linux-x86_64","key":"e533312cff231c50944045005e90c2b48ce1920b317c9037a705bfda5b49ef4c","lane":"lint","parents":["930903b5e8c0cac6cec54edd05abeaacb825637c"],"secs":17,"stamp":"a33efc3cd6c98f3fbd2fa57e9a61a281","tree":"58f2156a689831720a1e6ad9004041e400917579","v":1,"via":"run"} Ci-Attestation: {"at":1791658556,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"e533312cff231c50944045005e90c2b48ce1920b317c9037a705bfda5b49ef4c","lane":"lint","parents":["930903b5e8c0cac6cec54edd05abeaacb825637c"],"secs":17,"stamp":"fb2d0a58bcefb05085a4b512fc916740","tree":"58f2156a689831720a1e6ad9004041e400917579","v":1,"via":"run"} Ci-Attestation: {"at":1791658556,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"1a00cb7a8eb7b67b33a108e748711133d604e544b254813435cc1ca5ea24cd26","lane":"rust-test","parents":["930903b5e8c0cac6cec54edd05abeaacb825637c"],"secs":22,"stamp":"d80b75173a27c995da2676193fa36904","tree":"58f2156a689831720a1e6ad9004041e400917579","v":1,"via":"run"} Ci-Attestation: {"at":1791658556,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"a950373231b455174e5c031fe578e1e48c61e04f0387195a7ddc0e265e371e15","lane":"tier2-linux","parents":["930903b5e8c0cac6cec54edd05abeaacb825637c"],"secs":96,"stamp":"f1c2d81609277e26492a5a3f3553cd9c","tree":"58f2156a689831720a1e6ad9004041e400917579","v":1,"via":"run"}
10 of 22 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
First step of the parser plan in #45: ports
libobs/obs-nal.c(obs_nal_find_startcode, the Annex B start-code search thatobs-avc.c,obs-hevc.cand the outputs call) into a new crate,rust/obs-codec. WithENABLE_RUST_LIBOBS=ONlibobs builds withoutobs-nal.c.The C function is FFmpeg's
ff_avc_find_startcode_internal: a byte prologue up to 4-byte alignment, a word-at-a-time scan using thehaszerotrick, and a byte tail. It reports the earliest00 00 01at an indexiwithi + 3 < len, whatever the alignment, so the port is a plain byte scan over those positions. Then, as in C, one preceding zero is folded in, so a 4-byte00 00 00 01code is found at its first byte.One intentional difference (found while testing the AVC port on top of this): with fewer than three bytes the C search computes
end - 3, before the start of the range. For a pointer within 3 bytes of address 0, such asobs_nal_find_startcode(NULL, NULL), that wraps around and the C code reads address 0. With a real heap pointer it is harmless. The port returnsendfor any empty or short range. Commit ffa8db8 records this in the README and the parity file, and tests the NULL case on the Rust side.One C behavior worth knowing, pinned by the tests: a start code in the last three bytes (nothing after it) is not reported.
obs-codecis wired intolibobs-rust, andexport_list.rsnow requires it to be scanned. It will hold the AVC, HEVC and AV1 ports next.Motivation and Context
Phase 5 parser item of #45 (plan: #45 (comment)).
obs-avc.ccomes next and builds on this.Refs #45
How Has This Been Tested?
Windows 11, MSVC 14.44, soldr 0.9.31.
test/cmocka/test_nal.c(C characterization: 3- and 4-byte codes, the zero-run rule, no code, the last-three-bytes rule, and every position at 8 alignments), then RED (todo!()core: Tier 1 fails 0/6, the parity binary aborts), then GREEN.test_nal.cexpectations, checked against the oracle since cmocka does not run here.len, last match instead of first.soldr cargo test --workspace --locked(39 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