Skip to content

Commit

Permalink
feat: Add ccxr_dtvcc_init and ccxr_dtvcc_free functions
Browse files Browse the repository at this point in the history
  • Loading branch information
IshanGrover2004 committed Feb 22, 2024
1 parent ffbf138 commit 440ecfa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lib_ccx/ccx_dtvcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ void dtvcc_process_data(struct dtvcc_ctx *dtvcc,
dtvcc_ctx *dtvcc_init(ccx_decoder_dtvcc_settings *opts);
void dtvcc_free(dtvcc_ctx **);

extern void *ccxr_dtvcc_init(struct ccx_decoder_dtvcc_settings *settings_dtvcc);
extern void ccxr_dtvcc_free(void *dtvcc_rust);

#endif //CCEXTRACTOR_CCX_DTVCC_H
29 changes: 29 additions & 0 deletions src/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,35 @@ pub extern "C" fn ccxr_init_logger() {
.init();
}

/// Create a `dtvcc_rust`
///
/// # SAFETY:
/// The following should not be `NULL`:
/// - opts
/// - opts.report
/// - opts.timing
#[no_mangle]
extern "C" fn ccxr_dtvcc_init<'a>(
dtvcc_settings_ptr: *mut ccx_decoder_dtvcc_settings,
) -> *mut Dtvcc<'a> {
let mut opts = unsafe { dtvcc_settings_ptr.as_mut() }.expect("Didn't get dtvcc pointer");
Box::into_raw(Box::new(Dtvcc::new(opts)))
}

/// Frees `dtvcc_rust`
///
/// SAFETY:
/// The following should not be `NULL`:
/// - dtvcc_rust
/// - dtvcc_rust.decoders[i] if dtvcc_rust.services_active[i] is true
/// - dtvcc_rust.decoders[i].windows[j].rows[k] if
/// dtvcc_rust.decoders[i].windows[j].memory_reserved is true
/// - dtvcc_rust.decoders[i].tv
#[no_mangle]
extern "C" fn ccxr_dtvcc_free(dtvcc_rust: *mut Dtvcc) {
unsafe { dtvcc_rust.drop_in_place() };
}

/// Process cc_data
///
/// # Safety
Expand Down

0 comments on commit 440ecfa

Please sign in to comment.