From f2b8b43bae7a2f6866fa9ed9696e20ceec964b7c Mon Sep 17 00:00:00 2001 From: Evgeny Date: Thu, 5 Jan 2017 11:38:04 +0300 Subject: [PATCH] Added PAC row positioning --- src/lib_ccx/ccx_encoders_common.c | 2 +- src/lib_ccx/ccx_encoders_common.h | 4 +-- src/lib_ccx/ccx_encoders_webvtt.c | 46 ++++++++++++++++-------------- src/lib_ccx/dvb_subtitle_decoder.c | 2 +- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/lib_ccx/ccx_encoders_common.c b/src/lib_ccx/ccx_encoders_common.c index 45a6f3fb..70027ada 100644 --- a/src/lib_ccx/ccx_encoders_common.c +++ b/src/lib_ccx/ccx_encoders_common.c @@ -935,7 +935,7 @@ struct encoder_ctx *init_encoder(struct encoder_cfg *opt) ctx->capacity=INITIAL_ENC_BUFFER_CAPACITY; ctx->srt_counter = 0; - ctx->wrote_webvtt_sync_header = 0; + ctx->wrote_webvtt_header = 0; ctx->program_number = opt->program_number; ctx->send_to_srv = opt->send_to_srv; diff --git a/src/lib_ccx/ccx_encoders_common.h b/src/lib_ccx/ccx_encoders_common.h index ba5a87d0..4559c3ef 100644 --- a/src/lib_ccx/ccx_encoders_common.h +++ b/src/lib_ccx/ccx_encoders_common.h @@ -45,8 +45,8 @@ struct encoder_ctx /* keep count of srt subtitle*/ unsigned int srt_counter; - /* Did we write the WebVTT sync header already? */ - unsigned int wrote_webvtt_sync_header; + /* Did we write the WebVTT header already? */ + unsigned int wrote_webvtt_header; /* Input outputs */ /* Flag giving hint that output is send to server through network */ diff --git a/src/lib_ccx/ccx_encoders_webvtt.c b/src/lib_ccx/ccx_encoders_webvtt.c index fc60a79e..f3ba8a89 100644 --- a/src/lib_ccx/ccx_encoders_webvtt.c +++ b/src/lib_ccx/ccx_encoders_webvtt.c @@ -115,6 +115,9 @@ static const char *webvtt_inline_css = "/* default values */\n" " background-color: rgba(0, 0, 0, 0.5);\n" "}\n"; +static const char** webvtt_pac_row_percent[] = { "10", "15.33", "20.66", "26", "31.33", "36.66", "42", + "47.33", "52.66", "58", "63.33", "68.66", "74", "79.33", "84.66" }; + /* The timing here is not PTS based, but output based, i.e. user delay must be accounted for if there is any */ int write_stringz_as_webvtt(char *string, struct encoder_ctx *context, LLONG ms_start, LLONG ms_end) @@ -198,9 +201,9 @@ int write_stringz_as_webvtt(char *string, struct encoder_ctx *context, LLONG ms_ return 0; } -int write_xtimestamp_header(struct encoder_ctx *context) +int write_webvtt_header(struct encoder_ctx *context) { - if (context->wrote_webvtt_sync_header) // Already done + if (context->wrote_webvtt_header) // Already done return 1; if (ccx_options.webvtt_create_css) @@ -242,7 +245,7 @@ int write_xtimestamp_header(struct encoder_ctx *context) } - context->wrote_webvtt_sync_header = 1; // Do it even if couldn't write the header, because it won't be possible anyway + context->wrote_webvtt_header = 1; // Do it even if couldn't write the header, because it won't be possible anyway } @@ -266,7 +269,7 @@ int write_cc_bitmap_as_webvtt(struct cc_subtitle *sub, struct encoder_ctx *conte if (sub->nb_data == 0) return 0; - write_xtimestamp_header(context); + write_webvtt_header(context); if (sub->flags & SUB_EOD_MARKER) context->prev_start = sub->start_time; @@ -425,7 +428,6 @@ int write_cc_buffer_as_webvtt(struct eia608_screen *data, struct encoder_ctx *co ms_start = data->start_time; int empty_buf = 1; - char timeline[128] = ""; for (int i = 0; i<15; i++) { if (data->row_used[i]) @@ -441,28 +443,30 @@ int write_cc_buffer_as_webvtt(struct eia608_screen *data, struct encoder_ctx *co if (ms_start<0) // Drop screens that because of subs_delay start too early return 0; - write_xtimestamp_header(context); + write_webvtt_header(context); ms_end = data->end_time; millis_to_time(ms_start, &h1, &m1, &s1, &ms1); millis_to_time(ms_end - 1, &h2, &m2, &s2, &ms2); // -1 To prevent overlapping with next line. - sprintf(timeline, "%02u:%02u:%02u.%03u --> %02u:%02u:%02u.%03u%s", - h1, m1, s1, ms1, h2, m2, s2, ms2, context->encoded_crlf); - used = encode_line(context, context->buffer, (unsigned char *)timeline); - - dbg_print(CCX_DMT_DECODER_608, "\n- - - WEBVTT caption - - -\n"); - dbg_print(CCX_DMT_DECODER_608, "%s", timeline); - - written = write(context->out->fh, context->buffer, used); - if (written != used) - return -1; - for (int i = 0; i<15; i++) { if (data->row_used[i]) { + char timeline[128] = ""; + + sprintf(timeline, "%02u:%02u:%02u.%03u --> %02u:%02u:%02u.%03u line:%s%%%s", + h1, m1, s1, ms1, h2, m2, s2, ms2, webvtt_pac_row_percent[i], context->encoded_crlf); + used = encode_line(context, context->buffer, (unsigned char *)timeline); + + dbg_print(CCX_DMT_DECODER_608, "\n- - - WEBVTT caption - - -\n"); + dbg_print(CCX_DMT_DECODER_608, "%s", timeline); + + written = write(context->out->fh, context->buffer, used); + if (written != used) + return -1; + int length = get_line_encoded(context, context->subline, i, data); if (context->encoding != CCX_ENC_UNICODE) @@ -544,14 +548,14 @@ int write_cc_buffer_as_webvtt(struct eia608_screen *data, struct encoder_ctx *co if (written != context->encoded_crlf_length) return -1; + written = write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length); + if (written != context->encoded_crlf_length) + return -1; + wrote_something = 1; } } dbg_print(CCX_DMT_DECODER_608, "- - - - - - - - - - - -\r\n"); - written = write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length); - if (written != context->encoded_crlf_length) - return -1; - return wrote_something; } diff --git a/src/lib_ccx/dvb_subtitle_decoder.c b/src/lib_ccx/dvb_subtitle_decoder.c index a4a79cf4..e8fb0232 100644 --- a/src/lib_ccx/dvb_subtitle_decoder.c +++ b/src/lib_ccx/dvb_subtitle_decoder.c @@ -1651,7 +1651,7 @@ int dvbsub_decode(struct encoder_ctx *enc_ctx, struct lib_cc_decode *dec_ctx, co enc_ctx->prev_start = enc_ctx->prev->prev_start; sub->prev->got_output = 0; if (enc_ctx->write_format == CCX_OF_WEBVTT) { // we already wrote header, but since we encoded last sub, we must prevent multiple headers in future - enc_ctx->wrote_webvtt_sync_header = 1; + enc_ctx->wrote_webvtt_header = 1; } } memcpy(enc_ctx->prev, enc_ctx, sizeof(struct encoder_ctx)); //we save the current encoder context