mirror of
https://github.com/CCExtractor/ccextractor.git
synced 2024-12-24 11:53:25 +00:00
minor refactoring to correctly set options
This commit is contained in:
parent
5bdd6971f7
commit
2125e58e1f
@ -42,8 +42,11 @@ int main(int argc, char *argv[])
|
||||
|
||||
init_options (&ccx_options);
|
||||
|
||||
parse_configuration(&ccx_options);
|
||||
parse_parameters (&ccx_options, argc, argv);
|
||||
|
||||
// Initialize libraries
|
||||
ctx = init_libraries();
|
||||
ctx = init_libraries(&ccx_options);
|
||||
|
||||
// Init timing
|
||||
ccx_common_timing_init(&ctx->past,ccx_options.nosync);
|
||||
@ -67,8 +70,6 @@ int main(int argc, char *argv[])
|
||||
memset (&cea708services[0],0,CCX_DECODERS_708_MAX_SERVICES*sizeof (int)); // Cannot (yet) be moved because it's needed in parse_parameters.
|
||||
memset (&dec_sub, 0,sizeof(dec_sub));
|
||||
|
||||
parse_configuration(&ccx_options);
|
||||
parse_parameters (ctx, argc, argv);
|
||||
|
||||
if (ctx->num_input_files==0 && ccx_options.input_source==CCX_DS_FILE)
|
||||
{
|
||||
|
@ -86,4 +86,5 @@ void init_options (struct ccx_s_options *options)
|
||||
options->line_terminator_lf=0; // 0 = CRLF
|
||||
options->noautotimeref=0; // Do NOT set time automatically?
|
||||
options->input_source=CCX_DS_FILE; // Files, stdin or network
|
||||
options->auto_stream = CCX_SM_AUTODETECT;
|
||||
}
|
||||
|
@ -82,6 +82,15 @@ struct ccx_s_options // Options from user parameters
|
||||
int line_terminator_lf; // 0 = CRLF, 1=LF
|
||||
int noautotimeref; // Do NOT set time automatically?
|
||||
enum ccx_datasource input_source; // Files, stdin or network
|
||||
|
||||
char **inputfile; // List of files to process
|
||||
int num_input_files; // How many?
|
||||
enum ccx_stream_mode_enum auto_stream;
|
||||
LLONG subs_delay; // ms to delay (or advance) subs
|
||||
int *cc_to_stdout; // If this is set to 1, the stdout will be flushed when data was written to the screen during a process_608 call.
|
||||
// Output structures
|
||||
struct ccx_s_write wbout1;
|
||||
struct ccx_s_write wbout2;
|
||||
};
|
||||
|
||||
struct ccx_s_options ccx_options;
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include "ccx_common_option.h"
|
||||
|
||||
|
||||
struct lib_ccx_ctx* init_libraries(void)
|
||||
struct lib_ccx_ctx* init_libraries(struct ccx_s_options *opt)
|
||||
{
|
||||
struct lib_ccx_ctx *ctx;
|
||||
|
||||
@ -12,7 +12,7 @@ struct lib_ccx_ctx* init_libraries(void)
|
||||
memset(ctx,0,sizeof(struct lib_ccx_ctx));
|
||||
|
||||
ctx->stream_mode = CCX_SM_ELEMENTARY_OR_NOT_FOUND;
|
||||
ctx->auto_stream = CCX_SM_AUTODETECT;
|
||||
ctx->auto_stream = opt->auto_stream;
|
||||
ctx->screens_to_process = -1;
|
||||
ctx->current_file = -1;
|
||||
ctx->infd = -1;//Set to -1 to indicate no file is open.
|
||||
@ -63,5 +63,14 @@ struct lib_ccx_ctx* init_libraries(void)
|
||||
// Init XDS buffers
|
||||
ccx_decoders_xds_init_library(&ccx_options.transcript_settings, ctx->subs_delay, ccx_options.millis_separator);
|
||||
//xds_cea608_test();
|
||||
|
||||
//Initialize input files
|
||||
ctx->inputfile = opt->inputfile;
|
||||
ctx->num_input_files = opt->num_input_files;
|
||||
ctx->subs_delay = opt->subs_delay;
|
||||
ctx->wbout1.filename = opt->wbout2.filename;
|
||||
ctx->wbout2.filename = opt->wbout2.filename;
|
||||
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "ccx_common_char_encoding.h"
|
||||
#include "ccx_common_structs.h"
|
||||
#include "ccx_common_timing.h"
|
||||
#include "ccx_common_option.h"
|
||||
|
||||
#include "ccx_encoders_common.h"
|
||||
#include "ccx_decoders_608.h"
|
||||
@ -154,11 +155,11 @@ struct lib_ccx_ctx
|
||||
LLONG last_displayed_subs_ms; // When did the last subs end?
|
||||
LLONG screens_to_process; // How many screenfuls we want?
|
||||
char *basefilename; // Input filename without the extension
|
||||
char **inputfile; // List of files to process
|
||||
|
||||
const char *extension; // Output extension
|
||||
int current_file; // If current_file!=1, we are processing *inputfile[current_file]
|
||||
|
||||
char **inputfile; // List of files to process
|
||||
int num_input_files; // How many?
|
||||
|
||||
/* Hauppauge support */
|
||||
@ -209,10 +210,10 @@ int main_telxcc (int argc, char *argv[]);
|
||||
|
||||
LLONG buffered_read_opt (struct lib_ccx_ctx *ctx, unsigned char *buffer, unsigned int bytes);
|
||||
|
||||
struct lib_ccx_ctx* init_libraries(void);
|
||||
struct lib_ccx_ctx* init_libraries(struct ccx_s_options *opt);
|
||||
|
||||
//params.c
|
||||
void parse_parameters (struct lib_ccx_ctx *ctx, int argc, char *argv[]);
|
||||
void parse_parameters (struct ccx_s_options *opt, int argc, char *argv[]);
|
||||
void usage (void);
|
||||
int atoi_hex (char *s);
|
||||
int stringztoms (const char *s, struct ccx_boundary_time *bt);
|
||||
|
@ -107,7 +107,7 @@ int isanumber (char *s)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int parsedelay (struct lib_ccx_ctx *ctx, char *par)
|
||||
int parsedelay (struct ccx_s_options *opt, char *par)
|
||||
{
|
||||
int sign=0;
|
||||
char *c=par;
|
||||
@ -124,37 +124,37 @@ int parsedelay (struct lib_ccx_ctx *ctx, char *par)
|
||||
{
|
||||
if (!isdigit (*c))
|
||||
return 1;
|
||||
ctx->subs_delay = ctx->subs_delay*10 + (*c-'0');
|
||||
opt->subs_delay = opt->subs_delay*10 + (*c-'0');
|
||||
}
|
||||
c++;
|
||||
}
|
||||
if (sign)
|
||||
ctx->subs_delay =- ctx->subs_delay;
|
||||
opt->subs_delay =- opt->subs_delay;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int append_file_to_queue (struct lib_ccx_ctx *ctx,char *filename)
|
||||
int append_file_to_queue (struct ccx_s_options *opt,char *filename)
|
||||
{
|
||||
char *c=(char *) malloc (strlen (filename)+1);
|
||||
if (c==NULL)
|
||||
return -1;
|
||||
strcpy (c,filename);
|
||||
if (inputfile_capacity<=ctx->num_input_files)
|
||||
if (inputfile_capacity<=opt->num_input_files)
|
||||
{
|
||||
inputfile_capacity+=10;
|
||||
ctx->inputfile=(char **) realloc (ctx->inputfile,sizeof (char *) * inputfile_capacity);
|
||||
if (ctx->inputfile==NULL)
|
||||
opt->inputfile=(char **) realloc (opt->inputfile,sizeof (char *) * inputfile_capacity);
|
||||
if (opt->inputfile==NULL)
|
||||
{
|
||||
free(c);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
ctx->inputfile[ctx->num_input_files]=c;
|
||||
ctx->num_input_files++;
|
||||
opt->inputfile[opt->num_input_files]=c;
|
||||
opt->num_input_files++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int add_file_sequence (struct lib_ccx_ctx *ctx, char *filename)
|
||||
int add_file_sequence (struct ccx_s_options *opt, char *filename)
|
||||
{
|
||||
int m,n;
|
||||
n=strlen (filename)-1;
|
||||
@ -162,7 +162,7 @@ int add_file_sequence (struct lib_ccx_ctx *ctx, char *filename)
|
||||
while (n>=0 && !isdigit (filename[n]))
|
||||
n--;
|
||||
if (n==-1) // None. No expansion needed
|
||||
return append_file_to_queue(ctx, filename);
|
||||
return append_file_to_queue(opt, filename);
|
||||
m=n;
|
||||
while (m>=0 && isdigit (filename[m]))
|
||||
m--;
|
||||
@ -187,7 +187,7 @@ int add_file_sequence (struct lib_ccx_ctx *ctx, char *filename)
|
||||
if (f==NULL) // Doesn't exist or we can't read it. We're done
|
||||
break;
|
||||
fclose (f);
|
||||
if (append_file_to_queue (ctx, filename)) // Memory panic
|
||||
if (append_file_to_queue (opt, filename)) // Memory panic
|
||||
{
|
||||
free(num);
|
||||
free(temp);
|
||||
@ -263,7 +263,7 @@ void set_output_format (const char *format)
|
||||
fatal (EXIT_MALFORMED_PARAMETER, "Unknown output file format: %s\n", format);
|
||||
}
|
||||
|
||||
void set_input_format (struct lib_ccx_ctx *ctx, const char *format)
|
||||
void set_input_format (struct ccx_s_options *opt, const char *format)
|
||||
{
|
||||
if (ccx_options.input_source == CCX_DS_TCP && strcmp(format, "bin")!=0)
|
||||
{
|
||||
@ -274,24 +274,24 @@ void set_input_format (struct lib_ccx_ctx *ctx, const char *format)
|
||||
while (*format=='-')
|
||||
format++;
|
||||
if (strcmp (format,"es")==0) // Does this actually do anything?
|
||||
ctx->auto_stream = CCX_SM_ELEMENTARY_OR_NOT_FOUND;
|
||||
opt->auto_stream = CCX_SM_ELEMENTARY_OR_NOT_FOUND;
|
||||
else if (strcmp (format,"ts")==0)
|
||||
ctx->auto_stream = CCX_SM_TRANSPORT;
|
||||
opt->auto_stream = CCX_SM_TRANSPORT;
|
||||
else if (strcmp (format,"ps")==0 || strcmp (format,"nots")==0)
|
||||
ctx->auto_stream = CCX_SM_PROGRAM;
|
||||
opt->auto_stream = CCX_SM_PROGRAM;
|
||||
else if (strcmp (format,"asf")==0 || strcmp (format,"dvr-ms")==0)
|
||||
ctx->auto_stream = CCX_SM_ASF;
|
||||
opt->auto_stream = CCX_SM_ASF;
|
||||
else if (strcmp (format,"wtv")==0)
|
||||
ctx->auto_stream = CCX_SM_WTV;
|
||||
opt->auto_stream = CCX_SM_WTV;
|
||||
else if (strcmp (format,"raw")==0)
|
||||
ctx->auto_stream = CCX_SM_MCPOODLESRAW;
|
||||
opt->auto_stream = CCX_SM_MCPOODLESRAW;
|
||||
else if (strcmp (format,"bin")==0)
|
||||
ctx->auto_stream = CCX_SM_RCWT;
|
||||
opt->auto_stream = CCX_SM_RCWT;
|
||||
else if (strcmp (format,"mp4")==0)
|
||||
ctx->auto_stream = CCX_SM_MP4;
|
||||
opt->auto_stream = CCX_SM_MP4;
|
||||
#ifdef WTV_DEBUG
|
||||
else if (strcmp (format,"hex")==0)
|
||||
ctx->auto_stream = CCX_SM_HEX_DUMP;
|
||||
opt->auto_stream = CCX_SM_HEX_DUMP;
|
||||
#endif
|
||||
else
|
||||
fatal (EXIT_MALFORMED_PARAMETER, "Unknown input file format: %s\n", format);
|
||||
@ -797,17 +797,17 @@ void init_option (struct ccx_s_options *option)
|
||||
option->ts_forced_program_selected = 1;
|
||||
}
|
||||
|
||||
void parse_parameters (struct lib_ccx_ctx *ctx, int argc, char *argv[])
|
||||
void parse_parameters (struct ccx_s_options *opt, int argc, char *argv[])
|
||||
{
|
||||
char *cea708_service_list=NULL; // List CEA-708 services
|
||||
|
||||
// Sensible default values for credits
|
||||
stringztoms (DEF_VAL_STARTCREDITSNOTBEFORE, &ccx_options.startcreditsnotbefore);
|
||||
stringztoms (DEF_VAL_STARTCREDITSNOTAFTER, &ccx_options.startcreditsnotafter);
|
||||
stringztoms (DEF_VAL_STARTCREDITSFORATLEAST, &ccx_options.startcreditsforatleast);
|
||||
stringztoms (DEF_VAL_STARTCREDITSFORATMOST, &ccx_options.startcreditsforatmost);
|
||||
stringztoms (DEF_VAL_ENDCREDITSFORATLEAST, &ccx_options.endcreditsforatleast);
|
||||
stringztoms (DEF_VAL_ENDCREDITSFORATMOST, &ccx_options.endcreditsforatmost);
|
||||
stringztoms (DEF_VAL_STARTCREDITSNOTBEFORE, &opt->startcreditsnotbefore);
|
||||
stringztoms (DEF_VAL_STARTCREDITSNOTAFTER, &opt->startcreditsnotafter);
|
||||
stringztoms (DEF_VAL_STARTCREDITSFORATLEAST, &opt->startcreditsforatleast);
|
||||
stringztoms (DEF_VAL_STARTCREDITSFORATMOST, &opt->startcreditsforatmost);
|
||||
stringztoms (DEF_VAL_ENDCREDITSFORATLEAST, &opt->endcreditsforatleast);
|
||||
stringztoms (DEF_VAL_ENDCREDITSFORATMOST, &opt->endcreditsforatmost);
|
||||
|
||||
// Parse parameters
|
||||
for (int i=1; i<argc; i++)
|
||||
@ -815,8 +815,8 @@ void parse_parameters (struct lib_ccx_ctx *ctx, int argc, char *argv[])
|
||||
if (strcmp (argv[i], "-")==0 || strcmp(argv[i], "-stdin") == 0)
|
||||
{
|
||||
|
||||
ccx_options.input_source=CCX_DS_STDIN;
|
||||
ccx_options.live_stream=-1;
|
||||
opt->input_source=CCX_DS_STDIN;
|
||||
opt->live_stream=-1;
|
||||
continue;
|
||||
}
|
||||
if (argv[i][0]!='-')
|
||||
@ -824,12 +824,12 @@ void parse_parameters (struct lib_ccx_ctx *ctx, int argc, char *argv[])
|
||||
int rc;
|
||||
if (argv[i][strlen (argv[i])-1]!='+')
|
||||
{
|
||||
rc=append_file_to_queue (ctx, argv[i]);
|
||||
rc=append_file_to_queue (opt, argv[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
argv[i][strlen (argv[i])-1]=0;
|
||||
rc=add_file_sequence (ctx, argv[i]);
|
||||
rc=add_file_sequence (opt, argv[i]);
|
||||
}
|
||||
if (rc)
|
||||
{
|
||||
@ -888,12 +888,12 @@ void parse_parameters (struct lib_ccx_ctx *ctx, int argc, char *argv[])
|
||||
strcmp (argv[i],"-mp4")==0 ||
|
||||
strcmp (argv[i],"--dvr-ms")==0 )
|
||||
{
|
||||
set_input_format (ctx, argv[i]);
|
||||
set_input_format (opt, argv[i]);
|
||||
continue;
|
||||
}
|
||||
if (strncmp (argv[i],"-in=", 4)==0)
|
||||
{
|
||||
set_input_format (ctx, argv[i]+4);
|
||||
set_input_format (opt, argv[i]+4);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1162,7 +1162,7 @@ void parse_parameters (struct lib_ccx_ctx *ctx, int argc, char *argv[])
|
||||
}
|
||||
if (strcmp (argv[i],"-delay")==0 && i<argc-1)
|
||||
{
|
||||
if (parsedelay (ctx, argv[i+1]))
|
||||
if (parsedelay (opt, argv[i+1]))
|
||||
{
|
||||
fatal (EXIT_MALFORMED_PARAMETER, "-delay only accept integers (such as -300 or 300)\n");
|
||||
}
|
||||
@ -1217,7 +1217,7 @@ void parse_parameters (struct lib_ccx_ctx *ctx, int argc, char *argv[])
|
||||
{
|
||||
if (ccx_options.messages_target==1) // Only change this if still stdout. -quiet could set it to 0 for example
|
||||
ccx_options.messages_target=2; // stderr
|
||||
ctx->cc_to_stdout=1;
|
||||
opt->cc_to_stdout=1;
|
||||
continue;
|
||||
}
|
||||
if (strcmp (argv[i],"-quiet")==0)
|
||||
@ -1383,13 +1383,13 @@ void parse_parameters (struct lib_ccx_ctx *ctx, int argc, char *argv[])
|
||||
}
|
||||
if (strcmp (argv[i],"-o1")==0 && i<argc-1)
|
||||
{
|
||||
ctx->wbout1.filename=argv[i+1];
|
||||
opt->wbout1.filename=argv[i+1];
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
if (strcmp (argv[i],"-o2")==0 && i<argc-1)
|
||||
{
|
||||
ctx->wbout2.filename=argv[i+1];
|
||||
opt->wbout2.filename=argv[i+1];
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
@ -1585,7 +1585,7 @@ void parse_parameters (struct lib_ccx_ctx *ctx, int argc, char *argv[])
|
||||
ccx_options.tcpport = argv[i + 1];
|
||||
ccx_options.input_source = CCX_DS_TCP;
|
||||
|
||||
set_input_format(ctx, "bin");
|
||||
set_input_format(opt, "bin");
|
||||
|
||||
i++;
|
||||
continue;
|
||||
|
Loading…
Reference in New Issue
Block a user