Mercurial > mplayer.hg
changeset 8056:324b6e5387be
A-V sync cleanup: sh_audio->timer replaced by sh_audio->delay, it contains
delay relative to sh_video->timer (or to 0 if audioonly).
It fixes ct: drifts of very long (several hours) playback.
author | arpi |
---|---|
date | Sat, 02 Nov 2002 19:52:59 +0000 |
parents | 79ddb7291765 |
children | 10698ce4b2a4 |
files | libmpdemux/demux_audio.c libmpdemux/demux_demuxers.c libmpdemux/demuxer.c libmpdemux/stheader.h mplayer.c |
diffstat | 5 files changed, 19 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/libmpdemux/demux_audio.c Sat Nov 02 18:57:14 2002 +0000 +++ b/libmpdemux/demux_audio.c Sat Nov 02 19:52:59 2002 +0000 @@ -295,7 +295,7 @@ } if(len > 0) high_res_mp3_seek(demuxer,len); - sh_audio->timer = priv->last_pts - (ds_tell_pts(demuxer->audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; + sh_audio->delay = priv->last_pts - (ds_tell_pts(demuxer->audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; resync_audio_stream(sh_audio); return; } @@ -307,13 +307,13 @@ pos = base + (rel_seek_secs*sh_audio->i_bps); if(demuxer->movi_end && pos >= demuxer->movi_end) { - sh_audio->timer = (stream_tell(s) - demuxer->movi_start)/(float)sh_audio->i_bps; + sh_audio->delay = (stream_tell(s) - demuxer->movi_start)/(float)sh_audio->i_bps; return; } else if(pos < demuxer->movi_start) pos = demuxer->movi_start; priv->last_pts = (pos-demuxer->movi_start)/(float)sh_audio->i_bps; - sh_audio->timer = priv->last_pts - (ds_tell_pts(demuxer->audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; + sh_audio->delay = priv->last_pts - (ds_tell_pts(demuxer->audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; switch(priv->frmt) { case WAV:
--- a/libmpdemux/demux_demuxers.c Sat Nov 02 18:57:14 2002 +0000 +++ b/libmpdemux/demux_demuxers.c Sat Nov 02 19:52:59 2002 +0000 @@ -73,8 +73,7 @@ // In case the demuxer don't set pts if(!demuxer->audio->pts) demuxer->audio->pts = pos-((ds_tell_pts(demuxer->audio)-sh->a_in_buffer_len)/(float)sh->i_bps); - if(sh->timer) - sh->timer = 0; + sh->delay = 0; } if(priv->sd != priv->vd)
--- a/libmpdemux/demuxer.c Sat Nov 02 18:57:14 2002 +0000 +++ b/libmpdemux/demuxer.c Sat Nov 02 19:52:59 2002 +0000 @@ -1135,7 +1135,7 @@ #if 0 if(sh_audio) sh_audio->timer=sh_video->timer; #else - if(sh_audio) sh_audio->timer=0; + if(sh_audio) sh_audio->delay=0; if(sh_video) sh_video->timer=0; // !!!!!! #endif
--- a/libmpdemux/stheader.h Sat Nov 02 18:57:14 2002 +0000 +++ b/libmpdemux/stheader.h Sat Nov 02 19:52:59 2002 +0000 @@ -46,7 +46,7 @@ struct codecs_st *codec; unsigned int format; int inited; - float timer; // value of old a_frame + float delay; // value of old a_frame // output format: int sample_format; int samplerate;
--- a/mplayer.c Sat Nov 02 18:57:14 2002 +0000 +++ b/mplayer.c Sat Nov 02 19:52:59 2002 +0000 @@ -1349,7 +1349,7 @@ current_module="av_init"; if(sh_video) sh_video->timer=0; -if(sh_audio) sh_audio->timer=-audio_delay; +if(sh_audio) sh_audio->delay=-audio_delay; if(!sh_audio){ mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_NoSound); @@ -1414,7 +1414,7 @@ current_module="play_audio"; - ao_data.pts=sh_audio->timer*90000.0; + ao_data.pts=((sh_video?sh_video->timer:0)+sh_audio->delay)*90000.0; playsize=audio_out->get_space(); // handle audio-only case: @@ -1445,7 +1445,7 @@ if(playsize>0){ sh_audio->a_out_buffer_len-=playsize; memmove(sh_audio->a_out_buffer,&sh_audio->a_out_buffer[playsize],sh_audio->a_out_buffer_len); - sh_audio->timer+=playback_speed*playsize/((float)((ao_data.bps && sh_audio->afilter) ? + sh_audio->delay+=playback_speed*playsize/((float)((ao_data.bps && sh_audio->afilter) ? ao_data.bps : sh_audio->o_bps)); } @@ -1455,8 +1455,8 @@ if(!sh_video) { // handle audio-only case: if(!quiet) mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A:%6.1f %4.1f%% %d%% \r" - ,sh_audio->timer-audio_out->get_delay() - ,(sh_audio->timer>0.5)?100.0*audio_time_usage/(double)sh_audio->timer:0 + ,sh_audio->delay-audio_out->get_delay() + ,(sh_audio->delay>0.5)?100.0*audio_time_usage/(double)sh_audio->delay:0 ,cache_fill_status ); if(d_audio->eof) eof = PT_NEXT_ENTRY; @@ -1482,12 +1482,13 @@ if(in_size<0){ eof=1; break; } if(in_size>max_framesize) max_framesize=in_size; // stats sh_video->timer+=frame_time; + if(sh_audio) sh_audio->delay-=frame_time; time_frame+=frame_time; // for nosound // check for frame-drop: current_module="check_framedrop"; if(sh_audio && !d_audio->eof){ float delay=playback_speed*audio_out->get_delay(); - float d=(sh_video->timer)-(sh_audio->timer-delay); + float d=delay-sh_audio->delay; // we should avoid dropping to many frames in sequence unless we // are too late. and we allow 100ms A-V delay here: if(d<-dropped_frames*frame_time-0.100){ @@ -1573,13 +1574,12 @@ * sync to settle at the right value (but it eventually will.) * This settling time is very short for values below 100. */ - float predicted = sh_audio->timer-sh_video->timer+time_frame; + float predicted = sh_audio->delay+time_frame; float difference = delay - predicted; delay = predicted + difference / (float)autosync; } - time_frame=sh_video->timer; - time_frame-=sh_audio->timer-delay; + time_frame=delay-sh_audio->delay; // delay = amount of audio buffered in soundcard/driver if(delay>0.25) delay=0.25; else @@ -1693,7 +1693,7 @@ * value here, even a "corrected" one, would be incompatible with * autosync mode.) */ - delay=sh_audio->timer-sh_video->timer; + delay=sh_audio->delay; delay+=(float)sh_audio->a_buffer_len/(float)sh_audio->o_bps; } @@ -1742,7 +1742,7 @@ max_pts_correction=default_max_pts_correction; else max_pts_correction=sh_video->frametime*0.10; // +-10% of time - if(!frame_time_remaining){ sh_audio->timer+=x; c_total+=x;} // correction + if(!frame_time_remaining){ sh_audio->delay+=x; c_total+=x;} // correction if(!quiet) mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A:%6.1f V:%6.1f A-V:%7.3f ct:%7.3f %3d/%3d %2d%% %2d%% %4.1f%% %d %d %d%%\r", a_pts-audio_delay-delay,v_pts,AV_delay,c_total, (int)sh_video->num_frames,(int)sh_video->num_frames_decoded, @@ -1897,7 +1897,7 @@ float v = cmd->args[0].v.f; audio_delay += v; osd_show_av_delay = 9; - if(sh_audio) sh_audio->timer+= v; + if(sh_audio) sh_audio->delay+= v; } break; case MP_CMD_PAUSE : { osd_function=OSD_PAUSE; @@ -2591,7 +2591,7 @@ guiIntfStruct.Position=(len <= 0? 0.0f : ( pos - demuxer->movi_start ) * 100.0f / len ); } if ( sh_video ) guiIntfStruct.TimeSec=d_video->pts; - else if ( sh_audio ) guiIntfStruct.TimeSec=sh_audio->timer; + else if ( sh_audio ) guiIntfStruct.TimeSec=sh_audio->delay; guiGetEvent( guiReDraw,NULL ); guiGetEvent( guiSetVolume,NULL ); if(guiIntfStruct.Playing==0) break; // STOP