diff mbox

[FFmpeg-devel,2/5] avfilter/scale2ref: update links and re-eval expr upon ref frame change

Message ID 95da4784-aa5c-a24b-0d96-62549a57ccc9@gyani.pro
State New
Headers show

Commit Message

Gyan Doshi Dec. 15, 2019, 5:06 p.m. UTC
2nd of 5 factorized patches; supersedes 
https://patchwork.ffmpeg.org/patch/16272/
From f5055424fb9988644d413c2599fe7ed4526c8334 Mon Sep 17 00:00:00 2001
From: Gyan Doshi <ffmpeg@gyani.pro>
Date: Sun, 8 Dec 2019 15:54:28 +0530
Subject: [PATCH 2/5] avfilter/scale2ref: update links and re-eval expr upon
 ref frame change

Needed when filtergraph reinit is disabled for the ref input.
---
 libavfilter/vf_scale.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

Comments

Michael Niedermayer Dec. 16, 2019, 8:04 p.m. UTC | #1
On Sun, Dec 15, 2019 at 10:36:43PM +0530, Gyan wrote:
> 2nd of 5 factorized patches; supersedes
> https://patchwork.ffmpeg.org/patch/16272/

>  vf_scale.c |   26 +++++++++++++++++++++++---
>  1 file changed, 23 insertions(+), 3 deletions(-)
> f14dfec0c69734fc8d9291ab719918e2503625c6  0002-avfilter-scale2ref-update-links-and-re-eval-expr-upo.patch
> From f5055424fb9988644d413c2599fe7ed4526c8334 Mon Sep 17 00:00:00 2001
> From: Gyan Doshi <ffmpeg@gyani.pro>
> Date: Sun, 8 Dec 2019 15:54:28 +0530
> Subject: [PATCH 2/5] avfilter/scale2ref: update links and re-eval expr upon
>  ref frame change
> 
> Needed when filtergraph reinit is disabled for the ref input.
> ---
>  libavfilter/vf_scale.c | 26 +++++++++++++++++++++++---
>  1 file changed, 23 insertions(+), 3 deletions(-)

maybe ok

thanks

[...]
diff mbox

Patch

diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c
index ba693bb601..5a375fac5d 100644
--- a/libavfilter/vf_scale.c
+++ b/libavfilter/vf_scale.c
@@ -392,8 +392,9 @@  static int scale_slice(AVFilterLink *link, AVFrame *out_buf, AVFrame *cur_pic, s
 
 static int scale_frame(AVFilterLink *link, AVFrame *in, AVFrame **frame_out)
 {
-    ScaleContext *scale = link->dst->priv;
-    AVFilterLink *outlink = link->dst->outputs[0];
+    AVFilterContext *ctx = link->dst;
+    ScaleContext *scale = ctx->priv;
+    AVFilterLink *outlink = ctx->outputs[0];
     AVFrame *out;
     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(link->format);
     char buf[32];
@@ -410,7 +411,9 @@  static int scale_frame(AVFilterLink *link, AVFrame *in, AVFrame **frame_out)
                     in->sample_aspect_ratio.den != link->sample_aspect_ratio.den ||
                     in->sample_aspect_ratio.num != link->sample_aspect_ratio.num;
 
-    if (frame_changed) {
+    if (frame_changed ||
+        (scale->eval_mode == EVAL_MODE_FRAME &&
+         ctx->filter == &ff_vf_scale2ref) ) {
         int ret;
 
         if (scale->eval_mode == EVAL_MODE_INIT) {
@@ -538,6 +541,23 @@  static int filter_frame(AVFilterLink *link, AVFrame *in)
 static int filter_frame_ref(AVFilterLink *link, AVFrame *in)
 {
     AVFilterLink *outlink = link->dst->outputs[1];
+    int frame_changed;
+
+    frame_changed = in->width  != link->w ||
+                    in->height != link->h ||
+                    in->format != link->format ||
+                    in->sample_aspect_ratio.den != link->sample_aspect_ratio.den ||
+                    in->sample_aspect_ratio.num != link->sample_aspect_ratio.num;
+
+    if (frame_changed) {
+        link->format = in->format;
+        link->w = in->width;
+        link->h = in->height;
+        link->sample_aspect_ratio.num = in->sample_aspect_ratio.num;
+        link->sample_aspect_ratio.den = in->sample_aspect_ratio.den;
+
+        config_props_ref(outlink);
+    }
 
     return ff_filter_frame(outlink, in);
 }