Skip to content

Commit

Permalink
[FEAT] add teletext and encoders_helpers module (#1635)
Browse files Browse the repository at this point in the history
* create lib_ccxr and libccxr_exports

* add bits and levenshtein module

* add log module

* add encoding module

* add common constants module

* add time units module

* add options module

* add teletext module

* chore: remove outdated

* chore: update lock files

* chore: fix naming

* fix: reference to TeletextConfig

* fix: issue with ts_forced_program default value

* fix: use correct definition

* chore: lint warnings

* fix: example code

* fix(rust): adjust defaults, more accurate logging, use safe functions, add encoders_helper module

* fix: tests and formatting

* fix: allow hex values for streamtype

* chore: format files

* fix: naming of fields and docs

* fix: defaults for options

* fix: memory leak in vector to string

* fix(c): init logger before running parser

---------

Co-authored-by: Elbert Ronnie <[email protected]>
  • Loading branch information
prateekmedia and elbertronnie authored Aug 27, 2024
1 parent 98a85e1 commit 90f9f0a
Show file tree
Hide file tree
Showing 28 changed files with 2,906 additions and 656 deletions.
8 changes: 7 additions & 1 deletion src/ccextractor.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ int api_start(struct ccx_s_options api_options)
if (!api_options.use_gop_as_pts) // If !0 then the user selected something
api_options.use_gop_as_pts = 1; // Force GOP timing for ES
ccx_common_timing_settings.is_elementary_stream = 1;
break;
case CCX_SM_TRANSPORT:
case CCX_SM_PROGRAM:
case CCX_SM_ASF:
Expand Down Expand Up @@ -425,6 +426,7 @@ int api_start(struct ccx_s_options api_options)
mprint("code in the MythTV's branch. Please report results to the address above. If\n");
mprint("something is broken it will be fixed. Thanks\n");
}

return ret ? EXIT_OK : EXIT_NO_CAPTIONS;
}

Expand All @@ -447,7 +449,11 @@ int main(int argc, char *argv[])
// See docs/ccextractor.cnf.sample for more info.

#ifndef DISABLE_RUST
int compile_ret = ccxr_parse_parameters(api_options, argc, argv);
ccxr_init_basic_logger();
#endif

#ifndef DISABLE_RUST
int compile_ret = ccxr_parse_parameters(argc, argv);
#else
int compile_ret = parse_parameters(api_options, argc, argv);
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/lib_ccx/ccx_common_option.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void init_options(struct ccx_s_options *options)

options->extract = 1; // Extract 1st field only (primary language)
options->cc_channel = 1; // Channel we want to dump in srt mode
options->binary_concat = 1; // Disabled by -ve or --videoedited
options->binary_concat = 1; // Disabled by --videoedited
options->use_gop_as_pts = 0; // Use GOP instead of PTS timing (0=do as needed, 1=always, -1=never)
options->fix_padding = 0; // Replace 0000 with 8080 in HDTV (needed for some cards)
options->gui_mode_reports = 0; // If 1, output in stderr progress updates so the GUI can grab them
Expand Down
4 changes: 0 additions & 4 deletions src/lib_ccx/lib_ccx.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ struct lib_ccx_ctx *init_libraries(struct ccx_s_options *opt)
ccx_common_logging.log_ftn = &mprint;
ccx_common_logging.gui_ftn = &activity_library_process;

#ifndef DISABLE_RUST
ccxr_init_basic_logger(opt);
#endif

struct lib_ccx_ctx *ctx = malloc(sizeof(struct lib_ccx_ctx));
if (!ctx)
ccx_common_logging.fatal_ftn(EXIT_NOT_ENOUGH_MEMORY, "init_libraries: Not enough memory allocating lib_ccx_ctx context.");
Expand Down
4 changes: 2 additions & 2 deletions src/lib_ccx/lib_ccx.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ struct lib_ccx_ctx *init_libraries(struct ccx_s_options *opt);
void dinit_libraries( struct lib_ccx_ctx **ctx);

#ifndef DISABLE_RUST
extern void ccxr_init_basic_logger(struct ccx_s_options *opts);
extern void ccxr_init_basic_logger();
#endif

//ccextractor.c
void print_end_msg(void);

//params.c
#ifndef DISABLE_RUST
extern int ccxr_parse_parameters(struct ccx_s_options *opt, int argc, char *argv[]);
extern int ccxr_parse_parameters(int argc, char *argv[]);
#endif
int parse_parameters (struct ccx_s_options *opt, int argc, char *argv[]);
void print_usage (void);
Expand Down
13 changes: 8 additions & 5 deletions src/lib_ccx/params.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,11 @@ void print_usage(void)
mprint(" --tcp-description description: Sends to the server short description about\n");
mprint(" captions e.g. channel name or file name\n");
mprint("Options that affect what will be processed:\n");
mprint(" --output-field 1 / 2 / both: Output Field 1 data, Field 2 data, or both\n");
mprint(" (DEFAULT is 1)\n");
mprint(" --output-field 1 / 2 / both:\n");
mprint(" Values: 1 = Output Field 1\n");
mprint(" 2 = Output Field 2\n");
mprint(" both = Both Output Field 1 and 2\n");
mprint(" Defaults to 1\n");
mprint("Use --append to prevent overwriting of existing files. The output will be\n");
mprint(" appended instead.\n");
mprint(" --cc2: When in srt/sami mode, process captions in channel 2\n");
Expand Down Expand Up @@ -601,7 +604,7 @@ void print_usage(void)
mprint(" white). This causes all output in .srt/.smi/.vtt\n");
mprint(" files to have a font tag, which makes the files\n");
mprint(" larger. Add the color you want in RGB, such as\n");
mprint(" --dc #FF0000 for red.\n");
mprint(" --defaultcolor #FF0000 for red.\n");
mprint(" --sentencecap: Sentence capitalization. Use if you hate\n");
mprint(" ALL CAPS in subtitles.\n");
mprint(" --capfile file: Add the contents of 'file' to the list of words\n");
Expand Down Expand Up @@ -992,7 +995,7 @@ void print_usage(void)
mprint(" input.d/sub0001.png\n");
mprint(" ...\n");
mprint(" The command:\n");
mprint(" ccextractor --out=spupng -o /tmp/output --12 input.mpg\n");
mprint(" ccextractor --out=spupng -o /tmp/output --output-field both input.mpg\n");
mprint(" will create the files:\n");
mprint(" /tmp/output_1.xml\n");
mprint(" /tmp/output_1.d/sub0000.png\n");
Expand Down Expand Up @@ -2111,7 +2114,7 @@ int parse_parameters(struct ccx_s_options *opt, int argc, char *argv[])
opt->extract = strcmp(argv[i], "both") == 0 ? 12 : atoi_hex(argv[i]);
if (opt->extract != 1 && opt->extract != 2 && opt->extract != 12)
{
fatal(EXIT_MALFORMED_PARAMETER, "--output-field only accepts 1 or 2 or both.\n");
fatal(EXIT_MALFORMED_PARAMETER, "--output-field only accepts 1 , 2 , 12 / both.\n");
}
opt->is_608_enabled = 1;
continue;
Expand Down
11 changes: 8 additions & 3 deletions src/lib_ccx/utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ int temp_debug = 0; // This is a convenience variable used to enable/disable deb
volatile sig_atomic_t change_filename_requested = 0;

#ifndef DISABLE_RUST
extern int ccxr_verify_crc32(uint8_t *buf, int len);
extern int ccxr_levenshtein_dist(const uint64_t *s1, const uint64_t *s2, unsigned s1len, unsigned s2len);
extern int ccxr_levenshtein_dist_char(const char *s1, const char *s2, unsigned s1len, unsigned s2len);
extern void ccxr_timestamp_to_srttime(uint64_t timestamp, char *buffer);
extern void ccxr_timestamp_to_vtttime(uint64_t timestamp, char *buffer);
extern void ccxr_millis_to_date(uint64_t timestamp, char *buffer, enum ccx_output_date_format date_format, char millis_separator);
Expand Down Expand Up @@ -86,7 +89,8 @@ int verify_crc32(uint8_t *buf, int len)
{
#ifndef DISABLE_RUST
return ccxr_verify_crc32(buf, len);
#endif /* ifndef DISABLE_RUST */
#endif

int i = 0;
int32_t crc = -1;
for (i = 0; i < len; i++)
Expand All @@ -99,8 +103,8 @@ int stringztoms(const char *s, struct ccx_boundary_time *bt)
#ifndef DISABLE_RUST
return ccxr_stringztoms(s, bt);
#endif
unsigned ss = 0,
mm = 0, hh = 0;

unsigned ss = 0, mm = 0, hh = 0;
int value = -1;
int colons = 0;
const char *c = s;
Expand Down Expand Up @@ -176,6 +180,7 @@ int levenshtein_dist(const uint64_t *s1, const uint64_t *s2, unsigned s1len, uns
#ifndef DISABLE_RUST
return ccxr_levenshtein_dist(s1, s2, s1len, s2len);
#endif

unsigned int x, y, v, lastdiag, olddiag;
unsigned int *column = (unsigned *)malloc((s1len + 1) * sizeof(unsigned int));
for (y = 1; y <= s1len; y++)
Expand Down
Loading

0 comments on commit 90f9f0a

Please sign in to comment.