Coverage Report

Created: 2025-08-28 07:12

/src/libvpx/vp9/encoder/vp9_speed_features.c
Line
Count
Source (jump to first uncovered line)
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
50.4k
static int frame_is_boosted(const VP9_COMP *cpi) {
39
50.4k
  return frame_is_kf_gf_arf(cpi);
40
50.4k
}
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
25.2k
                                                       int speed) {
67
25.2k
  VP9_COMMON *const cm = &cpi->common;
68
25.2k
  const int min_frame_size = VPXMIN(cm->width, cm->height);
69
25.2k
  const int is_480p_or_larger = min_frame_size >= 480;
70
25.2k
  const int is_720p_or_larger = min_frame_size >= 720;
71
25.2k
  const int is_1080p_or_larger = min_frame_size >= 1080;
72
25.2k
  const int is_2160p_or_larger = min_frame_size >= 2160;
73
25.2k
  const int boosted = frame_is_boosted(cpi);
74
75
  // speed 0 features
76
25.2k
  sf->partition_search_breakout_thr.dist = (1 << 20);
77
25.2k
  sf->partition_search_breakout_thr.rate = 80;
78
25.2k
  sf->use_square_only_thresh_high = BLOCK_SIZES;
79
25.2k
  sf->use_square_only_thresh_low = BLOCK_4X4;
80
81
25.2k
  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
30
    sf->rd_ml_partition.search_early_termination = 1;
85
30
    sf->recode_tolerance_high = 45;
86
25.1k
  } else {
87
25.1k
    sf->use_square_only_thresh_high = BLOCK_32X32;
88
25.1k
  }
89
25.2k
  if (is_720p_or_larger) {
90
0
    sf->alt_ref_search_fp = 1;
91
0
  }
92
93
25.2k
  if (!is_1080p_or_larger) {
94
25.2k
    sf->rd_ml_partition.search_breakout = 1;
95
25.2k
    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
25.2k
    } else {
100
25.2k
      sf->rd_ml_partition.search_breakout_thresh[0] = 2.5f;
101
25.2k
      sf->rd_ml_partition.search_breakout_thresh[1] = 1.5f;
102
25.2k
      sf->rd_ml_partition.search_breakout_thresh[2] = 1.5f;
103
25.2k
    }
104
25.2k
  }
105
106
25.2k
  if (!is_720p_or_larger) {
107
25.2k
    if (is_480p_or_larger)
108
30
      sf->prune_single_mode_based_on_mv_diff_mode_rate = boosted ? 0 : 1;
109
25.1k
    else
110
25.1k
      sf->prune_single_mode_based_on_mv_diff_mode_rate = 1;
111
25.2k
  }
112
113
25.2k
  if (speed >= 1) {
114
21.2k
    sf->rd_ml_partition.search_early_termination = 0;
115
21.2k
    sf->rd_ml_partition.search_breakout = 1;
116
21.2k
    if (is_480p_or_larger)
117
8
      sf->use_square_only_thresh_high = BLOCK_64X64;
118
21.2k
    else
119
21.2k
      sf->use_square_only_thresh_high = BLOCK_32X32;
120
21.2k
    sf->use_square_only_thresh_low = BLOCK_16X16;
121
21.2k
    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
21.2k
    } else {
129
21.2k
      sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
130
21.2k
      sf->partition_search_breakout_thr.dist = (1 << 21);
131
21.2k
      sf->rd_ml_partition.search_breakout_thresh[0] = -1.0f;
132
21.2k
      sf->rd_ml_partition.search_breakout_thresh[1] = -1.0f;
133
21.2k
      sf->rd_ml_partition.search_breakout_thresh[2] = -1.0f;
134
21.2k
    }
135
21.2k
#if CONFIG_VP9_HIGHBITDEPTH
136
21.2k
    if (cpi->Source->flags & YV12_FLAG_HIGHBITDEPTH) {
137
0
      sf->rd_ml_partition.search_breakout_thresh[0] -= 1.0f;
138
0
      sf->rd_ml_partition.search_breakout_thresh[1] -= 1.0f;
139
0
      sf->rd_ml_partition.search_breakout_thresh[2] -= 1.0f;
140
0
    }
141
21.2k
#endif  // CONFIG_VP9_HIGHBITDEPTH
142
21.2k
  }
143
144
25.2k
  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
25.2k
  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
25.2k
  if ((speed >= 1) && (cpi->oxcf.pass == 2) &&
196
25.2k
      ((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
25.2k
  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
25.2k
  if (speed >= 5) {
212
0
    sf->partition_search_breakout_thr.rate = 500;
213
0
  }
214
25.2k
}
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
25.2k
                                                         int speed) {
223
25.2k
  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
224
25.2k
  const int boosted = frame_is_boosted(cpi);
225
25.2k
  int i;
226
227
25.2k
  sf->adaptive_interp_filter_search = 1;
228
25.2k
  sf->adaptive_pred_interp_filter = 1;
229
25.2k
  sf->adaptive_rd_thresh = 1;
230
25.2k
  sf->adaptive_rd_thresh_row_mt = 0;
231
25.2k
  sf->allow_skip_recode = 1;
232
25.2k
  sf->less_rectangular_check = 1;
233
25.2k
  sf->mv.auto_mv_step_size = 1;
234
25.2k
  sf->mv.use_downsampled_sad = 1;
235
25.2k
  sf->prune_ref_frame_for_rect_partitions = 1;
236
25.2k
  sf->temporal_filter_search_method = NSTEP;
237
25.2k
  sf->tx_size_search_breakout = 1;
238
25.2k
  sf->use_square_partition_only = !boosted;
239
25.2k
  sf->early_term_interp_search_plane_rd = 1;
240
25.2k
  sf->cb_pred_filter_search = 1;
241
25.2k
  sf->trellis_opt_tx_rd.method = sf->optimize_coefficients
242
25.2k
                                     ? ENABLE_TRELLIS_OPT_TX_RD_RESIDUAL_MSE
243
25.2k
                                     : DISABLE_TRELLIS_OPT;
244
25.2k
  sf->trellis_opt_tx_rd.thresh = boosted ? 4.0 : 3.0;
245
246
25.2k
  sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
247
25.2k
  sf->comp_inter_joint_search_iter_level = 1;
248
249
  // Reference masking is not supported in dynamic scaling mode.
250
25.2k
  sf->reference_masking = oxcf->resize_mode != RESIZE_DYNAMIC;
251
252
25.2k
  sf->rd_ml_partition.var_pruning = 1;
253
25.2k
  sf->rd_ml_partition.prune_rect_thresh[0] = -1;
254
25.2k
  sf->rd_ml_partition.prune_rect_thresh[1] = 350;
255
25.2k
  sf->rd_ml_partition.prune_rect_thresh[2] = 325;
256
25.2k
  sf->rd_ml_partition.prune_rect_thresh[3] = 250;
257
258
25.2k
  if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) {
259
0
    sf->exhaustive_searches_thresh = (1 << 22);
260
25.2k
  } else {
261
25.2k
    sf->exhaustive_searches_thresh = INT_MAX;
262
25.2k
  }
263
264
126k
  for (i = 0; i < MAX_MESH_STEP; ++i) {
265
100k
    const int mesh_density_level = 0;
266
100k
    sf->mesh_patterns[i].range =
267
100k
        good_quality_mesh_patterns[mesh_density_level][i].range;
268
100k
    sf->mesh_patterns[i].interval =
269
100k
        good_quality_mesh_patterns[mesh_density_level][i].interval;
270
100k
  }
271
272
25.2k
  if (speed >= 1) {
273
21.2k
    sf->rd_ml_partition.var_pruning = !boosted;
274
21.2k
    sf->rd_ml_partition.prune_rect_thresh[1] = 225;
275
21.2k
    sf->rd_ml_partition.prune_rect_thresh[2] = 225;
276
21.2k
    sf->rd_ml_partition.prune_rect_thresh[3] = 225;
277
278
21.2k
    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
21.2k
    } else {
287
21.2k
      sf->use_square_partition_only = !frame_is_intra_only(cm);
288
21.2k
    }
289
290
21.2k
    sf->allow_txfm_domain_distortion = 1;
291
21.2k
    sf->tx_domain_thresh = tx_dom_thresholds[(speed < 6) ? speed : 5];
292
21.2k
    sf->trellis_opt_tx_rd.method = sf->optimize_coefficients
293
21.2k
                                       ? ENABLE_TRELLIS_OPT_TX_RD_SRC_VAR
294
21.2k
                                       : DISABLE_TRELLIS_OPT;
295
21.2k
    sf->trellis_opt_tx_rd.thresh = qopt_thresholds[(speed < 6) ? speed : 5];
296
21.2k
    sf->less_rectangular_check = 1;
297
21.2k
    sf->use_rd_breakout = 1;
298
21.2k
    sf->adaptive_motion_search = 1;
299
21.2k
    sf->adaptive_rd_thresh = 2;
300
21.2k
    sf->mv.subpel_search_level = 1;
301
21.2k
    if (cpi->oxcf.content != VP9E_CONTENT_FILM) sf->mode_skip_start = 10;
302
21.2k
    sf->allow_acl = 0;
303
304
21.2k
    sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
305
21.2k
    if (cpi->oxcf.content != VP9E_CONTENT_FILM) {
306
21.2k
      sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
307
21.2k
      sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
308
21.2k
    }
309
310
21.2k
    sf->recode_tolerance_low = 15;
311
21.2k
    sf->recode_tolerance_high = 30;
312
313
21.2k
    sf->exhaustive_searches_thresh =
314
21.2k
        (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ? (1 << 23)
315
21.2k
                                                                : INT_MAX;
316
21.2k
    sf->use_accurate_subpel_search = USE_4_TAPS;
317
21.2k
  }
318
319
25.2k
  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
25.2k
  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
25.2k
  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
25.2k
  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
25.2k
}
412
#endif  // !CONFIG_REALTIME_ONLY
413
414
static void set_rt_speed_feature_framesize_dependent(VP9_COMP *cpi,
415
                                                     SPEED_FEATURES *sf,
416
31.9k
                                                     int speed) {
417
31.9k
  VP9_COMMON *const cm = &cpi->common;
418
419
31.9k
  if (speed >= 1) {
420
31.9k
    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
31.9k
    } else {
424
31.9k
      sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
425
31.9k
    }
426
31.9k
  }
427
428
31.9k
  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
31.9k
  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
31.9k
  if (speed >= 7) {
447
0
    sf->encode_breakout_thresh =
448
0
        (VPXMIN(cm->width, cm->height) >= 720) ? 800 : 300;
449
0
  }
450
31.9k
}
451
452
static void set_rt_speed_feature_framesize_independent(
453
31.9k
    VP9_COMP *cpi, SPEED_FEATURES *sf, int speed, vp9e_tune_content content) {
454
31.9k
  VP9_COMMON *const cm = &cpi->common;
455
31.9k
  SVC *const svc = &cpi->svc;
456
31.9k
  const int is_keyframe = cm->frame_type == KEY_FRAME;
457
31.9k
  const int frames_since_key = is_keyframe ? 0 : cpi->rc.frames_since_key;
458
31.9k
  sf->static_segmentation = 0;
459
31.9k
  sf->adaptive_rd_thresh = 1;
460
31.9k
  sf->adaptive_rd_thresh_row_mt = 0;
461
31.9k
  sf->use_fast_coef_costing = 1;
462
31.9k
  sf->exhaustive_searches_thresh = INT_MAX;
463
31.9k
  sf->allow_acl = 0;
464
31.9k
  sf->copy_partition_flag = 0;
465
31.9k
  sf->use_source_sad = 0;
466
31.9k
  sf->use_simple_block_yrd = 0;
467
31.9k
  sf->adapt_partition_source_sad = 0;
468
31.9k
  sf->use_altref_onepass = 0;
469
31.9k
  sf->use_compound_nonrd_pickmode = 0;
470
31.9k
  sf->nonrd_keyframe = 0;
471
31.9k
  sf->svc_use_lowres_part = 0;
472
31.9k
  sf->overshoot_detection_cbr_rt = NO_DETECTION;
473
31.9k
  sf->disable_16x16part_nonkey = 0;
474
31.9k
  sf->disable_golden_ref = 0;
475
31.9k
  sf->enable_tpl_model = 0;
476
31.9k
  sf->enhanced_full_pixel_motion_search = 0;
477
31.9k
  sf->use_accurate_subpel_search = USE_2_TAPS;
478
31.9k
  sf->nonrd_use_ml_partition = 0;
479
31.9k
  sf->variance_part_thresh_mult = 1;
480
31.9k
  sf->cb_pred_filter_search = 0;
481
31.9k
  sf->force_smooth_interpol = 0;
482
31.9k
  sf->rt_intra_dc_only_low_content = 0;
483
31.9k
  sf->mv.enable_adaptive_subpel_force_stop = 0;
484
485
31.9k
  if (speed >= 1) {
486
31.9k
    sf->allow_txfm_domain_distortion = 1;
487
31.9k
    sf->tx_domain_thresh = 0.0;
488
31.9k
    sf->trellis_opt_tx_rd.method = DISABLE_TRELLIS_OPT;
489
31.9k
    sf->trellis_opt_tx_rd.thresh = 0.0;
490
31.9k
    sf->use_square_partition_only = !frame_is_intra_only(cm);
491
31.9k
    sf->less_rectangular_check = 1;
492
31.9k
    sf->tx_size_search_method =
493
31.9k
        frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL;
494
495
31.9k
    sf->use_rd_breakout = 1;
496
497
31.9k
    sf->adaptive_motion_search = 1;
498
31.9k
    sf->adaptive_pred_interp_filter = 1;
499
31.9k
    sf->mv.auto_mv_step_size = 1;
500
31.9k
    sf->adaptive_rd_thresh = 2;
501
31.9k
    sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
502
31.9k
    sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
503
31.9k
    sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
504
31.9k
  }
505
506
31.9k
  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
31.9k
  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
31.9k
  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
31.9k
  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
31.9k
  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
        CHECK_MEM_ERROR(&cm->error, cpi->content_state_sb_fd,
680
0
                        (uint8_t *)vpx_calloc(
681
0
                            (cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1),
682
0
                            sizeof(uint8_t)));
683
0
      }
684
0
    }
685
0
    if (cpi->oxcf.rc_mode == VPX_CBR && content != VP9E_CONTENT_SCREEN) {
686
      // Enable short circuit for low temporal variance.
687
0
      sf->short_circuit_low_temp_var = 1;
688
0
    }
689
0
    if (svc->temporal_layer_id > 0) {
690
0
      sf->adaptive_rd_thresh = 4;
691
0
      sf->limit_newmv_early_exit = 0;
692
0
      sf->base_mv_aggressive = 1;
693
0
    }
694
0
    if (cm->frame_type != KEY_FRAME && cpi->resize_state == ORIG &&
695
0
        cpi->oxcf.rc_mode == VPX_CBR && !cpi->rc.disable_overshoot_maxq_cbr)
696
0
      sf->overshoot_detection_cbr_rt = FAST_DETECTION_MAXQ;
697
0
  }
698
699
31.9k
  if (speed >= 7) {
700
0
    sf->adapt_partition_source_sad = 0;
701
0
    sf->adaptive_rd_thresh = 3;
702
0
    sf->mv.search_method = FAST_DIAMOND;
703
0
    sf->mv.fullpel_search_step_param = 10;
704
    // For SVC: use better mv search on base temporal layer, and only
705
    // on base spatial layer if highest resolution is above 640x360.
706
0
    if (svc->number_temporal_layers > 2 && svc->temporal_layer_id == 0 &&
707
0
        (svc->spatial_layer_id == 0 ||
708
0
         cpi->oxcf.width * cpi->oxcf.height <= 640 * 360)) {
709
0
      sf->mv.search_method = NSTEP;
710
0
      sf->mv.fullpel_search_step_param = 6;
711
0
    }
712
0
    if (svc->temporal_layer_id > 0 || svc->spatial_layer_id > 1) {
713
0
      sf->use_simple_block_yrd = 1;
714
0
      if (svc->non_reference_frame)
715
0
        sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED_EVENMORE;
716
0
    }
717
0
    if (cpi->use_svc && cpi->row_mt && cpi->oxcf.max_threads > 1)
718
0
      sf->adaptive_rd_thresh_row_mt = 1;
719
    // Enable partition copy. For SVC only enabled for top spatial resolution
720
    // layer.
721
0
    cpi->max_copied_frame = 0;
722
0
    if (!cpi->last_frame_dropped && cpi->resize_state == ORIG &&
723
0
        !cpi->external_resize &&
724
0
        (!cpi->use_svc ||
725
0
         (svc->spatial_layer_id == svc->number_spatial_layers - 1 &&
726
0
          !svc->last_layer_dropped[svc->number_spatial_layers - 1]))) {
727
0
      sf->copy_partition_flag = 1;
728
0
      cpi->max_copied_frame = 2;
729
      // The top temporal enhancement layer (for number of temporal layers > 1)
730
      // are non-reference frames, so use large/max value for max_copied_frame.
731
0
      if (svc->number_temporal_layers > 1 &&
732
0
          svc->temporal_layer_id == svc->number_temporal_layers - 1)
733
0
        cpi->max_copied_frame = 255;
734
0
    }
735
    // For SVC: enable use of lower resolution partition for higher resolution,
736
    // only for 3 spatial layers and when config/top resolution is above VGA.
737
    // Enable only for non-base temporal layer frames.
738
0
    if (cpi->use_svc && svc->use_partition_reuse &&
739
0
        svc->number_spatial_layers == 3 && svc->temporal_layer_id > 0 &&
740
0
        cpi->oxcf.width * cpi->oxcf.height > 640 * 480)
741
0
      sf->svc_use_lowres_part = 1;
742
    // For SVC when golden is used as second temporal reference: to avoid
743
    // encode time increase only use this feature on base temporal layer.
744
    // (i.e remove golden flag from frame_flags for temporal_layer_id > 0).
745
0
    if (cpi->use_svc && svc->use_gf_temporal_ref_current_layer &&
746
0
        svc->temporal_layer_id > 0)
747
0
      cpi->ref_frame_flags &= (~VP9_GOLD_FLAG);
748
0
    if (cm->width * cm->height > 640 * 480) sf->cb_pred_filter_search = 2;
749
0
  }
750
751
31.9k
  if (speed >= 8) {
752
0
    sf->adaptive_rd_thresh = 4;
753
0
    sf->skip_encode_sb = 1;
754
0
    if (cpi->svc.number_spatial_layers > 1 && !cpi->svc.simulcast_mode)
755
0
      sf->nonrd_keyframe = 0;
756
0
    else
757
0
      sf->nonrd_keyframe = 1;
758
0
    if (!cpi->use_svc) cpi->max_copied_frame = 4;
759
0
    if (cpi->row_mt && cpi->oxcf.max_threads > 1)
760
0
      sf->adaptive_rd_thresh_row_mt = 1;
761
    // Enable ML based partition for low res.
762
0
    if (!frame_is_intra_only(cm) && cm->width * cm->height <= 352 * 288) {
763
0
      sf->nonrd_use_ml_partition = 1;
764
0
    }
765
0
#if CONFIG_VP9_HIGHBITDEPTH
766
0
    if (cpi->Source->flags & YV12_FLAG_HIGHBITDEPTH)
767
0
      sf->nonrd_use_ml_partition = 0;
768
0
#endif
769
0
    if (content == VP9E_CONTENT_SCREEN) sf->mv.subpel_force_stop = HALF_PEL;
770
0
    sf->rt_intra_dc_only_low_content = 1;
771
0
    if (!cpi->use_svc && cpi->oxcf.rc_mode == VPX_CBR &&
772
0
        content != VP9E_CONTENT_SCREEN) {
773
      // More aggressive short circuit for speed 8.
774
0
      sf->short_circuit_low_temp_var = 3;
775
      // Use level 2 for noisey cases as there is a regression in some
776
      // noisy clips with level 3.
777
0
      if (cpi->noise_estimate.enabled && cm->width >= 1280 &&
778
0
          cm->height >= 720) {
779
0
        NOISE_LEVEL noise_level =
780
0
            vp9_noise_estimate_extract_level(&cpi->noise_estimate);
781
0
        if (noise_level >= kMedium) sf->short_circuit_low_temp_var = 2;
782
0
      }
783
      // Since the short_circuit_low_temp_var is used, reduce the
784
      // adaptive_rd_thresh level.
785
0
      if (cm->width * cm->height > 352 * 288)
786
0
        sf->adaptive_rd_thresh = 1;
787
0
      else
788
0
        sf->adaptive_rd_thresh = 2;
789
0
    }
790
0
    sf->limit_newmv_early_exit = 0;
791
0
    sf->use_simple_block_yrd = 1;
792
0
    if (cm->width * cm->height > 352 * 288) sf->cb_pred_filter_search = 2;
793
0
  }
794
795
31.9k
  if (speed >= 9) {
796
    // Only keep INTRA_DC mode for speed 9.
797
0
    if (!is_keyframe) {
798
0
      int i = 0;
799
0
      for (i = 0; i < BLOCK_SIZES; ++i)
800
0
        sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
801
0
    }
802
0
    sf->cb_pred_filter_search = 2;
803
0
    sf->mv.enable_adaptive_subpel_force_stop = 1;
804
0
    sf->mv.adapt_subpel_force_stop.mv_thresh = 1;
805
0
    sf->mv.adapt_subpel_force_stop.force_stop_below = QUARTER_PEL;
806
0
    sf->mv.adapt_subpel_force_stop.force_stop_above = HALF_PEL;
807
    // Disable partition blocks below 16x16, except for low-resolutions.
808
0
    if (cm->frame_type != KEY_FRAME && cm->width >= 320 && cm->height >= 240)
809
0
      sf->disable_16x16part_nonkey = 1;
810
    // Allow for disabling GOLDEN reference, for CBR mode.
811
0
    if (cpi->oxcf.rc_mode == VPX_CBR) sf->disable_golden_ref = 1;
812
0
    if (cpi->rc.avg_frame_low_motion < 70) sf->default_interp_filter = BILINEAR;
813
0
    if (cm->width * cm->height >= 640 * 360) sf->variance_part_thresh_mult = 2;
814
0
  }
815
816
  // Disable split to 8x8 for low-resolution at very high Q.
817
  // For variance partition (speed >= 6). Ignore the first few frames
818
  // as avg_frame_qindex starts at max_q (worst_quality).
819
31.9k
  if (cm->frame_type != KEY_FRAME && cm->width * cm->height <= 320 * 240 &&
820
31.9k
      sf->partition_search_type == VAR_BASED_PARTITION &&
821
31.9k
      cpi->rc.avg_frame_qindex[INTER_FRAME] > 208 &&
822
31.9k
      cpi->common.current_video_frame > 8)
823
0
    sf->disable_16x16part_nonkey = 1;
824
825
31.9k
  if (sf->nonrd_use_ml_partition)
826
0
    sf->partition_search_type = ML_BASED_PARTITION;
827
828
31.9k
  if (sf->use_altref_onepass) {
829
0
    if (cpi->rc.is_src_frame_alt_ref && cm->frame_type != KEY_FRAME) {
830
0
      sf->partition_search_type = FIXED_PARTITION;
831
0
      sf->always_this_block_size = BLOCK_64X64;
832
0
    }
833
0
    if (cpi->count_arf_frame_usage == NULL) {
834
0
      CHECK_MEM_ERROR(
835
0
          &cm->error, cpi->count_arf_frame_usage,
836
0
          (uint8_t *)vpx_calloc((cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1),
837
0
                                sizeof(*cpi->count_arf_frame_usage)));
838
0
    }
839
0
    if (cpi->count_lastgolden_frame_usage == NULL)
840
0
      CHECK_MEM_ERROR(
841
0
          &cm->error, cpi->count_lastgolden_frame_usage,
842
0
          (uint8_t *)vpx_calloc((cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1),
843
0
                                sizeof(*cpi->count_lastgolden_frame_usage)));
844
0
  }
845
31.9k
  if (svc->previous_frame_is_intra_only) {
846
0
    sf->partition_search_type = FIXED_PARTITION;
847
0
    sf->always_this_block_size = BLOCK_64X64;
848
0
  }
849
  // Special case for screen content: increase motion search on base spatial
850
  // layer when high motion is detected or previous SL0 frame was dropped.
851
31.9k
  if (cpi->oxcf.content == VP9E_CONTENT_SCREEN && cpi->oxcf.speed >= 5 &&
852
31.9k
      (svc->high_num_blocks_with_motion || svc->last_layer_dropped[0])) {
853
0
    sf->mv.search_method = NSTEP;
854
    // TODO(marpan/jianj): Tune this setting for screensharing. For now use
855
    // small step_param for all spatial layers.
856
0
    sf->mv.fullpel_search_step_param = 2;
857
0
  }
858
  // TODO(marpan): There is regression for aq-mode=3 speed <= 4, force it
859
  // off for now.
860
31.9k
  if (speed <= 3 && cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
861
0
    cpi->oxcf.aq_mode = 0;
862
  // For all speeds for rt mode: if the deadline mode changed (was good/best
863
  // quality on previous frame and now is realtime) set nonrd_keyframe to 1 to
864
  // avoid entering rd pickmode. This causes issues, such as: b/310663186.
865
31.9k
  if (cpi->oxcf.mode != cpi->deadline_mode_previous_frame)
866
0
    sf->nonrd_keyframe = 1;
867
868
  // TODO(marpan): Force this feature off always, for the issue: 366146260
869
  // Remove this disabling when underlying issue is resolved.
870
31.9k
  sf->svc_use_lowres_part = 0;
871
31.9k
}
872
873
57.1k
void vp9_set_speed_features_framesize_dependent(VP9_COMP *cpi, int speed) {
874
57.1k
  SPEED_FEATURES *const sf = &cpi->sf;
875
57.1k
  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
876
57.1k
  RD_OPT *const rd = &cpi->rd;
877
57.1k
  int i;
878
879
  // best quality defaults
880
  // Some speed-up features even for best quality as minimal impact on quality.
881
57.1k
  sf->partition_search_breakout_thr.dist = (1 << 19);
882
57.1k
  sf->partition_search_breakout_thr.rate = 80;
883
57.1k
  sf->rd_ml_partition.search_early_termination = 0;
884
57.1k
  sf->rd_ml_partition.search_breakout = 0;
885
886
57.1k
  if (oxcf->mode == REALTIME)
887
31.9k
    set_rt_speed_feature_framesize_dependent(cpi, sf, speed);
888
25.2k
#if !CONFIG_REALTIME_ONLY
889
25.2k
  else if (oxcf->mode == GOOD)
890
25.2k
    set_good_speed_feature_framesize_dependent(cpi, sf, speed);
891
57.1k
#endif
892
893
57.1k
  if (sf->disable_split_mask == DISABLE_ALL_SPLIT) {
894
0
    sf->adaptive_pred_interp_filter = 0;
895
0
  }
896
897
57.1k
  if (cpi->encode_breakout && oxcf->mode == REALTIME &&
898
57.1k
      sf->encode_breakout_thresh > cpi->encode_breakout) {
899
0
    cpi->encode_breakout = sf->encode_breakout_thresh;
900
0
  }
901
902
  // Check for masked out split cases.
903
399k
  for (i = 0; i < MAX_REFS; ++i) {
904
342k
    if (sf->disable_split_mask & (1 << i)) {
905
106k
      rd->thresh_mult_sub8x8[i] = INT_MAX;
906
106k
    }
907
342k
  }
908
909
  // With row based multi-threading, the following speed features
910
  // have to be disabled to guarantee that bitstreams encoded with single thread
911
  // and multiple threads match.
912
  // It can be used in realtime when adaptive_rd_thresh_row_mt is enabled since
913
  // adaptive_rd_thresh is defined per-row for non-rd pickmode.
914
57.1k
  if (!sf->adaptive_rd_thresh_row_mt && cpi->row_mt_bit_exact &&
915
57.1k
      oxcf->max_threads > 1)
916
0
    sf->adaptive_rd_thresh = 0;
917
57.1k
}
918
919
57.1k
void vp9_set_speed_features_framesize_independent(VP9_COMP *cpi, int speed) {
920
57.1k
  SPEED_FEATURES *const sf = &cpi->sf;
921
57.1k
#if !CONFIG_REALTIME_ONLY
922
57.1k
  VP9_COMMON *const cm = &cpi->common;
923
57.1k
#endif
924
57.1k
  MACROBLOCK *const x = &cpi->td.mb;
925
57.1k
  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
926
57.1k
  int i;
927
928
  // best quality defaults
929
57.1k
  sf->frame_parameter_update = 1;
930
57.1k
  sf->mv.search_method = NSTEP;
931
57.1k
  sf->recode_loop = ALLOW_RECODE_FIRST;
932
57.1k
  sf->mv.subpel_search_method = SUBPEL_TREE;
933
57.1k
  sf->mv.subpel_search_level = 2;
934
57.1k
  sf->mv.subpel_force_stop = EIGHTH_PEL;
935
57.1k
  sf->optimize_coefficients = !is_lossless_requested(&cpi->oxcf);
936
57.1k
  sf->mv.reduce_first_step_size = 0;
937
57.1k
  sf->coeff_prob_appx_step = 1;
938
57.1k
  sf->mv.auto_mv_step_size = 0;
939
57.1k
  sf->mv.fullpel_search_step_param = 6;
940
57.1k
  sf->mv.use_downsampled_sad = 0;
941
57.1k
  sf->comp_inter_joint_search_iter_level = 0;
942
57.1k
  sf->tx_size_search_method = USE_FULL_RD;
943
57.1k
  sf->use_lp32x32fdct = 0;
944
57.1k
  sf->adaptive_motion_search = 0;
945
57.1k
  sf->enhanced_full_pixel_motion_search = 1;
946
57.1k
  sf->adaptive_pred_interp_filter = 0;
947
57.1k
  sf->adaptive_mode_search = 0;
948
57.1k
  sf->prune_single_mode_based_on_mv_diff_mode_rate = 0;
949
57.1k
  sf->cb_pred_filter_search = 0;
950
57.1k
  sf->early_term_interp_search_plane_rd = 0;
951
57.1k
  sf->cb_partition_search = 0;
952
57.1k
  sf->motion_field_mode_search = 0;
953
57.1k
  sf->alt_ref_search_fp = 0;
954
57.1k
  sf->use_quant_fp = 0;
955
57.1k
  sf->reference_masking = 0;
956
57.1k
  sf->partition_search_type = SEARCH_PARTITION;
957
57.1k
  sf->less_rectangular_check = 0;
958
57.1k
  sf->use_square_partition_only = 0;
959
57.1k
  sf->use_square_only_thresh_high = BLOCK_SIZES;
960
57.1k
  sf->use_square_only_thresh_low = BLOCK_4X4;
961
57.1k
  sf->auto_min_max_partition_size = NOT_IN_USE;
962
57.1k
  sf->rd_auto_partition_min_limit = BLOCK_4X4;
963
57.1k
  sf->default_max_partition_size = BLOCK_64X64;
964
57.1k
  sf->default_min_partition_size = BLOCK_4X4;
965
57.1k
  sf->adjust_partitioning_from_last_frame = 0;
966
57.1k
  sf->last_partitioning_redo_frequency = 4;
967
57.1k
  sf->disable_split_mask = 0;
968
57.1k
  sf->mode_search_skip_flags = 0;
969
57.1k
  sf->force_frame_boost = 0;
970
57.1k
  sf->max_delta_qindex = 0;
971
57.1k
  sf->disable_filter_search_var_thresh = 0;
972
57.1k
  sf->adaptive_interp_filter_search = 0;
973
57.1k
  sf->allow_txfm_domain_distortion = 0;
974
57.1k
  sf->tx_domain_thresh = 99.0;
975
57.1k
  sf->trellis_opt_tx_rd.method =
976
57.1k
      sf->optimize_coefficients ? ENABLE_TRELLIS_OPT : DISABLE_TRELLIS_OPT;
977
57.1k
  sf->trellis_opt_tx_rd.thresh = 99.0;
978
57.1k
  sf->allow_acl = 1;
979
57.1k
  sf->enable_tpl_model = oxcf->enable_tpl_model;
980
57.1k
  sf->prune_ref_frame_for_rect_partitions = 0;
981
57.1k
  sf->temporal_filter_search_method = MESH;
982
57.1k
  sf->allow_skip_txfm_ac_dc = 0;
983
984
285k
  for (i = 0; i < TX_SIZES; i++) {
985
228k
    sf->intra_y_mode_mask[i] = INTRA_ALL;
986
228k
    sf->intra_uv_mode_mask[i] = INTRA_ALL;
987
228k
  }
988
57.1k
  sf->use_rd_breakout = 0;
989
57.1k
  sf->skip_encode_sb = 0;
990
57.1k
  sf->use_uv_intra_rd_estimate = 0;
991
57.1k
  sf->allow_skip_recode = 0;
992
57.1k
  sf->lpf_pick = LPF_PICK_FROM_FULL_IMAGE;
993
57.1k
  sf->use_fast_coef_updates = TWO_LOOP;
994
57.1k
  sf->use_fast_coef_costing = 0;
995
57.1k
  sf->mode_skip_start = MAX_MODES;  // Mode index at which mode skip mask set
996
57.1k
  sf->schedule_mode_search = 0;
997
57.1k
  sf->use_nonrd_pick_mode = 0;
998
799k
  for (i = 0; i < BLOCK_SIZES; ++i) sf->inter_mode_mask[i] = INTER_ALL;
999
57.1k
  sf->max_intra_bsize = BLOCK_64X64;
1000
57.1k
  sf->reuse_inter_pred_sby = 0;
1001
  // This setting only takes effect when partition_search_type is set
1002
  // to FIXED_PARTITION.
1003
57.1k
  sf->always_this_block_size = BLOCK_16X16;
1004
57.1k
  sf->encode_breakout_thresh = 0;
1005
  // Recode loop tolerance %.
1006
57.1k
  sf->recode_tolerance_low = 12;
1007
57.1k
  sf->recode_tolerance_high = 25;
1008
57.1k
  sf->default_interp_filter = SWITCHABLE;
1009
57.1k
  sf->simple_model_rd_from_var = 0;
1010
57.1k
  sf->short_circuit_flat_blocks = 0;
1011
57.1k
  sf->short_circuit_low_temp_var = 0;
1012
57.1k
  sf->limit_newmv_early_exit = 0;
1013
57.1k
  sf->bias_golden = 0;
1014
57.1k
  sf->base_mv_aggressive = 0;
1015
57.1k
  sf->rd_ml_partition.prune_rect_thresh[0] = -1;
1016
57.1k
  sf->rd_ml_partition.prune_rect_thresh[1] = -1;
1017
57.1k
  sf->rd_ml_partition.prune_rect_thresh[2] = -1;
1018
57.1k
  sf->rd_ml_partition.prune_rect_thresh[3] = -1;
1019
57.1k
  sf->rd_ml_partition.var_pruning = 0;
1020
57.1k
  sf->use_accurate_subpel_search = USE_8_TAPS;
1021
1022
  // Some speed-up features even for best quality as minimal impact on quality.
1023
57.1k
  sf->adaptive_rd_thresh = 1;
1024
57.1k
  sf->tx_size_search_breakout = 1;
1025
57.1k
  sf->tx_size_search_depth = 2;
1026
1027
57.1k
  sf->exhaustive_searches_thresh =
1028
57.1k
      (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ? (1 << 20)
1029
57.1k
                                                              : INT_MAX;
1030
57.1k
  {
1031
57.1k
    const int mesh_density_level =
1032
57.1k
        (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ? 0 : 1;
1033
285k
    for (i = 0; i < MAX_MESH_STEP; ++i) {
1034
228k
      sf->mesh_patterns[i].range =
1035
228k
          best_quality_mesh_pattern[mesh_density_level][i].range;
1036
228k
      sf->mesh_patterns[i].interval =
1037
228k
          best_quality_mesh_pattern[mesh_density_level][i].interval;
1038
228k
    }
1039
57.1k
  }
1040
1041
57.1k
  if (oxcf->mode == REALTIME)
1042
31.9k
    set_rt_speed_feature_framesize_independent(cpi, sf, speed, oxcf->content);
1043
25.2k
#if !CONFIG_REALTIME_ONLY
1044
25.2k
  else if (oxcf->mode == GOOD)
1045
25.2k
    set_good_speed_feature_framesize_independent(cpi, cm, sf, speed);
1046
57.1k
#endif
1047
1048
57.1k
  cpi->diamond_search_sad = vp9_diamond_search_sad;
1049
1050
  // Slow quant, dct and trellis not worthwhile for first pass
1051
  // so make sure they are always turned off.
1052
57.1k
  if (oxcf->pass == 1) sf->optimize_coefficients = 0;
1053
1054
  // No recode for 1 pass.
1055
57.1k
  if (oxcf->pass == 0) {
1056
57.1k
    sf->recode_loop = DISALLOW_RECODE;
1057
57.1k
    sf->optimize_coefficients = 0;
1058
57.1k
  }
1059
1060
57.1k
  if (sf->mv.subpel_force_stop == FULL_PEL) {
1061
    // Whole pel only
1062
0
    cpi->find_fractional_mv_step = vp9_skip_sub_pixel_tree;
1063
57.1k
  } else if (sf->mv.subpel_search_method == SUBPEL_TREE) {
1064
57.1k
    cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree;
1065
57.1k
  } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED) {
1066
0
    cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned;
1067
0
  } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_MORE) {
1068
0
    cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_more;
1069
0
  } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_EVENMORE) {
1070
0
    cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_evenmore;
1071
0
  }
1072
1073
  // This is only used in motion vector unit test.
1074
57.1k
  if (cpi->oxcf.motion_vector_unit_test == 1)
1075
0
    cpi->find_fractional_mv_step = vp9_return_max_sub_pixel_mv;
1076
57.1k
  else if (cpi->oxcf.motion_vector_unit_test == 2)
1077
0
    cpi->find_fractional_mv_step = vp9_return_min_sub_pixel_mv;
1078
1079
57.1k
  x->optimize = sf->optimize_coefficients == 1 && oxcf->pass != 1;
1080
1081
57.1k
  x->min_partition_size = sf->default_min_partition_size;
1082
57.1k
  x->max_partition_size = sf->default_max_partition_size;
1083
1084
57.1k
  if (!cpi->oxcf.frame_periodic_boost) {
1085
57.1k
    sf->max_delta_qindex = 0;
1086
57.1k
  }
1087
1088
  // With row based multi-threading, the following speed features
1089
  // have to be disabled to guarantee that bitstreams encoded with single thread
1090
  // and multiple threads match.
1091
  // It can be used in realtime when adaptive_rd_thresh_row_mt is enabled since
1092
  // adaptive_rd_thresh is defined per-row for non-rd pickmode.
1093
57.1k
  if (!sf->adaptive_rd_thresh_row_mt && cpi->row_mt_bit_exact &&
1094
57.1k
      oxcf->max_threads > 1)
1095
0
    sf->adaptive_rd_thresh = 0;
1096
57.1k
}