diff mbox series

[FFmpeg-devel,2/4] lavfi/vaf_spectrumsynth: switch to activate.

Message ID 20200812172558.262021-2-george@nsup.org
State Accepted
Commit 29e0c30b1c182199db5802ad785a928c0663c352
Headers show
Series [FFmpeg-devel,1/4] lavfi/vf_overlay_qsv: remove needs_fifo. | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Nicolas George Aug. 12, 2020, 5:25 p.m. UTC
Preserve the original workings, that does not use frames timestamps
and therefore is very fragile.

Allow to remove needs_fifo.

Signed-off-by: Nicolas George <george@nsup.org>
---
 libavfilter/vaf_spectrumsynth.c | 69 ++++++++++++++++-----------------
 1 file changed, 34 insertions(+), 35 deletions(-)


Tested with the example in the doc.

Comments

Paul B Mahol Aug. 19, 2020, 6:25 p.m. UTC | #1
On 8/12/20, Nicolas George <george@nsup.org> wrote:
> Preserve the original workings, that does not use frames timestamps
> and therefore is very fragile.

That could be added later.

>
> Allow to remove needs_fifo.
>

Patch OK.

> Signed-off-by: Nicolas George <george@nsup.org>
> ---
>  libavfilter/vaf_spectrumsynth.c | 69 ++++++++++++++++-----------------
>  1 file changed, 34 insertions(+), 35 deletions(-)
>
>
> Tested with the example in the doc.
>
>
> diff --git a/libavfilter/vaf_spectrumsynth.c
> b/libavfilter/vaf_spectrumsynth.c
> index fed2cbba03..6a0c45450d 100644
> --- a/libavfilter/vaf_spectrumsynth.c
> +++ b/libavfilter/vaf_spectrumsynth.c
> @@ -34,6 +34,7 @@
>  #include "formats.h"
>  #include "audio.h"
>  #include "video.h"
> +#include "filters.h"
>  #include "internal.h"
>  #include "window_func.h"
>
> @@ -222,25 +223,6 @@ static int config_output(AVFilterLink *outlink)
>      return 0;
>  }
>
> -static int request_frame(AVFilterLink *outlink)
> -{
> -    AVFilterContext *ctx = outlink->src;
> -    SpectrumSynthContext *s = ctx->priv;
> -    int ret;
> -
> -    if (!s->magnitude) {
> -        ret = ff_request_frame(ctx->inputs[0]);
> -        if (ret < 0)
> -            return ret;
> -    }
> -    if (!s->phase) {
> -        ret = ff_request_frame(ctx->inputs[1]);
> -        if (ret < 0)
> -            return ret;
> -    }
> -    return 0;
> -}
> -
>  static void read16_fft_bin(SpectrumSynthContext *s,
>                             int x, int y, int f, int ch)
>  {
> @@ -470,22 +452,43 @@ static int try_push_frames(AVFilterContext *ctx)
>      return ret;
>  }
>
> -static int filter_frame_magnitude(AVFilterLink *inlink, AVFrame *magnitude)
> +static int activate(AVFilterContext *ctx)
>  {
> -    AVFilterContext *ctx = inlink->dst;
>      SpectrumSynthContext *s = ctx->priv;
> +    AVFrame **staging[2] = { &s->magnitude, &s->phase };
> +    int64_t pts;
> +    int i, ret;
>
> -    s->magnitude = magnitude;
> -    return try_push_frames(ctx);
> -}
> +    FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[0], ctx);
>
> -static int filter_frame_phase(AVFilterLink *inlink, AVFrame *phase)
> -{
> -    AVFilterContext *ctx = inlink->dst;
> -    SpectrumSynthContext *s = ctx->priv;
> +    for (i = 0; i < 2; i++) {
> +        if (*staging[i])
> +            continue;
> +        ret = ff_inlink_consume_frame(ctx->inputs[i], staging[i]);
> +        if (ret < 0)
> +            return ret;
> +        if (ret) {
> +            ff_filter_set_ready(ctx, 10);
> +            return try_push_frames(ctx);
> +        }
> +    }
> +
> +    for (i = 0; i < 2; i++) {
> +        if (ff_inlink_acknowledge_status(ctx->inputs[i], &ret, &pts)) {
> +            ff_outlink_set_status(ctx->outputs[0], ret, pts);
> +            ff_inlink_set_status(ctx->inputs[1 - i], ret);
> +            return 0;
> +        }
> +    }
> +
> +    if (ff_outlink_frame_wanted(ctx->outputs[0])) {
> +        for (i = 0; i < 2; i++) {
> +            if (!*staging[i])
> +                ff_inlink_request_frame(ctx->inputs[i]);
> +        }
> +    }
>
> -    s->phase = phase;
> -    return try_push_frames(ctx);
> +    return FFERROR_NOT_READY;
>  }
>
>  static av_cold void uninit(AVFilterContext *ctx)
> @@ -509,14 +512,10 @@ static const AVFilterPad spectrumsynth_inputs[] = {
>      {
>          .name         = "magnitude",
>          .type         = AVMEDIA_TYPE_VIDEO,
> -        .filter_frame = filter_frame_magnitude,
> -        .needs_fifo   = 1,
>      },
>      {
>          .name         = "phase",
>          .type         = AVMEDIA_TYPE_VIDEO,
> -        .filter_frame = filter_frame_phase,
> -        .needs_fifo   = 1,
>      },
>      { NULL }
>  };
> @@ -526,7 +525,6 @@ static const AVFilterPad spectrumsynth_outputs[] = {
>          .name          = "default",
>          .type          = AVMEDIA_TYPE_AUDIO,
>          .config_props  = config_output,
> -        .request_frame = request_frame,
>      },
>      { NULL }
>  };
> @@ -536,6 +534,7 @@ AVFilter ff_vaf_spectrumsynth = {
>      .description   = NULL_IF_CONFIG_SMALL("Convert input spectrum videos to
> audio output."),
>      .uninit        = uninit,
>      .query_formats = query_formats,
> +    .activate      = activate,
>      .priv_size     = sizeof(SpectrumSynthContext),
>      .inputs        = spectrumsynth_inputs,
>      .outputs       = spectrumsynth_outputs,
> --
> 2.28.0
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavfilter/vaf_spectrumsynth.c b/libavfilter/vaf_spectrumsynth.c
index fed2cbba03..6a0c45450d 100644
--- a/libavfilter/vaf_spectrumsynth.c
+++ b/libavfilter/vaf_spectrumsynth.c
@@ -34,6 +34,7 @@ 
 #include "formats.h"
 #include "audio.h"
 #include "video.h"
+#include "filters.h"
 #include "internal.h"
 #include "window_func.h"
 
@@ -222,25 +223,6 @@  static int config_output(AVFilterLink *outlink)
     return 0;
 }
 
-static int request_frame(AVFilterLink *outlink)
-{
-    AVFilterContext *ctx = outlink->src;
-    SpectrumSynthContext *s = ctx->priv;
-    int ret;
-
-    if (!s->magnitude) {
-        ret = ff_request_frame(ctx->inputs[0]);
-        if (ret < 0)
-            return ret;
-    }
-    if (!s->phase) {
-        ret = ff_request_frame(ctx->inputs[1]);
-        if (ret < 0)
-            return ret;
-    }
-    return 0;
-}
-
 static void read16_fft_bin(SpectrumSynthContext *s,
                            int x, int y, int f, int ch)
 {
@@ -470,22 +452,43 @@  static int try_push_frames(AVFilterContext *ctx)
     return ret;
 }
 
-static int filter_frame_magnitude(AVFilterLink *inlink, AVFrame *magnitude)
+static int activate(AVFilterContext *ctx)
 {
-    AVFilterContext *ctx = inlink->dst;
     SpectrumSynthContext *s = ctx->priv;
+    AVFrame **staging[2] = { &s->magnitude, &s->phase };
+    int64_t pts;
+    int i, ret;
 
-    s->magnitude = magnitude;
-    return try_push_frames(ctx);
-}
+    FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[0], ctx);
 
-static int filter_frame_phase(AVFilterLink *inlink, AVFrame *phase)
-{
-    AVFilterContext *ctx = inlink->dst;
-    SpectrumSynthContext *s = ctx->priv;
+    for (i = 0; i < 2; i++) {
+        if (*staging[i])
+            continue;
+        ret = ff_inlink_consume_frame(ctx->inputs[i], staging[i]);
+        if (ret < 0)
+            return ret;
+        if (ret) {
+            ff_filter_set_ready(ctx, 10);
+            return try_push_frames(ctx);
+        }
+    }
+
+    for (i = 0; i < 2; i++) {
+        if (ff_inlink_acknowledge_status(ctx->inputs[i], &ret, &pts)) {
+            ff_outlink_set_status(ctx->outputs[0], ret, pts);
+            ff_inlink_set_status(ctx->inputs[1 - i], ret);
+            return 0;
+        }
+    }
+
+    if (ff_outlink_frame_wanted(ctx->outputs[0])) {
+        for (i = 0; i < 2; i++) {
+            if (!*staging[i])
+                ff_inlink_request_frame(ctx->inputs[i]);
+        }
+    }
 
-    s->phase = phase;
-    return try_push_frames(ctx);
+    return FFERROR_NOT_READY;
 }
 
 static av_cold void uninit(AVFilterContext *ctx)
@@ -509,14 +512,10 @@  static const AVFilterPad spectrumsynth_inputs[] = {
     {
         .name         = "magnitude",
         .type         = AVMEDIA_TYPE_VIDEO,
-        .filter_frame = filter_frame_magnitude,
-        .needs_fifo   = 1,
     },
     {
         .name         = "phase",
         .type         = AVMEDIA_TYPE_VIDEO,
-        .filter_frame = filter_frame_phase,
-        .needs_fifo   = 1,
     },
     { NULL }
 };
@@ -526,7 +525,6 @@  static const AVFilterPad spectrumsynth_outputs[] = {
         .name          = "default",
         .type          = AVMEDIA_TYPE_AUDIO,
         .config_props  = config_output,
-        .request_frame = request_frame,
     },
     { NULL }
 };
@@ -536,6 +534,7 @@  AVFilter ff_vaf_spectrumsynth = {
     .description   = NULL_IF_CONFIG_SMALL("Convert input spectrum videos to audio output."),
     .uninit        = uninit,
     .query_formats = query_formats,
+    .activate      = activate,
     .priv_size     = sizeof(SpectrumSynthContext),
     .inputs        = spectrumsynth_inputs,
     .outputs       = spectrumsynth_outputs,