From beccc3d5b70aed92c2e8ebe8b8dd7d746a6b0cdb Mon Sep 17 00:00:00 2001 From: Anshul Maheshwari Date: Wed, 17 Jun 2015 16:23:33 +0530 Subject: [PATCH] Correct broken rcwt Signed-off-by: Anshul Maheshwari --- src/ccextractor.c | 5 +++++ src/lib_ccx/ccx_encoders_common.c | 8 ++++++++ src/lib_ccx/output.c | 18 +++++++++++++----- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/ccextractor.c b/src/ccextractor.c index e1d422a6..862286c3 100644 --- a/src/ccextractor.c +++ b/src/ccextractor.c @@ -667,6 +667,11 @@ int main(int argc, char *argv[]) { // Write last header and data writercwtdata (dec_ctx, NULL, &dec_sub); + if (dec_sub.got_output) + { + encode_sub(enc_ctx,&dec_sub); + dec_sub.got_output = 0; + } } dinit_encoder(enc_ctx); } diff --git a/src/lib_ccx/ccx_encoders_common.c b/src/lib_ccx/ccx_encoders_common.c index d26cec74..e70ffc23 100644 --- a/src/lib_ccx/ccx_encoders_common.c +++ b/src/lib_ccx/ccx_encoders_common.c @@ -564,6 +564,14 @@ int encode_sub(struct encoder_ctx *context, struct cc_subtitle *sub) } } + if (sub->type == CC_RAW) + { + if (context->send_to_srv) + net_send_header(sub->data, sub->nb_data); + else + write(context->out->fh, sub->data, sub->nb_data); + sub->nb_data = 0; + } if (!sub->nb_data) freep(&sub->data); return wrote_something; diff --git a/src/lib_ccx/output.c b/src/lib_ccx/output.c index 07e9f7b6..32d5ec64 100644 --- a/src/lib_ccx/output.c +++ b/src/lib_ccx/output.c @@ -23,9 +23,17 @@ int writeraw (const unsigned char *data, int length, void *private_data, struct if (data==NULL) return -1; - /* TODO dont write directly to file instead follow complete path and write raw data in sub and in above - layer choose whether u want to write it to file or not */ - write (context->out->fh, data, length); + sub->data = realloc(sub->data,length + sub->nb_data); + if (!sub->data) + return EXIT_NOT_ENOUGH_MEMORY; + + memcpy(sub->data + sub->nb_data, data, length); + sub->got_output = 1; + sub->nb_data += length; + sub->type = CC_RAW; + + + return EXIT_SUCCESS; } void flushbuffer (struct lib_ccx_ctx *ctx, struct ccx_s_write *wb, int closefile) @@ -215,8 +223,8 @@ void writercwtdata (struct lib_cc_decode *ctx, const unsigned char *data, struct memcpy(cbbuffer, "\x04\x80\x80", 3); // Field 1 padding memcpy(cbbuffer+3, "\x05\x80\x80", 3); // Field 2 padding - ctx->writedata(cbheader, 10, ctx->context_cc608_field_1, NULL); - ctx->writedata(cbbuffer, 3 * cbcount, ctx->context_cc608_field_1, NULL); + ctx->writedata(cbheader, 10, ctx->context_cc608_field_1, sub); + ctx->writedata(cbbuffer, 3 * cbcount, ctx->context_cc608_field_1, sub); cbcount = 0; cbempty = 0;