Skip to content

Commit

Permalink
Exporting ccxr_process_data from Rust and using in mp4.c
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchitBhonsle committed Apr 11, 2023
1 parent e42fe35 commit 22f5684
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 42 deletions.
85 changes: 43 additions & 42 deletions src/lib_ccx/ccx_decoders_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,22 +77,22 @@ 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 */
enum ccx_eia608_format format;
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 */
Expand All @@ -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;
Expand All @@ -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 */
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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;
};
Expand Down
10 changes: 10 additions & 0 deletions src/lib_ccx/mp4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions src/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 22f5684

Please sign in to comment.