From 405d808d0b5092a185ed09f7ccbbef3bbf5fcf43 Mon Sep 17 00:00:00 2001 From: wforums Date: Mon, 4 Aug 2014 21:04:49 +0200 Subject: [PATCH] WTV fix Fixed WTV --- src/wtv_constants.h | 4 ++++ src/wtv_functions.c | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/wtv_constants.h b/src/wtv_constants.h index 14cbabb1..719e9990 100644 --- a/src/wtv_constants.h +++ b/src/wtv_constants.h @@ -4,6 +4,7 @@ #define WTV_STREAM2 "\xA2\xC3\xD2\xC2\x7E\x9A\xDA\x11\x8B\xF7\x00\x07\xE9\x5E\xAD\x8D" #define WTV_DATA "\x95\xC3\xD2\xC2\x7E\x9A\xDA\x11\x8B\xF7\x00\x07\xE9\x5E\xAD\x8D" #define WTV_STREAM_VIDEO "\x76\x69\x64\x73\x00\x00\x10\x00\x80\x00\x00\xAA\x00\x38\x9B\x71" +#define WTV_STREAM_AUDIO "\x61\x75\x64\x73\x00\x00\x10\x00\x80\x00\x00\xAA\x00\x38\x9B\x71" #define WTV_STREAM_MSTVCAPTION "\x89\x8A\x8B\xB8\x49\xB0\x80\x4C\xAD\xCF\x58\x98\x98\x5E\x22\xC1" #define WTV_EOF "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" #define WTV_TIMING "\x5B\x05\xE6\x1B\x97\xA9\x49\x43\x88\x17\x1A\x65\x5A\x29\x8A\x97" @@ -18,6 +19,9 @@ //Maximum size we will try and malloc for chunked_buffer. 100MB #define WTV_MAX_ALLOC 1024*1024*100 +#define WTV_CC_TIMESTAMP_MAGIC 1668330 +#define WTV_CC_TIMESTAMP_MAGIC_THRESH 2 //Only switch to alt stream after THRESH magic numbers + struct wtv_chunked_buffer { uint64_t skip_chunks[256]; diff --git a/src/wtv_functions.c b/src/wtv_functions.c index 0af62dfe..47fc697e 100644 --- a/src/wtv_functions.c +++ b/src/wtv_functions.c @@ -297,6 +297,8 @@ int read_header(struct wtv_chunked_buffer *cb) { LLONG get_data(struct wtv_chunked_buffer *cb) { static int video_streams[32]; + static int alt_stream; //Stream to use for timestamps if the cc stream has broken timestamps + static int use_alt_stream = 0; static int num_streams=0; while(1) { @@ -368,9 +370,12 @@ LLONG get_data(struct wtv_chunked_buffer *cb) { video_streams[num_streams]=stream_id; // We keep a list of stream ids num_streams++; // Even though there should only be 1 } + if (memcmp(stream_type, WTV_STREAM_AUDIO, 16)) + alt_stream = stream_id; len-=28; } - if( !memcmp(guid, WTV_TIMING, 16 ) && check_stream_id(stream_id, video_streams, num_streams)) + if (!memcmp(guid, WTV_TIMING, 16) && ((use_alt_stream < WTV_CC_TIMESTAMP_MAGIC_THRESH && check_stream_id(stream_id, video_streams, num_streams)) + || (use_alt_stream == WTV_CC_TIMESTAMP_MAGIC_THRESH && stream_id == alt_stream))) { // The WTV_TIMING GUID contains a timestamp for the given stream_id dbg_print(CCX_DMT_PARSE, "WTV TIMING\n"); @@ -379,12 +384,18 @@ LLONG get_data(struct wtv_chunked_buffer *cb) { int64_t time; memcpy(&time, cb->buffer+0x8, 8); // Read the timestamp dbg_print(CCX_DMT_PARSE, "TIME: %ld\n", time); - if(time!=-1) { // Ignore -1 timestamps + if (time != -1 && time != WTV_CC_TIMESTAMP_MAGIC) { // Ignore -1 timestamps current_pts = time_to_pes_time(time); // Convert from WTV to PES time pts_set = 1; frames_since_ref_time = 0; set_fts(); - } + } + else if (time == WTV_CC_TIMESTAMP_MAGIC && stream_id != alt_stream) { + use_alt_stream++; + mprint("WARNING: %i WTV_CC_TIMESTAMP_MAGIC detected in cc timestamps. \n", use_alt_stream); + if (use_alt_stream == WTV_CC_TIMESTAMP_MAGIC_THRESH) + mprint("WARNING: WTV_CC_TIMESTAMP_MAGIC_THRESH reached. Switching to alt timestamps!\n"); + } len-=16; } if( !memcmp(guid, WTV_DATA, 16 )