diff mbox series

[FFmpeg-devel,v4,05/21] lavfi/vpp_qsv: handle NULL pointer when evaluating an expression

Message ID 20210729052509.30992-6-haihao.xiang@intel.com
State New
Headers show
Series clean-up QSV filters
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Haihao Xiang July 29, 2021, 5:24 a.m. UTC
This is in preparation for re-using VPPContext but with a different
option array for scale_qsv filter
---
 libavfilter/vf_vpp_qsv.c | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)
diff mbox series

Patch

diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c
index cc8fe1645e..c0fc0d4154 100644
--- a/libavfilter/vf_vpp_qsv.c
+++ b/libavfilter/vf_vpp_qsv.c
@@ -162,14 +162,19 @@  enum var_name {
 static int eval_expr(AVFilterContext *ctx)
 {
 #define PASS_EXPR(e, s) {\
-    ret = av_expr_parse(&e, s, var_names, NULL, NULL, NULL, NULL, 0, ctx); \
-    if (ret < 0) {\
-        av_log(ctx, AV_LOG_ERROR, "Error when passing '%s'.\n", s);\
-        goto release;\
+    if (s) {\
+        ret = av_expr_parse(&e, s, var_names, NULL, NULL, NULL, NULL, 0, ctx); \
+        if (ret < 0) {                                                  \
+            av_log(ctx, AV_LOG_ERROR, "Error when passing '%s'.\n", s); \
+            goto release;                                               \
+        }                                                               \
     }\
 }
-#define CALC_EXPR(e, v, i) {\
-    i = v = av_expr_eval(e, var_values, NULL); \
+#define CALC_EXPR(e, v, i, d) {\
+    if (e)\
+        i = v = av_expr_eval(e, var_values, NULL);      \
+    else\
+        i = v = d;\
 }
     VPPContext *vpp = ctx->priv;
     double  var_values[VAR_VARS_NB] = { NAN };
@@ -199,30 +204,29 @@  static int eval_expr(AVFilterContext *ctx)
     var_values[VAR_DAR] = var_values[VAR_A] * var_values[VAR_SAR];
 
     /* crop params */
-    CALC_EXPR(cw_expr, var_values[CW], vpp->crop_w);
-    CALC_EXPR(ch_expr, var_values[CH], vpp->crop_h);
+    CALC_EXPR(cw_expr, var_values[CW], vpp->crop_w, var_values[VAR_IW]);
+    CALC_EXPR(ch_expr, var_values[CH], vpp->crop_h, var_values[VAR_IH]);
 
     /* calc again in case cw is relative to ch */
-    CALC_EXPR(cw_expr, var_values[CW], vpp->crop_w);
+    CALC_EXPR(cw_expr, var_values[CW], vpp->crop_w, var_values[VAR_IW]);
 
     CALC_EXPR(w_expr,
             var_values[VAR_OUT_W] = var_values[VAR_OW] = var_values[VAR_W],
-            vpp->out_width);
+            vpp->out_width, var_values[CW]);
     CALC_EXPR(h_expr,
             var_values[VAR_OUT_H] = var_values[VAR_OH] = var_values[VAR_H],
-            vpp->out_height);
+            vpp->out_height, var_values[CH]);
 
     /* calc again in case ow is relative to oh */
     CALC_EXPR(w_expr,
             var_values[VAR_OUT_W] = var_values[VAR_OW] = var_values[VAR_W],
-            vpp->out_width);
+            vpp->out_width, var_values[CW]);
 
-
-    CALC_EXPR(cx_expr, var_values[CX], vpp->crop_x);
-    CALC_EXPR(cy_expr, var_values[CY], vpp->crop_y);
+    CALC_EXPR(cx_expr, var_values[CX], vpp->crop_x, (var_values[VAR_IW] - var_values[VAR_OW]) / 2);
+    CALC_EXPR(cy_expr, var_values[CY], vpp->crop_y, (var_values[VAR_IH] - var_values[VAR_OH]) / 2);
 
     /* calc again in case cx is relative to cy */
-    CALC_EXPR(cx_expr, var_values[CX], vpp->crop_x);
+    CALC_EXPR(cx_expr, var_values[CX], vpp->crop_x, (var_values[VAR_IW] - var_values[VAR_OW]) / 2);
 
     if ((vpp->crop_w != var_values[VAR_IW]) || (vpp->crop_h != var_values[VAR_IH]))
         vpp->use_crop = 1;