From 0c29b8b27d518e9ede76b03fa89826e6795491d6 Mon Sep 17 00:00:00 2001 From: Anshul Maheshwari Date: Tue, 1 Jul 2014 17:49:21 +0530 Subject: [PATCH] Support for configuration file --- docs/ccextractor.cnf.sample | 369 ++++++++++++++++++++++++++++++++++++ src/ccextractor.c | 2 + src/ccextractor.h | 4 +- src/configuration.c | 148 +++++++++++++++ src/configuration.h | 4 + src/params.c | 37 ++-- 6 files changed, 549 insertions(+), 15 deletions(-) create mode 100644 docs/ccextractor.cnf.sample create mode 100644 src/configuration.c create mode 100644 src/configuration.h diff --git a/docs/ccextractor.cnf.sample b/docs/ccextractor.cnf.sample new file mode 100644 index 00000000..89dccfb4 --- /dev/null +++ b/docs/ccextractor.cnf.sample @@ -0,0 +1,369 @@ +# The Input Source tag option give ability to user +# to take imput from file, standurd input or network +# This tag take number in its input and there meanings +# are following +# 0 = file +# 1 = stdin +# 2 = network + +INPUT_SOURCE=1 + +# The Buffer Input tag +# This tag take number in its input and there meanings +# are following + +BUFFER_INPUT=0 + +# The Direct Rollup tag +# This tag take number in its input and there meanings +# are following + +DIRECT_ROLLUP= + +#The No font Color Tag +# This tag take number in its input and there meanings +# are following +# 0 = no +# 1 = yes + +NOFONT_COLOR= + +#The No type Setting Tag +# This tag take number in its input and there meanings +# are following +# 0 = no +# 1 = yes + +NOTYPE_SETTING= + +# The Codec Tag take the preference of codec +# tag CCX_CODEC_ANY is by default +# This tag take number in its input and there meaning +# are following +# 0 = CCX_CODEC_ANY +# 1 = CCX_CODEC_TELETEXT +# 2 = CCX_CODEC_DVB + +CODEC= + +# The NO Codec Tag do not use codec specified +# tag CCX_CODEC_NONE is by default +# This tag take number in its input and there meaning +# are following +# 1 = CCX_CODEC_TELETEXT +# 2 = CCX_CODEC_DVB +# 3 = CCX_CODEC_NONE + +NOCODEC= + +# OUTPUT_FORMAT tag specify format of output +# by default output format is srt +# This tag take number in its input and there meaning +# are following +# 0 = CCX_OF_RAW +# 1 = CCX_OF_SRT (default) +# 2 = CCX_OF_SAMI +# 3 = CCX_OF_TRANSCRIPT +# 4 = CCX_OF_RCWT +# 5 = CCX_OF_NULL +# 6 = CCX_OF_SMPTETT +# 7 = CCX_OF_SPUPNG +# 8 = CCX_OF_DVDRAW + +OUTPUT_FORMAT= + +# Start credit Text is shown at start +# this tag take text in input +# Please note text is limited to one line in configuration +# file + +START_CREDIT_TEXT= + +# Start credit do not start before apecified time in tag +# this tag only accepts SS, MM:SS or HH:MM:SS + +START_CREDIT_NOT_BEFORE= + +# Start credits do not start after specified time in tag +# this tag only accepts SS, MM:SS or HH:MM:SS + +START_CREDIT_NOT_AFTER= + +# Start credits run for at least time specied in tag +# this tag only accepts SS, MM:SS or HH:MM:SS + +START_CREDIT_FOR_ATLEAST= + +# Start credits are displayed for atmost time specified in tag +# this tag only accepts SS, MM:SS or HH:MM:SS + +START_CREDIT_FOR_ATMOST= + +# End Credit text are shown at beginning +# this tag take text in input +# Please note text is limited to one line in configuration +# file + +END_CREDITS_TEXT= + +# End credits run for at least time specied in tag +# this tag only accepts SS, MM:SS or HH:MM:SS + +END_CREDITS_FOR_ATLEAST + +# End credits are displayed for atmost time specified in tag +# this tag only accepts SS, MM:SS or HH:MM:SS + +END_CREDITS_FOR_ATMOST + +# Is Video edited or splitted by tool +# By default its 1, ccextractor will process input files in +# sequence as if they were all one large file i.e +# split by a generic, non video-aware tool. If you +# are processing video hat was split with a editing +# tool, use 0 so ccextractor doesn't try to rebuild +# the original timing. +# This tag take 0 or 1 in input + +VIDEO_EDITED=1 + +# Use GOP for timing instead of PTS. This only applies +# to Program or Transport Streams with MPEG2 data and +# overrides the default PTS timing,GOP timing is always +# used for Elementary Streams. +# +# This tag take number in its input and there meaning +# are following +# 0 = use pts for time (when reasonable) +# 1 = use gop for time (when reasonable) +# -1 = Never use GOP timing (use PTS), even if ccextractor +# detects GOP timing is the reasonable choice. + +GOP_TIME=0 + +# Fix padding - some cards (or providers, or whatever) +# seem to send 0000 as CC padding instead of 8080. If you +# get bad timing, this might solve it. +# +# This tag take number in its input and there meaning +# are following +# 0 = no +# 1 = yes + +FIX_PADDINDG=0 + +# If you hate the repeated lines caused by the roll-up +# emulation, you can have ccextractor write only one +# line at a time, getting rid of these repeated lines. +# +# This tag take number in its input and there meaning +# are following +# 0 = no (default) +# 1 = yes + +NO_ROLL_UP=0 + +# Roll-up captions can consist of 2, 3 or 4 visible +# lines at any time (the number of lines is part of +# the transmission). If having 3 or 4 lines annoys +# you can use this tag to force the decoder to always +# use 1, 2 or 3 lines. Note that 1 line is not +# a real mode rollup mode, so CCExtractor does what +# it can. +# In value = 1 the start timestamp is actually the timestamp +# of the first character received which is possibly more +# accurate. +# +# This tag take number in its input and there meaning +# are following +# 1 +# 2 +# 3 + +FORCED_RU + +# This tag trim line +# This tag take number in its input and there meaning +# are following +# 0 = no +# 1 = yes + +TRIM=0 + +# +# Report progress and interesting events to stderr +# in a easy to parse format. This is intended to be +# used by other programs. See docs directory for details +# This tag take number in its input and there meaning +# are following +# 0 = no +# 1 = yes + +GUI_MODE_REPORTS=0 + +# Suppress the output of the progress bar +# This tag take number in its input and there meaning +# are following +# 0 = no +# 1 = yes + +NO_PROGRESS_BAR=0 + +# Sentence capitalization. Use if you hate +# ALL CAPS in subtitles +# This tag take number in its input and there meaning +# are following +# 0 = no +# 1 = yes + +SENTENCE_CAP=0 + +#this tag take Dictionary file name containing words in each line + +#CAP_FILE=Dictionary.txt + +# Program number(pid) to be selected from ts file +# This tag take number in its input and there meaning +# are following +# -1 = automaticaly selected +# X = actual program pid in ts file + +PROGRAM_NUMBER=-1 + +# select automaticaly program from ts file +# This tag take number in its input and there meaning +# are following +# 0 = no +# 1 = yes + +AUTO_PROGRAM=0 + +# Stream number(pid) to be selected from file +# This tag take number in its input and there meaning +# are following +# -1 = automaticaly selected +# X = actual stream pid in ts file + +STREAM=-1 + +#Write number of screenfuls and terminate processing +#This tag take number of secreen + +#SCREEN_TO_PROCESS=100 + +# start extraction from the time specified +# this tag only accepts SS, MM:SS or HH:MM:SS + +START_AT + +# End extraction at the time specified +# this tag only accepts SS, MM:SS or HH:MM:SS + +END_AT + +# If no CC packets are detected based on the PMT, try +# to find data in all packets by scanning. +# This tag take number in its input and there meaning +# are following +# 0 = no +# 1 = yes + +INVASTIGATE_PACKET=0 + +# If the video was recorder using a Hauppauge card, it +# might need special processing. This parameter will +# force the special treatment. + +HAUPPAUGE_MODE=0 + +# MP4 files the closed caption data can be embedded in +# the video track or in a dedicated CC track. If a +# dedicated track is detected it will be processed instead +# of the video track. If you need to force the video track +# to be processed instead use this option. +# This tag take number in its input and there meaning +# are following +# 0 = no +# 1 = yes + +MP4_VIDEO_TRACK + +# File need to be encoding in which format +# This tag take number in its input and there meaning +# are following +# 0 = no +# 0 = CX_ENC_UNICODE +# 1 = CCX_ENC_LATIN_1 +# 2 = CCX_ENC_UTF_8 + +ENCODING=2 + +# Use the pic_order_cnt_lsb in AVC/H.264 data streams +# to order the CC information. The default way is to +# use the PTS information. Use this switch only when +# needed. +# This tag take number in its input and there meaning +# are following +# 0 = no +# 1 = yes + +USE_PIC_ORDER=0 + +# The MythTV branch is needed for analog captures where +# the closed caption data is stored in the VBI, such as +# those with bttv cards (Hauppage 250 for example). This +# is detected automatically so you don't need to worry +# about this unless autodetection doesn't work for you. +# This tag take number in its input and there meaning +# are following +# 0 = NO Myth +# 1 = Myth +# 2 = Auto + +AUTO_MYTH=2 + +# Read the captions from the MPEG2 video stream rather +# than the captions stream in WTV files +# This tag take number in its input and there meaning +# are following +# 0 = no +# 1 = yes + +WTV_MPEG2=0 + +# This tag take output file name + +#OUTPUT_FILENAME=output.srt + +# Don't try to find out the stream for subtitles +# use the provided pid +# Takes number as input + +#DATA_PID=0x100 + +# Instead of selecting the stream by its PID, select it +# by its type (pick the stream that has this type in +# the PMT +# Takes number as input + +#STREAM_TYPE=0x6 + +# Assume the data is of this type, don't autodetect. This +# parameter may be needed if DATA_PID or STREAM_TYPE tag +# is set and CCExtractor cannot determine how to process +# the stream. The value may be 2 (MPEG video) or +# 6 (MPEG private data). +# +# Tekes number in input + +#TS_FORCED_STREAM_TYPE=0x6 + +# This tag specify the format of date +# 0 = ODF_NONE +# 1 = ODF_HHMMSS +# 2 = ODF_SECONDS +# 3 = ODF_DATE +# 4 = ODF_HHMMSSMS ( HH:MM:SS,MILIS .srt style ) + + +#DATE_FORMAT=4 diff --git a/src/ccextractor.c b/src/ccextractor.c index 6ef019ce..0688c3ca 100644 --- a/src/ccextractor.c +++ b/src/ccextractor.c @@ -4,6 +4,7 @@ License: GPL 2.0 */ #include #include "ccextractor.h" +#include "configuration.h" #include #include @@ -277,6 +278,7 @@ int main(int argc, char *argv[]) int show_myth_banner = 0; memset (&cea708services[0],0,63*sizeof (int)); + parse_configuration(&ccx_options); parse_parameters (argc,argv); if (num_input_files==0 && ccx_options.input_source==CCX_DS_FILE) diff --git a/src/ccextractor.h b/src/ccextractor.h index 561519aa..26eb2835 100644 --- a/src/ccextractor.h +++ b/src/ccextractor.h @@ -233,9 +233,11 @@ struct ccx_s_teletext_config { extern LLONG buffered_read_opt (unsigned char *buffer, unsigned int bytes); -//params.cpp +//params.c void parse_parameters (int argc, char *argv[]); void usage (void); +int atoi_hex (char *s); +int stringztoms (const char *s, struct ccx_boundary_time *bt); // general_loop.cpp void position_sanity_check (); diff --git a/src/configuration.c b/src/configuration.c new file mode 100644 index 00000000..ed3e210b --- /dev/null +++ b/src/configuration.c @@ -0,0 +1,148 @@ +#include "ccextractor.h" +#include "configuration.h" +#include +#define CNF_FILE "ccextractor.cnf" +struct conf_map +{ + char *name; + int offset; + int (*parse_val)(void *var,char*val); +}; + + +static int set_string(void *var,char*val) +{ + char **p = (char**)var; + char *val1 = NULL; + + if(val == NULL) + return -1; + + val1 = strdup(val); + *p = val1; + return 0; +} +static int set_time(void *var, char*val) +{ + struct ccx_boundary_time **p = (struct ccx_boundary_time **)var; + if(val == NULL) + return -1; + + return stringztoms(val,*p); + +} +static int set_int(void *var, char*val) +{ + int *p = (int*)var; + if(val == NULL) + return -1; + + *p = atoi_hex(val); + return 0; +} + +struct conf_map configuration_map[] = { + {"INPUT_SOURCE",offsetof(struct ccx_s_options,input_source),set_int}, + {"BUFFER_INPUT",offsetof(struct ccx_s_options,buffer_input),set_int}, + {"DIRECT_ROLLUP",offsetof(struct ccx_s_options,direct_rollup),set_int}, + {"NOFONT_COLOR",offsetof(struct ccx_s_options,nofontcolor),set_int}, + {"NOTYPE_SETTING",offsetof(struct ccx_s_options,notypesetting),set_int}, + {"CODEC",offsetof(struct ccx_s_options,codec),set_int}, + {"NOCODEC",offsetof(struct ccx_s_options,nocodec),set_int}, + {"OUTPUT_FORMAT",offsetof(struct ccx_s_options,write_format),set_int}, + {"START_CREDIT_TEXT",offsetof(struct ccx_s_options,start_credits_text),set_string}, + {"START_CREDIT_NOT_BEFORE",offsetof(struct ccx_s_options,startcreditsnotbefore),set_time}, + {"START_CREDIT_NOT_AFTER",offsetof(struct ccx_s_options,startcreditsnotafter),set_time}, + {"START_CREDIT_FOR_ATLEAST",offsetof(struct ccx_s_options,startcreditsforatleast),set_time}, + {"START_CREDIT_FOR_ATMOST",offsetof(struct ccx_s_options,startcreditsforatmost),set_time}, + {"END_CREDITS_TEXT",offsetof(struct ccx_s_options,end_credits_text),set_string}, + {"END_CREDITS_FOR_ATLEAST",offsetof(struct ccx_s_options,endcreditsforatleast),set_time}, + {"END_CREDITS_FOR_ATMOST",offsetof(struct ccx_s_options,endcreditsforatmost),set_time}, + {"VIDEO_EDITED",offsetof(struct ccx_s_options,binary_concat),set_int}, + {"GOP_TIME",offsetof(struct ccx_s_options,use_gop_as_pts),set_int}, + {"FIX_PADDINDG",offsetof(struct ccx_s_options,fix_padding),set_int}, + {"NO_ROLL_UP",offsetof(struct ccx_s_options,norollup),set_int}, + {"FORCED_RU",offsetof(struct ccx_s_options,forced_ru),set_int}, + {"TRIM",offsetof(struct ccx_s_options,trim_subs),set_int}, + {"GUI_MODE_REPORTS",offsetof(struct ccx_s_options,gui_mode_reports),set_int}, + {"NO_PROGRESS_BAR",offsetof(struct ccx_s_options,no_progress_bar),set_int}, + {"SENTENCE_CAP",offsetof(struct ccx_s_options,sentence_cap),set_int}, + {"CAP_FILE",offsetof(struct ccx_s_options,sentence_cap_file),set_string}, + {"PROGRAM_NUMBER",offsetof(struct ccx_s_options,ts_forced_program),set_int}, + {"AUTO_PROGRAM",offsetof(struct ccx_s_options,ts_autoprogram),set_int}, + {"STREAM",offsetof(struct ccx_s_options,live_stream),set_int}, + {"SCREEN_TO_PROCESS",offsetof(struct ccx_s_options,screens_to_process),set_int}, + {"START_AT",offsetof(struct ccx_s_options,extraction_start),set_time}, + {"END_AT",offsetof(struct ccx_s_options,extraction_end),set_time}, + {"INVASTIGATE_PACKET",offsetof(struct ccx_s_options,investigate_packets),set_int}, + {"FULL_BIN",offsetof(struct ccx_s_options,fullbin),set_int}, + {"NO_SYNC",offsetof(struct ccx_s_options,nosync),set_int}, + {"HAUPPAUGE_MODE",offsetof(struct ccx_s_options,hauppauge_mode),set_int}, + {"MP4_VIDEO_TRACK",offsetof(struct ccx_s_options,mp4vidtrack),set_int}, + {"ENCODING",offsetof(struct ccx_s_options,encoding),set_int}, + {"USE_PIC_ORDER",offsetof(struct ccx_s_options,usepicorder),set_int}, + {"AUTO_MYTH",offsetof(struct ccx_s_options,auto_myth),set_int}, + {"WTV_MPEG2",offsetof(struct ccx_s_options,wtvmpeg2),set_int}, + {"OUTPUT_FILENAME",offsetof(struct ccx_s_options,output_filename),set_string}, + {"OUT_ELEMENTRY_STREAM_FILENAME",offsetof(struct ccx_s_options,out_elementarystream_filename),set_string}, + {"DATA_PID",offsetof(struct ccx_s_options,ts_cappid),set_int}, + {"STREAM_TYPE",offsetof(struct ccx_s_options,ts_datastreamtype),set_int}, + {"TS_FORCED_STREAM_TYPE",offsetof(struct ccx_s_options,ts_forced_streamtype),set_int}, + {"DATE_FORMAT",offsetof(struct ccx_s_options,date_format),set_int}, + {NULL} +}; +static int parse_opts(char *str, struct ccx_s_options *opt) +{ + struct conf_map *lmap = configuration_map; + char *var = strtok(str,"="); + if(!var) + return -1; + while(lmap->name) + { + if(!strcmp(lmap->name,var)) + { + char *val = strtok(NULL,"="); + return lmap->parse_val((void*)((char*)opt + lmap->offset ),val); + } + lmap++; + } + return 0; +} +static void parse_file(FILE *f,struct ccx_s_options *opt) +{ + char *str = (char*)malloc(128); + char c = '\0'; + int comments = 0; + int i = 0; + int ret = 0; + while ((c = fgetc(f)) != EOF ) + { + if( c == '\n') + { + if( str[0] != '\0') + ret = parse_opts(str,opt); + if(ret < 0) + mprint("invalid configuration file\n"); + comments = 0; + i = 0; + continue; + } + if(comments || c == '#') + { + comments = 1; + continue; + } + str[i] = c; + i++; + } + free(str); +} +void parse_configuration(struct ccx_s_options *opt) +{ + FILE *f = NULL; + if( (f = fopen(CNF_FILE,"r") ) != NULL) + { + parse_file(f,opt); + } + +} diff --git a/src/configuration.h b/src/configuration.h new file mode 100644 index 00000000..c6114424 --- /dev/null +++ b/src/configuration.h @@ -0,0 +1,4 @@ +#ifndef _CONFIGURATION_H +#define _CONFIGURATION_H +void parse_configuration(struct ccx_s_options *opt); +#endif diff --git a/src/params.c b/src/params.c index ea7ae026..274b71e1 100644 --- a/src/params.c +++ b/src/params.c @@ -789,6 +789,28 @@ int atoi_hex (char *s) return atoi (s); } } +void init_option (struct ccx_s_options *option) +{ + if(option->gui_mode_reports) + { + option->no_progress_bar=1; + // Do it as soon as possible, because it something fails we might not have a chance + activity_report_version(); + } + + if(option->sentence_cap) + { + if(add_built_in_words()) + fatal (EXIT_NOT_ENOUGH_MEMORY, "Not enough memory for word list"); + if(option->sentence_cap_file && process_cap_file (option->sentence_cap_file)) + fatal (EXIT_ERROR_IN_CAPITALIZATION_FILE, "There was an error processing the capitalization file.\n"); + + shell_sort(spell_lower,spell_words,sizeof(*spell_lower),string_cmp2,NULL); + shell_sort(spell_correct,spell_words,sizeof(*spell_correct),string_cmp2,NULL); + } + if(option->ts_forced_program != -1) + option->ts_forced_program_selected = 1; +} void parse_parameters (int argc, char *argv[]) { @@ -830,7 +852,7 @@ void parse_parameters (int argc, char *argv[]) } continue; } - if (strcmp (argv[i],"-bi")==0 || + if (strcmp (argv[i],"-bi")==0 || strcmp (argv[i],"--bufferinput")==0) { ccx_options.buffer_input = 1; @@ -1083,9 +1105,6 @@ void parse_parameters (int argc, char *argv[]) if (strcmp (argv[i],"--gui_mode_reports")==0) { ccx_options.gui_mode_reports=1; - ccx_options.no_progress_bar=1; - // Do it as soon as possible, because it something fails we might not have a chance - activity_report_version(); continue; } if (strcmp (argv[i],"--no_progress_bar")==0) @@ -1096,26 +1115,16 @@ void parse_parameters (int argc, char *argv[]) if (strcmp (argv[i],"--sentencecap")==0 || strcmp (argv[i],"-sc")==0) { - if (add_built_in_words()) - fatal (EXIT_NOT_ENOUGH_MEMORY, "Not enough memory for word list"); ccx_options.sentence_cap=1; - shell_sort(spell_lower,spell_words,sizeof(*spell_lower),string_cmp2,NULL); - shell_sort(spell_correct,spell_words,sizeof(*spell_correct),string_cmp2,NULL); continue; } if ((strcmp (argv[i],"--capfile")==0 || strcmp (argv[i],"-caf")==0) && i