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