From 4d5f80a01db4f8d8c67e1d9a0b4b699db25230c1 Mon Sep 17 00:00:00 2001 From: Diptanshu8 Date: Wed, 5 Jul 2017 15:12:31 +0000 Subject: [PATCH] Found wrapper for write. Check file_handle and start processing. --- src/ccextractor.c | 8 +++++++- src/ccextractor.h | 8 ++++++++ src/lib_ccx/ccx_encoders_srt.c | 15 +++++++++------ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/ccextractor.c b/src/ccextractor.c index 5f6987c8..2b0258c4 100644 --- a/src/ccextractor.c +++ b/src/ccextractor.c @@ -250,7 +250,6 @@ int api_start(struct ccx_s_options api_options){ fatal(CCX_COMMON_EXIT_BUG_BUG, "Cannot be reached!"); break; } - list_for_each_entry(dec_ctx, &ctx->dec_ctx_head, list, struct lib_cc_decode) { mprint("\n"); @@ -476,6 +475,13 @@ int api_param_count(struct ccx_s_options* api_options){ return api_options->python_param_count; } + +int __real_write(int file_handle, char* buffer, int nbyte); +int __wrap_write(int file_handle, char* buffer, int nbyte) +{ + printf("file_handle = %d\n",file_handle); + return __real_write(file_handle,buffer,nbyte); +} int main(int argc, char* argv[]){ int i; struct ccx_s_options* api_options = api_init_options(); diff --git a/src/ccextractor.h b/src/ccextractor.h index 2b7a0fd2..84b31074 100644 --- a/src/ccextractor.h +++ b/src/ccextractor.h @@ -22,8 +22,14 @@ CURLcode res; #define LEPT_MSG_SEVERITY L_SEVERITY_NONE #endif +struct cc_to_python_subs{ + char** subs; + int number_of_lines; +}; + struct ccx_s_options ccx_options; struct lib_ccx_ctx *signal_ctx; +struct cc_to_python_subs python_subs; //volatile int terminate_asap = 0; struct ccx_s_options* api_init_options(); @@ -38,4 +44,6 @@ void sigterm_handler(int sig); void sigint_handler(int sig); void print_end_msg(); int main(int argc, char *argv[]); +int __real_write(int file_handle, char* buffer, int nbyte); +int __wrap_write(int file_handle, char* buffer, int nbyte); #endif //CCEXTRACTOR_H diff --git a/src/lib_ccx/ccx_encoders_srt.c b/src/lib_ccx/ccx_encoders_srt.c index 2fccafe6..1233481b 100644 --- a/src/lib_ccx/ccx_encoders_srt.c +++ b/src/lib_ccx/ccx_encoders_srt.c @@ -4,6 +4,7 @@ #include "utility.h" #include "ccx_encoders_helpers.h" #include "ocr.h" +#include "ccextractor.h" /* The timing here is not PTS based, but output based, i.e. user delay must be accounted for if there is any */ @@ -195,7 +196,8 @@ int write_cc_buffer_as_srt(struct eia608_screen *data, struct encoder_ctx *conte context->srt_counter++; sprintf(timeline, "%u%s", context->srt_counter, context->encoded_crlf); used = encode_line(context, context->buffer,(unsigned char *) timeline); - write(context->out->fh, context->buffer, used); + __wrap_write(context->out->fh, context->buffer, used); + 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); @@ -203,7 +205,7 @@ int write_cc_buffer_as_srt(struct eia608_screen *data, struct encoder_ctx *conte dbg_print(CCX_DMT_DECODER_608, "\n- - - SRT caption ( %d) - - -\n", context->srt_counter); dbg_print(CCX_DMT_DECODER_608, "%s",timeline); - write (context->out->fh, context->buffer, used); + __wrap_write(context->out->fh, context->buffer, used); for (int i=0;i<15;i++) { if (data->row_used[i]) @@ -263,7 +265,7 @@ int write_cc_buffer_as_srt(struct eia608_screen *data, struct encoder_ctx *conte do_dash=0; if (do_dash) - write(context->out->fh, "- ", 2); + __wrap_write(context->out->fh, "- ", 2); prev_line_start=first; prev_line_end=last; prev_line_center1=center1; @@ -276,8 +278,8 @@ int write_cc_buffer_as_srt(struct eia608_screen *data, struct encoder_ctx *conte dbg_print(CCX_DMT_DECODER_608, "\r"); dbg_print(CCX_DMT_DECODER_608, "%s\n",context->subline); } - write(context->out->fh, context->subline, length); - write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length); + __wrap_write(context->out->fh, context->subline, length); + __wrap_write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length); wrote_something=1; // fprintf (wb->fh,context->encoded_crlf); } @@ -285,6 +287,7 @@ int write_cc_buffer_as_srt(struct eia608_screen *data, struct encoder_ctx *conte dbg_print(CCX_DMT_DECODER_608, "- - - - - - - - - - - -\r\n"); // fprintf (wb->fh, context->encoded_crlf); - write (context->out->fh, context->encoded_crlf, context->encoded_crlf_length); + __wrap_write(context->out->fh, context->encoded_crlf, context->encoded_crlf_length); + //printf("$ = %s\n",context->encoded_crlf); return wrote_something; }