Skip to content

Commit

Permalink
Merge branch 'pr/n118_anshul1912'
Browse files Browse the repository at this point in the history
  • Loading branch information
cfsmp3 committed Nov 11, 2014
2 parents 5c7430c + 7ed9909 commit b95e06c
Show file tree
Hide file tree
Showing 25 changed files with 634 additions and 440 deletions.
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ include_directories ("${PROJECT_SOURCE_DIR}/lib_ccx")
include_directories ("${PROJECT_SOURCE_DIR}/gpacmp4/")
include_directories ("${PROJECT_SOURCE_DIR}/libccx_common/")

#Adding some platform specific library path
LINK_DIRECTORIES(/opt/local/lib)
LINK_DIRECTORIES(/usr/local/lib)

SET (CMAKE_C_FLAGS "-O0 -Wall -g -std=gnu99 -Wno-write-strings -D_FILE_OFFSET_BITS=64")
add_subdirectory (lib_ccx)

Expand All @@ -28,3 +32,5 @@ set (EXTRA_LIBS ${EXTRA_LIBS} m)

add_executable(ccextractor ${SOURCEFILE})
target_link_libraries (ccextractor ${EXTRA_LIBS})

install (TARGETS ccextractor DESTINATION bin)
39 changes: 13 additions & 26 deletions src/ccextractor.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ int main(int argc, char *argv[])
struct cc_subtitle dec_sub;
void *ffmpeg_ctx = NULL;
struct lib_ccx_ctx *ctx;
struct lib_cc_decode *dec_ctx = NULL;

// Initialize some constants
init_ts();
init_avc();

init_options (&ccx_options);

Expand All @@ -42,23 +40,13 @@ int main(int argc, char *argv[])

// Initialize libraries
ctx = init_libraries(&ccx_options);
dec_ctx = ctx->dec_ctx;

// Init timing
ccx_common_timing_init(&ctx->past,ccx_options.nosync);

// Prepare write structures
init_write(&ctx->wbout1,ccx_options.wbout1.filename);
init_write(&ctx->wbout2,ccx_options.wbout2.filename);

// Prepare time structures
init_boundary_time (&ccx_options.extraction_start);
init_boundary_time (&ccx_options.extraction_end);
init_boundary_time (&ccx_options.startcreditsnotbefore);
init_boundary_time (&ccx_options.startcreditsnotafter);
init_boundary_time (&ccx_options.startcreditsforatleast);
init_boundary_time (&ccx_options.startcreditsforatmost);
init_boundary_time (&ccx_options.endcreditsforatleast);
init_boundary_time (&ccx_options.endcreditsforatmost);

int show_myth_banner = 0;

Expand Down Expand Up @@ -162,9 +150,7 @@ int main(int argc, char *argv[])
"CCExtractor's binary format can only be used simultaneously for input and\noutput if the output file name is specified given with -o.\n");
}

ctx->buffer = (unsigned char *) malloc (BUFSIZE);
subline = (unsigned char *) malloc (SUBLINESIZE);
ctx->pesheaderbuf = (unsigned char *) malloc (188); // Never larger anyway

switch (ccx_options.input_source)
{
Expand Down Expand Up @@ -409,7 +395,7 @@ int main(int argc, char *argv[])
time_t start, final;
time(&start);

ctx->processed_enough=0;
dec_ctx->processed_enough=0;
if (ccx_options.binary_concat)
{
ctx->total_inputsize=gettotalfilessize(ctx);
Expand All @@ -422,7 +408,7 @@ int main(int argc, char *argv[])
m_signal(SIGINT, sigint_handler);
#endif

while (switch_to_next_file(ctx, 0) && !ctx->processed_enough)
while (switch_to_next_file(ctx, 0) && !dec_ctx->processed_enough)
{
prepare_for_new_file(ctx);
#ifdef ENABLE_FFMPEG
Expand Down Expand Up @@ -642,10 +628,10 @@ int main(int argc, char *argv[])

if (ctx->stat_hdtv)
{
mprint ("\rCC type 0: %d (%s)\n", ctx->cc_stats[0], cc_types[0]);
mprint ("CC type 1: %d (%s)\n", ctx->cc_stats[1], cc_types[1]);
mprint ("CC type 2: %d (%s)\n", ctx->cc_stats[2], cc_types[2]);
mprint ("CC type 3: %d (%s)\n", ctx->cc_stats[3], cc_types[3]);
mprint ("\rCC type 0: %d (%s)\n", dec_ctx->cc_stats[0], cc_types[0]);
mprint ("CC type 1: %d (%s)\n", dec_ctx->cc_stats[1], cc_types[1]);
mprint ("CC type 2: %d (%s)\n", dec_ctx->cc_stats[2], cc_types[2]);
mprint ("CC type 3: %d (%s)\n", dec_ctx->cc_stats[3], cc_types[3]);
}
mprint ("\nTotal frames time: %s (%u frames at %.2ffps)\n",
print_mstime( (LLONG)(total_frames_count*1000/current_fps) ),
Expand Down Expand Up @@ -743,7 +729,7 @@ int main(int argc, char *argv[])
ccx_options.write_format==CCX_OF_SRT || ccx_options.write_format==CCX_OF_TRANSCRIPT
|| ccx_options.write_format==CCX_OF_SPUPNG )
{
handle_end_of_data(&ctx->context_cc608_field_1, &dec_sub);
handle_end_of_data(dec_ctx->context_cc608_field_1, &dec_sub);
if (dec_sub.got_output)
{
encode_sub(enc_ctx,&dec_sub);
Expand All @@ -753,7 +739,7 @@ int main(int argc, char *argv[])
else if(ccx_options.write_format==CCX_OF_RCWT)
{
// Write last header and data
writercwtdata (ctx, NULL);
writercwtdata (dec_ctx, NULL);
}
dinit_encoder(enc_ctx);
}
Expand All @@ -763,7 +749,7 @@ int main(int argc, char *argv[])
ccx_options.write_format==CCX_OF_SRT || ccx_options.write_format==CCX_OF_TRANSCRIPT
|| ccx_options.write_format==CCX_OF_SPUPNG )
{
handle_end_of_data(&ctx->context_cc608_field_2, &dec_sub);
handle_end_of_data(dec_ctx->context_cc608_field_2, &dec_sub);
if (dec_sub.got_output)
{
encode_sub(enc_ctx,&dec_sub);
Expand Down Expand Up @@ -791,7 +777,7 @@ int main(int argc, char *argv[])
if (ccx_options.teletext_mode == CCX_TXT_IN_USE)
mprint ( "Teletext decoder: %"PRIu32" packets processed, %"PRIu32" SRT frames written.\n", tlt_packet_counter, tlt_frames_produced);

if (ctx->processed_enough)
if (dec_ctx->processed_enough)
{
mprint ("\rNote: Processing was cancelled before all data was processed because\n");
mprint ("\rone or more user-defined limits were reached.\n");
Expand All @@ -809,5 +795,6 @@ int main(int argc, char *argv[])
mprint ("code in the MythTV's branch. Please report results to the address above. If\n");
mprint ("something is broken it will be fixed. Thanks\n");
}
dinit_libraries(&ctx);
return EXIT_OK;
}
2 changes: 1 addition & 1 deletion src/gpacmp4/mp4.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ int processmp4 (struct lib_ccx_ctx *ctx, char *file,void *enc_ctx)
#endif
do
{
ret = process608((unsigned char*)data, len, &ctx->context_cc608_field_1, &dec_sub);
ret = process608((unsigned char*)data, len, ctx->dec_ctx->context_cc608_field_1, &dec_sub);
len -= ret;
data += ret;
if(dec_sub.got_output)
Expand Down
11 changes: 11 additions & 0 deletions src/lib_ccx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,16 @@ AUX_SOURCE_DIRECTORY("${PROJECT_SOURCE_DIR}/gpacmp4/" SOURCEFILE)
add_library(ccx ${SOURCEFILE})

FILE(GLOB HeaderFiles *.h)
file(WRITE ccx.pc "prefix=${CMAKE_INSTALL_PREFIX}\n"
"includedir=\${prefix}/include\n"
"libdir=\${prefix}/lib\n\n"
"Name: ccx\n"
"Description: Closed Caption Extraction library\n"
"Version: 0.75\n"
"Cflags: -I\${includedir}/\n"
"Libs: -L\${libdir} -lccx -lpng\n"
"Libs.private: -lpng\n" )

install (TARGETS ccx DESTINATION lib)
install (FILES ${HeaderFiles} DESTINATION include)
install (FILES ccx.pc DESTINATION lib/pkgconfig )
5 changes: 4 additions & 1 deletion src/lib_ccx/ccx_common_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
void fdprintf(int fd, const char *fmt, ...);
void mstotime(LLONG milli, unsigned *hours, unsigned *minutes,unsigned *seconds, unsigned *ms);
void freep(void *arg);
void dbg_print(LLONG mask, const char *fmt, ...);
unsigned char *debug_608toASC(unsigned char *ccdata, int channel);

#endif
extern int cc608_parity_table[256]; // From myth
#endif
13 changes: 13 additions & 0 deletions src/lib_ccx/ccx_common_option.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "ccx_common_option.h"
#include "ccx_encoders_common.h"
#include "utility.h"

struct ccx_s_options ccx_options;
/* Parameters */
void init_options (struct ccx_s_options *options)
Expand Down Expand Up @@ -89,4 +91,15 @@ void init_options (struct ccx_s_options *options)
options->noautotimeref=0; // Do NOT set time automatically?
options->input_source=CCX_DS_FILE; // Files, stdin or network
options->auto_stream = CCX_SM_AUTODETECT;

// Prepare time structures
init_boundary_time (&options->extraction_start);
init_boundary_time (&options->extraction_end);
init_boundary_time (&options->startcreditsnotbefore);
init_boundary_time (&options->startcreditsnotafter);
init_boundary_time (&options->startcreditsforatleast);
init_boundary_time (&options->startcreditsforatmost);
init_boundary_time (&options->endcreditsforatleast);
init_boundary_time (&options->endcreditsforatmost);

}
97 changes: 55 additions & 42 deletions src/lib_ccx/ccx_decoders_608.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,42 +116,54 @@ void clear_eia608_cc_buffer(ccx_decoder_608_context *context, struct eia608_scre
data->empty=1;
}

ccx_decoder_608_context ccx_decoder_608_init_library(ccx_decoder_608_settings settings, int channel, int field, int trim_subs, enum ccx_encoding_type encoding, int *halt, int *cc_to_stdout)
void ccx_decoder_608_dinit_library(void **ctx)
{
ccx_decoder_608_context data;

data.cursor_column=0;
data.cursor_row=0;
data.visible_buffer=1;
data.last_c1=0;
data.last_c2=0;
data.mode=MODE_POPON;
// data.current_visible_start_cc=0;
data.current_visible_start_ms=0;
data.screenfuls_counter=0;
data.channel=1;
data.font=FONT_REGULAR;
data.rollup_base_row=14;
data.ts_start_of_current_line=-1;
data.ts_last_char_received=-1;
data.new_channel=1;
data.bytes_processed_608 = 0;
data.my_field = field;
data.my_channel = channel;
data.out = NULL;
data.have_cursor_position = 0;

data.trim_subs = trim_subs;
data.encoding = encoding;

data.halt = halt;
data.cc_to_stdout = cc_to_stdout;

data.settings = settings;
data.current_color = data.settings.default_color;

clear_eia608_cc_buffer(&data, &data.buffer1);
clear_eia608_cc_buffer(&data, &data.buffer2);
freep(ctx);
}
ccx_decoder_608_context* ccx_decoder_608_init_library(ccx_decoder_608_settings settings, int channel,
int field, int trim_subs,
enum ccx_encoding_type encoding, int *halt,
int cc_to_stdout, LLONG subs_delay,
enum ccx_output_format output_format)
{
ccx_decoder_608_context *data = NULL;

data = malloc(sizeof(ccx_decoder_608_context));

data->cursor_column=0;
data->cursor_row=0;
data->visible_buffer=1;
data->last_c1=0;
data->last_c2=0;
data->mode=MODE_POPON;
// data->current_visible_start_cc=0;
data->current_visible_start_ms=0;
data->screenfuls_counter=0;
data->channel=1;
data->font=FONT_REGULAR;
data->rollup_base_row=14;
data->ts_start_of_current_line=-1;
data->ts_last_char_received=-1;
data->new_channel=1;
data->bytes_processed_608 = 0;
data->my_field = field;
data->my_channel = channel;
data->out = NULL;
data->have_cursor_position = 0;

data->trim_subs = trim_subs;
data->encoding = encoding;

data->halt = halt;
data->cc_to_stdout = cc_to_stdout;
data->subs_delay = subs_delay;
data->output_format = output_format;

data->settings = settings;
data->current_color = data->settings.default_color;

clear_eia608_cc_buffer(data, &data->buffer1);
clear_eia608_cc_buffer(data, &data->buffer2);

return data;
}
Expand Down Expand Up @@ -292,7 +304,7 @@ int write_cc_buffer(ccx_decoder_608_context *context, struct cc_subtitle *sub)
context->current_visible_start_ms = context->ts_start_of_current_line;

start_time = context->current_visible_start_ms;
end_time = get_visible_end() + ccx_decoders_common_settings.subs_delay;
end_time = get_visible_end() + context->subs_delay;
sub->type = CC_608;
data->format = SFORMAT_CC_SCREEN;
data->start_time = 0;
Expand Down Expand Up @@ -348,8 +360,8 @@ int write_cc_line(ccx_decoder_608_context *context, struct cc_subtitle *sub)
int ret = 0;
data = get_current_visible_buffer(context);

start_time = context->ts_start_of_current_line + ccx_decoders_common_settings.subs_delay;
end_time = get_fts() + ccx_decoders_common_settings.subs_delay;
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;
Expand All @@ -358,6 +370,7 @@ int write_cc_line(ccx_decoder_608_context *context, struct cc_subtitle *sub)
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 )
{
Expand Down Expand Up @@ -728,7 +741,7 @@ void handle_command(/*const */ unsigned char c1, const unsigned char c2, ccx_dec
context->cursor_row++;
break;
}
if (ccx_decoders_common_settings.output_format == CCX_OF_TRANSCRIPT)
if (context->output_format == CCX_OF_TRANSCRIPT)
{
write_cc_line(context,sub);
}
Expand All @@ -739,7 +752,7 @@ void handle_command(/*const */ unsigned char c1, const unsigned char c2, ccx_dec
if (changes)
{
// Only if the roll up would actually cause a line to disappear we write the buffer
if (ccx_decoders_common_settings.output_format != CCX_OF_TRANSCRIPT)
if (context->output_format != CCX_OF_TRANSCRIPT)
{
if (write_cc_buffer(context, sub))
context->screenfuls_counter++;
Expand All @@ -759,7 +772,7 @@ void handle_command(/*const */ unsigned char c1, const unsigned char c2, ccx_dec
case COM_ERASEDISPLAYEDMEMORY:
// Write it to disk before doing this, and make a note of the new
// time it became clear.
if (ccx_decoders_common_settings.output_format == CCX_OF_TRANSCRIPT &&
if (context->output_format == CCX_OF_TRANSCRIPT &&
(context->mode == MODE_FAKE_ROLLUP_1 ||
context->mode == MODE_ROLLUP_2 ||
context->mode == MODE_ROLLUP_3 ||
Expand All @@ -772,7 +785,7 @@ void handle_command(/*const */ unsigned char c1, const unsigned char c2, ccx_dec
}
else
{
if (ccx_decoders_common_settings.output_format == CCX_OF_TRANSCRIPT)
if (context->output_format == CCX_OF_TRANSCRIPT)
context->ts_start_of_current_line = context->current_visible_start_ms;
if (write_cc_buffer(context, sub))
context->screenfuls_counter++;
Expand Down
10 changes: 8 additions & 2 deletions src/lib_ccx/ccx_decoders_608.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ typedef struct ccx_decoder_608_context
int *halt; // Can be used to halt the feeding of caption data. Set to 1 if screens_to_progress != -1 && screenfuls_counter >= screens_to_process
int cc_to_stdout; // If this is set to 1, the stdout will be flushed when data was written to the screen during a process_608 call.
struct ccx_decoder_608_report report;
LLONG subs_delay; // ms to delay (or advance) subs
enum ccx_output_format output_format; // What kind of output format should be used?
} ccx_decoder_608_context;

extern unsigned char *enc_buffer;
Expand Down Expand Up @@ -115,10 +117,15 @@ enum command_code
};


void ccx_decoder_608_dinit_library(void **ctx);
/*
*
*/
ccx_decoder_608_context ccx_decoder_608_init_library(ccx_decoder_608_settings settings, int channel, int field, int trim_subs, enum ccx_encoding_type encoding, int *halt, int *cc_to_stdout);
ccx_decoder_608_context* ccx_decoder_608_init_library(ccx_decoder_608_settings settings, int channel,
int field, int trim_subs,
enum ccx_encoding_type encoding, int *halt,
int cc_to_stdout, LLONG subs_delay,
enum ccx_output_format output_format);

/**
* @param data raw cc608 data to be processed
Expand All @@ -142,7 +149,6 @@ int process608(const unsigned char *data, int length, ccx_decoder_608_context *c
void handle_end_of_data(ccx_decoder_608_context *context, struct cc_subtitle *sub);

int write_cc_buffer(ccx_decoder_608_context *context, struct cc_subtitle *sub);
unsigned char *debug_608toASC(unsigned char *ccdata, int channel);

#define __608_H__
#endif

0 comments on commit b95e06c

Please sign in to comment.