diff --git a/docs/CHANGES.TXT b/docs/CHANGES.TXT index 3e18b2d8..69732f64 100644 --- a/docs/CHANGES.TXT +++ b/docs/CHANGES.TXT @@ -1,3 +1,7 @@ +0.76 +----------------- +- Added basic M2TS support + 0.75 (2015-01-15) ----------------- - Fixed issue with teletext to other then srt. diff --git a/src/lib_ccx/ccx_common_option.c b/src/lib_ccx/ccx_common_option.c index 66bca2c0..7d9c1392 100644 --- a/src/lib_ccx/ccx_common_option.c +++ b/src/lib_ccx/ccx_common_option.c @@ -91,6 +91,7 @@ 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; + options->m2ts = 0; // Prepare time structures init_boundary_time (&options->extraction_start); diff --git a/src/lib_ccx/ccx_common_option.h b/src/lib_ccx/ccx_common_option.h index 831c73db..5b7db38e 100644 --- a/src/lib_ccx/ccx_common_option.h +++ b/src/lib_ccx/ccx_common_option.h @@ -86,6 +86,7 @@ struct ccx_s_options // Options from user parameters char **inputfile; // List of files to process int num_input_files; // How many? enum ccx_stream_mode_enum auto_stream; + int m2ts; // Regular TS or M2TS LLONG subs_delay; // ms to delay (or advance) subs 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. // Output structures diff --git a/src/lib_ccx/lib_ccx.c b/src/lib_ccx/lib_ccx.c index 97bfd25a..f64d045c 100644 --- a/src/lib_ccx/lib_ccx.c +++ b/src/lib_ccx/lib_ccx.c @@ -50,6 +50,7 @@ struct lib_ccx_ctx* init_libraries(struct ccx_s_options *opt) ctx->stream_mode = CCX_SM_ELEMENTARY_OR_NOT_FOUND; ctx->auto_stream = opt->auto_stream; + ctx->m2ts = opt->m2ts; ctx->screens_to_process = -1; ctx->current_file = -1; ctx->infd = -1;//Set to -1 to indicate no file is open. diff --git a/src/lib_ccx/lib_ccx.h b/src/lib_ccx/lib_ccx.h index 8fc97ecf..08208362 100644 --- a/src/lib_ccx/lib_ccx.h +++ b/src/lib_ccx/lib_ccx.h @@ -135,6 +135,7 @@ struct lib_ccx_ctx struct lib_cc_decode *dec_ctx; enum ccx_stream_mode_enum stream_mode; enum ccx_stream_mode_enum auto_stream; + int m2ts; int rawmode; // Broadcast or DVD diff --git a/src/lib_ccx/params.c b/src/lib_ccx/params.c index 73fdb210..7d291949 100644 --- a/src/lib_ccx/params.c +++ b/src/lib_ccx/params.c @@ -272,8 +272,16 @@ void set_input_format (struct ccx_s_options *opt, const char *format) format++; if (strcmp (format,"es")==0) // Does this actually do anything? opt->auto_stream = CCX_SM_ELEMENTARY_OR_NOT_FOUND; - else if (strcmp (format,"ts")==0) + else if (strcmp(format, "ts") == 0) + { opt->auto_stream = CCX_SM_TRANSPORT; + opt->m2ts = 0; + } + else if (strcmp(format, "m2ts") == 0) + { + opt->auto_stream = CCX_SM_TRANSPORT; + opt->m2ts = 1; + } else if (strcmp (format,"ps")==0 || strcmp (format,"nots")==0) opt->auto_stream = CCX_SM_PROGRAM; else if (strcmp (format,"asf")==0 || strcmp (format,"dvr-ms")==0) diff --git a/src/lib_ccx/stream_functions.c b/src/lib_ccx/stream_functions.c index 42bbec21..d602672f 100644 --- a/src/lib_ccx/stream_functions.c +++ b/src/lib_ccx/stream_functions.c @@ -73,9 +73,26 @@ void detect_stream_type (struct lib_ccx_ctx *ctx) // Eight sync bytes, that's good enough ctx->startbytes_pos=i; ctx->stream_mode=CCX_SM_TRANSPORT; + ctx->m2ts = 0; break; } } + // Check for M2TS + for (unsigned i = 0; i<192; i++) + { + if (ctx->startbytes[i+4] == 0x47 && ctx->startbytes[i + 4 + 192] == 0x47 && + ctx->startbytes[i + 192 * 2+4] == 0x47 && ctx->startbytes[i + 192 * 3+4] == 0x47 && + ctx->startbytes[i + 192 * 4+4] == 0x47 && ctx->startbytes[i + 192 * 5+4] == 0x47 && + ctx->startbytes[i + 192 * 6+4] == 0x47 && ctx->startbytes[i + 192 * 7+4] == 0x47 + ) + { + // Eight sync bytes, that's good enough + ctx->startbytes_pos = i; + ctx->stream_mode = CCX_SM_TRANSPORT; + ctx->m2ts = 1; + break; + } + } // Now check for PS (Needs PACK header) for (unsigned i=0; i < (unsigned) (ctx->startbytes_avail<50000?ctx->startbytes_avail-3:49997); diff --git a/src/lib_ccx/ts_functions.c b/src/lib_ccx/ts_functions.c index ac0ca60a..6eaaaac0 100644 --- a/src/lib_ccx/ts_functions.c +++ b/src/lib_ccx/ts_functions.c @@ -57,6 +57,25 @@ void init_ts(struct lib_ccx_ctx *ctx) // Return 1 for sucessfully read ts packet int ts_readpacket(struct lib_ccx_ctx* ctx) { + if (ctx->m2ts) + { + /* M2TS just adds 4 bytes to each packet (so size goes from 188 to 192) + The 4 bytes are not important to us, so just skip + // TP_extra_header { + Copy_permission_indicator 2 unimsbf + Arrival_time_stamp 30 unimsbf + } */ + char tp_extra_header[4]; + buffered_read(ctx, tp_extra_header, 4); + ctx->past += result; + if (result != 4) + { + if (result>0) + mprint("Premature end of file!\n"); + end_of_file = 1; + return 0; + } + } buffered_read(ctx, tspacket, 188); ctx->past+=result; if (result!=188)