diff mbox

[FFmpeg-devel,v2,2/2] avfilter/vf_scale: change filter_frame interface to activate interface

Message ID 20190907151126.2112-2-lance.lmwang@gmail.com
State New
Headers show

Commit Message

Lance Wang Sept. 7, 2019, 3:11 p.m. UTC
From: Limin Wang <lance.lmwang@gmail.com>

Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
---
 libavfilter/vf_scale.c | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

Comments

Lance Wang Sept. 18, 2019, 2:23 p.m. UTC | #1
ping, patchset 1 is merged already.


On Sat, Sep 07, 2019 at 11:11:26PM +0800, lance.lmwang@gmail.com wrote:
> From: Limin Wang <lance.lmwang@gmail.com>
> 
> Signed-off-by: Limin Wang <lance.lmwang@gmail.com>
> ---
>  libavfilter/vf_scale.c | 36 +++++++++++++++++++++++++++++++++++-
>  1 file changed, 35 insertions(+), 1 deletion(-)
> 
> diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
> index cb42794..5c1d811 100644
> --- a/libavfilter/vf_scale.c
> +++ b/libavfilter/vf_scale.c
> @@ -27,6 +27,7 @@
>  #include <string.h>
>  
>  #include "avfilter.h"
> +#include "filters.h"
>  #include "formats.h"
>  #include "internal.h"
>  #include "scale.h"
> @@ -554,6 +555,39 @@ static int filter_frame(AVFilterLink *link, AVFrame *in)
>      return ret;
>  }
>  
> +static int activate(AVFilterContext *ctx)
> +{
> +    AVFilterLink *inlink = ctx->inputs[0];
> +    AVFilterLink *outlink = ctx->outputs[0];
> +    AVFrame *in, *out = NULL;
> +    int64_t pts;
> +    int ret, status;
> +
> +    FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
> +
> +    ret = ff_inlink_consume_frame(inlink, &in);
> +    if (ret > 0) {
> +        ret = scale_frame(inlink, in, &out);
> +        if (ret)
> +            return ret;
> +        if (out)
> +            return ff_filter_frame(outlink, out);
> +    }
> +
> +    if (ff_inlink_acknowledge_status(inlink, &status, &pts)) {
> +        if (status == AVERROR_EOF) {
> +            /* frame flushing */
> +        }
> +
> +        ff_outlink_set_status(outlink, status, pts);
> +        return ret;
> +    }
> +
> +    FF_FILTER_FORWARD_WANTED(outlink, inlink);
> +
> +    return FFERROR_NOT_READY;
> +}
> +
>  static int filter_frame_ref(AVFilterLink *link, AVFrame *in)
>  {
>      AVFilterLink *outlink = link->dst->outputs[1];
> @@ -653,7 +687,6 @@ static const AVFilterPad avfilter_vf_scale_inputs[] = {
>      {
>          .name         = "default",
>          .type         = AVMEDIA_TYPE_VIDEO,
> -        .filter_frame = filter_frame,
>      },
>      { NULL }
>  };
> @@ -672,6 +705,7 @@ AVFilter ff_vf_scale = {
>      .description     = NULL_IF_CONFIG_SMALL("Scale the input video size and/or convert the image format."),
>      .init_dict       = init_dict,
>      .uninit          = uninit,
> +    .activate        = activate,
>      .query_formats   = query_formats,
>      .priv_size       = sizeof(ScaleContext),
>      .priv_class      = &scale_class,
> -- 
> 2.6.4
>
diff mbox

Patch

diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index cb42794..5c1d811 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -27,6 +27,7 @@ 
 #include <string.h>
 
 #include "avfilter.h"
+#include "filters.h"
 #include "formats.h"
 #include "internal.h"
 #include "scale.h"
@@ -554,6 +555,39 @@  static int filter_frame(AVFilterLink *link, AVFrame *in)
     return ret;
 }
 
+static int activate(AVFilterContext *ctx)
+{
+    AVFilterLink *inlink = ctx->inputs[0];
+    AVFilterLink *outlink = ctx->outputs[0];
+    AVFrame *in, *out = NULL;
+    int64_t pts;
+    int ret, status;
+
+    FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink);
+
+    ret = ff_inlink_consume_frame(inlink, &in);
+    if (ret > 0) {
+        ret = scale_frame(inlink, in, &out);
+        if (ret)
+            return ret;
+        if (out)
+            return ff_filter_frame(outlink, out);
+    }
+
+    if (ff_inlink_acknowledge_status(inlink, &status, &pts)) {
+        if (status == AVERROR_EOF) {
+            /* frame flushing */
+        }
+
+        ff_outlink_set_status(outlink, status, pts);
+        return ret;
+    }
+
+    FF_FILTER_FORWARD_WANTED(outlink, inlink);
+
+    return FFERROR_NOT_READY;
+}
+
 static int filter_frame_ref(AVFilterLink *link, AVFrame *in)
 {
     AVFilterLink *outlink = link->dst->outputs[1];
@@ -653,7 +687,6 @@  static const AVFilterPad avfilter_vf_scale_inputs[] = {
     {
         .name         = "default",
         .type         = AVMEDIA_TYPE_VIDEO,
-        .filter_frame = filter_frame,
     },
     { NULL }
 };
@@ -672,6 +705,7 @@  AVFilter ff_vf_scale = {
     .description     = NULL_IF_CONFIG_SMALL("Scale the input video size and/or convert the image format."),
     .init_dict       = init_dict,
     .uninit          = uninit,
+    .activate        = activate,
     .query_formats   = query_formats,
     .priv_size       = sizeof(ScaleContext),
     .priv_class      = &scale_class,