Skip to content

Commit 22f5684

Browse files
committed
Exporting ccxr_process_data from Rust and using in mp4.c
1 parent e42fe35 commit 22f5684

File tree

3 files changed

+64
-42
lines changed

3 files changed

+64
-42
lines changed

src/lib_ccx/ccx_decoders_structs.h

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
#define CCX_DECODER_608_SCREEN_ROWS 15
1212
#define CCX_DECODER_608_SCREEN_WIDTH 32
1313
#define MAXBFRAMES 50
14-
#define SORTBUF (2 * MAXBFRAMES + 1)
14+
#define SORTBUF (2*MAXBFRAMES+1)
15+
1516

1617
/* flag raised when end of display marker arrives in Dvb Subtitle */
17-
#define SUB_EOD_MARKER (1 << 0)
18+
#define SUB_EOD_MARKER (1 << 0 )
1819
struct cc_bitmap
1920
{
2021
int x;
@@ -76,22 +77,22 @@ enum ccx_decoder_608_color_code
7677
};
7778

7879
/**
79-
* This structure have fields which need to be ignored according to format,
80-
* for example if format is SFORMAT_XDS then all fields other then
81-
* xds related (xds_str, xds_len and cur_xds_packet_class) should be
82-
* ignored and not to be dereferenced.
83-
*
84-
* TODO use union inside struct for each kind of fields
85-
*/
80+
* This structure have fields which need to be ignored according to format,
81+
* for example if format is SFORMAT_XDS then all fields other then
82+
* xds related (xds_str, xds_len and cur_xds_packet_class) should be
83+
* ignored and not to be dereferenced.
84+
*
85+
* TODO use union inside struct for each kind of fields
86+
*/
8687
struct eia608_screen // A CC buffer
8788
{
8889
/** format of data inside this structure */
8990
enum ccx_eia608_format format;
9091
unsigned char characters[CCX_DECODER_608_SCREEN_ROWS][CCX_DECODER_608_SCREEN_WIDTH + 1];
9192
enum ccx_decoder_608_color_code colors[CCX_DECODER_608_SCREEN_ROWS][CCX_DECODER_608_SCREEN_WIDTH + 1];
9293
enum font_bits fonts[CCX_DECODER_608_SCREEN_ROWS][CCX_DECODER_608_SCREEN_WIDTH + 1]; // Extra char at the end for a 0
93-
int row_used[CCX_DECODER_608_SCREEN_ROWS]; // Any data in row?
94-
int empty; // Buffer completely empty?
94+
int row_used[CCX_DECODER_608_SCREEN_ROWS]; // Any data in row?
95+
int empty; // Buffer completely empty?
9596
/** start time of this CC buffer */
9697
LLONG start_time;
9798
/** end time of this CC buffer */
@@ -109,20 +110,20 @@ struct eia608_screen // A CC buffer
109110

110111
struct ccx_decoders_common_settings_t
111112
{
112-
LLONG subs_delay; // ms to delay (or advance) subs
113-
enum ccx_output_format output_format; // What kind of output format should be used?
114-
int fix_padding; // Replace 0000 with 8080 in HDTV (needed for some cards)
113+
LLONG subs_delay; // ms to delay (or advance) subs
114+
enum ccx_output_format output_format; // What kind of output format should be used?
115+
int fix_padding; // Replace 0000 with 8080 in HDTV (needed for some cards)
115116
struct ccx_boundary_time extraction_start, extraction_end; // Segment we actually process
116117
int cc_to_stdout;
117-
int extract; // Extract 1st, 2nd or both fields
118-
int fullbin; // Disable pruning of padding cc blocks
118+
int extract; // Extract 1st, 2nd or both fields
119+
int fullbin; // Disable pruning of padding cc blocks
119120
int no_rollup;
120121
int noscte20;
121-
struct ccx_decoder_608_settings *settings_608; // Contains the settings for the 608 decoder.
122-
ccx_decoder_dtvcc_settings *settings_dtvcc; // Same for cea 708 captions decoder (dtvcc)
123-
int cc_channel; // Channel we want to dump in srt mode
122+
struct ccx_decoder_608_settings *settings_608; // Contains the settings for the 608 decoder.
123+
ccx_decoder_dtvcc_settings *settings_dtvcc; // Same for cea 708 captions decoder (dtvcc)
124+
int cc_channel; // Channel we want to dump in srt mode
124125
unsigned send_to_srv;
125-
unsigned int hauppauge_mode; // If 1, use PID=1003, process specially and so on
126+
unsigned int hauppauge_mode; // If 1, use PID=1003, process specially and so on
126127
int program_number;
127128
enum ccx_code_type codec;
128129
int xds_write_to_file;
@@ -141,17 +142,17 @@ struct lib_cc_decode
141142
void *context_cc608_field_1;
142143
void *context_cc608_field_2;
143144

144-
int no_rollup; // If 1, write one line at a time
145+
int no_rollup; // If 1, write one line at a time
145146
int noscte20;
146-
int fix_padding; // Replace 0000 with 8080 in HDTV (needed for some cards)
147-
enum ccx_output_format write_format; // 0 = Raw, 1 = srt, 2 = SMI
147+
int fix_padding; // Replace 0000 with 8080 in HDTV (needed for some cards)
148+
enum ccx_output_format write_format; // 0 = Raw, 1 = srt, 2 = SMI
148149
struct ccx_boundary_time extraction_start, extraction_end; // Segment we actually process
149-
LLONG subs_delay; // ms to delay (or advance) subs
150-
int extract; // Extract 1st, 2nd or both fields
151-
int fullbin; // Disable pruning of padding cc blocks
150+
LLONG subs_delay; // ms to delay (or advance) subs
151+
int extract; // Extract 1st, 2nd or both fields
152+
int fullbin; // Disable pruning of padding cc blocks
152153
struct cc_subtitle dec_sub;
153154
enum ccx_bufferdata_type in_bufferdatatype;
154-
unsigned int hauppauge_mode; // If 1, use PID=1003, process specially and so on
155+
unsigned int hauppauge_mode; // If 1, use PID=1003, process specially and so on
155156

156157
int frames_since_last_gop;
157158
/* GOP-based timing */
@@ -184,7 +185,7 @@ struct lib_cc_decode
184185
int in_pic_data;
185186

186187
unsigned int current_progressive_sequence;
187-
unsigned int current_pulldownfields;
188+
unsigned int current_pulldownfields ;
188189

189190
int temporal_reference;
190191
enum ccx_frame_type picture_coding_type;
@@ -196,18 +197,18 @@ struct lib_cc_decode
196197
/* Required in es_function.c and es_userdata.c */
197198
unsigned top_field_first; // Needs to be global
198199

199-
/* Stats. Modified in es_userdata.c*/
200-
int stat_numuserheaders;
201-
int stat_dvdccheaders;
202-
int stat_scte20ccheaders;
203-
int stat_replay5000headers;
204-
int stat_replay4000headers;
205-
int stat_dishheaders;
206-
int stat_hdtv;
207-
int stat_divicom;
208-
int false_pict_header;
209-
210-
void *dtvcc_rust;
200+
/* Stats. Modified in es_userdata.c*/
201+
int stat_numuserheaders;
202+
int stat_dvdccheaders;
203+
int stat_scte20ccheaders;
204+
int stat_replay5000headers;
205+
int stat_replay4000headers;
206+
int stat_dishheaders;
207+
int stat_hdtv;
208+
int stat_divicom;
209+
int false_pict_header;
210+
211+
void *dtvcc_rust;
211212
dtvcc_ctx *dtvcc;
212213
int current_field;
213214
// Analyse/use the picture information
@@ -217,7 +218,7 @@ struct lib_cc_decode
217218
// Store fts;
218219
LLONG cc_fts[SORTBUF];
219220
// Store HD CC packets
220-
unsigned char cc_data_pkts[SORTBUF][10 * 31 * 3 + 1]; // *10, because MP4 seems to have different limits
221+
unsigned char cc_data_pkts[SORTBUF][10*31*3+1]; // *10, because MP4 seems to have different limits
221222

222223
// The sequence number of the current anchor frame. All currently read
223224
// B-Frames belong to this I- or P-frame.
@@ -227,7 +228,7 @@ struct lib_cc_decode
227228

228229
int (*writedata)(const unsigned char *data, int length, void *private_data, struct cc_subtitle *sub);
229230

230-
// dvb subtitle related
231+
//dvb subtitle related
231232
int ocr_quantmode;
232233
struct lib_cc_decode *prev;
233234
};

src/lib_ccx/mp4.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616

1717
#define GF_ISOM_SUBTYPE_C708 GF_4CC('c', '7', '0', '8')
1818

19+
#ifndef DISABLE_RUST
20+
extern void ccxr_process_data(void *dtvcc_rust, unsigned char cc_valid, unsigned char cc_char, unsigned char data1, unsigned char data2);
21+
extern void ccxr_dtvcc_set_encoder(void *dtvcc_rust, void *encoder);
22+
#endif
23+
1924
static short bswap16(short v)
2025
{
2126
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,
394399
continue;
395400
}
396401
// WARN: otherwise cea-708 will not work
402+
#ifdef DISABLE_RUST
397403
dec_ctx->dtvcc->encoder = (void *)enc_ctx;
398404
dtvcc_process_data(dec_ctx->dtvcc, (unsigned char *)temp);
405+
#else
406+
ccxr_dtvcc_set_encoder(dec_ctx->dtvcc_rust, (void *)enc_ctx);
407+
ccxr_process_data(dec_ctx->dtvcc_rust, cc_valid, cc_type, cc_data[1], cc_data[2]);
408+
#endif
399409
cb_708++;
400410
}
401411
if (ctx->write_format == CCX_OF_MCC)

src/rust/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ extern "C" fn ccxr_dtvcc_set_encoder(dtvcc_rust: *mut Dtvcc, encoder: *mut encod
7676
unsafe { (*dtvcc_rust).encoder = encoder };
7777
}
7878

79+
#[no_mangle]
80+
extern "C" fn ccxr_process_data(
81+
dtvcc_rust: *mut Dtvcc,
82+
cc_valid: u8,
83+
cc_type: u8,
84+
data1: u8,
85+
data2: u8,
86+
) {
87+
unsafe { dtvcc_rust.as_mut().unwrap() }.process_cc_data(cc_valid, cc_type, data1, data2);
88+
}
89+
7990
/// Process cc_data
8091
///
8192
/// # Safety

0 commit comments

Comments
 (0)