diff libmpdemux/demux_avi.c @ 17636:b849a99cdc3c

Second-try commit of this patch. 1. Include audio_delay as an argument to demux_seek. 2. Modify demux_seek_avi to adjust the audio/video stream positions so that mplayer/mencoder will instantly be in sync even when -delay is specified. I've quadruple checked this time; hopefully I haven't missed anything.
author corey
date Fri, 17 Feb 2006 01:57:41 +0000
parents 6c541a8421ca
children cea08919336b
line wrap: on
line diff
--- a/libmpdemux/demux_avi.c	Thu Feb 16 22:43:42 2006 +0000
+++ b/libmpdemux/demux_avi.c	Fri Feb 17 01:57:41 2006 +0000
@@ -618,7 +618,7 @@
 
 //extern float initial_pts_delay;
 
-void demux_seek_avi(demuxer_t *demuxer,float rel_seek_secs,int flags){
+void demux_seek_avi(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){
     avi_priv_t *priv=demuxer->priv;
     demux_stream_t *d_audio=demuxer->audio;
     demux_stream_t *d_video=demuxer->video;
@@ -706,8 +706,8 @@
 	    curr_audio_pos/=align;
 	    curr_audio_pos*=align;
 #else
-	    curr_audio_pos=(priv->avi_video_pts)*(float)sh_audio->audio.dwRate/(float)sh_audio->audio.dwScale;
-	    curr_audio_pos-=sh_audio->audio.dwStart;
+	    /* immediate seeking to audio position, including when streams are delayed */
+	    curr_audio_pos=(priv->avi_video_pts + audio_delay)*(float)sh_audio->audio.dwRate/(float)sh_audio->audio.dwScale;
 	    curr_audio_pos*=sh_audio->audio.dwSampleSize;
 #endif
 
@@ -733,7 +733,8 @@
 	      
 	} else {
 	    // VBR audio
-	    int chunks=(priv->avi_video_pts)*(float)sh_audio->audio.dwRate/(float)sh_audio->audio.dwScale;
+	    /* immediate seeking to audio position, including when streams are delayed */
+	    int chunks=(priv->avi_video_pts + audio_delay)*(float)sh_audio->audio.dwRate/(float)sh_audio->audio.dwScale;
 	    audio_chunk_pos=0;
 	    
         // find audio chunk pos: