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 MAX_MESH_SPEED 5 // Max speed setting for mesh motion method
25 good_quality_mesh_patterns[MAX_MESH_SPEED + 1][MAX_MESH_STEP] = {
26 { { 64, 8 }, { 28, 4 }, { 15, 1 }, { 7, 1 } },
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 { { 64, 16 }, { 24, 8 }, { 12, 4 }, { 7, 1 } },
31 { { 64, 16 }, { 24, 8 }, { 12, 4 }, { 7, 1 } },
33 static unsigned char good_quality_max_mesh_pct[MAX_MESH_SPEED + 1] = {
37 // Intra only frames, golden frames (except alt ref overlays) and
38 // alt ref frames tend to be coded at a higher than ambient quality
39 static int frame_is_boosted(const VP9_COMP *cpi) {
40 return frame_is_kf_gf_arf(cpi) || vp9_is_upper_layer_key_frame(cpi);
43 // Sets a partition size down to which the auto partition code will always
44 // search (can go lower), based on the image dimensions. The logic here
45 // is that the extent to which ringing artefacts are offensive, depends
46 // partly on the screen area that over which they propogate. Propogation is
47 // limited by transform block size but the screen area take up by a given block
48 // size will be larger for a small image format stretched to full screen.
49 static BLOCK_SIZE set_partition_min_limit(VP9_COMMON *const cm) {
50 unsigned int screen_area = (cm->width * cm->height);
52 // Select block size based on image format size.
53 if (screen_area < 1280 * 720) {
54 // Formats smaller in area than 720P
56 } else if (screen_area < 1920 * 1080) {
57 // Format >= 720P and < 1080P
60 // Formats 1080P and up
65 static void set_good_speed_feature_framesize_dependent(VP9_COMP *cpi,
68 VP9_COMMON *const cm = &cpi->common;
71 sf->partition_search_breakout_thr.dist = (1 << 20);
72 sf->partition_search_breakout_thr.rate = 80;
75 if (VPXMIN(cm->width, cm->height) >= 720) {
76 sf->disable_split_mask =
77 cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
78 sf->partition_search_breakout_thr.dist = (1 << 23);
80 sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
81 sf->partition_search_breakout_thr.dist = (1 << 21);
86 if (VPXMIN(cm->width, cm->height) >= 720) {
87 sf->disable_split_mask =
88 cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
89 sf->adaptive_pred_interp_filter = 0;
90 sf->partition_search_breakout_thr.dist = (1 << 24);
91 sf->partition_search_breakout_thr.rate = 120;
93 sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY;
94 sf->partition_search_breakout_thr.dist = (1 << 22);
95 sf->partition_search_breakout_thr.rate = 100;
97 sf->rd_auto_partition_min_limit = set_partition_min_limit(cm);
99 // Use a set of speed features for 4k videos.
100 if (VPXMIN(cm->width, cm->height) >= 2160) {
101 sf->use_square_partition_only = 1;
102 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
103 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC;
104 sf->alt_ref_search_fp = 1;
105 sf->cb_pred_filter_search = 1;
106 sf->adaptive_interp_filter_search = 1;
107 sf->disable_split_mask = DISABLE_ALL_SPLIT;
112 if (VPXMIN(cm->width, cm->height) >= 720) {
113 sf->disable_split_mask = DISABLE_ALL_SPLIT;
114 sf->schedule_mode_search = cm->base_qindex < 220 ? 1 : 0;
115 sf->partition_search_breakout_thr.dist = (1 << 25);
116 sf->partition_search_breakout_thr.rate = 200;
118 sf->max_intra_bsize = BLOCK_32X32;
119 sf->disable_split_mask = DISABLE_ALL_INTER_SPLIT;
120 sf->schedule_mode_search = cm->base_qindex < 175 ? 1 : 0;
121 sf->partition_search_breakout_thr.dist = (1 << 23);
122 sf->partition_search_breakout_thr.rate = 120;
126 // If this is a two pass clip that fits the criteria for animated or
127 // graphics content then reset disable_split_mask for speeds 1-4.
128 // Also if the image edge is internal to the coded area.
129 if ((speed >= 1) && (cpi->oxcf.pass == 2) &&
130 ((cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ||
131 (vp9_internal_image_edge(cpi)))) {
132 sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
136 sf->partition_search_breakout_thr.rate = 300;
137 if (VPXMIN(cm->width, cm->height) >= 720) {
138 sf->partition_search_breakout_thr.dist = (1 << 26);
140 sf->partition_search_breakout_thr.dist = (1 << 24);
142 sf->disable_split_mask = DISABLE_ALL_SPLIT;
146 sf->partition_search_breakout_thr.rate = 500;
150 static double tx_dom_thresholds[6] = { 99.0, 14.0, 12.0, 8.0, 4.0, 0.0 };
151 static double qopt_thresholds[6] = { 99.0, 12.0, 10.0, 4.0, 2.0, 0.0 };
153 static void set_good_speed_feature_framesize_independent(VP9_COMP *cpi,
157 const int boosted = frame_is_boosted(cpi);
159 sf->tx_size_search_breakout = 1;
160 sf->adaptive_rd_thresh = 1;
161 sf->allow_skip_recode = 1;
162 sf->less_rectangular_check = 1;
163 sf->use_square_partition_only = !frame_is_boosted(cpi);
164 sf->use_square_only_threshold = BLOCK_16X16;
167 if (cpi->oxcf.pass == 2) {
168 TWO_PASS *const twopass = &cpi->twopass;
169 if ((twopass->fr_content_type == FC_GRAPHICS_ANIMATION) ||
170 vp9_internal_image_edge(cpi)) {
171 sf->use_square_partition_only = !frame_is_boosted(cpi);
173 sf->use_square_partition_only = !frame_is_intra_only(cm);
176 sf->use_square_partition_only = !frame_is_intra_only(cm);
179 sf->allow_txfm_domain_distortion = 1;
180 sf->tx_domain_thresh = tx_dom_thresholds[(speed < 6) ? speed : 5];
181 sf->allow_quant_coeff_opt = sf->optimize_coefficients;
182 sf->quant_opt_thresh = qopt_thresholds[(speed < 6) ? speed : 5];
184 sf->use_square_only_threshold = BLOCK_4X4;
185 sf->less_rectangular_check = 1;
187 sf->use_rd_breakout = 1;
188 sf->adaptive_motion_search = 1;
189 sf->mv.auto_mv_step_size = 1;
190 sf->adaptive_rd_thresh = 2;
191 sf->mv.subpel_iters_per_step = 1;
192 sf->mode_skip_start = 10;
193 sf->adaptive_pred_interp_filter = 1;
196 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
197 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
198 sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
199 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
201 sf->recode_tolerance_low = 15;
202 sf->recode_tolerance_high = 30;
206 sf->recode_loop = ALLOW_RECODE_KFARFGF;
207 sf->tx_size_search_method =
208 frame_is_boosted(cpi) ? USE_FULL_RD : USE_LARGESTALL;
210 // Reference masking is not supported in dynamic scaling mode.
211 sf->reference_masking = cpi->oxcf.resize_mode != RESIZE_DYNAMIC ? 1 : 0;
213 sf->mode_search_skip_flags =
214 (cm->frame_type == KEY_FRAME)
216 : FLAG_SKIP_INTRA_DIRMISMATCH | FLAG_SKIP_INTRA_BESTINTER |
217 FLAG_SKIP_COMP_BESTINTRA | FLAG_SKIP_INTRA_LOWVAR;
218 sf->disable_filter_search_var_thresh = 100;
219 sf->comp_inter_joint_search_thresh = BLOCK_SIZES;
220 sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
221 sf->allow_partition_search_skip = 1;
222 sf->recode_tolerance_low = 15;
223 sf->recode_tolerance_high = 45;
227 sf->use_square_partition_only = !frame_is_intra_only(cm);
228 sf->tx_size_search_method =
229 frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL;
230 sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED;
231 sf->adaptive_pred_interp_filter = 0;
232 sf->adaptive_mode_search = 1;
233 sf->cb_partition_search = !boosted;
234 sf->cb_pred_filter_search = 1;
235 sf->alt_ref_search_fp = 1;
236 sf->recode_loop = ALLOW_RECODE_KFMAXBW;
237 sf->adaptive_rd_thresh = 3;
238 sf->mode_skip_start = 6;
239 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
240 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC;
241 sf->adaptive_interp_filter_search = 1;
245 sf->use_square_partition_only = 1;
246 sf->tx_size_search_method = USE_LARGESTALL;
247 sf->mv.search_method = BIGDIA;
248 sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
249 sf->adaptive_rd_thresh = 4;
250 if (cm->frame_type != KEY_FRAME)
251 sf->mode_search_skip_flags |= FLAG_EARLY_TERMINATE;
252 sf->disable_filter_search_var_thresh = 200;
253 sf->use_lp32x32fdct = 1;
254 sf->use_fast_coef_updates = ONE_LOOP_REDUCED;
255 sf->use_fast_coef_costing = 1;
256 sf->motion_field_mode_search = !boosted;
261 sf->optimize_coefficients = 0;
262 sf->mv.search_method = HEX;
263 sf->disable_filter_search_var_thresh = 500;
264 for (i = 0; i < TX_SIZES; ++i) {
265 sf->intra_y_mode_mask[i] = INTRA_DC;
266 sf->intra_uv_mode_mask[i] = INTRA_DC;
268 sf->mv.reduce_first_step_size = 1;
269 sf->simple_model_rd_from_var = 1;
273 static void set_rt_speed_feature_framesize_dependent(VP9_COMP *cpi,
276 VP9_COMMON *const cm = &cpi->common;
279 if (VPXMIN(cm->width, cm->height) >= 720) {
280 sf->disable_split_mask =
281 cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
283 sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
288 if (VPXMIN(cm->width, cm->height) >= 720) {
289 sf->disable_split_mask =
290 cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
292 sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY;
297 sf->partition_search_breakout_thr.rate = 200;
298 if (VPXMIN(cm->width, cm->height) >= 720) {
299 sf->partition_search_breakout_thr.dist = (1 << 25);
301 sf->partition_search_breakout_thr.dist = (1 << 23);
306 sf->encode_breakout_thresh =
307 (VPXMIN(cm->width, cm->height) >= 720) ? 800 : 300;
311 static void set_rt_speed_feature_framesize_independent(
312 VP9_COMP *cpi, SPEED_FEATURES *sf, int speed, vp9e_tune_content content) {
313 VP9_COMMON *const cm = &cpi->common;
314 const int is_keyframe = cm->frame_type == KEY_FRAME;
315 const int frames_since_key = is_keyframe ? 0 : cpi->rc.frames_since_key;
316 sf->static_segmentation = 0;
317 sf->adaptive_rd_thresh = 1;
318 sf->use_fast_coef_costing = 1;
319 sf->allow_exhaustive_searches = 0;
320 sf->exhaustive_searches_thresh = INT_MAX;
322 sf->copy_partition_flag = 0;
323 sf->use_source_sad = 0;
324 sf->use_simple_block_yrd = 0;
327 sf->allow_txfm_domain_distortion = 1;
328 sf->tx_domain_thresh = 0.0;
329 sf->allow_quant_coeff_opt = 0;
330 sf->quant_opt_thresh = 0.0;
331 sf->use_square_partition_only = !frame_is_intra_only(cm);
332 sf->less_rectangular_check = 1;
333 sf->tx_size_search_method =
334 frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL;
336 sf->use_rd_breakout = 1;
338 sf->adaptive_motion_search = 1;
339 sf->adaptive_pred_interp_filter = 1;
340 sf->mv.auto_mv_step_size = 1;
341 sf->adaptive_rd_thresh = 2;
342 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
343 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
344 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
348 sf->mode_search_skip_flags =
349 (cm->frame_type == KEY_FRAME)
351 : FLAG_SKIP_INTRA_DIRMISMATCH | FLAG_SKIP_INTRA_BESTINTER |
352 FLAG_SKIP_COMP_BESTINTRA | FLAG_SKIP_INTRA_LOWVAR;
353 sf->adaptive_pred_interp_filter = 2;
355 // Reference masking only enabled for 1 spatial layer, and if none of the
356 // references have been scaled. The latter condition needs to be checked
357 // for external or internal dynamic resize.
358 sf->reference_masking = (cpi->svc.number_spatial_layers == 1);
359 if (sf->reference_masking == 1 &&
360 (cpi->external_resize == 1 ||
361 cpi->oxcf.resize_mode == RESIZE_DYNAMIC)) {
362 MV_REFERENCE_FRAME ref_frame;
363 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG,
365 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
366 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame);
367 if (yv12 != NULL && (cpi->ref_frame_flags & flag_list[ref_frame])) {
368 const struct scale_factors *const scale_fac =
369 &cm->frame_refs[ref_frame - 1].sf;
370 if (vp9_is_scaled(scale_fac)) sf->reference_masking = 0;
375 sf->disable_filter_search_var_thresh = 50;
376 sf->comp_inter_joint_search_thresh = BLOCK_SIZES;
377 sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
378 sf->lf_motion_threshold = LOW_MOTION_THRESHOLD;
379 sf->adjust_partitioning_from_last_frame = 1;
380 sf->last_partitioning_redo_frequency = 3;
381 sf->use_lp32x32fdct = 1;
382 sf->mode_skip_start = 11;
383 sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
387 sf->use_square_partition_only = 1;
388 sf->disable_filter_search_var_thresh = 100;
389 sf->use_uv_intra_rd_estimate = 1;
390 sf->skip_encode_sb = 1;
391 sf->mv.subpel_iters_per_step = 1;
392 sf->adaptive_rd_thresh = 4;
393 sf->mode_skip_start = 6;
394 sf->allow_skip_recode = 0;
395 sf->optimize_coefficients = 0;
396 sf->disable_split_mask = DISABLE_ALL_SPLIT;
397 sf->lpf_pick = LPF_PICK_FROM_Q;
402 sf->last_partitioning_redo_frequency = 4;
403 sf->adaptive_rd_thresh = 5;
404 sf->use_fast_coef_costing = 0;
405 sf->auto_min_max_partition_size = STRICT_NEIGHBORING_MIN_MAX;
406 sf->adjust_partitioning_from_last_frame =
407 cm->last_frame_type != cm->frame_type ||
408 (0 == (frames_since_key + 1) % sf->last_partitioning_redo_frequency);
409 sf->mv.subpel_force_stop = 1;
410 for (i = 0; i < TX_SIZES; i++) {
411 sf->intra_y_mode_mask[i] = INTRA_DC_H_V;
412 sf->intra_uv_mode_mask[i] = INTRA_DC;
414 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
415 sf->frame_parameter_update = 0;
416 sf->mv.search_method = FAST_HEX;
418 sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEAR_NEW;
419 sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST;
420 sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST;
421 sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST;
422 sf->max_intra_bsize = BLOCK_32X32;
423 sf->allow_skip_recode = 1;
427 sf->use_quant_fp = !is_keyframe;
428 sf->auto_min_max_partition_size =
429 is_keyframe ? RELAXED_NEIGHBORING_MIN_MAX : STRICT_NEIGHBORING_MIN_MAX;
430 sf->default_max_partition_size = BLOCK_32X32;
431 sf->default_min_partition_size = BLOCK_8X8;
432 sf->force_frame_boost =
434 (frames_since_key % (sf->last_partitioning_redo_frequency << 1) == 1);
435 sf->max_delta_qindex = is_keyframe ? 20 : 15;
436 sf->partition_search_type = REFERENCE_PARTITION;
437 if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0 &&
438 cpi->rc.is_src_frame_alt_ref) {
439 sf->partition_search_type = VAR_BASED_PARTITION;
441 sf->use_nonrd_pick_mode = 1;
442 sf->allow_skip_recode = 0;
443 sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEW_ZERO;
444 sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST_NEW_ZERO;
445 sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST_NEW_ZERO;
446 sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST_NEW_ZERO;
447 sf->adaptive_rd_thresh = 2;
448 // This feature is only enabled when partition search is disabled.
449 sf->reuse_inter_pred_sby = 1;
450 sf->coeff_prob_appx_step = 4;
451 sf->use_fast_coef_updates = is_keyframe ? TWO_LOOP : ONE_LOOP_REDUCED;
452 sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH;
453 sf->tx_size_search_method = is_keyframe ? USE_LARGESTALL : USE_TX_8X8;
454 sf->simple_model_rd_from_var = 1;
455 if (cpi->oxcf.rc_mode == VPX_VBR) sf->mv.search_method = NSTEP;
459 if (content == VP9E_CONTENT_SCREEN) {
460 for (i = 0; i < BLOCK_SIZES; ++i)
461 sf->intra_y_mode_bsize_mask[i] = INTRA_DC_TM_H_V;
463 for (i = 0; i < BLOCK_SIZES; ++i)
465 sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
467 // Use H and V intra mode for block sizes <= 16X16.
468 sf->intra_y_mode_bsize_mask[i] = INTRA_DC_H_V;
471 if (content == VP9E_CONTENT_SCREEN) {
472 sf->short_circuit_flat_blocks = 1;
474 if (cpi->oxcf.rc_mode == VPX_CBR &&
475 cpi->oxcf.content != VP9E_CONTENT_SCREEN && !cpi->use_svc) {
476 sf->limit_newmv_early_exit = 1;
482 sf->partition_search_type = VAR_BASED_PARTITION;
483 // Turn on this to use non-RD key frame coding mode.
484 sf->use_nonrd_pick_mode = 1;
485 sf->mv.search_method = NSTEP;
486 sf->mv.reduce_first_step_size = 1;
487 sf->skip_encode_sb = 0;
488 if (!cpi->use_svc && cpi->oxcf.rc_mode == VPX_CBR &&
489 content != VP9E_CONTENT_SCREEN) {
490 // Enable short circuit for low temporal variance.
491 sf->short_circuit_low_temp_var = 1;
493 if (cpi->use_svc) sf->base_mv_aggressive = 1;
497 sf->adaptive_rd_thresh = 3;
498 sf->mv.search_method = FAST_DIAMOND;
499 sf->mv.fullpel_search_step_param = 10;
500 if (cpi->svc.number_temporal_layers > 2 &&
501 cpi->svc.temporal_layer_id == 0) {
502 sf->mv.search_method = NSTEP;
503 sf->mv.fullpel_search_step_param = 6;
505 if (!cpi->use_svc && !cpi->resize_pending && !cpi->resize_state &&
506 !cpi->external_resize && cpi->oxcf.resize_mode == RESIZE_NONE)
507 sf->use_source_sad = 1;
508 if (sf->use_source_sad) {
509 if (cpi->content_state_sb == NULL) {
510 cpi->content_state_sb = (uint8_t *)vpx_calloc(
511 (cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1), sizeof(uint8_t));
517 sf->adaptive_rd_thresh = 4;
518 // Enable partition copy
519 if (!cpi->use_svc && !cpi->resize_pending && !cpi->resize_state &&
520 !cpi->external_resize && cpi->oxcf.resize_mode == RESIZE_NONE)
521 sf->copy_partition_flag = 1;
523 if (sf->copy_partition_flag) {
524 cpi->max_copied_frame = 5;
525 if (cpi->prev_partition == NULL) {
526 cpi->prev_partition = (BLOCK_SIZE *)vpx_calloc(
527 cm->mi_stride * cm->mi_rows, sizeof(BLOCK_SIZE));
529 if (cpi->prev_segment_id == NULL) {
530 cpi->prev_segment_id = (int8_t *)vpx_calloc(
531 (cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1), sizeof(int8_t));
533 if (cpi->prev_variance_low == NULL) {
534 cpi->prev_variance_low = (uint8_t *)vpx_calloc(
535 (cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1) * 25,
538 if (cpi->copied_frame_cnt == NULL) {
539 cpi->copied_frame_cnt = (uint8_t *)vpx_calloc(
540 (cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1), sizeof(uint8_t));
544 sf->mv.subpel_force_stop = (content == VP9E_CONTENT_SCREEN) ? 3 : 2;
545 if (content == VP9E_CONTENT_SCREEN) sf->lpf_pick = LPF_PICK_MINIMAL_LPF;
546 // Only keep INTRA_DC mode for speed 8.
549 for (i = 0; i < BLOCK_SIZES; ++i)
550 sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
552 if (!cpi->use_svc && cpi->oxcf.rc_mode == VPX_CBR &&
553 content != VP9E_CONTENT_SCREEN) {
554 // More aggressive short circuit for speed 8.
555 sf->short_circuit_low_temp_var = 3;
556 // Use level 2 for noisey cases as there is a regression in some
557 // noisy clips with level 3.
558 if (cpi->noise_estimate.enabled && cm->width >= 1280 &&
560 NOISE_LEVEL noise_level =
561 vp9_noise_estimate_extract_level(&cpi->noise_estimate);
562 if (noise_level >= kMedium) sf->short_circuit_low_temp_var = 2;
564 // Since the short_circuit_low_temp_var is used, reduce the
565 // adaptive_rd_thresh level.
566 sf->adaptive_rd_thresh = 2;
568 sf->limit_newmv_early_exit = 0;
569 sf->use_simple_block_yrd = 0;
571 // Turn off adaptive_rd_thresh if row_mt is on for all the non-rd paths. This
572 // causes too many locks in realtime mode in certain platforms (Android ARM,
574 if (speed >= 5 && cpi->row_mt && cpi->num_workers > 1) {
575 sf->adaptive_rd_thresh = 0;
579 void vp9_set_speed_features_framesize_dependent(VP9_COMP *cpi) {
580 SPEED_FEATURES *const sf = &cpi->sf;
581 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
582 RD_OPT *const rd = &cpi->rd;
585 // best quality defaults
586 // Some speed-up features even for best quality as minimal impact on quality.
587 sf->partition_search_breakout_thr.dist = (1 << 19);
588 sf->partition_search_breakout_thr.rate = 80;
590 if (oxcf->mode == REALTIME) {
591 set_rt_speed_feature_framesize_dependent(cpi, sf, oxcf->speed);
592 } else if (oxcf->mode == GOOD) {
593 set_good_speed_feature_framesize_dependent(cpi, sf, oxcf->speed);
596 if (sf->disable_split_mask == DISABLE_ALL_SPLIT) {
597 sf->adaptive_pred_interp_filter = 0;
600 if (cpi->encode_breakout && oxcf->mode == REALTIME &&
601 sf->encode_breakout_thresh > cpi->encode_breakout) {
602 cpi->encode_breakout = sf->encode_breakout_thresh;
605 // Check for masked out split cases.
606 for (i = 0; i < MAX_REFS; ++i) {
607 if (sf->disable_split_mask & (1 << i)) {
608 rd->thresh_mult_sub8x8[i] = INT_MAX;
612 // With row based multi-threading, the following speed features
613 // have to be disabled to guarantee that bitstreams encoded with single thread
614 // and multiple threads match
615 if (cpi->oxcf.row_mt_bit_exact) {
616 sf->adaptive_rd_thresh = 0;
617 sf->allow_exhaustive_searches = 0;
618 sf->adaptive_pred_interp_filter = 0;
622 void vp9_set_speed_features_framesize_independent(VP9_COMP *cpi) {
623 SPEED_FEATURES *const sf = &cpi->sf;
624 VP9_COMMON *const cm = &cpi->common;
625 MACROBLOCK *const x = &cpi->td.mb;
626 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
629 // best quality defaults
630 sf->frame_parameter_update = 1;
631 sf->mv.search_method = NSTEP;
632 sf->recode_loop = ALLOW_RECODE_FIRST;
633 sf->mv.subpel_search_method = SUBPEL_TREE;
634 sf->mv.subpel_iters_per_step = 2;
635 sf->mv.subpel_force_stop = 0;
636 sf->optimize_coefficients = !is_lossless_requested(&cpi->oxcf);
637 sf->mv.reduce_first_step_size = 0;
638 sf->coeff_prob_appx_step = 1;
639 sf->mv.auto_mv_step_size = 0;
640 sf->mv.fullpel_search_step_param = 6;
641 sf->comp_inter_joint_search_thresh = BLOCK_4X4;
642 sf->tx_size_search_method = USE_FULL_RD;
643 sf->use_lp32x32fdct = 0;
644 sf->adaptive_motion_search = 0;
645 sf->adaptive_pred_interp_filter = 0;
646 sf->adaptive_mode_search = 0;
647 sf->cb_pred_filter_search = 0;
648 sf->cb_partition_search = 0;
649 sf->motion_field_mode_search = 0;
650 sf->alt_ref_search_fp = 0;
651 sf->use_quant_fp = 0;
652 sf->reference_masking = 0;
653 sf->partition_search_type = SEARCH_PARTITION;
654 sf->less_rectangular_check = 0;
655 sf->use_square_partition_only = 0;
656 sf->use_square_only_threshold = BLOCK_SIZES;
657 sf->auto_min_max_partition_size = NOT_IN_USE;
658 sf->rd_auto_partition_min_limit = BLOCK_4X4;
659 sf->default_max_partition_size = BLOCK_64X64;
660 sf->default_min_partition_size = BLOCK_4X4;
661 sf->adjust_partitioning_from_last_frame = 0;
662 sf->last_partitioning_redo_frequency = 4;
663 sf->disable_split_mask = 0;
664 sf->mode_search_skip_flags = 0;
665 sf->force_frame_boost = 0;
666 sf->max_delta_qindex = 0;
667 sf->disable_filter_search_var_thresh = 0;
668 sf->adaptive_interp_filter_search = 0;
669 sf->allow_partition_search_skip = 0;
670 sf->allow_txfm_domain_distortion = 0;
671 sf->tx_domain_thresh = 99.0;
672 sf->allow_quant_coeff_opt = sf->optimize_coefficients;
673 sf->quant_opt_thresh = 99.0;
676 for (i = 0; i < TX_SIZES; i++) {
677 sf->intra_y_mode_mask[i] = INTRA_ALL;
678 sf->intra_uv_mode_mask[i] = INTRA_ALL;
680 sf->use_rd_breakout = 0;
681 sf->skip_encode_sb = 0;
682 sf->use_uv_intra_rd_estimate = 0;
683 sf->allow_skip_recode = 0;
684 sf->lpf_pick = LPF_PICK_FROM_FULL_IMAGE;
685 sf->use_fast_coef_updates = TWO_LOOP;
686 sf->use_fast_coef_costing = 0;
687 sf->mode_skip_start = MAX_MODES; // Mode index at which mode skip mask set
688 sf->schedule_mode_search = 0;
689 sf->use_nonrd_pick_mode = 0;
690 for (i = 0; i < BLOCK_SIZES; ++i) sf->inter_mode_mask[i] = INTER_ALL;
691 sf->max_intra_bsize = BLOCK_64X64;
692 sf->reuse_inter_pred_sby = 0;
693 // This setting only takes effect when partition_search_type is set
694 // to FIXED_PARTITION.
695 sf->always_this_block_size = BLOCK_16X16;
696 sf->search_type_check_frequency = 50;
697 sf->encode_breakout_thresh = 0;
698 // Recode loop tolerance %.
699 sf->recode_tolerance_low = 12;
700 sf->recode_tolerance_high = 25;
701 sf->default_interp_filter = SWITCHABLE;
702 sf->simple_model_rd_from_var = 0;
703 sf->short_circuit_flat_blocks = 0;
704 sf->short_circuit_low_temp_var = 0;
705 sf->limit_newmv_early_exit = 0;
707 sf->base_mv_aggressive = 0;
709 // Some speed-up features even for best quality as minimal impact on quality.
710 sf->adaptive_rd_thresh = 1;
711 sf->tx_size_search_breakout = 1;
713 if (oxcf->mode == REALTIME)
714 set_rt_speed_feature_framesize_independent(cpi, sf, oxcf->speed,
716 else if (oxcf->mode == GOOD)
717 set_good_speed_feature_framesize_independent(cpi, cm, sf, oxcf->speed);
719 cpi->full_search_sad = vp9_full_search_sad;
720 cpi->diamond_search_sad = vp9_diamond_search_sad;
722 sf->allow_exhaustive_searches = 1;
723 if (oxcf->mode == BEST) {
724 if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION)
725 sf->exhaustive_searches_thresh = (1 << 20);
727 sf->exhaustive_searches_thresh = (1 << 21);
728 sf->max_exaustive_pct = 100;
729 for (i = 0; i < MAX_MESH_STEP; ++i) {
730 sf->mesh_patterns[i].range = best_quality_mesh_pattern[i].range;
731 sf->mesh_patterns[i].interval = best_quality_mesh_pattern[i].interval;
734 int speed = (oxcf->speed > MAX_MESH_SPEED) ? MAX_MESH_SPEED : oxcf->speed;
735 if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION)
736 sf->exhaustive_searches_thresh = (1 << 22);
738 sf->exhaustive_searches_thresh = (1 << 23);
739 sf->max_exaustive_pct = good_quality_max_mesh_pct[speed];
741 sf->exhaustive_searches_thresh = sf->exhaustive_searches_thresh << 1;
743 for (i = 0; i < MAX_MESH_STEP; ++i) {
744 sf->mesh_patterns[i].range = good_quality_mesh_patterns[speed][i].range;
745 sf->mesh_patterns[i].interval =
746 good_quality_mesh_patterns[speed][i].interval;
750 // Slow quant, dct and trellis not worthwhile for first pass
751 // so make sure they are always turned off.
752 if (oxcf->pass == 1) sf->optimize_coefficients = 0;
754 // No recode for 1 pass.
755 if (oxcf->pass == 0) {
756 sf->recode_loop = DISALLOW_RECODE;
757 sf->optimize_coefficients = 0;
760 if (sf->mv.subpel_force_stop == 3) {
762 cpi->find_fractional_mv_step = vp9_skip_sub_pixel_tree;
763 } else if (sf->mv.subpel_search_method == SUBPEL_TREE) {
764 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree;
765 } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED) {
766 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned;
767 } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_MORE) {
768 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_more;
769 } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_EVENMORE) {
770 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_evenmore;
773 x->optimize = sf->optimize_coefficients == 1 && oxcf->pass != 1;
775 x->min_partition_size = sf->default_min_partition_size;
776 x->max_partition_size = sf->default_max_partition_size;
778 if (!cpi->oxcf.frame_periodic_boost) {
779 sf->max_delta_qindex = 0;
782 // With row based multi-threading, the following speed features
783 // have to be disabled to guarantee that bitstreams encoded with single thread
784 // and multiple threads match
785 if (cpi->oxcf.row_mt_bit_exact) {
786 sf->adaptive_rd_thresh = 0;
787 sf->allow_exhaustive_searches = 0;
788 sf->adaptive_pred_interp_filter = 0;