Skip to content

Commit 6300bb7

Browse files
authored
refactor: remove api structures (#1722)
* refactor: remove api structures * docs: add change to changes.txt
1 parent afde4d6 commit 6300bb7

File tree

2 files changed

+28
-32
lines changed

2 files changed

+28
-32
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+
- Refactor: Remove API structures from ccextractor
34
- New: Add Encoder Module to Rust
45
- Fix: Elementary stream regressions
56
- Fix: Segmentation faults on XDS files

src/ccextractor.c

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void print_end_msg(void)
3838
mprint("https://github.com/CCExtractor/ccextractor/issues\n");
3939
}
4040

41-
int api_start(struct ccx_s_options api_options)
41+
int start_ccx()
4242
{
4343
struct lib_ccx_ctx *ctx = NULL; // Context for libs
4444
struct lib_cc_decode *dec_ctx = NULL; // Context for decoder
@@ -49,7 +49,7 @@ int api_start(struct ccx_s_options api_options)
4949
setMsgSeverity(LEPT_MSG_SEVERITY);
5050
#endif
5151
// Initialize CCExtractor libraries
52-
ctx = init_libraries(&api_options);
52+
ctx = init_libraries(&ccx_options);
5353

5454
if (!ctx)
5555
{
@@ -66,10 +66,10 @@ int api_start(struct ccx_s_options api_options)
6666
}
6767

6868
#ifdef ENABLE_HARDSUBX
69-
if (api_options.hardsubx)
69+
if (ccx_options.hardsubx)
7070
{
7171
// Perform burned in subtitle extraction
72-
hardsubx(&api_options, ctx);
72+
hardsubx(&ccx_options, ctx);
7373
return 0;
7474
}
7575
#endif
@@ -97,19 +97,19 @@ int api_start(struct ccx_s_options api_options)
9797
tlt_config.page = ((tlt_config.page / 100) << 8) | (((tlt_config.page / 10) % 10) << 4) | (tlt_config.page % 10);
9898
}
9999

100-
if (api_options.transcript_settings.xds)
100+
if (ccx_options.transcript_settings.xds)
101101
{
102-
if (api_options.write_format != CCX_OF_TRANSCRIPT)
102+
if (ccx_options.write_format != CCX_OF_TRANSCRIPT)
103103
{
104-
api_options.transcript_settings.xds = 0;
104+
ccx_options.transcript_settings.xds = 0;
105105
mprint("Warning: -xds ignored, XDS can only be exported to transcripts at this time.\n");
106106
}
107107
}
108108

109109
time_t start, final;
110110
time(&start);
111111

112-
if (api_options.binary_concat)
112+
if (ccx_options.binary_concat)
113113
{
114114
ctx->total_inputsize = get_total_file_size(ctx);
115115
if (ctx->total_inputsize < 0)
@@ -139,24 +139,24 @@ int api_start(struct ccx_s_options api_options)
139139
terminate_asap = 0;
140140

141141
#ifdef ENABLE_SHARING
142-
if (api_options.translate_enabled && ctx->num_input_files > 1)
142+
if (ccx_options.translate_enabled && ctx->num_input_files > 1)
143143
{
144144
mprint("[share] WARNING: simultaneous translation of several input files is not supported yet\n");
145-
api_options.translate_enabled = 0;
146-
api_options.sharing_enabled = 0;
145+
ccx_options.translate_enabled = 0;
146+
ccx_options.sharing_enabled = 0;
147147
}
148-
if (api_options.translate_enabled)
148+
if (ccx_options.translate_enabled)
149149
{
150150
mprint("[share] launching translate service\n");
151-
ccx_share_launch_translator(api_options.translate_langs, api_options.translate_key);
151+
ccx_share_launch_translator(ccx_options.translate_langs, ccx_options.translate_key);
152152
}
153153
#endif // ENABLE_SHARING
154154
ret = 0;
155155
while (switch_to_next_file(ctx, 0))
156156
{
157157
prepare_for_new_file(ctx);
158158
#ifdef ENABLE_SHARING
159-
if (api_options.sharing_enabled)
159+
if (ccx_options.sharing_enabled)
160160
ccx_share_start(ctx->basefilename);
161161
#endif // ENABLE_SHARING
162162

@@ -185,8 +185,8 @@ int api_start(struct ccx_s_options api_options)
185185
{
186186
// Note: This case is meant to fall through
187187
case CCX_SM_ELEMENTARY_OR_NOT_FOUND:
188-
if (!api_options.use_gop_as_pts) // If !0 then the user selected something
189-
api_options.use_gop_as_pts = 1; // Force GOP timing for ES
188+
if (!ccx_options.use_gop_as_pts) // If !0 then the user selected something
189+
ccx_options.use_gop_as_pts = 1; // Force GOP timing for ES
190190
ccx_common_timing_settings.is_elementary_stream = 1;
191191
case CCX_SM_TRANSPORT:
192192
case CCX_SM_PROGRAM:
@@ -197,9 +197,9 @@ int api_start(struct ccx_s_options api_options)
197197
#ifdef ENABLE_FFMPEG
198198
case CCX_SM_FFMPEG:
199199
#endif
200-
if (!api_options.use_gop_as_pts) // If !0 then the user selected something
201-
api_options.use_gop_as_pts = 0;
202-
if (api_options.ignore_pts_jumps)
200+
if (!ccx_options.use_gop_as_pts) // If !0 then the user selected something
201+
ccx_options.use_gop_as_pts = 0;
202+
if (ccx_options.ignore_pts_jumps)
203203
ccx_common_timing_settings.disable_sync_check = 1;
204204
mprint("\rAnalyzing data in general mode\n");
205205
tmp = general_loop(ctx);
@@ -232,15 +232,15 @@ int api_start(struct ccx_s_options api_options)
232232
{
233233
fatal(EXIT_INCOMPATIBLE_PARAMETERS, "MP4 requires an actual file, it's not possible to read from a stream, including stdin.\n");
234234
}
235-
if (api_options.extract_chapters)
235+
if (ccx_options.extract_chapters)
236236
{
237237
tmp = dumpchapters(ctx, &ctx->mp4_cfg, ctx->inputfile[ctx->current_file]);
238238
}
239239
else
240240
{
241241
tmp = processmp4(ctx, &ctx->mp4_cfg, ctx->inputfile[ctx->current_file]);
242242
}
243-
if (api_options.print_file_reports)
243+
if (ccx_options.print_file_reports)
244244
print_file_report(ctx);
245245
if (!ret)
246246
ret = tmp;
@@ -311,7 +311,7 @@ int api_start(struct ccx_s_options api_options)
311311
dec_ctx->timing->fts_max = 0;
312312

313313
#ifdef ENABLE_SHARING
314-
if (api_options.sharing_enabled)
314+
if (ccx_options.sharing_enabled)
315315
{
316316
ccx_share_stream_done(ctx->basefilename);
317317
ccx_share_stop();
@@ -430,23 +430,18 @@ int api_start(struct ccx_s_options api_options)
430430
return ret ? EXIT_OK : EXIT_NO_CAPTIONS;
431431
}
432432

433-
struct ccx_s_options *api_init_options()
434-
{
435-
init_options(&ccx_options);
436-
return &ccx_options;
437-
}
438-
439433
int main(int argc, char *argv[])
440434
{
441435
setlocale(LC_ALL, ""); // Supports non-English CCs
442436
// Use POSIX locale for numbers so we get "." as decimal separator and no
443437
// thousands' groupoing instead of what the locale might say
444438
setlocale(LC_NUMERIC, "POSIX");
445439

446-
struct ccx_s_options *api_options = api_init_options();
447-
parse_configuration(api_options);
440+
init_options(&ccx_options);
441+
448442
// If "ccextractor.cnf" is present, takes options from it.
449443
// See docs/ccextractor.cnf.sample for more info.
444+
parse_configuration(&ccx_options);
450445

451446
#ifndef DISABLE_RUST
452447
ccxr_init_basic_logger();
@@ -455,7 +450,7 @@ int main(int argc, char *argv[])
455450
#ifndef DISABLE_RUST
456451
int compile_ret = ccxr_parse_parameters(argc, argv);
457452
#else
458-
int compile_ret = parse_parameters(api_options, argc, argv);
453+
int compile_ret = parse_parameters(&ccx_options, argc, argv);
459454
#endif
460455

461456
if (compile_ret == EXIT_NO_INPUT_FILES)
@@ -472,6 +467,6 @@ int main(int argc, char *argv[])
472467
exit(compile_ret);
473468
}
474469

475-
int start_ret = api_start(*api_options);
470+
int start_ret = start_ccx();
476471
return start_ret;
477472
}

0 commit comments

Comments
 (0)