aom: rtc: Extract some speed features used in screen

From 62732c87b889f20bc60b99c5675f7c2cc9ccdef1 Mon Sep 17 00:00:00 2001
From: Marco Paniconi <[EMAIL REDACTED]>
Date: Tue, 30 Apr 2024 15:24:49 -0700
Subject: [PATCH] rtc: Extract some speed features used in screen

Extract some features used for screen and add
speed features for them: newmv skip for flat blocks,
usage of idtx, and the min_thresh for scene detection.
This is to allow for better control for content with
mixed screen and video; also some of these may be used
for non-screen input.

No change in behavior.

Change-Id: I29307032a283d19f8899d980baa61a7d9b0748a4
---
 av1/encoder/nonrd_pickmode.c | 10 ++++++----
 av1/encoder/ratectrl.c       |  2 +-
 av1/encoder/speed_features.c |  6 ++++++
 av1/encoder/speed_features.h | 16 ++++++++++++----
 4 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/av1/encoder/nonrd_pickmode.c b/av1/encoder/nonrd_pickmode.c
index 08ecb8495..dcaf13f1d 100644
--- a/av1/encoder/nonrd_pickmode.c
+++ b/av1/encoder/nonrd_pickmode.c
@@ -2469,7 +2469,9 @@ static AOM_FORCE_INLINE bool skip_inter_mode_nonrd(
         return true;
     }
     // Skip NEWMV search for flat blocks.
-    if (*this_mode == NEWMV && x->source_variance < 100) return true;
+    if (rt_sf->skip_newmv_flat_blocks_screen && *this_mode == NEWMV &&
+        x->source_variance < 100)
+      return true;
     // Skip non-LAST for color on flat blocks.
     if (*ref_frame > LAST_FRAME && x->source_variance == 0 &&
         (x->color_sensitivity[COLOR_SENS_IDX(AOM_PLANE_U)] == 1 ||
@@ -2960,9 +2962,9 @@ static AOM_FORCE_INLINE void handle_screen_content_mode_nonrd(
 
   // TODO(marpan): Only allow for 8 bit-depth for now, re-enable for 10/12 bit
   // when issue 3359 is fixed.
-  if (cm->seq_params->bit_depth == 8 &&
-      cpi->oxcf.tune_cfg.content == AOM_CONTENT_SCREEN && !skip_idtx_palette &&
-      !cpi->oxcf.txfm_cfg.use_inter_dct_only && !x->force_zeromv_skip_for_blk &&
+  if (cm->seq_params->bit_depth == 8 && rt_sf->use_idtx_nonrd &&
+      !skip_idtx_palette && !cpi->oxcf.txfm_cfg.use_inter_dct_only &&
+      !x->force_zeromv_skip_for_blk &&
       is_inter_mode(best_pickmode->best_mode) &&
       best_pickmode->best_pred != NULL &&
       (!rt_sf->prune_idtx_nonrd ||
diff --git a/av1/encoder/ratectrl.c b/av1/encoder/ratectrl.c
index 7639484df..9daeb45c8 100644
--- a/av1/encoder/ratectrl.c
+++ b/av1/encoder/ratectrl.c
@@ -3073,7 +3073,7 @@ static void rc_scene_detection_onepass_rt(AV1_COMP *cpi,
   }
   int num_zero_temp_sad = 0;
   uint32_t min_thresh = 10000;
-  if (cpi->oxcf.tune_cfg.content != AOM_CONTENT_SCREEN) {
+  if (cpi->sf.rt_sf.higher_thresh_scene_detection) {
     min_thresh = cm->width * cm->height <= 320 * 240 && cpi->framerate < 10.0
                      ? 50000
                      : 100000;
diff --git a/av1/encoder/speed_features.c b/av1/encoder/speed_features.c
index 9a0004252..b0ab7feb3 100644
--- a/av1/encoder/speed_features.c
+++ b/av1/encoder/speed_features.c
@@ -1586,6 +1586,9 @@ static void set_rt_speed_feature_framesize_dependent(const AV1_COMP *const cpi,
       sf->rt_sf.prune_palette_nonrd = 1;
       sf->rt_sf.increase_color_thresh_palette = 0;
     }
+    sf->rt_sf.skip_newmv_flat_blocks_screen = 1;
+    sf->rt_sf.use_idtx_nonrd = 1;
+    sf->rt_sf.higher_thresh_scene_detection = 0;
     sf->rt_sf.use_nonrd_altref_frame = 0;
     sf->rt_sf.use_rtc_tf = 0;
     sf->rt_sf.use_comp_ref_nonrd = 0;
@@ -2270,6 +2273,7 @@ static AOM_INLINE void init_rt_sf(REAL_TIME_SPEED_FEATURES *rt_sf) {
   rt_sf->var_part_split_threshold_shift = 7;
   rt_sf->gf_refresh_based_on_qp = 0;
   rt_sf->use_rtc_tf = 0;
+  rt_sf->use_idtx_nonrd = 0;
   rt_sf->prune_idtx_nonrd = 0;
   rt_sf->prune_palette_nonrd = 0;
   rt_sf->dct_only_palette_nonrd = 0;
@@ -2299,6 +2303,8 @@ static AOM_INLINE void init_rt_sf(REAL_TIME_SPEED_FEATURES *rt_sf) {
   rt_sf->increase_color_thresh_palette = false;
   rt_sf->selective_cdf_update = 0;
   rt_sf->force_only_last_ref = 0;
+  rt_sf->higher_thresh_scene_detection = 1;
+  rt_sf->skip_newmv_flat_blocks_screen = 0;
 }
 
 static fractional_mv_step_fp
diff --git a/av1/encoder/speed_features.h b/av1/encoder/speed_features.h
index d59cb38a7..d6b294927 100644
--- a/av1/encoder/speed_features.h
+++ b/av1/encoder/speed_features.h
@@ -1754,10 +1754,12 @@ typedef struct REAL_TIME_SPEED_FEATURES {
   // Must be off for lossless mode.
   int use_rtc_tf;
 
-  // Prune the use of the identity transform in nonrd_pickmode,
-  // used for screen content mode: only for smaller blocks
-  // and higher spatial variance, and when skip_txfm is not
-  // already set.
+  // Use of the identity transform in nonrd_pickmode,
+  int use_idtx_nonrd;
+
+  // Prune the use of the identity transform in nonrd_pickmode:
+  // only for smaller blocks and higher spatial variance, and when skip_txfm
+  // is not already set.
   int prune_idtx_nonrd;
 
   // Prune the use of paletter mode in nonrd pickmode.
@@ -1902,6 +1904,12 @@ typedef struct REAL_TIME_SPEED_FEATURES {
   // This generally leads to better coding efficiency but with some speed loss.
   // Only used for screen content and for nonrd_pickmode.
   bool increase_color_thresh_palette;
+
+  // Flag to indicate selecting of higher threshold for scenee change detection.
+  int higher_thresh_scene_detection;
+
+  // FLag to indicate skip testing of NEWMV for flat blocks.
+  int skip_newmv_flat_blocks_screen;
 } REAL_TIME_SPEED_FEATURES;
 
 /*!\endcond */