OSDN Git Service

- Only do 'lost PCR' checks (r1712) when we're dealing with something that could...
authorvan <van@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Fri, 3 Oct 2008 05:10:21 +0000 (05:10 +0000)
committervan <van@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Fri, 3 Oct 2008 05:10:21 +0000 (05:10 +0000)
 - Widen the DTS-to-PCR acceptance window from +-5sec to +-5min since there's nothing in the standard that bounds the offset between a DTS and its clock reference.

git-svn-id: svn://localhost/HandBrake/trunk@1802 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/common.h
libhb/demuxmpeg.c
libhb/internal.h
libhb/reader.c
libhb/stream.c

index 0180558..a5cfcf4 100644 (file)
@@ -452,7 +452,8 @@ struct hb_title_s
     int         video_id;               /* demuxer stream id for video */
     int         video_codec;            /* worker object id of video codec */
     int         video_codec_param;      /* codec specific config */
-
+    int         flaky_clock;            /* can lose reference clock */
+                                        /* (for over-the-air transport streams) */
     const char  *video_codec_name;
     int         video_bitrate;
     const char  *container_name;
index d92798a..a30a15c 100644 (file)
@@ -137,7 +137,7 @@ int hb_demux_ps( hb_buffer_t * buf_ps, hb_list_t * list_es, hb_psdemux_t* state
             {
                 dts = pts;
             }
-            if ( state )
+            if ( state && state->flaky_clock )
             {
                 // Program streams have an SCR in every PACK header so they
                 // can't lose their clock reference. But the PCR in Transport
@@ -149,9 +149,10 @@ int hb_demux_ps( hb_buffer_t * buf_ps, hb_list_t * list_es, hb_psdemux_t* state
                 // timestamps against the current reference clock and discarding
                 // packets where the DTS is "too far" from its clock.
                 int64_t fdelta = dts - state->last_scr;
-                if ( fdelta < -5000 * 90 || fdelta > 5000 * 90 )
+                if ( fdelta < -300 * 90000LL || fdelta > 300 * 90000LL )
                 {
                     // packet too far behind or ahead of its clock reference
+                    ++state->dts_drops;
                     pos = pes_packet_end;
                     continue;
                 }
index 5f04e38..e9828fd 100644 (file)
@@ -108,6 +108,8 @@ hb_work_object_t * hb_codec_encoder( int );
 typedef struct {
     int64_t last_scr;       /* unadjusted SCR from most recent pack */
     int     scr_changes;    /* number of SCR discontinuities */
+    int     flaky_clock;    /* try to compensate for PCR drops */
+    int     dts_drops;      /* number of drops because DTS too far from SCR */
 } hb_psdemux_t;
 
 int hb_demux_ps( hb_buffer_t * ps_buf, hb_list_t * es_list, hb_psdemux_t * );
index 75fd1b4..62102c2 100644 (file)
@@ -209,6 +209,7 @@ static void ReaderFunc( void * _r )
 
     list  = hb_list_init();
     hb_buffer_t *ps = hb_buffer_init( HB_DVD_READ_BUFFER_SIZE );
+    r->demux.flaky_clock = r->title->flaky_clock;
 
     while( !*r->die && !r->job->done )
     {
@@ -381,6 +382,10 @@ static void ReaderFunc( void * _r )
     }
 
     hb_log( "reader: done. %d scr changes", r->demux.scr_changes );
+    if ( r->demux.dts_drops )
+    {
+        hb_log( "reader: %d drops because DTS out of range", r->demux.dts_drops );
+    }
 
     free( r );
     _r = NULL;
index 5c8f4f4..dd5c709 100755 (executable)
@@ -466,6 +466,13 @@ hb_stream_t * hb_stream_open( char *path, hb_title_t *title )
                 d->ts_buf[i] = malloc( HB_DVD_READ_BUFFER_SIZE );
             }
             hb_stream_seek( d, 0. );
+
+            if ( d->packetsize == 188 )
+            {
+                // Assume that an over-the-air transport stream can lose PCR
+                // packets and try to filter out the timing inconsistencies.
+                title->flaky_clock = 1;
+            }
         }
         return d;
     }