audio: move pts reset check

Reduces the dependency of the filter/output code on the decoder.
This commit is contained in:
wm4 2016-01-29 22:44:20 +01:00
parent 340deb4e6e
commit c5a48c6332
4 changed files with 17 additions and 16 deletions

View File

@ -167,7 +167,6 @@ void audio_reset_decoding(struct dec_audio *d_audio)
if (d_audio->ad_driver)
d_audio->ad_driver->control(d_audio, ADCTRL_RESET, NULL);
d_audio->pts = MP_NOPTS_VALUE;
d_audio->pts_reset = false;
talloc_free(d_audio->current_frame);
d_audio->current_frame = NULL;
talloc_free(d_audio->packet);
@ -183,17 +182,8 @@ static void fix_audio_pts(struct dec_audio *da)
double newpts = da->current_frame->pts;
// 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 || fabs(da->pts - newpts) > 0.001) {
// 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 (da->pts != MP_NOPTS_VALUE && fabs(newpts - da->pts) > 0.1) {
MP_WARN(da, "Invalid audio PTS: %f -> %f\n",
da->pts, newpts);
da->pts_reset = true;
}
if (da->pts == MP_NOPTS_VALUE || fabs(da->pts - newpts) > 0.001)
da->pts = da->current_frame->pts;
}
}
if (da->pts == MP_NOPTS_VALUE && da->header->missing_timestamps)

View File

@ -36,9 +36,6 @@ struct dec_audio {
bool try_spdif;
// set every time a jump in timestamps is encountered
bool pts_reset;
// For free use by the ad_driver
void *priv;

View File

@ -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;

View File

@ -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;