comparison 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
comparison
equal deleted inserted replaced
17635:db13b7295651 17636:b849a99cdc3c
616 616
617 } 617 }
618 618
619 //extern float initial_pts_delay; 619 //extern float initial_pts_delay;
620 620
621 void demux_seek_avi(demuxer_t *demuxer,float rel_seek_secs,int flags){ 621 void demux_seek_avi(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){
622 avi_priv_t *priv=demuxer->priv; 622 avi_priv_t *priv=demuxer->priv;
623 demux_stream_t *d_audio=demuxer->audio; 623 demux_stream_t *d_audio=demuxer->audio;
624 demux_stream_t *d_video=demuxer->video; 624 demux_stream_t *d_video=demuxer->video;
625 sh_audio_t *sh_audio=d_audio->sh; 625 sh_audio_t *sh_audio=d_audio->sh;
626 sh_video_t *sh_video=d_video->sh; 626 sh_video_t *sh_video=d_video->sh;
704 align=sh_audio->audio.dwSampleSize; 704 align=sh_audio->audio.dwSampleSize;
705 if(sh_audio->wf->nBlockAlign>align) align=sh_audio->wf->nBlockAlign; 705 if(sh_audio->wf->nBlockAlign>align) align=sh_audio->wf->nBlockAlign;
706 curr_audio_pos/=align; 706 curr_audio_pos/=align;
707 curr_audio_pos*=align; 707 curr_audio_pos*=align;
708 #else 708 #else
709 curr_audio_pos=(priv->avi_video_pts)*(float)sh_audio->audio.dwRate/(float)sh_audio->audio.dwScale; 709 /* immediate seeking to audio position, including when streams are delayed */
710 curr_audio_pos-=sh_audio->audio.dwStart; 710 curr_audio_pos=(priv->avi_video_pts + audio_delay)*(float)sh_audio->audio.dwRate/(float)sh_audio->audio.dwScale;
711 curr_audio_pos*=sh_audio->audio.dwSampleSize; 711 curr_audio_pos*=sh_audio->audio.dwSampleSize;
712 #endif 712 #endif
713 713
714 // find audio chunk pos: 714 // find audio chunk pos:
715 for(i=0;i<chunk_max;i++){ 715 for(i=0;i<chunk_max;i++){
731 mp_msg(MSGT_SEEK,MSGL_V,"SEEK: i=%d (max:%d) dpos=%d (wanted:%d) \n", 731 mp_msg(MSGT_SEEK,MSGL_V,"SEEK: i=%d (max:%d) dpos=%d (wanted:%d) \n",
732 i,chunk_max,(int)d_audio->dpos,curr_audio_pos); 732 i,chunk_max,(int)d_audio->dpos,curr_audio_pos);
733 733
734 } else { 734 } else {
735 // VBR audio 735 // VBR audio
736 int chunks=(priv->avi_video_pts)*(float)sh_audio->audio.dwRate/(float)sh_audio->audio.dwScale; 736 /* immediate seeking to audio position, including when streams are delayed */
737 int chunks=(priv->avi_video_pts + audio_delay)*(float)sh_audio->audio.dwRate/(float)sh_audio->audio.dwScale;
737 audio_chunk_pos=0; 738 audio_chunk_pos=0;
738 739
739 // find audio chunk pos: 740 // find audio chunk pos:
740 for(i=0;i<priv->idx_size && chunks>0;i++){ 741 for(i=0;i<priv->idx_size && chunks>0;i++){
741 int id=((AVIINDEXENTRY *)priv->idx)[i].ckid; 742 int id=((AVIINDEXENTRY *)priv->idx)[i].ckid;