xref: /aosp_15_r20/external/libaom/av1/encoder/speed_features.c (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker  * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker  *
4*77c1e3ccSAndroid Build Coastguard Worker  * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker  * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker  * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker  */
11*77c1e3ccSAndroid Build Coastguard Worker 
12*77c1e3ccSAndroid Build Coastguard Worker #include <limits.h>
13*77c1e3ccSAndroid Build Coastguard Worker 
14*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/reconintra.h"
15*77c1e3ccSAndroid Build Coastguard Worker 
16*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/encoder.h"
17*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/speed_features.h"
18*77c1e3ccSAndroid Build Coastguard Worker #include "av1/encoder/rdopt.h"
19*77c1e3ccSAndroid Build Coastguard Worker 
20*77c1e3ccSAndroid Build Coastguard Worker #include "aom_dsp/aom_dsp_common.h"
21*77c1e3ccSAndroid Build Coastguard Worker 
22*77c1e3ccSAndroid Build Coastguard Worker #define MAX_MESH_SPEED 5  // Max speed setting for mesh motion method
23*77c1e3ccSAndroid Build Coastguard Worker // Max speed setting for tx domain evaluation
24*77c1e3ccSAndroid Build Coastguard Worker #define MAX_TX_DOMAIN_EVAL_SPEED 5
25*77c1e3ccSAndroid Build Coastguard Worker static MESH_PATTERN
26*77c1e3ccSAndroid Build Coastguard Worker     good_quality_mesh_patterns[MAX_MESH_SPEED + 1][MAX_MESH_STEP] = {
27*77c1e3ccSAndroid Build Coastguard Worker       { { 64, 8 }, { 28, 4 }, { 15, 1 }, { 7, 1 } },
28*77c1e3ccSAndroid Build Coastguard Worker       { { 64, 8 }, { 28, 4 }, { 15, 1 }, { 7, 1 } },
29*77c1e3ccSAndroid Build Coastguard Worker       { { 64, 8 }, { 14, 2 }, { 7, 1 }, { 7, 1 } },
30*77c1e3ccSAndroid Build Coastguard Worker       { { 64, 16 }, { 24, 8 }, { 12, 4 }, { 7, 1 } },
31*77c1e3ccSAndroid Build Coastguard Worker       { { 64, 16 }, { 24, 8 }, { 12, 4 }, { 7, 1 } },
32*77c1e3ccSAndroid Build Coastguard Worker       { { 64, 16 }, { 24, 8 }, { 12, 4 }, { 7, 1 } },
33*77c1e3ccSAndroid Build Coastguard Worker     };
34*77c1e3ccSAndroid Build Coastguard Worker 
35*77c1e3ccSAndroid Build Coastguard Worker // TODO([email protected]): These settings are pretty relaxed, tune them for
36*77c1e3ccSAndroid Build Coastguard Worker // each speed setting
37*77c1e3ccSAndroid Build Coastguard Worker static MESH_PATTERN intrabc_mesh_patterns[MAX_MESH_SPEED + 1][MAX_MESH_STEP] = {
38*77c1e3ccSAndroid Build Coastguard Worker   { { 256, 1 }, { 256, 1 }, { 0, 0 }, { 0, 0 } },
39*77c1e3ccSAndroid Build Coastguard Worker   { { 256, 1 }, { 256, 1 }, { 0, 0 }, { 0, 0 } },
40*77c1e3ccSAndroid Build Coastguard Worker   { { 64, 1 }, { 64, 1 }, { 0, 0 }, { 0, 0 } },
41*77c1e3ccSAndroid Build Coastguard Worker   { { 64, 1 }, { 64, 1 }, { 0, 0 }, { 0, 0 } },
42*77c1e3ccSAndroid Build Coastguard Worker   { { 64, 4 }, { 16, 1 }, { 0, 0 }, { 0, 0 } },
43*77c1e3ccSAndroid Build Coastguard Worker   { { 64, 4 }, { 16, 1 }, { 0, 0 }, { 0, 0 } },
44*77c1e3ccSAndroid Build Coastguard Worker };
45*77c1e3ccSAndroid Build Coastguard Worker 
46*77c1e3ccSAndroid Build Coastguard Worker // Threshold values to be used for pruning the txfm_domain_distortion
47*77c1e3ccSAndroid Build Coastguard Worker // based on block MSE
48*77c1e3ccSAndroid Build Coastguard Worker // Index 0: Default mode evaluation, Winner mode processing is not
49*77c1e3ccSAndroid Build Coastguard Worker // applicable (Eg : IntraBc). Index 1: Mode evaluation.
50*77c1e3ccSAndroid Build Coastguard Worker // Index 2: Winner mode evaluation. Index 1 and 2 are applicable when
51*77c1e3ccSAndroid Build Coastguard Worker // enable_winner_mode_for_use_tx_domain_dist speed feature is ON
52*77c1e3ccSAndroid Build Coastguard Worker // TODO(any): Experiment the threshold logic based on variance metric
53*77c1e3ccSAndroid Build Coastguard Worker static unsigned int tx_domain_dist_thresholds[4][MODE_EVAL_TYPES] = {
54*77c1e3ccSAndroid Build Coastguard Worker   { UINT_MAX, UINT_MAX, UINT_MAX },
55*77c1e3ccSAndroid Build Coastguard Worker   { 22026, 22026, 22026 },
56*77c1e3ccSAndroid Build Coastguard Worker   { 1377, 1377, 1377 },
57*77c1e3ccSAndroid Build Coastguard Worker   { 0, 0, 0 }
58*77c1e3ccSAndroid Build Coastguard Worker };
59*77c1e3ccSAndroid Build Coastguard Worker 
60*77c1e3ccSAndroid Build Coastguard Worker // Number of different levels of aggressiveness in using transform domain
61*77c1e3ccSAndroid Build Coastguard Worker // distortion during the R-D evaluation based on the speed feature
62*77c1e3ccSAndroid Build Coastguard Worker // tx_domain_dist_level.
63*77c1e3ccSAndroid Build Coastguard Worker #define TX_DOMAIN_DIST_LEVELS 4
64*77c1e3ccSAndroid Build Coastguard Worker 
65*77c1e3ccSAndroid Build Coastguard Worker // Transform domain distortion type to be used for default, mode and winner mode
66*77c1e3ccSAndroid Build Coastguard Worker // evaluation Index 0: Default mode evaluation, Winner mode processing is not
67*77c1e3ccSAndroid Build Coastguard Worker // applicable (Eg : IntraBc). Index 1: Mode evaluation. Index 2: Winner mode
68*77c1e3ccSAndroid Build Coastguard Worker // evaluation. Index 1 and 2 are applicable when
69*77c1e3ccSAndroid Build Coastguard Worker // enable_winner_mode_for_use_tx_domain_dist speed feature is ON
70*77c1e3ccSAndroid Build Coastguard Worker static unsigned int
71*77c1e3ccSAndroid Build Coastguard Worker     tx_domain_dist_types[TX_DOMAIN_DIST_LEVELS][MODE_EVAL_TYPES] = {
72*77c1e3ccSAndroid Build Coastguard Worker       { 0, 2, 0 }, { 1, 2, 0 }, { 2, 2, 0 }, { 2, 2, 2 }
73*77c1e3ccSAndroid Build Coastguard Worker     };
74*77c1e3ccSAndroid Build Coastguard Worker 
75*77c1e3ccSAndroid Build Coastguard Worker // Threshold values to be used for disabling coeff RD-optimization
76*77c1e3ccSAndroid Build Coastguard Worker // based on block MSE / qstep^2.
77*77c1e3ccSAndroid Build Coastguard Worker // TODO(any): Experiment the threshold logic based on variance metric.
78*77c1e3ccSAndroid Build Coastguard Worker // Table has satd and dist threshold value index 0 : dist,index 1: satd
79*77c1e3ccSAndroid Build Coastguard Worker // For each row, the indices are as follows.
80*77c1e3ccSAndroid Build Coastguard Worker // Index 0: Default mode evaluation, Winner mode processing is not applicable
81*77c1e3ccSAndroid Build Coastguard Worker // (Eg : IntraBc)
82*77c1e3ccSAndroid Build Coastguard Worker // Index 1: Mode evaluation.
83*77c1e3ccSAndroid Build Coastguard Worker // Index 2: Winner mode evaluation.
84*77c1e3ccSAndroid Build Coastguard Worker // Index 1 and 2 are applicable when enable_winner_mode_for_coeff_opt speed
85*77c1e3ccSAndroid Build Coastguard Worker // feature is ON
86*77c1e3ccSAndroid Build Coastguard Worker // There are 7 levels with increasing speed, mapping to vertical indices.
87*77c1e3ccSAndroid Build Coastguard Worker static unsigned int coeff_opt_thresholds[9][MODE_EVAL_TYPES][2] = {
88*77c1e3ccSAndroid Build Coastguard Worker   { { UINT_MAX, UINT_MAX }, { UINT_MAX, UINT_MAX }, { UINT_MAX, UINT_MAX } },
89*77c1e3ccSAndroid Build Coastguard Worker   { { 3200, UINT_MAX }, { 250, UINT_MAX }, { UINT_MAX, UINT_MAX } },
90*77c1e3ccSAndroid Build Coastguard Worker   { { 1728, UINT_MAX }, { 142, UINT_MAX }, { UINT_MAX, UINT_MAX } },
91*77c1e3ccSAndroid Build Coastguard Worker   { { 864, UINT_MAX }, { 142, UINT_MAX }, { UINT_MAX, UINT_MAX } },
92*77c1e3ccSAndroid Build Coastguard Worker   { { 432, UINT_MAX }, { 86, UINT_MAX }, { UINT_MAX, UINT_MAX } },
93*77c1e3ccSAndroid Build Coastguard Worker   { { 864, 97 }, { 142, 16 }, { UINT_MAX, UINT_MAX } },
94*77c1e3ccSAndroid Build Coastguard Worker   { { 432, 97 }, { 86, 16 }, { UINT_MAX, UINT_MAX } },
95*77c1e3ccSAndroid Build Coastguard Worker   { { 216, 25 }, { 86, 10 }, { UINT_MAX, UINT_MAX } },
96*77c1e3ccSAndroid Build Coastguard Worker   { { 216, 25 }, { 0, 10 }, { UINT_MAX, UINT_MAX } }
97*77c1e3ccSAndroid Build Coastguard Worker };
98*77c1e3ccSAndroid Build Coastguard Worker 
99*77c1e3ccSAndroid Build Coastguard Worker // Transform size to be used for default, mode and winner mode evaluation
100*77c1e3ccSAndroid Build Coastguard Worker // Index 0: Default mode evaluation, Winner mode processing is not applicable
101*77c1e3ccSAndroid Build Coastguard Worker // (Eg : IntraBc) Index 1: Mode evaluation. Index 2: Winner mode evaluation.
102*77c1e3ccSAndroid Build Coastguard Worker // Index 1 and 2 are applicable when enable_winner_mode_for_tx_size_srch speed
103*77c1e3ccSAndroid Build Coastguard Worker // feature is ON
104*77c1e3ccSAndroid Build Coastguard Worker static TX_SIZE_SEARCH_METHOD tx_size_search_methods[4][MODE_EVAL_TYPES] = {
105*77c1e3ccSAndroid Build Coastguard Worker   { USE_FULL_RD, USE_LARGESTALL, USE_FULL_RD },
106*77c1e3ccSAndroid Build Coastguard Worker   { USE_FAST_RD, USE_LARGESTALL, USE_FULL_RD },
107*77c1e3ccSAndroid Build Coastguard Worker   { USE_LARGESTALL, USE_LARGESTALL, USE_FULL_RD },
108*77c1e3ccSAndroid Build Coastguard Worker   { USE_LARGESTALL, USE_LARGESTALL, USE_LARGESTALL }
109*77c1e3ccSAndroid Build Coastguard Worker };
110*77c1e3ccSAndroid Build Coastguard Worker 
111*77c1e3ccSAndroid Build Coastguard Worker // Predict transform skip levels to be used for default, mode and winner mode
112*77c1e3ccSAndroid Build Coastguard Worker // evaluation. Index 0: Default mode evaluation, Winner mode processing is not
113*77c1e3ccSAndroid Build Coastguard Worker // applicable. Index 1: Mode evaluation, Index 2: Winner mode evaluation
114*77c1e3ccSAndroid Build Coastguard Worker // Values indicate the aggressiveness of skip flag prediction.
115*77c1e3ccSAndroid Build Coastguard Worker // 0 : no early skip prediction
116*77c1e3ccSAndroid Build Coastguard Worker // 1 : conservative early skip prediction using DCT_DCT
117*77c1e3ccSAndroid Build Coastguard Worker // 2 : early skip prediction based on SSE
118*77c1e3ccSAndroid Build Coastguard Worker static unsigned int predict_skip_levels[3][MODE_EVAL_TYPES] = { { 0, 0, 0 },
119*77c1e3ccSAndroid Build Coastguard Worker                                                                 { 1, 1, 1 },
120*77c1e3ccSAndroid Build Coastguard Worker                                                                 { 1, 2, 1 } };
121*77c1e3ccSAndroid Build Coastguard Worker 
122*77c1e3ccSAndroid Build Coastguard Worker // Predict skip or DC block level used during transform type search. It is
123*77c1e3ccSAndroid Build Coastguard Worker // indexed using the following:
124*77c1e3ccSAndroid Build Coastguard Worker // First index  : Speed feature 'dc_blk_pred_level' (0 to 3)
125*77c1e3ccSAndroid Build Coastguard Worker // Second index : Mode evaluation type (DEFAULT_EVAL, MODE_EVAL and
126*77c1e3ccSAndroid Build Coastguard Worker // WINNER_MODE_EVAL).
127*77c1e3ccSAndroid Build Coastguard Worker //
128*77c1e3ccSAndroid Build Coastguard Worker // The values of predict_dc_levels[][] indicate the aggressiveness of predicting
129*77c1e3ccSAndroid Build Coastguard Worker // a block as transform skip or DC only.
130*77c1e3ccSAndroid Build Coastguard Worker // Type 0 : No skip block or DC only block prediction
131*77c1e3ccSAndroid Build Coastguard Worker // Type 1 : Prediction of skip block based on residual mean and variance
132*77c1e3ccSAndroid Build Coastguard Worker // Type 2 : Prediction of skip block or DC only block based on residual mean and
133*77c1e3ccSAndroid Build Coastguard Worker // variance
134*77c1e3ccSAndroid Build Coastguard Worker static unsigned int predict_dc_levels[4][MODE_EVAL_TYPES] = {
135*77c1e3ccSAndroid Build Coastguard Worker   { 0, 0, 0 }, { 1, 1, 0 }, { 2, 2, 0 }, { 2, 2, 2 }
136*77c1e3ccSAndroid Build Coastguard Worker };
137*77c1e3ccSAndroid Build Coastguard Worker 
138*77c1e3ccSAndroid Build Coastguard Worker #if !CONFIG_FPMT_TEST
139*77c1e3ccSAndroid Build Coastguard Worker // This table holds the maximum number of reference frames for global motion.
140*77c1e3ccSAndroid Build Coastguard Worker // The table is indexed as per the speed feature 'gm_search_type'.
141*77c1e3ccSAndroid Build Coastguard Worker // 0 : All reference frames are allowed.
142*77c1e3ccSAndroid Build Coastguard Worker // 1 : All reference frames except L2 and L3 are allowed.
143*77c1e3ccSAndroid Build Coastguard Worker // 2 : All reference frames except L2, L3 and ARF2 are allowed.
144*77c1e3ccSAndroid Build Coastguard Worker // 3 : No reference frame is allowed.
145*77c1e3ccSAndroid Build Coastguard Worker static int gm_available_reference_frames[GM_DISABLE_SEARCH + 1] = {
146*77c1e3ccSAndroid Build Coastguard Worker   INTER_REFS_PER_FRAME, INTER_REFS_PER_FRAME - 2, INTER_REFS_PER_FRAME - 3, 0
147*77c1e3ccSAndroid Build Coastguard Worker };
148*77c1e3ccSAndroid Build Coastguard Worker #endif
149*77c1e3ccSAndroid Build Coastguard Worker 
150*77c1e3ccSAndroid Build Coastguard Worker // Qindex threshold levels used for selecting full-pel motion search.
151*77c1e3ccSAndroid Build Coastguard Worker // ms_qthresh[i][j][k] indicates the qindex boundary value for 'k'th qindex band
152*77c1e3ccSAndroid Build Coastguard Worker // for resolution index 'j' for aggressiveness level 'i'.
153*77c1e3ccSAndroid Build Coastguard Worker // Aggressiveness increases from i = 0 to 2.
154*77c1e3ccSAndroid Build Coastguard Worker // j = 0: lower than 720p resolution, j = 1: 720p or larger resolution.
155*77c1e3ccSAndroid Build Coastguard Worker // Currently invoked only for speed 0, 1 and 2.
156*77c1e3ccSAndroid Build Coastguard Worker static int ms_qindex_thresh[3][2][2] = { { { 200, 70 }, { MAXQ, 200 } },
157*77c1e3ccSAndroid Build Coastguard Worker                                          { { 170, 50 }, { MAXQ, 200 } },
158*77c1e3ccSAndroid Build Coastguard Worker                                          { { 170, 40 }, { 200, 40 } } };
159*77c1e3ccSAndroid Build Coastguard Worker 
160*77c1e3ccSAndroid Build Coastguard Worker // Full-pel search methods for aggressive search based on qindex.
161*77c1e3ccSAndroid Build Coastguard Worker // Index 0 is for resolutions lower than 720p, index 1 for 720p or larger
162*77c1e3ccSAndroid Build Coastguard Worker // resolutions. Currently invoked only for speed 1 and 2.
163*77c1e3ccSAndroid Build Coastguard Worker static SEARCH_METHODS motion_search_method[2] = { CLAMPED_DIAMOND, DIAMOND };
164*77c1e3ccSAndroid Build Coastguard Worker 
165*77c1e3ccSAndroid Build Coastguard Worker // Intra only frames, golden frames (except alt ref overlays) and
166*77c1e3ccSAndroid Build Coastguard Worker // alt ref frames tend to be coded at a higher than ambient quality
frame_is_boosted(const AV1_COMP * cpi)167*77c1e3ccSAndroid Build Coastguard Worker static int frame_is_boosted(const AV1_COMP *cpi) {
168*77c1e3ccSAndroid Build Coastguard Worker   return frame_is_kf_gf_arf(cpi);
169*77c1e3ccSAndroid Build Coastguard Worker }
170*77c1e3ccSAndroid Build Coastguard Worker 
171*77c1e3ccSAndroid Build Coastguard Worker // Set transform rd gate level for all transform search cases.
set_txfm_rd_gate_level(int txfm_rd_gate_level[TX_SEARCH_CASES],int level)172*77c1e3ccSAndroid Build Coastguard Worker static inline void set_txfm_rd_gate_level(
173*77c1e3ccSAndroid Build Coastguard Worker     int txfm_rd_gate_level[TX_SEARCH_CASES], int level) {
174*77c1e3ccSAndroid Build Coastguard Worker   assert(level <= MAX_TX_RD_GATE_LEVEL);
175*77c1e3ccSAndroid Build Coastguard Worker   for (int idx = 0; idx < TX_SEARCH_CASES; idx++)
176*77c1e3ccSAndroid Build Coastguard Worker     txfm_rd_gate_level[idx] = level;
177*77c1e3ccSAndroid Build Coastguard Worker }
178*77c1e3ccSAndroid Build Coastguard Worker 
set_allintra_speed_feature_framesize_dependent(const AV1_COMP * const cpi,SPEED_FEATURES * const sf,int speed)179*77c1e3ccSAndroid Build Coastguard Worker static void set_allintra_speed_feature_framesize_dependent(
180*77c1e3ccSAndroid Build Coastguard Worker     const AV1_COMP *const cpi, SPEED_FEATURES *const sf, int speed) {
181*77c1e3ccSAndroid Build Coastguard Worker   const AV1_COMMON *const cm = &cpi->common;
182*77c1e3ccSAndroid Build Coastguard Worker   const int is_480p_or_larger = AOMMIN(cm->width, cm->height) >= 480;
183*77c1e3ccSAndroid Build Coastguard Worker   const int is_720p_or_larger = AOMMIN(cm->width, cm->height) >= 720;
184*77c1e3ccSAndroid Build Coastguard Worker   const int is_1080p_or_larger = AOMMIN(cm->width, cm->height) >= 1080;
185*77c1e3ccSAndroid Build Coastguard Worker   const int is_4k_or_larger = AOMMIN(cm->width, cm->height) >= 2160;
186*77c1e3ccSAndroid Build Coastguard Worker   const bool use_hbd = cpi->oxcf.use_highbitdepth;
187*77c1e3ccSAndroid Build Coastguard Worker 
188*77c1e3ccSAndroid Build Coastguard Worker   if (is_480p_or_larger) {
189*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.use_square_partition_only_threshold = BLOCK_128X128;
190*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger)
191*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.auto_max_partition_based_on_simple_motion = ADAPT_PRED;
192*77c1e3ccSAndroid Build Coastguard Worker     else
193*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.auto_max_partition_based_on_simple_motion = RELAXED_PRED;
194*77c1e3ccSAndroid Build Coastguard Worker   } else {
195*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.use_square_partition_only_threshold = BLOCK_64X64;
196*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.auto_max_partition_based_on_simple_motion = DIRECT_PRED;
197*77c1e3ccSAndroid Build Coastguard Worker     if (use_hbd) sf->tx_sf.prune_tx_size_level = 1;
198*77c1e3ccSAndroid Build Coastguard Worker   }
199*77c1e3ccSAndroid Build Coastguard Worker 
200*77c1e3ccSAndroid Build Coastguard Worker   if (is_4k_or_larger) {
201*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.default_min_partition_size = BLOCK_8X8;
202*77c1e3ccSAndroid Build Coastguard Worker   }
203*77c1e3ccSAndroid Build Coastguard Worker 
204*77c1e3ccSAndroid Build Coastguard Worker   // TODO([email protected]): train models for 720P and above.
205*77c1e3ccSAndroid Build Coastguard Worker   if (!is_720p_or_larger) {
206*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.ml_partition_search_breakout_thresh[0] = 200;  // BLOCK_8X8
207*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.ml_partition_search_breakout_thresh[1] = 250;  // BLOCK_16X16
208*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.ml_partition_search_breakout_thresh[2] = 300;  // BLOCK_32X32
209*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.ml_partition_search_breakout_thresh[3] = 500;  // BLOCK_64X64
210*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.ml_partition_search_breakout_thresh[4] = -1;   // BLOCK_128X128
211*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.ml_early_term_after_part_split_level = 1;
212*77c1e3ccSAndroid Build Coastguard Worker   }
213*77c1e3ccSAndroid Build Coastguard Worker 
214*77c1e3ccSAndroid Build Coastguard Worker   if (is_720p_or_larger) {
215*77c1e3ccSAndroid Build Coastguard Worker     // TODO([email protected]): make this speed feature adaptive based on
216*77c1e3ccSAndroid Build Coastguard Worker     // current block's vertical texture instead of hardcoded with resolution
217*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.use_downsampled_sad = 2;
218*77c1e3ccSAndroid Build Coastguard Worker   }
219*77c1e3ccSAndroid Build Coastguard Worker 
220*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 1) {
221*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger) {
222*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.use_square_partition_only_threshold = BLOCK_128X128;
223*77c1e3ccSAndroid Build Coastguard Worker     } else if (is_480p_or_larger) {
224*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.use_square_partition_only_threshold = BLOCK_64X64;
225*77c1e3ccSAndroid Build Coastguard Worker     } else {
226*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.use_square_partition_only_threshold = BLOCK_32X32;
227*77c1e3ccSAndroid Build Coastguard Worker     }
228*77c1e3ccSAndroid Build Coastguard Worker 
229*77c1e3ccSAndroid Build Coastguard Worker     if (!is_720p_or_larger) {
230*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.ml_partition_search_breakout_thresh[0] = 200;  // BLOCK_8X8
231*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.ml_partition_search_breakout_thresh[1] = 250;  // BLOCK_16X16
232*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.ml_partition_search_breakout_thresh[2] = 300;  // BLOCK_32X32
233*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.ml_partition_search_breakout_thresh[3] = 300;  // BLOCK_64X64
234*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.ml_partition_search_breakout_thresh[4] = -1;  // BLOCK_128X128
235*77c1e3ccSAndroid Build Coastguard Worker     }
236*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.ml_early_term_after_part_split_level = 2;
237*77c1e3ccSAndroid Build Coastguard Worker   }
238*77c1e3ccSAndroid Build Coastguard Worker 
239*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 2) {
240*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger) {
241*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.use_square_partition_only_threshold = BLOCK_64X64;
242*77c1e3ccSAndroid Build Coastguard Worker     } else if (is_480p_or_larger) {
243*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.use_square_partition_only_threshold = BLOCK_32X32;
244*77c1e3ccSAndroid Build Coastguard Worker     } else {
245*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.use_square_partition_only_threshold = BLOCK_32X32;
246*77c1e3ccSAndroid Build Coastguard Worker     }
247*77c1e3ccSAndroid Build Coastguard Worker 
248*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger) {
249*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.partition_search_breakout_dist_thr = (1 << 24);
250*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.partition_search_breakout_rate_thr = 120;
251*77c1e3ccSAndroid Build Coastguard Worker     } else {
252*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.partition_search_breakout_dist_thr = (1 << 22);
253*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.partition_search_breakout_rate_thr = 100;
254*77c1e3ccSAndroid Build Coastguard Worker     }
255*77c1e3ccSAndroid Build Coastguard Worker 
256*77c1e3ccSAndroid Build Coastguard Worker     if (is_480p_or_larger) {
257*77c1e3ccSAndroid Build Coastguard Worker       sf->tx_sf.tx_type_search.prune_tx_type_using_stats = 1;
258*77c1e3ccSAndroid Build Coastguard Worker       if (use_hbd) sf->tx_sf.prune_tx_size_level = 2;
259*77c1e3ccSAndroid Build Coastguard Worker     } else {
260*77c1e3ccSAndroid Build Coastguard Worker       if (use_hbd) sf->tx_sf.prune_tx_size_level = 3;
261*77c1e3ccSAndroid Build Coastguard Worker     }
262*77c1e3ccSAndroid Build Coastguard Worker   }
263*77c1e3ccSAndroid Build Coastguard Worker 
264*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 3) {
265*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.ml_early_term_after_part_split_level = 0;
266*77c1e3ccSAndroid Build Coastguard Worker 
267*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger) {
268*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.partition_search_breakout_dist_thr = (1 << 25);
269*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.partition_search_breakout_rate_thr = 200;
270*77c1e3ccSAndroid Build Coastguard Worker     } else {
271*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.max_intra_bsize = BLOCK_32X32;
272*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.partition_search_breakout_dist_thr = (1 << 23);
273*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.partition_search_breakout_rate_thr = 120;
274*77c1e3ccSAndroid Build Coastguard Worker     }
275*77c1e3ccSAndroid Build Coastguard Worker     if (use_hbd) sf->tx_sf.prune_tx_size_level = 3;
276*77c1e3ccSAndroid Build Coastguard Worker   }
277*77c1e3ccSAndroid Build Coastguard Worker 
278*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 4) {
279*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger) {
280*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.partition_search_breakout_dist_thr = (1 << 26);
281*77c1e3ccSAndroid Build Coastguard Worker     } else {
282*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.partition_search_breakout_dist_thr = (1 << 24);
283*77c1e3ccSAndroid Build Coastguard Worker     }
284*77c1e3ccSAndroid Build Coastguard Worker 
285*77c1e3ccSAndroid Build Coastguard Worker     if (is_480p_or_larger) {
286*77c1e3ccSAndroid Build Coastguard Worker       sf->tx_sf.tx_type_search.prune_tx_type_using_stats = 2;
287*77c1e3ccSAndroid Build Coastguard Worker     }
288*77c1e3ccSAndroid Build Coastguard Worker   }
289*77c1e3ccSAndroid Build Coastguard Worker 
290*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 6) {
291*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger) {
292*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.auto_max_partition_based_on_simple_motion = NOT_IN_USE;
293*77c1e3ccSAndroid Build Coastguard Worker     } else if (is_480p_or_larger) {
294*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.auto_max_partition_based_on_simple_motion = DIRECT_PRED;
295*77c1e3ccSAndroid Build Coastguard Worker     }
296*77c1e3ccSAndroid Build Coastguard Worker 
297*77c1e3ccSAndroid Build Coastguard Worker     if (is_1080p_or_larger) {
298*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.default_min_partition_size = BLOCK_8X8;
299*77c1e3ccSAndroid Build Coastguard Worker     }
300*77c1e3ccSAndroid Build Coastguard Worker 
301*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.use_square_partition_only_threshold = BLOCK_16X16;
302*77c1e3ccSAndroid Build Coastguard Worker   }
303*77c1e3ccSAndroid Build Coastguard Worker 
304*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 7) {
305*77c1e3ccSAndroid Build Coastguard Worker     // TODO(kyslov): add more speed features to control speed/quality
306*77c1e3ccSAndroid Build Coastguard Worker   }
307*77c1e3ccSAndroid Build Coastguard Worker 
308*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 8) {
309*77c1e3ccSAndroid Build Coastguard Worker     if (!is_480p_or_larger) {
310*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.nonrd_check_partition_merge_mode = 2;
311*77c1e3ccSAndroid Build Coastguard Worker     }
312*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger) {
313*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.force_large_partition_blocks_intra = 1;
314*77c1e3ccSAndroid Build Coastguard Worker     }
315*77c1e3ccSAndroid Build Coastguard Worker   }
316*77c1e3ccSAndroid Build Coastguard Worker 
317*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 9) {
318*77c1e3ccSAndroid Build Coastguard Worker     // TODO(kyslov): add more speed features to control speed/quality
319*77c1e3ccSAndroid Build Coastguard Worker     if (!is_4k_or_larger) {
320*77c1e3ccSAndroid Build Coastguard Worker       // In av1_select_sb_size(), superblock size is set to 64x64 only for
321*77c1e3ccSAndroid Build Coastguard Worker       // resolutions less than 4k in speed>=9, to improve the multithread
322*77c1e3ccSAndroid Build Coastguard Worker       // performance. If cost update levels are set to INTERNAL_COST_UPD_OFF
323*77c1e3ccSAndroid Build Coastguard Worker       // for resolutions >= 4k, the SB size setting can be modified for these
324*77c1e3ccSAndroid Build Coastguard Worker       // resolutions as well.
325*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.coeff_cost_upd_level = INTERNAL_COST_UPD_OFF;
326*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.mode_cost_upd_level = INTERNAL_COST_UPD_OFF;
327*77c1e3ccSAndroid Build Coastguard Worker     }
328*77c1e3ccSAndroid Build Coastguard Worker   }
329*77c1e3ccSAndroid Build Coastguard Worker }
330*77c1e3ccSAndroid Build Coastguard Worker 
set_allintra_speed_features_framesize_independent(const AV1_COMP * const cpi,SPEED_FEATURES * const sf,int speed)331*77c1e3ccSAndroid Build Coastguard Worker static void set_allintra_speed_features_framesize_independent(
332*77c1e3ccSAndroid Build Coastguard Worker     const AV1_COMP *const cpi, SPEED_FEATURES *const sf, int speed) {
333*77c1e3ccSAndroid Build Coastguard Worker   const AV1_COMMON *const cm = &cpi->common;
334*77c1e3ccSAndroid Build Coastguard Worker   const int allow_screen_content_tools =
335*77c1e3ccSAndroid Build Coastguard Worker       cm->features.allow_screen_content_tools;
336*77c1e3ccSAndroid Build Coastguard Worker   const int use_hbd = cpi->oxcf.use_highbitdepth;
337*77c1e3ccSAndroid Build Coastguard Worker 
338*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.less_rectangular_check_level = 1;
339*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.ml_prune_partition = 1;
340*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.prune_ext_partition_types_search_level = 1;
341*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.prune_part4_search = 2;
342*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.simple_motion_search_prune_rect = 1;
343*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.ml_predict_breakout_level = use_hbd ? 1 : 3;
344*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.reuse_prev_rd_results_for_part_ab = 1;
345*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.use_best_rd_for_pruning = 1;
346*77c1e3ccSAndroid Build Coastguard Worker 
347*77c1e3ccSAndroid Build Coastguard Worker   sf->intra_sf.intra_pruning_with_hog = 1;
348*77c1e3ccSAndroid Build Coastguard Worker   sf->intra_sf.prune_luma_palette_size_search_level = 1;
349*77c1e3ccSAndroid Build Coastguard Worker   sf->intra_sf.dv_cost_upd_level = INTERNAL_COST_UPD_OFF;
350*77c1e3ccSAndroid Build Coastguard Worker   sf->intra_sf.early_term_chroma_palette_size_search = 1;
351*77c1e3ccSAndroid Build Coastguard Worker 
352*77c1e3ccSAndroid Build Coastguard Worker   sf->tx_sf.adaptive_txb_search_level = 1;
353*77c1e3ccSAndroid Build Coastguard Worker   sf->tx_sf.intra_tx_size_search_init_depth_sqr = 1;
354*77c1e3ccSAndroid Build Coastguard Worker   sf->tx_sf.model_based_prune_tx_search_level = 1;
355*77c1e3ccSAndroid Build Coastguard Worker   sf->tx_sf.tx_type_search.use_reduced_intra_txset = 1;
356*77c1e3ccSAndroid Build Coastguard Worker 
357*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.use_nonrd_pick_mode = 0;
358*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.use_real_time_ref_set = 0;
359*77c1e3ccSAndroid Build Coastguard Worker 
360*77c1e3ccSAndroid Build Coastguard Worker   if (cpi->twopass_frame.fr_content_type == FC_GRAPHICS_ANIMATION ||
361*77c1e3ccSAndroid Build Coastguard Worker       cpi->use_screen_content_tools) {
362*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.exhaustive_searches_thresh = (1 << 20);
363*77c1e3ccSAndroid Build Coastguard Worker   } else {
364*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.exhaustive_searches_thresh = (1 << 25);
365*77c1e3ccSAndroid Build Coastguard Worker   }
366*77c1e3ccSAndroid Build Coastguard Worker 
367*77c1e3ccSAndroid Build Coastguard Worker   sf->rd_sf.perform_coeff_opt = 1;
368*77c1e3ccSAndroid Build Coastguard Worker   sf->hl_sf.superres_auto_search_type = SUPERRES_AUTO_DUAL;
369*77c1e3ccSAndroid Build Coastguard Worker 
370*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 1) {
371*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.intra_cnn_based_part_prune_level =
372*77c1e3ccSAndroid Build Coastguard Worker         allow_screen_content_tools ? 0 : 2;
373*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.simple_motion_search_early_term_none = 1;
374*77c1e3ccSAndroid Build Coastguard Worker     // TODO(Venkat): Clean-up frame type dependency for
375*77c1e3ccSAndroid Build Coastguard Worker     // simple_motion_search_split in partition search function and set the
376*77c1e3ccSAndroid Build Coastguard Worker     // speed feature accordingly
377*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.simple_motion_search_split = allow_screen_content_tools ? 1 : 2;
378*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.ml_predict_breakout_level = use_hbd ? 2 : 3;
379*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.reuse_best_prediction_for_part_ab = 1;
380*77c1e3ccSAndroid Build Coastguard Worker 
381*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.exhaustive_searches_thresh <<= 1;
382*77c1e3ccSAndroid Build Coastguard Worker 
383*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.prune_palette_search_level = 1;
384*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.prune_luma_palette_size_search_level = 2;
385*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.top_intra_model_count_allowed = 3;
386*77c1e3ccSAndroid Build Coastguard Worker 
387*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.adaptive_txb_search_level = 2;
388*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.inter_tx_size_search_init_depth_rect = 1;
389*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.inter_tx_size_search_init_depth_sqr = 1;
390*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.intra_tx_size_search_init_depth_rect = 1;
391*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.model_based_prune_tx_search_level = 0;
392*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.tx_type_search.ml_tx_split_thresh = 4000;
393*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.tx_type_search.prune_2d_txfm_mode = TX_TYPE_PRUNE_2;
394*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.tx_type_search.skip_tx_search = 1;
395*77c1e3ccSAndroid Build Coastguard Worker 
396*77c1e3ccSAndroid Build Coastguard Worker     sf->rd_sf.perform_coeff_opt = 2;
397*77c1e3ccSAndroid Build Coastguard Worker     sf->rd_sf.tx_domain_dist_level = 1;
398*77c1e3ccSAndroid Build Coastguard Worker     sf->rd_sf.tx_domain_dist_thres_level = 1;
399*77c1e3ccSAndroid Build Coastguard Worker 
400*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL1;
401*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.dual_sgr_penalty_level = 1;
402*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.enable_sgr_ep_pruning = 1;
403*77c1e3ccSAndroid Build Coastguard Worker   }
404*77c1e3ccSAndroid Build Coastguard Worker 
405*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 2) {
406*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.auto_mv_step_size = 1;
407*77c1e3ccSAndroid Build Coastguard Worker 
408*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.disable_smooth_intra = 1;
409*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.intra_pruning_with_hog = 2;
410*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.prune_filter_intra_level = 1;
411*77c1e3ccSAndroid Build Coastguard Worker 
412*77c1e3ccSAndroid Build Coastguard Worker     sf->rd_sf.perform_coeff_opt = 3;
413*77c1e3ccSAndroid Build Coastguard Worker 
414*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.prune_wiener_based_on_src_var = 1;
415*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.prune_sgr_based_on_wiener = 1;
416*77c1e3ccSAndroid Build Coastguard Worker   }
417*77c1e3ccSAndroid Build Coastguard Worker 
418*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 3) {
419*77c1e3ccSAndroid Build Coastguard Worker     sf->hl_sf.high_precision_mv_usage = CURRENT_Q;
420*77c1e3ccSAndroid Build Coastguard Worker     sf->hl_sf.recode_loop = ALLOW_RECODE_KFARFGF;
421*77c1e3ccSAndroid Build Coastguard Worker 
422*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.less_rectangular_check_level = 2;
423*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.simple_motion_search_prune_agg = SIMPLE_AGG_LVL1;
424*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.prune_ext_part_using_split_info = 1;
425*77c1e3ccSAndroid Build Coastguard Worker 
426*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.full_pixel_search_level = 1;
427*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.search_method = DIAMOND;
428*77c1e3ccSAndroid Build Coastguard Worker 
429*77c1e3ccSAndroid Build Coastguard Worker     // TODO([email protected]): the thresholds chosen for intra hog are
430*77c1e3ccSAndroid Build Coastguard Worker     // inherited directly from luma hog with some minor tweaking. Eventually we
431*77c1e3ccSAndroid Build Coastguard Worker     // should run this with a bayesian optimizer to find the Pareto frontier.
432*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.chroma_intra_pruning_with_hog = 2;
433*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.intra_pruning_with_hog = 3;
434*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.prune_palette_search_level = 2;
435*77c1e3ccSAndroid Build Coastguard Worker 
436*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.adaptive_txb_search_level = 2;
437*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.tx_type_search.use_skip_flag_prediction = 2;
438*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.use_rd_based_breakout_for_intra_tx_search = true;
439*77c1e3ccSAndroid Build Coastguard Worker 
440*77c1e3ccSAndroid Build Coastguard Worker     // TODO(any): evaluate if these lpf features can be moved to speed 2.
441*77c1e3ccSAndroid Build Coastguard Worker     // For screen content, "prune_sgr_based_on_wiener = 2" cause large quality
442*77c1e3ccSAndroid Build Coastguard Worker     // loss.
443*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.prune_sgr_based_on_wiener = allow_screen_content_tools ? 1 : 2;
444*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.disable_loop_restoration_chroma = 0;
445*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.reduce_wiener_window_size = 1;
446*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.prune_wiener_based_on_src_var = 2;
447*77c1e3ccSAndroid Build Coastguard Worker   }
448*77c1e3ccSAndroid Build Coastguard Worker 
449*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 4) {
450*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
451*77c1e3ccSAndroid Build Coastguard Worker 
452*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.simple_motion_search_prune_agg = SIMPLE_AGG_LVL2;
453*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.simple_motion_search_reduce_search_steps = 4;
454*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.prune_ext_part_using_split_info = 2;
455*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.early_term_after_none_split = 1;
456*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.ml_predict_breakout_level = 3;
457*77c1e3ccSAndroid Build Coastguard Worker 
458*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.prune_chroma_modes_using_luma_winner = 1;
459*77c1e3ccSAndroid Build Coastguard Worker 
460*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.simple_motion_subpel_force_stop = HALF_PEL;
461*77c1e3ccSAndroid Build Coastguard Worker 
462*77c1e3ccSAndroid Build Coastguard Worker     sf->tpl_sf.prune_starting_mv = 2;
463*77c1e3ccSAndroid Build Coastguard Worker     sf->tpl_sf.subpel_force_stop = HALF_PEL;
464*77c1e3ccSAndroid Build Coastguard Worker     sf->tpl_sf.search_method = FAST_BIGDIA;
465*77c1e3ccSAndroid Build Coastguard Worker 
466*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning = 2;
467*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.tx_type_search.fast_intra_tx_type_search = 1;
468*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.tx_type_search.prune_2d_txfm_mode = TX_TYPE_PRUNE_3;
469*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.tx_type_search.prune_tx_type_est_rd = 1;
470*77c1e3ccSAndroid Build Coastguard Worker 
471*77c1e3ccSAndroid Build Coastguard Worker     sf->rd_sf.perform_coeff_opt = 5;
472*77c1e3ccSAndroid Build Coastguard Worker     sf->rd_sf.tx_domain_dist_thres_level = 3;
473*77c1e3ccSAndroid Build Coastguard Worker 
474*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.lpf_pick = LPF_PICK_FROM_FULL_IMAGE_NON_DUAL;
475*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL3;
476*77c1e3ccSAndroid Build Coastguard Worker 
477*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.reduce_search_range = 1;
478*77c1e3ccSAndroid Build Coastguard Worker 
479*77c1e3ccSAndroid Build Coastguard Worker     sf->winner_mode_sf.enable_winner_mode_for_coeff_opt = 1;
480*77c1e3ccSAndroid Build Coastguard Worker     sf->winner_mode_sf.enable_winner_mode_for_use_tx_domain_dist = 1;
481*77c1e3ccSAndroid Build Coastguard Worker     sf->winner_mode_sf.multi_winner_mode_type = MULTI_WINNER_MODE_DEFAULT;
482*77c1e3ccSAndroid Build Coastguard Worker     sf->winner_mode_sf.enable_winner_mode_for_tx_size_srch = 1;
483*77c1e3ccSAndroid Build Coastguard Worker   }
484*77c1e3ccSAndroid Build Coastguard Worker 
485*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 5) {
486*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.simple_motion_search_prune_agg = SIMPLE_AGG_LVL3;
487*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.ext_partition_eval_thresh =
488*77c1e3ccSAndroid Build Coastguard Worker         allow_screen_content_tools ? BLOCK_8X8 : BLOCK_16X16;
489*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.intra_cnn_based_part_prune_level =
490*77c1e3ccSAndroid Build Coastguard Worker         allow_screen_content_tools ? 1 : 2;
491*77c1e3ccSAndroid Build Coastguard Worker 
492*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.chroma_intra_pruning_with_hog = 3;
493*77c1e3ccSAndroid Build Coastguard Worker 
494*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.use_coarse_filter_level_search = 0;
495*77c1e3ccSAndroid Build Coastguard Worker     // Disable Wiener and Self-guided Loop restoration filters.
496*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.disable_wiener_filter = true;
497*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.disable_sgr_filter = true;
498*77c1e3ccSAndroid Build Coastguard Worker 
499*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.prune_mesh_search = PRUNE_MESH_SEARCH_LVL_2;
500*77c1e3ccSAndroid Build Coastguard Worker 
501*77c1e3ccSAndroid Build Coastguard Worker     sf->winner_mode_sf.multi_winner_mode_type = MULTI_WINNER_MODE_FAST;
502*77c1e3ccSAndroid Build Coastguard Worker   }
503*77c1e3ccSAndroid Build Coastguard Worker 
504*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 6) {
505*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.prune_smooth_intra_mode_for_chroma = 1;
506*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.prune_filter_intra_level = 2;
507*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.chroma_intra_pruning_with_hog = 4;
508*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.intra_pruning_with_hog = 4;
509*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.cfl_search_range = 1;
510*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.top_intra_model_count_allowed = 2;
511*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.adapt_top_model_rd_count_using_neighbors = 1;
512*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.prune_luma_odd_delta_angles_in_intra = 1;
513*77c1e3ccSAndroid Build Coastguard Worker 
514*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.prune_rectangular_split_based_on_qidx =
515*77c1e3ccSAndroid Build Coastguard Worker         allow_screen_content_tools ? 0 : 2;
516*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.prune_rect_part_using_4x4_var_deviation = true;
517*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.prune_rect_part_using_none_pred_mode = true;
518*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.prune_sub_8x8_partition_level =
519*77c1e3ccSAndroid Build Coastguard Worker         allow_screen_content_tools ? 0 : 1;
520*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.prune_part4_search = 3;
521*77c1e3ccSAndroid Build Coastguard Worker     // TODO(jingning): This might not be a good trade off if the
522*77c1e3ccSAndroid Build Coastguard Worker     // target image quality is very low.
523*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.default_max_partition_size = BLOCK_32X32;
524*77c1e3ccSAndroid Build Coastguard Worker 
525*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.use_bsize_dependent_search_method = 1;
526*77c1e3ccSAndroid Build Coastguard Worker 
527*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning = 3;
528*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.tx_type_search.prune_tx_type_est_rd = 0;
529*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.prune_intra_tx_depths_using_nn = true;
530*77c1e3ccSAndroid Build Coastguard Worker 
531*77c1e3ccSAndroid Build Coastguard Worker     sf->rd_sf.perform_coeff_opt = 6;
532*77c1e3ccSAndroid Build Coastguard Worker     sf->rd_sf.tx_domain_dist_level = 3;
533*77c1e3ccSAndroid Build Coastguard Worker 
534*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL4;
535*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.lpf_pick = LPF_PICK_FROM_Q;
536*77c1e3ccSAndroid Build Coastguard Worker 
537*77c1e3ccSAndroid Build Coastguard Worker     sf->winner_mode_sf.multi_winner_mode_type = MULTI_WINNER_MODE_OFF;
538*77c1e3ccSAndroid Build Coastguard Worker     sf->winner_mode_sf.prune_winner_mode_eval_level = 1;
539*77c1e3ccSAndroid Build Coastguard Worker     sf->winner_mode_sf.dc_blk_pred_level = 1;
540*77c1e3ccSAndroid Build Coastguard Worker   }
541*77c1e3ccSAndroid Build Coastguard Worker   // The following should make all-intra mode speed 7 approximately equal
542*77c1e3ccSAndroid Build Coastguard Worker   // to real-time speed 6,
543*77c1e3ccSAndroid Build Coastguard Worker   // all-intra speed 8 close to real-time speed 7, and all-intra speed 9
544*77c1e3ccSAndroid Build Coastguard Worker   // close to real-time speed 8
545*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 7) {
546*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.default_min_partition_size = BLOCK_8X8;
547*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.partition_search_type = VAR_BASED_PARTITION;
548*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.cdef_pick_method = CDEF_PICK_FROM_Q;
549*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.mode_search_skip_flags |= FLAG_SKIP_INTRA_DIRMISMATCH;
550*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.var_part_split_threshold_shift = 7;
551*77c1e3ccSAndroid Build Coastguard Worker   }
552*77c1e3ccSAndroid Build Coastguard Worker 
553*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 8) {
554*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.hybrid_intra_pickmode = 1;
555*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.use_nonrd_pick_mode = 1;
556*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.nonrd_check_partition_merge_mode = 1;
557*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.var_part_split_threshold_shift = 8;
558*77c1e3ccSAndroid Build Coastguard Worker     // Set mask for intra modes.
559*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < BLOCK_SIZES; ++i)
560*77c1e3ccSAndroid Build Coastguard Worker       if (i >= BLOCK_32X32)
561*77c1e3ccSAndroid Build Coastguard Worker         sf->rt_sf.intra_y_mode_bsize_mask_nrd[i] = INTRA_DC;
562*77c1e3ccSAndroid Build Coastguard Worker       else
563*77c1e3ccSAndroid Build Coastguard Worker         // Use DC, H, V intra mode for block sizes < 32X32.
564*77c1e3ccSAndroid Build Coastguard Worker         sf->rt_sf.intra_y_mode_bsize_mask_nrd[i] = INTRA_DC_H_V;
565*77c1e3ccSAndroid Build Coastguard Worker   }
566*77c1e3ccSAndroid Build Coastguard Worker 
567*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 9) {
568*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.coeff_cost_upd_level = INTERNAL_COST_UPD_SBROW;
569*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.mode_cost_upd_level = INTERNAL_COST_UPD_SBROW;
570*77c1e3ccSAndroid Build Coastguard Worker 
571*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.nonrd_check_partition_merge_mode = 0;
572*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.hybrid_intra_pickmode = 0;
573*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.var_part_split_threshold_shift = 9;
574*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.vbp_prune_16x16_split_using_min_max_sub_blk_var = true;
575*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.prune_h_pred_using_best_mode_so_far = true;
576*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.enable_intra_mode_pruning_using_neighbors = true;
577*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.prune_intra_mode_using_best_sad_so_far = true;
578*77c1e3ccSAndroid Build Coastguard Worker   }
579*77c1e3ccSAndroid Build Coastguard Worker 
580*77c1e3ccSAndroid Build Coastguard Worker   // As the speed feature prune_chroma_modes_using_luma_winner already
581*77c1e3ccSAndroid Build Coastguard Worker   // constrains the number of chroma directional mode evaluations to a maximum
582*77c1e3ccSAndroid Build Coastguard Worker   // of 1, the HOG computation and the associated pruning logic does not seem to
583*77c1e3ccSAndroid Build Coastguard Worker   // help speed-up the chroma mode evaluations. Hence disable the speed feature
584*77c1e3ccSAndroid Build Coastguard Worker   // chroma_intra_pruning_with_hog when prune_chroma_modes_using_luma_winner is
585*77c1e3ccSAndroid Build Coastguard Worker   // enabled.
586*77c1e3ccSAndroid Build Coastguard Worker   if (sf->intra_sf.prune_chroma_modes_using_luma_winner)
587*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.chroma_intra_pruning_with_hog = 0;
588*77c1e3ccSAndroid Build Coastguard Worker }
589*77c1e3ccSAndroid Build Coastguard Worker 
set_good_speed_feature_framesize_dependent(const AV1_COMP * const cpi,SPEED_FEATURES * const sf,int speed)590*77c1e3ccSAndroid Build Coastguard Worker static void set_good_speed_feature_framesize_dependent(
591*77c1e3ccSAndroid Build Coastguard Worker     const AV1_COMP *const cpi, SPEED_FEATURES *const sf, int speed) {
592*77c1e3ccSAndroid Build Coastguard Worker   const AV1_COMMON *const cm = &cpi->common;
593*77c1e3ccSAndroid Build Coastguard Worker   const int is_480p_or_lesser = AOMMIN(cm->width, cm->height) <= 480;
594*77c1e3ccSAndroid Build Coastguard Worker   const int is_480p_or_larger = AOMMIN(cm->width, cm->height) >= 480;
595*77c1e3ccSAndroid Build Coastguard Worker   const int is_720p_or_larger = AOMMIN(cm->width, cm->height) >= 720;
596*77c1e3ccSAndroid Build Coastguard Worker   const int is_1080p_or_larger = AOMMIN(cm->width, cm->height) >= 1080;
597*77c1e3ccSAndroid Build Coastguard Worker   const int is_4k_or_larger = AOMMIN(cm->width, cm->height) >= 2160;
598*77c1e3ccSAndroid Build Coastguard Worker   const bool use_hbd = cpi->oxcf.use_highbitdepth;
599*77c1e3ccSAndroid Build Coastguard Worker   // Speed features applicable for temporal filtering and tpl modules may be
600*77c1e3ccSAndroid Build Coastguard Worker   // changed based on frame type at places where the sf is applied (Example :
601*77c1e3ccSAndroid Build Coastguard Worker   // use_downsampled_sad). This is because temporal filtering and tpl modules
602*77c1e3ccSAndroid Build Coastguard Worker   // are called before this function (except for the first key frame).
603*77c1e3ccSAndroid Build Coastguard Worker   // TODO([email protected]): For the speed features applicable to temporal
604*77c1e3ccSAndroid Build Coastguard Worker   // filtering and tpl modules, modify the sf initialization appropriately
605*77c1e3ccSAndroid Build Coastguard Worker   // before calling the modules.
606*77c1e3ccSAndroid Build Coastguard Worker   const int boosted = frame_is_boosted(cpi);
607*77c1e3ccSAndroid Build Coastguard Worker   const int is_boosted_arf2_bwd_type =
608*77c1e3ccSAndroid Build Coastguard Worker       boosted ||
609*77c1e3ccSAndroid Build Coastguard Worker       cpi->ppi->gf_group.update_type[cpi->gf_frame_index] == INTNL_ARF_UPDATE;
610*77c1e3ccSAndroid Build Coastguard Worker   const int is_lf_frame =
611*77c1e3ccSAndroid Build Coastguard Worker       cpi->ppi->gf_group.update_type[cpi->gf_frame_index] == LF_UPDATE;
612*77c1e3ccSAndroid Build Coastguard Worker   const int allow_screen_content_tools =
613*77c1e3ccSAndroid Build Coastguard Worker       cm->features.allow_screen_content_tools;
614*77c1e3ccSAndroid Build Coastguard Worker 
615*77c1e3ccSAndroid Build Coastguard Worker   if (is_480p_or_larger) {
616*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.use_square_partition_only_threshold = BLOCK_128X128;
617*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger)
618*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.auto_max_partition_based_on_simple_motion = ADAPT_PRED;
619*77c1e3ccSAndroid Build Coastguard Worker     else
620*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.auto_max_partition_based_on_simple_motion = RELAXED_PRED;
621*77c1e3ccSAndroid Build Coastguard Worker   } else {
622*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.use_square_partition_only_threshold = BLOCK_64X64;
623*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.auto_max_partition_based_on_simple_motion = DIRECT_PRED;
624*77c1e3ccSAndroid Build Coastguard Worker     if (use_hbd) sf->tx_sf.prune_tx_size_level = 1;
625*77c1e3ccSAndroid Build Coastguard Worker   }
626*77c1e3ccSAndroid Build Coastguard Worker 
627*77c1e3ccSAndroid Build Coastguard Worker   if (is_4k_or_larger) {
628*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.default_min_partition_size = BLOCK_8X8;
629*77c1e3ccSAndroid Build Coastguard Worker   }
630*77c1e3ccSAndroid Build Coastguard Worker 
631*77c1e3ccSAndroid Build Coastguard Worker   // TODO([email protected]): train models for 720P and above.
632*77c1e3ccSAndroid Build Coastguard Worker   if (!is_720p_or_larger) {
633*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.ml_partition_search_breakout_thresh[0] = 200;  // BLOCK_8X8
634*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.ml_partition_search_breakout_thresh[1] = 250;  // BLOCK_16X16
635*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.ml_partition_search_breakout_thresh[2] = 300;  // BLOCK_32X32
636*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.ml_partition_search_breakout_thresh[3] = 500;  // BLOCK_64X64
637*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.ml_partition_search_breakout_thresh[4] = -1;   // BLOCK_128X128
638*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.ml_early_term_after_part_split_level = 1;
639*77c1e3ccSAndroid Build Coastguard Worker   }
640*77c1e3ccSAndroid Build Coastguard Worker 
641*77c1e3ccSAndroid Build Coastguard Worker   if (is_720p_or_larger) {
642*77c1e3ccSAndroid Build Coastguard Worker     // TODO([email protected]): make this speed feature adaptive based on
643*77c1e3ccSAndroid Build Coastguard Worker     // current block's vertical texture instead of hardcoded with resolution
644*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.use_downsampled_sad = 2;
645*77c1e3ccSAndroid Build Coastguard Worker   }
646*77c1e3ccSAndroid Build Coastguard Worker 
647*77c1e3ccSAndroid Build Coastguard Worker   if (!is_720p_or_larger) {
648*77c1e3ccSAndroid Build Coastguard Worker     const RateControlCfg *const rc_cfg = &cpi->oxcf.rc_cfg;
649*77c1e3ccSAndroid Build Coastguard Worker     const int rate_tolerance =
650*77c1e3ccSAndroid Build Coastguard Worker         AOMMIN(rc_cfg->under_shoot_pct, rc_cfg->over_shoot_pct);
651*77c1e3ccSAndroid Build Coastguard Worker     sf->hl_sf.recode_tolerance = 25 + (rate_tolerance >> 2);
652*77c1e3ccSAndroid Build Coastguard Worker   }
653*77c1e3ccSAndroid Build Coastguard Worker 
654*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 1) {
655*77c1e3ccSAndroid Build Coastguard Worker     if (is_480p_or_lesser) sf->inter_sf.skip_newmv_in_drl = 1;
656*77c1e3ccSAndroid Build Coastguard Worker 
657*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger) {
658*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.use_square_partition_only_threshold = BLOCK_128X128;
659*77c1e3ccSAndroid Build Coastguard Worker     } else if (is_480p_or_larger) {
660*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.use_square_partition_only_threshold = BLOCK_64X64;
661*77c1e3ccSAndroid Build Coastguard Worker     } else {
662*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.use_square_partition_only_threshold = BLOCK_32X32;
663*77c1e3ccSAndroid Build Coastguard Worker     }
664*77c1e3ccSAndroid Build Coastguard Worker 
665*77c1e3ccSAndroid Build Coastguard Worker     if (!is_720p_or_larger) {
666*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.ml_partition_search_breakout_thresh[0] = 200;  // BLOCK_8X8
667*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.ml_partition_search_breakout_thresh[1] = 250;  // BLOCK_16X16
668*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.ml_partition_search_breakout_thresh[2] = 300;  // BLOCK_32X32
669*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.ml_partition_search_breakout_thresh[3] = 300;  // BLOCK_64X64
670*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.ml_partition_search_breakout_thresh[4] = -1;  // BLOCK_128X128
671*77c1e3ccSAndroid Build Coastguard Worker     }
672*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.ml_early_term_after_part_split_level = 2;
673*77c1e3ccSAndroid Build Coastguard Worker 
674*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL1;
675*77c1e3ccSAndroid Build Coastguard Worker   }
676*77c1e3ccSAndroid Build Coastguard Worker 
677*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 2) {
678*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger) {
679*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.use_square_partition_only_threshold = BLOCK_64X64;
680*77c1e3ccSAndroid Build Coastguard Worker     } else if (is_480p_or_larger) {
681*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.use_square_partition_only_threshold = BLOCK_32X32;
682*77c1e3ccSAndroid Build Coastguard Worker     } else {
683*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.use_square_partition_only_threshold = BLOCK_32X32;
684*77c1e3ccSAndroid Build Coastguard Worker     }
685*77c1e3ccSAndroid Build Coastguard Worker 
686*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger) {
687*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.partition_search_breakout_dist_thr = (1 << 24);
688*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.partition_search_breakout_rate_thr = 120;
689*77c1e3ccSAndroid Build Coastguard Worker     } else {
690*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.partition_search_breakout_dist_thr = (1 << 22);
691*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.partition_search_breakout_rate_thr = 100;
692*77c1e3ccSAndroid Build Coastguard Worker     }
693*77c1e3ccSAndroid Build Coastguard Worker 
694*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger) {
695*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.prune_obmc_prob_thresh = 16;
696*77c1e3ccSAndroid Build Coastguard Worker     } else {
697*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.prune_obmc_prob_thresh = 8;
698*77c1e3ccSAndroid Build Coastguard Worker     }
699*77c1e3ccSAndroid Build Coastguard Worker 
700*77c1e3ccSAndroid Build Coastguard Worker     if (is_480p_or_larger) {
701*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.disable_interintra_wedge_var_thresh = 100;
702*77c1e3ccSAndroid Build Coastguard Worker     } else {
703*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.disable_interintra_wedge_var_thresh = UINT_MAX;
704*77c1e3ccSAndroid Build Coastguard Worker     }
705*77c1e3ccSAndroid Build Coastguard Worker 
706*77c1e3ccSAndroid Build Coastguard Worker     if (is_480p_or_lesser) sf->inter_sf.skip_ext_comp_nearmv_mode = 1;
707*77c1e3ccSAndroid Build Coastguard Worker 
708*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger) {
709*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.limit_inter_mode_cands = is_lf_frame ? 1 : 0;
710*77c1e3ccSAndroid Build Coastguard Worker     } else {
711*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.limit_inter_mode_cands = is_lf_frame ? 2 : 0;
712*77c1e3ccSAndroid Build Coastguard Worker     }
713*77c1e3ccSAndroid Build Coastguard Worker 
714*77c1e3ccSAndroid Build Coastguard Worker     if (is_480p_or_larger) {
715*77c1e3ccSAndroid Build Coastguard Worker       sf->tx_sf.tx_type_search.prune_tx_type_using_stats = 1;
716*77c1e3ccSAndroid Build Coastguard Worker       if (use_hbd) sf->tx_sf.prune_tx_size_level = 2;
717*77c1e3ccSAndroid Build Coastguard Worker     } else {
718*77c1e3ccSAndroid Build Coastguard Worker       if (use_hbd) sf->tx_sf.prune_tx_size_level = 3;
719*77c1e3ccSAndroid Build Coastguard Worker       sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning = boosted ? 0 : 1;
720*77c1e3ccSAndroid Build Coastguard Worker       sf->winner_mode_sf.enable_winner_mode_for_tx_size_srch = boosted ? 0 : 1;
721*77c1e3ccSAndroid Build Coastguard Worker     }
722*77c1e3ccSAndroid Build Coastguard Worker 
723*77c1e3ccSAndroid Build Coastguard Worker     if (!is_720p_or_larger) {
724*77c1e3ccSAndroid Build Coastguard Worker       sf->mv_sf.disable_second_mv = 1;
725*77c1e3ccSAndroid Build Coastguard Worker       sf->mv_sf.auto_mv_step_size = 2;
726*77c1e3ccSAndroid Build Coastguard Worker     } else {
727*77c1e3ccSAndroid Build Coastguard Worker       sf->mv_sf.disable_second_mv = boosted ? 0 : 2;
728*77c1e3ccSAndroid Build Coastguard Worker       sf->mv_sf.auto_mv_step_size = 1;
729*77c1e3ccSAndroid Build Coastguard Worker     }
730*77c1e3ccSAndroid Build Coastguard Worker 
731*77c1e3ccSAndroid Build Coastguard Worker     if (!is_720p_or_larger) {
732*77c1e3ccSAndroid Build Coastguard Worker       sf->hl_sf.recode_tolerance = 50;
733*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.disable_interinter_wedge_newmv_search =
734*77c1e3ccSAndroid Build Coastguard Worker           is_boosted_arf2_bwd_type ? 0 : 1;
735*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.enable_fast_wedge_mask_search = 1;
736*77c1e3ccSAndroid Build Coastguard Worker     }
737*77c1e3ccSAndroid Build Coastguard Worker   }
738*77c1e3ccSAndroid Build Coastguard Worker 
739*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 3) {
740*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.enable_fast_wedge_mask_search = 1;
741*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.skip_newmv_in_drl = 2;
742*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.skip_ext_comp_nearmv_mode = 1;
743*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.limit_inter_mode_cands = is_lf_frame ? 3 : 0;
744*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.disable_interinter_wedge_newmv_search = boosted ? 0 : 1;
745*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning = 1;
746*77c1e3ccSAndroid Build Coastguard Worker     sf->winner_mode_sf.enable_winner_mode_for_tx_size_srch =
747*77c1e3ccSAndroid Build Coastguard Worker         frame_is_intra_only(&cpi->common) ? 0 : 1;
748*77c1e3ccSAndroid Build Coastguard Worker 
749*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.ml_early_term_after_part_split_level = 0;
750*77c1e3ccSAndroid Build Coastguard Worker 
751*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger) {
752*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.partition_search_breakout_dist_thr = (1 << 25);
753*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.partition_search_breakout_rate_thr = 200;
754*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.skip_non_sq_part_based_on_none = is_lf_frame ? 2 : 0;
755*77c1e3ccSAndroid Build Coastguard Worker     } else {
756*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.max_intra_bsize = BLOCK_32X32;
757*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.partition_search_breakout_dist_thr = (1 << 23);
758*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.partition_search_breakout_rate_thr = 120;
759*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.skip_non_sq_part_based_on_none = is_lf_frame ? 1 : 0;
760*77c1e3ccSAndroid Build Coastguard Worker     }
761*77c1e3ccSAndroid Build Coastguard Worker     if (use_hbd) sf->tx_sf.prune_tx_size_level = 3;
762*77c1e3ccSAndroid Build Coastguard Worker 
763*77c1e3ccSAndroid Build Coastguard Worker     if (is_480p_or_larger) {
764*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.early_term_after_none_split = 1;
765*77c1e3ccSAndroid Build Coastguard Worker     } else {
766*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.early_term_after_none_split = 0;
767*77c1e3ccSAndroid Build Coastguard Worker     }
768*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger) {
769*77c1e3ccSAndroid Build Coastguard Worker       sf->intra_sf.skip_intra_in_interframe = boosted ? 1 : 2;
770*77c1e3ccSAndroid Build Coastguard Worker     } else {
771*77c1e3ccSAndroid Build Coastguard Worker       sf->intra_sf.skip_intra_in_interframe = boosted ? 1 : 3;
772*77c1e3ccSAndroid Build Coastguard Worker     }
773*77c1e3ccSAndroid Build Coastguard Worker 
774*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger) {
775*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.disable_interinter_wedge_var_thresh = 100;
776*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.limit_txfm_eval_per_mode = boosted ? 0 : 1;
777*77c1e3ccSAndroid Build Coastguard Worker     } else {
778*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.disable_interinter_wedge_var_thresh = UINT_MAX;
779*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.limit_txfm_eval_per_mode = boosted ? 0 : 2;
780*77c1e3ccSAndroid Build Coastguard Worker       sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL2;
781*77c1e3ccSAndroid Build Coastguard Worker     }
782*77c1e3ccSAndroid Build Coastguard Worker 
783*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.disable_interintra_wedge_var_thresh = UINT_MAX;
784*77c1e3ccSAndroid Build Coastguard Worker   }
785*77c1e3ccSAndroid Build Coastguard Worker 
786*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 4) {
787*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning = 2;
788*77c1e3ccSAndroid Build Coastguard Worker     sf->winner_mode_sf.enable_winner_mode_for_tx_size_srch = 1;
789*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger) {
790*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.partition_search_breakout_dist_thr = (1 << 26);
791*77c1e3ccSAndroid Build Coastguard Worker     } else {
792*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.partition_search_breakout_dist_thr = (1 << 24);
793*77c1e3ccSAndroid Build Coastguard Worker     }
794*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.early_term_after_none_split = 1;
795*77c1e3ccSAndroid Build Coastguard Worker 
796*77c1e3ccSAndroid Build Coastguard Worker     if (is_480p_or_larger) {
797*77c1e3ccSAndroid Build Coastguard Worker       sf->tx_sf.tx_type_search.prune_tx_type_using_stats = 2;
798*77c1e3ccSAndroid Build Coastguard Worker     } else {
799*77c1e3ccSAndroid Build Coastguard Worker       sf->mv_sf.skip_fullpel_search_using_startmv = boosted ? 0 : 1;
800*77c1e3ccSAndroid Build Coastguard Worker     }
801*77c1e3ccSAndroid Build Coastguard Worker 
802*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.disable_interinter_wedge_var_thresh = UINT_MAX;
803*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.prune_obmc_prob_thresh = INT_MAX;
804*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.limit_txfm_eval_per_mode = boosted ? 0 : 2;
805*77c1e3ccSAndroid Build Coastguard Worker     if (is_480p_or_lesser) sf->inter_sf.skip_newmv_in_drl = 3;
806*77c1e3ccSAndroid Build Coastguard Worker 
807*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger) {
808*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.prune_comp_ref_frames = 1;
809*77c1e3ccSAndroid Build Coastguard Worker     } else if (is_480p_or_larger) {
810*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.prune_comp_ref_frames = is_boosted_arf2_bwd_type ? 0 : 1;
811*77c1e3ccSAndroid Build Coastguard Worker     }
812*77c1e3ccSAndroid Build Coastguard Worker 
813*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger)
814*77c1e3ccSAndroid Build Coastguard Worker       sf->hl_sf.recode_tolerance = 32;
815*77c1e3ccSAndroid Build Coastguard Worker     else
816*77c1e3ccSAndroid Build Coastguard Worker       sf->hl_sf.recode_tolerance = 55;
817*77c1e3ccSAndroid Build Coastguard Worker 
818*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.skip_intra_in_interframe = 4;
819*77c1e3ccSAndroid Build Coastguard Worker 
820*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL3;
821*77c1e3ccSAndroid Build Coastguard Worker   }
822*77c1e3ccSAndroid Build Coastguard Worker 
823*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 5) {
824*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger) {
825*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.prune_warped_prob_thresh = 16;
826*77c1e3ccSAndroid Build Coastguard Worker     } else if (is_480p_or_larger) {
827*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.prune_warped_prob_thresh = 8;
828*77c1e3ccSAndroid Build Coastguard Worker     }
829*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger) sf->hl_sf.recode_tolerance = 40;
830*77c1e3ccSAndroid Build Coastguard Worker 
831*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.skip_newmv_in_drl = 4;
832*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.prune_comp_ref_frames = 1;
833*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.skip_fullpel_search_using_startmv = boosted ? 0 : 1;
834*77c1e3ccSAndroid Build Coastguard Worker 
835*77c1e3ccSAndroid Build Coastguard Worker     if (!is_720p_or_larger) {
836*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.mv_cost_upd_level = INTERNAL_COST_UPD_SBROW_SET;
837*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.prune_nearest_near_mv_using_refmv_weight =
838*77c1e3ccSAndroid Build Coastguard Worker           (boosted || allow_screen_content_tools) ? 0 : 1;
839*77c1e3ccSAndroid Build Coastguard Worker       sf->mv_sf.use_downsampled_sad = 1;
840*77c1e3ccSAndroid Build Coastguard Worker     }
841*77c1e3ccSAndroid Build Coastguard Worker 
842*77c1e3ccSAndroid Build Coastguard Worker     if (!is_480p_or_larger) {
843*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.partition_search_breakout_dist_thr = (1 << 26);
844*77c1e3ccSAndroid Build Coastguard Worker     }
845*77c1e3ccSAndroid Build Coastguard Worker 
846*77c1e3ccSAndroid Build Coastguard Worker     if (is_480p_or_lesser) {
847*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.prune_nearmv_using_neighbors = PRUNE_NEARMV_LEVEL1;
848*77c1e3ccSAndroid Build Coastguard Worker     } else {
849*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.prune_nearmv_using_neighbors = PRUNE_NEARMV_LEVEL2;
850*77c1e3ccSAndroid Build Coastguard Worker     }
851*77c1e3ccSAndroid Build Coastguard Worker 
852*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger)
853*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.ext_part_eval_based_on_cur_best =
854*77c1e3ccSAndroid Build Coastguard Worker           (allow_screen_content_tools || frame_is_intra_only(cm)) ? 0 : 1;
855*77c1e3ccSAndroid Build Coastguard Worker 
856*77c1e3ccSAndroid Build Coastguard Worker     if (is_480p_or_larger) {
857*77c1e3ccSAndroid Build Coastguard Worker       sf->tpl_sf.reduce_num_frames = 1;
858*77c1e3ccSAndroid Build Coastguard Worker     }
859*77c1e3ccSAndroid Build Coastguard Worker   }
860*77c1e3ccSAndroid Build Coastguard Worker 
861*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 6) {
862*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning = 4;
863*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.prune_nearmv_using_neighbors = PRUNE_NEARMV_LEVEL3;
864*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.prune_comp_ref_frames = 2;
865*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.prune_nearest_near_mv_using_refmv_weight =
866*77c1e3ccSAndroid Build Coastguard Worker         (boosted || allow_screen_content_tools) ? 0 : 1;
867*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.skip_fullpel_search_using_startmv = boosted ? 0 : 2;
868*77c1e3ccSAndroid Build Coastguard Worker 
869*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger) {
870*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.auto_max_partition_based_on_simple_motion = NOT_IN_USE;
871*77c1e3ccSAndroid Build Coastguard Worker     } else if (is_480p_or_larger) {
872*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.auto_max_partition_based_on_simple_motion = DIRECT_PRED;
873*77c1e3ccSAndroid Build Coastguard Worker     }
874*77c1e3ccSAndroid Build Coastguard Worker 
875*77c1e3ccSAndroid Build Coastguard Worker     if (is_480p_or_larger) {
876*77c1e3ccSAndroid Build Coastguard Worker       sf->hl_sf.allow_sub_blk_me_in_tf = 1;
877*77c1e3ccSAndroid Build Coastguard Worker     }
878*77c1e3ccSAndroid Build Coastguard Worker 
879*77c1e3ccSAndroid Build Coastguard Worker     if (is_1080p_or_larger) {
880*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.default_min_partition_size = BLOCK_8X8;
881*77c1e3ccSAndroid Build Coastguard Worker     }
882*77c1e3ccSAndroid Build Coastguard Worker 
883*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger) {
884*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.disable_masked_comp = 1;
885*77c1e3ccSAndroid Build Coastguard Worker     }
886*77c1e3ccSAndroid Build Coastguard Worker 
887*77c1e3ccSAndroid Build Coastguard Worker     if (!is_720p_or_larger) {
888*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.coeff_cost_upd_level = INTERNAL_COST_UPD_SBROW;
889*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.mode_cost_upd_level = INTERNAL_COST_UPD_SBROW;
890*77c1e3ccSAndroid Build Coastguard Worker     }
891*77c1e3ccSAndroid Build Coastguard Worker 
892*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger) {
893*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.use_square_partition_only_threshold = BLOCK_32X32;
894*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.partition_search_breakout_dist_thr = (1 << 28);
895*77c1e3ccSAndroid Build Coastguard Worker     } else {
896*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.use_square_partition_only_threshold = BLOCK_16X16;
897*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.partition_search_breakout_dist_thr = (1 << 26);
898*77c1e3ccSAndroid Build Coastguard Worker     }
899*77c1e3ccSAndroid Build Coastguard Worker 
900*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger) {
901*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.prune_ref_mv_idx_search = 2;
902*77c1e3ccSAndroid Build Coastguard Worker     } else {
903*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.prune_ref_mv_idx_search = 1;
904*77c1e3ccSAndroid Build Coastguard Worker     }
905*77c1e3ccSAndroid Build Coastguard Worker 
906*77c1e3ccSAndroid Build Coastguard Worker     if (!is_720p_or_larger) {
907*77c1e3ccSAndroid Build Coastguard Worker       sf->tx_sf.tx_type_search.fast_inter_tx_type_prob_thresh =
908*77c1e3ccSAndroid Build Coastguard Worker           is_boosted_arf2_bwd_type ? 450 : 150;
909*77c1e3ccSAndroid Build Coastguard Worker     }
910*77c1e3ccSAndroid Build Coastguard Worker 
911*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL4;
912*77c1e3ccSAndroid Build Coastguard Worker 
913*77c1e3ccSAndroid Build Coastguard Worker     sf->hl_sf.recode_tolerance = 55;
914*77c1e3ccSAndroid Build Coastguard Worker   }
915*77c1e3ccSAndroid Build Coastguard Worker }
916*77c1e3ccSAndroid Build Coastguard Worker 
set_good_speed_features_framesize_independent(const AV1_COMP * const cpi,SPEED_FEATURES * const sf,int speed)917*77c1e3ccSAndroid Build Coastguard Worker static void set_good_speed_features_framesize_independent(
918*77c1e3ccSAndroid Build Coastguard Worker     const AV1_COMP *const cpi, SPEED_FEATURES *const sf, int speed) {
919*77c1e3ccSAndroid Build Coastguard Worker   const AV1_COMMON *const cm = &cpi->common;
920*77c1e3ccSAndroid Build Coastguard Worker   const GF_GROUP *const gf_group = &cpi->ppi->gf_group;
921*77c1e3ccSAndroid Build Coastguard Worker   const int boosted = frame_is_boosted(cpi);
922*77c1e3ccSAndroid Build Coastguard Worker   const int is_boosted_arf2_bwd_type =
923*77c1e3ccSAndroid Build Coastguard Worker       boosted || gf_group->update_type[cpi->gf_frame_index] == INTNL_ARF_UPDATE;
924*77c1e3ccSAndroid Build Coastguard Worker   const int is_inter_frame =
925*77c1e3ccSAndroid Build Coastguard Worker       gf_group->frame_type[cpi->gf_frame_index] == INTER_FRAME;
926*77c1e3ccSAndroid Build Coastguard Worker   const int allow_screen_content_tools =
927*77c1e3ccSAndroid Build Coastguard Worker       cm->features.allow_screen_content_tools;
928*77c1e3ccSAndroid Build Coastguard Worker   const int use_hbd = cpi->oxcf.use_highbitdepth;
929*77c1e3ccSAndroid Build Coastguard Worker   if (!cpi->oxcf.tile_cfg.enable_large_scale_tile) {
930*77c1e3ccSAndroid Build Coastguard Worker     sf->hl_sf.high_precision_mv_usage = LAST_MV_DATA;
931*77c1e3ccSAndroid Build Coastguard Worker   }
932*77c1e3ccSAndroid Build Coastguard Worker 
933*77c1e3ccSAndroid Build Coastguard Worker   // Speed 0 for all speed features that give neutral coding performance change.
934*77c1e3ccSAndroid Build Coastguard Worker   sf->gm_sf.gm_search_type = boosted ? GM_REDUCED_REF_SEARCH_SKIP_L2_L3_ARF2
935*77c1e3ccSAndroid Build Coastguard Worker                                      : GM_SEARCH_CLOSEST_REFS_ONLY;
936*77c1e3ccSAndroid Build Coastguard Worker   sf->gm_sf.prune_ref_frame_for_gm_search = boosted ? 0 : 1;
937*77c1e3ccSAndroid Build Coastguard Worker   sf->gm_sf.disable_gm_search_based_on_stats = 1;
938*77c1e3ccSAndroid Build Coastguard Worker 
939*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.less_rectangular_check_level = 1;
940*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.ml_prune_partition = 1;
941*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.prune_ext_partition_types_search_level = 1;
942*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.prune_part4_search = 2;
943*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.simple_motion_search_prune_rect = 1;
944*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.ml_predict_breakout_level = use_hbd ? 1 : 3;
945*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.reuse_prev_rd_results_for_part_ab = 1;
946*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.use_best_rd_for_pruning = 1;
947*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.simple_motion_search_prune_agg =
948*77c1e3ccSAndroid Build Coastguard Worker       allow_screen_content_tools ? NO_PRUNING : SIMPLE_AGG_LVL0;
949*77c1e3ccSAndroid Build Coastguard Worker 
950*77c1e3ccSAndroid Build Coastguard Worker   // TODO(debargha): Test, tweak and turn on either 1 or 2
951*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.inter_mode_rd_model_estimation = 1;
952*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.model_based_post_interp_filter_breakout = 1;
953*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.prune_compound_using_single_ref = 1;
954*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.prune_mode_search_simple_translation = 1;
955*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.prune_ref_frame_for_rect_partitions =
956*77c1e3ccSAndroid Build Coastguard Worker       (boosted || (allow_screen_content_tools))
957*77c1e3ccSAndroid Build Coastguard Worker           ? 0
958*77c1e3ccSAndroid Build Coastguard Worker           : (is_boosted_arf2_bwd_type ? 1 : 2);
959*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.reduce_inter_modes = boosted ? 1 : 2;
960*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.selective_ref_frame = 1;
961*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.use_dist_wtd_comp_flag = DIST_WTD_COMP_SKIP_MV_SEARCH;
962*77c1e3ccSAndroid Build Coastguard Worker 
963*77c1e3ccSAndroid Build Coastguard Worker   sf->interp_sf.use_fast_interpolation_filter_search = 1;
964*77c1e3ccSAndroid Build Coastguard Worker 
965*77c1e3ccSAndroid Build Coastguard Worker   sf->intra_sf.intra_pruning_with_hog = 1;
966*77c1e3ccSAndroid Build Coastguard Worker 
967*77c1e3ccSAndroid Build Coastguard Worker   sf->tx_sf.adaptive_txb_search_level = 1;
968*77c1e3ccSAndroid Build Coastguard Worker   sf->tx_sf.intra_tx_size_search_init_depth_sqr = 1;
969*77c1e3ccSAndroid Build Coastguard Worker   sf->tx_sf.model_based_prune_tx_search_level = 1;
970*77c1e3ccSAndroid Build Coastguard Worker   sf->tx_sf.tx_type_search.use_reduced_intra_txset = 1;
971*77c1e3ccSAndroid Build Coastguard Worker 
972*77c1e3ccSAndroid Build Coastguard Worker   sf->tpl_sf.search_method = NSTEP_8PT;
973*77c1e3ccSAndroid Build Coastguard Worker 
974*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.use_nonrd_pick_mode = 0;
975*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.use_real_time_ref_set = 0;
976*77c1e3ccSAndroid Build Coastguard Worker 
977*77c1e3ccSAndroid Build Coastguard Worker   if (cpi->twopass_frame.fr_content_type == FC_GRAPHICS_ANIMATION ||
978*77c1e3ccSAndroid Build Coastguard Worker       cpi->use_screen_content_tools) {
979*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.exhaustive_searches_thresh = (1 << 20);
980*77c1e3ccSAndroid Build Coastguard Worker   } else {
981*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.exhaustive_searches_thresh = (1 << 25);
982*77c1e3ccSAndroid Build Coastguard Worker   }
983*77c1e3ccSAndroid Build Coastguard Worker 
984*77c1e3ccSAndroid Build Coastguard Worker   sf->rd_sf.perform_coeff_opt = 1;
985*77c1e3ccSAndroid Build Coastguard Worker   sf->hl_sf.superres_auto_search_type = SUPERRES_AUTO_DUAL;
986*77c1e3ccSAndroid Build Coastguard Worker 
987*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 1) {
988*77c1e3ccSAndroid Build Coastguard Worker     sf->hl_sf.adjust_num_frames_for_arf_filtering =
989*77c1e3ccSAndroid Build Coastguard Worker         allow_screen_content_tools ? 0 : 1;
990*77c1e3ccSAndroid Build Coastguard Worker 
991*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.intra_cnn_based_part_prune_level =
992*77c1e3ccSAndroid Build Coastguard Worker         allow_screen_content_tools ? 0 : 2;
993*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.simple_motion_search_early_term_none = 1;
994*77c1e3ccSAndroid Build Coastguard Worker     // TODO(Venkat): Clean-up frame type dependency for
995*77c1e3ccSAndroid Build Coastguard Worker     // simple_motion_search_split in partition search function and set the
996*77c1e3ccSAndroid Build Coastguard Worker     // speed feature accordingly
997*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.simple_motion_search_split = allow_screen_content_tools ? 1 : 2;
998*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.ml_predict_breakout_level = use_hbd ? 2 : 3;
999*77c1e3ccSAndroid Build Coastguard Worker 
1000*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.exhaustive_searches_thresh <<= 1;
1001*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.obmc_full_pixel_search_level = 1;
1002*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.use_accurate_subpel_search = USE_4_TAPS;
1003*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.disable_extensive_joint_motion_search = 1;
1004*77c1e3ccSAndroid Build Coastguard Worker 
1005*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.prune_comp_search_by_single_result = boosted ? 2 : 1;
1006*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.prune_comp_type_by_comp_avg = 1;
1007*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.prune_comp_type_by_model_rd = boosted ? 0 : 1;
1008*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.prune_ref_frame_for_rect_partitions =
1009*77c1e3ccSAndroid Build Coastguard Worker         (frame_is_intra_only(&cpi->common) || (allow_screen_content_tools))
1010*77c1e3ccSAndroid Build Coastguard Worker             ? 0
1011*77c1e3ccSAndroid Build Coastguard Worker             : (boosted ? 1 : 2);
1012*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.reduce_inter_modes = boosted ? 1 : 3;
1013*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.reuse_inter_intra_mode = 1;
1014*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.selective_ref_frame = 2;
1015*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.skip_arf_compound = 1;
1016*77c1e3ccSAndroid Build Coastguard Worker 
1017*77c1e3ccSAndroid Build Coastguard Worker     sf->interp_sf.use_interp_filter = 1;
1018*77c1e3ccSAndroid Build Coastguard Worker 
1019*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.prune_palette_search_level = 1;
1020*77c1e3ccSAndroid Build Coastguard Worker 
1021*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.adaptive_txb_search_level = 2;
1022*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.inter_tx_size_search_init_depth_rect = 1;
1023*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.inter_tx_size_search_init_depth_sqr = 1;
1024*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.intra_tx_size_search_init_depth_rect = 1;
1025*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.model_based_prune_tx_search_level = 0;
1026*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.tx_type_search.ml_tx_split_thresh = 4000;
1027*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.tx_type_search.prune_2d_txfm_mode = TX_TYPE_PRUNE_2;
1028*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.tx_type_search.skip_tx_search = 1;
1029*77c1e3ccSAndroid Build Coastguard Worker 
1030*77c1e3ccSAndroid Build Coastguard Worker     sf->rd_sf.perform_coeff_opt = boosted ? 2 : 3;
1031*77c1e3ccSAndroid Build Coastguard Worker     sf->rd_sf.tx_domain_dist_level = boosted ? 1 : 2;
1032*77c1e3ccSAndroid Build Coastguard Worker     sf->rd_sf.tx_domain_dist_thres_level = 1;
1033*77c1e3ccSAndroid Build Coastguard Worker 
1034*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.dual_sgr_penalty_level = 1;
1035*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.enable_sgr_ep_pruning = 1;
1036*77c1e3ccSAndroid Build Coastguard Worker 
1037*77c1e3ccSAndroid Build Coastguard Worker     // TODO(any, yunqing): move this feature to speed 0.
1038*77c1e3ccSAndroid Build Coastguard Worker     sf->tpl_sf.skip_alike_starting_mv = 1;
1039*77c1e3ccSAndroid Build Coastguard Worker   }
1040*77c1e3ccSAndroid Build Coastguard Worker 
1041*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 2) {
1042*77c1e3ccSAndroid Build Coastguard Worker     sf->hl_sf.recode_loop = ALLOW_RECODE_KFARFGF;
1043*77c1e3ccSAndroid Build Coastguard Worker 
1044*77c1e3ccSAndroid Build Coastguard Worker     sf->fp_sf.skip_motion_search_threshold = 25;
1045*77c1e3ccSAndroid Build Coastguard Worker 
1046*77c1e3ccSAndroid Build Coastguard Worker     sf->gm_sf.num_refinement_steps = 2;
1047*77c1e3ccSAndroid Build Coastguard Worker 
1048*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.reuse_best_prediction_for_part_ab =
1049*77c1e3ccSAndroid Build Coastguard Worker         !frame_is_intra_only(&cpi->common);
1050*77c1e3ccSAndroid Build Coastguard Worker 
1051*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.simple_motion_subpel_force_stop = QUARTER_PEL;
1052*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.subpel_iters_per_step = 1;
1053*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.reduce_search_range = 1;
1054*77c1e3ccSAndroid Build Coastguard Worker 
1055*77c1e3ccSAndroid Build Coastguard Worker     // TODO([email protected]): We can get 10% speed up if we move
1056*77c1e3ccSAndroid Build Coastguard Worker     // adaptive_rd_thresh to speed 1. But currently it performs poorly on some
1057*77c1e3ccSAndroid Build Coastguard Worker     // clips (e.g. 5% loss on dinner_1080p). We need to examine the sequence a
1058*77c1e3ccSAndroid Build Coastguard Worker     // bit more closely to figure out why.
1059*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.adaptive_rd_thresh = 1;
1060*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.disable_interinter_wedge_var_thresh = 100;
1061*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.fast_interintra_wedge_search = 1;
1062*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.prune_comp_search_by_single_result = boosted ? 4 : 1;
1063*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.prune_ext_comp_using_neighbors = 1;
1064*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.prune_comp_using_best_single_mode_ref = 2;
1065*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.prune_comp_type_by_comp_avg = 2;
1066*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.selective_ref_frame = 3;
1067*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.use_dist_wtd_comp_flag = DIST_WTD_COMP_DISABLED;
1068*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.enable_fast_compound_mode_search = 1;
1069*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.reuse_mask_search_results = 1;
1070*77c1e3ccSAndroid Build Coastguard Worker     set_txfm_rd_gate_level(sf->inter_sf.txfm_rd_gate_level, boosted ? 0 : 1);
1071*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.inter_mode_txfm_breakout = boosted ? 0 : 1;
1072*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.alt_ref_search_fp = 1;
1073*77c1e3ccSAndroid Build Coastguard Worker 
1074*77c1e3ccSAndroid Build Coastguard Worker     sf->interp_sf.adaptive_interp_filter_search = 1;
1075*77c1e3ccSAndroid Build Coastguard Worker     sf->interp_sf.disable_dual_filter = 1;
1076*77c1e3ccSAndroid Build Coastguard Worker 
1077*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.disable_smooth_intra =
1078*77c1e3ccSAndroid Build Coastguard Worker         !frame_is_intra_only(&cpi->common) || (cpi->rc.frames_to_key > 1);
1079*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.intra_pruning_with_hog = 2;
1080*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.skip_intra_in_interframe = is_inter_frame ? 2 : 1;
1081*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.skip_filter_intra_in_inter_frames = 1;
1082*77c1e3ccSAndroid Build Coastguard Worker 
1083*77c1e3ccSAndroid Build Coastguard Worker     sf->tpl_sf.prune_starting_mv = 1;
1084*77c1e3ccSAndroid Build Coastguard Worker     sf->tpl_sf.search_method = DIAMOND;
1085*77c1e3ccSAndroid Build Coastguard Worker 
1086*77c1e3ccSAndroid Build Coastguard Worker     sf->rd_sf.perform_coeff_opt = is_boosted_arf2_bwd_type ? 3 : 4;
1087*77c1e3ccSAndroid Build Coastguard Worker     sf->rd_sf.use_mb_rd_hash = 1;
1088*77c1e3ccSAndroid Build Coastguard Worker 
1089*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.prune_wiener_based_on_src_var = 1;
1090*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.prune_sgr_based_on_wiener = 1;
1091*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.disable_loop_restoration_chroma = boosted ? 0 : 1;
1092*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.reduce_wiener_window_size = boosted ? 0 : 1;
1093*77c1e3ccSAndroid Build Coastguard Worker 
1094*77c1e3ccSAndroid Build Coastguard Worker     // TODO(any): Re-evaluate this feature set to 1 in speed 2.
1095*77c1e3ccSAndroid Build Coastguard Worker     sf->tpl_sf.allow_compound_pred = 0;
1096*77c1e3ccSAndroid Build Coastguard Worker     sf->tpl_sf.prune_ref_frames_in_tpl = 1;
1097*77c1e3ccSAndroid Build Coastguard Worker   }
1098*77c1e3ccSAndroid Build Coastguard Worker 
1099*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 3) {
1100*77c1e3ccSAndroid Build Coastguard Worker     sf->hl_sf.high_precision_mv_usage = CURRENT_Q;
1101*77c1e3ccSAndroid Build Coastguard Worker 
1102*77c1e3ccSAndroid Build Coastguard Worker     sf->gm_sf.prune_ref_frame_for_gm_search = 1;
1103*77c1e3ccSAndroid Build Coastguard Worker     sf->gm_sf.prune_zero_mv_with_sse = 1;
1104*77c1e3ccSAndroid Build Coastguard Worker     sf->gm_sf.num_refinement_steps = 0;
1105*77c1e3ccSAndroid Build Coastguard Worker 
1106*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.less_rectangular_check_level = 2;
1107*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.simple_motion_search_prune_agg =
1108*77c1e3ccSAndroid Build Coastguard Worker         allow_screen_content_tools
1109*77c1e3ccSAndroid Build Coastguard Worker             ? SIMPLE_AGG_LVL0
1110*77c1e3ccSAndroid Build Coastguard Worker             : (boosted ? SIMPLE_AGG_LVL1 : QIDX_BASED_AGG_LVL1);
1111*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.prune_ext_part_using_split_info = 1;
1112*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.simple_motion_search_rect_split = 1;
1113*77c1e3ccSAndroid Build Coastguard Worker 
1114*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.full_pixel_search_level = 1;
1115*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED;
1116*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.search_method = DIAMOND;
1117*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.disable_second_mv = 2;
1118*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.prune_mesh_search = PRUNE_MESH_SEARCH_LVL_1;
1119*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.use_intrabc = 0;
1120*77c1e3ccSAndroid Build Coastguard Worker 
1121*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.disable_interinter_wedge_newmv_search = boosted ? 0 : 1;
1122*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.mv_cost_upd_level = INTERNAL_COST_UPD_SBROW;
1123*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.disable_onesided_comp = 1;
1124*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.disable_interintra_wedge_var_thresh = UINT_MAX;
1125*77c1e3ccSAndroid Build Coastguard Worker     // TODO(any): Experiment with the early exit mechanism for speeds 0, 1 and 2
1126*77c1e3ccSAndroid Build Coastguard Worker     // and clean-up the speed feature
1127*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.perform_best_rd_based_gating_for_chroma = 1;
1128*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.prune_inter_modes_based_on_tpl = boosted ? 0 : 1;
1129*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.prune_comp_search_by_single_result = boosted ? 4 : 2;
1130*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.selective_ref_frame = 5;
1131*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.reuse_compound_type_decision = 1;
1132*77c1e3ccSAndroid Build Coastguard Worker     set_txfm_rd_gate_level(sf->inter_sf.txfm_rd_gate_level,
1133*77c1e3ccSAndroid Build Coastguard Worker                            boosted ? 0 : (is_boosted_arf2_bwd_type ? 1 : 2));
1134*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.inter_mode_txfm_breakout = boosted ? 0 : 2;
1135*77c1e3ccSAndroid Build Coastguard Worker 
1136*77c1e3ccSAndroid Build Coastguard Worker     sf->interp_sf.adaptive_interp_filter_search = 2;
1137*77c1e3ccSAndroid Build Coastguard Worker 
1138*77c1e3ccSAndroid Build Coastguard Worker     // TODO([email protected]): the thresholds chosen for intra hog are
1139*77c1e3ccSAndroid Build Coastguard Worker     // inherited directly from luma hog with some minor tweaking. Eventually we
1140*77c1e3ccSAndroid Build Coastguard Worker     // should run this with a bayesian optimizer to find the Pareto frontier.
1141*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.chroma_intra_pruning_with_hog = 2;
1142*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.intra_pruning_with_hog = 3;
1143*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.prune_palette_search_level = 2;
1144*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.top_intra_model_count_allowed = 2;
1145*77c1e3ccSAndroid Build Coastguard Worker 
1146*77c1e3ccSAndroid Build Coastguard Worker     sf->tpl_sf.prune_starting_mv = 2;
1147*77c1e3ccSAndroid Build Coastguard Worker     sf->tpl_sf.skip_alike_starting_mv = 2;
1148*77c1e3ccSAndroid Build Coastguard Worker     sf->tpl_sf.prune_intra_modes = 1;
1149*77c1e3ccSAndroid Build Coastguard Worker     sf->tpl_sf.reduce_first_step_size = 6;
1150*77c1e3ccSAndroid Build Coastguard Worker     sf->tpl_sf.subpel_force_stop = QUARTER_PEL;
1151*77c1e3ccSAndroid Build Coastguard Worker     sf->tpl_sf.gop_length_decision_method = 1;
1152*77c1e3ccSAndroid Build Coastguard Worker 
1153*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.adaptive_txb_search_level = boosted ? 2 : 3;
1154*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.tx_type_search.use_skip_flag_prediction = 2;
1155*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.tx_type_search.prune_2d_txfm_mode = TX_TYPE_PRUNE_3;
1156*77c1e3ccSAndroid Build Coastguard Worker 
1157*77c1e3ccSAndroid Build Coastguard Worker     // TODO(any): Refactor the code related to following winner mode speed
1158*77c1e3ccSAndroid Build Coastguard Worker     // features
1159*77c1e3ccSAndroid Build Coastguard Worker     sf->winner_mode_sf.enable_winner_mode_for_coeff_opt = 1;
1160*77c1e3ccSAndroid Build Coastguard Worker     sf->winner_mode_sf.enable_winner_mode_for_use_tx_domain_dist = 1;
1161*77c1e3ccSAndroid Build Coastguard Worker     sf->winner_mode_sf.motion_mode_for_winner_cand =
1162*77c1e3ccSAndroid Build Coastguard Worker         boosted                                                          ? 0
1163*77c1e3ccSAndroid Build Coastguard Worker         : gf_group->update_type[cpi->gf_frame_index] == INTNL_ARF_UPDATE ? 1
1164*77c1e3ccSAndroid Build Coastguard Worker                                                                          : 2;
1165*77c1e3ccSAndroid Build Coastguard Worker     sf->winner_mode_sf.prune_winner_mode_eval_level = boosted ? 0 : 4;
1166*77c1e3ccSAndroid Build Coastguard Worker 
1167*77c1e3ccSAndroid Build Coastguard Worker     // For screen content, "prune_sgr_based_on_wiener = 2" cause large quality
1168*77c1e3ccSAndroid Build Coastguard Worker     // loss.
1169*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.prune_sgr_based_on_wiener = allow_screen_content_tools ? 1 : 2;
1170*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.prune_wiener_based_on_src_var = 2;
1171*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.use_coarse_filter_level_search =
1172*77c1e3ccSAndroid Build Coastguard Worker         frame_is_intra_only(&cpi->common) ? 0 : 1;
1173*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.use_downsampled_wiener_stats = 1;
1174*77c1e3ccSAndroid Build Coastguard Worker   }
1175*77c1e3ccSAndroid Build Coastguard Worker 
1176*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 4) {
1177*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
1178*77c1e3ccSAndroid Build Coastguard Worker 
1179*77c1e3ccSAndroid Build Coastguard Worker     sf->gm_sf.prune_zero_mv_with_sse = 2;
1180*77c1e3ccSAndroid Build Coastguard Worker     sf->gm_sf.downsample_level = 1;
1181*77c1e3ccSAndroid Build Coastguard Worker 
1182*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.simple_motion_search_prune_agg =
1183*77c1e3ccSAndroid Build Coastguard Worker         allow_screen_content_tools ? SIMPLE_AGG_LVL0 : SIMPLE_AGG_LVL2;
1184*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.simple_motion_search_reduce_search_steps = 4;
1185*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.prune_ext_part_using_split_info = 2;
1186*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.ml_predict_breakout_level = 3;
1187*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.prune_rectangular_split_based_on_qidx =
1188*77c1e3ccSAndroid Build Coastguard Worker         (allow_screen_content_tools || frame_is_intra_only(&cpi->common)) ? 0
1189*77c1e3ccSAndroid Build Coastguard Worker                                                                           : 1;
1190*77c1e3ccSAndroid Build Coastguard Worker 
1191*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.alt_ref_search_fp = 2;
1192*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.txfm_rd_gate_level[TX_SEARCH_DEFAULT] = boosted ? 0 : 3;
1193*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.txfm_rd_gate_level[TX_SEARCH_MOTION_MODE] = boosted ? 0 : 5;
1194*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.txfm_rd_gate_level[TX_SEARCH_COMP_TYPE_MODE] = boosted ? 0 : 3;
1195*77c1e3ccSAndroid Build Coastguard Worker 
1196*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.prune_inter_modes_based_on_tpl = boosted ? 0 : 2;
1197*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.prune_ext_comp_using_neighbors = 2;
1198*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.prune_obmc_prob_thresh = INT_MAX;
1199*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.disable_interinter_wedge_var_thresh = UINT_MAX;
1200*77c1e3ccSAndroid Build Coastguard Worker 
1201*77c1e3ccSAndroid Build Coastguard Worker     sf->interp_sf.cb_pred_filter_search = 1;
1202*77c1e3ccSAndroid Build Coastguard Worker     sf->interp_sf.skip_sharp_interp_filter_search = 1;
1203*77c1e3ccSAndroid Build Coastguard Worker     sf->interp_sf.use_interp_filter = 2;
1204*77c1e3ccSAndroid Build Coastguard Worker 
1205*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.intra_uv_mode_mask[TX_16X16] = UV_INTRA_DC_H_V_CFL;
1206*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.intra_uv_mode_mask[TX_32X32] = UV_INTRA_DC_H_V_CFL;
1207*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.intra_uv_mode_mask[TX_64X64] = UV_INTRA_DC_H_V_CFL;
1208*77c1e3ccSAndroid Build Coastguard Worker     // TODO(any): "intra_y_mode_mask" doesn't help much at speed 4.
1209*77c1e3ccSAndroid Build Coastguard Worker     // sf->intra_sf.intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
1210*77c1e3ccSAndroid Build Coastguard Worker     // sf->intra_sf.intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
1211*77c1e3ccSAndroid Build Coastguard Worker     // sf->intra_sf.intra_y_mode_mask[TX_64X64] = INTRA_DC_H_V;
1212*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.skip_intra_in_interframe = 4;
1213*77c1e3ccSAndroid Build Coastguard Worker 
1214*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.simple_motion_subpel_force_stop = HALF_PEL;
1215*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.prune_mesh_search = PRUNE_MESH_SEARCH_LVL_2;
1216*77c1e3ccSAndroid Build Coastguard Worker 
1217*77c1e3ccSAndroid Build Coastguard Worker     sf->tpl_sf.subpel_force_stop = HALF_PEL;
1218*77c1e3ccSAndroid Build Coastguard Worker     sf->tpl_sf.search_method = FAST_BIGDIA;
1219*77c1e3ccSAndroid Build Coastguard Worker     sf->tpl_sf.use_sad_for_mode_decision = 1;
1220*77c1e3ccSAndroid Build Coastguard Worker 
1221*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.tx_type_search.fast_intra_tx_type_search = 1;
1222*77c1e3ccSAndroid Build Coastguard Worker 
1223*77c1e3ccSAndroid Build Coastguard Worker     sf->rd_sf.perform_coeff_opt = is_boosted_arf2_bwd_type ? 5 : 7;
1224*77c1e3ccSAndroid Build Coastguard Worker 
1225*77c1e3ccSAndroid Build Coastguard Worker     // TODO(any): Extend multi-winner mode processing support for inter frames
1226*77c1e3ccSAndroid Build Coastguard Worker     sf->winner_mode_sf.multi_winner_mode_type =
1227*77c1e3ccSAndroid Build Coastguard Worker         frame_is_intra_only(&cpi->common) ? MULTI_WINNER_MODE_DEFAULT
1228*77c1e3ccSAndroid Build Coastguard Worker                                           : MULTI_WINNER_MODE_OFF;
1229*77c1e3ccSAndroid Build Coastguard Worker     sf->winner_mode_sf.dc_blk_pred_level = boosted ? 0 : 2;
1230*77c1e3ccSAndroid Build Coastguard Worker 
1231*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.lpf_pick = LPF_PICK_FROM_FULL_IMAGE_NON_DUAL;
1232*77c1e3ccSAndroid Build Coastguard Worker   }
1233*77c1e3ccSAndroid Build Coastguard Worker 
1234*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 5) {
1235*77c1e3ccSAndroid Build Coastguard Worker     sf->hl_sf.weight_calc_level_in_tf = 1;
1236*77c1e3ccSAndroid Build Coastguard Worker     sf->hl_sf.adjust_num_frames_for_arf_filtering =
1237*77c1e3ccSAndroid Build Coastguard Worker         allow_screen_content_tools ? 0 : 2;
1238*77c1e3ccSAndroid Build Coastguard Worker 
1239*77c1e3ccSAndroid Build Coastguard Worker     sf->fp_sf.reduce_mv_step_param = 4;
1240*77c1e3ccSAndroid Build Coastguard Worker 
1241*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.simple_motion_search_prune_agg =
1242*77c1e3ccSAndroid Build Coastguard Worker         allow_screen_content_tools ? SIMPLE_AGG_LVL0 : SIMPLE_AGG_LVL3;
1243*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.ext_partition_eval_thresh =
1244*77c1e3ccSAndroid Build Coastguard Worker         allow_screen_content_tools ? BLOCK_8X8 : BLOCK_16X16;
1245*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.prune_sub_8x8_partition_level =
1246*77c1e3ccSAndroid Build Coastguard Worker         allow_screen_content_tools ? 1 : 2;
1247*77c1e3ccSAndroid Build Coastguard Worker 
1248*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.warp_search_method = WARP_SEARCH_DIAMOND;
1249*77c1e3ccSAndroid Build Coastguard Worker 
1250*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.prune_inter_modes_if_skippable = 1;
1251*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.prune_single_ref = is_boosted_arf2_bwd_type ? 0 : 1;
1252*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.txfm_rd_gate_level[TX_SEARCH_DEFAULT] = boosted ? 0 : 4;
1253*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.txfm_rd_gate_level[TX_SEARCH_COMP_TYPE_MODE] = boosted ? 0 : 5;
1254*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.enable_fast_compound_mode_search = 2;
1255*77c1e3ccSAndroid Build Coastguard Worker 
1256*77c1e3ccSAndroid Build Coastguard Worker     sf->interp_sf.skip_interp_filter_search = boosted ? 0 : 1;
1257*77c1e3ccSAndroid Build Coastguard Worker 
1258*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.chroma_intra_pruning_with_hog = 3;
1259*77c1e3ccSAndroid Build Coastguard Worker 
1260*77c1e3ccSAndroid Build Coastguard Worker     // TODO(any): Extend multi-winner mode processing support for inter frames
1261*77c1e3ccSAndroid Build Coastguard Worker     sf->winner_mode_sf.multi_winner_mode_type =
1262*77c1e3ccSAndroid Build Coastguard Worker         frame_is_intra_only(&cpi->common) ? MULTI_WINNER_MODE_FAST
1263*77c1e3ccSAndroid Build Coastguard Worker                                           : MULTI_WINNER_MODE_OFF;
1264*77c1e3ccSAndroid Build Coastguard Worker 
1265*77c1e3ccSAndroid Build Coastguard Worker     // Disable Self-guided Loop restoration filter.
1266*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.disable_sgr_filter = true;
1267*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.disable_wiener_coeff_refine_search = true;
1268*77c1e3ccSAndroid Build Coastguard Worker 
1269*77c1e3ccSAndroid Build Coastguard Worker     sf->tpl_sf.prune_starting_mv = 3;
1270*77c1e3ccSAndroid Build Coastguard Worker     sf->tpl_sf.use_y_only_rate_distortion = 1;
1271*77c1e3ccSAndroid Build Coastguard Worker     sf->tpl_sf.subpel_force_stop = FULL_PEL;
1272*77c1e3ccSAndroid Build Coastguard Worker     sf->tpl_sf.gop_length_decision_method = 2;
1273*77c1e3ccSAndroid Build Coastguard Worker     sf->tpl_sf.use_sad_for_mode_decision = 2;
1274*77c1e3ccSAndroid Build Coastguard Worker 
1275*77c1e3ccSAndroid Build Coastguard Worker     sf->winner_mode_sf.dc_blk_pred_level = 2;
1276*77c1e3ccSAndroid Build Coastguard Worker 
1277*77c1e3ccSAndroid Build Coastguard Worker     sf->fp_sf.disable_recon = 1;
1278*77c1e3ccSAndroid Build Coastguard Worker   }
1279*77c1e3ccSAndroid Build Coastguard Worker 
1280*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 6) {
1281*77c1e3ccSAndroid Build Coastguard Worker     sf->hl_sf.disable_extra_sc_testing = 1;
1282*77c1e3ccSAndroid Build Coastguard Worker     sf->hl_sf.second_alt_ref_filtering = 0;
1283*77c1e3ccSAndroid Build Coastguard Worker 
1284*77c1e3ccSAndroid Build Coastguard Worker     sf->gm_sf.downsample_level = 2;
1285*77c1e3ccSAndroid Build Coastguard Worker 
1286*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.prune_inter_modes_based_on_tpl = boosted ? 0 : 3;
1287*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.selective_ref_frame = 6;
1288*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.prune_single_ref = is_boosted_arf2_bwd_type ? 0 : 2;
1289*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.prune_ext_comp_using_neighbors = 3;
1290*77c1e3ccSAndroid Build Coastguard Worker 
1291*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.chroma_intra_pruning_with_hog = 4;
1292*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.intra_pruning_with_hog = 4;
1293*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.intra_uv_mode_mask[TX_32X32] = UV_INTRA_DC;
1294*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.intra_uv_mode_mask[TX_64X64] = UV_INTRA_DC;
1295*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.intra_y_mode_mask[TX_32X32] = INTRA_DC;
1296*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.intra_y_mode_mask[TX_64X64] = INTRA_DC;
1297*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.early_term_chroma_palette_size_search = 1;
1298*77c1e3ccSAndroid Build Coastguard Worker 
1299*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.prune_rectangular_split_based_on_qidx =
1300*77c1e3ccSAndroid Build Coastguard Worker         boosted || allow_screen_content_tools ? 0 : 2;
1301*77c1e3ccSAndroid Build Coastguard Worker 
1302*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.prune_part4_search = 3;
1303*77c1e3ccSAndroid Build Coastguard Worker 
1304*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.simple_motion_subpel_force_stop = FULL_PEL;
1305*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.use_bsize_dependent_search_method = 1;
1306*77c1e3ccSAndroid Build Coastguard Worker 
1307*77c1e3ccSAndroid Build Coastguard Worker     sf->tpl_sf.gop_length_decision_method = 3;
1308*77c1e3ccSAndroid Build Coastguard Worker 
1309*77c1e3ccSAndroid Build Coastguard Worker     sf->rd_sf.perform_coeff_opt = is_boosted_arf2_bwd_type ? 6 : 8;
1310*77c1e3ccSAndroid Build Coastguard Worker 
1311*77c1e3ccSAndroid Build Coastguard Worker     sf->winner_mode_sf.dc_blk_pred_level = 3;
1312*77c1e3ccSAndroid Build Coastguard Worker     sf->winner_mode_sf.multi_winner_mode_type = MULTI_WINNER_MODE_OFF;
1313*77c1e3ccSAndroid Build Coastguard Worker 
1314*77c1e3ccSAndroid Build Coastguard Worker     sf->fp_sf.skip_zeromv_motion_search = 1;
1315*77c1e3ccSAndroid Build Coastguard Worker   }
1316*77c1e3ccSAndroid Build Coastguard Worker }
1317*77c1e3ccSAndroid Build Coastguard Worker 
set_rt_speed_feature_framesize_dependent(const AV1_COMP * const cpi,SPEED_FEATURES * const sf,int speed)1318*77c1e3ccSAndroid Build Coastguard Worker static void set_rt_speed_feature_framesize_dependent(const AV1_COMP *const cpi,
1319*77c1e3ccSAndroid Build Coastguard Worker                                                      SPEED_FEATURES *const sf,
1320*77c1e3ccSAndroid Build Coastguard Worker                                                      int speed) {
1321*77c1e3ccSAndroid Build Coastguard Worker   const AV1_COMMON *const cm = &cpi->common;
1322*77c1e3ccSAndroid Build Coastguard Worker   const int boosted = frame_is_boosted(cpi);
1323*77c1e3ccSAndroid Build Coastguard Worker   const int is_1080p_or_larger = AOMMIN(cm->width, cm->height) >= 1080;
1324*77c1e3ccSAndroid Build Coastguard Worker   const int is_720p_or_larger = AOMMIN(cm->width, cm->height) >= 720;
1325*77c1e3ccSAndroid Build Coastguard Worker   const int is_480p_or_larger = AOMMIN(cm->width, cm->height) >= 480;
1326*77c1e3ccSAndroid Build Coastguard Worker   const int is_360p_or_larger = AOMMIN(cm->width, cm->height) >= 360;
1327*77c1e3ccSAndroid Build Coastguard Worker 
1328*77c1e3ccSAndroid Build Coastguard Worker   if (!is_360p_or_larger) {
1329*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.prune_intra_mode_based_on_mv_range = 1;
1330*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.prune_inter_modes_wrt_gf_arf_based_on_sad = 1;
1331*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 6)
1332*77c1e3ccSAndroid Build Coastguard Worker       sf->winner_mode_sf.prune_winner_mode_eval_level = boosted ? 0 : 2;
1333*77c1e3ccSAndroid Build Coastguard Worker     if (speed == 7) sf->rt_sf.prefer_large_partition_blocks = 2;
1334*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 7) {
1335*77c1e3ccSAndroid Build Coastguard Worker       sf->lpf_sf.cdef_pick_method = CDEF_PICK_FROM_Q;
1336*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.check_only_zero_zeromv_on_large_blocks = true;
1337*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.use_rtc_tf = 2;
1338*77c1e3ccSAndroid Build Coastguard Worker     }
1339*77c1e3ccSAndroid Build Coastguard Worker     if (speed == 8) sf->rt_sf.prefer_large_partition_blocks = 1;
1340*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 8) {
1341*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.use_nonrd_filter_search = 1;
1342*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.tx_size_level_based_on_qstep = 1;
1343*77c1e3ccSAndroid Build Coastguard Worker     }
1344*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 9) {
1345*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.use_comp_ref_nonrd = 0;
1346*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.nonrd_aggressive_skip = 1;
1347*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.skip_intra_pred = 1;
1348*77c1e3ccSAndroid Build Coastguard Worker       // Only turn on enable_ref_short_signaling for low resolution when only
1349*77c1e3ccSAndroid Build Coastguard Worker       // LAST and GOLDEN ref frames are used.
1350*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.enable_ref_short_signaling =
1351*77c1e3ccSAndroid Build Coastguard Worker           (!sf->rt_sf.use_nonrd_altref_frame &&
1352*77c1e3ccSAndroid Build Coastguard Worker            (!sf->rt_sf.use_comp_ref_nonrd ||
1353*77c1e3ccSAndroid Build Coastguard Worker             (!sf->rt_sf.ref_frame_comp_nonrd[1] &&
1354*77c1e3ccSAndroid Build Coastguard Worker              !sf->rt_sf.ref_frame_comp_nonrd[2])));
1355*77c1e3ccSAndroid Build Coastguard Worker 
1356*77c1e3ccSAndroid Build Coastguard Worker // TODO(kyslov) Re-enable when AV1 models are trained
1357*77c1e3ccSAndroid Build Coastguard Worker #if 0
1358*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_RT_ML_PARTITIONING
1359*77c1e3ccSAndroid Build Coastguard Worker       if (!frame_is_intra_only(cm)) {
1360*77c1e3ccSAndroid Build Coastguard Worker         sf->part_sf.partition_search_type = ML_BASED_PARTITION;
1361*77c1e3ccSAndroid Build Coastguard Worker         sf->rt_sf.reuse_inter_pred_nonrd = 0;
1362*77c1e3ccSAndroid Build Coastguard Worker       }
1363*77c1e3ccSAndroid Build Coastguard Worker #endif
1364*77c1e3ccSAndroid Build Coastguard Worker #endif
1365*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.use_adaptive_subpel_search = false;
1366*77c1e3ccSAndroid Build Coastguard Worker     }
1367*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 10) {
1368*77c1e3ccSAndroid Build Coastguard Worker       // TODO([email protected]): To be conservative, disable
1369*77c1e3ccSAndroid Build Coastguard Worker       // sf->rt_sf.estimate_motion_for_var_based_partition = 3 for speed 10/qvga
1370*77c1e3ccSAndroid Build Coastguard Worker       // for now. May enable it in the future.
1371*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.estimate_motion_for_var_based_partition = 0;
1372*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.skip_intra_pred = 2;
1373*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.hybrid_intra_pickmode = 3;
1374*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.reduce_mv_pel_precision_lowcomplex = 1;
1375*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.reduce_mv_pel_precision_highmotion = 2;
1376*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.use_nonrd_filter_search = 0;
1377*77c1e3ccSAndroid Build Coastguard Worker     }
1378*77c1e3ccSAndroid Build Coastguard Worker   } else {
1379*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.prune_intra_mode_based_on_mv_range = 2;
1380*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.skip_filter_intra_in_inter_frames = 1;
1381*77c1e3ccSAndroid Build Coastguard Worker     if (speed <= 5) {
1382*77c1e3ccSAndroid Build Coastguard Worker       sf->tx_sf.tx_type_search.fast_inter_tx_type_prob_thresh =
1383*77c1e3ccSAndroid Build Coastguard Worker           boosted ? INT_MAX : 350;
1384*77c1e3ccSAndroid Build Coastguard Worker       sf->winner_mode_sf.prune_winner_mode_eval_level = boosted ? 0 : 2;
1385*77c1e3ccSAndroid Build Coastguard Worker     }
1386*77c1e3ccSAndroid Build Coastguard Worker     if (speed == 6) sf->part_sf.disable_8x8_part_based_on_qidx = 1;
1387*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 6) sf->rt_sf.skip_newmv_mode_based_on_sse = 2;
1388*77c1e3ccSAndroid Build Coastguard Worker     if (speed == 7) {
1389*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.prefer_large_partition_blocks = 1;
1390*77c1e3ccSAndroid Build Coastguard Worker       // Enable this feature for [360p, 720p] resolution range initially.
1391*77c1e3ccSAndroid Build Coastguard Worker       // Only enable for low bitdepth to mitigate issue: b/303023614.
1392*77c1e3ccSAndroid Build Coastguard Worker       if (!cpi->rc.rtc_external_ratectrl &&
1393*77c1e3ccSAndroid Build Coastguard Worker           AOMMIN(cm->width, cm->height) <= 720 && !cpi->oxcf.use_highbitdepth)
1394*77c1e3ccSAndroid Build Coastguard Worker         sf->hl_sf.accurate_bit_estimate = cpi->oxcf.q_cfg.aq_mode == NO_AQ;
1395*77c1e3ccSAndroid Build Coastguard Worker     }
1396*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 7) {
1397*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.use_rtc_tf = 1;
1398*77c1e3ccSAndroid Build Coastguard Worker     }
1399*77c1e3ccSAndroid Build Coastguard Worker     if (speed == 8 && !cpi->ppi->use_svc) {
1400*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.short_circuit_low_temp_var = 0;
1401*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.use_nonrd_altref_frame = 1;
1402*77c1e3ccSAndroid Build Coastguard Worker     }
1403*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 8) sf->rt_sf.tx_size_level_based_on_qstep = 2;
1404*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 9) {
1405*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.gf_length_lvl = 1;
1406*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.skip_cdef_sb = 1;
1407*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.sad_based_adp_altref_lag = 2;
1408*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.reduce_mv_pel_precision_highmotion = 2;
1409*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.use_adaptive_subpel_search = true;
1410*77c1e3ccSAndroid Build Coastguard Worker       sf->interp_sf.cb_pred_filter_search = 1;
1411*77c1e3ccSAndroid Build Coastguard Worker     }
1412*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 10) {
1413*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.hybrid_intra_pickmode = 2;
1414*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.sad_based_adp_altref_lag = 4;
1415*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.tx_size_level_based_on_qstep = 0;
1416*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.reduce_mv_pel_precision_highmotion = 3;
1417*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.use_adaptive_subpel_search = false;
1418*77c1e3ccSAndroid Build Coastguard Worker       sf->interp_sf.cb_pred_filter_search = 2;
1419*77c1e3ccSAndroid Build Coastguard Worker     }
1420*77c1e3ccSAndroid Build Coastguard Worker   }
1421*77c1e3ccSAndroid Build Coastguard Worker   if (!is_480p_or_larger) {
1422*77c1e3ccSAndroid Build Coastguard Worker     if (speed == 7) {
1423*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.nonrd_check_partition_merge_mode = 2;
1424*77c1e3ccSAndroid Build Coastguard Worker     }
1425*77c1e3ccSAndroid Build Coastguard Worker   }
1426*77c1e3ccSAndroid Build Coastguard Worker   if (!is_720p_or_larger) {
1427*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 9) {
1428*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.force_large_partition_blocks_intra = 1;
1429*77c1e3ccSAndroid Build Coastguard Worker     }
1430*77c1e3ccSAndroid Build Coastguard Worker   } else {
1431*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 6) sf->rt_sf.skip_newmv_mode_based_on_sse = 3;
1432*77c1e3ccSAndroid Build Coastguard Worker     if (speed == 7) sf->rt_sf.prefer_large_partition_blocks = 0;
1433*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 7) {
1434*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.reduce_mv_pel_precision_lowcomplex = 2;
1435*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.reduce_mv_pel_precision_highmotion = 1;
1436*77c1e3ccSAndroid Build Coastguard Worker     }
1437*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 9) {
1438*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.sad_based_adp_altref_lag = 1;
1439*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.reduce_mv_pel_precision_lowcomplex = 0;
1440*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.reduce_mv_pel_precision_highmotion = 2;
1441*77c1e3ccSAndroid Build Coastguard Worker     }
1442*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 10) {
1443*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.sad_based_adp_altref_lag = 3;
1444*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.reduce_mv_pel_precision_highmotion = 3;
1445*77c1e3ccSAndroid Build Coastguard Worker     }
1446*77c1e3ccSAndroid Build Coastguard Worker   }
1447*77c1e3ccSAndroid Build Coastguard Worker   // TODO(Any): Check/Tune settings of other sfs for 1080p.
1448*77c1e3ccSAndroid Build Coastguard Worker   if (is_1080p_or_larger) {
1449*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 7) {
1450*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.reduce_mv_pel_precision_highmotion = 0;
1451*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.use_adaptive_subpel_search = 0;
1452*77c1e3ccSAndroid Build Coastguard Worker     }
1453*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 9) sf->interp_sf.cb_pred_filter_search = 0;
1454*77c1e3ccSAndroid Build Coastguard Worker   } else {
1455*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 9) sf->lpf_sf.cdef_pick_method = CDEF_PICK_FROM_Q;
1456*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 10) sf->rt_sf.nonrd_aggressive_skip = 1;
1457*77c1e3ccSAndroid Build Coastguard Worker   }
1458*77c1e3ccSAndroid Build Coastguard Worker   // TODO(marpan): Tune settings for speed 11 video mode,
1459*77c1e3ccSAndroid Build Coastguard Worker   // for resolutions below 720p.
1460*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 11 && !is_720p_or_larger &&
1461*77c1e3ccSAndroid Build Coastguard Worker       cpi->oxcf.tune_cfg.content != AOM_CONTENT_SCREEN) {
1462*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.skip_cdef_sb = 1;
1463*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.force_only_last_ref = 1;
1464*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.selective_cdf_update = 1;
1465*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.use_nonrd_filter_search = 0;
1466*77c1e3ccSAndroid Build Coastguard Worker     if (is_360p_or_larger) {
1467*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.fixed_partition_size = BLOCK_32X32;
1468*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.use_fast_fixed_part = 1;
1469*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.reduce_mv_pel_precision_lowcomplex = 2;
1470*77c1e3ccSAndroid Build Coastguard Worker     }
1471*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.increase_source_sad_thresh = 1;
1472*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.part_early_exit_zeromv = 2;
1473*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.set_zeromv_skip_based_on_source_sad = 2;
1474*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < BLOCK_SIZES; ++i) {
1475*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.intra_y_mode_bsize_mask_nrd[i] = INTRA_DC;
1476*77c1e3ccSAndroid Build Coastguard Worker     }
1477*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.hybrid_intra_pickmode = 0;
1478*77c1e3ccSAndroid Build Coastguard Worker   }
1479*77c1e3ccSAndroid Build Coastguard Worker   // Setting for SVC, or when the ref_frame_config control is
1480*77c1e3ccSAndroid Build Coastguard Worker   // used to set the reference structure.
1481*77c1e3ccSAndroid Build Coastguard Worker   if (cpi->ppi->use_svc || cpi->ppi->rtc_ref.set_ref_frame_config) {
1482*77c1e3ccSAndroid Build Coastguard Worker     const RTC_REF *const rtc_ref = &cpi->ppi->rtc_ref;
1483*77c1e3ccSAndroid Build Coastguard Worker     // For SVC: for greater than 2 temporal layers, use better mv search on
1484*77c1e3ccSAndroid Build Coastguard Worker     // base temporal layers, and only on base spatial layer if highest
1485*77c1e3ccSAndroid Build Coastguard Worker     // resolution is above 640x360.
1486*77c1e3ccSAndroid Build Coastguard Worker     if (cpi->svc.number_temporal_layers >= 2 &&
1487*77c1e3ccSAndroid Build Coastguard Worker         cpi->svc.temporal_layer_id == 0 &&
1488*77c1e3ccSAndroid Build Coastguard Worker         (cpi->svc.spatial_layer_id == 0 ||
1489*77c1e3ccSAndroid Build Coastguard Worker          cpi->oxcf.frm_dim_cfg.width * cpi->oxcf.frm_dim_cfg.height <=
1490*77c1e3ccSAndroid Build Coastguard Worker              640 * 360)) {
1491*77c1e3ccSAndroid Build Coastguard Worker       sf->mv_sf.search_method = NSTEP;
1492*77c1e3ccSAndroid Build Coastguard Worker       sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED;
1493*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.fullpel_search_step_param = 10;
1494*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.reduce_mv_pel_precision_highmotion = 0;
1495*77c1e3ccSAndroid Build Coastguard Worker       if (cm->width * cm->height <= 352 * 288)
1496*77c1e3ccSAndroid Build Coastguard Worker         sf->rt_sf.nonrd_prune_ref_frame_search = 2;
1497*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.force_large_partition_blocks_intra = 0;
1498*77c1e3ccSAndroid Build Coastguard Worker     }
1499*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 8) {
1500*77c1e3ccSAndroid Build Coastguard Worker       if (cpi->svc.number_temporal_layers > 2)
1501*77c1e3ccSAndroid Build Coastguard Worker         sf->rt_sf.disable_cdf_update_non_reference_frame = true;
1502*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.reduce_mv_pel_precision_highmotion = 3;
1503*77c1e3ccSAndroid Build Coastguard Worker       if (rtc_ref->non_reference_frame) {
1504*77c1e3ccSAndroid Build Coastguard Worker         sf->rt_sf.nonrd_aggressive_skip = 1;
1505*77c1e3ccSAndroid Build Coastguard Worker         sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
1506*77c1e3ccSAndroid Build Coastguard Worker       }
1507*77c1e3ccSAndroid Build Coastguard Worker     }
1508*77c1e3ccSAndroid Build Coastguard Worker     if (speed <= 9 && cpi->svc.number_temporal_layers > 2 &&
1509*77c1e3ccSAndroid Build Coastguard Worker         cpi->svc.temporal_layer_id == 0)
1510*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.check_only_zero_zeromv_on_large_blocks = false;
1511*77c1e3ccSAndroid Build Coastguard Worker     else
1512*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.check_only_zero_zeromv_on_large_blocks = true;
1513*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.frame_level_mode_cost_update = false;
1514*77c1e3ccSAndroid Build Coastguard Worker 
1515*77c1e3ccSAndroid Build Coastguard Worker     // Compound mode enabling.
1516*77c1e3ccSAndroid Build Coastguard Worker     if (rtc_ref->ref_frame_comp[0] || rtc_ref->ref_frame_comp[1] ||
1517*77c1e3ccSAndroid Build Coastguard Worker         rtc_ref->ref_frame_comp[2]) {
1518*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.use_comp_ref_nonrd = 1;
1519*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.ref_frame_comp_nonrd[0] =
1520*77c1e3ccSAndroid Build Coastguard Worker           rtc_ref->ref_frame_comp[0] && rtc_ref->reference[GOLDEN_FRAME - 1];
1521*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.ref_frame_comp_nonrd[1] =
1522*77c1e3ccSAndroid Build Coastguard Worker           rtc_ref->ref_frame_comp[1] && rtc_ref->reference[LAST2_FRAME - 1];
1523*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.ref_frame_comp_nonrd[2] =
1524*77c1e3ccSAndroid Build Coastguard Worker           rtc_ref->ref_frame_comp[2] && rtc_ref->reference[ALTREF_FRAME - 1];
1525*77c1e3ccSAndroid Build Coastguard Worker     } else {
1526*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.use_comp_ref_nonrd = 0;
1527*77c1e3ccSAndroid Build Coastguard Worker     }
1528*77c1e3ccSAndroid Build Coastguard Worker 
1529*77c1e3ccSAndroid Build Coastguard Worker     if (cpi->svc.number_spatial_layers > 1 ||
1530*77c1e3ccSAndroid Build Coastguard Worker         cpi->svc.number_temporal_layers > 1)
1531*77c1e3ccSAndroid Build Coastguard Worker       sf->hl_sf.accurate_bit_estimate = 0;
1532*77c1e3ccSAndroid Build Coastguard Worker 
1533*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.estimate_motion_for_var_based_partition = 1;
1534*77c1e3ccSAndroid Build Coastguard Worker 
1535*77c1e3ccSAndroid Build Coastguard Worker     // For single layers RPS: bias/adjustment for recovery frame.
1536*77c1e3ccSAndroid Build Coastguard Worker     if (cpi->ppi->rtc_ref.bias_recovery_frame) {
1537*77c1e3ccSAndroid Build Coastguard Worker       sf->mv_sf.search_method = NSTEP;
1538*77c1e3ccSAndroid Build Coastguard Worker       sf->mv_sf.subpel_search_method = SUBPEL_TREE;
1539*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.fullpel_search_step_param = 8;
1540*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.nonrd_aggressive_skip = 0;
1541*77c1e3ccSAndroid Build Coastguard Worker     }
1542*77c1e3ccSAndroid Build Coastguard Worker   }
1543*77c1e3ccSAndroid Build Coastguard Worker   // Screen settings.
1544*77c1e3ccSAndroid Build Coastguard Worker   if (cpi->oxcf.tune_cfg.content == AOM_CONTENT_SCREEN) {
1545*77c1e3ccSAndroid Build Coastguard Worker     // TODO(marpan): Check settings for speed 7 and 8.
1546*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 7) {
1547*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.reduce_mv_pel_precision_highmotion = 1;
1548*77c1e3ccSAndroid Build Coastguard Worker       sf->mv_sf.use_bsize_dependent_search_method = 0;
1549*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.skip_cdef_sb = 1;
1550*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.increase_color_thresh_palette = 1;
1551*77c1e3ccSAndroid Build Coastguard Worker       if (!frame_is_intra_only(cm)) sf->rt_sf.dct_only_palette_nonrd = 1;
1552*77c1e3ccSAndroid Build Coastguard Worker     }
1553*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 8) {
1554*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.nonrd_check_partition_merge_mode = 3;
1555*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.nonrd_prune_ref_frame_search = 1;
1556*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.use_nonrd_filter_search = 0;
1557*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.prune_hv_pred_modes_using_src_sad = false;
1558*77c1e3ccSAndroid Build Coastguard Worker     }
1559*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 9) {
1560*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.prune_idtx_nonrd = 1;
1561*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.part_early_exit_zeromv = 2;
1562*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.skip_lf_screen = 1;
1563*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.nonrd_prune_ref_frame_search = 3;
1564*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.var_part_split_threshold_shift = 10;
1565*77c1e3ccSAndroid Build Coastguard Worker       sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
1566*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.reduce_mv_pel_precision_highmotion = 3;
1567*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.reduce_mv_pel_precision_lowcomplex = 1;
1568*77c1e3ccSAndroid Build Coastguard Worker       sf->lpf_sf.cdef_pick_method = CDEF_PICK_FROM_Q;
1569*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.nonrd_check_partition_merge_mode = 0;
1570*77c1e3ccSAndroid Build Coastguard Worker       sf->interp_sf.cb_pred_filter_search = 0;
1571*77c1e3ccSAndroid Build Coastguard Worker     }
1572*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 10) {
1573*77c1e3ccSAndroid Build Coastguard Worker       if (cm->width * cm->height > 1920 * 1080)
1574*77c1e3ccSAndroid Build Coastguard Worker         sf->part_sf.disable_8x8_part_based_on_qidx = 1;
1575*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.screen_content_cdef_filter_qindex_thresh = 80;
1576*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.part_early_exit_zeromv = 1;
1577*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.nonrd_aggressive_skip = 1;
1578*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.thresh_active_maps_skip_lf_cdef = 90;
1579*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.hybrid_intra_pickmode = 0;
1580*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.dct_only_palette_nonrd = 1;
1581*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.prune_palette_search_nonrd = 1;
1582*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.prune_intra_mode_using_best_sad_so_far = true;
1583*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.rc_faster_convergence_static = 1;
1584*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.rc_compute_spatial_var_sc = 1;
1585*77c1e3ccSAndroid Build Coastguard Worker     }
1586*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 11) {
1587*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.skip_lf_screen = 2;
1588*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.skip_cdef_sb = 2;
1589*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.prune_palette_search_nonrd = 2;
1590*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.increase_color_thresh_palette = 0;
1591*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.prune_h_pred_using_best_mode_so_far = true;
1592*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.enable_intra_mode_pruning_using_neighbors = true;
1593*77c1e3ccSAndroid Build Coastguard Worker     }
1594*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.skip_encoding_non_reference_slide_change =
1595*77c1e3ccSAndroid Build Coastguard Worker         cpi->oxcf.rc_cfg.drop_frames_water_mark > 0 ? 1 : 0;
1596*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.skip_newmv_flat_blocks_screen = 1;
1597*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.use_idtx_nonrd = 1;
1598*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.higher_thresh_scene_detection = 0;
1599*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.use_nonrd_altref_frame = 0;
1600*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.use_rtc_tf = 0;
1601*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.use_comp_ref_nonrd = 0;
1602*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.source_metrics_sb_nonrd = 1;
1603*77c1e3ccSAndroid Build Coastguard Worker     if (cpi->rc.high_source_sad == 1) {
1604*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.prefer_large_partition_blocks = 0;
1605*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.max_intra_bsize = BLOCK_128X128;
1606*77c1e3ccSAndroid Build Coastguard Worker       for (int i = 0; i < BLOCK_SIZES; ++i) {
1607*77c1e3ccSAndroid Build Coastguard Worker         if (i > BLOCK_32X32)
1608*77c1e3ccSAndroid Build Coastguard Worker           sf->rt_sf.intra_y_mode_bsize_mask_nrd[i] = INTRA_DC;
1609*77c1e3ccSAndroid Build Coastguard Worker         else
1610*77c1e3ccSAndroid Build Coastguard Worker           sf->rt_sf.intra_y_mode_bsize_mask_nrd[i] = INTRA_DC_H_V;
1611*77c1e3ccSAndroid Build Coastguard Worker       }
1612*77c1e3ccSAndroid Build Coastguard Worker     }
1613*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 11 && cpi->rc.high_motion_content_screen_rtc) {
1614*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.higher_thresh_scene_detection = 1;
1615*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.force_only_last_ref = 1;
1616*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.use_nonrd_filter_search = 0;
1617*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.fixed_partition_size = BLOCK_32X32;
1618*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.use_fast_fixed_part = 1;
1619*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.increase_source_sad_thresh = 1;
1620*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.selective_cdf_update = 1;
1621*77c1e3ccSAndroid Build Coastguard Worker       sf->mv_sf.search_method = FAST_DIAMOND;
1622*77c1e3ccSAndroid Build Coastguard Worker     } else if (cpi->rc.max_block_source_sad > 20000 &&
1623*77c1e3ccSAndroid Build Coastguard Worker                cpi->rc.frame_source_sad > 100 && speed >= 6 &&
1624*77c1e3ccSAndroid Build Coastguard Worker                (cpi->rc.percent_blocks_with_motion > 1 ||
1625*77c1e3ccSAndroid Build Coastguard Worker                 cpi->svc.last_layer_dropped[0])) {
1626*77c1e3ccSAndroid Build Coastguard Worker       sf->mv_sf.search_method = NSTEP;
1627*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.fullpel_search_step_param = 2;
1628*77c1e3ccSAndroid Build Coastguard Worker     }
1629*77c1e3ccSAndroid Build Coastguard Worker     if (cpi->rc.high_source_sad && cpi->ppi->rtc_ref.non_reference_frame) {
1630*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.use_idtx_nonrd = 0;
1631*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.prefer_large_partition_blocks = 1;
1632*77c1e3ccSAndroid Build Coastguard Worker       sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
1633*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.fullpel_search_step_param = 10;
1634*77c1e3ccSAndroid Build Coastguard Worker     }
1635*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.partition_direct_merging = 0;
1636*77c1e3ccSAndroid Build Coastguard Worker     sf->hl_sf.accurate_bit_estimate = 0;
1637*77c1e3ccSAndroid Build Coastguard Worker     // This feature is for nonrd_pickmode.
1638*77c1e3ccSAndroid Build Coastguard Worker     if (sf->rt_sf.use_nonrd_pick_mode)
1639*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.estimate_motion_for_var_based_partition = 1;
1640*77c1e3ccSAndroid Build Coastguard Worker     else
1641*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.estimate_motion_for_var_based_partition = 0;
1642*77c1e3ccSAndroid Build Coastguard Worker   }
1643*77c1e3ccSAndroid Build Coastguard Worker   if (is_lossless_requested(&cpi->oxcf.rc_cfg)) {
1644*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.use_rtc_tf = 0;
1645*77c1e3ccSAndroid Build Coastguard Worker     // TODO(aomedia:3412): The setting accurate_bit_estimate = 0
1646*77c1e3ccSAndroid Build Coastguard Worker     // can be removed once it's fixed for lossless mode.
1647*77c1e3ccSAndroid Build Coastguard Worker     sf->hl_sf.accurate_bit_estimate = 0;
1648*77c1e3ccSAndroid Build Coastguard Worker   }
1649*77c1e3ccSAndroid Build Coastguard Worker   if (cpi->oxcf.use_highbitdepth) {
1650*77c1e3ccSAndroid Build Coastguard Worker     // Disable for use_highbitdepth = 1 to mitigate issue: b/303023614.
1651*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.estimate_motion_for_var_based_partition = 0;
1652*77c1e3ccSAndroid Build Coastguard Worker   }
1653*77c1e3ccSAndroid Build Coastguard Worker   if (cpi->oxcf.superres_cfg.enable_superres) {
1654*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.use_rtc_tf = 0;
1655*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.nonrd_prune_ref_frame_search = 1;
1656*77c1e3ccSAndroid Build Coastguard Worker   }
1657*77c1e3ccSAndroid Build Coastguard Worker   // rtc_tf feature allocates new source because of possible
1658*77c1e3ccSAndroid Build Coastguard Worker   // temporal filtering which may change the input source during encoding:
1659*77c1e3ccSAndroid Build Coastguard Worker   // this causes an issue on resized frames when psnr is calculated,
1660*77c1e3ccSAndroid Build Coastguard Worker   // so disable it here for frames that are resized (encoding width/height
1661*77c1e3ccSAndroid Build Coastguard Worker   // different from configured width/height).
1662*77c1e3ccSAndroid Build Coastguard Worker   if (is_psnr_calc_enabled(cpi) && (cpi->oxcf.frm_dim_cfg.width != cm->width ||
1663*77c1e3ccSAndroid Build Coastguard Worker                                     cpi->oxcf.frm_dim_cfg.height != cm->height))
1664*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.use_rtc_tf = 0;
1665*77c1e3ccSAndroid Build Coastguard Worker }
1666*77c1e3ccSAndroid Build Coastguard Worker 
1667*77c1e3ccSAndroid Build Coastguard Worker // TODO(kyslov): now this is very similar to
1668*77c1e3ccSAndroid Build Coastguard Worker // set_good_speed_features_framesize_independent
1669*77c1e3ccSAndroid Build Coastguard Worker // except it sets non-rd flag on speed 8. This function will likely
1670*77c1e3ccSAndroid Build Coastguard Worker // be modified in the future with RT-specific speed features.
set_rt_speed_features_framesize_independent(AV1_COMP * cpi,SPEED_FEATURES * sf,int speed)1671*77c1e3ccSAndroid Build Coastguard Worker static void set_rt_speed_features_framesize_independent(AV1_COMP *cpi,
1672*77c1e3ccSAndroid Build Coastguard Worker                                                         SPEED_FEATURES *sf,
1673*77c1e3ccSAndroid Build Coastguard Worker                                                         int speed) {
1674*77c1e3ccSAndroid Build Coastguard Worker   AV1_COMMON *const cm = &cpi->common;
1675*77c1e3ccSAndroid Build Coastguard Worker   const int boosted = frame_is_boosted(cpi);
1676*77c1e3ccSAndroid Build Coastguard Worker 
1677*77c1e3ccSAndroid Build Coastguard Worker   // Currently, rt speed 0, 1, 2, 3, 4, 5 are the same.
1678*77c1e3ccSAndroid Build Coastguard Worker   // Following set of speed features are not impacting encoder's decisions as
1679*77c1e3ccSAndroid Build Coastguard Worker   // the relevant tools are disabled by default.
1680*77c1e3ccSAndroid Build Coastguard Worker   sf->gm_sf.gm_search_type = GM_DISABLE_SEARCH;
1681*77c1e3ccSAndroid Build Coastguard Worker   sf->hl_sf.recode_loop = ALLOW_RECODE_KFARFGF;
1682*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.reuse_inter_intra_mode = 1;
1683*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.prune_compound_using_single_ref = 0;
1684*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.prune_comp_search_by_single_result = 2;
1685*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.prune_comp_type_by_comp_avg = 2;
1686*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.fast_wedge_sign_estimate = 1;
1687*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.use_dist_wtd_comp_flag = DIST_WTD_COMP_DISABLED;
1688*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.mv_cost_upd_level = INTERNAL_COST_UPD_SBROW;
1689*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.disable_interinter_wedge_var_thresh = 100;
1690*77c1e3ccSAndroid Build Coastguard Worker   sf->interp_sf.cb_pred_filter_search = 0;
1691*77c1e3ccSAndroid Build Coastguard Worker   sf->interp_sf.skip_interp_filter_search = 1;
1692*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.ml_prune_partition = 1;
1693*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.reuse_prev_rd_results_for_part_ab = 1;
1694*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.prune_ext_partition_types_search_level = 2;
1695*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.less_rectangular_check_level = 2;
1696*77c1e3ccSAndroid Build Coastguard Worker   sf->mv_sf.obmc_full_pixel_search_level = 1;
1697*77c1e3ccSAndroid Build Coastguard Worker   sf->intra_sf.dv_cost_upd_level = INTERNAL_COST_UPD_OFF;
1698*77c1e3ccSAndroid Build Coastguard Worker   sf->tx_sf.model_based_prune_tx_search_level = 0;
1699*77c1e3ccSAndroid Build Coastguard Worker   sf->lpf_sf.dual_sgr_penalty_level = 1;
1700*77c1e3ccSAndroid Build Coastguard Worker   // Disable Wiener and Self-guided Loop restoration filters.
1701*77c1e3ccSAndroid Build Coastguard Worker   sf->lpf_sf.disable_wiener_filter = true;
1702*77c1e3ccSAndroid Build Coastguard Worker   sf->lpf_sf.disable_sgr_filter = true;
1703*77c1e3ccSAndroid Build Coastguard Worker   sf->intra_sf.prune_palette_search_level = 2;
1704*77c1e3ccSAndroid Build Coastguard Worker   sf->intra_sf.prune_luma_palette_size_search_level = 2;
1705*77c1e3ccSAndroid Build Coastguard Worker   sf->intra_sf.early_term_chroma_palette_size_search = 1;
1706*77c1e3ccSAndroid Build Coastguard Worker 
1707*77c1e3ccSAndroid Build Coastguard Worker   // End of set
1708*77c1e3ccSAndroid Build Coastguard Worker 
1709*77c1e3ccSAndroid Build Coastguard Worker   // TODO(any, yunqing): tune these features for real-time use cases.
1710*77c1e3ccSAndroid Build Coastguard Worker   sf->hl_sf.superres_auto_search_type = SUPERRES_AUTO_SOLO;
1711*77c1e3ccSAndroid Build Coastguard Worker   sf->hl_sf.frame_parameter_update = 0;
1712*77c1e3ccSAndroid Build Coastguard Worker 
1713*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.model_based_post_interp_filter_breakout = 1;
1714*77c1e3ccSAndroid Build Coastguard Worker   // TODO(any): As per the experiments, this speed feature is doing redundant
1715*77c1e3ccSAndroid Build Coastguard Worker   // computation since the model rd based pruning logic is similar to model rd
1716*77c1e3ccSAndroid Build Coastguard Worker   // based gating when inter_mode_rd_model_estimation = 2. Enable this SF if
1717*77c1e3ccSAndroid Build Coastguard Worker   // either of the condition becomes true.
1718*77c1e3ccSAndroid Build Coastguard Worker   //    (1) inter_mode_rd_model_estimation != 2
1719*77c1e3ccSAndroid Build Coastguard Worker   //    (2) skip_interp_filter_search == 0
1720*77c1e3ccSAndroid Build Coastguard Worker   //    (3) Motion mode or compound mode is enabled */
1721*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.prune_mode_search_simple_translation = 0;
1722*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.prune_ref_frame_for_rect_partitions = !boosted;
1723*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.disable_interintra_wedge_var_thresh = UINT_MAX;
1724*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.selective_ref_frame = 4;
1725*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.alt_ref_search_fp = 2;
1726*77c1e3ccSAndroid Build Coastguard Worker   set_txfm_rd_gate_level(sf->inter_sf.txfm_rd_gate_level, boosted ? 0 : 4);
1727*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.limit_txfm_eval_per_mode = 3;
1728*77c1e3ccSAndroid Build Coastguard Worker 
1729*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.adaptive_rd_thresh = 4;
1730*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.inter_mode_rd_model_estimation = 2;
1731*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.prune_inter_modes_if_skippable = 1;
1732*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.prune_nearmv_using_neighbors = PRUNE_NEARMV_LEVEL3;
1733*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.reduce_inter_modes = boosted ? 1 : 3;
1734*77c1e3ccSAndroid Build Coastguard Worker   sf->inter_sf.skip_newmv_in_drl = 4;
1735*77c1e3ccSAndroid Build Coastguard Worker 
1736*77c1e3ccSAndroid Build Coastguard Worker   sf->interp_sf.use_fast_interpolation_filter_search = 1;
1737*77c1e3ccSAndroid Build Coastguard Worker   sf->interp_sf.use_interp_filter = 1;
1738*77c1e3ccSAndroid Build Coastguard Worker   sf->interp_sf.adaptive_interp_filter_search = 1;
1739*77c1e3ccSAndroid Build Coastguard Worker   sf->interp_sf.disable_dual_filter = 1;
1740*77c1e3ccSAndroid Build Coastguard Worker 
1741*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.default_max_partition_size = BLOCK_128X128;
1742*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.default_min_partition_size = BLOCK_8X8;
1743*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.use_best_rd_for_pruning = 1;
1744*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.early_term_after_none_split = 1;
1745*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.partition_search_breakout_dist_thr = (1 << 25);
1746*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.max_intra_bsize = BLOCK_16X16;
1747*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.partition_search_breakout_rate_thr = 500;
1748*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.partition_search_type = VAR_BASED_PARTITION;
1749*77c1e3ccSAndroid Build Coastguard Worker   sf->part_sf.adjust_var_based_rd_partitioning = 2;
1750*77c1e3ccSAndroid Build Coastguard Worker 
1751*77c1e3ccSAndroid Build Coastguard Worker   sf->mv_sf.full_pixel_search_level = 1;
1752*77c1e3ccSAndroid Build Coastguard Worker   sf->mv_sf.exhaustive_searches_thresh = INT_MAX;
1753*77c1e3ccSAndroid Build Coastguard Worker   sf->mv_sf.auto_mv_step_size = 1;
1754*77c1e3ccSAndroid Build Coastguard Worker   sf->mv_sf.subpel_iters_per_step = 1;
1755*77c1e3ccSAndroid Build Coastguard Worker   sf->mv_sf.use_accurate_subpel_search = USE_2_TAPS;
1756*77c1e3ccSAndroid Build Coastguard Worker   sf->mv_sf.search_method = FAST_DIAMOND;
1757*77c1e3ccSAndroid Build Coastguard Worker   sf->mv_sf.subpel_force_stop = EIGHTH_PEL;
1758*77c1e3ccSAndroid Build Coastguard Worker   sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED;
1759*77c1e3ccSAndroid Build Coastguard Worker 
1760*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < TX_SIZES; ++i) {
1761*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.intra_y_mode_mask[i] = INTRA_DC;
1762*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.intra_uv_mode_mask[i] = UV_INTRA_DC_CFL;
1763*77c1e3ccSAndroid Build Coastguard Worker   }
1764*77c1e3ccSAndroid Build Coastguard Worker   sf->intra_sf.skip_intra_in_interframe = 5;
1765*77c1e3ccSAndroid Build Coastguard Worker   sf->intra_sf.disable_smooth_intra = 1;
1766*77c1e3ccSAndroid Build Coastguard Worker   sf->intra_sf.skip_filter_intra_in_inter_frames = 1;
1767*77c1e3ccSAndroid Build Coastguard Worker 
1768*77c1e3ccSAndroid Build Coastguard Worker   sf->tx_sf.intra_tx_size_search_init_depth_sqr = 1;
1769*77c1e3ccSAndroid Build Coastguard Worker   sf->tx_sf.tx_type_search.use_reduced_intra_txset = 1;
1770*77c1e3ccSAndroid Build Coastguard Worker   sf->tx_sf.adaptive_txb_search_level = 2;
1771*77c1e3ccSAndroid Build Coastguard Worker   sf->tx_sf.intra_tx_size_search_init_depth_rect = 1;
1772*77c1e3ccSAndroid Build Coastguard Worker   sf->tx_sf.tx_size_search_lgr_block = 1;
1773*77c1e3ccSAndroid Build Coastguard Worker   sf->tx_sf.tx_type_search.ml_tx_split_thresh = 4000;
1774*77c1e3ccSAndroid Build Coastguard Worker   sf->tx_sf.tx_type_search.skip_tx_search = 1;
1775*77c1e3ccSAndroid Build Coastguard Worker   sf->tx_sf.inter_tx_size_search_init_depth_rect = 1;
1776*77c1e3ccSAndroid Build Coastguard Worker   sf->tx_sf.inter_tx_size_search_init_depth_sqr = 1;
1777*77c1e3ccSAndroid Build Coastguard Worker   sf->tx_sf.tx_type_search.prune_2d_txfm_mode = TX_TYPE_PRUNE_3;
1778*77c1e3ccSAndroid Build Coastguard Worker   sf->tx_sf.refine_fast_tx_search_results = 0;
1779*77c1e3ccSAndroid Build Coastguard Worker   sf->tx_sf.tx_type_search.fast_intra_tx_type_search = 1;
1780*77c1e3ccSAndroid Build Coastguard Worker   sf->tx_sf.tx_type_search.use_skip_flag_prediction = 2;
1781*77c1e3ccSAndroid Build Coastguard Worker   sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning = 4;
1782*77c1e3ccSAndroid Build Coastguard Worker 
1783*77c1e3ccSAndroid Build Coastguard Worker   sf->rd_sf.optimize_coefficients = NO_TRELLIS_OPT;
1784*77c1e3ccSAndroid Build Coastguard Worker   sf->rd_sf.simple_model_rd_from_var = 1;
1785*77c1e3ccSAndroid Build Coastguard Worker   sf->rd_sf.tx_domain_dist_level = 2;
1786*77c1e3ccSAndroid Build Coastguard Worker   sf->rd_sf.tx_domain_dist_thres_level = 2;
1787*77c1e3ccSAndroid Build Coastguard Worker 
1788*77c1e3ccSAndroid Build Coastguard Worker   sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL4;
1789*77c1e3ccSAndroid Build Coastguard Worker   sf->lpf_sf.lpf_pick = LPF_PICK_FROM_Q;
1790*77c1e3ccSAndroid Build Coastguard Worker 
1791*77c1e3ccSAndroid Build Coastguard Worker   sf->winner_mode_sf.dc_blk_pred_level = frame_is_intra_only(cm) ? 0 : 3;
1792*77c1e3ccSAndroid Build Coastguard Worker   sf->winner_mode_sf.enable_winner_mode_for_tx_size_srch = 1;
1793*77c1e3ccSAndroid Build Coastguard Worker   sf->winner_mode_sf.tx_size_search_level = 1;
1794*77c1e3ccSAndroid Build Coastguard Worker   sf->winner_mode_sf.winner_mode_ifs = 1;
1795*77c1e3ccSAndroid Build Coastguard Worker 
1796*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.check_intra_pred_nonrd = 1;
1797*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.estimate_motion_for_var_based_partition = 2;
1798*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.hybrid_intra_pickmode = 1;
1799*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.use_comp_ref_nonrd = 0;
1800*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.ref_frame_comp_nonrd[0] = 0;
1801*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.ref_frame_comp_nonrd[1] = 0;
1802*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.ref_frame_comp_nonrd[2] = 0;
1803*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.use_nonrd_filter_search = 1;
1804*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.mode_search_skip_flags |= FLAG_SKIP_INTRA_DIRMISMATCH;
1805*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.num_inter_modes_for_tx_search = 5;
1806*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.prune_inter_modes_using_temp_var = 1;
1807*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.use_real_time_ref_set = 1;
1808*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.use_simple_rd_model = 1;
1809*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.prune_inter_modes_with_golden_ref = boosted ? 0 : 1;
1810*77c1e3ccSAndroid Build Coastguard Worker   // TODO(any): This sf could be removed.
1811*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.short_circuit_low_temp_var = 1;
1812*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.check_scene_detection = 1;
1813*77c1e3ccSAndroid Build Coastguard Worker   if (cpi->rc.rtc_external_ratectrl) sf->rt_sf.check_scene_detection = 0;
1814*77c1e3ccSAndroid Build Coastguard Worker   if (cm->current_frame.frame_type != KEY_FRAME &&
1815*77c1e3ccSAndroid Build Coastguard Worker       cpi->oxcf.rc_cfg.mode == AOM_CBR)
1816*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.overshoot_detection_cbr = FAST_DETECTION_MAXQ;
1817*77c1e3ccSAndroid Build Coastguard Worker   // Enable noise estimation only for high resolutions for now.
1818*77c1e3ccSAndroid Build Coastguard Worker   //
1819*77c1e3ccSAndroid Build Coastguard Worker   // Since use_temporal_noise_estimate has no effect for all-intra frame
1820*77c1e3ccSAndroid Build Coastguard Worker   // encoding, it is disabled for this case.
1821*77c1e3ccSAndroid Build Coastguard Worker   if (cpi->oxcf.kf_cfg.key_freq_max != 0 && cm->width * cm->height > 640 * 480)
1822*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.use_temporal_noise_estimate = 1;
1823*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.skip_tx_no_split_var_based_partition = 1;
1824*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.skip_newmv_mode_based_on_sse = 1;
1825*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.mode_search_skip_flags =
1826*77c1e3ccSAndroid Build Coastguard Worker       (cm->current_frame.frame_type == KEY_FRAME)
1827*77c1e3ccSAndroid Build Coastguard Worker           ? 0
1828*77c1e3ccSAndroid Build Coastguard Worker           : FLAG_SKIP_INTRA_DIRMISMATCH | FLAG_SKIP_INTRA_BESTINTER |
1829*77c1e3ccSAndroid Build Coastguard Worker                 FLAG_SKIP_COMP_BESTINTRA | FLAG_SKIP_INTRA_LOWVAR |
1830*77c1e3ccSAndroid Build Coastguard Worker                 FLAG_EARLY_TERMINATE;
1831*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.var_part_split_threshold_shift = 5;
1832*77c1e3ccSAndroid Build Coastguard Worker   if (!frame_is_intra_only(&cpi->common)) sf->rt_sf.var_part_based_on_qidx = 1;
1833*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.use_fast_fixed_part = 0;
1834*77c1e3ccSAndroid Build Coastguard Worker   sf->rt_sf.increase_source_sad_thresh = 0;
1835*77c1e3ccSAndroid Build Coastguard Worker 
1836*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 6) {
1837*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.use_fullpel_costlist = 1;
1838*77c1e3ccSAndroid Build Coastguard Worker 
1839*77c1e3ccSAndroid Build Coastguard Worker     sf->rd_sf.tx_domain_dist_thres_level = 3;
1840*77c1e3ccSAndroid Build Coastguard Worker 
1841*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.tx_type_search.fast_inter_tx_type_prob_thresh = 0;
1842*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.limit_inter_mode_cands = 4;
1843*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.prune_warped_prob_thresh = 8;
1844*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.extra_prune_warped = 1;
1845*77c1e3ccSAndroid Build Coastguard Worker 
1846*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.gf_refresh_based_on_qp = 1;
1847*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.prune_inter_modes_wrt_gf_arf_based_on_sad = 1;
1848*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.var_part_split_threshold_shift = 7;
1849*77c1e3ccSAndroid Build Coastguard Worker     if (!frame_is_intra_only(&cpi->common))
1850*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.var_part_based_on_qidx = 2;
1851*77c1e3ccSAndroid Build Coastguard Worker 
1852*77c1e3ccSAndroid Build Coastguard Worker     sf->winner_mode_sf.prune_winner_mode_eval_level = boosted ? 0 : 3;
1853*77c1e3ccSAndroid Build Coastguard Worker   }
1854*77c1e3ccSAndroid Build Coastguard Worker 
1855*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 7) {
1856*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.sse_early_term_inter_search = EARLY_TERM_IDX_1;
1857*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.use_comp_ref_nonrd = 1;
1858*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.ref_frame_comp_nonrd[2] = 1;  // LAST_ALTREF
1859*77c1e3ccSAndroid Build Coastguard Worker     sf->tx_sf.intra_tx_size_search_init_depth_sqr = 2;
1860*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.partition_search_type = VAR_BASED_PARTITION;
1861*77c1e3ccSAndroid Build Coastguard Worker     sf->part_sf.max_intra_bsize = BLOCK_32X32;
1862*77c1e3ccSAndroid Build Coastguard Worker 
1863*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.search_method = FAST_DIAMOND;
1864*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.subpel_force_stop = QUARTER_PEL;
1865*77c1e3ccSAndroid Build Coastguard Worker 
1866*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.inter_mode_rd_model_estimation = 2;
1867*77c1e3ccSAndroid Build Coastguard Worker     // This sf is not applicable in non-rd path.
1868*77c1e3ccSAndroid Build Coastguard Worker     sf->inter_sf.skip_newmv_in_drl = 0;
1869*77c1e3ccSAndroid Build Coastguard Worker 
1870*77c1e3ccSAndroid Build Coastguard Worker     sf->interp_sf.skip_interp_filter_search = 0;
1871*77c1e3ccSAndroid Build Coastguard Worker 
1872*77c1e3ccSAndroid Build Coastguard Worker     // Disable intra_y_mode_mask pruning since the performance at speed 7 isn't
1873*77c1e3ccSAndroid Build Coastguard Worker     // good. May need more study.
1874*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < TX_SIZES; ++i) {
1875*77c1e3ccSAndroid Build Coastguard Worker       sf->intra_sf.intra_y_mode_mask[i] = INTRA_ALL;
1876*77c1e3ccSAndroid Build Coastguard Worker     }
1877*77c1e3ccSAndroid Build Coastguard Worker 
1878*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.lpf_pick = LPF_PICK_FROM_Q;
1879*77c1e3ccSAndroid Build Coastguard Worker     sf->lpf_sf.cdef_pick_method = CDEF_FAST_SEARCH_LVL5;
1880*77c1e3ccSAndroid Build Coastguard Worker 
1881*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.mode_search_skip_flags |= FLAG_SKIP_INTRA_DIRMISMATCH;
1882*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.nonrd_prune_ref_frame_search = 1;
1883*77c1e3ccSAndroid Build Coastguard Worker     // This is for rd path only.
1884*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.prune_inter_modes_using_temp_var = 0;
1885*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.prune_inter_modes_wrt_gf_arf_based_on_sad = 0;
1886*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.prune_intra_mode_based_on_mv_range = 0;
1887*77c1e3ccSAndroid Build Coastguard Worker #if !CONFIG_REALTIME_ONLY
1888*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.reuse_inter_pred_nonrd =
1889*77c1e3ccSAndroid Build Coastguard Worker         (cpi->oxcf.motion_mode_cfg.enable_warped_motion == 0);
1890*77c1e3ccSAndroid Build Coastguard Worker #else
1891*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.reuse_inter_pred_nonrd = 1;
1892*77c1e3ccSAndroid Build Coastguard Worker #endif
1893*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_TEMPORAL_DENOISING
1894*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.reuse_inter_pred_nonrd = (cpi->oxcf.noise_sensitivity == 0);
1895*77c1e3ccSAndroid Build Coastguard Worker #endif
1896*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.short_circuit_low_temp_var = 0;
1897*77c1e3ccSAndroid Build Coastguard Worker     // For spatial layers, only LAST and GOLDEN are currently used in the SVC
1898*77c1e3ccSAndroid Build Coastguard Worker     // for nonrd. The flag use_nonrd_altref_frame can disable GOLDEN in the
1899*77c1e3ccSAndroid Build Coastguard Worker     // get_ref_frame_flags() for some patterns, so disable it here for
1900*77c1e3ccSAndroid Build Coastguard Worker     // spatial layers.
1901*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.use_nonrd_altref_frame =
1902*77c1e3ccSAndroid Build Coastguard Worker         (cpi->svc.number_spatial_layers > 1) ? 0 : 1;
1903*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.use_nonrd_pick_mode = 1;
1904*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.nonrd_check_partition_merge_mode = 3;
1905*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.skip_intra_pred = 1;
1906*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.source_metrics_sb_nonrd = 1;
1907*77c1e3ccSAndroid Build Coastguard Worker     // Set mask for intra modes.
1908*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < BLOCK_SIZES; ++i)
1909*77c1e3ccSAndroid Build Coastguard Worker       if (i >= BLOCK_32X32)
1910*77c1e3ccSAndroid Build Coastguard Worker         sf->rt_sf.intra_y_mode_bsize_mask_nrd[i] = INTRA_DC;
1911*77c1e3ccSAndroid Build Coastguard Worker       else
1912*77c1e3ccSAndroid Build Coastguard Worker         // Use DC, H, V intra mode for block sizes < 32X32.
1913*77c1e3ccSAndroid Build Coastguard Worker         sf->rt_sf.intra_y_mode_bsize_mask_nrd[i] = INTRA_DC_H_V;
1914*77c1e3ccSAndroid Build Coastguard Worker 
1915*77c1e3ccSAndroid Build Coastguard Worker     sf->winner_mode_sf.dc_blk_pred_level = 0;
1916*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.var_part_based_on_qidx = 3;
1917*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.prune_compoundmode_with_singlecompound_var = true;
1918*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.prune_compoundmode_with_singlemode_var = true;
1919*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.skip_compound_based_on_var = true;
1920*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.use_adaptive_subpel_search = true;
1921*77c1e3ccSAndroid Build Coastguard Worker   }
1922*77c1e3ccSAndroid Build Coastguard Worker 
1923*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 8) {
1924*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.sse_early_term_inter_search = EARLY_TERM_IDX_2;
1925*77c1e3ccSAndroid Build Coastguard Worker     sf->intra_sf.intra_pruning_with_hog = 1;
1926*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.short_circuit_low_temp_var = 1;
1927*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.use_nonrd_altref_frame = 0;
1928*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.nonrd_prune_ref_frame_search = 2;
1929*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.nonrd_check_partition_merge_mode = 0;
1930*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.var_part_split_threshold_shift = 8;
1931*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.var_part_based_on_qidx = 4;
1932*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.partition_direct_merging = 1;
1933*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.prune_compoundmode_with_singlemode_var = false;
1934*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.use_bsize_dependent_search_method = 2;
1935*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.prune_hv_pred_modes_using_src_sad = true;
1936*77c1e3ccSAndroid Build Coastguard Worker   }
1937*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 9) {
1938*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.sse_early_term_inter_search = EARLY_TERM_IDX_3;
1939*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.estimate_motion_for_var_based_partition = 3;
1940*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.prefer_large_partition_blocks = 3;
1941*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.skip_intra_pred = 2;
1942*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.var_part_split_threshold_shift = 9;
1943*77c1e3ccSAndroid Build Coastguard Worker     for (int i = 0; i < BLOCK_SIZES; ++i)
1944*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.intra_y_mode_bsize_mask_nrd[i] = INTRA_DC;
1945*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.var_part_based_on_qidx = 0;
1946*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.frame_level_mode_cost_update = true;
1947*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.check_only_zero_zeromv_on_large_blocks = true;
1948*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.reduce_mv_pel_precision_highmotion = 0;
1949*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.use_adaptive_subpel_search = true;
1950*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.use_bsize_dependent_search_method = 0;
1951*77c1e3ccSAndroid Build Coastguard Worker   }
1952*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 10) {
1953*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.sse_early_term_inter_search = EARLY_TERM_IDX_4;
1954*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.nonrd_prune_ref_frame_search = 3;
1955*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.var_part_split_threshold_shift = 10;
1956*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
1957*77c1e3ccSAndroid Build Coastguard Worker   }
1958*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 11 && !frame_is_intra_only(cm) &&
1959*77c1e3ccSAndroid Build Coastguard Worker       cpi->oxcf.tune_cfg.content == AOM_CONTENT_SCREEN) {
1960*77c1e3ccSAndroid Build Coastguard Worker     sf->winner_mode_sf.dc_blk_pred_level = 3;
1961*77c1e3ccSAndroid Build Coastguard Worker   }
1962*77c1e3ccSAndroid Build Coastguard Worker }
1963*77c1e3ccSAndroid Build Coastguard Worker 
init_hl_sf(HIGH_LEVEL_SPEED_FEATURES * hl_sf)1964*77c1e3ccSAndroid Build Coastguard Worker static inline void init_hl_sf(HIGH_LEVEL_SPEED_FEATURES *hl_sf) {
1965*77c1e3ccSAndroid Build Coastguard Worker   // best quality defaults
1966*77c1e3ccSAndroid Build Coastguard Worker   hl_sf->frame_parameter_update = 1;
1967*77c1e3ccSAndroid Build Coastguard Worker   hl_sf->recode_loop = ALLOW_RECODE;
1968*77c1e3ccSAndroid Build Coastguard Worker   // Recode loop tolerance %.
1969*77c1e3ccSAndroid Build Coastguard Worker   hl_sf->recode_tolerance = 25;
1970*77c1e3ccSAndroid Build Coastguard Worker   hl_sf->high_precision_mv_usage = CURRENT_Q;
1971*77c1e3ccSAndroid Build Coastguard Worker   hl_sf->superres_auto_search_type = SUPERRES_AUTO_ALL;
1972*77c1e3ccSAndroid Build Coastguard Worker   hl_sf->disable_extra_sc_testing = 0;
1973*77c1e3ccSAndroid Build Coastguard Worker   hl_sf->second_alt_ref_filtering = 1;
1974*77c1e3ccSAndroid Build Coastguard Worker   hl_sf->adjust_num_frames_for_arf_filtering = 0;
1975*77c1e3ccSAndroid Build Coastguard Worker   hl_sf->accurate_bit_estimate = 0;
1976*77c1e3ccSAndroid Build Coastguard Worker   hl_sf->weight_calc_level_in_tf = 0;
1977*77c1e3ccSAndroid Build Coastguard Worker   hl_sf->allow_sub_blk_me_in_tf = 0;
1978*77c1e3ccSAndroid Build Coastguard Worker }
1979*77c1e3ccSAndroid Build Coastguard Worker 
init_fp_sf(FIRST_PASS_SPEED_FEATURES * fp_sf)1980*77c1e3ccSAndroid Build Coastguard Worker static inline void init_fp_sf(FIRST_PASS_SPEED_FEATURES *fp_sf) {
1981*77c1e3ccSAndroid Build Coastguard Worker   fp_sf->reduce_mv_step_param = 3;
1982*77c1e3ccSAndroid Build Coastguard Worker   fp_sf->skip_motion_search_threshold = 0;
1983*77c1e3ccSAndroid Build Coastguard Worker   fp_sf->disable_recon = 0;
1984*77c1e3ccSAndroid Build Coastguard Worker   fp_sf->skip_zeromv_motion_search = 0;
1985*77c1e3ccSAndroid Build Coastguard Worker }
1986*77c1e3ccSAndroid Build Coastguard Worker 
init_tpl_sf(TPL_SPEED_FEATURES * tpl_sf)1987*77c1e3ccSAndroid Build Coastguard Worker static inline void init_tpl_sf(TPL_SPEED_FEATURES *tpl_sf) {
1988*77c1e3ccSAndroid Build Coastguard Worker   tpl_sf->gop_length_decision_method = 0;
1989*77c1e3ccSAndroid Build Coastguard Worker   tpl_sf->prune_intra_modes = 0;
1990*77c1e3ccSAndroid Build Coastguard Worker   tpl_sf->prune_starting_mv = 0;
1991*77c1e3ccSAndroid Build Coastguard Worker   tpl_sf->reduce_first_step_size = 0;
1992*77c1e3ccSAndroid Build Coastguard Worker   tpl_sf->skip_alike_starting_mv = 0;
1993*77c1e3ccSAndroid Build Coastguard Worker   tpl_sf->subpel_force_stop = EIGHTH_PEL;
1994*77c1e3ccSAndroid Build Coastguard Worker   tpl_sf->search_method = NSTEP;
1995*77c1e3ccSAndroid Build Coastguard Worker   tpl_sf->prune_ref_frames_in_tpl = 0;
1996*77c1e3ccSAndroid Build Coastguard Worker   tpl_sf->allow_compound_pred = 1;
1997*77c1e3ccSAndroid Build Coastguard Worker   tpl_sf->use_y_only_rate_distortion = 0;
1998*77c1e3ccSAndroid Build Coastguard Worker   tpl_sf->use_sad_for_mode_decision = 0;
1999*77c1e3ccSAndroid Build Coastguard Worker   tpl_sf->reduce_num_frames = 0;
2000*77c1e3ccSAndroid Build Coastguard Worker }
2001*77c1e3ccSAndroid Build Coastguard Worker 
init_gm_sf(GLOBAL_MOTION_SPEED_FEATURES * gm_sf)2002*77c1e3ccSAndroid Build Coastguard Worker static inline void init_gm_sf(GLOBAL_MOTION_SPEED_FEATURES *gm_sf) {
2003*77c1e3ccSAndroid Build Coastguard Worker   gm_sf->gm_search_type = GM_FULL_SEARCH;
2004*77c1e3ccSAndroid Build Coastguard Worker   gm_sf->prune_ref_frame_for_gm_search = 0;
2005*77c1e3ccSAndroid Build Coastguard Worker   gm_sf->prune_zero_mv_with_sse = 0;
2006*77c1e3ccSAndroid Build Coastguard Worker   gm_sf->disable_gm_search_based_on_stats = 0;
2007*77c1e3ccSAndroid Build Coastguard Worker   gm_sf->downsample_level = 0;
2008*77c1e3ccSAndroid Build Coastguard Worker   gm_sf->num_refinement_steps = GM_MAX_REFINEMENT_STEPS;
2009*77c1e3ccSAndroid Build Coastguard Worker }
2010*77c1e3ccSAndroid Build Coastguard Worker 
init_part_sf(PARTITION_SPEED_FEATURES * part_sf)2011*77c1e3ccSAndroid Build Coastguard Worker static inline void init_part_sf(PARTITION_SPEED_FEATURES *part_sf) {
2012*77c1e3ccSAndroid Build Coastguard Worker   part_sf->partition_search_type = SEARCH_PARTITION;
2013*77c1e3ccSAndroid Build Coastguard Worker   part_sf->less_rectangular_check_level = 0;
2014*77c1e3ccSAndroid Build Coastguard Worker   part_sf->use_square_partition_only_threshold = BLOCK_128X128;
2015*77c1e3ccSAndroid Build Coastguard Worker   part_sf->auto_max_partition_based_on_simple_motion = NOT_IN_USE;
2016*77c1e3ccSAndroid Build Coastguard Worker   part_sf->default_max_partition_size = BLOCK_LARGEST;
2017*77c1e3ccSAndroid Build Coastguard Worker   part_sf->default_min_partition_size = BLOCK_4X4;
2018*77c1e3ccSAndroid Build Coastguard Worker   part_sf->adjust_var_based_rd_partitioning = 0;
2019*77c1e3ccSAndroid Build Coastguard Worker   part_sf->max_intra_bsize = BLOCK_LARGEST;
2020*77c1e3ccSAndroid Build Coastguard Worker   // This setting only takes effect when partition_search_type is set
2021*77c1e3ccSAndroid Build Coastguard Worker   // to FIXED_PARTITION.
2022*77c1e3ccSAndroid Build Coastguard Worker   part_sf->fixed_partition_size = BLOCK_16X16;
2023*77c1e3ccSAndroid Build Coastguard Worker   // Recode loop tolerance %.
2024*77c1e3ccSAndroid Build Coastguard Worker   part_sf->partition_search_breakout_dist_thr = 0;
2025*77c1e3ccSAndroid Build Coastguard Worker   part_sf->partition_search_breakout_rate_thr = 0;
2026*77c1e3ccSAndroid Build Coastguard Worker   part_sf->prune_ext_partition_types_search_level = 0;
2027*77c1e3ccSAndroid Build Coastguard Worker   part_sf->prune_part4_search = 0;
2028*77c1e3ccSAndroid Build Coastguard Worker   part_sf->ml_prune_partition = 0;
2029*77c1e3ccSAndroid Build Coastguard Worker   part_sf->ml_early_term_after_part_split_level = 0;
2030*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < PARTITION_BLOCK_SIZES; ++i) {
2031*77c1e3ccSAndroid Build Coastguard Worker     part_sf->ml_partition_search_breakout_thresh[i] =
2032*77c1e3ccSAndroid Build Coastguard Worker         -1;  // -1 means not enabled.
2033*77c1e3ccSAndroid Build Coastguard Worker   }
2034*77c1e3ccSAndroid Build Coastguard Worker   part_sf->simple_motion_search_prune_agg = SIMPLE_AGG_LVL0;
2035*77c1e3ccSAndroid Build Coastguard Worker   part_sf->simple_motion_search_split = 0;
2036*77c1e3ccSAndroid Build Coastguard Worker   part_sf->simple_motion_search_prune_rect = 0;
2037*77c1e3ccSAndroid Build Coastguard Worker   part_sf->simple_motion_search_early_term_none = 0;
2038*77c1e3ccSAndroid Build Coastguard Worker   part_sf->simple_motion_search_reduce_search_steps = 0;
2039*77c1e3ccSAndroid Build Coastguard Worker   part_sf->intra_cnn_based_part_prune_level = 0;
2040*77c1e3ccSAndroid Build Coastguard Worker   part_sf->ext_partition_eval_thresh = BLOCK_8X8;
2041*77c1e3ccSAndroid Build Coastguard Worker   part_sf->rect_partition_eval_thresh = BLOCK_128X128;
2042*77c1e3ccSAndroid Build Coastguard Worker   part_sf->ext_part_eval_based_on_cur_best = 0;
2043*77c1e3ccSAndroid Build Coastguard Worker   part_sf->prune_ext_part_using_split_info = 0;
2044*77c1e3ccSAndroid Build Coastguard Worker   part_sf->prune_rectangular_split_based_on_qidx = 0;
2045*77c1e3ccSAndroid Build Coastguard Worker   part_sf->prune_rect_part_using_4x4_var_deviation = false;
2046*77c1e3ccSAndroid Build Coastguard Worker   part_sf->prune_rect_part_using_none_pred_mode = false;
2047*77c1e3ccSAndroid Build Coastguard Worker   part_sf->early_term_after_none_split = 0;
2048*77c1e3ccSAndroid Build Coastguard Worker   part_sf->ml_predict_breakout_level = 0;
2049*77c1e3ccSAndroid Build Coastguard Worker   part_sf->prune_sub_8x8_partition_level = 0;
2050*77c1e3ccSAndroid Build Coastguard Worker   part_sf->simple_motion_search_rect_split = 0;
2051*77c1e3ccSAndroid Build Coastguard Worker   part_sf->reuse_prev_rd_results_for_part_ab = 0;
2052*77c1e3ccSAndroid Build Coastguard Worker   part_sf->reuse_best_prediction_for_part_ab = 0;
2053*77c1e3ccSAndroid Build Coastguard Worker   part_sf->use_best_rd_for_pruning = 0;
2054*77c1e3ccSAndroid Build Coastguard Worker   part_sf->skip_non_sq_part_based_on_none = 0;
2055*77c1e3ccSAndroid Build Coastguard Worker   part_sf->disable_8x8_part_based_on_qidx = 0;
2056*77c1e3ccSAndroid Build Coastguard Worker }
2057*77c1e3ccSAndroid Build Coastguard Worker 
init_mv_sf(MV_SPEED_FEATURES * mv_sf)2058*77c1e3ccSAndroid Build Coastguard Worker static inline void init_mv_sf(MV_SPEED_FEATURES *mv_sf) {
2059*77c1e3ccSAndroid Build Coastguard Worker   mv_sf->full_pixel_search_level = 0;
2060*77c1e3ccSAndroid Build Coastguard Worker   mv_sf->auto_mv_step_size = 0;
2061*77c1e3ccSAndroid Build Coastguard Worker   mv_sf->exhaustive_searches_thresh = 0;
2062*77c1e3ccSAndroid Build Coastguard Worker   mv_sf->obmc_full_pixel_search_level = 0;
2063*77c1e3ccSAndroid Build Coastguard Worker   mv_sf->prune_mesh_search = PRUNE_MESH_SEARCH_DISABLED;
2064*77c1e3ccSAndroid Build Coastguard Worker   mv_sf->reduce_search_range = 0;
2065*77c1e3ccSAndroid Build Coastguard Worker   mv_sf->search_method = NSTEP;
2066*77c1e3ccSAndroid Build Coastguard Worker   mv_sf->simple_motion_subpel_force_stop = EIGHTH_PEL;
2067*77c1e3ccSAndroid Build Coastguard Worker   mv_sf->subpel_force_stop = EIGHTH_PEL;
2068*77c1e3ccSAndroid Build Coastguard Worker   mv_sf->subpel_iters_per_step = 2;
2069*77c1e3ccSAndroid Build Coastguard Worker   mv_sf->subpel_search_method = SUBPEL_TREE;
2070*77c1e3ccSAndroid Build Coastguard Worker   mv_sf->use_accurate_subpel_search = USE_8_TAPS;
2071*77c1e3ccSAndroid Build Coastguard Worker   mv_sf->use_bsize_dependent_search_method = 0;
2072*77c1e3ccSAndroid Build Coastguard Worker   mv_sf->use_fullpel_costlist = 0;
2073*77c1e3ccSAndroid Build Coastguard Worker   mv_sf->use_downsampled_sad = 0;
2074*77c1e3ccSAndroid Build Coastguard Worker   mv_sf->disable_extensive_joint_motion_search = 0;
2075*77c1e3ccSAndroid Build Coastguard Worker   mv_sf->disable_second_mv = 0;
2076*77c1e3ccSAndroid Build Coastguard Worker   mv_sf->skip_fullpel_search_using_startmv = 0;
2077*77c1e3ccSAndroid Build Coastguard Worker   mv_sf->warp_search_method = WARP_SEARCH_SQUARE;
2078*77c1e3ccSAndroid Build Coastguard Worker   mv_sf->warp_search_iters = 8;
2079*77c1e3ccSAndroid Build Coastguard Worker   mv_sf->use_intrabc = 1;
2080*77c1e3ccSAndroid Build Coastguard Worker }
2081*77c1e3ccSAndroid Build Coastguard Worker 
init_inter_sf(INTER_MODE_SPEED_FEATURES * inter_sf)2082*77c1e3ccSAndroid Build Coastguard Worker static inline void init_inter_sf(INTER_MODE_SPEED_FEATURES *inter_sf) {
2083*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->adaptive_rd_thresh = 0;
2084*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->model_based_post_interp_filter_breakout = 0;
2085*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->reduce_inter_modes = 0;
2086*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->alt_ref_search_fp = 0;
2087*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->prune_single_ref = 0;
2088*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->prune_comp_ref_frames = 0;
2089*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->selective_ref_frame = 0;
2090*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->prune_ref_frame_for_rect_partitions = 0;
2091*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->fast_wedge_sign_estimate = 0;
2092*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->use_dist_wtd_comp_flag = DIST_WTD_COMP_ENABLED;
2093*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->reuse_inter_intra_mode = 0;
2094*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->mv_cost_upd_level = INTERNAL_COST_UPD_SB;
2095*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->coeff_cost_upd_level = INTERNAL_COST_UPD_SB;
2096*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->mode_cost_upd_level = INTERNAL_COST_UPD_SB;
2097*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->prune_inter_modes_based_on_tpl = 0;
2098*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->prune_nearmv_using_neighbors = PRUNE_NEARMV_OFF;
2099*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->prune_comp_search_by_single_result = 0;
2100*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->skip_repeated_ref_mv = 0;
2101*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->skip_newmv_in_drl = 0;
2102*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->inter_mode_rd_model_estimation = 0;
2103*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->prune_compound_using_single_ref = 0;
2104*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->prune_ext_comp_using_neighbors = 0;
2105*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->skip_ext_comp_nearmv_mode = 0;
2106*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->prune_comp_using_best_single_mode_ref = 0;
2107*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->prune_nearest_near_mv_using_refmv_weight = 0;
2108*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->disable_onesided_comp = 0;
2109*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->prune_mode_search_simple_translation = 0;
2110*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->prune_comp_type_by_comp_avg = 0;
2111*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->disable_interinter_wedge_newmv_search = 0;
2112*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->fast_interintra_wedge_search = 0;
2113*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->prune_comp_type_by_model_rd = 0;
2114*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->perform_best_rd_based_gating_for_chroma = 0;
2115*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->prune_obmc_prob_thresh = 0;
2116*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->disable_interinter_wedge_var_thresh = 0;
2117*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->disable_interintra_wedge_var_thresh = 0;
2118*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->prune_ref_mv_idx_search = 0;
2119*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->prune_warped_prob_thresh = 0;
2120*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->reuse_compound_type_decision = 0;
2121*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->prune_inter_modes_if_skippable = 0;
2122*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->disable_masked_comp = 0;
2123*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->enable_fast_compound_mode_search = 0;
2124*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->reuse_mask_search_results = 0;
2125*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->enable_fast_wedge_mask_search = 0;
2126*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->inter_mode_txfm_breakout = 0;
2127*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->limit_inter_mode_cands = 0;
2128*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->limit_txfm_eval_per_mode = 0;
2129*77c1e3ccSAndroid Build Coastguard Worker   inter_sf->skip_arf_compound = 0;
2130*77c1e3ccSAndroid Build Coastguard Worker   set_txfm_rd_gate_level(inter_sf->txfm_rd_gate_level, 0);
2131*77c1e3ccSAndroid Build Coastguard Worker }
2132*77c1e3ccSAndroid Build Coastguard Worker 
init_interp_sf(INTERP_FILTER_SPEED_FEATURES * interp_sf)2133*77c1e3ccSAndroid Build Coastguard Worker static inline void init_interp_sf(INTERP_FILTER_SPEED_FEATURES *interp_sf) {
2134*77c1e3ccSAndroid Build Coastguard Worker   interp_sf->adaptive_interp_filter_search = 0;
2135*77c1e3ccSAndroid Build Coastguard Worker   interp_sf->cb_pred_filter_search = 0;
2136*77c1e3ccSAndroid Build Coastguard Worker   interp_sf->disable_dual_filter = 0;
2137*77c1e3ccSAndroid Build Coastguard Worker   interp_sf->skip_sharp_interp_filter_search = 0;
2138*77c1e3ccSAndroid Build Coastguard Worker   interp_sf->use_fast_interpolation_filter_search = 0;
2139*77c1e3ccSAndroid Build Coastguard Worker   interp_sf->use_interp_filter = 0;
2140*77c1e3ccSAndroid Build Coastguard Worker   interp_sf->skip_interp_filter_search = 0;
2141*77c1e3ccSAndroid Build Coastguard Worker }
2142*77c1e3ccSAndroid Build Coastguard Worker 
init_intra_sf(INTRA_MODE_SPEED_FEATURES * intra_sf)2143*77c1e3ccSAndroid Build Coastguard Worker static inline void init_intra_sf(INTRA_MODE_SPEED_FEATURES *intra_sf) {
2144*77c1e3ccSAndroid Build Coastguard Worker   intra_sf->dv_cost_upd_level = INTERNAL_COST_UPD_SB;
2145*77c1e3ccSAndroid Build Coastguard Worker   intra_sf->skip_intra_in_interframe = 1;
2146*77c1e3ccSAndroid Build Coastguard Worker   intra_sf->intra_pruning_with_hog = 0;
2147*77c1e3ccSAndroid Build Coastguard Worker   intra_sf->chroma_intra_pruning_with_hog = 0;
2148*77c1e3ccSAndroid Build Coastguard Worker   intra_sf->prune_palette_search_level = 0;
2149*77c1e3ccSAndroid Build Coastguard Worker   intra_sf->prune_luma_palette_size_search_level = 0;
2150*77c1e3ccSAndroid Build Coastguard Worker 
2151*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < TX_SIZES; i++) {
2152*77c1e3ccSAndroid Build Coastguard Worker     intra_sf->intra_y_mode_mask[i] = INTRA_ALL;
2153*77c1e3ccSAndroid Build Coastguard Worker     intra_sf->intra_uv_mode_mask[i] = UV_INTRA_ALL;
2154*77c1e3ccSAndroid Build Coastguard Worker   }
2155*77c1e3ccSAndroid Build Coastguard Worker   intra_sf->disable_smooth_intra = 0;
2156*77c1e3ccSAndroid Build Coastguard Worker   intra_sf->prune_smooth_intra_mode_for_chroma = 0;
2157*77c1e3ccSAndroid Build Coastguard Worker   intra_sf->prune_filter_intra_level = 0;
2158*77c1e3ccSAndroid Build Coastguard Worker   intra_sf->prune_chroma_modes_using_luma_winner = 0;
2159*77c1e3ccSAndroid Build Coastguard Worker   intra_sf->cfl_search_range = 3;
2160*77c1e3ccSAndroid Build Coastguard Worker   intra_sf->top_intra_model_count_allowed = TOP_INTRA_MODEL_COUNT;
2161*77c1e3ccSAndroid Build Coastguard Worker   intra_sf->adapt_top_model_rd_count_using_neighbors = 0;
2162*77c1e3ccSAndroid Build Coastguard Worker   intra_sf->early_term_chroma_palette_size_search = 0;
2163*77c1e3ccSAndroid Build Coastguard Worker   intra_sf->skip_filter_intra_in_inter_frames = 0;
2164*77c1e3ccSAndroid Build Coastguard Worker   intra_sf->prune_luma_odd_delta_angles_in_intra = 0;
2165*77c1e3ccSAndroid Build Coastguard Worker }
2166*77c1e3ccSAndroid Build Coastguard Worker 
init_tx_sf(TX_SPEED_FEATURES * tx_sf)2167*77c1e3ccSAndroid Build Coastguard Worker static inline void init_tx_sf(TX_SPEED_FEATURES *tx_sf) {
2168*77c1e3ccSAndroid Build Coastguard Worker   tx_sf->inter_tx_size_search_init_depth_sqr = 0;
2169*77c1e3ccSAndroid Build Coastguard Worker   tx_sf->inter_tx_size_search_init_depth_rect = 0;
2170*77c1e3ccSAndroid Build Coastguard Worker   tx_sf->intra_tx_size_search_init_depth_rect = 0;
2171*77c1e3ccSAndroid Build Coastguard Worker   tx_sf->intra_tx_size_search_init_depth_sqr = 0;
2172*77c1e3ccSAndroid Build Coastguard Worker   tx_sf->tx_size_search_lgr_block = 0;
2173*77c1e3ccSAndroid Build Coastguard Worker   tx_sf->model_based_prune_tx_search_level = 0;
2174*77c1e3ccSAndroid Build Coastguard Worker   tx_sf->tx_type_search.prune_2d_txfm_mode = TX_TYPE_PRUNE_1;
2175*77c1e3ccSAndroid Build Coastguard Worker   tx_sf->tx_type_search.ml_tx_split_thresh = 8500;
2176*77c1e3ccSAndroid Build Coastguard Worker   tx_sf->tx_type_search.use_skip_flag_prediction = 1;
2177*77c1e3ccSAndroid Build Coastguard Worker   tx_sf->tx_type_search.use_reduced_intra_txset = 0;
2178*77c1e3ccSAndroid Build Coastguard Worker   tx_sf->tx_type_search.fast_intra_tx_type_search = 0;
2179*77c1e3ccSAndroid Build Coastguard Worker   tx_sf->tx_type_search.fast_inter_tx_type_prob_thresh = INT_MAX;
2180*77c1e3ccSAndroid Build Coastguard Worker   tx_sf->tx_type_search.skip_tx_search = 0;
2181*77c1e3ccSAndroid Build Coastguard Worker   tx_sf->tx_type_search.prune_tx_type_using_stats = 0;
2182*77c1e3ccSAndroid Build Coastguard Worker   tx_sf->tx_type_search.prune_tx_type_est_rd = 0;
2183*77c1e3ccSAndroid Build Coastguard Worker   tx_sf->tx_type_search.winner_mode_tx_type_pruning = 0;
2184*77c1e3ccSAndroid Build Coastguard Worker   tx_sf->txb_split_cap = 1;
2185*77c1e3ccSAndroid Build Coastguard Worker   tx_sf->adaptive_txb_search_level = 0;
2186*77c1e3ccSAndroid Build Coastguard Worker   tx_sf->refine_fast_tx_search_results = 1;
2187*77c1e3ccSAndroid Build Coastguard Worker   tx_sf->prune_tx_size_level = 0;
2188*77c1e3ccSAndroid Build Coastguard Worker   tx_sf->prune_intra_tx_depths_using_nn = false;
2189*77c1e3ccSAndroid Build Coastguard Worker   tx_sf->use_rd_based_breakout_for_intra_tx_search = false;
2190*77c1e3ccSAndroid Build Coastguard Worker }
2191*77c1e3ccSAndroid Build Coastguard Worker 
init_rd_sf(RD_CALC_SPEED_FEATURES * rd_sf,const AV1EncoderConfig * oxcf)2192*77c1e3ccSAndroid Build Coastguard Worker static inline void init_rd_sf(RD_CALC_SPEED_FEATURES *rd_sf,
2193*77c1e3ccSAndroid Build Coastguard Worker                               const AV1EncoderConfig *oxcf) {
2194*77c1e3ccSAndroid Build Coastguard Worker   const int disable_trellis_quant = oxcf->algo_cfg.disable_trellis_quant;
2195*77c1e3ccSAndroid Build Coastguard Worker   if (disable_trellis_quant == 3) {
2196*77c1e3ccSAndroid Build Coastguard Worker     rd_sf->optimize_coefficients = !is_lossless_requested(&oxcf->rc_cfg)
2197*77c1e3ccSAndroid Build Coastguard Worker                                        ? NO_ESTIMATE_YRD_TRELLIS_OPT
2198*77c1e3ccSAndroid Build Coastguard Worker                                        : NO_TRELLIS_OPT;
2199*77c1e3ccSAndroid Build Coastguard Worker   } else if (disable_trellis_quant == 2) {
2200*77c1e3ccSAndroid Build Coastguard Worker     rd_sf->optimize_coefficients = !is_lossless_requested(&oxcf->rc_cfg)
2201*77c1e3ccSAndroid Build Coastguard Worker                                        ? FINAL_PASS_TRELLIS_OPT
2202*77c1e3ccSAndroid Build Coastguard Worker                                        : NO_TRELLIS_OPT;
2203*77c1e3ccSAndroid Build Coastguard Worker   } else if (disable_trellis_quant == 0) {
2204*77c1e3ccSAndroid Build Coastguard Worker     if (is_lossless_requested(&oxcf->rc_cfg)) {
2205*77c1e3ccSAndroid Build Coastguard Worker       rd_sf->optimize_coefficients = NO_TRELLIS_OPT;
2206*77c1e3ccSAndroid Build Coastguard Worker     } else {
2207*77c1e3ccSAndroid Build Coastguard Worker       rd_sf->optimize_coefficients = FULL_TRELLIS_OPT;
2208*77c1e3ccSAndroid Build Coastguard Worker     }
2209*77c1e3ccSAndroid Build Coastguard Worker   } else if (disable_trellis_quant == 1) {
2210*77c1e3ccSAndroid Build Coastguard Worker     rd_sf->optimize_coefficients = NO_TRELLIS_OPT;
2211*77c1e3ccSAndroid Build Coastguard Worker   } else {
2212*77c1e3ccSAndroid Build Coastguard Worker     assert(0 && "Invalid disable_trellis_quant value");
2213*77c1e3ccSAndroid Build Coastguard Worker   }
2214*77c1e3ccSAndroid Build Coastguard Worker   rd_sf->use_mb_rd_hash = 0;
2215*77c1e3ccSAndroid Build Coastguard Worker   rd_sf->simple_model_rd_from_var = 0;
2216*77c1e3ccSAndroid Build Coastguard Worker   rd_sf->tx_domain_dist_level = 0;
2217*77c1e3ccSAndroid Build Coastguard Worker   rd_sf->tx_domain_dist_thres_level = 0;
2218*77c1e3ccSAndroid Build Coastguard Worker   rd_sf->perform_coeff_opt = 0;
2219*77c1e3ccSAndroid Build Coastguard Worker }
2220*77c1e3ccSAndroid Build Coastguard Worker 
init_winner_mode_sf(WINNER_MODE_SPEED_FEATURES * winner_mode_sf)2221*77c1e3ccSAndroid Build Coastguard Worker static inline void init_winner_mode_sf(
2222*77c1e3ccSAndroid Build Coastguard Worker     WINNER_MODE_SPEED_FEATURES *winner_mode_sf) {
2223*77c1e3ccSAndroid Build Coastguard Worker   winner_mode_sf->motion_mode_for_winner_cand = 0;
2224*77c1e3ccSAndroid Build Coastguard Worker   // Set this at the appropriate speed levels
2225*77c1e3ccSAndroid Build Coastguard Worker   winner_mode_sf->tx_size_search_level = 0;
2226*77c1e3ccSAndroid Build Coastguard Worker   winner_mode_sf->enable_winner_mode_for_coeff_opt = 0;
2227*77c1e3ccSAndroid Build Coastguard Worker   winner_mode_sf->enable_winner_mode_for_tx_size_srch = 0;
2228*77c1e3ccSAndroid Build Coastguard Worker   winner_mode_sf->enable_winner_mode_for_use_tx_domain_dist = 0;
2229*77c1e3ccSAndroid Build Coastguard Worker   winner_mode_sf->multi_winner_mode_type = 0;
2230*77c1e3ccSAndroid Build Coastguard Worker   winner_mode_sf->dc_blk_pred_level = 0;
2231*77c1e3ccSAndroid Build Coastguard Worker   winner_mode_sf->winner_mode_ifs = 0;
2232*77c1e3ccSAndroid Build Coastguard Worker   winner_mode_sf->prune_winner_mode_eval_level = 0;
2233*77c1e3ccSAndroid Build Coastguard Worker }
2234*77c1e3ccSAndroid Build Coastguard Worker 
init_lpf_sf(LOOP_FILTER_SPEED_FEATURES * lpf_sf)2235*77c1e3ccSAndroid Build Coastguard Worker static inline void init_lpf_sf(LOOP_FILTER_SPEED_FEATURES *lpf_sf) {
2236*77c1e3ccSAndroid Build Coastguard Worker   lpf_sf->disable_loop_restoration_chroma = 0;
2237*77c1e3ccSAndroid Build Coastguard Worker   lpf_sf->disable_loop_restoration_luma = 0;
2238*77c1e3ccSAndroid Build Coastguard Worker   lpf_sf->min_lr_unit_size = RESTORATION_PROC_UNIT_SIZE;
2239*77c1e3ccSAndroid Build Coastguard Worker   lpf_sf->max_lr_unit_size = RESTORATION_UNITSIZE_MAX;
2240*77c1e3ccSAndroid Build Coastguard Worker   lpf_sf->prune_wiener_based_on_src_var = 0;
2241*77c1e3ccSAndroid Build Coastguard Worker   lpf_sf->prune_sgr_based_on_wiener = 0;
2242*77c1e3ccSAndroid Build Coastguard Worker   lpf_sf->enable_sgr_ep_pruning = 0;
2243*77c1e3ccSAndroid Build Coastguard Worker   lpf_sf->reduce_wiener_window_size = 0;
2244*77c1e3ccSAndroid Build Coastguard Worker   lpf_sf->lpf_pick = LPF_PICK_FROM_FULL_IMAGE;
2245*77c1e3ccSAndroid Build Coastguard Worker   lpf_sf->use_coarse_filter_level_search = 0;
2246*77c1e3ccSAndroid Build Coastguard Worker   lpf_sf->cdef_pick_method = CDEF_FULL_SEARCH;
2247*77c1e3ccSAndroid Build Coastguard Worker   // Set decoder side speed feature to use less dual sgr modes
2248*77c1e3ccSAndroid Build Coastguard Worker   lpf_sf->dual_sgr_penalty_level = 0;
2249*77c1e3ccSAndroid Build Coastguard Worker   // Enable Wiener and Self-guided Loop restoration filters by default.
2250*77c1e3ccSAndroid Build Coastguard Worker   lpf_sf->disable_wiener_filter = false;
2251*77c1e3ccSAndroid Build Coastguard Worker   lpf_sf->disable_sgr_filter = false;
2252*77c1e3ccSAndroid Build Coastguard Worker   lpf_sf->disable_wiener_coeff_refine_search = false;
2253*77c1e3ccSAndroid Build Coastguard Worker   lpf_sf->use_downsampled_wiener_stats = 0;
2254*77c1e3ccSAndroid Build Coastguard Worker }
2255*77c1e3ccSAndroid Build Coastguard Worker 
init_rt_sf(REAL_TIME_SPEED_FEATURES * rt_sf)2256*77c1e3ccSAndroid Build Coastguard Worker static inline void init_rt_sf(REAL_TIME_SPEED_FEATURES *rt_sf) {
2257*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->check_intra_pred_nonrd = 0;
2258*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->skip_intra_pred = 0;
2259*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->estimate_motion_for_var_based_partition = 0;
2260*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->nonrd_check_partition_merge_mode = 0;
2261*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->nonrd_check_partition_split = 0;
2262*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->mode_search_skip_flags = 0;
2263*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->nonrd_prune_ref_frame_search = 0;
2264*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->use_nonrd_pick_mode = 0;
2265*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->use_nonrd_altref_frame = 0;
2266*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->use_comp_ref_nonrd = 0;
2267*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->use_real_time_ref_set = 0;
2268*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->short_circuit_low_temp_var = 0;
2269*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->reuse_inter_pred_nonrd = 0;
2270*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->num_inter_modes_for_tx_search = INT_MAX;
2271*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->use_nonrd_filter_search = 0;
2272*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->use_simple_rd_model = 0;
2273*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->hybrid_intra_pickmode = 0;
2274*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->prune_palette_search_nonrd = 0;
2275*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->source_metrics_sb_nonrd = 0;
2276*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->overshoot_detection_cbr = NO_DETECTION;
2277*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->check_scene_detection = 0;
2278*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->rc_adjust_keyframe = 0;
2279*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->rc_compute_spatial_var_sc = 0;
2280*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->prefer_large_partition_blocks = 0;
2281*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->use_temporal_noise_estimate = 0;
2282*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->fullpel_search_step_param = 0;
2283*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < BLOCK_SIZES; ++i)
2284*77c1e3ccSAndroid Build Coastguard Worker     rt_sf->intra_y_mode_bsize_mask_nrd[i] = INTRA_ALL;
2285*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->prune_hv_pred_modes_using_src_sad = false;
2286*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->nonrd_aggressive_skip = 0;
2287*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->skip_cdef_sb = 0;
2288*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->force_large_partition_blocks_intra = 0;
2289*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->skip_tx_no_split_var_based_partition = 0;
2290*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->skip_newmv_mode_based_on_sse = 0;
2291*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->gf_length_lvl = 0;
2292*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->prune_inter_modes_with_golden_ref = 0;
2293*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->prune_inter_modes_wrt_gf_arf_based_on_sad = 0;
2294*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->prune_inter_modes_using_temp_var = 0;
2295*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->reduce_mv_pel_precision_highmotion = 0;
2296*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->reduce_mv_pel_precision_lowcomplex = 0;
2297*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->prune_intra_mode_based_on_mv_range = 0;
2298*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->var_part_split_threshold_shift = 7;
2299*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->gf_refresh_based_on_qp = 0;
2300*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->use_rtc_tf = 0;
2301*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->use_idtx_nonrd = 0;
2302*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->prune_idtx_nonrd = 0;
2303*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->dct_only_palette_nonrd = 0;
2304*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->part_early_exit_zeromv = 0;
2305*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->sse_early_term_inter_search = EARLY_TERM_DISABLED;
2306*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->skip_lf_screen = 0;
2307*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->thresh_active_maps_skip_lf_cdef = 100;
2308*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->sad_based_adp_altref_lag = 0;
2309*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->partition_direct_merging = 0;
2310*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->var_part_based_on_qidx = 0;
2311*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->tx_size_level_based_on_qstep = 0;
2312*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->vbp_prune_16x16_split_using_min_max_sub_blk_var = false;
2313*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->prune_compoundmode_with_singlecompound_var = false;
2314*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->frame_level_mode_cost_update = false;
2315*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->prune_h_pred_using_best_mode_so_far = false;
2316*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->enable_intra_mode_pruning_using_neighbors = false;
2317*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->prune_intra_mode_using_best_sad_so_far = false;
2318*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->check_only_zero_zeromv_on_large_blocks = false;
2319*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->disable_cdf_update_non_reference_frame = false;
2320*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->prune_compoundmode_with_singlemode_var = false;
2321*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->skip_compound_based_on_var = false;
2322*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->set_zeromv_skip_based_on_source_sad = 1;
2323*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->use_adaptive_subpel_search = false;
2324*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->screen_content_cdef_filter_qindex_thresh = 0;
2325*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->enable_ref_short_signaling = false;
2326*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->check_globalmv_on_single_ref = true;
2327*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->increase_color_thresh_palette = false;
2328*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->selective_cdf_update = 0;
2329*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->force_only_last_ref = 0;
2330*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->higher_thresh_scene_detection = 1;
2331*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->skip_newmv_flat_blocks_screen = 0;
2332*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->skip_encoding_non_reference_slide_change = 0;
2333*77c1e3ccSAndroid Build Coastguard Worker   rt_sf->rc_faster_convergence_static = 0;
2334*77c1e3ccSAndroid Build Coastguard Worker }
2335*77c1e3ccSAndroid Build Coastguard Worker 
2336*77c1e3ccSAndroid Build Coastguard Worker static fractional_mv_step_fp
2337*77c1e3ccSAndroid Build Coastguard Worker     *const fractional_mv_search[SUBPEL_SEARCH_METHODS] = {
2338*77c1e3ccSAndroid Build Coastguard Worker       av1_find_best_sub_pixel_tree,             // SUBPEL_TREE = 0
2339*77c1e3ccSAndroid Build Coastguard Worker       av1_find_best_sub_pixel_tree_pruned,      // SUBPEL_TREE_PRUNED = 1
2340*77c1e3ccSAndroid Build Coastguard Worker       av1_find_best_sub_pixel_tree_pruned_more  // SUBPEL_TREE_PRUNED_MORE = 2
2341*77c1e3ccSAndroid Build Coastguard Worker     };
2342*77c1e3ccSAndroid Build Coastguard Worker 
2343*77c1e3ccSAndroid Build Coastguard Worker // Populate appropriate sub-pel search method based on speed feature and user
2344*77c1e3ccSAndroid Build Coastguard Worker // specified settings
set_subpel_search_method(MotionVectorSearchParams * mv_search_params,unsigned int motion_vector_unit_test,SUBPEL_SEARCH_METHOD subpel_search_method)2345*77c1e3ccSAndroid Build Coastguard Worker static void set_subpel_search_method(
2346*77c1e3ccSAndroid Build Coastguard Worker     MotionVectorSearchParams *mv_search_params,
2347*77c1e3ccSAndroid Build Coastguard Worker     unsigned int motion_vector_unit_test,
2348*77c1e3ccSAndroid Build Coastguard Worker     SUBPEL_SEARCH_METHOD subpel_search_method) {
2349*77c1e3ccSAndroid Build Coastguard Worker   assert(subpel_search_method <= SUBPEL_TREE_PRUNED_MORE);
2350*77c1e3ccSAndroid Build Coastguard Worker   mv_search_params->find_fractional_mv_step =
2351*77c1e3ccSAndroid Build Coastguard Worker       fractional_mv_search[subpel_search_method];
2352*77c1e3ccSAndroid Build Coastguard Worker 
2353*77c1e3ccSAndroid Build Coastguard Worker   // This is only used in motion vector unit test.
2354*77c1e3ccSAndroid Build Coastguard Worker   if (motion_vector_unit_test == 1)
2355*77c1e3ccSAndroid Build Coastguard Worker     mv_search_params->find_fractional_mv_step = av1_return_max_sub_pixel_mv;
2356*77c1e3ccSAndroid Build Coastguard Worker   else if (motion_vector_unit_test == 2)
2357*77c1e3ccSAndroid Build Coastguard Worker     mv_search_params->find_fractional_mv_step = av1_return_min_sub_pixel_mv;
2358*77c1e3ccSAndroid Build Coastguard Worker }
2359*77c1e3ccSAndroid Build Coastguard Worker 
av1_set_speed_features_framesize_dependent(AV1_COMP * cpi,int speed)2360*77c1e3ccSAndroid Build Coastguard Worker void av1_set_speed_features_framesize_dependent(AV1_COMP *cpi, int speed) {
2361*77c1e3ccSAndroid Build Coastguard Worker   SPEED_FEATURES *const sf = &cpi->sf;
2362*77c1e3ccSAndroid Build Coastguard Worker   const AV1EncoderConfig *const oxcf = &cpi->oxcf;
2363*77c1e3ccSAndroid Build Coastguard Worker 
2364*77c1e3ccSAndroid Build Coastguard Worker   switch (oxcf->mode) {
2365*77c1e3ccSAndroid Build Coastguard Worker     case GOOD:
2366*77c1e3ccSAndroid Build Coastguard Worker       set_good_speed_feature_framesize_dependent(cpi, sf, speed);
2367*77c1e3ccSAndroid Build Coastguard Worker       break;
2368*77c1e3ccSAndroid Build Coastguard Worker     case ALLINTRA:
2369*77c1e3ccSAndroid Build Coastguard Worker       set_allintra_speed_feature_framesize_dependent(cpi, sf, speed);
2370*77c1e3ccSAndroid Build Coastguard Worker       break;
2371*77c1e3ccSAndroid Build Coastguard Worker     case REALTIME:
2372*77c1e3ccSAndroid Build Coastguard Worker       set_rt_speed_feature_framesize_dependent(cpi, sf, speed);
2373*77c1e3ccSAndroid Build Coastguard Worker       break;
2374*77c1e3ccSAndroid Build Coastguard Worker   }
2375*77c1e3ccSAndroid Build Coastguard Worker 
2376*77c1e3ccSAndroid Build Coastguard Worker   if (!cpi->ppi->seq_params_locked) {
2377*77c1e3ccSAndroid Build Coastguard Worker     cpi->common.seq_params->enable_masked_compound &=
2378*77c1e3ccSAndroid Build Coastguard Worker         !sf->inter_sf.disable_masked_comp;
2379*77c1e3ccSAndroid Build Coastguard Worker     cpi->common.seq_params->enable_interintra_compound &=
2380*77c1e3ccSAndroid Build Coastguard Worker         (sf->inter_sf.disable_interintra_wedge_var_thresh != UINT_MAX);
2381*77c1e3ccSAndroid Build Coastguard Worker   }
2382*77c1e3ccSAndroid Build Coastguard Worker 
2383*77c1e3ccSAndroid Build Coastguard Worker   set_subpel_search_method(&cpi->mv_search_params,
2384*77c1e3ccSAndroid Build Coastguard Worker                            cpi->oxcf.unit_test_cfg.motion_vector_unit_test,
2385*77c1e3ccSAndroid Build Coastguard Worker                            sf->mv_sf.subpel_search_method);
2386*77c1e3ccSAndroid Build Coastguard Worker 
2387*77c1e3ccSAndroid Build Coastguard Worker   // For multi-thread use case with row_mt enabled, cost update for a set of
2388*77c1e3ccSAndroid Build Coastguard Worker   // SB rows is not desirable. Hence, the sf mv_cost_upd_level is set to
2389*77c1e3ccSAndroid Build Coastguard Worker   // INTERNAL_COST_UPD_SBROW in such cases.
2390*77c1e3ccSAndroid Build Coastguard Worker   if ((cpi->oxcf.row_mt == 1) && (cpi->mt_info.num_workers > 1)) {
2391*77c1e3ccSAndroid Build Coastguard Worker     if (sf->inter_sf.mv_cost_upd_level == INTERNAL_COST_UPD_SBROW_SET) {
2392*77c1e3ccSAndroid Build Coastguard Worker       // Set mv_cost_upd_level to use row level update.
2393*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.mv_cost_upd_level = INTERNAL_COST_UPD_SBROW;
2394*77c1e3ccSAndroid Build Coastguard Worker     }
2395*77c1e3ccSAndroid Build Coastguard Worker   }
2396*77c1e3ccSAndroid Build Coastguard Worker }
2397*77c1e3ccSAndroid Build Coastguard Worker 
av1_set_speed_features_framesize_independent(AV1_COMP * cpi,int speed)2398*77c1e3ccSAndroid Build Coastguard Worker void av1_set_speed_features_framesize_independent(AV1_COMP *cpi, int speed) {
2399*77c1e3ccSAndroid Build Coastguard Worker   SPEED_FEATURES *const sf = &cpi->sf;
2400*77c1e3ccSAndroid Build Coastguard Worker   WinnerModeParams *const winner_mode_params = &cpi->winner_mode_params;
2401*77c1e3ccSAndroid Build Coastguard Worker   const AV1EncoderConfig *const oxcf = &cpi->oxcf;
2402*77c1e3ccSAndroid Build Coastguard Worker   int i;
2403*77c1e3ccSAndroid Build Coastguard Worker 
2404*77c1e3ccSAndroid Build Coastguard Worker   init_hl_sf(&sf->hl_sf);
2405*77c1e3ccSAndroid Build Coastguard Worker   init_fp_sf(&sf->fp_sf);
2406*77c1e3ccSAndroid Build Coastguard Worker   init_tpl_sf(&sf->tpl_sf);
2407*77c1e3ccSAndroid Build Coastguard Worker   init_gm_sf(&sf->gm_sf);
2408*77c1e3ccSAndroid Build Coastguard Worker   init_part_sf(&sf->part_sf);
2409*77c1e3ccSAndroid Build Coastguard Worker   init_mv_sf(&sf->mv_sf);
2410*77c1e3ccSAndroid Build Coastguard Worker   init_inter_sf(&sf->inter_sf);
2411*77c1e3ccSAndroid Build Coastguard Worker   init_interp_sf(&sf->interp_sf);
2412*77c1e3ccSAndroid Build Coastguard Worker   init_intra_sf(&sf->intra_sf);
2413*77c1e3ccSAndroid Build Coastguard Worker   init_tx_sf(&sf->tx_sf);
2414*77c1e3ccSAndroid Build Coastguard Worker   init_rd_sf(&sf->rd_sf, oxcf);
2415*77c1e3ccSAndroid Build Coastguard Worker   init_winner_mode_sf(&sf->winner_mode_sf);
2416*77c1e3ccSAndroid Build Coastguard Worker   init_lpf_sf(&sf->lpf_sf);
2417*77c1e3ccSAndroid Build Coastguard Worker   init_rt_sf(&sf->rt_sf);
2418*77c1e3ccSAndroid Build Coastguard Worker 
2419*77c1e3ccSAndroid Build Coastguard Worker   switch (oxcf->mode) {
2420*77c1e3ccSAndroid Build Coastguard Worker     case GOOD:
2421*77c1e3ccSAndroid Build Coastguard Worker       set_good_speed_features_framesize_independent(cpi, sf, speed);
2422*77c1e3ccSAndroid Build Coastguard Worker       break;
2423*77c1e3ccSAndroid Build Coastguard Worker     case ALLINTRA:
2424*77c1e3ccSAndroid Build Coastguard Worker       set_allintra_speed_features_framesize_independent(cpi, sf, speed);
2425*77c1e3ccSAndroid Build Coastguard Worker       break;
2426*77c1e3ccSAndroid Build Coastguard Worker     case REALTIME:
2427*77c1e3ccSAndroid Build Coastguard Worker       set_rt_speed_features_framesize_independent(cpi, sf, speed);
2428*77c1e3ccSAndroid Build Coastguard Worker       break;
2429*77c1e3ccSAndroid Build Coastguard Worker   }
2430*77c1e3ccSAndroid Build Coastguard Worker 
2431*77c1e3ccSAndroid Build Coastguard Worker   // Note: when use_nonrd_pick_mode is true, the transform size is the
2432*77c1e3ccSAndroid Build Coastguard Worker   // minimum of 16x16 and the largest possible size of the current block,
2433*77c1e3ccSAndroid Build Coastguard Worker   // which conflicts with the speed feature "enable_tx_size_search".
2434*77c1e3ccSAndroid Build Coastguard Worker   if (!oxcf->txfm_cfg.enable_tx_size_search &&
2435*77c1e3ccSAndroid Build Coastguard Worker       sf->rt_sf.use_nonrd_pick_mode == 0) {
2436*77c1e3ccSAndroid Build Coastguard Worker     sf->winner_mode_sf.tx_size_search_level = 3;
2437*77c1e3ccSAndroid Build Coastguard Worker   }
2438*77c1e3ccSAndroid Build Coastguard Worker 
2439*77c1e3ccSAndroid Build Coastguard Worker   if (cpi->mt_info.num_workers > 1) {
2440*77c1e3ccSAndroid Build Coastguard Worker     // Loop restoration stage is conditionally disabled for speed 5, 6 when
2441*77c1e3ccSAndroid Build Coastguard Worker     // num_workers > 1. Since av1_pick_filter_restoration() is not
2442*77c1e3ccSAndroid Build Coastguard Worker     // multi-threaded, enabling the Loop restoration stage will cause an
2443*77c1e3ccSAndroid Build Coastguard Worker     // increase in encode time (3% to 7% increase depends on frame
2444*77c1e3ccSAndroid Build Coastguard Worker     // resolution).
2445*77c1e3ccSAndroid Build Coastguard Worker     // TODO(aomedia:3446): Implement multi-threading of
2446*77c1e3ccSAndroid Build Coastguard Worker     // av1_pick_filter_restoration() and enable Wiener filter for speed 5, 6
2447*77c1e3ccSAndroid Build Coastguard Worker     // similar to single thread encoding path.
2448*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 5) {
2449*77c1e3ccSAndroid Build Coastguard Worker       sf->lpf_sf.disable_sgr_filter = true;
2450*77c1e3ccSAndroid Build Coastguard Worker       sf->lpf_sf.disable_wiener_filter = true;
2451*77c1e3ccSAndroid Build Coastguard Worker     }
2452*77c1e3ccSAndroid Build Coastguard Worker   }
2453*77c1e3ccSAndroid Build Coastguard Worker 
2454*77c1e3ccSAndroid Build Coastguard Worker   if (!cpi->ppi->seq_params_locked) {
2455*77c1e3ccSAndroid Build Coastguard Worker     cpi->common.seq_params->order_hint_info.enable_dist_wtd_comp &=
2456*77c1e3ccSAndroid Build Coastguard Worker         (sf->inter_sf.use_dist_wtd_comp_flag != DIST_WTD_COMP_DISABLED);
2457*77c1e3ccSAndroid Build Coastguard Worker     cpi->common.seq_params->enable_dual_filter &=
2458*77c1e3ccSAndroid Build Coastguard Worker         !sf->interp_sf.disable_dual_filter;
2459*77c1e3ccSAndroid Build Coastguard Worker     // Set the flag 'enable_restoration', if one the Loop restoration filters
2460*77c1e3ccSAndroid Build Coastguard Worker     // (i.e., Wiener or Self-guided) is enabled.
2461*77c1e3ccSAndroid Build Coastguard Worker     cpi->common.seq_params->enable_restoration &=
2462*77c1e3ccSAndroid Build Coastguard Worker         (!sf->lpf_sf.disable_wiener_filter || !sf->lpf_sf.disable_sgr_filter);
2463*77c1e3ccSAndroid Build Coastguard Worker 
2464*77c1e3ccSAndroid Build Coastguard Worker     cpi->common.seq_params->enable_interintra_compound &=
2465*77c1e3ccSAndroid Build Coastguard Worker         (sf->inter_sf.disable_interintra_wedge_var_thresh != UINT_MAX);
2466*77c1e3ccSAndroid Build Coastguard Worker   }
2467*77c1e3ccSAndroid Build Coastguard Worker 
2468*77c1e3ccSAndroid Build Coastguard Worker   const int mesh_speed = AOMMIN(speed, MAX_MESH_SPEED);
2469*77c1e3ccSAndroid Build Coastguard Worker   for (i = 0; i < MAX_MESH_STEP; ++i) {
2470*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.mesh_patterns[i].range =
2471*77c1e3ccSAndroid Build Coastguard Worker         good_quality_mesh_patterns[mesh_speed][i].range;
2472*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.mesh_patterns[i].interval =
2473*77c1e3ccSAndroid Build Coastguard Worker         good_quality_mesh_patterns[mesh_speed][i].interval;
2474*77c1e3ccSAndroid Build Coastguard Worker   }
2475*77c1e3ccSAndroid Build Coastguard Worker 
2476*77c1e3ccSAndroid Build Coastguard Worker   // Update the mesh pattern of exhaustive motion search for intraBC
2477*77c1e3ccSAndroid Build Coastguard Worker   // Though intraBC mesh pattern is populated for all frame types, it is used
2478*77c1e3ccSAndroid Build Coastguard Worker   // only for intra frames of screen contents
2479*77c1e3ccSAndroid Build Coastguard Worker   for (i = 0; i < MAX_MESH_STEP; ++i) {
2480*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.intrabc_mesh_patterns[i].range =
2481*77c1e3ccSAndroid Build Coastguard Worker         intrabc_mesh_patterns[mesh_speed][i].range;
2482*77c1e3ccSAndroid Build Coastguard Worker     sf->mv_sf.intrabc_mesh_patterns[i].interval =
2483*77c1e3ccSAndroid Build Coastguard Worker         intrabc_mesh_patterns[mesh_speed][i].interval;
2484*77c1e3ccSAndroid Build Coastguard Worker   }
2485*77c1e3ccSAndroid Build Coastguard Worker 
2486*77c1e3ccSAndroid Build Coastguard Worker   // Slow quant, dct and trellis not worthwhile for first pass
2487*77c1e3ccSAndroid Build Coastguard Worker   // so make sure they are always turned off.
2488*77c1e3ccSAndroid Build Coastguard Worker   if (is_stat_generation_stage(cpi))
2489*77c1e3ccSAndroid Build Coastguard Worker     sf->rd_sf.optimize_coefficients = NO_TRELLIS_OPT;
2490*77c1e3ccSAndroid Build Coastguard Worker 
2491*77c1e3ccSAndroid Build Coastguard Worker   // No recode for 1 pass.
2492*77c1e3ccSAndroid Build Coastguard Worker   if (oxcf->pass == AOM_RC_ONE_PASS && has_no_stats_stage(cpi))
2493*77c1e3ccSAndroid Build Coastguard Worker     sf->hl_sf.recode_loop = DISALLOW_RECODE;
2494*77c1e3ccSAndroid Build Coastguard Worker 
2495*77c1e3ccSAndroid Build Coastguard Worker   set_subpel_search_method(&cpi->mv_search_params,
2496*77c1e3ccSAndroid Build Coastguard Worker                            cpi->oxcf.unit_test_cfg.motion_vector_unit_test,
2497*77c1e3ccSAndroid Build Coastguard Worker                            sf->mv_sf.subpel_search_method);
2498*77c1e3ccSAndroid Build Coastguard Worker 
2499*77c1e3ccSAndroid Build Coastguard Worker   // assert ensures that tx_domain_dist_level is accessed correctly
2500*77c1e3ccSAndroid Build Coastguard Worker   assert(cpi->sf.rd_sf.tx_domain_dist_thres_level >= 0 &&
2501*77c1e3ccSAndroid Build Coastguard Worker          cpi->sf.rd_sf.tx_domain_dist_thres_level < 4);
2502*77c1e3ccSAndroid Build Coastguard Worker   memcpy(winner_mode_params->tx_domain_dist_threshold,
2503*77c1e3ccSAndroid Build Coastguard Worker          tx_domain_dist_thresholds[cpi->sf.rd_sf.tx_domain_dist_thres_level],
2504*77c1e3ccSAndroid Build Coastguard Worker          sizeof(winner_mode_params->tx_domain_dist_threshold));
2505*77c1e3ccSAndroid Build Coastguard Worker 
2506*77c1e3ccSAndroid Build Coastguard Worker   assert(cpi->sf.rd_sf.tx_domain_dist_level >= 0 &&
2507*77c1e3ccSAndroid Build Coastguard Worker          cpi->sf.rd_sf.tx_domain_dist_level < TX_DOMAIN_DIST_LEVELS);
2508*77c1e3ccSAndroid Build Coastguard Worker   memcpy(winner_mode_params->use_transform_domain_distortion,
2509*77c1e3ccSAndroid Build Coastguard Worker          tx_domain_dist_types[cpi->sf.rd_sf.tx_domain_dist_level],
2510*77c1e3ccSAndroid Build Coastguard Worker          sizeof(winner_mode_params->use_transform_domain_distortion));
2511*77c1e3ccSAndroid Build Coastguard Worker 
2512*77c1e3ccSAndroid Build Coastguard Worker   // assert ensures that coeff_opt_thresholds is accessed correctly
2513*77c1e3ccSAndroid Build Coastguard Worker   assert(cpi->sf.rd_sf.perform_coeff_opt >= 0 &&
2514*77c1e3ccSAndroid Build Coastguard Worker          cpi->sf.rd_sf.perform_coeff_opt < 9);
2515*77c1e3ccSAndroid Build Coastguard Worker   memcpy(winner_mode_params->coeff_opt_thresholds,
2516*77c1e3ccSAndroid Build Coastguard Worker          &coeff_opt_thresholds[cpi->sf.rd_sf.perform_coeff_opt],
2517*77c1e3ccSAndroid Build Coastguard Worker          sizeof(winner_mode_params->coeff_opt_thresholds));
2518*77c1e3ccSAndroid Build Coastguard Worker 
2519*77c1e3ccSAndroid Build Coastguard Worker   // assert ensures that predict_skip_levels is accessed correctly
2520*77c1e3ccSAndroid Build Coastguard Worker   assert(cpi->sf.tx_sf.tx_type_search.use_skip_flag_prediction >= 0 &&
2521*77c1e3ccSAndroid Build Coastguard Worker          cpi->sf.tx_sf.tx_type_search.use_skip_flag_prediction < 3);
2522*77c1e3ccSAndroid Build Coastguard Worker   memcpy(winner_mode_params->skip_txfm_level,
2523*77c1e3ccSAndroid Build Coastguard Worker          predict_skip_levels[cpi->sf.tx_sf.tx_type_search
2524*77c1e3ccSAndroid Build Coastguard Worker                                  .use_skip_flag_prediction],
2525*77c1e3ccSAndroid Build Coastguard Worker          sizeof(winner_mode_params->skip_txfm_level));
2526*77c1e3ccSAndroid Build Coastguard Worker 
2527*77c1e3ccSAndroid Build Coastguard Worker   // assert ensures that tx_size_search_level is accessed correctly
2528*77c1e3ccSAndroid Build Coastguard Worker   assert(cpi->sf.winner_mode_sf.tx_size_search_level >= 0 &&
2529*77c1e3ccSAndroid Build Coastguard Worker          cpi->sf.winner_mode_sf.tx_size_search_level <= 3);
2530*77c1e3ccSAndroid Build Coastguard Worker   memcpy(winner_mode_params->tx_size_search_methods,
2531*77c1e3ccSAndroid Build Coastguard Worker          tx_size_search_methods[cpi->sf.winner_mode_sf.tx_size_search_level],
2532*77c1e3ccSAndroid Build Coastguard Worker          sizeof(winner_mode_params->tx_size_search_methods));
2533*77c1e3ccSAndroid Build Coastguard Worker   memcpy(winner_mode_params->predict_dc_level,
2534*77c1e3ccSAndroid Build Coastguard Worker          predict_dc_levels[cpi->sf.winner_mode_sf.dc_blk_pred_level],
2535*77c1e3ccSAndroid Build Coastguard Worker          sizeof(winner_mode_params->predict_dc_level));
2536*77c1e3ccSAndroid Build Coastguard Worker 
2537*77c1e3ccSAndroid Build Coastguard Worker   if (cpi->oxcf.row_mt == 1 && (cpi->mt_info.num_workers > 1)) {
2538*77c1e3ccSAndroid Build Coastguard Worker     if (sf->inter_sf.inter_mode_rd_model_estimation == 1) {
2539*77c1e3ccSAndroid Build Coastguard Worker       // Revert to type 2
2540*77c1e3ccSAndroid Build Coastguard Worker       sf->inter_sf.inter_mode_rd_model_estimation = 2;
2541*77c1e3ccSAndroid Build Coastguard Worker     }
2542*77c1e3ccSAndroid Build Coastguard Worker 
2543*77c1e3ccSAndroid Build Coastguard Worker #if !CONFIG_FPMT_TEST
2544*77c1e3ccSAndroid Build Coastguard Worker     // Disable the speed feature 'prune_ref_frame_for_gm_search' to achieve
2545*77c1e3ccSAndroid Build Coastguard Worker     // better parallelism when number of threads available are greater than or
2546*77c1e3ccSAndroid Build Coastguard Worker     // equal to maximum number of reference frames allowed for global motion.
2547*77c1e3ccSAndroid Build Coastguard Worker     if (sf->gm_sf.gm_search_type != GM_DISABLE_SEARCH &&
2548*77c1e3ccSAndroid Build Coastguard Worker         (cpi->mt_info.num_workers >=
2549*77c1e3ccSAndroid Build Coastguard Worker          gm_available_reference_frames[sf->gm_sf.gm_search_type]))
2550*77c1e3ccSAndroid Build Coastguard Worker       sf->gm_sf.prune_ref_frame_for_gm_search = 0;
2551*77c1e3ccSAndroid Build Coastguard Worker #endif
2552*77c1e3ccSAndroid Build Coastguard Worker   }
2553*77c1e3ccSAndroid Build Coastguard Worker 
2554*77c1e3ccSAndroid Build Coastguard Worker   // This only applies to the real time mode. Adaptive gf refresh is disabled if
2555*77c1e3ccSAndroid Build Coastguard Worker   // gf_cbr_boost_pct that is set by the user is larger than 0.
2556*77c1e3ccSAndroid Build Coastguard Worker   if (cpi->oxcf.rc_cfg.gf_cbr_boost_pct > 0)
2557*77c1e3ccSAndroid Build Coastguard Worker     sf->rt_sf.gf_refresh_based_on_qp = 0;
2558*77c1e3ccSAndroid Build Coastguard Worker }
2559*77c1e3ccSAndroid Build Coastguard Worker 
2560*77c1e3ccSAndroid Build Coastguard Worker // Override some speed features based on qindex
av1_set_speed_features_qindex_dependent(AV1_COMP * cpi,int speed)2561*77c1e3ccSAndroid Build Coastguard Worker void av1_set_speed_features_qindex_dependent(AV1_COMP *cpi, int speed) {
2562*77c1e3ccSAndroid Build Coastguard Worker   AV1_COMMON *const cm = &cpi->common;
2563*77c1e3ccSAndroid Build Coastguard Worker   SPEED_FEATURES *const sf = &cpi->sf;
2564*77c1e3ccSAndroid Build Coastguard Worker   WinnerModeParams *const winner_mode_params = &cpi->winner_mode_params;
2565*77c1e3ccSAndroid Build Coastguard Worker   const int boosted = frame_is_boosted(cpi);
2566*77c1e3ccSAndroid Build Coastguard Worker   const int is_480p_or_lesser = AOMMIN(cm->width, cm->height) <= 480;
2567*77c1e3ccSAndroid Build Coastguard Worker   const int is_480p_or_larger = AOMMIN(cm->width, cm->height) >= 480;
2568*77c1e3ccSAndroid Build Coastguard Worker   const int is_720p_or_larger = AOMMIN(cm->width, cm->height) >= 720;
2569*77c1e3ccSAndroid Build Coastguard Worker   const int is_1080p_or_larger = AOMMIN(cm->width, cm->height) >= 1080;
2570*77c1e3ccSAndroid Build Coastguard Worker   const int is_1440p_or_larger = AOMMIN(cm->width, cm->height) >= 1440;
2571*77c1e3ccSAndroid Build Coastguard Worker   const int is_arf2_bwd_type =
2572*77c1e3ccSAndroid Build Coastguard Worker       cpi->ppi->gf_group.update_type[cpi->gf_frame_index] == INTNL_ARF_UPDATE;
2573*77c1e3ccSAndroid Build Coastguard Worker 
2574*77c1e3ccSAndroid Build Coastguard Worker   if (cpi->oxcf.mode == REALTIME) {
2575*77c1e3ccSAndroid Build Coastguard Worker     if (speed >= 6) {
2576*77c1e3ccSAndroid Build Coastguard Worker       const int qindex_thresh = boosted ? 190 : (is_720p_or_larger ? 120 : 150);
2577*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.adjust_var_based_rd_partitioning =
2578*77c1e3ccSAndroid Build Coastguard Worker           frame_is_intra_only(cm)
2579*77c1e3ccSAndroid Build Coastguard Worker               ? 0
2580*77c1e3ccSAndroid Build Coastguard Worker               : cm->quant_params.base_qindex > qindex_thresh;
2581*77c1e3ccSAndroid Build Coastguard Worker     }
2582*77c1e3ccSAndroid Build Coastguard Worker     return;
2583*77c1e3ccSAndroid Build Coastguard Worker   }
2584*77c1e3ccSAndroid Build Coastguard Worker 
2585*77c1e3ccSAndroid Build Coastguard Worker   if (speed == 0) {
2586*77c1e3ccSAndroid Build Coastguard Worker     // qindex_thresh for resolution < 720p
2587*77c1e3ccSAndroid Build Coastguard Worker     const int qindex_thresh = boosted ? 70 : (is_arf2_bwd_type ? 110 : 140);
2588*77c1e3ccSAndroid Build Coastguard Worker     if (!is_720p_or_larger && cm->quant_params.base_qindex <= qindex_thresh) {
2589*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.simple_motion_search_split =
2590*77c1e3ccSAndroid Build Coastguard Worker           cm->features.allow_screen_content_tools ? 1 : 2;
2591*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.simple_motion_search_early_term_none = 1;
2592*77c1e3ccSAndroid Build Coastguard Worker       sf->tx_sf.model_based_prune_tx_search_level = 0;
2593*77c1e3ccSAndroid Build Coastguard Worker     }
2594*77c1e3ccSAndroid Build Coastguard Worker 
2595*77c1e3ccSAndroid Build Coastguard Worker     if (is_720p_or_larger && cm->quant_params.base_qindex <= 128) {
2596*77c1e3ccSAndroid Build Coastguard Worker       sf->rd_sf.perform_coeff_opt = 2 + is_1080p_or_larger;
2597*77c1e3ccSAndroid Build Coastguard Worker       memcpy(winner_mode_params->coeff_opt_thresholds,
2598*77c1e3ccSAndroid Build Coastguard Worker              &coeff_opt_thresholds[sf->rd_sf.perform_coeff_opt],
2599*77c1e3ccSAndroid Build Coastguard Worker              sizeof(winner_mode_params->coeff_opt_thresholds));
2600*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.simple_motion_search_split =
2601*77c1e3ccSAndroid Build Coastguard Worker           cm->features.allow_screen_content_tools ? 1 : 2;
2602*77c1e3ccSAndroid Build Coastguard Worker       sf->tx_sf.inter_tx_size_search_init_depth_rect = 1;
2603*77c1e3ccSAndroid Build Coastguard Worker       sf->tx_sf.inter_tx_size_search_init_depth_sqr = 1;
2604*77c1e3ccSAndroid Build Coastguard Worker       sf->tx_sf.intra_tx_size_search_init_depth_rect = 1;
2605*77c1e3ccSAndroid Build Coastguard Worker       sf->tx_sf.model_based_prune_tx_search_level = 0;
2606*77c1e3ccSAndroid Build Coastguard Worker 
2607*77c1e3ccSAndroid Build Coastguard Worker       if (is_1080p_or_larger && cm->quant_params.base_qindex <= 108) {
2608*77c1e3ccSAndroid Build Coastguard Worker         sf->inter_sf.selective_ref_frame = 2;
2609*77c1e3ccSAndroid Build Coastguard Worker         sf->rd_sf.tx_domain_dist_level = boosted ? 1 : 2;
2610*77c1e3ccSAndroid Build Coastguard Worker         sf->rd_sf.tx_domain_dist_thres_level = 1;
2611*77c1e3ccSAndroid Build Coastguard Worker         sf->part_sf.simple_motion_search_early_term_none = 1;
2612*77c1e3ccSAndroid Build Coastguard Worker         sf->tx_sf.tx_type_search.ml_tx_split_thresh = 4000;
2613*77c1e3ccSAndroid Build Coastguard Worker         sf->interp_sf.cb_pred_filter_search = 0;
2614*77c1e3ccSAndroid Build Coastguard Worker         sf->tx_sf.tx_type_search.prune_2d_txfm_mode = TX_TYPE_PRUNE_2;
2615*77c1e3ccSAndroid Build Coastguard Worker         sf->tx_sf.tx_type_search.skip_tx_search = 1;
2616*77c1e3ccSAndroid Build Coastguard Worker       }
2617*77c1e3ccSAndroid Build Coastguard Worker     }
2618*77c1e3ccSAndroid Build Coastguard Worker   }
2619*77c1e3ccSAndroid Build Coastguard Worker 
2620*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 2) {
2621*77c1e3ccSAndroid Build Coastguard Worker     // Disable extended partitions for lower quantizers
2622*77c1e3ccSAndroid Build Coastguard Worker     const int aggr = AOMMIN(4, speed - 2);
2623*77c1e3ccSAndroid Build Coastguard Worker     const int qindex_thresh1[4] = { 50, 50, 80, 100 };
2624*77c1e3ccSAndroid Build Coastguard Worker     const int qindex_thresh2[4] = { 80, 100, 120, 160 };
2625*77c1e3ccSAndroid Build Coastguard Worker     int qindex_thresh;
2626*77c1e3ccSAndroid Build Coastguard Worker     if (aggr <= 1) {
2627*77c1e3ccSAndroid Build Coastguard Worker       const int qthresh2 =
2628*77c1e3ccSAndroid Build Coastguard Worker           (!aggr && !is_480p_or_larger) ? 70 : qindex_thresh2[aggr];
2629*77c1e3ccSAndroid Build Coastguard Worker       qindex_thresh = cm->features.allow_screen_content_tools
2630*77c1e3ccSAndroid Build Coastguard Worker                           ? qindex_thresh1[aggr]
2631*77c1e3ccSAndroid Build Coastguard Worker                           : qthresh2;
2632*77c1e3ccSAndroid Build Coastguard Worker       if (cm->quant_params.base_qindex <= qindex_thresh && !boosted)
2633*77c1e3ccSAndroid Build Coastguard Worker         sf->part_sf.ext_partition_eval_thresh = BLOCK_128X128;
2634*77c1e3ccSAndroid Build Coastguard Worker     } else if (aggr <= 2) {
2635*77c1e3ccSAndroid Build Coastguard Worker       qindex_thresh = boosted ? qindex_thresh1[aggr] : qindex_thresh2[aggr];
2636*77c1e3ccSAndroid Build Coastguard Worker       if (cm->quant_params.base_qindex <= qindex_thresh &&
2637*77c1e3ccSAndroid Build Coastguard Worker           !frame_is_intra_only(cm))
2638*77c1e3ccSAndroid Build Coastguard Worker         sf->part_sf.ext_partition_eval_thresh = BLOCK_128X128;
2639*77c1e3ccSAndroid Build Coastguard Worker     } else if (aggr <= 3) {
2640*77c1e3ccSAndroid Build Coastguard Worker       if (!is_480p_or_larger) {
2641*77c1e3ccSAndroid Build Coastguard Worker         sf->part_sf.ext_partition_eval_thresh = BLOCK_128X128;
2642*77c1e3ccSAndroid Build Coastguard Worker       } else if (!is_720p_or_larger && !frame_is_intra_only(cm) &&
2643*77c1e3ccSAndroid Build Coastguard Worker                  !cm->features.allow_screen_content_tools) {
2644*77c1e3ccSAndroid Build Coastguard Worker         sf->part_sf.ext_partition_eval_thresh = BLOCK_128X128;
2645*77c1e3ccSAndroid Build Coastguard Worker       } else {
2646*77c1e3ccSAndroid Build Coastguard Worker         qindex_thresh = boosted ? qindex_thresh1[aggr] : qindex_thresh2[aggr];
2647*77c1e3ccSAndroid Build Coastguard Worker         if (cm->quant_params.base_qindex <= qindex_thresh &&
2648*77c1e3ccSAndroid Build Coastguard Worker             !frame_is_intra_only(cm))
2649*77c1e3ccSAndroid Build Coastguard Worker           sf->part_sf.ext_partition_eval_thresh = BLOCK_128X128;
2650*77c1e3ccSAndroid Build Coastguard Worker       }
2651*77c1e3ccSAndroid Build Coastguard Worker     } else {
2652*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.ext_partition_eval_thresh = BLOCK_128X128;
2653*77c1e3ccSAndroid Build Coastguard Worker     }
2654*77c1e3ccSAndroid Build Coastguard Worker   }
2655*77c1e3ccSAndroid Build Coastguard Worker 
2656*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 4) {
2657*77c1e3ccSAndroid Build Coastguard Worker     // Disable rectangular partitions for lower quantizers
2658*77c1e3ccSAndroid Build Coastguard Worker     const int aggr = AOMMIN(1, speed - 4);
2659*77c1e3ccSAndroid Build Coastguard Worker     const int qindex_thresh[2] = { 65, 80 };
2660*77c1e3ccSAndroid Build Coastguard Worker     int disable_rect_part;
2661*77c1e3ccSAndroid Build Coastguard Worker     disable_rect_part = !boosted;
2662*77c1e3ccSAndroid Build Coastguard Worker     if (cm->quant_params.base_qindex <= qindex_thresh[aggr] &&
2663*77c1e3ccSAndroid Build Coastguard Worker         disable_rect_part && is_480p_or_larger) {
2664*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.rect_partition_eval_thresh = BLOCK_8X8;
2665*77c1e3ccSAndroid Build Coastguard Worker     }
2666*77c1e3ccSAndroid Build Coastguard Worker   }
2667*77c1e3ccSAndroid Build Coastguard Worker 
2668*77c1e3ccSAndroid Build Coastguard Worker   if (speed <= 2) {
2669*77c1e3ccSAndroid Build Coastguard Worker     if (!is_stat_generation_stage(cpi)) {
2670*77c1e3ccSAndroid Build Coastguard Worker       // Use faster full-pel motion search for high quantizers.
2671*77c1e3ccSAndroid Build Coastguard Worker       // Also use reduced total search range for low resolutions at high
2672*77c1e3ccSAndroid Build Coastguard Worker       // quantizers.
2673*77c1e3ccSAndroid Build Coastguard Worker       const int aggr = speed;
2674*77c1e3ccSAndroid Build Coastguard Worker       const int qindex_thresh1 = ms_qindex_thresh[aggr][is_720p_or_larger][0];
2675*77c1e3ccSAndroid Build Coastguard Worker       const int qindex_thresh2 = ms_qindex_thresh[aggr][is_720p_or_larger][1];
2676*77c1e3ccSAndroid Build Coastguard Worker       const SEARCH_METHODS search_method =
2677*77c1e3ccSAndroid Build Coastguard Worker           motion_search_method[is_720p_or_larger];
2678*77c1e3ccSAndroid Build Coastguard Worker       if (cm->quant_params.base_qindex > qindex_thresh1) {
2679*77c1e3ccSAndroid Build Coastguard Worker         sf->mv_sf.search_method = search_method;
2680*77c1e3ccSAndroid Build Coastguard Worker         sf->tpl_sf.search_method = search_method;
2681*77c1e3ccSAndroid Build Coastguard Worker       } else if (cm->quant_params.base_qindex > qindex_thresh2) {
2682*77c1e3ccSAndroid Build Coastguard Worker         sf->mv_sf.search_method = NSTEP_8PT;
2683*77c1e3ccSAndroid Build Coastguard Worker       }
2684*77c1e3ccSAndroid Build Coastguard Worker     }
2685*77c1e3ccSAndroid Build Coastguard Worker   }
2686*77c1e3ccSAndroid Build Coastguard Worker 
2687*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 4) {
2688*77c1e3ccSAndroid Build Coastguard Worker     // Disable LR search at low and high quantizers and enable only for
2689*77c1e3ccSAndroid Build Coastguard Worker     // mid-quantizer range.
2690*77c1e3ccSAndroid Build Coastguard Worker     if (!boosted && !is_arf2_bwd_type) {
2691*77c1e3ccSAndroid Build Coastguard Worker       const int qindex_low[2] = { 100, 60 };
2692*77c1e3ccSAndroid Build Coastguard Worker       const int qindex_high[2] = { 180, 160 };
2693*77c1e3ccSAndroid Build Coastguard Worker       if (cm->quant_params.base_qindex <= qindex_low[is_720p_or_larger] ||
2694*77c1e3ccSAndroid Build Coastguard Worker           cm->quant_params.base_qindex > qindex_high[is_720p_or_larger]) {
2695*77c1e3ccSAndroid Build Coastguard Worker         sf->lpf_sf.disable_loop_restoration_luma = 1;
2696*77c1e3ccSAndroid Build Coastguard Worker       }
2697*77c1e3ccSAndroid Build Coastguard Worker     }
2698*77c1e3ccSAndroid Build Coastguard Worker   }
2699*77c1e3ccSAndroid Build Coastguard Worker 
2700*77c1e3ccSAndroid Build Coastguard Worker   if (speed == 1) {
2701*77c1e3ccSAndroid Build Coastguard Worker     // Reuse interinter wedge mask search from first search for non-boosted
2702*77c1e3ccSAndroid Build Coastguard Worker     // non-internal-arf frames, except at very high quantizers.
2703*77c1e3ccSAndroid Build Coastguard Worker     if (cm->quant_params.base_qindex <= 200) {
2704*77c1e3ccSAndroid Build Coastguard Worker       if (!boosted && !is_arf2_bwd_type)
2705*77c1e3ccSAndroid Build Coastguard Worker         sf->inter_sf.reuse_mask_search_results = 1;
2706*77c1e3ccSAndroid Build Coastguard Worker     }
2707*77c1e3ccSAndroid Build Coastguard Worker   }
2708*77c1e3ccSAndroid Build Coastguard Worker 
2709*77c1e3ccSAndroid Build Coastguard Worker   if (speed == 5) {
2710*77c1e3ccSAndroid Build Coastguard Worker     if (!(frame_is_intra_only(&cpi->common) ||
2711*77c1e3ccSAndroid Build Coastguard Worker           cm->features.allow_screen_content_tools)) {
2712*77c1e3ccSAndroid Build Coastguard Worker       const int qindex[2] = { 256, 128 };
2713*77c1e3ccSAndroid Build Coastguard Worker       // Set the sf value as 3 for low resolution and
2714*77c1e3ccSAndroid Build Coastguard Worker       // for higher resolutions with low quantizers.
2715*77c1e3ccSAndroid Build Coastguard Worker       if (cm->quant_params.base_qindex < qindex[is_480p_or_larger])
2716*77c1e3ccSAndroid Build Coastguard Worker         sf->tx_sf.tx_type_search.winner_mode_tx_type_pruning = 3;
2717*77c1e3ccSAndroid Build Coastguard Worker     }
2718*77c1e3ccSAndroid Build Coastguard Worker   }
2719*77c1e3ccSAndroid Build Coastguard Worker 
2720*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 5) {
2721*77c1e3ccSAndroid Build Coastguard Worker     // Disable the sf for low quantizers in case of low resolution screen
2722*77c1e3ccSAndroid Build Coastguard Worker     // contents.
2723*77c1e3ccSAndroid Build Coastguard Worker     if (cm->features.allow_screen_content_tools &&
2724*77c1e3ccSAndroid Build Coastguard Worker         cm->quant_params.base_qindex < 128 && is_480p_or_lesser) {
2725*77c1e3ccSAndroid Build Coastguard Worker       sf->part_sf.prune_sub_8x8_partition_level = 0;
2726*77c1e3ccSAndroid Build Coastguard Worker     }
2727*77c1e3ccSAndroid Build Coastguard Worker   }
2728*77c1e3ccSAndroid Build Coastguard Worker 
2729*77c1e3ccSAndroid Build Coastguard Worker   // Loop restoration size search
2730*77c1e3ccSAndroid Build Coastguard Worker   // At speed 0, always search all available sizes for the maximum possible gain
2731*77c1e3ccSAndroid Build Coastguard Worker   sf->lpf_sf.min_lr_unit_size = RESTORATION_PROC_UNIT_SIZE;
2732*77c1e3ccSAndroid Build Coastguard Worker   sf->lpf_sf.max_lr_unit_size = RESTORATION_UNITSIZE_MAX;
2733*77c1e3ccSAndroid Build Coastguard Worker 
2734*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 1) {
2735*77c1e3ccSAndroid Build Coastguard Worker     // For large frames, small restoration units are almost never useful,
2736*77c1e3ccSAndroid Build Coastguard Worker     // so prune them away
2737*77c1e3ccSAndroid Build Coastguard Worker     if (is_1440p_or_larger) {
2738*77c1e3ccSAndroid Build Coastguard Worker       sf->lpf_sf.min_lr_unit_size = RESTORATION_UNITSIZE_MAX;
2739*77c1e3ccSAndroid Build Coastguard Worker     } else if (is_720p_or_larger) {
2740*77c1e3ccSAndroid Build Coastguard Worker       sf->lpf_sf.min_lr_unit_size = RESTORATION_UNITSIZE_MAX >> 1;
2741*77c1e3ccSAndroid Build Coastguard Worker     }
2742*77c1e3ccSAndroid Build Coastguard Worker   }
2743*77c1e3ccSAndroid Build Coastguard Worker 
2744*77c1e3ccSAndroid Build Coastguard Worker   if (speed >= 3 || (cpi->oxcf.mode == ALLINTRA && speed >= 1)) {
2745*77c1e3ccSAndroid Build Coastguard Worker     // At this speed, a full search is too expensive. Instead, pick a single
2746*77c1e3ccSAndroid Build Coastguard Worker     // size based on size and qindex. Note that, in general, higher quantizers
2747*77c1e3ccSAndroid Build Coastguard Worker     // (== lower quality) and larger frames generally want to use larger
2748*77c1e3ccSAndroid Build Coastguard Worker     // restoration units.
2749*77c1e3ccSAndroid Build Coastguard Worker     int qindex_thresh = 96;
2750*77c1e3ccSAndroid Build Coastguard Worker     if (cm->quant_params.base_qindex <= qindex_thresh && !is_1440p_or_larger) {
2751*77c1e3ccSAndroid Build Coastguard Worker       sf->lpf_sf.min_lr_unit_size = RESTORATION_UNITSIZE_MAX >> 1;
2752*77c1e3ccSAndroid Build Coastguard Worker       sf->lpf_sf.max_lr_unit_size = RESTORATION_UNITSIZE_MAX >> 1;
2753*77c1e3ccSAndroid Build Coastguard Worker     } else {
2754*77c1e3ccSAndroid Build Coastguard Worker       sf->lpf_sf.min_lr_unit_size = RESTORATION_UNITSIZE_MAX;
2755*77c1e3ccSAndroid Build Coastguard Worker       sf->lpf_sf.max_lr_unit_size = RESTORATION_UNITSIZE_MAX;
2756*77c1e3ccSAndroid Build Coastguard Worker     }
2757*77c1e3ccSAndroid Build Coastguard Worker   }
2758*77c1e3ccSAndroid Build Coastguard Worker 
2759*77c1e3ccSAndroid Build Coastguard Worker   set_subpel_search_method(&cpi->mv_search_params,
2760*77c1e3ccSAndroid Build Coastguard Worker                            cpi->oxcf.unit_test_cfg.motion_vector_unit_test,
2761*77c1e3ccSAndroid Build Coastguard Worker                            sf->mv_sf.subpel_search_method);
2762*77c1e3ccSAndroid Build Coastguard Worker }
2763