From 6ce02126cec5ceb4c0f0be8099aba89d61345c09 Mon Sep 17 00:00:00 2001 From: Paul B Mahol <onemda@gmail.com> Date: Wed, 30 Sep 2015 13:02:03 +0200 Subject: avfilter/af_rubberband: flush only if there is something available Signed-off-by: Paul B Mahol <onemda@gmail.com> --- libavfilter/af_rubberband.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/libavfilter/af_rubberband.c b/libavfilter/af_rubberband.c index abd6483a75..0a15fdc51a 100644 --- a/libavfilter/af_rubberband.c +++ b/libavfilter/af_rubberband.c @@ -175,29 +175,31 @@ static int request_frame(AVFilterLink *outlink) ret = ff_request_frame(ctx->inputs[0]); if (ret == AVERROR_EOF && !s->flushed) { - AVFrame *out = ff_get_audio_buffer(inlink, 1); - int nb_samples; + if (rubberband_available(s->rbs) > 0) { + AVFrame *out = ff_get_audio_buffer(inlink, 1); + int nb_samples; - if (!out) - return AVERROR(ENOMEM); - - rubberband_process(s->rbs, (const float *const *)out->data, 1, 1); - av_frame_free(&out); - s->flushed = 1; - nb_samples = rubberband_available(s->rbs); - - if (nb_samples > 0) { - out = ff_get_audio_buffer(inlink, nb_samples); if (!out) return AVERROR(ENOMEM); - out->pts = av_rescale_q(s->nb_samples_out, - (AVRational){ 1, outlink->sample_rate }, - outlink->time_base); - nb_samples = rubberband_retrieve(s->rbs, (float *const *)out->data, nb_samples); - out->nb_samples = nb_samples; - ret = ff_filter_frame(outlink, out); - s->nb_samples_out += nb_samples; + + rubberband_process(s->rbs, (const float *const *)out->data, 1, 1); + av_frame_free(&out); + nb_samples = rubberband_available(s->rbs); + + if (nb_samples > 0) { + out = ff_get_audio_buffer(inlink, nb_samples); + if (!out) + return AVERROR(ENOMEM); + out->pts = av_rescale_q(s->nb_samples_out, + (AVRational){ 1, outlink->sample_rate }, + outlink->time_base); + nb_samples = rubberband_retrieve(s->rbs, (float *const *)out->data, nb_samples); + out->nb_samples = nb_samples; + ret = ff_filter_frame(outlink, out); + s->nb_samples_out += nb_samples; + } } + s->flushed = 1; av_log(ctx, AV_LOG_DEBUG, "nb_samples_in %"PRId64" nb_samples_out %"PRId64"\n", s->nb_samples_in, s->nb_samples_out); } -- cgit v1.2.3