diff options
author | van <[email protected]> | 2008-04-15 19:14:03 +0000 |
---|---|---|
committer | van <[email protected]> | 2008-04-15 19:14:03 +0000 |
commit | 56d9caaefb91abc763be3a1d17d14d0e7e2e9059 (patch) | |
tree | c693cf6b581410cc53b55772bf1d5a68ddc9456f /libhb/reader.c | |
parent | b856292606251eafc70286eac8c5dc6e6fd9dd02 (diff) |
Move clock recovery code from reader to demuxmpeg so it sees all frames & not just the ones we happen to be encoding. This change gives a more accurate clock and allows us to once again ignore audio during pass 1 of a 2 pass encode.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1420 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb/reader.c')
-rw-r--r-- | libhb/reader.c | 61 |
1 files changed, 9 insertions, 52 deletions
diff --git a/libhb/reader.c b/libhb/reader.c index ac02f90ca..233319833 100644 --- a/libhb/reader.c +++ b/libhb/reader.c @@ -16,12 +16,9 @@ typedef struct hb_buffer_t * ps; hb_stream_t * stream; + hb_psdemux_t demux; uint sequence; int saw_video; - int64_t scr_offset; - int64_t last_scr; - int scr_changes; - } hb_reader_t; /*********************************************************************** @@ -161,7 +158,7 @@ static void ReaderFunc( void * _r ) hb_set_state( r->job->h, &state ); } - hb_demux_ps( r->ps, list ); + hb_demux_ps( r->ps, list, &r->demux ); while( ( buf = hb_list_item( list, 0 ) ) ) { @@ -175,10 +172,9 @@ static void ReaderFunc( void * _r ) if ( buf->id == 0xE0 && buf->start != -1 ) { r->saw_video = 1; - r->scr_offset = buf->start; - r->last_scr = buf->stop; + r->demux.scr_offset = buf->start; hb_log( "reader: first SCR %llu scr_offset %llu", - r->last_scr, r->scr_offset ); + r->demux.last_scr, r->demux.scr_offset ); } else { @@ -187,52 +183,13 @@ static void ReaderFunc( void * _r ) } if( fifos ) { - /* - * This section of code implements the timing model of - * the "Standard Target Decoder" (STD) of the MPEG2 standard - * (specified in ISO 13818-1 sections 2.4.2, 2.5.2 & Annex D). - * The STD removes and corrects for clock discontinuities so - * that the time stamps on the video, audio & other media - * streams can be used for cross-media synchronization. To do - * this the STD has its own timestamp value, the System Clock - * Reference or SCR, in the PACK header. Clock discontinuities - * are detected using the SCR & and the adjustment needed - * to correct post-discontinuity timestamps to be contiguous - * with pre-discontinuity timestamps is computed from pre- and - * post-discontinuity values of the SCR. Then this adjustment - * is applied to every media timestamp (PTS). - * - * hb_demux_ps left the SCR for this pack in buf->stop. - * ISO 13818-1 says there must be an SCR at least every 700ms - * (100ms for Transport Streams) so if the difference between - * this SCR & the previous is >700ms it's a discontinuity. - * If the difference is negative it's non-physical (time doesn't - * go backward) and must also be a discontinuity. When we find a - * discontinuity we adjust the scr_offset so that the SCR of the - * new packet lines up with that of the previous packet. - */ - int64_t scr_delta = buf->stop - r->last_scr; - if ( scr_delta > (90*700) || scr_delta < -90 ) - { - ++r->scr_changes; - r->scr_offset += scr_delta - 1; - } - r->last_scr = buf->stop; - buf->stop = -1; - - /* - * The last section detected discontinuites and computed the - * appropriate correction to remove them. The next couple of - * lines apply the correction to the media timestamps so the - * code downstream of us sees only timestamps relative to the - * same, continuous clock with time zero on that clock being - * the time of the first video packet. - */ if ( buf->start != -1 ) { /* this packet has a PTS - correct it for the initial - video time offset & any timing discontinuities. */ - buf->start -= r->scr_offset; + video time offset & any timing discontinuities so that + everything after this sees a continuous clock with 0 + being the time of the first video packet. */ + buf->start -= r->demux.scr_offset; } buf->sequence = r->sequence++; for( n = 0; fifos[n] != NULL; n++) @@ -284,7 +241,7 @@ static void ReaderFunc( void * _r ) hb_stream_close(&r->stream); } - hb_log( "reader: done. %d scr changes", r->scr_changes ); + hb_log( "reader: done. %d scr changes", r->demux.scr_changes ); free( r ); _r = NULL; |