[FFmpeg-cvslog] avfilter/af_rubberband: switch to activate

Paul B Mahol git at videolan.org
Mon Apr 29 16:22:12 EEST 2019


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Mon Apr 29 14:22:13 2019 +0200| [a40bcb5c93b576c7158e0388a750b077eb6aa807] | committer: Paul B Mahol

avfilter/af_rubberband: switch to activate

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a40bcb5c93b576c7158e0388a750b077eb6aa807
---

 libavfilter/af_rubberband.c | 66 +++++++++++++++------------------------------
 1 file changed, 22 insertions(+), 44 deletions(-)

diff --git a/libavfilter/af_rubberband.c b/libavfilter/af_rubberband.c
index 767e50f1bb..ca2be4dcb9 100644
--- a/libavfilter/af_rubberband.c
+++ b/libavfilter/af_rubberband.c
@@ -24,6 +24,7 @@
 
 #include "audio.h"
 #include "avfilter.h"
+#include "filters.h"
 #include "formats.h"
 #include "internal.h"
 
@@ -36,7 +37,7 @@ typedef struct RubberBandContext {
         smoothing, formant, opitch, channels;
     int64_t nb_samples_out;
     int64_t nb_samples_in;
-    int flushed;
+    int nb_samples;
 } RubberBandContext;
 
 #define OFFSET(x) offsetof(RubberBandContext, x)
@@ -123,7 +124,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     AVFrame *out;
     int ret = 0, nb_samples;
 
-    rubberband_process(s->rbs, (const float *const *)in->data, in->nb_samples, 0);
+    rubberband_process(s->rbs, (const float *const *)in->data, in->nb_samples, ff_outlink_get_status(inlink));
     s->nb_samples_in += in->nb_samples;
 
     nb_samples = rubberband_available(s->rbs);
@@ -160,53 +161,31 @@ static int config_input(AVFilterLink *inlink)
     if (!s->rbs)
         return AVERROR(ENOMEM);
 
-    inlink->partial_buf_size =
-    inlink->min_samples =
-    inlink->max_samples = rubberband_get_samples_required(s->rbs);
+    s->nb_samples = rubberband_get_samples_required(s->rbs);
 
     return 0;
 }
 
-static int request_frame(AVFilterLink *outlink)
+static int activate(AVFilterContext *ctx)
 {
-    AVFilterContext *ctx = outlink->src;
-    RubberBandContext *s = ctx->priv;
     AVFilterLink *inlink = ctx->inputs[0];
-    int ret = 0;
-
-    ret = ff_request_frame(ctx->inputs[0]);
-
-    if (ret == AVERROR_EOF && !s->flushed) {
-        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);
-            nb_samples = rubberband_available(s->rbs);
-
-            if (nb_samples > 0) {
-                out = ff_get_audio_buffer(outlink, 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);
-    }
+    AVFilterLink *outlink = ctx->outputs[0];
+    RubberBandContext *s = ctx->priv;
+    AVFrame *in = NULL;
+    int ret;
 
-    return ret;
+    FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
+
+    ret = ff_inlink_consume_samples(inlink, s->nb_samples, s->nb_samples, &in);
+    if (ret < 0)
+        return ret;
+    if (ret > 0)
+        return filter_frame(inlink, in);
+
+    FF_FILTER_FORWARD_STATUS(inlink, outlink);
+    FF_FILTER_FORWARD_WANTED(outlink, inlink);
+
+    return FFERROR_NOT_READY;
 }
 
 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
@@ -246,7 +225,6 @@ static const AVFilterPad rubberband_inputs[] = {
         .name          = "default",
         .type          = AVMEDIA_TYPE_AUDIO,
         .config_props  = config_input,
-        .filter_frame  = filter_frame,
     },
     { NULL }
 };
@@ -255,7 +233,6 @@ static const AVFilterPad rubberband_outputs[] = {
     {
         .name          = "default",
         .type          = AVMEDIA_TYPE_AUDIO,
-        .request_frame = request_frame,
     },
     { NULL }
 };
@@ -267,6 +244,7 @@ AVFilter ff_af_rubberband = {
     .priv_size     = sizeof(RubberBandContext),
     .priv_class    = &rubberband_class,
     .uninit        = uninit,
+    .activate      = activate,
     .inputs        = rubberband_inputs,
     .outputs       = rubberband_outputs,
     .process_command = process_command,



More information about the ffmpeg-cvslog mailing list