From 968e3de4940eda863c9f7b0404a155e3bda8f2bf Mon Sep 17 00:00:00 2001
From: James Almer <jamrial@gmail.com>
Date: Tue, 29 Nov 2022 18:35:27 -0300
Subject: [PATCH 15/18] avcodec/libsvtav1: don't force a default value for
 deprecated options

Stick to the library's default value instead.

Should address AOMediaCodec/SVT-AV1 issue #2011.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/libsvtav1.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c
index de6e6e813d..91c1252d4c 100644
--- a/libavcodec/libsvtav1.c
+++ b/libavcodec/libsvtav1.c
@@ -154,14 +154,19 @@ static int config_enc_params(EbSvtAv1EncConfiguration *param,
 
     // Update param from options
 #if FF_API_SVTAV1_OPTS
-    param->hierarchical_levels      = svt_enc->hierarchical_level;
-    param->tier                     = svt_enc->tier;
-    param->scene_change_detection   = svt_enc->scd;
-    param->tile_columns             = svt_enc->tile_columns;
-    param->tile_rows                = svt_enc->tile_rows;
+    if (svt_enc->hierarchical_level >= 0)
+        param->hierarchical_levels    = svt_enc->hierarchical_level;
+    if (svt_enc->tier >= 0)
+        param->tier                   = svt_enc->tier;
+    if (svt_enc->scd >= 0)
+        param->scene_change_detection = svt_enc->scd;
+    if (svt_enc->tile_columns >= 0)
+        param->tile_columns           = svt_enc->tile_columns;
+    if (svt_enc->tile_rows >= 0)
+        param->tile_rows              = svt_enc->tile_rows;
 
     if (svt_enc->la_depth >= 0)
-        param->look_ahead_distance  = svt_enc->la_depth;
+        param->look_ahead_distance    = svt_enc->la_depth;
 #endif
 
     if (svt_enc->enc_mode >= 0)
@@ -571,7 +576,7 @@ static av_cold int eb_enc_close(AVCodecContext *avctx)
 static const AVOption options[] = {
 #if FF_API_SVTAV1_OPTS
     { "hielevel", "Hierarchical prediction levels setting (Deprecated, use svtav1-params)", OFFSET(hierarchical_level),
-      AV_OPT_TYPE_INT, { .i64 = 4 }, 3, 4, VE | AV_OPT_FLAG_DEPRECATED , "hielevel"},
+      AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 4, VE | AV_OPT_FLAG_DEPRECATED , "hielevel"},
         { "3level", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 3 },  INT_MIN, INT_MAX, VE, "hielevel" },
         { "4level", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 4 },  INT_MIN, INT_MAX, VE, "hielevel" },
 
@@ -579,7 +584,7 @@ static const AVOption options[] = {
       AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 120, VE | AV_OPT_FLAG_DEPRECATED },
 
     { "tier", "Set operating point tier (Deprecated, use svtav1-params)", OFFSET(tier),
-      AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE | AV_OPT_FLAG_DEPRECATED, "tier" },
+      AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, VE | AV_OPT_FLAG_DEPRECATED, "tier" },
         { "main", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, VE, "tier" },
         { "high", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, VE, "tier" },
 #endif
@@ -622,10 +627,10 @@ static const AVOption options[] = {
       AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 63, VE },
 #if FF_API_SVTAV1_OPTS
     { "sc_detection", "Scene change detection (Deprecated, use svtav1-params)", OFFSET(scd),
-      AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE | AV_OPT_FLAG_DEPRECATED },
+      AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, VE | AV_OPT_FLAG_DEPRECATED },
 
-    { "tile_columns", "Log2 of number of tile columns to use (Deprecated, use svtav1-params)", OFFSET(tile_columns), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 4, VE | AV_OPT_FLAG_DEPRECATED },
-    { "tile_rows", "Log2 of number of tile rows to use (Deprecated, use svtav1-params)", OFFSET(tile_rows), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 6, VE | AV_OPT_FLAG_DEPRECATED },
+    { "tile_columns", "Log2 of number of tile columns to use (Deprecated, use svtav1-params)", OFFSET(tile_columns), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 4, VE | AV_OPT_FLAG_DEPRECATED },
+    { "tile_rows", "Log2 of number of tile rows to use (Deprecated, use svtav1-params)", OFFSET(tile_rows), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 6, VE | AV_OPT_FLAG_DEPRECATED },
 #endif
 
     { "svtav1-params", "Set the SVT-AV1 configuration using a :-separated list of key=value parameters", OFFSET(svtav1_opts), AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE },
-- 
2.40.1

