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
349 if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) {
350 for (i = 0; i < MAX_MESH_STEP; ++i) {
351 int mesh_density_level = 2;
352 sf->mesh_patterns[i].range =
353 good_quality_mesh_patterns[mesh_density_level][i].range;
354 sf->mesh_patterns[i].interval =
355 good_quality_mesh_patterns[mesh_density_level][i].interval;
356 }
357 }
358 }
359
360 if (speed >= 4) {
361 sf->use_square_partition_only = 1;
362 sf->tx_size_search_method = USE_LARGESTALL;
363 sf->mv.search_method = BIGDIA;
364 sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
365 sf->adaptive_rd_thresh = 4;
366 if (cm->frame_type != KEY_FRAME)
367 sf->mode_search_skip_flags |= FLAG_EARLY_TERMINATE;
368 sf->disable_filter_search_var_thresh = 200;
369 sf->use_lp32x32fdct = 1;
370 sf->use_fast_coef_updates = ONE_LOOP_REDUCED;
371 sf->use_fast_coef_costing = 1;
372 sf->motion_field_mode_search = !boosted;
373 }
374
375 if (speed >= 5) {
376 int i;
377 sf->optimize_coefficients = 0;
378 sf->mv.search_method = HEX;
379 sf->disable_filter_search_var_thresh = 500;
380 for (i = 0; i < TX_SIZES; ++i) {
381 sf->intra_y_mode_mask[i] = INTRA_DC;
382 sf->intra_uv_mode_mask[i] = INTRA_DC;
383 }
384 sf->mv.reduce_first_step_size = 1;
385 sf->simple_model_rd_from_var = 1;
386 }
387 }
388 #endif // !CONFIG_REALTIME_ONLY
389
set_rt_speed_feature_framesize_dependent(VP9_COMP * cpi,SPEED_FEATURES * sf,int speed)390 static void set_rt_speed_feature_framesize_dependent(VP9_COMP *cpi,
391 SPEED_FEATURES *sf,
392 int speed) {
393 VP9_COMMON *const cm = &cpi->common;
394
395 if (speed >= 1) {
396 if (VPXMIN(cm->width, cm->height) >= 720) {
397 sf->disable_split_mask =
398 cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
399 } else {
400 sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
401 }
402 }
403
404 if (speed >= 2) {
405 if (VPXMIN(cm->width, cm->height) >= 720) {
406 sf->disable_split_mask =
407 cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
408 } else {
409 sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY;
410 }
411 }
412
413 if (speed >= 5) {
414 sf->partition_search_breakout_thr.rate = 200;
415 if (VPXMIN(cm->width, cm->height) >= 720) {
416 sf->partition_search_breakout_thr.dist = (1 << 25);
417 } else {
418 sf->partition_search_breakout_thr.dist = (1 << 23);
419 }
420 }
421
422 if (speed >= 7) {
423 sf->encode_breakout_thresh =
424 (VPXMIN(cm->width, cm->height) >= 720) ? 800 : 300;
425 }
426 }
427
set_rt_speed_feature_framesize_independent(VP9_COMP * cpi,SPEED_FEATURES * sf,int speed,vp9e_tune_content content)428 static void set_rt_speed_feature_framesize_independent(
429 VP9_COMP *cpi, SPEED_FEATURES *sf, int speed, vp9e_tune_content content) {
430 VP9_COMMON *const cm = &cpi->common;
431 SVC *const svc = &cpi->svc;
432 const int is_keyframe = cm->frame_type == KEY_FRAME;
433 const int frames_since_key = is_keyframe ? 0 : cpi->rc.frames_since_key;
434 sf->static_segmentation = 0;
435 sf->adaptive_rd_thresh = 1;
436 sf->adaptive_rd_thresh_row_mt = 0;
437 sf->use_fast_coef_costing = 1;
438 sf->exhaustive_searches_thresh = INT_MAX;
439 sf->allow_acl = 0;
440 sf->copy_partition_flag = 0;
441 sf->use_source_sad = 0;
442 sf->use_simple_block_yrd = 0;
443 sf->adapt_partition_source_sad = 0;
444 sf->use_altref_onepass = 0;
445 sf->use_compound_nonrd_pickmode = 0;
446 sf->nonrd_keyframe = 0;
447 sf->svc_use_lowres_part = 0;
448 sf->overshoot_detection_cbr_rt = NO_DETECTION;
449 sf->disable_16x16part_nonkey = 0;
450 sf->disable_golden_ref = 0;
451 sf->enable_tpl_model = 0;
452 sf->enhanced_full_pixel_motion_search = 0;
453 sf->use_accurate_subpel_search = USE_2_TAPS;
454 sf->nonrd_use_ml_partition = 0;
455 sf->variance_part_thresh_mult = 1;
456 sf->cb_pred_filter_search = 0;
457 sf->force_smooth_interpol = 0;
458 sf->rt_intra_dc_only_low_content = 0;
459 sf->mv.enable_adaptive_subpel_force_stop = 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 && !cpi->rc.disable_overshoot_maxq_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 if (!cpi->external_resize) sf->use_source_sad = 1;
637 }
638
639 if (speed >= 6) {
640 if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0) {
641 sf->use_altref_onepass = 1;
642 sf->use_compound_nonrd_pickmode = 1;
643 }
644 sf->partition_search_type = VAR_BASED_PARTITION;
645 sf->mv.search_method = NSTEP;
646 sf->mv.reduce_first_step_size = 1;
647 sf->skip_encode_sb = 0;
648
649 if (sf->use_source_sad) {
650 sf->adapt_partition_source_sad = 1;
651 sf->adapt_partition_thresh =
652 (cm->width * cm->height <= 640 * 360) ? 40000 : 60000;
653 if (cpi->content_state_sb_fd == NULL &&
654 (!cpi->use_svc ||
655 svc->spatial_layer_id == svc->number_spatial_layers - 1)) {
656 cpi->content_state_sb_fd = (uint8_t *)vpx_calloc(
657 (cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1), sizeof(uint8_t));
658 }
659 }
660 if (cpi->oxcf.rc_mode == VPX_CBR && content != VP9E_CONTENT_SCREEN) {
661 // Enable short circuit for low temporal variance.
662 sf->short_circuit_low_temp_var = 1;
663 }
664 if (svc->temporal_layer_id > 0) {
665 sf->adaptive_rd_thresh = 4;
666 sf->limit_newmv_early_exit = 0;
667 sf->base_mv_aggressive = 1;
668 }
669 if (cm->frame_type != KEY_FRAME && cpi->resize_state == ORIG &&
670 cpi->oxcf.rc_mode == VPX_CBR && !cpi->rc.disable_overshoot_maxq_cbr)
671 sf->overshoot_detection_cbr_rt = FAST_DETECTION_MAXQ;
672 }
673
674 if (speed >= 7) {
675 sf->adapt_partition_source_sad = 0;
676 sf->adaptive_rd_thresh = 3;
677 sf->mv.search_method = FAST_DIAMOND;
678 sf->mv.fullpel_search_step_param = 10;
679 // For SVC: use better mv search on base temporal layer, and only
680 // on base spatial layer if highest resolution is above 640x360.
681 if (svc->number_temporal_layers > 2 && svc->temporal_layer_id == 0 &&
682 (svc->spatial_layer_id == 0 ||
683 cpi->oxcf.width * cpi->oxcf.height <= 640 * 360)) {
684 sf->mv.search_method = NSTEP;
685 sf->mv.fullpel_search_step_param = 6;
686 }
687 if (svc->temporal_layer_id > 0 || svc->spatial_layer_id > 1) {
688 sf->use_simple_block_yrd = 1;
689 if (svc->non_reference_frame)
690 sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED_EVENMORE;
691 }
692 if (cpi->use_svc && cpi->row_mt && cpi->oxcf.max_threads > 1)
693 sf->adaptive_rd_thresh_row_mt = 1;
694 // Enable partition copy. For SVC only enabled for top spatial resolution
695 // layer.
696 cpi->max_copied_frame = 0;
697 if (!cpi->last_frame_dropped && cpi->resize_state == ORIG &&
698 !cpi->external_resize &&
699 (!cpi->use_svc ||
700 (svc->spatial_layer_id == svc->number_spatial_layers - 1 &&
701 !svc->last_layer_dropped[svc->number_spatial_layers - 1]))) {
702 sf->copy_partition_flag = 1;
703 cpi->max_copied_frame = 2;
704 // The top temporal enhancement layer (for number of temporal layers > 1)
705 // are non-reference frames, so use large/max value for max_copied_frame.
706 if (svc->number_temporal_layers > 1 &&
707 svc->temporal_layer_id == svc->number_temporal_layers - 1)
708 cpi->max_copied_frame = 255;
709 }
710 // For SVC: enable use of lower resolution partition for higher resolution,
711 // only for 3 spatial layers and when config/top resolution is above VGA.
712 // Enable only for non-base temporal layer frames.
713 if (cpi->use_svc && svc->use_partition_reuse &&
714 svc->number_spatial_layers == 3 && svc->temporal_layer_id > 0 &&
715 cpi->oxcf.width * cpi->oxcf.height > 640 * 480)
716 sf->svc_use_lowres_part = 1;
717 // For SVC when golden is used as second temporal reference: to avoid
718 // encode time increase only use this feature on base temporal layer.
719 // (i.e remove golden flag from frame_flags for temporal_layer_id > 0).
720 if (cpi->use_svc && svc->use_gf_temporal_ref_current_layer &&
721 svc->temporal_layer_id > 0)
722 cpi->ref_frame_flags &= (~VP9_GOLD_FLAG);
723 if (cm->width * cm->height > 640 * 480) sf->cb_pred_filter_search = 1;
724 }
725
726 if (speed >= 8) {
727 sf->adaptive_rd_thresh = 4;
728 sf->skip_encode_sb = 1;
729 if (cpi->svc.number_spatial_layers > 1 && !cpi->svc.simulcast_mode)
730 sf->nonrd_keyframe = 0;
731 else
732 sf->nonrd_keyframe = 1;
733 if (!cpi->use_svc) cpi->max_copied_frame = 4;
734 if (cpi->row_mt && cpi->oxcf.max_threads > 1)
735 sf->adaptive_rd_thresh_row_mt = 1;
736 // Enable ML based partition for low res.
737 if (!frame_is_intra_only(cm) && cm->width * cm->height <= 352 * 288) {
738 sf->nonrd_use_ml_partition = 1;
739 }
740 #if CONFIG_VP9_HIGHBITDEPTH
741 if (cpi->Source->flags & YV12_FLAG_HIGHBITDEPTH)
742 sf->nonrd_use_ml_partition = 0;
743 #endif
744 if (content == VP9E_CONTENT_SCREEN) sf->mv.subpel_force_stop = HALF_PEL;
745 sf->rt_intra_dc_only_low_content = 1;
746 if (!cpi->use_svc && cpi->oxcf.rc_mode == VPX_CBR &&
747 content != VP9E_CONTENT_SCREEN) {
748 // More aggressive short circuit for speed 8.
749 sf->short_circuit_low_temp_var = 3;
750 // Use level 2 for noisey cases as there is a regression in some
751 // noisy clips with level 3.
752 if (cpi->noise_estimate.enabled && cm->width >= 1280 &&
753 cm->height >= 720) {
754 NOISE_LEVEL noise_level =
755 vp9_noise_estimate_extract_level(&cpi->noise_estimate);
756 if (noise_level >= kMedium) sf->short_circuit_low_temp_var = 2;
757 }
758 // Since the short_circuit_low_temp_var is used, reduce the
759 // adaptive_rd_thresh level.
760 if (cm->width * cm->height > 352 * 288)
761 sf->adaptive_rd_thresh = 1;
762 else
763 sf->adaptive_rd_thresh = 2;
764 }
765 sf->limit_newmv_early_exit = 0;
766 sf->use_simple_block_yrd = 1;
767 if (cm->width * cm->height > 352 * 288) sf->cb_pred_filter_search = 1;
768 }
769
770 if (speed >= 9) {
771 // Only keep INTRA_DC mode for speed 9.
772 if (!is_keyframe) {
773 int i = 0;
774 for (i = 0; i < BLOCK_SIZES; ++i)
775 sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
776 }
777 sf->cb_pred_filter_search = 1;
778 sf->mv.enable_adaptive_subpel_force_stop = 1;
779 sf->mv.adapt_subpel_force_stop.mv_thresh = 1;
780 sf->mv.adapt_subpel_force_stop.force_stop_below = QUARTER_PEL;
781 sf->mv.adapt_subpel_force_stop.force_stop_above = HALF_PEL;
782 // Disable partition blocks below 16x16, except for low-resolutions.
783 if (cm->frame_type != KEY_FRAME && cm->width >= 320 && cm->height >= 240)
784 sf->disable_16x16part_nonkey = 1;
785 // Allow for disabling GOLDEN reference, for CBR mode.
786 if (cpi->oxcf.rc_mode == VPX_CBR) sf->disable_golden_ref = 1;
787 if (cpi->rc.avg_frame_low_motion < 70) sf->default_interp_filter = BILINEAR;
788 if (cm->width * cm->height >= 640 * 360) sf->variance_part_thresh_mult = 2;
789 }
790
791 // Disable split to 8x8 for low-resolution at very high Q.
792 // For variance partition (speed >= 6). Ignore the first few frames
793 // as avg_frame_qindex starts at max_q (worst_quality).
794 if (cm->frame_type != KEY_FRAME && cm->width * cm->height <= 320 * 240 &&
795 sf->partition_search_type == VAR_BASED_PARTITION &&
796 cpi->rc.avg_frame_qindex[INTER_FRAME] > 208 &&
797 cpi->common.current_video_frame > 8)
798 sf->disable_16x16part_nonkey = 1;
799
800 if (sf->nonrd_use_ml_partition)
801 sf->partition_search_type = ML_BASED_PARTITION;
802
803 if (sf->use_altref_onepass) {
804 if (cpi->rc.is_src_frame_alt_ref && cm->frame_type != KEY_FRAME) {
805 sf->partition_search_type = FIXED_PARTITION;
806 sf->always_this_block_size = BLOCK_64X64;
807 }
808 if (cpi->count_arf_frame_usage == NULL)
809 cpi->count_arf_frame_usage =
810 (uint8_t *)vpx_calloc((cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1),
811 sizeof(*cpi->count_arf_frame_usage));
812 if (cpi->count_lastgolden_frame_usage == NULL)
813 cpi->count_lastgolden_frame_usage =
814 (uint8_t *)vpx_calloc((cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1),
815 sizeof(*cpi->count_lastgolden_frame_usage));
816 }
817 if (svc->previous_frame_is_intra_only) {
818 sf->partition_search_type = FIXED_PARTITION;
819 sf->always_this_block_size = BLOCK_64X64;
820 }
821 // Special case for screen content: increase motion search on base spatial
822 // layer when high motion is detected or previous SL0 frame was dropped.
823 if (cpi->oxcf.content == VP9E_CONTENT_SCREEN && cpi->oxcf.speed >= 5 &&
824 (svc->high_num_blocks_with_motion || svc->last_layer_dropped[0])) {
825 sf->mv.search_method = NSTEP;
826 // TODO(marpan/jianj): Tune this setting for screensharing. For now use
827 // small step_param for all spatial layers.
828 sf->mv.fullpel_search_step_param = 2;
829 }
830 // TODO(marpan): There is regression for aq-mode=3 speed <= 4, force it
831 // off for now.
832 if (speed <= 3 && cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
833 cpi->oxcf.aq_mode = 0;
834 }
835
vp9_set_speed_features_framesize_dependent(VP9_COMP * cpi,int speed)836 void vp9_set_speed_features_framesize_dependent(VP9_COMP *cpi, int speed) {
837 SPEED_FEATURES *const sf = &cpi->sf;
838 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
839 RD_OPT *const rd = &cpi->rd;
840 int i;
841
842 // best quality defaults
843 // Some speed-up features even for best quality as minimal impact on quality.
844 sf->partition_search_breakout_thr.dist = (1 << 19);
845 sf->partition_search_breakout_thr.rate = 80;
846 sf->rd_ml_partition.search_early_termination = 0;
847 sf->rd_ml_partition.search_breakout = 0;
848
849 if (oxcf->mode == REALTIME)
850 set_rt_speed_feature_framesize_dependent(cpi, sf, speed);
851 #if !CONFIG_REALTIME_ONLY
852 else if (oxcf->mode == GOOD)
853 set_good_speed_feature_framesize_dependent(cpi, sf, speed);
854 #endif
855
856 if (sf->disable_split_mask == DISABLE_ALL_SPLIT) {
857 sf->adaptive_pred_interp_filter = 0;
858 }
859
860 if (cpi->encode_breakout && oxcf->mode == REALTIME &&
861 sf->encode_breakout_thresh > cpi->encode_breakout) {
862 cpi->encode_breakout = sf->encode_breakout_thresh;
863 }
864
865 // Check for masked out split cases.
866 for (i = 0; i < MAX_REFS; ++i) {
867 if (sf->disable_split_mask & (1 << i)) {
868 rd->thresh_mult_sub8x8[i] = INT_MAX;
869 }
870 }
871
872 // With row based multi-threading, the following speed features
873 // have to be disabled to guarantee that bitstreams encoded with single thread
874 // and multiple threads match.
875 // It can be used in realtime when adaptive_rd_thresh_row_mt is enabled since
876 // adaptive_rd_thresh is defined per-row for non-rd pickmode.
877 if (!sf->adaptive_rd_thresh_row_mt && cpi->row_mt_bit_exact &&
878 oxcf->max_threads > 1)
879 sf->adaptive_rd_thresh = 0;
880 }
881
vp9_set_speed_features_framesize_independent(VP9_COMP * cpi,int speed)882 void vp9_set_speed_features_framesize_independent(VP9_COMP *cpi, int speed) {
883 SPEED_FEATURES *const sf = &cpi->sf;
884 #if !CONFIG_REALTIME_ONLY
885 VP9_COMMON *const cm = &cpi->common;
886 #endif
887 MACROBLOCK *const x = &cpi->td.mb;
888 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
889 int i;
890
891 // best quality defaults
892 sf->frame_parameter_update = 1;
893 sf->mv.search_method = NSTEP;
894 sf->recode_loop = ALLOW_RECODE_FIRST;
895 sf->mv.subpel_search_method = SUBPEL_TREE;
896 sf->mv.subpel_search_level = 2;
897 sf->mv.subpel_force_stop = EIGHTH_PEL;
898 sf->optimize_coefficients = !is_lossless_requested(&cpi->oxcf);
899 sf->mv.reduce_first_step_size = 0;
900 sf->coeff_prob_appx_step = 1;
901 sf->mv.auto_mv_step_size = 0;
902 sf->mv.fullpel_search_step_param = 6;
903 sf->comp_inter_joint_search_thresh = BLOCK_4X4;
904 sf->tx_size_search_method = USE_FULL_RD;
905 sf->use_lp32x32fdct = 0;
906 sf->adaptive_motion_search = 0;
907 sf->enhanced_full_pixel_motion_search = 1;
908 sf->adaptive_pred_interp_filter = 0;
909 sf->adaptive_mode_search = 0;
910 sf->cb_pred_filter_search = 0;
911 sf->cb_partition_search = 0;
912 sf->motion_field_mode_search = 0;
913 sf->alt_ref_search_fp = 0;
914 sf->use_quant_fp = 0;
915 sf->reference_masking = 0;
916 sf->partition_search_type = SEARCH_PARTITION;
917 sf->less_rectangular_check = 0;
918 sf->use_square_partition_only = 0;
919 sf->use_square_only_thresh_high = BLOCK_SIZES;
920 sf->use_square_only_thresh_low = BLOCK_4X4;
921 sf->auto_min_max_partition_size = NOT_IN_USE;
922 sf->rd_auto_partition_min_limit = BLOCK_4X4;
923 sf->default_max_partition_size = BLOCK_64X64;
924 sf->default_min_partition_size = BLOCK_4X4;
925 sf->adjust_partitioning_from_last_frame = 0;
926 sf->last_partitioning_redo_frequency = 4;
927 sf->disable_split_mask = 0;
928 sf->mode_search_skip_flags = 0;
929 sf->force_frame_boost = 0;
930 sf->max_delta_qindex = 0;
931 sf->disable_filter_search_var_thresh = 0;
932 sf->adaptive_interp_filter_search = 0;
933 sf->allow_txfm_domain_distortion = 0;
934 sf->tx_domain_thresh = 99.0;
935 sf->allow_quant_coeff_opt = sf->optimize_coefficients;
936 sf->quant_opt_thresh = 99.0;
937 sf->allow_acl = 1;
938 sf->enable_tpl_model = oxcf->enable_tpl_model;
939 sf->prune_ref_frame_for_rect_partitions = 0;
940 sf->temporal_filter_search_method = MESH;
941 sf->allow_skip_txfm_ac_dc = 0;
942
943 for (i = 0; i < TX_SIZES; i++) {
944 sf->intra_y_mode_mask[i] = INTRA_ALL;
945 sf->intra_uv_mode_mask[i] = INTRA_ALL;
946 }
947 sf->use_rd_breakout = 0;
948 sf->skip_encode_sb = 0;
949 sf->use_uv_intra_rd_estimate = 0;
950 sf->allow_skip_recode = 0;
951 sf->lpf_pick = LPF_PICK_FROM_FULL_IMAGE;
952 sf->use_fast_coef_updates = TWO_LOOP;
953 sf->use_fast_coef_costing = 0;
954 sf->mode_skip_start = MAX_MODES; // Mode index at which mode skip mask set
955 sf->schedule_mode_search = 0;
956 sf->use_nonrd_pick_mode = 0;
957 for (i = 0; i < BLOCK_SIZES; ++i) sf->inter_mode_mask[i] = INTER_ALL;
958 sf->max_intra_bsize = BLOCK_64X64;
959 sf->reuse_inter_pred_sby = 0;
960 // This setting only takes effect when partition_search_type is set
961 // to FIXED_PARTITION.
962 sf->always_this_block_size = BLOCK_16X16;
963 sf->search_type_check_frequency = 50;
964 sf->encode_breakout_thresh = 0;
965 // Recode loop tolerance %.
966 sf->recode_tolerance_low = 12;
967 sf->recode_tolerance_high = 25;
968 sf->default_interp_filter = SWITCHABLE;
969 sf->simple_model_rd_from_var = 0;
970 sf->short_circuit_flat_blocks = 0;
971 sf->short_circuit_low_temp_var = 0;
972 sf->limit_newmv_early_exit = 0;
973 sf->bias_golden = 0;
974 sf->base_mv_aggressive = 0;
975 sf->rd_ml_partition.prune_rect_thresh[0] = -1;
976 sf->rd_ml_partition.prune_rect_thresh[1] = -1;
977 sf->rd_ml_partition.prune_rect_thresh[2] = -1;
978 sf->rd_ml_partition.prune_rect_thresh[3] = -1;
979 sf->rd_ml_partition.var_pruning = 0;
980 sf->use_accurate_subpel_search = USE_8_TAPS;
981
982 // Some speed-up features even for best quality as minimal impact on quality.
983 sf->adaptive_rd_thresh = 1;
984 sf->tx_size_search_breakout = 1;
985 sf->tx_size_search_depth = 2;
986
987 sf->exhaustive_searches_thresh =
988 (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ? (1 << 20)
989 : INT_MAX;
990 if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) {
991 for (i = 0; i < MAX_MESH_STEP; ++i) {
992 sf->mesh_patterns[i].range = best_quality_mesh_pattern[i].range;
993 sf->mesh_patterns[i].interval = best_quality_mesh_pattern[i].interval;
994 }
995 }
996
997 if (oxcf->mode == REALTIME)
998 set_rt_speed_feature_framesize_independent(cpi, sf, speed, oxcf->content);
999 #if !CONFIG_REALTIME_ONLY
1000 else if (oxcf->mode == GOOD)
1001 set_good_speed_feature_framesize_independent(cpi, cm, sf, speed);
1002 #endif
1003
1004 cpi->diamond_search_sad = vp9_diamond_search_sad;
1005
1006 // Slow quant, dct and trellis not worthwhile for first pass
1007 // so make sure they are always turned off.
1008 if (oxcf->pass == 1) sf->optimize_coefficients = 0;
1009
1010 // No recode for 1 pass.
1011 if (oxcf->pass == 0) {
1012 sf->recode_loop = DISALLOW_RECODE;
1013 sf->optimize_coefficients = 0;
1014 }
1015
1016 if (sf->mv.subpel_force_stop == FULL_PEL) {
1017 // Whole pel only
1018 cpi->find_fractional_mv_step = vp9_skip_sub_pixel_tree;
1019 } else if (sf->mv.subpel_search_method == SUBPEL_TREE) {
1020 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree;
1021 } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED) {
1022 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned;
1023 } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_MORE) {
1024 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_more;
1025 } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_EVENMORE) {
1026 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_evenmore;
1027 }
1028
1029 // This is only used in motion vector unit test.
1030 if (cpi->oxcf.motion_vector_unit_test == 1)
1031 cpi->find_fractional_mv_step = vp9_return_max_sub_pixel_mv;
1032 else if (cpi->oxcf.motion_vector_unit_test == 2)
1033 cpi->find_fractional_mv_step = vp9_return_min_sub_pixel_mv;
1034
1035 x->optimize = sf->optimize_coefficients == 1 && oxcf->pass != 1;
1036
1037 x->min_partition_size = sf->default_min_partition_size;
1038 x->max_partition_size = sf->default_max_partition_size;
1039
1040 if (!cpi->oxcf.frame_periodic_boost) {
1041 sf->max_delta_qindex = 0;
1042 }
1043
1044 // With row based multi-threading, the following speed features
1045 // have to be disabled to guarantee that bitstreams encoded with single thread
1046 // and multiple threads match.
1047 // It can be used in realtime when adaptive_rd_thresh_row_mt is enabled since
1048 // adaptive_rd_thresh is defined per-row for non-rd pickmode.
1049 if (!sf->adaptive_rd_thresh_row_mt && cpi->row_mt_bit_exact &&
1050 oxcf->max_threads > 1)
1051 sf->adaptive_rd_thresh = 0;
1052 }
1053