diff options
author | wm4 <wm4@nowhere> | 2016-01-29 22:44:20 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2016-01-29 22:44:20 +0100 |
commit | c5a48c63321de00bb8cb6b91a8d6ed22caa3b36f (patch) | |
tree | b01e6e28b78819a782119049bcbfa717ed88aa75 /player | |
parent | 340deb4e6eb1cf09c19cef5bd19c7eab51d6862b (diff) | |
download | mpv-c5a48c63321de00bb8cb6b91a8d6ed22caa3b36f.tar.bz2 mpv-c5a48c63321de00bb8cb6b91a8d6ed22caa3b36f.tar.xz |
audio: move pts reset check
Reduces the dependency of the filter/output code on the decoder.
Diffstat (limited to 'player')
-rw-r--r-- | player/audio.c | 17 | ||||
-rw-r--r-- | player/core.h | 1 |
2 files changed, 16 insertions, 2 deletions
diff --git a/player/audio.c b/player/audio.c index ddf32fb277..e9320d5117 100644 --- a/player/audio.c +++ b/player/audio.c @@ -166,6 +166,7 @@ void update_playback_speed(struct MPContext *mpctx) static void ao_chain_reset_state(struct ao_chain *ao_c) { ao_c->pts = MP_NOPTS_VALUE; + ao_c->pts_reset = false; talloc_free(ao_c->input_frame); ao_c->input_frame = NULL; af_seek_reset(ao_c->af); @@ -611,7 +612,19 @@ static int filter_audio(struct ao_chain *ao_c, struct mp_audio_buffer *outbuf, struct mp_audio *mpa = ao_c->input_frame; ao_c->input_frame = NULL; - ao_c->pts = mpa->pts + mpa->samples / (double)mpa->rate; + if (mpa->pts == MP_NOPTS_VALUE) { + ao_c->pts = MP_NOPTS_VALUE; + } else { + // Attempt to detect jumps in PTS. Even for the lowest sample rates + // and with worst container rounded timestamp, this should be a + // margin more than enough. + if (ao_c->pts != MP_NOPTS_VALUE && fabs(mpa->pts - ao_c->pts) > 0.1) { + MP_WARN(ao_c, "Invalid audio PTS: %f -> %f\n", + ao_c->pts, mpa->pts); + ao_c->pts_reset = true; + } + ao_c->pts = mpa->pts + mpa->samples / (double)mpa->rate; + } if (af_filter_frame(afs, mpa) < 0) return AD_ERR; } @@ -660,7 +673,7 @@ void fill_audio_out_buffers(struct MPContext *mpctx, double endpts) return; // try again next iteration } - if (mpctx->vo_chain && ao_c->audio_src->pts_reset) { + if (mpctx->vo_chain && ao_c->pts_reset) { MP_VERBOSE(mpctx, "Reset playback due to audio timestamp reset.\n"); reset_playback_state(mpctx); mpctx->sleeptime = 0; diff --git a/player/core.h b/player/core.h index 7d34380e87..b144ab6936 100644 --- a/player/core.h +++ b/player/core.h @@ -179,6 +179,7 @@ struct ao_chain { double pts; // timestamp of first sample output by decoder bool spdif_passthrough, spdif_failed; + bool pts_reset; struct af_stream *af; struct ao *ao; |