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