summaryrefslogtreecommitdiffstats
path: root/mplayer.c
diff options
context:
space:
mode:
authoruau <uau@b3059339-0415-0410-9bf9-f77b7e298cf2>2007-11-01 06:52:50 +0000
committeruau <uau@b3059339-0415-0410-9bf9-f77b7e298cf2>2007-11-01 06:52:50 +0000
commitd7f6cb23dec483f538239eb42e21c321713c976e (patch)
treea5a87950b4cdae8d0b4e9a6df202000fd4825615 /mplayer.c
parentde034ce87fdf632b48563e5764f19d66120550a8 (diff)
downloadmpv-d7f6cb23dec483f538239eb42e21c321713c976e.tar.bz2
mpv-d7f6cb23dec483f538239eb42e21c321713c976e.tar.xz
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. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@24928 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'mplayer.c')
-rw-r--r--mplayer.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/mplayer.c b/mplayer.c
index a50e7f7694..6b7515e64b 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -1589,9 +1589,16 @@ static double written_audio_pts(sh_audio_t *sh_audio, demux_stream_t *d_audio)
// 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;
}