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;
455 sf->cb_pred_filter_search = 0;
458 sf->allow_txfm_domain_distortion = 1;
459 sf->tx_domain_thresh = 0.0;
460 sf->allow_quant_coeff_opt = 0;
461 sf->quant_opt_thresh = 0.0;
462 sf->use_square_partition_only = !frame_is_intra_only(cm);
463 sf->less_rectangular_check = 1;
464 sf->tx_size_search_method =
465 frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL;
467 sf->use_rd_breakout = 1;
469 sf->adaptive_motion_search = 1;
470 sf->adaptive_pred_interp_filter = 1;
471 sf->mv.auto_mv_step_size = 1;
472 sf->adaptive_rd_thresh = 2;
473 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
474 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
475 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
479 sf->mode_search_skip_flags =
480 (cm->frame_type == KEY_FRAME)
482 : FLAG_SKIP_INTRA_DIRMISMATCH | FLAG_SKIP_INTRA_BESTINTER |
483 FLAG_SKIP_COMP_BESTINTRA | FLAG_SKIP_INTRA_LOWVAR;
484 sf->adaptive_pred_interp_filter = 2;
486 // Reference masking only enabled for 1 spatial layer, and if none of the
487 // references have been scaled. The latter condition needs to be checked
488 // for external or internal dynamic resize.
489 sf->reference_masking = (svc->number_spatial_layers == 1);
490 if (sf->reference_masking == 1 &&
491 (cpi->external_resize == 1 ||
492 cpi->oxcf.resize_mode == RESIZE_DYNAMIC)) {
493 MV_REFERENCE_FRAME ref_frame;
494 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG,
496 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
497 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame);
498 if (yv12 != NULL && (cpi->ref_frame_flags & flag_list[ref_frame])) {
499 const struct scale_factors *const scale_fac =
500 &cm->frame_refs[ref_frame - 1].sf;
501 if (vp9_is_scaled(scale_fac)) sf->reference_masking = 0;
506 sf->disable_filter_search_var_thresh = 50;
507 sf->comp_inter_joint_search_thresh = BLOCK_SIZES;
508 sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
509 sf->lf_motion_threshold = LOW_MOTION_THRESHOLD;
510 sf->adjust_partitioning_from_last_frame = 1;
511 sf->last_partitioning_redo_frequency = 3;
512 sf->use_lp32x32fdct = 1;
513 sf->mode_skip_start = 11;
514 sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
518 sf->use_square_partition_only = 1;
519 sf->disable_filter_search_var_thresh = 100;
520 sf->use_uv_intra_rd_estimate = 1;
521 sf->skip_encode_sb = 1;
522 sf->mv.subpel_search_level = 0;
523 sf->adaptive_rd_thresh = 4;
524 sf->mode_skip_start = 6;
525 sf->allow_skip_recode = 0;
526 sf->optimize_coefficients = 0;
527 sf->disable_split_mask = DISABLE_ALL_SPLIT;
528 sf->lpf_pick = LPF_PICK_FROM_Q;
533 if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0)
534 sf->use_altref_onepass = 1;
535 sf->last_partitioning_redo_frequency = 4;
536 sf->adaptive_rd_thresh = 5;
537 sf->use_fast_coef_costing = 0;
538 sf->auto_min_max_partition_size = STRICT_NEIGHBORING_MIN_MAX;
539 sf->adjust_partitioning_from_last_frame =
540 cm->last_frame_type != cm->frame_type ||
541 (0 == (frames_since_key + 1) % sf->last_partitioning_redo_frequency);
542 sf->mv.subpel_force_stop = QUARTER_PEL;
543 for (i = 0; i < TX_SIZES; i++) {
544 sf->intra_y_mode_mask[i] = INTRA_DC_H_V;
545 sf->intra_uv_mode_mask[i] = INTRA_DC;
547 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
548 sf->frame_parameter_update = 0;
549 sf->mv.search_method = FAST_HEX;
551 sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEAR_NEW;
552 sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST;
553 sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST;
554 sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST;
555 sf->max_intra_bsize = BLOCK_32X32;
556 sf->allow_skip_recode = 1;
560 sf->use_altref_onepass = 0;
561 sf->use_quant_fp = !is_keyframe;
562 sf->auto_min_max_partition_size =
563 is_keyframe ? RELAXED_NEIGHBORING_MIN_MAX : STRICT_NEIGHBORING_MIN_MAX;
564 sf->default_max_partition_size = BLOCK_32X32;
565 sf->default_min_partition_size = BLOCK_8X8;
566 sf->force_frame_boost =
568 (frames_since_key % (sf->last_partitioning_redo_frequency << 1) == 1);
569 sf->max_delta_qindex = is_keyframe ? 20 : 15;
570 sf->partition_search_type = REFERENCE_PARTITION;
571 if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0 &&
572 cpi->rc.is_src_frame_alt_ref) {
573 sf->partition_search_type = VAR_BASED_PARTITION;
575 sf->use_nonrd_pick_mode = 1;
576 sf->allow_skip_recode = 0;
577 sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEW_ZERO;
578 sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST_NEW_ZERO;
579 sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST_NEW_ZERO;
580 sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST_NEW_ZERO;
581 sf->adaptive_rd_thresh = 2;
582 // This feature is only enabled when partition search is disabled.
583 sf->reuse_inter_pred_sby = 1;
584 sf->coeff_prob_appx_step = 4;
585 sf->use_fast_coef_updates = is_keyframe ? TWO_LOOP : ONE_LOOP_REDUCED;
586 sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH;
587 sf->tx_size_search_method = is_keyframe ? USE_LARGESTALL : USE_TX_8X8;
588 sf->simple_model_rd_from_var = 1;
589 if (cpi->oxcf.rc_mode == VPX_VBR) sf->mv.search_method = NSTEP;
593 if (content == VP9E_CONTENT_SCREEN) {
594 for (i = 0; i < BLOCK_SIZES; ++i)
595 if (i >= BLOCK_32X32)
596 sf->intra_y_mode_bsize_mask[i] = INTRA_DC_H_V;
598 sf->intra_y_mode_bsize_mask[i] = INTRA_DC_TM_H_V;
600 for (i = 0; i < BLOCK_SIZES; ++i)
602 sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
604 // Use H and V intra mode for block sizes <= 16X16.
605 sf->intra_y_mode_bsize_mask[i] = INTRA_DC_H_V;
608 if (content == VP9E_CONTENT_SCREEN) {
609 sf->short_circuit_flat_blocks = 1;
611 if (cpi->oxcf.rc_mode == VPX_CBR &&
612 cpi->oxcf.content != VP9E_CONTENT_SCREEN) {
613 sf->limit_newmv_early_exit = 1;
614 if (!cpi->use_svc) sf->bias_golden = 1;
616 // Keep nonrd_keyframe = 1 for non-base spatial layers to prevent
617 // increase in encoding time.
618 if (cpi->use_svc && svc->spatial_layer_id > 0) sf->nonrd_keyframe = 1;
619 if (cm->frame_type != KEY_FRAME && cpi->resize_state == ORIG &&
620 cpi->oxcf.rc_mode == VPX_CBR)
621 sf->overshoot_detection_cbr_rt = FAST_DETECTION_MAXQ;
622 if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0 &&
623 cm->width <= 1280 && cm->height <= 720) {
624 sf->use_altref_onepass = 1;
625 sf->use_compound_nonrd_pickmode = 1;
630 if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0) {
631 sf->use_altref_onepass = 1;
632 sf->use_compound_nonrd_pickmode = 1;
634 sf->partition_search_type = VAR_BASED_PARTITION;
635 sf->mv.search_method = NSTEP;
636 sf->mv.reduce_first_step_size = 1;
637 sf->skip_encode_sb = 0;
639 if (!cpi->external_resize) sf->use_source_sad = 1;
641 if (sf->use_source_sad) {
642 sf->adapt_partition_source_sad = 1;
643 sf->adapt_partition_thresh =
644 (cm->width * cm->height <= 640 * 360) ? 40000 : 60000;
645 if (cpi->content_state_sb_fd == NULL &&
647 svc->spatial_layer_id == svc->number_spatial_layers - 1)) {
648 cpi->content_state_sb_fd = (uint8_t *)vpx_calloc(
649 (cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1), sizeof(uint8_t));
652 if (cpi->oxcf.rc_mode == VPX_CBR && content != VP9E_CONTENT_SCREEN) {
653 // Enable short circuit for low temporal variance.
654 sf->short_circuit_low_temp_var = 1;
656 if (svc->temporal_layer_id > 0) {
657 sf->adaptive_rd_thresh = 4;
658 sf->limit_newmv_early_exit = 0;
659 sf->base_mv_aggressive = 1;
664 sf->adapt_partition_source_sad = 0;
665 sf->adaptive_rd_thresh = 3;
666 sf->mv.search_method = FAST_DIAMOND;
667 sf->mv.fullpel_search_step_param = 10;
668 // For SVC: use better mv search on base temporal layer, and only
669 // on base spatial layer if highest resolution is above 640x360.
670 if (svc->number_temporal_layers > 2 && svc->temporal_layer_id == 0 &&
671 (svc->spatial_layer_id == 0 ||
672 cpi->oxcf.width * cpi->oxcf.height <= 640 * 360)) {
673 sf->mv.search_method = NSTEP;
674 sf->mv.fullpel_search_step_param = 6;
676 if (svc->temporal_layer_id > 0 || svc->spatial_layer_id > 1) {
677 sf->use_simple_block_yrd = 1;
678 if (svc->non_reference_frame)
679 sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED_EVENMORE;
681 if (cpi->use_svc && cpi->row_mt && cpi->oxcf.max_threads > 1)
682 sf->adaptive_rd_thresh_row_mt = 1;
683 // Enable partition copy. For SVC only enabled for top spatial resolution
685 cpi->max_copied_frame = 0;
686 if (!cpi->last_frame_dropped && cpi->resize_state == ORIG &&
687 !cpi->external_resize &&
689 (svc->spatial_layer_id == svc->number_spatial_layers - 1 &&
690 !svc->last_layer_dropped[svc->number_spatial_layers - 1]))) {
691 sf->copy_partition_flag = 1;
692 cpi->max_copied_frame = 2;
693 // The top temporal enhancement layer (for number of temporal layers > 1)
694 // are non-reference frames, so use large/max value for max_copied_frame.
695 if (svc->number_temporal_layers > 1 &&
696 svc->temporal_layer_id == svc->number_temporal_layers - 1)
697 cpi->max_copied_frame = 255;
699 // For SVC: enable use of lower resolution partition for higher resolution,
700 // only for 3 spatial layers and when config/top resolution is above VGA.
701 // Enable only for non-base temporal layer frames.
702 if (cpi->use_svc && svc->use_partition_reuse &&
703 svc->number_spatial_layers == 3 && svc->temporal_layer_id > 0 &&
704 cpi->oxcf.width * cpi->oxcf.height > 640 * 480)
705 sf->svc_use_lowres_part = 1;
706 // For SVC when golden is used as second temporal reference: to avoid
707 // encode time increase only use this feature on base temporal layer.
708 // (i.e remove golden flag from frame_flags for temporal_layer_id > 0).
709 if (cpi->use_svc && svc->use_gf_temporal_ref_current_layer &&
710 svc->temporal_layer_id > 0)
711 cpi->ref_frame_flags &= (~VP9_GOLD_FLAG);
715 sf->adaptive_rd_thresh = 4;
716 sf->skip_encode_sb = 1;
717 sf->nonrd_keyframe = 1;
718 if (!cpi->use_svc) cpi->max_copied_frame = 4;
719 if (cpi->row_mt && cpi->oxcf.max_threads > 1)
720 sf->adaptive_rd_thresh_row_mt = 1;
721 // Enable ML based partition for low res.
722 if (!frame_is_intra_only(cm) && cm->width * cm->height <= 352 * 288) {
723 sf->nonrd_use_ml_partition = 1;
725 if (content == VP9E_CONTENT_SCREEN) sf->mv.subpel_force_stop = HALF_PEL;
726 // Only keep INTRA_DC mode for speed 8.
729 for (i = 0; i < BLOCK_SIZES; ++i)
730 sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
732 if (!cpi->use_svc && cpi->oxcf.rc_mode == VPX_CBR &&
733 content != VP9E_CONTENT_SCREEN) {
734 // More aggressive short circuit for speed 8.
735 sf->short_circuit_low_temp_var = 3;
736 // Use level 2 for noisey cases as there is a regression in some
737 // noisy clips with level 3.
738 if (cpi->noise_estimate.enabled && cm->width >= 1280 &&
740 NOISE_LEVEL noise_level =
741 vp9_noise_estimate_extract_level(&cpi->noise_estimate);
742 if (noise_level >= kMedium) sf->short_circuit_low_temp_var = 2;
744 // Since the short_circuit_low_temp_var is used, reduce the
745 // adaptive_rd_thresh level.
746 if (cm->width * cm->height > 352 * 288)
747 sf->adaptive_rd_thresh = 1;
749 sf->adaptive_rd_thresh = 2;
751 sf->limit_newmv_early_exit = 0;
752 sf->use_simple_block_yrd = 1;
753 if (cm->width * cm->height > 352 * 288) sf->cb_pred_filter_search = 1;
757 sf->cb_pred_filter_search = 1;
758 sf->mv.enable_adaptive_subpel_force_stop = 1;
759 sf->mv.adapt_subpel_force_stop.mv_thresh = 1;
760 sf->mv.adapt_subpel_force_stop.force_stop_below = QUARTER_PEL;
761 sf->mv.adapt_subpel_force_stop.force_stop_above = HALF_PEL;
762 // Disable partition blocks below 16x16, except for low-resolutions.
763 if (cm->frame_type != KEY_FRAME && cm->width >= 320 && cm->height >= 240)
764 sf->disable_16x16part_nonkey = 1;
765 // Allow for disabling GOLDEN reference, for CBR mode.
766 if (cpi->oxcf.rc_mode == VPX_CBR) sf->disable_golden_ref = 1;
767 if (cpi->rc.avg_frame_low_motion < 70) sf->default_interp_filter = BILINEAR;
768 if (cm->width * cm->height >= 640 * 360) sf->variance_part_thresh_mult = 2;
771 if (sf->nonrd_use_ml_partition)
772 sf->partition_search_type = ML_BASED_PARTITION;
774 if (sf->use_altref_onepass) {
775 if (cpi->rc.is_src_frame_alt_ref && cm->frame_type != KEY_FRAME) {
776 sf->partition_search_type = FIXED_PARTITION;
777 sf->always_this_block_size = BLOCK_64X64;
779 if (cpi->count_arf_frame_usage == NULL)
780 cpi->count_arf_frame_usage =
781 (uint8_t *)vpx_calloc((cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1),
782 sizeof(*cpi->count_arf_frame_usage));
783 if (cpi->count_lastgolden_frame_usage == NULL)
784 cpi->count_lastgolden_frame_usage =
785 (uint8_t *)vpx_calloc((cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1),
786 sizeof(*cpi->count_lastgolden_frame_usage));
788 if (svc->previous_frame_is_intra_only) {
789 sf->partition_search_type = FIXED_PARTITION;
790 sf->always_this_block_size = BLOCK_64X64;
792 // Special case for screen content: increase motion search on base spatial
793 // layer when high motion is detected or previous SL0 frame was dropped.
794 if (cpi->oxcf.content == VP9E_CONTENT_SCREEN && cpi->oxcf.speed >= 5 &&
795 (svc->high_num_blocks_with_motion || svc->last_layer_dropped[0])) {
796 sf->mv.search_method = NSTEP;
797 // TODO(marpan/jianj): Tune this setting for screensharing. For now use
798 // small step_param for all spatial layers.
799 sf->mv.fullpel_search_step_param = 2;
801 // TODO(marpan): There is regression for aq-mode=3 speed <= 4, force it
803 if (speed <= 4 && cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
804 cpi->oxcf.aq_mode = 0;
807 void vp9_set_speed_features_framesize_dependent(VP9_COMP *cpi, int speed) {
808 SPEED_FEATURES *const sf = &cpi->sf;
809 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
810 RD_OPT *const rd = &cpi->rd;
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->rd_ml_partition.search_early_termination = 0;
818 sf->rd_ml_partition.search_breakout = 0;
820 if (oxcf->mode == REALTIME) {
821 set_rt_speed_feature_framesize_dependent(cpi, sf, speed);
822 } else if (oxcf->mode == GOOD) {
823 set_good_speed_feature_framesize_dependent(cpi, sf, speed);
826 if (sf->disable_split_mask == DISABLE_ALL_SPLIT) {
827 sf->adaptive_pred_interp_filter = 0;
830 if (cpi->encode_breakout && oxcf->mode == REALTIME &&
831 sf->encode_breakout_thresh > cpi->encode_breakout) {
832 cpi->encode_breakout = sf->encode_breakout_thresh;
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;
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;
852 void vp9_set_speed_features_framesize_independent(VP9_COMP *cpi, int speed) {
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;
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;
907 sf->enable_tpl_model = oxcf->enable_tpl_model;
908 sf->prune_ref_frame_for_rect_partitions = 0;
909 sf->temporal_filter_search_method = MESH;
911 for (i = 0; i < TX_SIZES; i++) {
912 sf->intra_y_mode_mask[i] = INTRA_ALL;
913 sf->intra_uv_mode_mask[i] = INTRA_ALL;
915 sf->use_rd_breakout = 0;
916 sf->skip_encode_sb = 0;
917 sf->use_uv_intra_rd_estimate = 0;
918 sf->allow_skip_recode = 0;
919 sf->lpf_pick = LPF_PICK_FROM_FULL_IMAGE;
920 sf->use_fast_coef_updates = TWO_LOOP;
921 sf->use_fast_coef_costing = 0;
922 sf->mode_skip_start = MAX_MODES; // Mode index at which mode skip mask set
923 sf->schedule_mode_search = 0;
924 sf->use_nonrd_pick_mode = 0;
925 for (i = 0; i < BLOCK_SIZES; ++i) sf->inter_mode_mask[i] = INTER_ALL;
926 sf->max_intra_bsize = BLOCK_64X64;
927 sf->reuse_inter_pred_sby = 0;
928 // This setting only takes effect when partition_search_type is set
929 // to FIXED_PARTITION.
930 sf->always_this_block_size = BLOCK_16X16;
931 sf->search_type_check_frequency = 50;
932 sf->encode_breakout_thresh = 0;
933 // Recode loop tolerance %.
934 sf->recode_tolerance_low = 12;
935 sf->recode_tolerance_high = 25;
936 sf->default_interp_filter = SWITCHABLE;
937 sf->simple_model_rd_from_var = 0;
938 sf->short_circuit_flat_blocks = 0;
939 sf->short_circuit_low_temp_var = 0;
940 sf->limit_newmv_early_exit = 0;
942 sf->base_mv_aggressive = 0;
943 sf->rd_ml_partition.prune_rect_thresh[0] = -1;
944 sf->rd_ml_partition.prune_rect_thresh[1] = -1;
945 sf->rd_ml_partition.prune_rect_thresh[2] = -1;
946 sf->rd_ml_partition.prune_rect_thresh[3] = -1;
947 sf->rd_ml_partition.var_pruning = 0;
948 sf->use_accurate_subpel_search = USE_8_TAPS;
950 // Some speed-up features even for best quality as minimal impact on quality.
951 sf->adaptive_rd_thresh = 1;
952 sf->tx_size_search_breakout = 1;
953 sf->tx_size_search_depth = 2;
955 // Manually turn this on during experimentation. Off by default to disable its
956 // effect on the baseline encoder.
957 sf->enable_wiener_variance = 0;
959 sf->exhaustive_searches_thresh =
960 (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ? (1 << 20)
962 if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) {
963 for (i = 0; i < MAX_MESH_STEP; ++i) {
964 sf->mesh_patterns[i].range = best_quality_mesh_pattern[i].range;
965 sf->mesh_patterns[i].interval = best_quality_mesh_pattern[i].interval;
969 if (oxcf->mode == REALTIME)
970 set_rt_speed_feature_framesize_independent(cpi, sf, speed, oxcf->content);
971 else if (oxcf->mode == GOOD)
972 set_good_speed_feature_framesize_independent(cpi, cm, sf, speed);
974 cpi->diamond_search_sad = vp9_diamond_search_sad;
976 // Slow quant, dct and trellis not worthwhile for first pass
977 // so make sure they are always turned off.
978 if (oxcf->pass == 1) sf->optimize_coefficients = 0;
980 // No recode for 1 pass.
981 if (oxcf->pass == 0) {
982 sf->recode_loop = DISALLOW_RECODE;
983 sf->optimize_coefficients = 0;
986 if (sf->mv.subpel_force_stop == FULL_PEL) {
988 cpi->find_fractional_mv_step = vp9_skip_sub_pixel_tree;
989 } else if (sf->mv.subpel_search_method == SUBPEL_TREE) {
990 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree;
991 } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED) {
992 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned;
993 } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_MORE) {
994 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_more;
995 } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_EVENMORE) {
996 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_evenmore;
999 // This is only used in motion vector unit test.
1000 if (cpi->oxcf.motion_vector_unit_test == 1)
1001 cpi->find_fractional_mv_step = vp9_return_max_sub_pixel_mv;
1002 else if (cpi->oxcf.motion_vector_unit_test == 2)
1003 cpi->find_fractional_mv_step = vp9_return_min_sub_pixel_mv;
1005 x->optimize = sf->optimize_coefficients == 1 && oxcf->pass != 1;
1007 x->min_partition_size = sf->default_min_partition_size;
1008 x->max_partition_size = sf->default_max_partition_size;
1010 if (!cpi->oxcf.frame_periodic_boost) {
1011 sf->max_delta_qindex = 0;
1014 // With row based multi-threading, the following speed features
1015 // have to be disabled to guarantee that bitstreams encoded with single thread
1016 // and multiple threads match.
1017 // It can be used in realtime when adaptive_rd_thresh_row_mt is enabled since
1018 // adaptive_rd_thresh is defined per-row for non-rd pickmode.
1019 if (!sf->adaptive_rd_thresh_row_mt && cpi->row_mt_bit_exact &&
1020 oxcf->max_threads > 1)
1021 sf->adaptive_rd_thresh = 0;