summaryrefslogtreecommitdiffstats
path: root/audio/decode
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-11-08 18:05:16 +0100
committerwm4 <wm4@nowhere>2015-11-08 18:06:24 +0100
commit0ff3ffb2be1f3520434a92bd83c57c911572ae3a (patch)
tree630e791dc92f575f993bd016c00848d7bf2566aa /audio/decode
parentd91434756b1bd16d788d93e6b888c2d1a54f1968 (diff)
downloadmpv-0ff3ffb2be1f3520434a92bd83c57c911572ae3a.tar.bz2
mpv-0ff3ffb2be1f3520434a92bd83c57c911572ae3a.tar.xz
audio: interpolate audio timestamps
Deal with jittering Matroska crap timestamps. This reuses the mechanism that is needed for frames without PTS, and adds a heuristic to it. If the interpolated timestamp is less than 1ms away from the real one, it might be due to Matroska timestamp rounding (or other file formats with such rounding, or files remuxed from Matroska). While there actually isn't much of a need to do this (audio PTS jittering by such a low amount doesn't negatively influence much), it helps with identifying jitter from other sources.
Diffstat (limited to 'audio/decode')
-rw-r--r--audio/decode/dec_audio.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/audio/decode/dec_audio.c b/audio/decode/dec_audio.c
index 623951eb22..98fb83f895 100644
--- a/audio/decode/dec_audio.c
+++ b/audio/decode/dec_audio.c
@@ -172,8 +172,18 @@ static int decode_new_frame(struct dec_audio *da)
if (da->waiting) {
if (da->waiting->pts != MP_NOPTS_VALUE) {
- da->pts = da->waiting->pts;
- da->pts_offset = 0;
+ if (da->pts != MP_NOPTS_VALUE) {
+ da->pts += da->pts_offset / (double)da->waiting->rate;
+ da->pts_offset = 0;
+ }
+ // Keep the interpolated timestamp if it doesn't deviate more
+ // than 1 ms from the real one. (MKV rounded timestamps.)
+ if (da->pts == MP_NOPTS_VALUE || da->pts_offset != 0 ||
+ fabs(da->pts - da->waiting->pts) > 0.001)
+ {
+ da->pts = da->waiting->pts;
+ da->pts_offset = 0;
+ }
}
da->pts_offset += da->waiting->samples;
da->decode_format = *da->waiting;