From 0ff3ffb2be1f3520434a92bd83c57c911572ae3a Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 8 Nov 2015 18:05:16 +0100 Subject: 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. --- audio/decode/dec_audio.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'audio/decode') 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; -- cgit v1.2.3