update enable trellis quant control flag

Change-Id: I2e2a3bc2045138fbe36c0324b9d4dd55bc48ece6
diff --git a/aom/aom_encoder.h b/aom/aom_encoder.h
index 8b845ea..33326ff 100644
--- a/aom/aom_encoder.h
+++ b/aom/aom_encoder.h
@@ -341,7 +341,7 @@
   /*!\brief enable trellis quantization
    *
    */
-  unsigned int disable_trellis_quant;
+  unsigned int enable_trellis_quant;
   /*!\brief enable ref frame MV
    *
    */
diff --git a/aom/aomcx.h b/aom/aomcx.h
index 32bea52..308578a 100644
--- a/aom/aomcx.h
+++ b/aom/aomcx.h
@@ -644,15 +644,15 @@
    */
   AV1E_SET_ENABLE_OBMC = 61,
 
-  /*!\brief Codec control function to encode without trellis quantization,
+  /*!\brief Codec control function to enable trellis quantization,
    * unsigned int parameter
    *
-   * - 0 = apply trellis quantization (default)
-   * - 1 = do not apply trellis quantization
-   * - 2 = disable trellis quantization in rd search
-   * - 3 = disable trellis quantization in estimate yrd
+   * - 0 = do not apply trellis quantization
+   * - 1 = apply trellis quantization in all stages
+   * - 2 = apply trellis quantization in only the final encode pass
+   * - 3 = disable trellis quantization in estimate_yrd_for_sb
    */
-  AV1E_SET_DISABLE_TRELLIS_QUANT = 62,
+  AV1E_SET_ENABLE_TRELLIS_QUANT = 62,
 
   /*!\brief Codec control function to encode with quantisation matrices,
    * unsigned int parameter
@@ -1522,8 +1522,8 @@
 AOM_CTRL_USE_TYPE(AV1E_SET_ENABLE_OBMC, unsigned int)
 #define AOM_CTRL_AV1E_SET_ENABLE_OBMC
 
-AOM_CTRL_USE_TYPE(AV1E_SET_DISABLE_TRELLIS_QUANT, unsigned int)
-#define AOM_CTRL_AV1E_SET_DISABLE_TRELLIS_QUANT
+AOM_CTRL_USE_TYPE(AV1E_SET_ENABLE_TRELLIS_QUANT, unsigned int)
+#define AOM_CTRL_AV1E_SET_ENABLE_TRELLIS_QUANT
 
 AOM_CTRL_USE_TYPE(AV1E_SET_ENABLE_QM, unsigned int)
 #define AOM_CTRL_AV1E_SET_ENABLE_QM
diff --git a/aom/src/aom_encoder.c b/aom/src/aom_encoder.c
index a998fbd..f3c7c08 100644
--- a/aom/src/aom_encoder.c
+++ b/aom/src/aom_encoder.c
@@ -94,7 +94,7 @@
     cfg->encoder_cfg.superblock_size = 0;  // Dynamic
     cfg->encoder_cfg.max_partition_size = 128;
     cfg->encoder_cfg.min_partition_size = 4;
-    cfg->encoder_cfg.disable_trellis_quant = 3;
+    cfg->encoder_cfg.enable_trellis_quant = 3;
   }
   return res;
 }
diff --git a/apps/aomenc.c b/apps/aomenc.c
index 845f74d..489c55f 100644
--- a/apps/aomenc.c
+++ b/apps/aomenc.c
@@ -573,11 +573,12 @@
 static const arg_def_t enable_angle_delta =
     ARG_DEF(NULL, "enable-angle-delta", 1,
             "Enable intra angle delta (0: false, 1: true (default))");
-static const arg_def_t disable_trellis_quant =
-    ARG_DEF(NULL, "disable-trellis-quant", 1,
-            "Disable trellis optimization of quantized coefficients (0: false "
-            "1: true  2: true for rd search 3: true for estimate yrd serch "
-            "(default))");
+static const arg_def_t enable_trellis_quant =
+    ARG_DEF(NULL, "enable-trellis-quant", 1,
+            "Enable trellis optimization of quantized coefficients "
+            "(0: no trellis, 1: enable trellis for all encoding stages, "
+            "2: enable trellis only in the last encoding pass, 3: disable "
+            "trellis in estimate_yrd_for_sb (default))");
 static const arg_def_t enable_qm =
     ARG_DEF(NULL, "enable-qm", 1,
             "Enable quantisation matrices (0: false (default), 1: true)");
@@ -906,7 +907,7 @@
                                        &enable_palette,
                                        &enable_intrabc,
                                        &enable_angle_delta,
-                                       &disable_trellis_quant,
+                                       &enable_trellis_quant,
                                        &enable_qm,
                                        &qm_min,
                                        &qm_max,
@@ -1013,7 +1014,7 @@
                                         AV1E_SET_ENABLE_PALETTE,
                                         AV1E_SET_ENABLE_INTRABC,
                                         AV1E_SET_ENABLE_ANGLE_DELTA,
-                                        AV1E_SET_DISABLE_TRELLIS_QUANT,
+                                        AV1E_SET_ENABLE_TRELLIS_QUANT,
                                         AV1E_SET_ENABLE_QM,
                                         AV1E_SET_QM_MIN,
                                         AV1E_SET_QM_MAX,
@@ -1183,7 +1184,7 @@
   config->superblock_size = 0;  // Dynamic
   config->max_partition_size = 128;
   config->min_partition_size = 4;
-  config->disable_trellis_quant = 3;
+  config->enable_trellis_quant = 3;
 }
 
 /* Parses global config arguments into the AvxEncoderConfig. Note that
@@ -1863,7 +1864,7 @@
   fprintf(stdout, "\nEncoder speed setting          : %d (cpu-used)\n",
           cpu_used);
   fprintf(stdout, "Trellis quantization           : %d\n",
-          !encoder_cfg->disable_trellis_quant);
+          encoder_cfg->enable_trellis_quant);
   fprintf(stdout, "Reduced reference frame set    : %d\n",
           encoder_cfg->enable_reduced_reference_set);
   fprintf(stdout, "Reduced transform set          : %d\n",
diff --git a/av1/av1_cx_iface.c b/av1/av1_cx_iface.c
index 973b105..b9c71e9 100644
--- a/av1/av1_cx_iface.c
+++ b/av1/av1_cx_iface.c
@@ -64,7 +64,7 @@
   unsigned int enable_restoration;
   unsigned int force_video_mode;
   unsigned int enable_obmc;
-  unsigned int disable_trellis_quant;
+  unsigned int enable_trellis_quant;
   unsigned int enable_qm;
   unsigned int qm_y;
   unsigned int qm_u;
@@ -304,7 +304,7 @@
   1,                                         // enable_restoration
   0,                                         // force_video_mode
   1,                                         // enable_obmc
-  3,                                         // disable_trellis_quant
+  3,                                         // enable_trellis_quant
   0,                                         // enable_qm
   DEFAULT_QM_Y,                              // qm_y
   DEFAULT_QM_U,                              // qm_u
@@ -656,7 +656,7 @@
   RANGE_CHECK_HI(extra_cfg, chroma_subsampling_x, 1);
   RANGE_CHECK_HI(extra_cfg, chroma_subsampling_y, 1);
 
-  RANGE_CHECK_HI(extra_cfg, disable_trellis_quant, 3);
+  RANGE_CHECK_HI(extra_cfg, enable_trellis_quant, 3);
   RANGE_CHECK(extra_cfg, coeff_cost_upd_freq, 0, 2);
   RANGE_CHECK(extra_cfg, mode_cost_upd_freq, 0, 2);
   RANGE_CHECK(extra_cfg, mv_cost_upd_freq, 0, 3);
@@ -772,7 +772,7 @@
   cfg->enable_obmc = extra_cfg->enable_obmc;
   cfg->enable_palette = extra_cfg->enable_palette;
   cfg->enable_intrabc = extra_cfg->enable_intrabc;
-  cfg->disable_trellis_quant = extra_cfg->disable_trellis_quant;
+  cfg->enable_trellis_quant = extra_cfg->enable_trellis_quant;
   cfg->enable_ref_frame_mvs =
       (extra_cfg->allow_ref_frame_mvs || extra_cfg->enable_ref_frame_mvs);
   cfg->enable_onesided_comp = extra_cfg->enable_onesided_comp;
@@ -820,7 +820,7 @@
   extra_cfg->enable_obmc = cfg->enable_obmc;
   extra_cfg->enable_palette = cfg->enable_palette;
   extra_cfg->enable_intrabc = cfg->enable_intrabc;
-  extra_cfg->disable_trellis_quant = cfg->disable_trellis_quant;
+  extra_cfg->enable_trellis_quant = cfg->enable_trellis_quant;
   extra_cfg->enable_ref_frame_mvs = cfg->enable_ref_frame_mvs;
   extra_cfg->enable_onesided_comp = cfg->enable_onesided_comp;
   extra_cfg->enable_reduced_reference_set = cfg->enable_reduced_reference_set;
@@ -1048,7 +1048,7 @@
 
   // Set encoder algorithm related configuration.
   algo_cfg->enable_overlay = extra_cfg->enable_overlay;
-  algo_cfg->disable_trellis_quant = extra_cfg->disable_trellis_quant;
+  algo_cfg->enable_trellis_quant = extra_cfg->enable_trellis_quant;
   algo_cfg->sharpness = extra_cfg->sharpness;
   algo_cfg->arnr_max_frames = extra_cfg->arnr_max_frames;
   algo_cfg->arnr_strength = extra_cfg->arnr_strength;
@@ -1516,10 +1516,10 @@
   return update_extra_cfg(ctx, &extra_cfg);
 }
 
-static aom_codec_err_t ctrl_set_disable_trellis_quant(aom_codec_alg_priv_t *ctx,
-                                                      va_list args) {
+static aom_codec_err_t ctrl_set_enable_trellis_quant(aom_codec_alg_priv_t *ctx,
+                                                     va_list args) {
   struct av1_extracfg extra_cfg = ctx->extra_cfg;
-  extra_cfg.disable_trellis_quant = CAST(AV1E_SET_DISABLE_TRELLIS_QUANT, args);
+  extra_cfg.enable_trellis_quant = CAST(AV1E_SET_ENABLE_TRELLIS_QUANT, args);
   return update_extra_cfg(ctx, &extra_cfg);
 }
 
@@ -3057,7 +3057,7 @@
   { AV1E_SET_ENABLE_RESTORATION, ctrl_set_enable_restoration },
   { AV1E_SET_FORCE_VIDEO_MODE, ctrl_set_force_video_mode },
   { AV1E_SET_ENABLE_OBMC, ctrl_set_enable_obmc },
-  { AV1E_SET_DISABLE_TRELLIS_QUANT, ctrl_set_disable_trellis_quant },
+  { AV1E_SET_ENABLE_TRELLIS_QUANT, ctrl_set_enable_trellis_quant },
   { AV1E_SET_ENABLE_QM, ctrl_set_enable_qm },
   { AV1E_SET_QM_Y, ctrl_set_qm_y },
   { AV1E_SET_QM_U, ctrl_set_qm_u },
@@ -3242,7 +3242,7 @@
 #if !CONFIG_REMOVE_DUAL_FILTER
         1,
 #endif                                          // !CONFIG_REMOVE_DUAL_FILTER
-        1, 1,   1,   1, 1, 1, 1, 1, 1, 1, 0 },  // cfg
+        1, 1,   1,   1, 1, 1, 1, 3, 1, 1, 0 },  // cfg
   },
   {
       // NOLINT
@@ -3317,7 +3317,7 @@
 #if !CONFIG_REMOVE_DUAL_FILTER
         1,
 #endif                                          // !CONFIG_REMOVE_DUAL_FILTER
-        1, 1,   1,   1, 1, 1, 1, 1, 1, 1, 0 },  // cfg
+        1, 1,   1,   1, 1, 1, 1, 3, 1, 1, 0 },  // cfg
   },
 };
 
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index 8f280b7..3807fcb 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -713,11 +713,11 @@
   /*!
    * Indicates the trellis optimization mode of quantized coefficients.
    * 0: disabled
-   * 1: enabled
-   * 2: enabled for rd search
-   * 3: true for estimate yrd search
+   * 1: enabled for all stages
+   * 2: enabled only for the last encoding pass
+   * 3: disable trellis for estimate_yrd_for_sb
    */
-  int disable_trellis_quant;
+  int enable_trellis_quant;
 
   /*!
    * The maximum number of frames used to create an arf.
diff --git a/av1/encoder/speed_features.c b/av1/encoder/speed_features.c
index abaf2b7..6a542cb 100644
--- a/av1/encoder/speed_features.c
+++ b/av1/encoder/speed_features.c
@@ -1156,25 +1156,25 @@
 
 static AOM_INLINE void init_rd_sf(RD_CALC_SPEED_FEATURES *rd_sf,
                                   const AV1EncoderConfig *oxcf) {
-  const int disable_trellis_quant = oxcf->algo_cfg.disable_trellis_quant;
-  if (disable_trellis_quant == 3) {
+  const int enable_trellis_quant = oxcf->algo_cfg.enable_trellis_quant;
+  if (enable_trellis_quant == 3) {
     rd_sf->optimize_coefficients = !is_lossless_requested(&oxcf->rc_cfg)
                                        ? NO_ESTIMATE_YRD_TRELLIS_OPT
                                        : NO_TRELLIS_OPT;
-  } else if (disable_trellis_quant == 2) {
+  } else if (enable_trellis_quant == 2) {
     rd_sf->optimize_coefficients = !is_lossless_requested(&oxcf->rc_cfg)
                                        ? FINAL_PASS_TRELLIS_OPT
                                        : NO_TRELLIS_OPT;
-  } else if (disable_trellis_quant == 0) {
+  } else if (enable_trellis_quant == 1) {
     if (is_lossless_requested(&oxcf->rc_cfg)) {
       rd_sf->optimize_coefficients = NO_TRELLIS_OPT;
     } else {
       rd_sf->optimize_coefficients = FULL_TRELLIS_OPT;
     }
-  } else if (disable_trellis_quant == 1) {
+  } else if (enable_trellis_quant == 0) {
     rd_sf->optimize_coefficients = NO_TRELLIS_OPT;
   } else {
-    assert(0 && "Invalid disable_trellis_quant value");
+    assert(0 && "Invalid enable_trellis_quant value");
   }
   rd_sf->use_mb_rd_hash = 1;
   rd_sf->simple_model_rd_from_var = 0;
diff --git a/common/args.c b/common/args.c
index 0ba7ebc..22a7688 100644
--- a/common/args.c
+++ b/common/args.c
@@ -121,7 +121,7 @@
     GET_PARAMS(enable_interinter_wedge);
     GET_PARAMS(enable_interintra_wedge);
     GET_PARAMS(enable_paeth_intra);
-    GET_PARAMS(disable_trellis_quant);
+    GET_PARAMS(enable_trellis_quant);
     GET_PARAMS(enable_ref_frame_mvs);
     GET_PARAMS(enable_reduced_reference_set);
     GET_PARAMS(reduced_tx_type_set);