From fd96bddca98b88e77d6047371b54d6065c4260c2 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 4 Jun 2015 20:08:12 +0200 Subject: [PATCH] af_lavrresample: slightly better computation of total delay On libavresample, don't ignore the buffered output data. On libswresample, don't round the total buffer size to the input samplerate. --- audio/filter/af_lavrresample.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/audio/filter/af_lavrresample.c b/audio/filter/af_lavrresample.c index fec3927671..869f5840ab 100644 --- a/audio/filter/af_lavrresample.c +++ b/audio/filter/af_lavrresample.c @@ -91,9 +91,10 @@ struct af_resample { }; #if HAVE_LIBAVRESAMPLE -static int get_delay(struct af_resample *s) +static double get_delay(struct af_resample *s) { - return avresample_get_delay(s->avrctx); + return avresample_get_delay(s->avrctx) / (double)s->ctx.in_rate + + avresample_available(s->avrctx) / (double)s->ctx.out_rate; } static void drop_all_output(struct af_resample *s) { @@ -104,9 +105,10 @@ static int get_out_samples(struct af_resample *s, int in_samples) return avresample_get_out_samples(s->avrctx, in_samples); } #else -static int get_delay(struct af_resample *s) +static double get_delay(struct af_resample *s) { - return swr_get_delay(s->avrctx, s->ctx.in_rate); + int64_t base = s->ctx.in_rate * (int64_t)s->ctx.out_rate; + return swr_get_delay(s->avrctx, base) / (double)base; } static void drop_all_output(struct af_resample *s) { @@ -419,8 +421,6 @@ static int filter(struct af_instance *af, struct mp_audio *in) if (in) mp_audio_copy_attributes(out, in); - af->delay = get_delay(s) / (double)s->ctx.in_rate; - if (out->samples) { out->samples = resample_frame(s->avrctx, out, in); if (out->samples < 0) @@ -450,6 +450,9 @@ static int filter(struct af_instance *af, struct mp_audio *in) } else { talloc_free(out); } + + af->delay = get_delay(s); + return 0; error: talloc_free(in);