diff mbox

[FFmpeg-devel] avilter/avf_showwaves: switch to activate in showwaves filter

Message ID 20190530183601.3892-1-onemda@gmail.com
State Accepted
Commit d3f236b300e334d84f40b836278278833107d0fd
Headers show

Commit Message

Paul B Mahol May 30, 2019, 6:36 p.m. UTC
Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavfilter/avf_showwaves.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

Comments

Paul B Mahol June 3, 2019, 8:54 a.m. UTC | #1
On 5/30/19, Paul B Mahol <onemda@gmail.com> wrote:
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
>  libavfilter/avf_showwaves.c | 30 +++++++++++++++++++++++++++---
>  1 file changed, 27 insertions(+), 3 deletions(-)
>

Will apply soon.
diff mbox

Patch

diff --git a/libavfilter/avf_showwaves.c b/libavfilter/avf_showwaves.c
index d85ebd9050..afe05fb504 100644
--- a/libavfilter/avf_showwaves.c
+++ b/libavfilter/avf_showwaves.c
@@ -29,6 +29,7 @@ 
 #include "libavutil/opt.h"
 #include "libavutil/parseutils.h"
 #include "avfilter.h"
+#include "filters.h"
 #include "formats.h"
 #include "audio.h"
 #include "video.h"
@@ -706,7 +707,8 @@  static int showwaves_filter_frame(AVFilterLink *inlink, AVFrame *insamples)
             showwaves->sample_count_mod = 0;
             showwaves->buf_idx++;
         }
-        if (showwaves->buf_idx == showwaves->w)
+        if (showwaves->buf_idx == showwaves->w ||
+            (ff_outlink_get_status(inlink) && i == nb_samples - 1))
             if ((ret = push_frame(outlink)) < 0)
                 break;
         outpicref = showwaves->outpicref;
@@ -717,11 +719,33 @@  end:
     return ret;
 }
 
+static int activate(AVFilterContext *ctx)
+{
+    AVFilterLink *inlink = ctx->inputs[0];
+    AVFilterLink *outlink = ctx->outputs[0];
+    ShowWavesContext *showwaves = ctx->priv;
+    AVFrame *in;
+    const int nb_samples = showwaves->n * outlink->w;
+    int ret;
+
+    FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
+
+    ret = ff_inlink_consume_samples(inlink, nb_samples, nb_samples, &in);
+    if (ret < 0)
+        return ret;
+    if (ret > 0)
+        return showwaves_filter_frame(inlink, in);
+
+    FF_FILTER_FORWARD_STATUS(inlink, outlink);
+    FF_FILTER_FORWARD_WANTED(outlink, inlink);
+
+    return FFERROR_NOT_READY;
+}
+
 static const AVFilterPad showwaves_inputs[] = {
     {
         .name         = "default",
         .type         = AVMEDIA_TYPE_AUDIO,
-        .filter_frame = showwaves_filter_frame,
     },
     { NULL }
 };
@@ -731,7 +755,6 @@  static const AVFilterPad showwaves_outputs[] = {
         .name          = "default",
         .type          = AVMEDIA_TYPE_VIDEO,
         .config_props  = config_output,
-        .request_frame = request_frame,
     },
     { NULL }
 };
@@ -744,6 +767,7 @@  AVFilter ff_avf_showwaves = {
     .query_formats = query_formats,
     .priv_size     = sizeof(ShowWavesContext),
     .inputs        = showwaves_inputs,
+    .activate      = activate,
     .outputs       = showwaves_outputs,
     .priv_class    = &showwaves_class,
 };