From afbd06d8d6151b69bbb18adf83cfab8d680c3946 Mon Sep 17 00:00:00 2001 From: van Date: Sat, 31 May 2008 17:00:42 +0000 Subject: - support blu-ray, avchd & dvb x264 - support video files handled by ffmpeg (avi, mkv, mp4, etc.) git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@1480 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- libhb/sync.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'libhb/sync.c') diff --git a/libhb/sync.c b/libhb/sync.c index 34b426f6d..f9c738bdf 100644 --- a/libhb/sync.c +++ b/libhb/sync.c @@ -8,7 +8,7 @@ #include #include "samplerate.h" -#include "ffmpeg/avcodec.h" +#include "libavcodec/avcodec.h" #ifdef INT64_MIN #undef INT64_MIN /* Because it isn't defined correctly in Zeta */ @@ -729,28 +729,34 @@ static void SyncAudio( hb_work_object_t * w, int i ) { if ( (int64_t)( buf->start - sync->next_pts ) < 0 ) { - /* - * audio time went backwards by more than a frame time (this can - * happen when we reset the PTS because of lost data). - * Discard data that's in the past. - */ - if ( sync->first_drop == 0 ) + // audio time went backwards. + // If our output clock is more than a half frame ahead of the + // input clock drop this frame to move closer to sync. + // Otherwise drop frames until the input clock matches the output clock. + if ( sync->first_drop || sync->next_start - buf->start > 90*15 ) { - sync->first_drop = buf->start; + // Discard data that's in the past. + if ( sync->first_drop == 0 ) + { + sync->first_drop = sync->next_pts; + } + ++sync->drop_count; + buf = hb_fifo_get( audio->priv.fifo_raw ); + hb_buffer_close( &buf ); + continue; } - ++sync->drop_count; - buf = hb_fifo_get( audio->priv.fifo_raw ); - hb_buffer_close( &buf ); - continue; + sync->next_pts = buf->start; } if ( sync->first_drop ) { + // we were dropping old data but input buf time is now current hb_log( "sync: audio %d time went backwards %d ms, dropped %d frames " "(next %lld, current %lld)", i, (int)( sync->next_pts - sync->first_drop ) / 90, sync->drop_count, sync->first_drop, sync->next_pts ); sync->first_drop = 0; sync->drop_count = 0; + sync->next_pts = buf->start; } if ( buf->start - sync->next_pts >= (90 * 70) ) { -- cgit v1.2.3