Skip to content

[IMPROVEMENT] Port sequencing.c to Rust - #2523

Open
Neo-matrix-coder wants to merge 4 commits into
CCExtractor:masterfrom
Neo-matrix-coder:port/sequencing-to-rust
Open

Neo-matrix-coder wants to merge 4 commits into
CCExtractor:masterfrom
Neo-matrix-coder:port/sequencing-to-rust

Conversation

@Neo-matrix-coder

Copy link
Copy Markdown

Summary

Ports src/lib_ccx/sequencing.c (HDCC B-frame caption reordering) to Rust. The four public C functions preserve their exact names and C ABI, delegating to the Rust implementation when Rust is enabled (#ifndef DISABLE_RUST).

What was ported

C function Rust FFI entry point
init_hdcc() ccxr_init_hdcc()
store_hdcc() ccxr_store_hdcc()
anchor_hdcc() ccxr_anchor_hdcc()
process_hdcc() ccxr_process_hdcc()

The reordering behavior is preserved: captions are buffered in SORTBUF slots indexed by sequence number relative to the current anchor frame, and process_hdcc() flushes them in display order while restoring timing->fts_now.

FFI boundary & build changes

  • src/rust/src/sequencing.rs: Exposes four #[no_mangle] pub unsafe extern "C" entry points (ccxr_*) alongside pub unsafe fn wrappers (init_hdcc, store_hdcc, anchor_hdcc, process_hdcc) for Rust callers.
  • src/lib_ccx/sequencing.c: Delegates to ccxr_* under #ifndef DISABLE_RUST and retains the verbatim original C implementation under #else. No C call sites were modified.
  • No struct duplication: All struct access goes through existing bindgen types (lib_cc_decode, encoder_ctx, cc_subtitle, and ccx_common_timing_ctx, added to the bindgen type allowlist in src/rust/build.rs). SORTBUF and per-slot capacities are derived from the generated bindings rather than hardcoded.
  • Updated Rust call sites: Switched avc/nal.rs, avc/core.rs, es/userdata.rs, es/pic.rs, and es/gop.rs from extern "C" C calls to crate::sequencing::*, removed the obsolete extern "C" declarations from src/rust/src/lib.rs, removed those functions from src/rust/build.rs, and dropped -Wl,--undefined=store_hdcc from src/CMakeLists.txt.

Behavior & defensive checks

  • Identical behavior for all valid streams.
  • Added null-pointer early returns for ctx/dec_ctx and dec_ctx->timing in process_hdcc to prevent null dereferences on malformed states.

Tests & verification

  • Added #[cfg(test)] unit tests in src/rust/src/sequencing.rs covering buffer initialization, anchor assignment/out-of-range replacement, slot mapping, overwrite-vs-append semantics, flush-on-fts change, display-order flushing, fts_now restoration, empty-slot skipping, null-timing safety, and C ABI entry points.
  • Relying on GitHub Actions CI for full Rust compilation and cargo test verification.

@ccextractor-bot

Copy link
Copy Markdown
Collaborator
CCExtractor CI platform finished running the test files on linux. 171/238 tests matched the approved output:
Report Name Tests Passed
Broken 9/13
CEA-708 2/14
DVB 0/7
DVD 3/3
DVR-MS 2/2
General 26/28
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 68/86
Teletext 0/21
WTV 12/13
XDS 32/34

67 tests do not match the approved output. That is the pass/fail verdict. Whether this branch caused it is a separate question, answered below.


Compared with the tip of master — test 10180, commit 2c1c1c6:

  • 0 pass there and fail here
  • 0 fail there and pass here
  • 0 fail on both, with different output
  • 67 fail on both, byte for byte the same

Compared with the commit this branch was cut from: the same run as the tip of master (test 10180), so the comparison above already covers it.


No test changes behaviour relative to the tip of master: every failure above fails there too, byte for byte. The approved output for those tests is out of date, which is a baseline to review rather than a regression in this branch.

@ccextractor-bot

Copy link
Copy Markdown
Collaborator
CCExtractor CI platform finished running the test files on windows. 171/238 tests matched the approved output:
Report Name Tests Passed
Broken 9/13
CEA-708 2/14
DVB 0/7
DVD 3/3
DVR-MS 2/2
General 26/28
Hardsubx 1/1
Hauppage 3/3
MP4 3/3
NoCC 10/10
Options 68/86
Teletext 0/21
WTV 12/13
XDS 32/34

67 tests do not match the approved output. That is the pass/fail verdict. Whether this branch caused it is a separate question, answered below.


Compared with the tip of master — test 10179, commit f56427e:

  • 0 pass there and fail here
  • 0 fail there and pass here
  • 0 fail on both, with different output
  • 67 fail on both, byte for byte the same

Compared with the commit this branch was cut from — test 10181, commit 2c1c1c6:

  • 0 pass there and fail here
  • 0 fail there and pass here
  • 0 fail on both, with different output
  • 67 fail on both, byte for byte the same

No test changes behaviour relative to the tip of master: every failure above fails there too, byte for byte. The approved output for those tests is out of date, which is a baseline to review rather than a regression in this branch.

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.

2 participants