From 22f568451de4954cb70f467fcd8ff1b383e9ae9b Mon Sep 17 00:00:00 2001 From: Archit Bhonsle Date: Wed, 22 Mar 2023 13:00:06 +0530 Subject: [PATCH] Exporting `ccxr_process_data` from Rust and using in `mp4.c` --- src/lib_ccx/ccx_decoders_structs.h | 85 +++++++++++++++--------------- src/lib_ccx/mp4.c | 10 ++++ src/rust/src/lib.rs | 11 ++++ 3 files changed, 64 insertions(+), 42 deletions(-) diff --git a/src/lib_ccx/ccx_decoders_structs.h b/src/lib_ccx/ccx_decoders_structs.h index 75de7924b..da6b3ace6 100644 --- a/src/lib_ccx/ccx_decoders_structs.h +++ b/src/lib_ccx/ccx_decoders_structs.h @@ -11,10 +11,11 @@ #define CCX_DECODER_608_SCREEN_ROWS 15 #define CCX_DECODER_608_SCREEN_WIDTH 32 #define MAXBFRAMES 50 -#define SORTBUF (2 * MAXBFRAMES + 1) +#define SORTBUF (2*MAXBFRAMES+1) + /* flag raised when end of display marker arrives in Dvb Subtitle */ -#define SUB_EOD_MARKER (1 << 0) +#define SUB_EOD_MARKER (1 << 0 ) struct cc_bitmap { int x; @@ -76,13 +77,13 @@ enum ccx_decoder_608_color_code }; /** - * This structure have fields which need to be ignored according to format, - * for example if format is SFORMAT_XDS then all fields other then - * xds related (xds_str, xds_len and cur_xds_packet_class) should be - * ignored and not to be dereferenced. - * - * TODO use union inside struct for each kind of fields - */ +* This structure have fields which need to be ignored according to format, +* for example if format is SFORMAT_XDS then all fields other then +* xds related (xds_str, xds_len and cur_xds_packet_class) should be +* ignored and not to be dereferenced. +* +* TODO use union inside struct for each kind of fields +*/ struct eia608_screen // A CC buffer { /** format of data inside this structure */ @@ -90,8 +91,8 @@ struct eia608_screen // A CC buffer unsigned char characters[CCX_DECODER_608_SCREEN_ROWS][CCX_DECODER_608_SCREEN_WIDTH + 1]; enum ccx_decoder_608_color_code colors[CCX_DECODER_608_SCREEN_ROWS][CCX_DECODER_608_SCREEN_WIDTH + 1]; enum font_bits fonts[CCX_DECODER_608_SCREEN_ROWS][CCX_DECODER_608_SCREEN_WIDTH + 1]; // Extra char at the end for a 0 - int row_used[CCX_DECODER_608_SCREEN_ROWS]; // Any data in row? - int empty; // Buffer completely empty? + int row_used[CCX_DECODER_608_SCREEN_ROWS]; // Any data in row? + int empty; // Buffer completely empty? /** start time of this CC buffer */ LLONG start_time; /** end time of this CC buffer */ @@ -109,20 +110,20 @@ struct eia608_screen // A CC buffer struct ccx_decoders_common_settings_t { - LLONG subs_delay; // ms to delay (or advance) subs - enum ccx_output_format output_format; // What kind of output format should be used? - int fix_padding; // Replace 0000 with 8080 in HDTV (needed for some cards) + LLONG subs_delay; // ms to delay (or advance) subs + enum ccx_output_format output_format; // What kind of output format should be used? + int fix_padding; // Replace 0000 with 8080 in HDTV (needed for some cards) struct ccx_boundary_time extraction_start, extraction_end; // Segment we actually process int cc_to_stdout; - int extract; // Extract 1st, 2nd or both fields - int fullbin; // Disable pruning of padding cc blocks + int extract; // Extract 1st, 2nd or both fields + int fullbin; // Disable pruning of padding cc blocks int no_rollup; int noscte20; - struct ccx_decoder_608_settings *settings_608; // Contains the settings for the 608 decoder. - ccx_decoder_dtvcc_settings *settings_dtvcc; // Same for cea 708 captions decoder (dtvcc) - int cc_channel; // Channel we want to dump in srt mode + struct ccx_decoder_608_settings *settings_608; // Contains the settings for the 608 decoder. + ccx_decoder_dtvcc_settings *settings_dtvcc; // Same for cea 708 captions decoder (dtvcc) + int cc_channel; // Channel we want to dump in srt mode unsigned send_to_srv; - unsigned int hauppauge_mode; // If 1, use PID=1003, process specially and so on + unsigned int hauppauge_mode; // If 1, use PID=1003, process specially and so on int program_number; enum ccx_code_type codec; int xds_write_to_file; @@ -141,17 +142,17 @@ struct lib_cc_decode void *context_cc608_field_1; void *context_cc608_field_2; - int no_rollup; // If 1, write one line at a time + int no_rollup; // If 1, write one line at a time int noscte20; - int fix_padding; // Replace 0000 with 8080 in HDTV (needed for some cards) - enum ccx_output_format write_format; // 0 = Raw, 1 = srt, 2 = SMI + int fix_padding; // Replace 0000 with 8080 in HDTV (needed for some cards) + enum ccx_output_format write_format; // 0 = Raw, 1 = srt, 2 = SMI struct ccx_boundary_time extraction_start, extraction_end; // Segment we actually process - LLONG subs_delay; // ms to delay (or advance) subs - int extract; // Extract 1st, 2nd or both fields - int fullbin; // Disable pruning of padding cc blocks + LLONG subs_delay; // ms to delay (or advance) subs + int extract; // Extract 1st, 2nd or both fields + int fullbin; // Disable pruning of padding cc blocks struct cc_subtitle dec_sub; enum ccx_bufferdata_type in_bufferdatatype; - unsigned int hauppauge_mode; // If 1, use PID=1003, process specially and so on + unsigned int hauppauge_mode; // If 1, use PID=1003, process specially and so on int frames_since_last_gop; /* GOP-based timing */ @@ -184,7 +185,7 @@ struct lib_cc_decode int in_pic_data; unsigned int current_progressive_sequence; - unsigned int current_pulldownfields; + unsigned int current_pulldownfields ; int temporal_reference; enum ccx_frame_type picture_coding_type; @@ -196,18 +197,18 @@ struct lib_cc_decode /* Required in es_function.c and es_userdata.c */ unsigned top_field_first; // Needs to be global - /* Stats. Modified in es_userdata.c*/ - int stat_numuserheaders; - int stat_dvdccheaders; - int stat_scte20ccheaders; - int stat_replay5000headers; - int stat_replay4000headers; - int stat_dishheaders; - int stat_hdtv; - int stat_divicom; - int false_pict_header; - - void *dtvcc_rust; + /* Stats. Modified in es_userdata.c*/ + int stat_numuserheaders; + int stat_dvdccheaders; + int stat_scte20ccheaders; + int stat_replay5000headers; + int stat_replay4000headers; + int stat_dishheaders; + int stat_hdtv; + int stat_divicom; + int false_pict_header; + + void *dtvcc_rust; dtvcc_ctx *dtvcc; int current_field; // Analyse/use the picture information @@ -217,7 +218,7 @@ struct lib_cc_decode // Store fts; LLONG cc_fts[SORTBUF]; // Store HD CC packets - unsigned char cc_data_pkts[SORTBUF][10 * 31 * 3 + 1]; // *10, because MP4 seems to have different limits + unsigned char cc_data_pkts[SORTBUF][10*31*3+1]; // *10, because MP4 seems to have different limits // The sequence number of the current anchor frame. All currently read // B-Frames belong to this I- or P-frame. @@ -227,7 +228,7 @@ struct lib_cc_decode int (*writedata)(const unsigned char *data, int length, void *private_data, struct cc_subtitle *sub); - // dvb subtitle related + //dvb subtitle related int ocr_quantmode; struct lib_cc_decode *prev; }; diff --git a/src/lib_ccx/mp4.c b/src/lib_ccx/mp4.c index 1b5c45119..0fcc8346b 100644 --- a/src/lib_ccx/mp4.c +++ b/src/lib_ccx/mp4.c @@ -16,6 +16,11 @@ #define GF_ISOM_SUBTYPE_C708 GF_4CC('c', '7', '0', '8') +#ifndef DISABLE_RUST +extern void ccxr_process_data(void *dtvcc_rust, unsigned char cc_valid, unsigned char cc_char, unsigned char data1, unsigned char data2); +extern void ccxr_dtvcc_set_encoder(void *dtvcc_rust, void *encoder); +#endif + static short bswap16(short v) { return ((v >> 8) & 0x00FF) | ((v << 8) & 0xFF00); @@ -394,8 +399,13 @@ static int process_clcp(struct lib_ccx_ctx *ctx, struct encoder_ctx *enc_ctx, continue; } // WARN: otherwise cea-708 will not work +#ifdef DISABLE_RUST dec_ctx->dtvcc->encoder = (void *)enc_ctx; dtvcc_process_data(dec_ctx->dtvcc, (unsigned char *)temp); +#else + ccxr_dtvcc_set_encoder(dec_ctx->dtvcc_rust, (void *)enc_ctx); + ccxr_process_data(dec_ctx->dtvcc_rust, cc_valid, cc_type, cc_data[1], cc_data[2]); +#endif cb_708++; } if (ctx->write_format == CCX_OF_MCC) diff --git a/src/rust/src/lib.rs b/src/rust/src/lib.rs index e69a707d7..1fed0e1b1 100644 --- a/src/rust/src/lib.rs +++ b/src/rust/src/lib.rs @@ -76,6 +76,17 @@ extern "C" fn ccxr_dtvcc_set_encoder(dtvcc_rust: *mut Dtvcc, encoder: *mut encod unsafe { (*dtvcc_rust).encoder = encoder }; } +#[no_mangle] +extern "C" fn ccxr_process_data( + dtvcc_rust: *mut Dtvcc, + cc_valid: u8, + cc_type: u8, + data1: u8, + data2: u8, +) { + unsafe { dtvcc_rust.as_mut().unwrap() }.process_cc_data(cc_valid, cc_type, data1, data2); +} + /// Process cc_data /// /// # Safety