Repository navigation
rust: Port obs-hevc.c to obs-codec - #98
Conversation
74969fb to
c774270
Compare
|
Rebased onto #89 (obs-nal, rebased on master) and made independent of #90 (obs-avc). obs-hevc.c calls no AVC code, so the shared NAL walk and packet helpers now come in their own commit, and the Fixed the CI failure in all 3 Tier 2 jobs: RED: at 7a43416, Tier 1 Added a cargo-fuzz differential target, The local gate passed and the commit is stamped. CI is green. |
c774270 to
e612457
Compare
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]>
Pins the four exports of obs-hevc.c before the Rust port: - keyframes are decided by the first unit of type 23 or below, and are true for IRAP types 16..23; reserved VCL types 24..31 are skipped; - Annex B to length-prefixed conversion with the long reference count in front; - priorities: IRAP highest, the sub-layer reference types high, the rest disposable; - the VPS/SPS/PPS and prefix/suffix SEI split. Built only with ENABLE_HEVC, like obs-hevc.c. Co-Authored-By: Claude Opus 5.5 <[email protected]>
C ABI shims for the four exports of libobs/obs-hevc.c on the shared packet plumbing, the oracle (obs-hevc.c over the oracle copies of obs-nal.c and array-serializer.c), rust-exports.txt entries, and Tier 1 and Tier 3 tests, against a todo!() core: Tier 1 fails 0/5 and the parity binary aborts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
obs_hevc_keyframe, obs_parse_hevc_packet, obs_parse_hevc_packet_priority and obs_extract_hevc_headers move to Rust. libobs builds obs-hevc.c only with ENABLE_HEVC and without ENABLE_RUST_LIBOBS. The port is the HEVC classification on the NAL walk and packet helpers shared with the AVC port: - the unit type is (header & 0x7F) >> 1; - keyframes are decided by the first unit of type 23 or below, so the reserved VCL types 24..31 are skipped; - IRAP types are keyframes with the highest priority, the sub-layer reference types are high, the rest disposable; - VPS/SPS/PPS units are headers and both SEI kinds are SEI. Intentional differences: - NULL data with size 0 gives empty results, inherited from obs-nal. - With ENABLE_HEVC=OFF and ENABLE_RUST_LIBOBS=ON, libobs still exports the four HEVC functions, which the C build leaves out. Co-Authored-By: Claude Opus 5.5 <[email protected]>
rust/obs-codec/fuzz/hevc_diff runs every exported obs-hevc.c function on fuzzer input through the Rust port and the C oracle and aborts on any difference in return values, output fields or output buffers. It is a standalone crate built only by cargo fuzz (nightly). Excluded: NULL and near-address-0 ranges (C UB in the start-code search); the input is always copied into a real allocation. Co-Authored-By: Claude Opus 5.5 <[email protected]> Local-Gate: v1 tree=16e2a64e965bcb7b6a8583ee0c91465a01d93982 secs=58 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791653555,"gate":"rust/all/fmt","host":"linux-x86_64","key":"2093a35250a125a260b36500294bc49c632cb4d69691c32066b86a03111f6b1a","lane":"lint","parents":["b1b1a5032bcd1105ca9bd81c757bcb1d69078a41"],"secs":13,"stamp":"3fb9e1684cb1894b64e3c01b72551e54","tree":"16e2a64e965bcb7b6a8583ee0c91465a01d93982","v":1,"via":"run"} Ci-Attestation: {"at":1791653555,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"2093a35250a125a260b36500294bc49c632cb4d69691c32066b86a03111f6b1a","lane":"lint","parents":["b1b1a5032bcd1105ca9bd81c757bcb1d69078a41"],"secs":13,"stamp":"cc9775fdac5e407a552bb58d4e05fac7","tree":"16e2a64e965bcb7b6a8583ee0c91465a01d93982","v":1,"via":"run"} Ci-Attestation: {"at":1791653555,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"749a77db2d82a9a0e79d9beb39556909d11715f257899d4b386828847c512609","lane":"rust-test","parents":["b1b1a5032bcd1105ca9bd81c757bcb1d69078a41"],"secs":16,"stamp":"b262a46b68bc6339c75892724105e541","tree":"16e2a64e965bcb7b6a8583ee0c91465a01d93982","v":1,"via":"run"} Ci-Attestation: {"at":1791653555,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"62cc2e8b3f7c8a40c94652acd830c605def12acad1f905afe0050b41add72c7a","lane":"tier2-linux","parents":["b1b1a5032bcd1105ca9bd81c757bcb1d69078a41"],"secs":29,"stamp":"2e21993a939ba43cd1d063fb8dabfe3d","tree":"16e2a64e965bcb7b6a8583ee0c91465a01d93982","v":1,"via":"run"}
e612457 to
5dc0fae
Compare
|
Rebased onto current master, after #97 and #83. Both sides are kept in the oracle and README. Fixed the clang-format failure: an earlier rebase of mine had accidentally committed |
…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"}
…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"}
…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"}
Description
Third step of the parser plan in #45: ports
libobs/obs-hevc.ctoobs-codec::hevc, all four exports:obs_hevc_keyframe,obs_parse_hevc_packet,obs_parse_hevc_packet_priorityandobs_extract_hevc_headers. libobs now buildsobs-hevc.conly withENABLE_HEVCand withoutENABLE_RUST_LIBOBS.Commit 1, refactor, no behavior change.
obs-hevc.crepeatsobs-avc.c's NAL walk, length-prefixed conversion, priority scan and header split, and differs only in how a NAL header byte is classified. These move out of the AVC port:obs-codec::nal: the walk,to_length_prefixed,packet_priorityandsplit_headers, each taking the classification as a function;obs-codec::ffi::packet:struct encoder_packet, thebmallocoutputs and thelong-refcounted packet block.The AVC tests are unchanged and pass.
Commits 2–4: HEVC (C characterization test, then RED, then GREEN). The port is only the classification:
(header & 0x7F) >> 1.obs_hevc_keyframeis decided by the first unit of type ≤ 23 and is true for the IRAP types 16..23. The reserved VCL types 24..31 are skipped, like parameter sets, as in C.OBS_NAL_PRIORITY_HIGHEST;TRAIL_R,TSA_R,STSA_R,RADL_RandRASL_RareHIGH; everything else isDISPOSABLE. The packet's own priority is a floor.Intentional differences:
ENABLE_HEVC=OFFandENABLE_RUST_LIBOBS=ON, libobs still exports the four HEVC functions, which the C build leaves out. It is the non-default configuration, and Tier 2 builds with HEVC on. If you want the export sets to match there too, a Corrosion feature (FEATURES hevcwhenENABLE_HEVC) plus a conditionalrust-exports.txtentry would do it. I left that out to keep this PR small.Motivation and Context
Plan: #45 (comment). AV1 is last.
Refs #45
How Has This Been Tested?
Windows 11, MSVC 14.44, soldr 0.9.31.
test/cmocka/test_hevc.cis new and built only withENABLE_HEVC, likeobs-hevc.c. It covers keyframes (IDR, CRA, reserved IRAP 23, a leadingTRAIL_R, VPS only, skipped type 24), conversion with the refcount prefix, priorities, and the VPS/SPS/PPS and SEI split. I traced its expectations against the C, since cmocka does not run here.every_unit_type_matches_c_oracleruns each of the 64 types alone and before an IDR.BLA_W_LPnot a keyframe, type 23 not rated IRAP,RASL_Rnot high, high = 1, suffix SEI in the packet, VPS in the packet, IRAP not a keyframe.soldr cargo test --workspace --locked(44 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