Mercurial > mplayer.hg
diff mplayer.c @ 24900:9079c9745ff9
A/V sync: take audio filter buffers into account
Substract the delay caused by filter buffering when calculating
currently playing audio position. This matters for af_scaletempo which
buffers significant and varying amounts of data. For other current
filters the effect is normally insignificant.
Instead of the old time-based filter delay field (which was ignored)
this version stores the per-filter delay in units of bytes input read
without corresponding output. This allows the current scaletempo
behavior where other filters before and after it can see the same
nominal samplerate even though the real duration of the data varies;
in this case the other filters can not know the delay they're causing
in terms of real time.
author | uau |
---|---|
date | Thu, 01 Nov 2007 06:52:50 +0000 |
parents | 8133163bd1dd |
children | 38f25bdb3cbc |
line wrap: on
line diff
--- a/mplayer.c Thu Nov 01 06:52:47 2007 +0000 +++ b/mplayer.c Thu Nov 01 06:52:50 2007 +0000 @@ -1589,9 +1589,16 @@ // Decoded but not filtered a_pts -= sh_audio->a_buffer_len / (double)sh_audio->o_bps; + // Data buffered in audio filters, measured in bytes of "missing" output + double buffered_output = af_calc_delay(sh_audio->afilter); + // Data that was ready for ao but was buffered because ao didn't fully // accept everything to internal buffers yet - a_pts -= sh_audio->a_out_buffer_len * playback_speed / (double)ao_data.bps; + buffered_output += sh_audio->a_out_buffer_len; + + // Filters divide audio length by playback_speed, so multiply by it + // to get the length in original units without speedup or slowdown + a_pts -= buffered_output * playback_speed / ao_data.bps; return a_pts; }