Coverage Report

Created: 2024-09-06 07:53

/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
45.2k
static int frame_is_boosted(const VP9_COMP *cpi) {
39
45.2k
  return frame_is_kf_gf_arf(cpi);
40
45.2k
}
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
22.6k
                                                       int speed) {
67
22.6k
  VP9_COMMON *const cm = &cpi->common;
68
22.6k
  const int min_frame_size = VPXMIN(cm->width, cm->height);
69
22.6k
  const int is_480p_or_larger = min_frame_size >= 480;
70
22.6k
  const int is_720p_or_larger = min_frame_size >= 720;
71
22.6k
  const int is_1080p_or_larger = min_frame_size >= 1080;
72
22.6k
  const int is_2160p_or_larger = min_frame_size >= 2160;
73
22.6k
  const int boosted = frame_is_boosted(cpi);
74
75
  // speed 0 features
76
22.6k
  sf->partition_search_breakout_thr.dist = (1 << 20);
77
22.6k
  sf->partition_search_breakout_thr.rate = 80;
78
22.6k
  sf->use_square_only_thresh_high = BLOCK_SIZES;
79
22.6k
  sf->use_square_only_thresh_low = BLOCK_4X4;
80
81
22.6k
  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
13
    sf->rd_ml_partition.search_early_termination = 1;
85
13
    sf->recode_tolerance_high = 45;
86
22.6k
  } else {
87
22.6k
    sf->use_square_only_thresh_high = BLOCK_32X32;
88
22.6k
  }
89
22.6k
  if (is_720p_or_larger) {
90
0
    sf->alt_ref_search_fp = 1;
91
0
  }
92
93
22.6k
  if (!is_1080p_or_larger) {
94
22.6k
    sf->rd_ml_partition.search_breakout = 1;
95
22.6k
    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
22.6k
    } else {
100
22.6k
      sf->rd_ml_partition.search_breakout_thresh[0] = 2.5f;
101
22.6k
      sf->rd_ml_partition.search_breakout_thresh[1] = 1.5f;
102
22.6k
      sf->rd_ml_partition.search_breakout_thresh[2] = 1.5f;
103
22.6k
    }
104
22.6k
  }
105
106
22.6k
  if (!is_720p_or_larger) {
107
22.6k
    if (is_480p_or_larger)
108
13
      sf->prune_single_mode_based_on_mv_diff_mode_rate = boosted ? 0 : 1;
109
22.6k
    else
110
22.6k
      sf->prune_single_mode_based_on_mv_diff_mode_rate = 1;
111
22.6k
  }
112
113
22.6k
  if (speed >= 1) {
114
19.6k
    sf->rd_ml_partition.search_early_termination = 0;
115
19.6k
    sf->rd_ml_partition.search_breakout = 1;
116
19.6k
    if (is_480p_or_larger)
117
5
      sf->use_square_only_thresh_high = BLOCK_64X64;
118
19.6k
    else
119
19.6k
      sf->use_square_only_thresh_high = BLOCK_32X32;
120
19.6k
    sf->use_square_only_thresh_low = BLOCK_16X16;
121
19.6k
    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
19.6k
    } else {
129
19.6k
      sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
130
19.6k
      sf->partition_search_breakout_thr.dist = (1 << 21);
131
19.6k
      sf->rd_ml_partition.search_breakout_thresh[0] = -1.0f;
132
19.6k
      sf->rd_ml_partition.search_breakout_thresh[1] = -1.0f;
133
19.6k
      sf->rd_ml_partition.search_breakout_thresh[2] = -1.0f;
134
19.6k
    }
135
19.6k
#if CONFIG_VP9_HIGHBITDEPTH
136
19.6k
    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
19.6k
#endif  // CONFIG_VP9_HIGHBITDEPTH
142
19.6k
  }
143
144
22.6k
  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
22.6k
  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
22.6k
  if ((speed >= 1) && (cpi->oxcf.pass == 2) &&
196
22.6k
      ((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
22.6k
  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
22.6k
  if (speed >= 5) {
212
0
    sf->partition_search_breakout_thr.rate = 500;
213
0
  }
214
22.6k
}
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
22.6k
                                                         int speed) {
223
22.6k
  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
224
22.6k
  const int boosted = frame_is_boosted(cpi);
225
22.6k
  int i;
226
227
22.6k
  sf->adaptive_interp_filter_search = 1;
228
22.6k
  sf->adaptive_pred_interp_filter = 1;
229
22.6k
  sf->adaptive_rd_thresh = 1;
230
22.6k
  sf->adaptive_rd_thresh_row_mt = 0;
231
22.6k
  sf->allow_skip_recode = 1;
232
22.6k
  sf->less_rectangular_check = 1;
233
22.6k
  sf->mv.auto_mv_step_size = 1;
234
22.6k
  sf->mv.use_downsampled_sad = 1;
235
22.6k
  sf->prune_ref_frame_for_rect_partitions = 1;
236
22.6k
  sf->temporal_filter_search_method = NSTEP;
237
22.6k
  sf->tx_size_search_breakout = 1;
238
22.6k
  sf->use_square_partition_only = !boosted;
239
22.6k
  sf->early_term_interp_search_plane_rd = 1;
240
22.6k
  sf->cb_pred_filter_search = 1;
241
22.6k
  sf->trellis_opt_tx_rd.method = sf->optimize_coefficients
242
22.6k
                                     ? ENABLE_TRELLIS_OPT_TX_RD_RESIDUAL_MSE
243
22.6k
                                     : DISABLE_TRELLIS_OPT;
244
22.6k
  sf->trellis_opt_tx_rd.thresh = boosted ? 4.0 : 3.0;
245
246
22.6k
  sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
247
22.6k
  sf->comp_inter_joint_search_iter_level = 1;
248
249
  // Reference masking is not supported in dynamic scaling mode.
250
22.6k
  sf->reference_masking = oxcf->resize_mode != RESIZE_DYNAMIC;
251
252
22.6k
  sf->rd_ml_partition.var_pruning = 1;
253
22.6k
  sf->rd_ml_partition.prune_rect_thresh[0] = -1;
254
22.6k
  sf->rd_ml_partition.prune_rect_thresh[1] = 350;
255
22.6k
  sf->rd_ml_partition.prune_rect_thresh[2] = 325;
256
22.6k
  sf->rd_ml_partition.prune_rect_thresh[3] = 250;
257
258
22.6k
  if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) {
259
0
    sf->exhaustive_searches_thresh = (1 << 22);
260
22.6k
  } else {
261
22.6k
    sf->exhaustive_searches_thresh = INT_MAX;
262
22.6k
  }
263
264
113k
  for (i = 0; i < MAX_MESH_STEP; ++i) {
265
90.5k
    const int mesh_density_level = 0;
266
90.5k
    sf->mesh_patterns[i].range =
267
90.5k
        good_quality_mesh_patterns[mesh_density_level][i].range;
268
90.5k
    sf->mesh_patterns[i].interval =
269
90.5k
        good_quality_mesh_patterns[mesh_density_level][i].interval;
270
90.5k
  }
271
272
22.6k
  if (speed >= 1) {
273
19.6k
    sf->rd_ml_partition.var_pruning = !boosted;
274
19.6k
    sf->rd_ml_partition.prune_rect_thresh[1] = 225;
275
19.6k
    sf->rd_ml_partition.prune_rect_thresh[2] = 225;
276
19.6k
    sf->rd_ml_partition.prune_rect_thresh[3] = 225;
277
278
19.6k
    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
19.6k
    } else {
287
19.6k
      sf->use_square_partition_only = !frame_is_intra_only(cm);
288
19.6k
    }
289
290
19.6k
    sf->allow_txfm_domain_distortion = 1;
291
19.6k
    sf->tx_domain_thresh = tx_dom_thresholds[(speed < 6) ? speed : 5];
292
19.6k
    sf->trellis_opt_tx_rd.method = sf->optimize_coefficients
293
19.6k
                                       ? ENABLE_TRELLIS_OPT_TX_RD_SRC_VAR
294
19.6k
                                       : DISABLE_TRELLIS_OPT;
295
19.6k
    sf->trellis_opt_tx_rd.thresh = qopt_thresholds[(speed < 6) ? speed : 5];
296
19.6k
    sf->less_rectangular_check = 1;
297
19.6k
    sf->use_rd_breakout = 1;
298
19.6k
    sf->adaptive_motion_search = 1;
299
19.6k
    sf->adaptive_rd_thresh = 2;
300
19.6k
    sf->mv.subpel_search_level = 1;
301
19.6k
    if (cpi->oxcf.content != VP9E_CONTENT_FILM) sf->mode_skip_start = 10;
302
19.6k
    sf->allow_acl = 0;
303
304
19.6k
    sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
305
19.6k
    if (cpi->oxcf.content != VP9E_CONTENT_FILM) {
306
19.6k
      sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
307
19.6k
      sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
308
19.6k
    }
309
310
19.6k
    sf->recode_tolerance_low = 15;
311
19.6k
    sf->recode_tolerance_high = 30;
312
313
19.6k
    sf->exhaustive_searches_thresh =
314
19.6k
        (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ? (1 << 23)
315
19.6k
                                                                : INT_MAX;
316
19.6k
    sf->use_accurate_subpel_search = USE_4_TAPS;
317
19.6k
  }
318
319
22.6k
  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
22.6k
  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
22.6k
  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
22.6k
  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
22.6k
}
412
#endif  // !CONFIG_REALTIME_ONLY
413
414
static void set_rt_speed_feature_framesize_dependent(VP9_COMP *cpi,
415
                                                     SPEED_FEATURES *sf,
416
22.6k
                                                     int speed) {
417
22.6k
  VP9_COMMON *const cm = &cpi->common;
418
419
22.6k
  if (speed >= 1) {
420
22.6k
    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
22.6k
    } else {
424
22.6k
      sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
425
22.6k
    }
426
22.6k
  }
427
428
22.6k
  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
22.6k
  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
22.6k
  if (speed >= 7) {
447
0
    sf->encode_breakout_thresh =
448
0
        (VPXMIN(cm->width, cm->height) >= 720) ? 800 : 300;
449
0
  }
450
22.6k
}
451
452
static void set_rt_speed_feature_framesize_independent(
453
22.6k
    VP9_COMP *cpi, SPEED_FEATURES *sf, int speed, vp9e_tune_content content) {
454
22.6k
  VP9_COMMON *const cm = &cpi->common;
455
22.6k
  SVC *const svc = &cpi->svc;
456
22.6k
  const int is_keyframe = cm->frame_type == KEY_FRAME;
457
22.6k
  const int frames_since_key = is_keyframe ? 0 : cpi->rc.frames_since_key;
458
22.6k
  sf->static_segmentation = 0;
459
22.6k
  sf->adaptive_rd_thresh = 1;
460
22.6k
  sf->adaptive_rd_thresh_row_mt = 0;
461
22.6k
  sf->use_fast_coef_costing = 1;
462
22.6k
  sf->exhaustive_searches_thresh = INT_MAX;
463
22.6k
  sf->allow_acl = 0;
464
22.6k
  sf->copy_partition_flag = 0;
465
22.6k
  sf->use_source_sad = 0;
466
22.6k
  sf->use_simple_block_yrd = 0;
467
22.6k
  sf->adapt_partition_source_sad = 0;
468
22.6k
  sf->use_altref_onepass = 0;
469
22.6k
  sf->use_compound_nonrd_pickmode = 0;
470
22.6k
  sf->nonrd_keyframe = 0;
471
22.6k
  sf->svc_use_lowres_part = 0;
472
22.6k
  sf->overshoot_detection_cbr_rt = NO_DETECTION;
473
22.6k
  sf->disable_16x16part_nonkey = 0;
474
22.6k
  sf->disable_golden_ref = 0;
475
22.6k
  sf->enable_tpl_model = 0;
476
22.6k
  sf->enhanced_full_pixel_motion_search = 0;
477
22.6k
  sf->use_accurate_subpel_search = USE_2_TAPS;
478
22.6k
  sf->nonrd_use_ml_partition = 0;
479
22.6k
  sf->variance_part_thresh_mult = 1;
480
22.6k
  sf->cb_pred_filter_search = 0;
481
22.6k
  sf->force_smooth_interpol = 0;
482
22.6k
  sf->rt_intra_dc_only_low_content = 0;
483
22.6k
  sf->mv.enable_adaptive_subpel_force_stop = 0;
484
485
22.6k
  if (speed >= 1) {
486
22.6k
    sf->allow_txfm_domain_distortion = 1;
487
22.6k
    sf->tx_domain_thresh = 0.0;
488
22.6k
    sf->trellis_opt_tx_rd.method = DISABLE_TRELLIS_OPT;
489
22.6k
    sf->trellis_opt_tx_rd.thresh = 0.0;
490
22.6k
    sf->use_square_partition_only = !frame_is_intra_only(cm);
491
22.6k
    sf->less_rectangular_check = 1;
492
22.6k
    sf->tx_size_search_method =
493
22.6k
        frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL;
494
495
22.6k
    sf->use_rd_breakout = 1;
496
497
22.6k
    sf->adaptive_motion_search = 1;
498
22.6k
    sf->adaptive_pred_interp_filter = 1;
499
22.6k
    sf->mv.auto_mv_step_size = 1;
500
22.6k
    sf->adaptive_rd_thresh = 2;
501
22.6k
    sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
502
22.6k
    sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
503
22.6k
    sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
504
22.6k
  }
505
506
22.6k
  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
22.6k
  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
22.6k
  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
22.6k
  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
22.6k
  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
22.6k
  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
22.6k
  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
22.6k
  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
22.6k
  if (cm->frame_type != KEY_FRAME && cm->width * cm->height <= 320 * 240 &&
820
22.6k
      sf->partition_search_type == VAR_BASED_PARTITION &&
821
22.6k
      cpi->rc.avg_frame_qindex[INTER_FRAME] > 208 &&
822
22.6k
      cpi->common.current_video_frame > 8)
823
0
    sf->disable_16x16part_nonkey = 1;
824
825
22.6k
  if (sf->nonrd_use_ml_partition)
826
0
    sf->partition_search_type = ML_BASED_PARTITION;
827
828
22.6k
  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
22.6k
  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
22.6k
  if (cpi->oxcf.content == VP9E_CONTENT_SCREEN && cpi->oxcf.speed >= 5 &&
852
22.6k
      (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
22.6k
  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
22.6k
  if (cpi->oxcf.mode != cpi->deadline_mode_previous_frame)
866
0
    sf->nonrd_keyframe = 1;
867
22.6k
}
868
869
45.2k
void vp9_set_speed_features_framesize_dependent(VP9_COMP *cpi, int speed) {
870
45.2k
  SPEED_FEATURES *const sf = &cpi->sf;
871
45.2k
  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
872
45.2k
  RD_OPT *const rd = &cpi->rd;
873
45.2k
  int i;
874
875
  // best quality defaults
876
  // Some speed-up features even for best quality as minimal impact on quality.
877
45.2k
  sf->partition_search_breakout_thr.dist = (1 << 19);
878
45.2k
  sf->partition_search_breakout_thr.rate = 80;
879
45.2k
  sf->rd_ml_partition.search_early_termination = 0;
880
45.2k
  sf->rd_ml_partition.search_breakout = 0;
881
882
45.2k
  if (oxcf->mode == REALTIME)
883
22.6k
    set_rt_speed_feature_framesize_dependent(cpi, sf, speed);
884
22.6k
#if !CONFIG_REALTIME_ONLY
885
22.6k
  else if (oxcf->mode == GOOD)
886
22.6k
    set_good_speed_feature_framesize_dependent(cpi, sf, speed);
887
45.2k
#endif
888
889
45.2k
  if (sf->disable_split_mask == DISABLE_ALL_SPLIT) {
890
0
    sf->adaptive_pred_interp_filter = 0;
891
0
  }
892
893
45.2k
  if (cpi->encode_breakout && oxcf->mode == REALTIME &&
894
45.2k
      sf->encode_breakout_thresh > cpi->encode_breakout) {
895
0
    cpi->encode_breakout = sf->encode_breakout_thresh;
896
0
  }
897
898
  // Check for masked out split cases.
899
316k
  for (i = 0; i < MAX_REFS; ++i) {
900
271k
    if (sf->disable_split_mask & (1 << i)) {
901
84.5k
      rd->thresh_mult_sub8x8[i] = INT_MAX;
902
84.5k
    }
903
271k
  }
904
905
  // With row based multi-threading, the following speed features
906
  // have to be disabled to guarantee that bitstreams encoded with single thread
907
  // and multiple threads match.
908
  // It can be used in realtime when adaptive_rd_thresh_row_mt is enabled since
909
  // adaptive_rd_thresh is defined per-row for non-rd pickmode.
910
45.2k
  if (!sf->adaptive_rd_thresh_row_mt && cpi->row_mt_bit_exact &&
911
45.2k
      oxcf->max_threads > 1)
912
0
    sf->adaptive_rd_thresh = 0;
913
45.2k
}
914
915
45.2k
void vp9_set_speed_features_framesize_independent(VP9_COMP *cpi, int speed) {
916
45.2k
  SPEED_FEATURES *const sf = &cpi->sf;
917
45.2k
#if !CONFIG_REALTIME_ONLY
918
45.2k
  VP9_COMMON *const cm = &cpi->common;
919
45.2k
#endif
920
45.2k
  MACROBLOCK *const x = &cpi->td.mb;
921
45.2k
  const VP9EncoderConfig *const oxcf = &cpi->oxcf;
922
45.2k
  int i;
923
924
  // best quality defaults
925
45.2k
  sf->frame_parameter_update = 1;
926
45.2k
  sf->mv.search_method = NSTEP;
927
45.2k
  sf->recode_loop = ALLOW_RECODE_FIRST;
928
45.2k
  sf->mv.subpel_search_method = SUBPEL_TREE;
929
45.2k
  sf->mv.subpel_search_level = 2;
930
45.2k
  sf->mv.subpel_force_stop = EIGHTH_PEL;
931
45.2k
  sf->optimize_coefficients = !is_lossless_requested(&cpi->oxcf);
932
45.2k
  sf->mv.reduce_first_step_size = 0;
933
45.2k
  sf->coeff_prob_appx_step = 1;
934
45.2k
  sf->mv.auto_mv_step_size = 0;
935
45.2k
  sf->mv.fullpel_search_step_param = 6;
936
45.2k
  sf->mv.use_downsampled_sad = 0;
937
45.2k
  sf->comp_inter_joint_search_iter_level = 0;
938
45.2k
  sf->tx_size_search_method = USE_FULL_RD;
939
45.2k
  sf->use_lp32x32fdct = 0;
940
45.2k
  sf->adaptive_motion_search = 0;
941
45.2k
  sf->enhanced_full_pixel_motion_search = 1;
942
45.2k
  sf->adaptive_pred_interp_filter = 0;
943
45.2k
  sf->adaptive_mode_search = 0;
944
45.2k
  sf->prune_single_mode_based_on_mv_diff_mode_rate = 0;
945
45.2k
  sf->cb_pred_filter_search = 0;
946
45.2k
  sf->early_term_interp_search_plane_rd = 0;
947
45.2k
  sf->cb_partition_search = 0;
948
45.2k
  sf->motion_field_mode_search = 0;
949
45.2k
  sf->alt_ref_search_fp = 0;
950
45.2k
  sf->use_quant_fp = 0;
951
45.2k
  sf->reference_masking = 0;
952
45.2k
  sf->partition_search_type = SEARCH_PARTITION;
953
45.2k
  sf->less_rectangular_check = 0;
954
45.2k
  sf->use_square_partition_only = 0;
955
45.2k
  sf->use_square_only_thresh_high = BLOCK_SIZES;
956
45.2k
  sf->use_square_only_thresh_low = BLOCK_4X4;
957
45.2k
  sf->auto_min_max_partition_size = NOT_IN_USE;
958
45.2k
  sf->rd_auto_partition_min_limit = BLOCK_4X4;
959
45.2k
  sf->default_max_partition_size = BLOCK_64X64;
960
45.2k
  sf->default_min_partition_size = BLOCK_4X4;
961
45.2k
  sf->adjust_partitioning_from_last_frame = 0;
962
45.2k
  sf->last_partitioning_redo_frequency = 4;
963
45.2k
  sf->disable_split_mask = 0;
964
45.2k
  sf->mode_search_skip_flags = 0;
965
45.2k
  sf->force_frame_boost = 0;
966
45.2k
  sf->max_delta_qindex = 0;
967
45.2k
  sf->disable_filter_search_var_thresh = 0;
968
45.2k
  sf->adaptive_interp_filter_search = 0;
969
45.2k
  sf->allow_txfm_domain_distortion = 0;
970
45.2k
  sf->tx_domain_thresh = 99.0;
971
45.2k
  sf->trellis_opt_tx_rd.method =
972
45.2k
      sf->optimize_coefficients ? ENABLE_TRELLIS_OPT : DISABLE_TRELLIS_OPT;
973
45.2k
  sf->trellis_opt_tx_rd.thresh = 99.0;
974
45.2k
  sf->allow_acl = 1;
975
45.2k
  sf->enable_tpl_model = oxcf->enable_tpl_model;
976
45.2k
  sf->prune_ref_frame_for_rect_partitions = 0;
977
45.2k
  sf->temporal_filter_search_method = MESH;
978
45.2k
  sf->allow_skip_txfm_ac_dc = 0;
979
980
226k
  for (i = 0; i < TX_SIZES; i++) {
981
181k
    sf->intra_y_mode_mask[i] = INTRA_ALL;
982
181k
    sf->intra_uv_mode_mask[i] = INTRA_ALL;
983
181k
  }
984
45.2k
  sf->use_rd_breakout = 0;
985
45.2k
  sf->skip_encode_sb = 0;
986
45.2k
  sf->use_uv_intra_rd_estimate = 0;
987
45.2k
  sf->allow_skip_recode = 0;
988
45.2k
  sf->lpf_pick = LPF_PICK_FROM_FULL_IMAGE;
989
45.2k
  sf->use_fast_coef_updates = TWO_LOOP;
990
45.2k
  sf->use_fast_coef_costing = 0;
991
45.2k
  sf->mode_skip_start = MAX_MODES;  // Mode index at which mode skip mask set
992
45.2k
  sf->schedule_mode_search = 0;
993
45.2k
  sf->use_nonrd_pick_mode = 0;
994
633k
  for (i = 0; i < BLOCK_SIZES; ++i) sf->inter_mode_mask[i] = INTER_ALL;
995
45.2k
  sf->max_intra_bsize = BLOCK_64X64;
996
45.2k
  sf->reuse_inter_pred_sby = 0;
997
  // This setting only takes effect when partition_search_type is set
998
  // to FIXED_PARTITION.
999
45.2k
  sf->always_this_block_size = BLOCK_16X16;
1000
45.2k
  sf->search_type_check_frequency = 50;
1001
45.2k
  sf->encode_breakout_thresh = 0;
1002
  // Recode loop tolerance %.
1003
45.2k
  sf->recode_tolerance_low = 12;
1004
45.2k
  sf->recode_tolerance_high = 25;
1005
45.2k
  sf->default_interp_filter = SWITCHABLE;
1006
45.2k
  sf->simple_model_rd_from_var = 0;
1007
45.2k
  sf->short_circuit_flat_blocks = 0;
1008
45.2k
  sf->short_circuit_low_temp_var = 0;
1009
45.2k
  sf->limit_newmv_early_exit = 0;
1010
45.2k
  sf->bias_golden = 0;
1011
45.2k
  sf->base_mv_aggressive = 0;
1012
45.2k
  sf->rd_ml_partition.prune_rect_thresh[0] = -1;
1013
45.2k
  sf->rd_ml_partition.prune_rect_thresh[1] = -1;
1014
45.2k
  sf->rd_ml_partition.prune_rect_thresh[2] = -1;
1015
45.2k
  sf->rd_ml_partition.prune_rect_thresh[3] = -1;
1016
45.2k
  sf->rd_ml_partition.var_pruning = 0;
1017
45.2k
  sf->use_accurate_subpel_search = USE_8_TAPS;
1018
1019
  // Some speed-up features even for best quality as minimal impact on quality.
1020
45.2k
  sf->adaptive_rd_thresh = 1;
1021
45.2k
  sf->tx_size_search_breakout = 1;
1022
45.2k
  sf->tx_size_search_depth = 2;
1023
1024
45.2k
  sf->exhaustive_searches_thresh =
1025
45.2k
      (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ? (1 << 20)
1026
45.2k
                                                              : INT_MAX;
1027
45.2k
  {
1028
45.2k
    const int mesh_density_level =
1029
45.2k
        (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ? 0 : 1;
1030
226k
    for (i = 0; i < MAX_MESH_STEP; ++i) {
1031
181k
      sf->mesh_patterns[i].range =
1032
181k
          best_quality_mesh_pattern[mesh_density_level][i].range;
1033
181k
      sf->mesh_patterns[i].interval =
1034
181k
          best_quality_mesh_pattern[mesh_density_level][i].interval;
1035
181k
    }
1036
45.2k
  }
1037
1038
45.2k
  if (oxcf->mode == REALTIME)
1039
22.6k
    set_rt_speed_feature_framesize_independent(cpi, sf, speed, oxcf->content);
1040
22.6k
#if !CONFIG_REALTIME_ONLY
1041
22.6k
  else if (oxcf->mode == GOOD)
1042
22.6k
    set_good_speed_feature_framesize_independent(cpi, cm, sf, speed);
1043
45.2k
#endif
1044
1045
45.2k
  cpi->diamond_search_sad = vp9_diamond_search_sad;
1046
1047
  // Slow quant, dct and trellis not worthwhile for first pass
1048
  // so make sure they are always turned off.
1049
45.2k
  if (oxcf->pass == 1) sf->optimize_coefficients = 0;
1050
1051
  // No recode for 1 pass.
1052
45.2k
  if (oxcf->pass == 0) {
1053
45.2k
    sf->recode_loop = DISALLOW_RECODE;
1054
45.2k
    sf->optimize_coefficients = 0;
1055
45.2k
  }
1056
1057
45.2k
  if (sf->mv.subpel_force_stop == FULL_PEL) {
1058
    // Whole pel only
1059
0
    cpi->find_fractional_mv_step = vp9_skip_sub_pixel_tree;
1060
45.2k
  } else if (sf->mv.subpel_search_method == SUBPEL_TREE) {
1061
45.2k
    cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree;
1062
45.2k
  } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED) {
1063
0
    cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned;
1064
0
  } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_MORE) {
1065
0
    cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_more;
1066
0
  } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_EVENMORE) {
1067
0
    cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_evenmore;
1068
0
  }
1069
1070
  // This is only used in motion vector unit test.
1071
45.2k
  if (cpi->oxcf.motion_vector_unit_test == 1)
1072
0
    cpi->find_fractional_mv_step = vp9_return_max_sub_pixel_mv;
1073
45.2k
  else if (cpi->oxcf.motion_vector_unit_test == 2)
1074
0
    cpi->find_fractional_mv_step = vp9_return_min_sub_pixel_mv;
1075
1076
45.2k
  x->optimize = sf->optimize_coefficients == 1 && oxcf->pass != 1;
1077
1078
45.2k
  x->min_partition_size = sf->default_min_partition_size;
1079
45.2k
  x->max_partition_size = sf->default_max_partition_size;
1080
1081
45.2k
  if (!cpi->oxcf.frame_periodic_boost) {
1082
45.2k
    sf->max_delta_qindex = 0;
1083
45.2k
  }
1084
1085
  // With row based multi-threading, the following speed features
1086
  // have to be disabled to guarantee that bitstreams encoded with single thread
1087
  // and multiple threads match.
1088
  // It can be used in realtime when adaptive_rd_thresh_row_mt is enabled since
1089
  // adaptive_rd_thresh is defined per-row for non-rd pickmode.
1090
45.2k
  if (!sf->adaptive_rd_thresh_row_mt && cpi->row_mt_bit_exact &&
1091
45.2k
      oxcf->max_threads > 1)
1092
0
    sf->adaptive_rd_thresh = 0;
1093
45.2k
}