Port C(ccx_encoder_srt.c) to Rust(ccxr_encoder_srt.rs)#1927
Port C(ccx_encoder_srt.c) to Rust(ccxr_encoder_srt.rs)#1927VivianVRodrigues wants to merge 11 commits intoCCExtractor:masterfrom
Conversation
- Renamed CcxSWriteRust to ccxr_s_write for consistency - Renamed EncoderCtxRust to ccxr_encoder_ctx - Changed out field from raw pointer to Vec<ccxr_s_write> - Unified encode_line functions into single optimal version - Added ccxr_write_cc_bitmap_as_srt (OCR stub) - Added ccxr_write_cc_subtitle_as_srt with proper cleanup - Added ccxr_write_cc_buffer_as_srt using Rust context - Updated C code to call Rust implementations - Improved type safety and eliminated unsafe pointer dereferencing
…ompatibility - wrote_ccd_channel_header: i8 -> u8 - millis_separator: i8 -> u8 - Added type casts in from_ctype conversion This fixes compilation errors on Linux where char is unsigned by default.
The Rust function was calling C which called Rust again, causing infinite recursion. Removed the wrapper since OCR functionality stays in C for now.
cfsmp3
left a comment
There was a problem hiding this comment.
Thanks for working on porting the SRT encoder to Rust! However, the build currently fails on Linux.
The issue is in utility.h - you've added function declarations that use struct encoder_ctx, struct cc_subtitle, and struct eia608_screen, but these types aren't visible at that point in the include chain.
To fix this, you have a few options:
-
Add forward declarations at the top of
utility.h:struct encoder_ctx; struct cc_subtitle; struct eia608_screen;
-
Or move these declarations to a header that's included after the struct definitions (perhaps
ccx_encoders_common.hwhereencoder_ctxis defined)
Please fix the build and we can continue the review. Thanks!
|
@carlos Thanks for the review! |
|
Hi @VivianVRodrigues, thanks for the explanation! Could you push the changes you mentioned so we can verify the build works? The CI needs to run on the updated code to confirm the forward declarations fix the build issue. |
|
Hello @cfsmp3, I have pushed the changes ! |
|
Closed due to inactivity, feel free to submit a new one (make sure it's based off master) when you are ready to resume work. |
- utility.h: keep Rust forward declarations and DISABLE_RUST block with SRT exports; keep rest from master - Cargo.toml: keep libc from rust_encoder_upd2; keep serial_test, encoding_rs 0.8.35, and rsmpeg target deps from master
Overview
This branch migrates the SRT encoder to Rust and refactors the encoder context. 13 files changed: 872 insertions, 101 deletions.
Main Changes
New Rust SRT encoder implementation(ccx_encoder_srt rewrite)
Added src/rust/src/encoder/ccxr_encoder_srt.rs (285 lines)
Functions: ccxr_write_stringz_srt, ccxr_write_cc_subtitle_as_srt, ccxr_write_cc_buffer_as_srt
New encoder context module
Added src/rust/src/libccxr_exports/encoder_ctx.rs (467 lines)
Safe Rust wrapper for C encoder_ctx
Conversion functions: copy_encoder_ctx_c_to_rust, copy_encoder_ctx_rust_to_c
Rust struct ccxr_encoder_ctx with Vec<ccxr_s_write> for file handles
C code integration
Modified src/lib_ccx/ccx_encoders_srt.c
Added conditional Rust calls (wrapped in #ifndef DISABLE_RUST)
Functions delegate to Rust when Rust is enabled:
write_stringz_as_srt → ccxr_write_stringz_srt
write_cc_subtitle_as_srt → ccxr_write_cc_subtitle_as_srt
write_cc_buffer_as_srt → ccxr_write_cc_buffer_as_srt
Refactored common encoder utilities to take Rust struct instead of C
Modified src/rust/src/encoder/common.rs
Refactored encode_line to take ccxr_encoder_ctx(Rust) instead of encoder_ctx(C)
Refactored write_subtitle_file_footer_rust to use ccxr_encoder_ctx(Rust) instead of encoder_ctx(C)
Build system updates(build related to port )
Updated src/rust/Cargo.toml and Cargo.lock (new dependencies)
Updated src/rust/build.rs (build configuration)
Updated src/rust/wrapper.h (C bindings)
Updated src/lib_ccx/utility.h (utility declarations)
Local testing on Linux
Test data : https://drive.google.com/drive/folders/1qPm8ImCPg_3nK2kH9aWWWWliqJmwwotR?usp=sharing