int write_cc_line(ccx_decoder_608_context *context, struct cc_subtitle *sub) { struct eia608_screen *data; LLONG start_time; LLONG end_time; int i = 0; int wrote_something=0; int ret = 0; data = get_current_visible_buffer(context); start_time = context->ts_start_of_current_line + context->subs_delay; end_time = get_fts() + context->subs_delay; sub->type = CC_608; data->format = SFORMAT_CC_LINE; data->start_time = 0; data->end_time = 0; data->mode = context->mode; data->channel = context->channel; data->my_field = context->my_field; //TODO need to put below functionality in encoder context ret = get_decoder_line_basic (subline, context->cursor_row, data,context->trim_subs,context->encoding); if( ret > 0 ) { sub->data = (struct eia608_screen *) realloc(sub->data,(sub->nb_data +1) * sizeof(*data)); if (!sub->data) { ccx_common_logging.log_ftn("No Memory left"); return 0; } memcpy(((struct eia608_screen *)sub->data) + sub->nb_data, data, sizeof(*data)); data = (struct eia608_screen *)sub->data + sub->nb_data; sub->nb_data++; for(i = 0; i < 15; i++) { if(i == context->cursor_row) data->row_used[i] = 1; else data->row_used[i] = 0; } wrote_something = 1; if(start_time < end_time) { int nb_data = sub->nb_data; data = (struct eia608_screen *)sub->data; for(i = 0;(unsigned) i < sub->nb_data; i++) { if(!data->start_time) break; nb_data--; data++; } for(i = 0;(int) i < nb_data; i++) { 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) ); data++; } sub->got_output = 1; } } return wrote_something; }
void write_cc_line_as_transcript2(struct eia608_screen *data, struct encoder_ctx *context, int line_number) { unsigned h1,m1,s1,ms1; unsigned h2,m2,s2,ms2; LLONG start_time = data->start_time; LLONG end_time = data->end_time; if (ccx_options.sentence_cap) { capitalize (line_number,data); correct_case(line_number,data); } int length = get_decoder_line_basic (subline, line_number, data,ccx_options.trim_subs,ccx_options.encoding); if (ccx_options.encoding!=CCX_ENC_UNICODE) { dbg_print(CCX_DMT_DECODER_608, "\r"); dbg_print(CCX_DMT_DECODER_608, "%s\n",subline); } if (length>0) { if (data->start_time == -1) { // CFS: Means that the line has characters but we don't have a timestamp for the first one. Since the timestamp // is set for example by the write_char function, it possible that we don't have one in empty lines (unclear) // For now, let's not consider this a bug as before and just return. // fatal (EXIT_BUG_BUG, "Bug in timedtranscript (ts_start_of_current_line==-1). Please report."); return; } if (ccx_options.transcript_settings.showStartTime){ char buf1[80]; if (ccx_options.transcript_settings.relativeTimestamp){ millis_to_date(start_time + context->subs_delay, buf1); fdprintf(context->out->fh, "%s|", buf1); } else { mstotime(start_time + context->subs_delay, &h1, &m1, &s1, &ms1); time_t start_time_int = (start_time + context->subs_delay) / 1000; int start_time_dec = (start_time + context->subs_delay) % 1000; struct tm *start_time_struct = gmtime(&start_time_int); strftime(buf1, sizeof(buf1), "%Y%m%d%H%M%S", start_time_struct); fdprintf(context->out->fh, "%s%c%03d|", buf1,ccx_options.millis_separator,start_time_dec); } } if (ccx_options.transcript_settings.showEndTime){ char buf2[80]; if (ccx_options.transcript_settings.relativeTimestamp){ millis_to_date(end_time, buf2); fdprintf(context->out->fh, "%s|", buf2); } else { mstotime(get_fts() + context->subs_delay, &h2, &m2, &s2, &ms2); time_t end_time_int = (end_time + context->subs_delay) / 1000; int end_time_dec = (end_time + context->subs_delay) % 1000; struct tm *end_time_struct = gmtime(&end_time_int); strftime(buf2, sizeof(buf2), "%Y%m%d%H%M%S", end_time_struct); fdprintf(context->out->fh, "%s%c%03d|", buf2,ccx_options.millis_separator,end_time_dec); } } if (ccx_options.transcript_settings.showCC){ fdprintf(context->out->fh, "CC%d|", data->my_field == 1 ? data->channel : data->channel + 2); // Data from field 2 is CC3 or 4 } if (ccx_options.transcript_settings.showMode){ const char *mode = "???"; switch (data->mode) { case MODE_POPON: mode = "POP"; break; case MODE_FAKE_ROLLUP_1: mode = "RU1"; break; case MODE_ROLLUP_2: mode = "RU2"; break; case MODE_ROLLUP_3: mode = "RU3"; break; case MODE_ROLLUP_4: mode = "RU4"; break; case MODE_TEXT: mode = "TXT"; break; case MODE_PAINTON: mode = "PAI"; break; } fdprintf(context->out->fh, "%s|", mode); } write(context->out->fh, subline, length); write(context->out->fh, encoded_crlf, encoded_crlf_length); } // fprintf (wb->fh,encoded_crlf); }