Skip to content

Commit afde4d6

Browse files
authored
feat(rust): Added Encoder Module (#1710)
* Added Encoder Module * Encoder: Windows Compatibility * Encoder: C formatting * Encoder: recommended changes to the encoding module - logic reduction * Encoder: Minor stylistic change * Encoder: Review changes, renamed Line21 to Ascii * Encoder: Slight modification in C version of write_cc_buffer_as_simplexml * Encoder: Renamed 2 files * Encoder: Minor Capitalization Change * Encoder: Review Suggestions
1 parent b63a29c commit afde4d6

File tree

16 files changed

+1471
-142
lines changed

16 files changed

+1471
-142
lines changed

docs/CHANGES.TXT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
1.0 (to be released)
22
-----------------
3+
- New: Add Encoder Module to Rust
34
- Fix: Elementary stream regressions
45
- Fix: Segmentation faults on XDS files
56
- Fix: Clippy Errors Based on Rust 1.88

src/lib_ccx/ccx_encoders_common.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ int fsync(int fd)
1919
}
2020
#endif
2121

22+
#ifndef DISABLE_RUST
23+
int ccxr_get_str_basic(unsigned char *out_buffer, unsigned char *in_buffer, int trim_subs,
24+
enum ccx_encoding_type in_enc, enum ccx_encoding_type out_enc, int max_len);
25+
#endif
2226
// These are the default settings for plain transcripts. No times, no CC or caption mode, and no XDS.
2327
ccx_encoders_transcript_format ccx_encoders_default_transcript_settings =
2428
{
@@ -293,6 +297,9 @@ int change_ascii_encoding(unsigned char *dest, unsigned char *src, int len, enum
293297
int get_str_basic(unsigned char *out_buffer, unsigned char *in_buffer, int trim_subs,
294298
enum ccx_encoding_type in_enc, enum ccx_encoding_type out_enc, int max_len)
295299
{
300+
#ifndef DISABLE_RUST
301+
return ccxr_get_str_basic(out_buffer, in_buffer, trim_subs, in_enc, out_enc, max_len);
302+
#else
296303
int last_non_blank = -1;
297304
int first_non_blank = -1;
298305
int len = 0;
@@ -305,7 +312,6 @@ int get_str_basic(unsigned char *out_buffer, unsigned char *in_buffer, int trim_
305312
*out_buffer = 0;
306313
return 0;
307314
}
308-
309315
// change encoding only when required
310316
switch (in_enc)
311317
{
@@ -331,6 +337,7 @@ int get_str_basic(unsigned char *out_buffer, unsigned char *in_buffer, int trim_
331337
return (unsigned)len; // Return length
332338

333339
return 0; // Return length
340+
#endif
334341
}
335342

336343
int write_subtitle_file_footer(struct encoder_ctx *ctx, struct ccx_s_write *out)
@@ -631,8 +638,8 @@ int write_cc_buffer_as_simplexml(struct eia608_screen *data, struct encoder_ctx
631638
if (data->row_used[i])
632639
{
633640
write_cc_line_as_simplexml(data, context, i);
641+
wrote_something = 1;
634642
}
635-
wrote_something = 1;
636643
}
637644
return wrote_something;
638645
}

src/lib_ccx/ccx_encoders_spupng.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,6 @@ FT_Face face_regular = NULL;
2929
FT_Face face_italics = NULL;
3030
FT_Face face = NULL;
3131

32-
struct spupng_t
33-
{
34-
FILE *fpxml;
35-
FILE *fppng;
36-
char *dirname;
37-
char *pngfile;
38-
char *relative_path_png;
39-
int fileIndex;
40-
int xOffset;
41-
int yOffset;
42-
};
43-
4432
#define CCPL (ccfont2_width / CCW * ccfont2_height / CCH)
4533

4634
static int initialized = 0;

src/lib_ccx/ccx_encoders_structs.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,16 @@ struct ccx_s_write
2929

3030
};
3131

32+
struct spupng_t
33+
{
34+
FILE *fpxml;
35+
FILE *fppng;
36+
char *dirname;
37+
char *pngfile;
38+
char *relative_path_png;
39+
int fileIndex;
40+
int xOffset;
41+
int yOffset;
42+
};
43+
3244
#endif

src/rust/build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ fn main() {
1212
"writercwtdata",
1313
"version",
1414
"set_binary_mode",
15+
"net_send_header", // shall be removed after NET
16+
"write_spumux_footer",
17+
"write_spumux_header",
1518
]);
1619

1720
#[cfg(feature = "hardsubx_ocr")]
@@ -39,6 +42,7 @@ fn main() {
3942
"ccx_encoding_type",
4043
"ccx_decoder_608_settings",
4144
"ccx_decoder_608_report",
45+
"eia608_screen",
4246
"uint8_t",
4347
"word_list",
4448
]);

src/rust/lib_ccxr/src/encoder/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pub mod txt_helpers;
2+
/* Note
3+
This is a part of the encoder library, which is made in pure rust; hence it's kept in `lib_ccxr` instead of `src`.
4+
*/

0 commit comments

Comments
 (0)