From 0f06f47ab487f8ae6f1c1ad98ac22697e4280e02 Mon Sep 17 00:00:00 2001 From: Anshul Maheshwari Date: Fri, 11 Jul 2014 18:40:00 +0530 Subject: [PATCH] logic to devide time between frames --- src/608.c | 52 +++++++++++++++++++++++++++++++++++++--- src/608.h | 5 +++- src/608_srt.c | 4 ++-- src/cc_decoders_common.h | 10 ++++++++ 4 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 src/cc_decoders_common.h diff --git a/src/608.c b/src/608.c index f926e91f..d1dbdb26 100644 --- a/src/608.c +++ b/src/608.c @@ -1,5 +1,6 @@ #include "ccextractor.h" #include "608_spupng.h" +#include "cc_decoders_common.h" static const int rowdata[] = {11,-1,1,2,3,4,12,13,14,15,5,6,7,8,9,10}; // Relationship between the first PAC byte and the row number @@ -477,7 +478,18 @@ struct eia608_screen *get_current_visible_buffer(struct s_context_cc608 *context int write_cc_buffer(struct s_context_cc608 *context) { struct eia608_screen *data; + struct cc_subtitle *sub = NULL; int wrote_something=0; + LLONG start_time; + LLONG end_time; + + if(!context->sub) + { + sub = + context->sub = malloc(sizeof(struct cc_subtitle)); + } + else + sub = context->sub; if (ccx_options.screens_to_process!=-1 && context->screenfuls_counter >= ccx_options.screens_to_process) { @@ -490,12 +502,45 @@ int write_cc_buffer(struct s_context_cc608 *context) else data = &context->buffer2; + if (context->mode == MODE_FAKE_ROLLUP_1 && // Use the actual start of data instead of last buffer change + context->ts_start_of_current_line != -1) + start_time = context->ts_start_of_current_line; + else + start_time = context->current_visible_start_ms; + + end_time = get_visible_end() + subs_delay; + if (!data->empty) { - if (context->mode == MODE_FAKE_ROLLUP_1 && // Use the actual start of data instead of last buffer change - context->ts_start_of_current_line != -1) - context->current_visible_start_ms = context->ts_start_of_current_line; + sub->data = (struct eia608_screen *) realloc(sub->data,sub->size + sizeof(*data)); + memcpy(sub->data + sub->size, data, sizeof(*data)); + sub->size += sizeof(*data); + wrote_something = 1; + if(start_time < end_time) + { + int i = 0; + int nb_data = sub->size/sizeof(*data); + for(i = 0; i < nb_data; i++) + { + data = sub->data + (i * sizeof(*data) ); + data->start_time = start_time + ( ( (end_time - start_time)/nb_data ) * i ); + data->end_time = start_time + ( ( (end_time - start_time)/nb_data ) * (i + 1) ); + } + } + else + { + data = sub->data; + data->start_time = 0; + data->end_time = 0; + } + + + } + for(data = sub->data; sub->size ; sub->size -= sizeof(struct eia608_screen)) + { + if(!data->start_time) + break; new_sentence=1; switch (ccx_options.write_format) { @@ -528,6 +573,7 @@ int write_cc_buffer(struct s_context_cc608 *context) if (ccx_options.gui_mode_reports) write_cc_buffer_to_gui(data, context); + data = sub->data + sizeof(struct eia608_screen); } return wrote_something; } diff --git a/src/608.h b/src/608.h index 90f90757..bdc71077 100644 --- a/src/608.h +++ b/src/608.h @@ -18,7 +18,9 @@ struct eia608_screen // A CC buffer unsigned char colors[15][33]; unsigned char fonts[15][33]; // Extra char at the end for a 0 int row_used[15]; // Any data in row? - int empty; // Buffer completely empty? + int empty; // Buffer completely empty? + LLONG start_time; + LLONG end_time; }; struct s_context_cc608 @@ -44,6 +46,7 @@ struct s_context_cc608 long bytes_processed_608; // To be written ONLY by process_608 struct ccx_s_write *out; int have_cursor_position; + struct cc_subtitle *sub; }; extern unsigned char *enc_buffer; diff --git a/src/608_srt.c b/src/608_srt.c index 2a5351f3..bdbcc081 100644 --- a/src/608_srt.c +++ b/src/608_srt.c @@ -71,7 +71,7 @@ int write_cc_buffer_as_srt(struct eia608_screen *data, struct s_context_cc608 *c unsigned h2,m2,s2,ms2; LLONG ms_start, ms_end; int wrote_something = 0; - ms_start = context->current_visible_start_ms; + ms_start = data->start_time; int prev_line_start=-1, prev_line_end=-1; // Column in which the previous line started and ended, for autodash int prev_line_center1=-1, prev_line_center2=-1; // Center column of previous line text @@ -91,7 +91,7 @@ int write_cc_buffer_as_srt(struct eia608_screen *data, struct s_context_cc608 *c if (ms_start<0) // Drop screens that because of subs_delay start too early return 0; - ms_end=get_visible_end()+subs_delay; + ms_end = data->end_time; mstotime (ms_start,&h1,&m1,&s1,&ms1); mstotime (ms_end-1,&h2,&m2,&s2,&ms2); // -1 To prevent overlapping with next line. diff --git a/src/cc_decoders_common.h b/src/cc_decoders_common.h new file mode 100644 index 00000000..3e278905 --- /dev/null +++ b/src/cc_decoders_common.h @@ -0,0 +1,10 @@ +#ifndef _CC_DECODER_COMMON +#define _CC_DECODER_COMMON + +struct cc_subtitle +{ + void *data; + size_t size; + enum ccx_encoding_type format; +}; +#endif