Coverage Report

Created: 2026-10-28 08:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libvpx/vp9/encoder/vp9_speed_features.c
Line
Count
Source
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5
 *  that can be found in the LICENSE file in the root of the source
6
 *  tree. An additional intellectual property rights grant can be found
7
 *  in the file PATENTS.  All contributing project authors may
8
 *  be found in the AUTHORS file in the root of the source tree.
9
 */
10
11
#include <limits.h>
12
13
#include "vp9/encoder/vp9_encoder.h"
14
#include "vp9/encoder/vp9_speed_features.h"
15
#include "vp9/encoder/vp9_rdopt.h"
16
#include "vpx_dsp/vpx_dsp_common.h"
17
18
// Mesh search patters for various speed settings
19
// Define 2 mesh density levels for FC_GRAPHICS_ANIMATION content type and non
20
// FC_GRAPHICS_ANIMATION content type.
21
static MESH_PATTERN best_quality_mesh_pattern[2][MAX_MESH_STEP] = {
22
  { { 64, 4 }, { 28, 2 }, { 15, 1 }, { 7, 1 } },
23
  { { 64, 8 }, { 28, 4 }, { 15, 1 }, { 7, 1 } },
24
};
25
26
#if !CONFIG_REALTIME_ONLY
27
// Define 3 mesh density levels to control the number of searches.
28
#define MESH_DENSITY_LEVELS 3
29
static MESH_PATTERN
30
    good_quality_mesh_patterns[MESH_DENSITY_LEVELS][MAX_MESH_STEP] = {
31
      { { 64, 8 }, { 28, 4 }, { 15, 1 }, { 7, 1 } },
32
      { { 64, 8 }, { 14, 2 }, { 7, 1 }, { 7, 1 } },
33
      { { 64, 16 }, { 24, 8 }, { 12, 4 }, { 7, 1 } },
34
    };
35
36
// Intra only frames, golden frames (except alt ref overlays) and
37
// alt ref frames tend to be coded at a higher than ambient quality
38
70.7k
static int frame_is_boosted(const VP9_COMP *cpi) {
39
70.7k
  return frame_is_kf_gf_arf(cpi);
40
70.7k
}
41
42
// Sets a partition size down to which the auto partition code will always
43
// search (can go lower), based on the image dimensions. The logic here
44
// is that the extent to which ringing artefacts are offensive, depends
45
// partly on the screen area that over which they propagate. Propagation is
46
// limited by transform block size but the screen area take up by a given block
47
// size will be larger for a small image format stretched to full screen.
48
0
static BLOCK_SIZE set_partition_min_limit(VP9_COMMON *const cm) {
49
0
  unsigned int screen_area = (cm->width * cm->height);
50
51
  // Select block size based on image format size.
52
0
  if (screen_area < 1280 * 720) {
53
    // Formats smaller in area than 720P
54
0
    return BLOCK_4X4;
55
0
  } else if (screen_area < 1920 * 1080) {
56
    // Format >= 720P and < 1080P
57
0
    return BLOCK_8X8;
58
0
  } else {
59
    // Formats 1080P and up
60
0
    return BLOCK_16X16;
61
0
  }
62
0
}
63
64
static void set_good_speed_feature_framesize_dependent(VP9_COMP *cpi,
65
                                                       SPEED_FEATURES *sf,
66
35.3k
                                                       int speed) {
67
35.3k
  VP9_COMMON *const cm = &cpi->common;
68
35.3k
  const int min_frame_size = VPXMIN(cm->width, cm->height);
69
35.3k
  const int is_480p_or_larger = min_frame_size >= 480;
70
35.3k
  const int is_720p_or_larger = min_frame_size >= 720;
71
35.3k
  const int is_1080p_or_larger = min_frame_size >= 1080;
72
35.3k
  const int is_2160p_or_larger = min_frame_size >= 2160;
73
35.3k
  const int boosted = frame_is_boosted(cpi);
74
75
  // speed 0 features
76
35.3k
  sf->partition_search_breakout_thr.dist = (1 << 20);
77
35.3k
  sf->partition_search_breakout_thr.rate = 80;
78
35.3k
  sf->use_square_only_thresh_high = BLOCK_SIZES;
79
35.3k
  sf->use_square_only_thresh_low = BLOCK_4X4;
80
81
35.3k
  if (is_480p_or_larger) {
82
    // Currently, the machine-learning based partition search early termination
83
    // is only used while VPXMIN(cm->width, cm->height) >= 480 and speed = 0.
84
31
    sf->rd_ml_partition.search_early_termination = 1;
85
31
    sf->recode_tolerance_high = 45;
86
35.3k
  } else {
87
35.3k
    sf->use_square_only_thresh_high = BLOCK_32X32;
88
35.3k
  }
89
35.3k
  if (is_720p_or_larger) {
90
0
    sf->alt_ref_search_fp = 1;
91
0
  }
92
93
35.3k
  if (!is_1080p_or_larger) {
94
35.3k
    sf->rd_ml_partition.search_breakout = 1;
95
35.3k
    if (is_720p_or_larger) {
96
0
      sf->rd_ml_partition.search_breakout_thresh[0] = 0.0f;
97
0
      sf->rd_ml_partition.search_breakout_thresh[1] = 0.0f;
98
0
      sf->rd_ml_partition.search_breakout_thresh[2] = 0.0f;
99
35.3k
    } else {
100
35.3k
      sf->rd_ml_partition.search_breakout_thresh[0] = 2.5f;
101
35.3k
      sf->rd_ml_partition.search_breakout_thresh[1] = 1.5f;
102
35.3k
      sf->rd_ml_partition.search_breakout_thresh[2] = 1.5f;
103
35.3k
    }
104
35.3k
  }
105
106
35.3k
  if (!is_720p_or_larger) {
107
35.3k
    if (is_480p_or_larger)
108
31
      sf->prune_single_mode_based_on_mv_diff_mode_rate = boosted ? 0 : 1;
109
35.3k
    else
110
35.3k
      sf->prune_single_mode_based_on_mv_diff_mode_rate = 1;
111
35.3k
  }
112
113
35.3k
  if (speed >= 1) {
114
30.5k
    sf->rd_ml_partition.search_early_termination = 0;
115
30.5k
    sf->rd_ml_partition.search_breakout = 1;
116
30.5k
    if (is_480p_or_larger)
117
8
      sf->use_square_only_thresh_high = BLOCK_64X64;
118
30.5k
    else
119
30.5k
      sf->use_square_only_thresh_high = BLOCK_32X32;
120
30.5k
    sf->use_square_only_thresh_low = BLOCK_16X16;
121
30.5k
    if (is_720p_or_larger) {
122
0
      sf->disable_split_mask =
123
0
          cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
124
0
      sf->partition_search_breakout_thr.dist = (1 << 22);
125
0
      sf->rd_ml_partition.search_breakout_thresh[0] = -5.0f;
126
0
      sf->rd_ml_partition.search_breakout_thresh[1] = -5.0f;
127
0
      sf->rd_ml_partition.search_breakout_thresh[2] = -9.0f;
128
30.5k
    } else {
129
30.5k
      sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
130
30.5k
      sf->partition_search_breakout_thr.dist = (1 << 21);
131
30.5k
      sf->rd_ml_partition.search_breakout_thresh[0] = -1.0f;
132
30.5k
      sf->rd_ml_partition.search_breakout_thresh[1] = -1.0f;
133
30.5k
      sf->rd_ml_partition.search_breakout_thresh[2] = -1.0f;
134
30.5k
    }
135
30.5k
#if CONFIG_VP9_HIGHBITDEPTH
136
30.5k
    if (cpi->Source->flags & YV12_FLAG_HIGHBITDEPTH) {
137
1.85k
      sf->rd_ml_partition.search_breakout_thresh[0] -= 1.0f;
138
1.85k
      sf->rd_ml_partition.search_breakout_thresh[1] -= 1.0f;
139
1.85k
      sf->rd_ml_partition.search_breakout_thresh[2] -= 1.0f;
140
1.85k
    }
141
30.5k
#endif  // CONFIG_VP9_HIGHBITDEPTH
142
30.5k
  }
143
144
35.3k
  if (speed >= 2) {
145
0
    sf->use_square_only_thresh_high = BLOCK_4X4;
146
0
    sf->use_square_only_thresh_low = BLOCK_SIZES;
147
0
    if (is_720p_or_larger) {
148
0
      sf->disable_split_mask =
149
0
          cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
150
0
      sf->adaptive_pred_interp_filter = 0;
151
0
      sf->partition_search_breakout_thr.dist = (1 << 24);
152
0
      sf->partition_search_breakout_thr.rate = 120;
153
0
      sf->rd_ml_partition.search_breakout = 0;
154
0
    } else {
155
0
      sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY;
156
0
      sf->partition_search_breakout_thr.dist = (1 << 22);
157
0
      sf->partition_search_breakout_thr.rate = 100;
158
0
      sf->rd_ml_partition.search_breakout_thresh[0] = 0.0f;
159
0
      sf->rd_ml_partition.search_breakout_thresh[1] = -1.0f;
160
0
      sf->rd_ml_partition.search_breakout_thresh[2] = -4.0f;
161
0
    }
162
0
    sf->rd_auto_partition_min_limit = set_partition_min_limit(cm);
163
164
    // Use a set of speed features for 4k videos.
165
0
    if (is_2160p_or_larger) {
166
0
      sf->use_square_partition_only = 1;
167
0
      sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
168
0
      sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC;
169
0
      sf->alt_ref_search_fp = 1;
170
0
      sf->cb_pred_filter_search = 2;
171
0
      sf->adaptive_interp_filter_search = 1;
172
0
      sf->disable_split_mask = DISABLE_ALL_SPLIT;
173
0
    }
174
0
  }
175
176
35.3k
  if (speed >= 3) {
177
0
    sf->rd_ml_partition.search_breakout = 0;
178
0
    if (is_720p_or_larger) {
179
0
      sf->disable_split_mask = DISABLE_ALL_SPLIT;
180
0
      sf->schedule_mode_search = cm->base_qindex < 220 ? 1 : 0;
181
0
      sf->partition_search_breakout_thr.dist = (1 << 25);
182
0
      sf->partition_search_breakout_thr.rate = 200;
183
0
    } else {
184
0
      sf->max_intra_bsize = BLOCK_32X32;
185
0
      sf->disable_split_mask = DISABLE_ALL_INTER_SPLIT;
186
0
      sf->schedule_mode_search = cm->base_qindex < 175 ? 1 : 0;
187
0
      sf->partition_search_breakout_thr.dist = (1 << 23);
188
0
      sf->partition_search_breakout_thr.rate = 120;
189
0
    }
190
0
  }
191
192
  // If this is a two pass clip that fits the criteria for animated or
193
  // graphics content then reset disable_split_mask for speeds 1-4.
194
  // Also if the image edge is internal to the coded area.
195
35.3k
  if ((speed >= 1) && (cpi->oxcf.pass == 2) &&
196
0
      ((cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ||
197
0
       (vp9_internal_image_edge(cpi)))) {
198
0
    sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
199
0
  }
200
201
35.3k
  if (speed >= 4) {
202
0
    sf->partition_search_breakout_thr.rate = 300;
203
0
    if (is_720p_or_larger) {
204
0
      sf->partition_search_breakout_thr.dist = (1 << 26);
205
0
    } else {
206
0
      sf->partition_search_breakout_thr.dist = (1 << 24);
207
0
    }
208
0
    sf->disable_split_mask = DISABLE_ALL_SPLIT;
209
0
  }
210
211
35.3k
  if (speed >= 5) {
212
0
    sf->partition_search_breakout_thr.rate = 500;
213
0
  }
214
35.3k
}
215
216
static double tx_dom_thresholds[6] = { 99.0, 14.0, 12.0, 8.0, 4.0, 0.0 };
217
static double qopt_thresholds[6] = { 99.0, 12.0, 10.0, 4.0, 2.0, 0.0 };
218
219
static void set_good_speed_feature_framesize_independent(VP9_COMP *cpi,
220
                                                         VP9_COMMON *cm,
221
                                                         SPEED_FEATURES *sf,
222
35.3k
                                                         int speed) {
223
35.3k
  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
224
35.3k
  const int boosted = frame_is_boosted(cpi);
225
35.3k
  int i;
226
227
35.3k
  sf->adaptive_interp_filter_search = 1;
228
35.3k
  sf->adaptive_pred_interp_filter = 1;
229
35.3k
  sf->adaptive_rd_thresh = 1;
230
35.3k
  sf->adaptive_rd_thresh_row_mt = 0;
231
35.3k
  sf->allow_skip_recode = 1;
232
35.3k
  sf->less_rectangular_check = 1;
233
35.3k
  sf->mv.auto_mv_step_size = 1;
234
35.3k
  sf->mv.use_downsampled_sad = 1;
235
35.3k
  sf->prune_ref_frame_for_rect_partitions = 1;
236
35.3k
  sf->temporal_filter_search_method = NSTEP;
237
35.3k
  sf->tx_size_search_breakout = 1;
238
35.3k
  sf->use_square_partition_only = !boosted;
239
35.3k
  sf->early_term_interp_search_plane_rd = 1;
240
35.3k
  sf->cb_pred_filter_search = 1;
241
35.3k
  sf->trellis_opt_tx_rd.method = sf->optimize_coefficients
242
35.3k
                                     ? ENABLE_TRELLIS_OPT_TX_RD_RESIDUAL_MSE
243
35.3k
                                     : DISABLE_TRELLIS_OPT;
244
35.3k
  sf->trellis_opt_tx_rd.thresh = boosted ? 4.0 : 3.0;
245
246
35.3k
  sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
247
35.3k
  sf->comp_inter_joint_search_iter_level = 1;
248
249
  // Reference masking is not supported in dynamic scaling mode.
250
35.3k
  sf->reference_masking = oxcf->resize_mode != RESIZE_DYNAMIC;
251
252
35.3k
  sf->rd_ml_partition.var_pruning = 1;
253
35.3k
  sf->rd_ml_partition.prune_rect_thresh[0] = -1;
254
35.3k
  sf->rd_ml_partition.prune_rect_thresh[1] = 350;
255
35.3k
  sf->rd_ml_partition.prune_rect_thresh[2] = 325;
256
35.3k
  sf->rd_ml_partition.prune_rect_thresh[3] = 250;
257
258
35.3k
  if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) {
259
0
    sf->exhaustive_searches_thresh = (1 << 22);
260
35.3k
  } else {
261
35.3k
    sf->exhaustive_searches_thresh = INT_MAX;
262
35.3k
  }
263
264
176k
  for (i = 0; i < MAX_MESH_STEP; ++i) {
265
141k
    const int mesh_density_level = 0;
266
141k
    sf->mesh_patterns[i].range =
267
141k
        good_quality_mesh_patterns[mesh_density_level][i].range;
268
141k
    sf->mesh_patterns[i].interval =
269
141k
        good_quality_mesh_patterns[mesh_density_level][i].interval;
270
141k
  }
271
272
35.3k
  if (speed >= 1) {
273
30.5k
    sf->rd_ml_partition.var_pruning = !boosted;
274
30.5k
    sf->rd_ml_partition.prune_rect_thresh[1] = 225;
275
30.5k
    sf->rd_ml_partition.prune_rect_thresh[2] = 225;
276
30.5k
    sf->rd_ml_partition.prune_rect_thresh[3] = 225;
277
278
30.5k
    if (oxcf->pass == 2) {
279
0
      TWO_PASS *const twopass = &cpi->twopass;
280
0
      if ((twopass->fr_content_type == FC_GRAPHICS_ANIMATION) ||
281
0
          vp9_internal_image_edge(cpi)) {
282
0
        sf->use_square_partition_only = !boosted;
283
0
      } else {
284
0
        sf->use_square_partition_only = !frame_is_intra_only(cm);
285
0
      }
286
30.5k
    } else {
287
30.5k
      sf->use_square_partition_only = !frame_is_intra_only(cm);
288
30.5k
    }
289
290
30.5k
    sf->allow_txfm_domain_distortion = 1;
291
30.5k
    sf->tx_domain_thresh = tx_dom_thresholds[(speed < 6) ? speed : 5];
292
30.5k
    sf->trellis_opt_tx_rd.method = sf->optimize_coefficients
293
30.5k
                                       ? ENABLE_TRELLIS_OPT_TX_RD_SRC_VAR
294
30.5k
                                       : DISABLE_TRELLIS_OPT;
295
30.5k
    sf->trellis_opt_tx_rd.thresh = qopt_thresholds[(speed < 6) ? speed : 5];
296
30.5k
    sf->less_rectangular_check = 1;
297
30.5k
    sf->use_rd_breakout = 1;
298
30.5k
    sf->adaptive_motion_search = 1;
299
30.5k
    sf->adaptive_rd_thresh = 2;
300
30.5k
    sf->mv.subpel_search_level = 1;
301
30.5k
    if (cpi->oxcf.content != VP9E_CONTENT_FILM) sf->mode_skip_start = 10;
302
30.5k
    sf->allow_acl = 0;
303
304
30.5k
    sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
305
30.5k
    if (cpi->oxcf.content != VP9E_CONTENT_FILM) {
306
30.5k
      sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
307
30.5k
      sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
308
30.5k
    }
309
310
30.5k
    sf->recode_tolerance_low = 15;
311
30.5k
    sf->recode_tolerance_high = 30;
312
313
30.5k
    sf->exhaustive_searches_thresh =
314
30.5k
        (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ? (1 << 23)
315
30.5k
                                                                : INT_MAX;
316
30.5k
    sf->use_accurate_subpel_search = USE_4_TAPS;
317
30.5k
  }
318
319
35.3k
  if (speed >= 2) {
320
0
    sf->rd_ml_partition.var_pruning = 0;
321
0
    if (oxcf->vbr_corpus_complexity)
322
0
      sf->recode_loop = ALLOW_RECODE_FIRST;
323
0
    else
324
0
      sf->recode_loop = ALLOW_RECODE_KFARFGF;
325
326
0
    sf->tx_size_search_method =
327
0
        frame_is_boosted(cpi) ? USE_FULL_RD : USE_LARGESTALL;
328
329
0
    sf->mode_search_skip_flags =
330
0
        (cm->frame_type == KEY_FRAME)
331
0
            ? 0
332
0
            : FLAG_SKIP_INTRA_DIRMISMATCH | FLAG_SKIP_INTRA_BESTINTER |
333
0
                  FLAG_SKIP_COMP_BESTINTRA | FLAG_SKIP_INTRA_LOWVAR;
334
0
    sf->disable_filter_search_var_thresh = 100;
335
0
    sf->comp_inter_joint_search_iter_level = 2;
336
0
    sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
337
0
    sf->recode_tolerance_high = 45;
338
0
    sf->enhanced_full_pixel_motion_search = 0;
339
0
    sf->prune_ref_frame_for_rect_partitions = 0;
340
0
    sf->rd_ml_partition.prune_rect_thresh[1] = -1;
341
0
    sf->rd_ml_partition.prune_rect_thresh[2] = -1;
342
0
    sf->rd_ml_partition.prune_rect_thresh[3] = -1;
343
0
    sf->mv.subpel_search_level = 0;
344
345
0
    if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) {
346
0
      for (i = 0; i < MAX_MESH_STEP; ++i) {
347
0
        int mesh_density_level = 1;
348
0
        sf->mesh_patterns[i].range =
349
0
            good_quality_mesh_patterns[mesh_density_level][i].range;
350
0
        sf->mesh_patterns[i].interval =
351
0
            good_quality_mesh_patterns[mesh_density_level][i].interval;
352
0
      }
353
0
    }
354
355
0
    sf->use_accurate_subpel_search = USE_2_TAPS;
356
0
  }
357
358
35.3k
  if (speed >= 3) {
359
0
    sf->use_square_partition_only = !frame_is_intra_only(cm);
360
0
    sf->tx_size_search_method =
361
0
        frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL;
362
0
    sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED;
363
0
    sf->adaptive_pred_interp_filter = 0;
364
0
    sf->adaptive_mode_search = 1;
365
0
    sf->cb_partition_search = !boosted;
366
0
    sf->cb_pred_filter_search = 2;
367
0
    sf->alt_ref_search_fp = 1;
368
0
    sf->recode_loop = ALLOW_RECODE_KFMAXBW;
369
0
    sf->adaptive_rd_thresh = 3;
370
0
    sf->mode_skip_start = 6;
371
0
    sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
372
0
    sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC;
373
374
0
    if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) {
375
0
      for (i = 0; i < MAX_MESH_STEP; ++i) {
376
0
        int mesh_density_level = 2;
377
0
        sf->mesh_patterns[i].range =
378
0
            good_quality_mesh_patterns[mesh_density_level][i].range;
379
0
        sf->mesh_patterns[i].interval =
380
0
            good_quality_mesh_patterns[mesh_density_level][i].interval;
381
0
      }
382
0
    }
383
0
  }
384
385
35.3k
  if (speed >= 4) {
386
0
    sf->use_square_partition_only = 1;
387
0
    sf->tx_size_search_method = USE_LARGESTALL;
388
0
    sf->mv.search_method = BIGDIA;
389
0
    sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
390
0
    sf->adaptive_rd_thresh = 4;
391
0
    if (cm->frame_type != KEY_FRAME)
392
0
      sf->mode_search_skip_flags |= FLAG_EARLY_TERMINATE;
393
0
    sf->disable_filter_search_var_thresh = 200;
394
0
    sf->use_lp32x32fdct = 1;
395
0
    sf->use_fast_coef_updates = ONE_LOOP_REDUCED;
396
0
    sf->use_fast_coef_costing = 1;
397
0
    sf->motion_field_mode_search = !boosted;
398
0
  }
399
400
35.3k
  if (speed >= 5) {
401
0
    sf->optimize_coefficients = 0;
402
0
    sf->mv.search_method = HEX;
403
0
    sf->disable_filter_search_var_thresh = 500;
404
0
    for (i = 0; i < TX_SIZES; ++i) {
405
0
      sf->intra_y_mode_mask[i] = INTRA_DC;
406
0
      sf->intra_uv_mode_mask[i] = INTRA_DC;
407
0
    }
408
0
    sf->mv.reduce_first_step_size = 1;
409
0
    sf->simple_model_rd_from_var = 1;
410
0
  }
411
35.3k
}
412
#endif  // !CONFIG_REALTIME_ONLY
413
414
static void set_rt_speed_feature_framesize_dependent(VP9_COMP *cpi,
415
                                                     SPEED_FEATURES *sf,
416
43.4k
                                                     int speed) {
417
43.4k
  VP9_COMMON *const cm = &cpi->common;
418
419
43.4k
  if (speed >= 1) {
420
43.4k
    if (VPXMIN(cm->width, cm->height) >= 720) {
421
0
      sf->disable_split_mask =
422
0
          cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
423
43.4k
    } else {
424
43.4k
      sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
425
43.4k
    }
426
43.4k
  }
427
428
43.4k
  if (speed >= 2) {
429
0
    if (VPXMIN(cm->width, cm->height) >= 720) {
430
0
      sf->disable_split_mask =
431
0
          cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
432
0
    } else {
433
0
      sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY;
434
0
    }
435
0
  }
436
437
43.4k
  if (speed >= 5) {
438
0
    sf->partition_search_breakout_thr.rate = 200;
439
0
    if (VPXMIN(cm->width, cm->height) >= 720) {
440
0
      sf->partition_search_breakout_thr.dist = (1 << 25);
441
0
    } else {
442
0
      sf->partition_search_breakout_thr.dist = (1 << 23);
443
0
    }
444
0
  }
445
446
43.4k
  if (speed >= 7) {
447
0
    sf->encode_breakout_thresh =
448
0
        (VPXMIN(cm->width, cm->height) >= 720) ? 800 : 300;
449
0
  }
450
43.4k
}
451
452
static void set_rt_speed_feature_framesize_independent(
453
43.4k
    VP9_COMP *cpi, SPEED_FEATURES *sf, int speed, vp9e_tune_content content) {
454
43.4k
  VP9_COMMON *const cm = &cpi->common;
455
43.4k
  SVC *const svc = &cpi->svc;
456
43.4k
  const int is_keyframe = cm->frame_type == KEY_FRAME;
457
43.4k
  const int frames_since_key = is_keyframe ? 0 : cpi->rc.frames_since_key;
458
43.4k
  sf->static_segmentation = 0;
459
43.4k
  sf->adaptive_rd_thresh = 1;
460
43.4k
  sf->adaptive_rd_thresh_row_mt = 0;
461
43.4k
  sf->use_fast_coef_costing = 1;
462
43.4k
  sf->exhaustive_searches_thresh = INT_MAX;
463
43.4k
  sf->allow_acl = 0;
464
43.4k
  sf->copy_partition_flag = 0;
465
43.4k
  sf->use_source_sad = 0;
466
43.4k
  sf->use_simple_block_yrd = 0;
467
43.4k
  sf->adapt_partition_source_sad = 0;
468
43.4k
  sf->use_altref_onepass = 0;
469
43.4k
  sf->use_compound_nonrd_pickmode = 0;
470
43.4k
  sf->nonrd_keyframe = 0;
471
43.4k
  sf->svc_use_lowres_part = 0;
472
43.4k
  sf->overshoot_detection_cbr_rt = NO_DETECTION;
473
43.4k
  sf->disable_16x16part_nonkey = 0;
474
43.4k
  sf->disable_golden_ref = 0;
475
43.4k
  sf->enable_tpl_model = 0;
476
43.4k
  sf->enhanced_full_pixel_motion_search = 0;
477
43.4k
  sf->use_accurate_subpel_search = USE_2_TAPS;
478
43.4k
  sf->nonrd_use_ml_partition = 0;
479
43.4k
  sf->variance_part_thresh_mult = 1;
480
43.4k
  sf->cb_pred_filter_search = 0;
481
43.4k
  sf->force_smooth_interpol = 0;
482
43.4k
  sf->rt_intra_dc_only_low_content = 0;
483
43.4k
  sf->mv.enable_adaptive_subpel_force_stop = 0;
484
485
43.4k
  if (speed >= 1) {
486
43.4k
    sf->allow_txfm_domain_distortion = 1;
487
43.4k
    sf->tx_domain_thresh = 0.0;
488
43.4k
    sf->trellis_opt_tx_rd.method = DISABLE_TRELLIS_OPT;
489
43.4k
    sf->trellis_opt_tx_rd.thresh = 0.0;
490
43.4k
    sf->use_square_partition_only = !frame_is_intra_only(cm);
491
43.4k
    sf->less_rectangular_check = 1;
492
43.4k
    sf->tx_size_search_method =
493
43.4k
        frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL;
494
495
43.4k
    sf->use_rd_breakout = 1;
496
497
43.4k
    sf->adaptive_motion_search = 1;
498
43.4k
    sf->adaptive_pred_interp_filter = 1;
499
43.4k
    sf->mv.auto_mv_step_size = 1;
500
43.4k
    sf->adaptive_rd_thresh = 2;
501
43.4k
    sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
502
43.4k
    sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
503
43.4k
    sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
504
43.4k
  }
505
506
43.4k
  if (speed >= 2) {
507
0
    sf->mode_search_skip_flags =
508
0
        (cm->frame_type == KEY_FRAME)
509
0
            ? 0
510
0
            : FLAG_SKIP_INTRA_DIRMISMATCH | FLAG_SKIP_INTRA_BESTINTER |
511
0
                  FLAG_SKIP_COMP_BESTINTRA | FLAG_SKIP_INTRA_LOWVAR;
512
0
    sf->adaptive_pred_interp_filter = 2;
513
514
    // Reference masking only enabled for 1 spatial layer, and if none of the
515
    // references have been scaled. The latter condition needs to be checked
516
    // for external or internal dynamic resize.
517
0
    sf->reference_masking = (svc->number_spatial_layers == 1);
518
0
    if (sf->reference_masking == 1 &&
519
0
        (cpi->external_resize == 1 ||
520
0
         cpi->oxcf.resize_mode == RESIZE_DYNAMIC)) {
521
0
      MV_REFERENCE_FRAME ref_frame;
522
0
      for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
523
0
        const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame);
524
0
        if (yv12 != NULL &&
525
0
            (cpi->ref_frame_flags & ref_frame_to_flag(ref_frame))) {
526
0
          const struct scale_factors *const scale_fac =
527
0
              &cm->frame_refs[ref_frame - 1].sf;
528
0
          if (vp9_is_scaled(scale_fac)) sf->reference_masking = 0;
529
0
        }
530
0
      }
531
0
    }
532
533
0
    sf->disable_filter_search_var_thresh = 50;
534
0
    sf->comp_inter_joint_search_iter_level = 2;
535
0
    sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
536
0
    sf->lf_motion_threshold = LOW_MOTION_THRESHOLD;
537
0
    sf->adjust_partitioning_from_last_frame = 1;
538
0
    sf->last_partitioning_redo_frequency = 3;
539
0
    sf->use_lp32x32fdct = 1;
540
0
    sf->mode_skip_start = 11;
541
0
    sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
542
0
  }
543
544
43.4k
  if (speed >= 3) {
545
0
    sf->use_square_partition_only = 1;
546
0
    sf->disable_filter_search_var_thresh = 100;
547
0
    sf->use_uv_intra_rd_estimate = 1;
548
0
    sf->skip_encode_sb = 1;
549
0
    sf->mv.subpel_search_level = 0;
550
0
    sf->adaptive_rd_thresh = 4;
551
0
    sf->mode_skip_start = 6;
552
0
    sf->allow_skip_recode = 0;
553
0
    sf->optimize_coefficients = 0;
554
0
    sf->disable_split_mask = DISABLE_ALL_SPLIT;
555
0
    sf->lpf_pick = LPF_PICK_FROM_Q;
556
0
  }
557
558
43.4k
  if (speed >= 4) {
559
0
    int i;
560
0
    if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0)
561
0
      sf->use_altref_onepass = 1;
562
0
    sf->mv.subpel_force_stop = QUARTER_PEL;
563
0
    for (i = 0; i < TX_SIZES; i++) {
564
0
      sf->intra_y_mode_mask[i] = INTRA_DC_H_V;
565
0
      sf->intra_uv_mode_mask[i] = INTRA_DC;
566
0
    }
567
0
    sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
568
0
    sf->frame_parameter_update = 0;
569
0
    sf->mv.search_method = FAST_HEX;
570
0
    sf->allow_skip_recode = 0;
571
0
    sf->max_intra_bsize = BLOCK_32X32;
572
0
    sf->use_fast_coef_costing = 0;
573
0
    sf->use_quant_fp = !is_keyframe;
574
0
    sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEW_ZERO;
575
0
    sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST_NEW_ZERO;
576
0
    sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST_NEW_ZERO;
577
0
    sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST_NEW_ZERO;
578
0
    sf->adaptive_rd_thresh = 2;
579
0
    sf->use_fast_coef_updates = is_keyframe ? TWO_LOOP : ONE_LOOP_REDUCED;
580
0
    sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH;
581
0
    sf->tx_size_search_method = is_keyframe ? USE_LARGESTALL : USE_TX_8X8;
582
0
    sf->partition_search_type = VAR_BASED_PARTITION;
583
0
  }
584
585
43.4k
  if (speed >= 5) {
586
0
    sf->use_altref_onepass = 0;
587
0
    sf->use_quant_fp = !is_keyframe;
588
0
    sf->auto_min_max_partition_size =
589
0
        is_keyframe ? RELAXED_NEIGHBORING_MIN_MAX : STRICT_NEIGHBORING_MIN_MAX;
590
0
    sf->default_max_partition_size = BLOCK_32X32;
591
0
    sf->default_min_partition_size = BLOCK_8X8;
592
0
    sf->force_frame_boost =
593
0
        is_keyframe ||
594
0
        (frames_since_key % (sf->last_partitioning_redo_frequency << 1) == 1);
595
0
    sf->max_delta_qindex = is_keyframe ? 20 : 15;
596
0
    sf->partition_search_type = REFERENCE_PARTITION;
597
0
    if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0 &&
598
0
        cpi->rc.is_src_frame_alt_ref) {
599
0
      sf->partition_search_type = VAR_BASED_PARTITION;
600
0
    }
601
0
    sf->use_nonrd_pick_mode = 1;
602
0
    sf->allow_skip_recode = 0;
603
0
    sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEW_ZERO;
604
0
    sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST_NEW_ZERO;
605
0
    sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST_NEW_ZERO;
606
0
    sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST_NEW_ZERO;
607
0
    sf->adaptive_rd_thresh = 2;
608
    // This feature is only enabled when partition search is disabled.
609
0
    sf->reuse_inter_pred_sby = 1;
610
0
    sf->coeff_prob_appx_step = 4;
611
0
    sf->use_fast_coef_updates = is_keyframe ? TWO_LOOP : ONE_LOOP_REDUCED;
612
0
    sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH;
613
0
    sf->tx_size_search_method = is_keyframe ? USE_LARGESTALL : USE_TX_8X8;
614
0
    sf->simple_model_rd_from_var = 1;
615
0
    if (cpi->oxcf.rc_mode == VPX_VBR) sf->mv.search_method = NSTEP;
616
617
0
    if (!is_keyframe) {
618
0
      int i;
619
0
      if (content == VP9E_CONTENT_SCREEN) {
620
0
        for (i = 0; i < BLOCK_SIZES; ++i)
621
0
          if (i >= BLOCK_32X32)
622
0
            sf->intra_y_mode_bsize_mask[i] = INTRA_DC_H_V;
623
0
          else
624
0
            sf->intra_y_mode_bsize_mask[i] = INTRA_DC_TM_H_V;
625
0
      } else {
626
0
        for (i = 0; i < BLOCK_SIZES; ++i)
627
0
          if (i > BLOCK_16X16)
628
0
            sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
629
0
          else
630
            // Use H and V intra mode for block sizes <= 16X16.
631
0
            sf->intra_y_mode_bsize_mask[i] = INTRA_DC_H_V;
632
0
      }
633
0
    }
634
0
    if (content == VP9E_CONTENT_SCREEN) {
635
0
      sf->short_circuit_flat_blocks = 1;
636
0
    }
637
0
    if (cpi->oxcf.rc_mode == VPX_CBR &&
638
0
        cpi->oxcf.content != VP9E_CONTENT_SCREEN) {
639
0
      sf->limit_newmv_early_exit = 1;
640
0
      if (!cpi->use_svc) sf->bias_golden = 1;
641
0
    }
642
    // Keep nonrd_keyframe = 1 for non-base spatial layers to prevent
643
    // increase in encoding time.
644
0
    if (cpi->use_svc && svc->spatial_layer_id > 0) sf->nonrd_keyframe = 1;
645
0
    if (cm->frame_type != KEY_FRAME && cpi->resize_state == ORIG &&
646
0
        cpi->oxcf.rc_mode == VPX_CBR && !cpi->rc.disable_overshoot_maxq_cbr) {
647
0
      if (cm->width * cm->height <= 352 * 288 && !cpi->use_svc &&
648
0
          cpi->oxcf.content != VP9E_CONTENT_SCREEN)
649
0
        sf->overshoot_detection_cbr_rt = RE_ENCODE_MAXQ;
650
0
      else
651
0
        sf->overshoot_detection_cbr_rt = FAST_DETECTION_MAXQ;
652
0
    }
653
0
    if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0 &&
654
0
        cm->width <= 1280 && cm->height <= 720) {
655
0
      sf->use_altref_onepass = 1;
656
0
      sf->use_compound_nonrd_pickmode = 1;
657
0
    }
658
0
    if (cm->width * cm->height > 1280 * 720) sf->cb_pred_filter_search = 2;
659
0
    if (!cpi->external_resize) sf->use_source_sad = 1;
660
0
  }
661
662
43.4k
  if (speed >= 6) {
663
0
    if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0) {
664
0
      sf->use_altref_onepass = 1;
665
0
      sf->use_compound_nonrd_pickmode = 1;
666
0
    }
667
0
    sf->partition_search_type = VAR_BASED_PARTITION;
668
0
    sf->mv.search_method = NSTEP;
669
0
    sf->mv.reduce_first_step_size = 1;
670
0
    sf->skip_encode_sb = 0;
671
672
0
    if (sf->use_source_sad) {
673
0
      sf->adapt_partition_source_sad = 1;
674
0
      sf->adapt_partition_thresh =
675
0
          (cm->width * cm->height <= 640 * 360) ? 40000 : 60000;
676
0
      if (cpi->content_state_sb_fd == NULL &&
677
0
          (!cpi->use_svc ||
678
0
           svc->spatial_layer_id == svc->number_spatial_layers - 1)) {
679
0
        int init_mi_rows, init_mi_cols, init_mi_stride;
680
0
        vp9_set_mi_size(&init_mi_rows, &init_mi_cols, &init_mi_stride,
681
0
                        cpi->initial_width, cpi->initial_height);
682
0
        CHECK_MEM_ERROR(&cm->error, cpi->content_state_sb_fd,
683
0
                        (uint8_t *)vpx_calloc(
684
0
                            (init_mi_stride >> 3) * ((init_mi_rows >> 3) + 1),
685
0
                            sizeof(uint8_t)));
686
0
      }
687
0
    }
688
0
    if (cpi->oxcf.rc_mode == VPX_CBR && content != VP9E_CONTENT_SCREEN) {
689
      // Enable short circuit for low temporal variance.
690
0
      sf->short_circuit_low_temp_var = 1;
691
0
    }
692
0
    if (svc->temporal_layer_id > 0) {
693
0
      sf->adaptive_rd_thresh = 4;
694
0
      sf->limit_newmv_early_exit = 0;
695
0
      sf->base_mv_aggressive = 1;
696
0
    }
697
0
    if (cm->frame_type != KEY_FRAME && cpi->resize_state == ORIG &&
698
0
        cpi->oxcf.rc_mode == VPX_CBR && !cpi->rc.disable_overshoot_maxq_cbr)
699
0
      sf->overshoot_detection_cbr_rt = FAST_DETECTION_MAXQ;
700
0
  }
701
702
43.4k
  if (speed >= 7) {
703
0
    sf->adapt_partition_source_sad = 0;
704
0
    sf->adaptive_rd_thresh = 3;
705
0
    sf->mv.search_method = FAST_DIAMOND;
706
0
    sf->mv.fullpel_search_step_param = 10;
707
    // For SVC: use better mv search on base temporal layer, and only
708
    // on base spatial layer if highest resolution is above 640x360.
709
0
    if (svc->number_temporal_layers > 2 && svc->temporal_layer_id == 0 &&
710
0
        (svc->spatial_layer_id == 0 ||
711
0
         cpi->oxcf.width * cpi->oxcf.height <= 640 * 360)) {
712
0
      sf->mv.search_method = NSTEP;
713
0
      sf->mv.fullpel_search_step_param = 6;
714
0
    }
715
0
    if (svc->temporal_layer_id > 0 || svc->spatial_layer_id > 1) {
716
0
      sf->use_simple_block_yrd = 1;
717
0
      if (svc->non_reference_frame)
718
0
        sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED_EVENMORE;
719
0
    }
720
0
    if (cpi->use_svc && cpi->row_mt && cpi->oxcf.max_threads > 1)
721
0
      sf->adaptive_rd_thresh_row_mt = 1;
722
    // Enable partition copy. For SVC only enabled for top spatial resolution
723
    // layer.
724
0
    cpi->max_copied_frame = 0;
725
0
    if (!cpi->last_frame_dropped && cpi->resize_state == ORIG &&
726
0
        !cpi->external_resize &&
727
0
        (!cpi->use_svc ||
728
0
         (svc->spatial_layer_id == svc->number_spatial_layers - 1 &&
729
0
          !svc->last_layer_dropped[svc->number_spatial_layers - 1]))) {
730
0
      sf->copy_partition_flag = 1;
731
0
      cpi->max_copied_frame = 2;
732
      // The top temporal enhancement layer (for number of temporal layers > 1)
733
      // are non-reference frames, so use large/max value for max_copied_frame.
734
0
      if (svc->number_temporal_layers > 1 &&
735
0
          svc->temporal_layer_id == svc->number_temporal_layers - 1)
736
0
        cpi->max_copied_frame = 255;
737
0
    }
738
    // For SVC: enable use of lower resolution partition for higher resolution,
739
    // only for 3 spatial layers and when config/top resolution is above VGA.
740
    // Enable only for non-base temporal layer frames.
741
0
    if (cpi->use_svc && svc->use_partition_reuse &&
742
0
        svc->number_spatial_layers == 3 && svc->temporal_layer_id > 0 &&
743
0
        cpi->oxcf.width * cpi->oxcf.height > 640 * 480)
744
0
      sf->svc_use_lowres_part = 1;
745
    // For SVC when golden is used as second temporal reference: to avoid
746
    // encode time increase only use this feature on base temporal layer.
747
    // (i.e remove golden flag from frame_flags for temporal_layer_id > 0).
748
0
    if (cpi->use_svc && svc->use_gf_temporal_ref_current_layer &&
749
0
        svc->temporal_layer_id > 0)
750
0
      cpi->ref_frame_flags &= (~VP9_GOLD_FLAG);
751
0
    if (cm->width * cm->height > 640 * 480) sf->cb_pred_filter_search = 2;
752
0
  }
753
754
43.4k
  if (speed >= 8) {
755
0
    sf->adaptive_rd_thresh = 4;
756
0
    sf->skip_encode_sb = 1;
757
0
    if (cpi->svc.number_spatial_layers > 1 && !cpi->svc.simulcast_mode)
758
0
      sf->nonrd_keyframe = 0;
759
0
    else
760
0
      sf->nonrd_keyframe = 1;
761
0
    if (!cpi->use_svc) cpi->max_copied_frame = 4;
762
0
    if (cpi->row_mt && cpi->oxcf.max_threads > 1)
763
0
      sf->adaptive_rd_thresh_row_mt = 1;
764
    // Enable ML based partition for low res.
765
0
    if (!frame_is_intra_only(cm) && !cpi->use_svc &&
766
0
        cm->width * cm->height <= 352 * 288) {
767
0
      sf->nonrd_use_ml_partition = 1;
768
0
    }
769
0
#if CONFIG_VP9_HIGHBITDEPTH
770
0
    if (cpi->Source->flags & YV12_FLAG_HIGHBITDEPTH)
771
0
      sf->nonrd_use_ml_partition = 0;
772
0
#endif
773
0
    if (content == VP9E_CONTENT_SCREEN) sf->mv.subpel_force_stop = HALF_PEL;
774
0
    sf->rt_intra_dc_only_low_content = 1;
775
0
    if (!cpi->use_svc && cpi->oxcf.rc_mode == VPX_CBR &&
776
0
        content != VP9E_CONTENT_SCREEN) {
777
      // More aggressive short circuit for speed 8.
778
0
      sf->short_circuit_low_temp_var = 3;
779
      // Use level 2 for noisey cases as there is a regression in some
780
      // noisy clips with level 3.
781
0
      if (cpi->noise_estimate.enabled && cm->width >= 1280 &&
782
0
          cm->height >= 720) {
783
0
        NOISE_LEVEL noise_level =
784
0
            vp9_noise_estimate_extract_level(&cpi->noise_estimate);
785
0
        if (noise_level >= kMedium) sf->short_circuit_low_temp_var = 2;
786
0
      }
787
      // Since the short_circuit_low_temp_var is used, reduce the
788
      // adaptive_rd_thresh level.
789
0
      if (cm->width * cm->height > 352 * 288)
790
0
        sf->adaptive_rd_thresh = 1;
791
0
      else
792
0
        sf->adaptive_rd_thresh = 2;
793
0
    }
794
0
    sf->limit_newmv_early_exit = 0;
795
0
    sf->use_simple_block_yrd = 1;
796
0
    if (cm->width * cm->height > 352 * 288) sf->cb_pred_filter_search = 2;
797
0
  }
798
799
43.4k
  if (speed >= 9) {
800
    // Only keep INTRA_DC mode for speed 9.
801
0
    if (!is_keyframe) {
802
0
      int i = 0;
803
0
      for (i = 0; i < BLOCK_SIZES; ++i)
804
0
        sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
805
0
    }
806
0
    sf->cb_pred_filter_search = 2;
807
0
    sf->mv.enable_adaptive_subpel_force_stop = 1;
808
0
    sf->mv.adapt_subpel_force_stop.mv_thresh = 1;
809
0
    sf->mv.adapt_subpel_force_stop.force_stop_below = QUARTER_PEL;
810
0
    sf->mv.adapt_subpel_force_stop.force_stop_above = HALF_PEL;
811
    // Disable partition blocks below 16x16, except for low-resolutions.
812
0
    if (cm->frame_type != KEY_FRAME && cm->width >= 320 && cm->height >= 240)
813
0
      sf->disable_16x16part_nonkey = 1;
814
    // Allow for disabling GOLDEN reference, for CBR mode.
815
0
    if (cpi->oxcf.rc_mode == VPX_CBR) sf->disable_golden_ref = 1;
816
0
    if (cpi->rc.avg_frame_low_motion < 70) sf->default_interp_filter = BILINEAR;
817
0
    if (cm->width * cm->height >= 640 * 360) sf->variance_part_thresh_mult = 2;
818
0
  }
819
820
  // Disable split to 8x8 for low-resolution at very high Q.
821
  // For variance partition (speed >= 6). Ignore the first few frames
822
  // as avg_frame_qindex starts at max_q (worst_quality).
823
43.4k
  if (cm->frame_type != KEY_FRAME && cm->width * cm->height <= 320 * 240 &&
824
32.3k
      sf->partition_search_type == VAR_BASED_PARTITION &&
825
0
      cpi->rc.avg_frame_qindex[INTER_FRAME] > 208 &&
826
0
      cpi->common.current_video_frame > 8)
827
0
    sf->disable_16x16part_nonkey = 1;
828
829
43.4k
  if (sf->nonrd_use_ml_partition)
830
0
    sf->partition_search_type = ML_BASED_PARTITION;
831
832
43.4k
  if (sf->use_altref_onepass) {
833
0
    if (cpi->rc.is_src_frame_alt_ref && cm->frame_type != KEY_FRAME) {
834
0
      sf->partition_search_type = FIXED_PARTITION;
835
0
      sf->always_this_block_size = BLOCK_64X64;
836
0
    }
837
0
    if (cpi->count_arf_frame_usage == NULL) {
838
0
      CHECK_MEM_ERROR(
839
0
          &cm->error, cpi->count_arf_frame_usage,
840
0
          (uint8_t *)vpx_calloc((cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1),
841
0
                                sizeof(*cpi->count_arf_frame_usage)));
842
0
    }
843
0
    if (cpi->count_lastgolden_frame_usage == NULL)
844
0
      CHECK_MEM_ERROR(
845
0
          &cm->error, cpi->count_lastgolden_frame_usage,
846
0
          (uint8_t *)vpx_calloc((cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1),
847
0
                                sizeof(*cpi->count_lastgolden_frame_usage)));
848
0
  }
849
43.4k
  if (svc->previous_frame_is_intra_only) {
850
0
    sf->partition_search_type = FIXED_PARTITION;
851
0
    sf->always_this_block_size = BLOCK_64X64;
852
0
  }
853
  // Special case for screen content: increase motion search on base spatial
854
  // layer when high motion is detected or previous SL0 frame was dropped.
855
43.4k
  if (cpi->oxcf.content == VP9E_CONTENT_SCREEN && cpi->oxcf.speed >= 5 &&
856
0
      (svc->high_num_blocks_with_motion || svc->last_layer_dropped[0])) {
857
0
    sf->mv.search_method = NSTEP;
858
    // TODO(marpan/jianj): Tune this setting for screensharing. For now use
859
    // small step_param for all spatial layers.
860
0
    sf->mv.fullpel_search_step_param = 2;
861
0
  }
862
  // TODO(marpan): There is regression for aq-mode=3 speed <= 4, force it
863
  // off for now.
864
43.4k
  if (speed <= 3 && cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
865
0
    cpi->oxcf.aq_mode = 0;
866
  // For all speeds for rt mode: if the deadline mode changed (was good/best
867
  // quality on previous frame and now is realtime) set nonrd_keyframe to 1 to
868
  // avoid entering rd pickmode. This causes issues, such as: b/310663186.
869
43.4k
  if (cpi->oxcf.mode != cpi->deadline_mode_previous_frame)
870
0
    sf->nonrd_keyframe = 1;
871
872
  // TODO(marpan): Force this feature off always, for the issue: 366146260
873
  // Remove this disabling when underlying issue is resolved.
874
43.4k
  sf->svc_use_lowres_part = 0;
875
43.4k
}
876
877
78.8k
void vp9_set_speed_features_framesize_dependent(VP9_COMP *cpi, int speed) {
878
78.8k
  SPEED_FEATURES *const sf = &cpi->sf;
879
78.8k
  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
880
78.8k
  RD_OPT *const rd = &cpi->rd;
881
78.8k
  int i;
882
883
  // best quality defaults
884
  // Some speed-up features even for best quality as minimal impact on quality.
885
78.8k
  sf->partition_search_breakout_thr.dist = (1 << 19);
886
78.8k
  sf->partition_search_breakout_thr.rate = 80;
887
78.8k
  sf->rd_ml_partition.search_early_termination = 0;
888
78.8k
  sf->rd_ml_partition.search_breakout = 0;
889
890
78.8k
  if (oxcf->mode == REALTIME)
891
43.4k
    set_rt_speed_feature_framesize_dependent(cpi, sf, speed);
892
35.3k
#if !CONFIG_REALTIME_ONLY
893
35.3k
  else if (oxcf->mode == GOOD)
894
35.3k
    set_good_speed_feature_framesize_dependent(cpi, sf, speed);
895
78.8k
#endif
896
897
78.8k
  if (sf->disable_split_mask == DISABLE_ALL_SPLIT) {
898
0
    sf->adaptive_pred_interp_filter = 0;
899
0
  }
900
901
78.8k
  if (cpi->encode_breakout && oxcf->mode == REALTIME &&
902
0
      sf->encode_breakout_thresh > cpi->encode_breakout) {
903
0
    cpi->encode_breakout = sf->encode_breakout_thresh;
904
0
  }
905
906
  // Check for masked out split cases.
907
551k
  for (i = 0; i < MAX_REFS; ++i) {
908
472k
    if (sf->disable_split_mask & (1 << i)) {
909
148k
      rd->thresh_mult_sub8x8[i] = INT_MAX;
910
148k
    }
911
472k
  }
912
913
  // With row based multi-threading, the following speed features
914
  // have to be disabled to guarantee that bitstreams encoded with single thread
915
  // and multiple threads match.
916
  // It can be used in realtime when adaptive_rd_thresh_row_mt is enabled since
917
  // adaptive_rd_thresh is defined per-row for non-rd pickmode.
918
78.8k
  if (!sf->adaptive_rd_thresh_row_mt && cpi->row_mt_bit_exact &&
919
0
      oxcf->max_threads > 1)
920
0
    sf->adaptive_rd_thresh = 0;
921
78.8k
}
922
923
78.8k
void vp9_set_speed_features_framesize_independent(VP9_COMP *cpi, int speed) {
924
78.8k
  SPEED_FEATURES *const sf = &cpi->sf;
925
78.8k
#if !CONFIG_REALTIME_ONLY
926
78.8k
  VP9_COMMON *const cm = &cpi->common;
927
78.8k
#endif
928
78.8k
  MACROBLOCK *const x = &cpi->td.mb;
929
78.8k
  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
930
78.8k
  int i;
931
932
  // best quality defaults
933
78.8k
  sf->frame_parameter_update = 1;
934
78.8k
  sf->mv.search_method = NSTEP;
935
78.8k
  sf->recode_loop = ALLOW_RECODE_FIRST;
936
78.8k
  sf->mv.subpel_search_method = SUBPEL_TREE;
937
78.8k
  sf->mv.subpel_search_level = 2;
938
78.8k
  sf->mv.subpel_force_stop = EIGHTH_PEL;
939
78.8k
  sf->optimize_coefficients = !is_lossless_requested(&cpi->oxcf);
940
78.8k
  sf->mv.reduce_first_step_size = 0;
941
78.8k
  sf->coeff_prob_appx_step = 1;
942
78.8k
  sf->mv.auto_mv_step_size = 0;
943
78.8k
  sf->mv.fullpel_search_step_param = 6;
944
78.8k
  sf->mv.use_downsampled_sad = 0;
945
78.8k
  sf->comp_inter_joint_search_iter_level = 0;
946
78.8k
  sf->tx_size_search_method = USE_FULL_RD;
947
78.8k
  sf->use_lp32x32fdct = 0;
948
78.8k
  sf->adaptive_motion_search = 0;
949
78.8k
  sf->enhanced_full_pixel_motion_search = 1;
950
78.8k
  sf->adaptive_pred_interp_filter = 0;
951
78.8k
  sf->adaptive_mode_search = 0;
952
78.8k
  sf->prune_single_mode_based_on_mv_diff_mode_rate = 0;
953
78.8k
  sf->cb_pred_filter_search = 0;
954
78.8k
  sf->early_term_interp_search_plane_rd = 0;
955
78.8k
  sf->cb_partition_search = 0;
956
78.8k
  sf->motion_field_mode_search = 0;
957
78.8k
  sf->alt_ref_search_fp = 0;
958
78.8k
  sf->use_quant_fp = 0;
959
78.8k
  sf->reference_masking = 0;
960
78.8k
  sf->partition_search_type = SEARCH_PARTITION;
961
78.8k
  sf->less_rectangular_check = 0;
962
78.8k
  sf->use_square_partition_only = 0;
963
78.8k
  sf->use_square_only_thresh_high = BLOCK_SIZES;
964
78.8k
  sf->use_square_only_thresh_low = BLOCK_4X4;
965
78.8k
  sf->auto_min_max_partition_size = NOT_IN_USE;
966
78.8k
  sf->rd_auto_partition_min_limit = BLOCK_4X4;
967
78.8k
  sf->default_max_partition_size = BLOCK_64X64;
968
78.8k
  sf->default_min_partition_size = BLOCK_4X4;
969
78.8k
  sf->adjust_partitioning_from_last_frame = 0;
970
78.8k
  sf->last_partitioning_redo_frequency = 4;
971
78.8k
  sf->disable_split_mask = 0;
972
78.8k
  sf->mode_search_skip_flags = 0;
973
78.8k
  sf->force_frame_boost = 0;
974
78.8k
  sf->max_delta_qindex = 0;
975
78.8k
  sf->disable_filter_search_var_thresh = 0;
976
78.8k
  sf->adaptive_interp_filter_search = 0;
977
78.8k
  sf->allow_txfm_domain_distortion = 0;
978
78.8k
  sf->tx_domain_thresh = 99.0;
979
78.8k
  sf->trellis_opt_tx_rd.method =
980
78.8k
      sf->optimize_coefficients ? ENABLE_TRELLIS_OPT : DISABLE_TRELLIS_OPT;
981
78.8k
  sf->trellis_opt_tx_rd.thresh = 99.0;
982
78.8k
  sf->allow_acl = 1;
983
78.8k
  sf->enable_tpl_model = oxcf->enable_tpl_model;
984
78.8k
  sf->prune_ref_frame_for_rect_partitions = 0;
985
78.8k
  sf->temporal_filter_search_method = MESH;
986
78.8k
  sf->allow_skip_txfm_ac_dc = 0;
987
988
394k
  for (i = 0; i < TX_SIZES; i++) {
989
315k
    sf->intra_y_mode_mask[i] = INTRA_ALL;
990
315k
    sf->intra_uv_mode_mask[i] = INTRA_ALL;
991
315k
  }
992
78.8k
  sf->use_rd_breakout = 0;
993
78.8k
  sf->skip_encode_sb = 0;
994
78.8k
  sf->use_uv_intra_rd_estimate = 0;
995
78.8k
  sf->allow_skip_recode = 0;
996
78.8k
  sf->lpf_pick = LPF_PICK_FROM_FULL_IMAGE;
997
78.8k
  sf->use_fast_coef_updates = TWO_LOOP;
998
78.8k
  sf->use_fast_coef_costing = 0;
999
78.8k
  sf->mode_skip_start = MAX_MODES;  // Mode index at which mode skip mask set
1000
78.8k
  sf->schedule_mode_search = 0;
1001
78.8k
  sf->use_nonrd_pick_mode = 0;
1002
1.10M
  for (i = 0; i < BLOCK_SIZES; ++i) sf->inter_mode_mask[i] = INTER_ALL;
1003
78.8k
  sf->max_intra_bsize = BLOCK_64X64;
1004
78.8k
  sf->reuse_inter_pred_sby = 0;
1005
  // This setting only takes effect when partition_search_type is set
1006
  // to FIXED_PARTITION.
1007
78.8k
  sf->always_this_block_size = BLOCK_16X16;
1008
78.8k
  sf->encode_breakout_thresh = 0;
1009
  // Recode loop tolerance %.
1010
78.8k
  sf->recode_tolerance_low = 12;
1011
78.8k
  sf->recode_tolerance_high = 25;
1012
78.8k
  sf->default_interp_filter = SWITCHABLE;
1013
78.8k
  sf->simple_model_rd_from_var = 0;
1014
78.8k
  sf->short_circuit_flat_blocks = 0;
1015
78.8k
  sf->short_circuit_low_temp_var = 0;
1016
78.8k
  sf->limit_newmv_early_exit = 0;
1017
78.8k
  sf->bias_golden = 0;
1018
78.8k
  sf->base_mv_aggressive = 0;
1019
78.8k
  sf->rd_ml_partition.prune_rect_thresh[0] = -1;
1020
78.8k
  sf->rd_ml_partition.prune_rect_thresh[1] = -1;
1021
78.8k
  sf->rd_ml_partition.prune_rect_thresh[2] = -1;
1022
78.8k
  sf->rd_ml_partition.prune_rect_thresh[3] = -1;
1023
78.8k
  sf->rd_ml_partition.var_pruning = 0;
1024
78.8k
  sf->use_accurate_subpel_search = USE_8_TAPS;
1025
1026
  // Some speed-up features even for best quality as minimal impact on quality.
1027
78.8k
  sf->adaptive_rd_thresh = 1;
1028
78.8k
  sf->tx_size_search_breakout = 1;
1029
78.8k
  sf->tx_size_search_depth = 2;
1030
1031
78.8k
  sf->exhaustive_searches_thresh =
1032
78.8k
      (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ? (1 << 20)
1033
78.8k
                                                              : INT_MAX;
1034
78.8k
  {
1035
78.8k
    const int mesh_density_level =
1036
78.8k
        (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ? 0 : 1;
1037
394k
    for (i = 0; i < MAX_MESH_STEP; ++i) {
1038
315k
      sf->mesh_patterns[i].range =
1039
315k
          best_quality_mesh_pattern[mesh_density_level][i].range;
1040
315k
      sf->mesh_patterns[i].interval =
1041
315k
          best_quality_mesh_pattern[mesh_density_level][i].interval;
1042
315k
    }
1043
78.8k
  }
1044
1045
78.8k
  if (oxcf->mode == REALTIME)
1046
43.4k
    set_rt_speed_feature_framesize_independent(cpi, sf, speed, oxcf->content);
1047
35.3k
#if !CONFIG_REALTIME_ONLY
1048
35.3k
  else if (oxcf->mode == GOOD)
1049
35.3k
    set_good_speed_feature_framesize_independent(cpi, cm, sf, speed);
1050
78.8k
#endif
1051
1052
78.8k
  cpi->diamond_search_sad = vp9_diamond_search_sad;
1053
1054
  // Slow quant, dct and trellis not worthwhile for first pass
1055
  // so make sure they are always turned off.
1056
78.8k
  if (oxcf->pass == 1) sf->optimize_coefficients = 0;
1057
1058
  // No recode for 1 pass.
1059
78.8k
  if (oxcf->pass == 0) {
1060
78.8k
    sf->recode_loop = DISALLOW_RECODE;
1061
78.8k
    sf->optimize_coefficients = 0;
1062
78.8k
  }
1063
1064
78.8k
  if (sf->mv.subpel_force_stop == FULL_PEL) {
1065
    // Whole pel only
1066
0
    cpi->find_fractional_mv_step = vp9_skip_sub_pixel_tree;
1067
78.8k
  } else if (sf->mv.subpel_search_method == SUBPEL_TREE) {
1068
78.8k
    cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree;
1069
78.8k
  } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED) {
1070
0
    cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned;
1071
0
  } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_MORE) {
1072
0
    cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_more;
1073
0
  } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_EVENMORE) {
1074
0
    cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_evenmore;
1075
0
  }
1076
1077
  // This is only used in motion vector unit test.
1078
78.8k
  if (cpi->oxcf.motion_vector_unit_test == 1)
1079
0
    cpi->find_fractional_mv_step = vp9_return_max_sub_pixel_mv;
1080
78.8k
  else if (cpi->oxcf.motion_vector_unit_test == 2)
1081
0
    cpi->find_fractional_mv_step = vp9_return_min_sub_pixel_mv;
1082
1083
78.8k
  x->optimize = sf->optimize_coefficients == 1 && oxcf->pass != 1;
1084
1085
78.8k
  x->min_partition_size = sf->default_min_partition_size;
1086
78.8k
  x->max_partition_size = sf->default_max_partition_size;
1087
1088
78.8k
  if (!cpi->oxcf.frame_periodic_boost) {
1089
78.8k
    sf->max_delta_qindex = 0;
1090
78.8k
  }
1091
1092
  // With row based multi-threading, the following speed features
1093
  // have to be disabled to guarantee that bitstreams encoded with single thread
1094
  // and multiple threads match.
1095
  // It can be used in realtime when adaptive_rd_thresh_row_mt is enabled since
1096
  // adaptive_rd_thresh is defined per-row for non-rd pickmode.
1097
78.8k
  if (!sf->adaptive_rd_thresh_row_mt && cpi->row_mt_bit_exact &&
1098
0
      oxcf->max_threads > 1)
1099
0
    sf->adaptive_rd_thresh = 0;
1100
78.8k
}