diff --git a/src/lib_ccx/ccx_common_option.c b/src/lib_ccx/ccx_common_option.c index 2f13927e4..7a69e164f 100644 --- a/src/lib_ccx/ccx_common_option.c +++ b/src/lib_ccx/ccx_common_option.c @@ -65,6 +65,8 @@ void init_options (struct ccx_s_options *options) options->output_filename = NULL; options->debug_mask=CCX_DMT_GENERIC_NOTICES; // dbg_print will use this mask to print or ignore different types options->debug_mask_on_debug=CCX_DMT_VERBOSE; // If we're using temp_debug to enable/disable debug "live", this is the mask when temp_debug=1 + options->force_flush = 0; //Default value=0 + /* Networking */ options->udpaddr = NULL; options->udpport=0; // Non-zero => Listen for UDP packets on this port, no files. diff --git a/src/lib_ccx/ccx_common_option.h b/src/lib_ccx/ccx_common_option.h index 570c174e0..a143901b9 100644 --- a/src/lib_ccx/ccx_common_option.h +++ b/src/lib_ccx/ccx_common_option.h @@ -35,7 +35,7 @@ struct encoder_cfg char *output_filename; enum ccx_output_format write_format; // 0=Raw, 1=srt, 2=SMI int keep_output_closed; - + int force_flush; //Flushing only when passed as a parameter enum ccx_encoding_type encoding; enum ccx_output_date_format date_format; char millis_separator; @@ -80,7 +80,7 @@ struct ccx_s_options // Options from user parameters struct ccx_boundary_time extraction_start, extraction_end; // Segment we actually process int print_file_reports; - + int force_flush ; // Flushing only when passed as a parameter. //0 - Don't flush, 1- Force Flush ccx_decoder_608_settings settings_608; // Contains the settings for the 608 decoder. ccx_decoder_dtvcc_settings settings_dtvcc; //Same for 708 decoder diff --git a/src/lib_ccx/ccx_encoders_common.c b/src/lib_ccx/ccx_encoders_common.c index c9d01bd04..00be0e4da 100644 --- a/src/lib_ccx/ccx_encoders_common.c +++ b/src/lib_ccx/ccx_encoders_common.c @@ -1066,7 +1066,8 @@ static int init_output_ctx(struct encoder_ctx *ctx, struct encoder_cfg *cfg) return -1; ctx->nb_out = nb_lang; ctx->keep_output_closed = cfg->keep_output_closed; - + ctx->force_flush = cfg->force_flush; + if(cfg->cc_to_stdout == CCX_FALSE && cfg->send_to_srv == CCX_FALSE) { if (cfg->output_filename != NULL) @@ -1254,7 +1255,8 @@ struct encoder_ctx *init_encoder(struct encoder_cfg *opt) ctx->gui_mode_reports = opt->gui_mode_reports; ctx->extract = opt->extract; ctx->keep_output_closed = opt->keep_output_closed; - + ctx->force_flush = opt->force_flush; + ctx->subline = (unsigned char *) malloc (SUBLINESIZE); if(!ctx->subline) { @@ -1498,7 +1500,8 @@ int encode_sub(struct encoder_ctx *context, struct cc_subtitle *sub) } if (!sub->nb_data) freep(&sub->data); - if (wrote_something) + //Flush only if -forceflush has been parsed and wrote_something returns non-zero value(by default both 0). + if (wrote_something && context->force_flush) fsync(context->out->fh); // Don't buffer return wrote_something; } diff --git a/src/lib_ccx/ccx_encoders_common.h b/src/lib_ccx/ccx_encoders_common.h index e73ca03b3..f675e340a 100644 --- a/src/lib_ccx/ccx_encoders_common.h +++ b/src/lib_ccx/ccx_encoders_common.h @@ -96,6 +96,7 @@ struct encoder_ctx int program_number; struct list_head list; + int force_flush; //Flush only if the parameter is passed }; #define INITIAL_ENC_BUFFER_CAPACITY 2048 diff --git a/src/lib_ccx/lib_ccx.c b/src/lib_ccx/lib_ccx.c index ae0638f90..f309bea0c 100644 --- a/src/lib_ccx/lib_ccx.c +++ b/src/lib_ccx/lib_ccx.c @@ -145,7 +145,7 @@ struct lib_ccx_ctx* init_libraries(struct ccx_s_options *opt) ctx->pesheaderbuf = (unsigned char *) malloc (188); // Never larger anyway ctx->cc_to_stdout = opt->cc_to_stdout; - + ctx->force_flush = opt->force_flush; ctx->hauppauge_mode = opt->hauppauge_mode; ctx->live_stream = opt->live_stream; ctx->binary_concat = opt->binary_concat; @@ -326,6 +326,8 @@ struct encoder_ctx *update_encoder_list_cinfo(struct lib_ccx_ctx *ctx, struct ca return enc_ctx; } + enc_ctx->force_flush = ctx->force_flush; + extension = get_file_extension(ccx_options.enc_cfg.write_format); if(!extension) return NULL; diff --git a/src/lib_ccx/lib_ccx.h b/src/lib_ccx/lib_ccx.h index dbe73dac0..605098f98 100644 --- a/src/lib_ccx/lib_ccx.h +++ b/src/lib_ccx/lib_ccx.h @@ -137,6 +137,7 @@ struct lib_ccx_ctx int out_interval; int segment_counter; LLONG system_start_time; + int force_flush; }; diff --git a/src/lib_ccx/params.c b/src/lib_ccx/params.c index 7b7a1e422..dc9c79310 100644 --- a/src/lib_ccx/params.c +++ b/src/lib_ccx/params.c @@ -520,6 +520,8 @@ void usage (void) mprint (" -koc: keep-output-close. If used then CCExtractor will close\n"); mprint (" the output file after writing each subtitle frame and\n"); mprint (" attempt to create it again when needed."); + mprint ("\t-ff --forceflush: Turn on Force Flush\n"); + mprint ("\n"); mprint ("Options that affect the built-in closed caption decoder:\n"); @@ -1707,6 +1709,11 @@ int parse_parameters (struct ccx_s_options *opt, int argc, char *argv[]) i++; continue; } + if (strcmp (argv[i],"-ff") == 0 || strcmp (argv[i],"-forceflush") == 0) + { + opt->force_flush = 1; + continue; + } fatal (EXIT_INCOMPATIBLE_PARAMETERS, "Error: Parameter %s not understood.\n", argv[i]); // Unrecognized switches are silently ignored @@ -1818,6 +1825,7 @@ int parse_parameters (struct ccx_s_options *opt, int argc, char *argv[]) opt->enc_cfg.no_font_color = opt->nofontcolor; opt->enc_cfg.no_type_setting = opt->notypesetting; opt->enc_cfg.subs_delay = opt->subs_delay; + opt->enc_cfg.force_flush = opt->force_flush; if(opt->output_filename && opt->multiprogram == CCX_FALSE) opt->enc_cfg.output_filename = strdup(opt->output_filename); else