Coverage Report

Created: 2026-08-31 06:35

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