2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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.
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"
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 }
23 // Define 3 mesh density levels to control the number of searches.
24 #define MESH_DENSITY_LEVELS 3
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 } },
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
34 static int frame_is_boosted(const VP9_COMP *cpi) {
35 return frame_is_kf_gf_arf(cpi);
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.
44 static BLOCK_SIZE set_partition_min_limit(VP9_COMMON *const cm) {
45 unsigned int screen_area = (cm->width * cm->height);
47 // Select block size based on image format size.
48 if (screen_area < 1280 * 720) {
49 // Formats smaller in area than 720P
51 } else if (screen_area < 1920 * 1080) {
52 // Format >= 720P and < 1080P
55 // Formats 1080P and up
60 static void set_good_speed_feature_framesize_dependent(VP9_COMP *cpi,
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;
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;
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->rd_ml_partition.search_early_termination = 1;
81 sf->use_square_only_thresh_high = BLOCK_32X32;
84 if (!is_1080p_or_larger) {
85 sf->rd_ml_partition.search_breakout = 1;
86 if (is_720p_or_larger) {
87 sf->rd_ml_partition.search_breakout_thresh[0] = 0.0f;
88 sf->rd_ml_partition.search_breakout_thresh[1] = 0.0f;
89 sf->rd_ml_partition.search_breakout_thresh[2] = 0.0f;
91 sf->rd_ml_partition.search_breakout_thresh[0] = 2.5f;
92 sf->rd_ml_partition.search_breakout_thresh[1] = 1.5f;
93 sf->rd_ml_partition.search_breakout_thresh[2] = 1.5f;
98 sf->rd_ml_partition.search_early_termination = 0;
99 sf->rd_ml_partition.search_breakout = 1;
100 if (is_480p_or_larger)
101 sf->use_square_only_thresh_high = BLOCK_64X64;
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->rd_ml_partition.search_breakout_thresh[0] = -5.0f;
110 sf->rd_ml_partition.search_breakout_thresh[1] = -5.0f;
111 sf->rd_ml_partition.search_breakout_thresh[2] = -9.0f;
113 sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
114 sf->partition_search_breakout_thr.dist = (1 << 21);
115 sf->rd_ml_partition.search_breakout_thresh[0] = -1.0f;
116 sf->rd_ml_partition.search_breakout_thresh[1] = -1.0f;
117 sf->rd_ml_partition.search_breakout_thresh[2] = -1.0f;
119 #if CONFIG_VP9_HIGHBITDEPTH
120 if (cpi->Source->flags & YV12_FLAG_HIGHBITDEPTH) {
121 sf->rd_ml_partition.search_breakout_thresh[0] -= 1.0f;
122 sf->rd_ml_partition.search_breakout_thresh[1] -= 1.0f;
123 sf->rd_ml_partition.search_breakout_thresh[2] -= 1.0f;
125 #endif // CONFIG_VP9_HIGHBITDEPTH
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->rd_ml_partition.search_breakout = 0;
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->rd_ml_partition.search_breakout_thresh[0] = 0.0f;
143 sf->rd_ml_partition.search_breakout_thresh[1] = -1.0f;
144 sf->rd_ml_partition.search_breakout_thresh[2] = -4.0f;
146 sf->rd_auto_partition_min_limit = set_partition_min_limit(cm);
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;
161 sf->rd_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;
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;
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;
186 sf->partition_search_breakout_thr.rate = 300;
187 if (is_720p_or_larger) {
188 sf->partition_search_breakout_thr.dist = (1 << 26);
190 sf->partition_search_breakout_thr.dist = (1 << 24);
192 sf->disable_split_mask = DISABLE_ALL_SPLIT;
196 sf->partition_search_breakout_thr.rate = 500;
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 };
203 static void set_good_speed_feature_framesize_independent(VP9_COMP *cpi,
207 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
208 const int boosted = frame_is_boosted(cpi);
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->rd_ml_partition.var_pruning = 1;
220 sf->rd_ml_partition.prune_rect_thresh[0] = -1;
221 sf->rd_ml_partition.prune_rect_thresh[1] = 350;
222 sf->rd_ml_partition.prune_rect_thresh[2] = 325;
223 sf->rd_ml_partition.prune_rect_thresh[3] = 250;
225 if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) {
226 sf->exhaustive_searches_thresh = (1 << 22);
228 sf->exhaustive_searches_thresh = INT_MAX;
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;
240 sf->temporal_filter_search_method = NSTEP;
241 sf->rd_ml_partition.var_pruning = !boosted;
242 sf->rd_ml_partition.prune_rect_thresh[1] = 225;
243 sf->rd_ml_partition.prune_rect_thresh[2] = 225;
244 sf->rd_ml_partition.prune_rect_thresh[3] = 225;
246 if (oxcf->pass == 2) {
247 TWO_PASS *const twopass = &cpi->twopass;
248 if ((twopass->fr_content_type == FC_GRAPHICS_ANIMATION) ||
249 vp9_internal_image_edge(cpi)) {
250 sf->use_square_partition_only = !boosted;
252 sf->use_square_partition_only = !frame_is_intra_only(cm);
255 sf->use_square_partition_only = !frame_is_intra_only(cm);
258 sf->allow_txfm_domain_distortion = 1;
259 sf->tx_domain_thresh = tx_dom_thresholds[(speed < 6) ? speed : 5];
260 sf->allow_quant_coeff_opt = sf->optimize_coefficients;
261 sf->quant_opt_thresh = qopt_thresholds[(speed < 6) ? speed : 5];
262 sf->less_rectangular_check = 1;
263 sf->use_rd_breakout = 1;
264 sf->adaptive_motion_search = 1;
265 sf->mv.auto_mv_step_size = 1;
266 sf->adaptive_rd_thresh = 2;
267 sf->mv.subpel_search_level = 1;
268 if (cpi->oxcf.content != VP9E_CONTENT_FILM) sf->mode_skip_start = 10;
269 sf->adaptive_pred_interp_filter = 1;
272 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
273 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
274 if (cpi->oxcf.content != VP9E_CONTENT_FILM) {
275 sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
276 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
279 sf->recode_tolerance_low = 15;
280 sf->recode_tolerance_high = 30;
282 sf->exhaustive_searches_thresh =
283 (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ? (1 << 23)
285 sf->use_accurate_subpel_search = USE_4_TAPS;
289 sf->rd_ml_partition.var_pruning = 0;
290 if (oxcf->vbr_corpus_complexity)
291 sf->recode_loop = ALLOW_RECODE_FIRST;
293 sf->recode_loop = ALLOW_RECODE_KFARFGF;
295 sf->tx_size_search_method =
296 frame_is_boosted(cpi) ? USE_FULL_RD : USE_LARGESTALL;
298 // Reference masking is not supported in dynamic scaling mode.
299 sf->reference_masking = oxcf->resize_mode != RESIZE_DYNAMIC ? 1 : 0;
301 sf->mode_search_skip_flags =
302 (cm->frame_type == KEY_FRAME)
304 : FLAG_SKIP_INTRA_DIRMISMATCH | FLAG_SKIP_INTRA_BESTINTER |
305 FLAG_SKIP_COMP_BESTINTRA | FLAG_SKIP_INTRA_LOWVAR;
306 sf->disable_filter_search_var_thresh = 100;
307 sf->comp_inter_joint_search_thresh = BLOCK_SIZES;
308 sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
309 sf->recode_tolerance_low = 15;
310 sf->recode_tolerance_high = 45;
311 sf->enhanced_full_pixel_motion_search = 0;
312 sf->prune_ref_frame_for_rect_partitions = 0;
313 sf->rd_ml_partition.prune_rect_thresh[1] = -1;
314 sf->rd_ml_partition.prune_rect_thresh[2] = -1;
315 sf->rd_ml_partition.prune_rect_thresh[3] = -1;
316 sf->mv.subpel_search_level = 0;
318 if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) {
319 for (i = 0; i < MAX_MESH_STEP; ++i) {
320 int mesh_density_level = 1;
321 sf->mesh_patterns[i].range =
322 good_quality_mesh_patterns[mesh_density_level][i].range;
323 sf->mesh_patterns[i].interval =
324 good_quality_mesh_patterns[mesh_density_level][i].interval;
328 sf->use_accurate_subpel_search = USE_2_TAPS;
332 sf->use_square_partition_only = !frame_is_intra_only(cm);
333 sf->tx_size_search_method =
334 frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL;
335 sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED;
336 sf->adaptive_pred_interp_filter = 0;
337 sf->adaptive_mode_search = 1;
338 sf->cb_partition_search = !boosted;
339 sf->cb_pred_filter_search = 1;
340 sf->alt_ref_search_fp = 1;
341 sf->recode_loop = ALLOW_RECODE_KFMAXBW;
342 sf->adaptive_rd_thresh = 3;
343 sf->mode_skip_start = 6;
344 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
345 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC;
346 sf->adaptive_interp_filter_search = 1;
347 sf->allow_partition_search_skip = 1;
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;
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;
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;
384 sf->mv.reduce_first_step_size = 1;
385 sf->simple_model_rd_from_var = 1;
389 static void set_rt_speed_feature_framesize_dependent(VP9_COMP *cpi,
392 VP9_COMMON *const cm = &cpi->common;
395 if (VPXMIN(cm->width, cm->height) >= 720) {
396 sf->disable_split_mask =
397 cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
399 sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
404 if (VPXMIN(cm->width, cm->height) >= 720) {
405 sf->disable_split_mask =
406 cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
408 sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY;
413 sf->partition_search_breakout_thr.rate = 200;
414 if (VPXMIN(cm->width, cm->height) >= 720) {
415 sf->partition_search_breakout_thr.dist = (1 << 25);
417 sf->partition_search_breakout_thr.dist = (1 << 23);
422 sf->encode_breakout_thresh =
423 (VPXMIN(cm->width, cm->height) >= 720) ? 800 : 300;
427 static void set_rt_speed_feature_framesize_independent(
428 VP9_COMP *cpi, SPEED_FEATURES *sf, int speed, vp9e_tune_content content) {
429 VP9_COMMON *const cm = &cpi->common;
430 SVC *const svc = &cpi->svc;
431 const int is_keyframe = cm->frame_type == KEY_FRAME;
432 const int frames_since_key = is_keyframe ? 0 : cpi->rc.frames_since_key;
433 sf->static_segmentation = 0;
434 sf->adaptive_rd_thresh = 1;
435 sf->adaptive_rd_thresh_row_mt = 0;
436 sf->use_fast_coef_costing = 1;
437 sf->exhaustive_searches_thresh = INT_MAX;
439 sf->copy_partition_flag = 0;
440 sf->use_source_sad = 0;
441 sf->use_simple_block_yrd = 0;
442 sf->adapt_partition_source_sad = 0;
443 sf->use_altref_onepass = 0;
444 sf->use_compound_nonrd_pickmode = 0;
445 sf->nonrd_keyframe = 0;
446 sf->svc_use_lowres_part = 0;
447 sf->overshoot_detection_cbr_rt = NO_DETECTION;
448 sf->disable_16x16part_nonkey = 0;
449 sf->disable_golden_ref = 0;
450 sf->enable_tpl_model = 0;
451 sf->enhanced_full_pixel_motion_search = 0;
452 sf->use_accurate_subpel_search = USE_2_TAPS;
453 sf->nonrd_use_ml_partition = 0;
454 sf->variance_part_thresh_mult = 1;
457 sf->allow_txfm_domain_distortion = 1;
458 sf->tx_domain_thresh = 0.0;
459 sf->allow_quant_coeff_opt = 0;
460 sf->quant_opt_thresh = 0.0;
461 sf->use_square_partition_only = !frame_is_intra_only(cm);
462 sf->less_rectangular_check = 1;
463 sf->tx_size_search_method =
464 frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL;
466 sf->use_rd_breakout = 1;
468 sf->adaptive_motion_search = 1;
469 sf->adaptive_pred_interp_filter = 1;
470 sf->mv.auto_mv_step_size = 1;
471 sf->adaptive_rd_thresh = 2;
472 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
473 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
474 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
478 sf->mode_search_skip_flags =
479 (cm->frame_type == KEY_FRAME)
481 : FLAG_SKIP_INTRA_DIRMISMATCH | FLAG_SKIP_INTRA_BESTINTER |
482 FLAG_SKIP_COMP_BESTINTRA | FLAG_SKIP_INTRA_LOWVAR;
483 sf->adaptive_pred_interp_filter = 2;
485 // Reference masking only enabled for 1 spatial layer, and if none of the
486 // references have been scaled. The latter condition needs to be checked
487 // for external or internal dynamic resize.
488 sf->reference_masking = (svc->number_spatial_layers == 1);
489 if (sf->reference_masking == 1 &&
490 (cpi->external_resize == 1 ||
491 cpi->oxcf.resize_mode == RESIZE_DYNAMIC)) {
492 MV_REFERENCE_FRAME ref_frame;
493 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG,
495 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
496 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame);
497 if (yv12 != NULL && (cpi->ref_frame_flags & flag_list[ref_frame])) {
498 const struct scale_factors *const scale_fac =
499 &cm->frame_refs[ref_frame - 1].sf;
500 if (vp9_is_scaled(scale_fac)) sf->reference_masking = 0;
505 sf->disable_filter_search_var_thresh = 50;
506 sf->comp_inter_joint_search_thresh = BLOCK_SIZES;
507 sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
508 sf->lf_motion_threshold = LOW_MOTION_THRESHOLD;
509 sf->adjust_partitioning_from_last_frame = 1;
510 sf->last_partitioning_redo_frequency = 3;
511 sf->use_lp32x32fdct = 1;
512 sf->mode_skip_start = 11;
513 sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
517 sf->use_square_partition_only = 1;
518 sf->disable_filter_search_var_thresh = 100;
519 sf->use_uv_intra_rd_estimate = 1;
520 sf->skip_encode_sb = 1;
521 sf->mv.subpel_search_level = 0;
522 sf->adaptive_rd_thresh = 4;
523 sf->mode_skip_start = 6;
524 sf->allow_skip_recode = 0;
525 sf->optimize_coefficients = 0;
526 sf->disable_split_mask = DISABLE_ALL_SPLIT;
527 sf->lpf_pick = LPF_PICK_FROM_Q;
532 if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0)
533 sf->use_altref_onepass = 1;
534 sf->last_partitioning_redo_frequency = 4;
535 sf->adaptive_rd_thresh = 5;
536 sf->use_fast_coef_costing = 0;
537 sf->auto_min_max_partition_size = STRICT_NEIGHBORING_MIN_MAX;
538 sf->adjust_partitioning_from_last_frame =
539 cm->last_frame_type != cm->frame_type ||
540 (0 == (frames_since_key + 1) % sf->last_partitioning_redo_frequency);
541 sf->mv.subpel_force_stop = QUARTER_PEL;
542 for (i = 0; i < TX_SIZES; i++) {
543 sf->intra_y_mode_mask[i] = INTRA_DC_H_V;
544 sf->intra_uv_mode_mask[i] = INTRA_DC;
546 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
547 sf->frame_parameter_update = 0;
548 sf->mv.search_method = FAST_HEX;
550 sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEAR_NEW;
551 sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST;
552 sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST;
553 sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST;
554 sf->max_intra_bsize = BLOCK_32X32;
555 sf->allow_skip_recode = 1;
559 sf->use_altref_onepass = 0;
560 sf->use_quant_fp = !is_keyframe;
561 sf->auto_min_max_partition_size =
562 is_keyframe ? RELAXED_NEIGHBORING_MIN_MAX : STRICT_NEIGHBORING_MIN_MAX;
563 sf->default_max_partition_size = BLOCK_32X32;
564 sf->default_min_partition_size = BLOCK_8X8;
565 sf->force_frame_boost =
567 (frames_since_key % (sf->last_partitioning_redo_frequency << 1) == 1);
568 sf->max_delta_qindex = is_keyframe ? 20 : 15;
569 sf->partition_search_type = REFERENCE_PARTITION;
570 if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0 &&
571 cpi->rc.is_src_frame_alt_ref) {
572 sf->partition_search_type = VAR_BASED_PARTITION;
574 sf->use_nonrd_pick_mode = 1;
575 sf->allow_skip_recode = 0;
576 sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEW_ZERO;
577 sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST_NEW_ZERO;
578 sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST_NEW_ZERO;
579 sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST_NEW_ZERO;
580 sf->adaptive_rd_thresh = 2;
581 // This feature is only enabled when partition search is disabled.
582 sf->reuse_inter_pred_sby = 1;
583 sf->coeff_prob_appx_step = 4;
584 sf->use_fast_coef_updates = is_keyframe ? TWO_LOOP : ONE_LOOP_REDUCED;
585 sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH;
586 sf->tx_size_search_method = is_keyframe ? USE_LARGESTALL : USE_TX_8X8;
587 sf->simple_model_rd_from_var = 1;
588 if (cpi->oxcf.rc_mode == VPX_VBR) sf->mv.search_method = NSTEP;
592 if (content == VP9E_CONTENT_SCREEN) {
593 for (i = 0; i < BLOCK_SIZES; ++i)
594 if (i >= BLOCK_32X32)
595 sf->intra_y_mode_bsize_mask[i] = INTRA_DC_H_V;
597 sf->intra_y_mode_bsize_mask[i] = INTRA_DC_TM_H_V;
599 for (i = 0; i < BLOCK_SIZES; ++i)
601 sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
603 // Use H and V intra mode for block sizes <= 16X16.
604 sf->intra_y_mode_bsize_mask[i] = INTRA_DC_H_V;
607 if (content == VP9E_CONTENT_SCREEN) {
608 sf->short_circuit_flat_blocks = 1;
610 if (cpi->oxcf.rc_mode == VPX_CBR &&
611 cpi->oxcf.content != VP9E_CONTENT_SCREEN) {
612 sf->limit_newmv_early_exit = 1;
613 if (!cpi->use_svc) sf->bias_golden = 1;
615 // Keep nonrd_keyframe = 1 for non-base spatial layers to prevent
616 // increase in encoding time.
617 if (cpi->use_svc && svc->spatial_layer_id > 0) sf->nonrd_keyframe = 1;
618 if (cm->frame_type != KEY_FRAME && cpi->resize_state == ORIG &&
619 cpi->oxcf.rc_mode == VPX_CBR)
620 sf->overshoot_detection_cbr_rt = FAST_DETECTION_MAXQ;
621 if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0 &&
622 cm->width <= 1280 && cm->height <= 720) {
623 sf->use_altref_onepass = 1;
624 sf->use_compound_nonrd_pickmode = 1;
629 if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0) {
630 sf->use_altref_onepass = 1;
631 sf->use_compound_nonrd_pickmode = 1;
633 sf->partition_search_type = VAR_BASED_PARTITION;
634 sf->mv.search_method = NSTEP;
635 sf->mv.reduce_first_step_size = 1;
636 sf->skip_encode_sb = 0;
638 if (!cpi->external_resize) sf->use_source_sad = 1;
640 if (sf->use_source_sad) {
641 sf->adapt_partition_source_sad = 1;
642 sf->adapt_partition_thresh =
643 (cm->width * cm->height <= 640 * 360) ? 40000 : 60000;
644 if (cpi->content_state_sb_fd == NULL &&
646 svc->spatial_layer_id == svc->number_spatial_layers - 1)) {
647 cpi->content_state_sb_fd = (uint8_t *)vpx_calloc(
648 (cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1), sizeof(uint8_t));
651 if (cpi->oxcf.rc_mode == VPX_CBR && content != VP9E_CONTENT_SCREEN) {
652 // Enable short circuit for low temporal variance.
653 sf->short_circuit_low_temp_var = 1;
655 if (svc->temporal_layer_id > 0) {
656 sf->adaptive_rd_thresh = 4;
657 sf->limit_newmv_early_exit = 0;
658 sf->base_mv_aggressive = 1;
663 sf->adapt_partition_source_sad = 0;
664 sf->adaptive_rd_thresh = 3;
665 sf->mv.search_method = FAST_DIAMOND;
666 sf->mv.fullpel_search_step_param = 10;
667 // For SVC: use better mv search on base temporal layer, and only
668 // on base spatial layer if highest resolution is above 640x360.
669 if (svc->number_temporal_layers > 2 && svc->temporal_layer_id == 0 &&
670 (svc->spatial_layer_id == 0 ||
671 cpi->oxcf.width * cpi->oxcf.height <= 640 * 360)) {
672 sf->mv.search_method = NSTEP;
673 sf->mv.fullpel_search_step_param = 6;
675 if (svc->temporal_layer_id > 0 || svc->spatial_layer_id > 1) {
676 sf->use_simple_block_yrd = 1;
677 if (svc->non_reference_frame)
678 sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED_EVENMORE;
680 if (cpi->use_svc && cpi->row_mt && cpi->oxcf.max_threads > 1)
681 sf->adaptive_rd_thresh_row_mt = 1;
682 // Enable partition copy. For SVC only enabled for top spatial resolution
684 cpi->max_copied_frame = 0;
685 if (!cpi->last_frame_dropped && cpi->resize_state == ORIG &&
686 !cpi->external_resize &&
688 (svc->spatial_layer_id == svc->number_spatial_layers - 1 &&
689 !svc->last_layer_dropped[svc->number_spatial_layers - 1]))) {
690 sf->copy_partition_flag = 1;
691 cpi->max_copied_frame = 2;
692 // The top temporal enhancement layer (for number of temporal layers > 1)
693 // are non-reference frames, so use large/max value for max_copied_frame.
694 if (svc->number_temporal_layers > 1 &&
695 svc->temporal_layer_id == svc->number_temporal_layers - 1)
696 cpi->max_copied_frame = 255;
698 // For SVC: enable use of lower resolution partition for higher resolution,
699 // only for 3 spatial layers and when config/top resolution is above VGA.
700 // Enable only for non-base temporal layer frames.
701 if (cpi->use_svc && svc->use_partition_reuse &&
702 svc->number_spatial_layers == 3 && svc->temporal_layer_id > 0 &&
703 cpi->oxcf.width * cpi->oxcf.height > 640 * 480)
704 sf->svc_use_lowres_part = 1;
705 // For SVC when golden is used as second temporal reference: to avoid
706 // encode time increase only use this feature on base temporal layer.
707 // (i.e remove golden flag from frame_flags for temporal_layer_id > 0).
708 if (cpi->use_svc && svc->use_gf_temporal_ref_current_layer &&
709 svc->temporal_layer_id > 0)
710 cpi->ref_frame_flags &= (~VP9_GOLD_FLAG);
714 sf->adaptive_rd_thresh = 4;
715 sf->skip_encode_sb = 1;
716 sf->nonrd_keyframe = 1;
717 if (!cpi->use_svc) cpi->max_copied_frame = 4;
718 if (cpi->row_mt && cpi->oxcf.max_threads > 1)
719 sf->adaptive_rd_thresh_row_mt = 1;
720 // Enable ML based partition for low res.
721 if (!frame_is_intra_only(cm) && cm->width * cm->height <= 352 * 288) {
722 sf->nonrd_use_ml_partition = 1;
724 if (content == VP9E_CONTENT_SCREEN) sf->mv.subpel_force_stop = HALF_PEL;
725 // Only keep INTRA_DC mode for speed 8.
728 for (i = 0; i < BLOCK_SIZES; ++i)
729 sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
731 if (!cpi->use_svc && cpi->oxcf.rc_mode == VPX_CBR &&
732 content != VP9E_CONTENT_SCREEN) {
733 // More aggressive short circuit for speed 8.
734 sf->short_circuit_low_temp_var = 3;
735 // Use level 2 for noisey cases as there is a regression in some
736 // noisy clips with level 3.
737 if (cpi->noise_estimate.enabled && cm->width >= 1280 &&
739 NOISE_LEVEL noise_level =
740 vp9_noise_estimate_extract_level(&cpi->noise_estimate);
741 if (noise_level >= kMedium) sf->short_circuit_low_temp_var = 2;
743 // Since the short_circuit_low_temp_var is used, reduce the
744 // adaptive_rd_thresh level.
745 if (cm->width * cm->height > 352 * 288)
746 sf->adaptive_rd_thresh = 1;
748 sf->adaptive_rd_thresh = 2;
750 sf->limit_newmv_early_exit = 0;
751 sf->use_simple_block_yrd = 1;
755 sf->mv.enable_adaptive_subpel_force_stop = 1;
756 sf->mv.adapt_subpel_force_stop.mv_thresh = 1;
757 sf->mv.adapt_subpel_force_stop.force_stop_below = QUARTER_PEL;
758 sf->mv.adapt_subpel_force_stop.force_stop_above = HALF_PEL;
759 // Disable partition blocks below 16x16, except for low-resolutions.
760 if (cm->frame_type != KEY_FRAME && cm->width >= 320 && cm->height >= 240)
761 sf->disable_16x16part_nonkey = 1;
762 // Allow for disabling GOLDEN reference, for CBR mode.
763 if (cpi->oxcf.rc_mode == VPX_CBR) sf->disable_golden_ref = 1;
764 if (cpi->rc.avg_frame_low_motion < 70) sf->default_interp_filter = BILINEAR;
765 if (cm->width * cm->height >= 640 * 360) sf->variance_part_thresh_mult = 2;
768 if (sf->nonrd_use_ml_partition)
769 sf->partition_search_type = ML_BASED_PARTITION;
771 if (sf->use_altref_onepass) {
772 if (cpi->rc.is_src_frame_alt_ref && cm->frame_type != KEY_FRAME) {
773 sf->partition_search_type = FIXED_PARTITION;
774 sf->always_this_block_size = BLOCK_64X64;
776 if (cpi->count_arf_frame_usage == NULL)
777 cpi->count_arf_frame_usage =
778 (uint8_t *)vpx_calloc((cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1),
779 sizeof(*cpi->count_arf_frame_usage));
780 if (cpi->count_lastgolden_frame_usage == NULL)
781 cpi->count_lastgolden_frame_usage =
782 (uint8_t *)vpx_calloc((cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1),
783 sizeof(*cpi->count_lastgolden_frame_usage));
785 if (svc->previous_frame_is_intra_only) {
786 sf->partition_search_type = FIXED_PARTITION;
787 sf->always_this_block_size = BLOCK_64X64;
789 // Special case for screen content: increase motion search on base spatial
790 // layer when high motion is detected or previous SL0 frame was dropped.
791 if (cpi->oxcf.content == VP9E_CONTENT_SCREEN && cpi->oxcf.speed >= 5 &&
792 (svc->high_num_blocks_with_motion || svc->last_layer_dropped[0])) {
793 sf->mv.search_method = NSTEP;
794 // TODO(marpan/jianj): Tune this setting for screensharing. For now use
795 // small step_param for all spatial layers.
796 sf->mv.fullpel_search_step_param = 2;
798 // TODO(marpan): There is regression for aq-mode=3 speed <= 4, force it
800 if (speed <= 4 && cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
801 cpi->oxcf.aq_mode = 0;
804 void vp9_set_speed_features_framesize_dependent(VP9_COMP *cpi, int speed) {
805 SPEED_FEATURES *const sf = &cpi->sf;
806 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
807 RD_OPT *const rd = &cpi->rd;
810 // best quality defaults
811 // Some speed-up features even for best quality as minimal impact on quality.
812 sf->partition_search_breakout_thr.dist = (1 << 19);
813 sf->partition_search_breakout_thr.rate = 80;
814 sf->rd_ml_partition.search_early_termination = 0;
815 sf->rd_ml_partition.search_breakout = 0;
817 if (oxcf->mode == REALTIME) {
818 set_rt_speed_feature_framesize_dependent(cpi, sf, speed);
819 } else if (oxcf->mode == GOOD) {
820 set_good_speed_feature_framesize_dependent(cpi, sf, speed);
823 if (sf->disable_split_mask == DISABLE_ALL_SPLIT) {
824 sf->adaptive_pred_interp_filter = 0;
827 if (cpi->encode_breakout && oxcf->mode == REALTIME &&
828 sf->encode_breakout_thresh > cpi->encode_breakout) {
829 cpi->encode_breakout = sf->encode_breakout_thresh;
832 // Check for masked out split cases.
833 for (i = 0; i < MAX_REFS; ++i) {
834 if (sf->disable_split_mask & (1 << i)) {
835 rd->thresh_mult_sub8x8[i] = INT_MAX;
839 // With row based multi-threading, the following speed features
840 // have to be disabled to guarantee that bitstreams encoded with single thread
841 // and multiple threads match.
842 // It can be used in realtime when adaptive_rd_thresh_row_mt is enabled since
843 // adaptive_rd_thresh is defined per-row for non-rd pickmode.
844 if (!sf->adaptive_rd_thresh_row_mt && cpi->row_mt_bit_exact &&
845 oxcf->max_threads > 1)
846 sf->adaptive_rd_thresh = 0;
849 void vp9_set_speed_features_framesize_independent(VP9_COMP *cpi, int speed) {
850 SPEED_FEATURES *const sf = &cpi->sf;
851 VP9_COMMON *const cm = &cpi->common;
852 MACROBLOCK *const x = &cpi->td.mb;
853 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
856 // best quality defaults
857 sf->frame_parameter_update = 1;
858 sf->mv.search_method = NSTEP;
859 sf->recode_loop = ALLOW_RECODE_FIRST;
860 sf->mv.subpel_search_method = SUBPEL_TREE;
861 sf->mv.subpel_search_level = 2;
862 sf->mv.subpel_force_stop = EIGHTH_PEL;
863 sf->optimize_coefficients = !is_lossless_requested(&cpi->oxcf);
864 sf->mv.reduce_first_step_size = 0;
865 sf->coeff_prob_appx_step = 1;
866 sf->mv.auto_mv_step_size = 0;
867 sf->mv.fullpel_search_step_param = 6;
868 sf->comp_inter_joint_search_thresh = BLOCK_4X4;
869 sf->tx_size_search_method = USE_FULL_RD;
870 sf->use_lp32x32fdct = 0;
871 sf->adaptive_motion_search = 0;
872 sf->enhanced_full_pixel_motion_search = 1;
873 sf->adaptive_pred_interp_filter = 0;
874 sf->adaptive_mode_search = 0;
875 sf->cb_pred_filter_search = 0;
876 sf->cb_partition_search = 0;
877 sf->motion_field_mode_search = 0;
878 sf->alt_ref_search_fp = 0;
879 sf->use_quant_fp = 0;
880 sf->reference_masking = 0;
881 sf->partition_search_type = SEARCH_PARTITION;
882 sf->less_rectangular_check = 0;
883 sf->use_square_partition_only = 0;
884 sf->use_square_only_thresh_high = BLOCK_SIZES;
885 sf->use_square_only_thresh_low = BLOCK_4X4;
886 sf->auto_min_max_partition_size = NOT_IN_USE;
887 sf->rd_auto_partition_min_limit = BLOCK_4X4;
888 sf->default_max_partition_size = BLOCK_64X64;
889 sf->default_min_partition_size = BLOCK_4X4;
890 sf->adjust_partitioning_from_last_frame = 0;
891 sf->last_partitioning_redo_frequency = 4;
892 sf->disable_split_mask = 0;
893 sf->mode_search_skip_flags = 0;
894 sf->force_frame_boost = 0;
895 sf->max_delta_qindex = 0;
896 sf->disable_filter_search_var_thresh = 0;
897 sf->adaptive_interp_filter_search = 0;
898 sf->allow_partition_search_skip = 0;
899 sf->allow_txfm_domain_distortion = 0;
900 sf->tx_domain_thresh = 99.0;
901 sf->allow_quant_coeff_opt = sf->optimize_coefficients;
902 sf->quant_opt_thresh = 99.0;
904 sf->enable_tpl_model = oxcf->enable_tpl_model;
905 sf->prune_ref_frame_for_rect_partitions = 0;
906 sf->temporal_filter_search_method = MESH;
908 for (i = 0; i < TX_SIZES; i++) {
909 sf->intra_y_mode_mask[i] = INTRA_ALL;
910 sf->intra_uv_mode_mask[i] = INTRA_ALL;
912 sf->use_rd_breakout = 0;
913 sf->skip_encode_sb = 0;
914 sf->use_uv_intra_rd_estimate = 0;
915 sf->allow_skip_recode = 0;
916 sf->lpf_pick = LPF_PICK_FROM_FULL_IMAGE;
917 sf->use_fast_coef_updates = TWO_LOOP;
918 sf->use_fast_coef_costing = 0;
919 sf->mode_skip_start = MAX_MODES; // Mode index at which mode skip mask set
920 sf->schedule_mode_search = 0;
921 sf->use_nonrd_pick_mode = 0;
922 for (i = 0; i < BLOCK_SIZES; ++i) sf->inter_mode_mask[i] = INTER_ALL;
923 sf->max_intra_bsize = BLOCK_64X64;
924 sf->reuse_inter_pred_sby = 0;
925 // This setting only takes effect when partition_search_type is set
926 // to FIXED_PARTITION.
927 sf->always_this_block_size = BLOCK_16X16;
928 sf->search_type_check_frequency = 50;
929 sf->encode_breakout_thresh = 0;
930 // Recode loop tolerance %.
931 sf->recode_tolerance_low = 12;
932 sf->recode_tolerance_high = 25;
933 sf->default_interp_filter = SWITCHABLE;
934 sf->simple_model_rd_from_var = 0;
935 sf->short_circuit_flat_blocks = 0;
936 sf->short_circuit_low_temp_var = 0;
937 sf->limit_newmv_early_exit = 0;
939 sf->base_mv_aggressive = 0;
940 sf->rd_ml_partition.prune_rect_thresh[0] = -1;
941 sf->rd_ml_partition.prune_rect_thresh[1] = -1;
942 sf->rd_ml_partition.prune_rect_thresh[2] = -1;
943 sf->rd_ml_partition.prune_rect_thresh[3] = -1;
944 sf->rd_ml_partition.var_pruning = 0;
945 sf->use_accurate_subpel_search = USE_8_TAPS;
947 // Some speed-up features even for best quality as minimal impact on quality.
948 sf->adaptive_rd_thresh = 1;
949 sf->tx_size_search_breakout = 1;
950 sf->tx_size_search_depth = 2;
952 // Manually turn this on during experimentation. Off by default to disable its
953 // effect on the baseline encoder.
954 sf->enable_wiener_variance = 0;
956 sf->exhaustive_searches_thresh =
957 (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ? (1 << 20)
959 if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) {
960 for (i = 0; i < MAX_MESH_STEP; ++i) {
961 sf->mesh_patterns[i].range = best_quality_mesh_pattern[i].range;
962 sf->mesh_patterns[i].interval = best_quality_mesh_pattern[i].interval;
966 if (oxcf->mode == REALTIME)
967 set_rt_speed_feature_framesize_independent(cpi, sf, speed, oxcf->content);
968 else if (oxcf->mode == GOOD)
969 set_good_speed_feature_framesize_independent(cpi, cm, sf, speed);
971 cpi->diamond_search_sad = vp9_diamond_search_sad;
973 // Slow quant, dct and trellis not worthwhile for first pass
974 // so make sure they are always turned off.
975 if (oxcf->pass == 1) sf->optimize_coefficients = 0;
977 // No recode for 1 pass.
978 if (oxcf->pass == 0) {
979 sf->recode_loop = DISALLOW_RECODE;
980 sf->optimize_coefficients = 0;
983 if (sf->mv.subpel_force_stop == FULL_PEL) {
985 cpi->find_fractional_mv_step = vp9_skip_sub_pixel_tree;
986 } else if (sf->mv.subpel_search_method == SUBPEL_TREE) {
987 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree;
988 } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED) {
989 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned;
990 } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_MORE) {
991 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_more;
992 } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_EVENMORE) {
993 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_evenmore;
996 // This is only used in motion vector unit test.
997 if (cpi->oxcf.motion_vector_unit_test == 1)
998 cpi->find_fractional_mv_step = vp9_return_max_sub_pixel_mv;
999 else if (cpi->oxcf.motion_vector_unit_test == 2)
1000 cpi->find_fractional_mv_step = vp9_return_min_sub_pixel_mv;
1002 x->optimize = sf->optimize_coefficients == 1 && oxcf->pass != 1;
1004 x->min_partition_size = sf->default_min_partition_size;
1005 x->max_partition_size = sf->default_max_partition_size;
1007 if (!cpi->oxcf.frame_periodic_boost) {
1008 sf->max_delta_qindex = 0;
1011 // With row based multi-threading, the following speed features
1012 // have to be disabled to guarantee that bitstreams encoded with single thread
1013 // and multiple threads match.
1014 // It can be used in realtime when adaptive_rd_thresh_row_mt is enabled since
1015 // adaptive_rd_thresh is defined per-row for non-rd pickmode.
1016 if (!sf->adaptive_rd_thresh_row_mt && cpi->row_mt_bit_exact &&
1017 oxcf->max_threads > 1)
1018 sf->adaptive_rd_thresh = 0;