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;
74 // Currently, the machine-learning based partition search early termination
75 // is only used while VPXMIN(cm->width, cm->height) >= 480 and speed = 0.
76 if (VPXMIN(cm->width, cm->height) >= 480) {
77 sf->ml_partition_search_early_termination = 1;
81 sf->ml_partition_search_early_termination = 0;
83 if (VPXMIN(cm->width, cm->height) >= 720) {
84 sf->disable_split_mask =
85 cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
86 sf->partition_search_breakout_thr.dist = (1 << 23);
88 sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
89 sf->partition_search_breakout_thr.dist = (1 << 21);
94 if (VPXMIN(cm->width, cm->height) >= 720) {
95 sf->disable_split_mask =
96 cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
97 sf->adaptive_pred_interp_filter = 0;
98 sf->partition_search_breakout_thr.dist = (1 << 24);
99 sf->partition_search_breakout_thr.rate = 120;
101 sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY;
102 sf->partition_search_breakout_thr.dist = (1 << 22);
103 sf->partition_search_breakout_thr.rate = 100;
105 sf->rd_auto_partition_min_limit = set_partition_min_limit(cm);
107 // Use a set of speed features for 4k videos.
108 if (VPXMIN(cm->width, cm->height) >= 2160) {
109 sf->use_square_partition_only = 1;
110 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
111 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC;
112 sf->alt_ref_search_fp = 1;
113 sf->cb_pred_filter_search = 1;
114 sf->adaptive_interp_filter_search = 1;
115 sf->disable_split_mask = DISABLE_ALL_SPLIT;
120 if (VPXMIN(cm->width, cm->height) >= 720) {
121 sf->disable_split_mask = DISABLE_ALL_SPLIT;
122 sf->schedule_mode_search = cm->base_qindex < 220 ? 1 : 0;
123 sf->partition_search_breakout_thr.dist = (1 << 25);
124 sf->partition_search_breakout_thr.rate = 200;
126 sf->max_intra_bsize = BLOCK_32X32;
127 sf->disable_split_mask = DISABLE_ALL_INTER_SPLIT;
128 sf->schedule_mode_search = cm->base_qindex < 175 ? 1 : 0;
129 sf->partition_search_breakout_thr.dist = (1 << 23);
130 sf->partition_search_breakout_thr.rate = 120;
134 // If this is a two pass clip that fits the criteria for animated or
135 // graphics content then reset disable_split_mask for speeds 1-4.
136 // Also if the image edge is internal to the coded area.
137 if ((speed >= 1) && (cpi->oxcf.pass == 2) &&
138 ((cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ||
139 (vp9_internal_image_edge(cpi)))) {
140 sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
144 sf->partition_search_breakout_thr.rate = 300;
145 if (VPXMIN(cm->width, cm->height) >= 720) {
146 sf->partition_search_breakout_thr.dist = (1 << 26);
148 sf->partition_search_breakout_thr.dist = (1 << 24);
150 sf->disable_split_mask = DISABLE_ALL_SPLIT;
154 sf->partition_search_breakout_thr.rate = 500;
158 static double tx_dom_thresholds[6] = { 99.0, 14.0, 12.0, 8.0, 4.0, 0.0 };
159 static double qopt_thresholds[6] = { 99.0, 12.0, 10.0, 4.0, 2.0, 0.0 };
161 static void set_good_speed_feature_framesize_independent(VP9_COMP *cpi,
165 const int boosted = frame_is_boosted(cpi);
167 sf->tx_size_search_breakout = 1;
168 sf->adaptive_rd_thresh = 1;
169 sf->allow_skip_recode = 1;
170 sf->less_rectangular_check = 1;
171 sf->use_square_partition_only = !frame_is_boosted(cpi);
172 sf->use_square_only_threshold = BLOCK_16X16;
175 if (cpi->oxcf.pass == 2) {
176 TWO_PASS *const twopass = &cpi->twopass;
177 if ((twopass->fr_content_type == FC_GRAPHICS_ANIMATION) ||
178 vp9_internal_image_edge(cpi)) {
179 sf->use_square_partition_only = !frame_is_boosted(cpi);
181 sf->use_square_partition_only = !frame_is_intra_only(cm);
184 sf->use_square_partition_only = !frame_is_intra_only(cm);
187 sf->allow_txfm_domain_distortion = 1;
188 sf->tx_domain_thresh = tx_dom_thresholds[(speed < 6) ? speed : 5];
189 sf->allow_quant_coeff_opt = sf->optimize_coefficients;
190 sf->quant_opt_thresh = qopt_thresholds[(speed < 6) ? speed : 5];
192 sf->use_square_only_threshold = BLOCK_4X4;
193 sf->less_rectangular_check = 1;
195 sf->use_rd_breakout = 1;
196 sf->adaptive_motion_search = 1;
197 sf->mv.auto_mv_step_size = 1;
198 sf->adaptive_rd_thresh = 2;
199 sf->mv.subpel_iters_per_step = 1;
200 sf->mode_skip_start = 10;
201 sf->adaptive_pred_interp_filter = 1;
204 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
205 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
206 sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
207 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
209 sf->recode_tolerance_low = 15;
210 sf->recode_tolerance_high = 30;
214 sf->recode_loop = ALLOW_RECODE_KFARFGF;
215 sf->tx_size_search_method =
216 frame_is_boosted(cpi) ? USE_FULL_RD : USE_LARGESTALL;
218 // Reference masking is not supported in dynamic scaling mode.
219 sf->reference_masking = cpi->oxcf.resize_mode != RESIZE_DYNAMIC ? 1 : 0;
221 sf->mode_search_skip_flags =
222 (cm->frame_type == KEY_FRAME)
224 : FLAG_SKIP_INTRA_DIRMISMATCH | FLAG_SKIP_INTRA_BESTINTER |
225 FLAG_SKIP_COMP_BESTINTRA | FLAG_SKIP_INTRA_LOWVAR;
226 sf->disable_filter_search_var_thresh = 100;
227 sf->comp_inter_joint_search_thresh = BLOCK_SIZES;
228 sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
229 sf->allow_partition_search_skip = 1;
230 sf->recode_tolerance_low = 15;
231 sf->recode_tolerance_high = 45;
235 sf->use_square_partition_only = !frame_is_intra_only(cm);
236 sf->tx_size_search_method =
237 frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL;
238 sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED;
239 sf->adaptive_pred_interp_filter = 0;
240 sf->adaptive_mode_search = 1;
241 sf->cb_partition_search = !boosted;
242 sf->cb_pred_filter_search = 1;
243 sf->alt_ref_search_fp = 1;
244 sf->recode_loop = ALLOW_RECODE_KFMAXBW;
245 sf->adaptive_rd_thresh = 3;
246 sf->mode_skip_start = 6;
247 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
248 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC;
249 sf->adaptive_interp_filter_search = 1;
253 sf->use_square_partition_only = 1;
254 sf->tx_size_search_method = USE_LARGESTALL;
255 sf->mv.search_method = BIGDIA;
256 sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
257 sf->adaptive_rd_thresh = 4;
258 if (cm->frame_type != KEY_FRAME)
259 sf->mode_search_skip_flags |= FLAG_EARLY_TERMINATE;
260 sf->disable_filter_search_var_thresh = 200;
261 sf->use_lp32x32fdct = 1;
262 sf->use_fast_coef_updates = ONE_LOOP_REDUCED;
263 sf->use_fast_coef_costing = 1;
264 sf->motion_field_mode_search = !boosted;
269 sf->optimize_coefficients = 0;
270 sf->mv.search_method = HEX;
271 sf->disable_filter_search_var_thresh = 500;
272 for (i = 0; i < TX_SIZES; ++i) {
273 sf->intra_y_mode_mask[i] = INTRA_DC;
274 sf->intra_uv_mode_mask[i] = INTRA_DC;
276 sf->mv.reduce_first_step_size = 1;
277 sf->simple_model_rd_from_var = 1;
281 static void set_rt_speed_feature_framesize_dependent(VP9_COMP *cpi,
284 VP9_COMMON *const cm = &cpi->common;
287 if (VPXMIN(cm->width, cm->height) >= 720) {
288 sf->disable_split_mask =
289 cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
291 sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
296 if (VPXMIN(cm->width, cm->height) >= 720) {
297 sf->disable_split_mask =
298 cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
300 sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY;
305 sf->partition_search_breakout_thr.rate = 200;
306 if (VPXMIN(cm->width, cm->height) >= 720) {
307 sf->partition_search_breakout_thr.dist = (1 << 25);
309 sf->partition_search_breakout_thr.dist = (1 << 23);
314 sf->encode_breakout_thresh =
315 (VPXMIN(cm->width, cm->height) >= 720) ? 800 : 300;
319 static void set_rt_speed_feature_framesize_independent(
320 VP9_COMP *cpi, SPEED_FEATURES *sf, int speed, vp9e_tune_content content) {
321 VP9_COMMON *const cm = &cpi->common;
322 const int is_keyframe = cm->frame_type == KEY_FRAME;
323 const int frames_since_key = is_keyframe ? 0 : cpi->rc.frames_since_key;
324 sf->static_segmentation = 0;
325 sf->adaptive_rd_thresh = 1;
326 sf->use_fast_coef_costing = 1;
327 sf->allow_exhaustive_searches = 0;
328 sf->exhaustive_searches_thresh = INT_MAX;
330 sf->copy_partition_flag = 0;
331 sf->use_source_sad = 0;
332 sf->use_simple_block_yrd = 0;
335 sf->allow_txfm_domain_distortion = 1;
336 sf->tx_domain_thresh = 0.0;
337 sf->allow_quant_coeff_opt = 0;
338 sf->quant_opt_thresh = 0.0;
339 sf->use_square_partition_only = !frame_is_intra_only(cm);
340 sf->less_rectangular_check = 1;
341 sf->tx_size_search_method =
342 frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL;
344 sf->use_rd_breakout = 1;
346 sf->adaptive_motion_search = 1;
347 sf->adaptive_pred_interp_filter = 1;
348 sf->mv.auto_mv_step_size = 1;
349 sf->adaptive_rd_thresh = 2;
350 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
351 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
352 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
356 sf->mode_search_skip_flags =
357 (cm->frame_type == KEY_FRAME)
359 : FLAG_SKIP_INTRA_DIRMISMATCH | FLAG_SKIP_INTRA_BESTINTER |
360 FLAG_SKIP_COMP_BESTINTRA | FLAG_SKIP_INTRA_LOWVAR;
361 sf->adaptive_pred_interp_filter = 2;
363 // Reference masking only enabled for 1 spatial layer, and if none of the
364 // references have been scaled. The latter condition needs to be checked
365 // for external or internal dynamic resize.
366 sf->reference_masking = (cpi->svc.number_spatial_layers == 1);
367 if (sf->reference_masking == 1 &&
368 (cpi->external_resize == 1 ||
369 cpi->oxcf.resize_mode == RESIZE_DYNAMIC)) {
370 MV_REFERENCE_FRAME ref_frame;
371 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG,
373 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
374 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame);
375 if (yv12 != NULL && (cpi->ref_frame_flags & flag_list[ref_frame])) {
376 const struct scale_factors *const scale_fac =
377 &cm->frame_refs[ref_frame - 1].sf;
378 if (vp9_is_scaled(scale_fac)) sf->reference_masking = 0;
383 sf->disable_filter_search_var_thresh = 50;
384 sf->comp_inter_joint_search_thresh = BLOCK_SIZES;
385 sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
386 sf->lf_motion_threshold = LOW_MOTION_THRESHOLD;
387 sf->adjust_partitioning_from_last_frame = 1;
388 sf->last_partitioning_redo_frequency = 3;
389 sf->use_lp32x32fdct = 1;
390 sf->mode_skip_start = 11;
391 sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
395 sf->use_square_partition_only = 1;
396 sf->disable_filter_search_var_thresh = 100;
397 sf->use_uv_intra_rd_estimate = 1;
398 sf->skip_encode_sb = 1;
399 sf->mv.subpel_iters_per_step = 1;
400 sf->adaptive_rd_thresh = 4;
401 sf->mode_skip_start = 6;
402 sf->allow_skip_recode = 0;
403 sf->optimize_coefficients = 0;
404 sf->disable_split_mask = DISABLE_ALL_SPLIT;
405 sf->lpf_pick = LPF_PICK_FROM_Q;
410 sf->last_partitioning_redo_frequency = 4;
411 sf->adaptive_rd_thresh = 5;
412 sf->use_fast_coef_costing = 0;
413 sf->auto_min_max_partition_size = STRICT_NEIGHBORING_MIN_MAX;
414 sf->adjust_partitioning_from_last_frame =
415 cm->last_frame_type != cm->frame_type ||
416 (0 == (frames_since_key + 1) % sf->last_partitioning_redo_frequency);
417 sf->mv.subpel_force_stop = 1;
418 for (i = 0; i < TX_SIZES; i++) {
419 sf->intra_y_mode_mask[i] = INTRA_DC_H_V;
420 sf->intra_uv_mode_mask[i] = INTRA_DC;
422 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
423 sf->frame_parameter_update = 0;
424 sf->mv.search_method = FAST_HEX;
426 sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEAR_NEW;
427 sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST;
428 sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST;
429 sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST;
430 sf->max_intra_bsize = BLOCK_32X32;
431 sf->allow_skip_recode = 1;
435 sf->use_quant_fp = !is_keyframe;
436 sf->auto_min_max_partition_size =
437 is_keyframe ? RELAXED_NEIGHBORING_MIN_MAX : STRICT_NEIGHBORING_MIN_MAX;
438 sf->default_max_partition_size = BLOCK_32X32;
439 sf->default_min_partition_size = BLOCK_8X8;
440 sf->force_frame_boost =
442 (frames_since_key % (sf->last_partitioning_redo_frequency << 1) == 1);
443 sf->max_delta_qindex = is_keyframe ? 20 : 15;
444 sf->partition_search_type = REFERENCE_PARTITION;
445 if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0 &&
446 cpi->rc.is_src_frame_alt_ref) {
447 sf->partition_search_type = VAR_BASED_PARTITION;
449 sf->use_nonrd_pick_mode = 1;
450 sf->allow_skip_recode = 0;
451 sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEW_ZERO;
452 sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST_NEW_ZERO;
453 sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST_NEW_ZERO;
454 sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST_NEW_ZERO;
455 sf->adaptive_rd_thresh = 2;
456 // This feature is only enabled when partition search is disabled.
457 sf->reuse_inter_pred_sby = 1;
458 sf->coeff_prob_appx_step = 4;
459 sf->use_fast_coef_updates = is_keyframe ? TWO_LOOP : ONE_LOOP_REDUCED;
460 sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH;
461 sf->tx_size_search_method = is_keyframe ? USE_LARGESTALL : USE_TX_8X8;
462 sf->simple_model_rd_from_var = 1;
463 if (cpi->oxcf.rc_mode == VPX_VBR) sf->mv.search_method = NSTEP;
467 if (content == VP9E_CONTENT_SCREEN) {
468 for (i = 0; i < BLOCK_SIZES; ++i)
469 sf->intra_y_mode_bsize_mask[i] = INTRA_DC_TM_H_V;
471 for (i = 0; i < BLOCK_SIZES; ++i)
473 sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
475 // Use H and V intra mode for block sizes <= 16X16.
476 sf->intra_y_mode_bsize_mask[i] = INTRA_DC_H_V;
479 if (content == VP9E_CONTENT_SCREEN) {
480 sf->short_circuit_flat_blocks = 1;
482 if (cpi->oxcf.rc_mode == VPX_CBR &&
483 cpi->oxcf.content != VP9E_CONTENT_SCREEN) {
484 sf->limit_newmv_early_exit = 1;
485 if (!cpi->use_svc) sf->bias_golden = 1;
490 sf->partition_search_type = VAR_BASED_PARTITION;
491 // Turn on this to use non-RD key frame coding mode.
492 sf->use_nonrd_pick_mode = 1;
493 sf->mv.search_method = NSTEP;
494 sf->mv.reduce_first_step_size = 1;
495 sf->skip_encode_sb = 0;
496 if (cpi->oxcf.rc_mode == VPX_CBR && content != VP9E_CONTENT_SCREEN) {
497 // Enable short circuit for low temporal variance.
498 sf->short_circuit_low_temp_var = 1;
500 if (cpi->use_svc) sf->base_mv_aggressive = 1;
504 sf->adaptive_rd_thresh = 3;
505 sf->mv.search_method = FAST_DIAMOND;
506 sf->mv.fullpel_search_step_param = 10;
507 if (cpi->svc.number_temporal_layers > 2 &&
508 cpi->svc.temporal_layer_id == 0) {
509 sf->mv.search_method = NSTEP;
510 sf->mv.fullpel_search_step_param = 6;
512 if (!cpi->external_resize) sf->use_source_sad = 1;
513 if (sf->use_source_sad) {
514 // For SVC allocate for top layer.
515 if (cpi->content_state_sb == NULL &&
517 cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1)) {
518 cpi->content_state_sb = (uint8_t *)vpx_calloc(
519 (cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1), sizeof(uint8_t));
520 cpi->content_state_sb_fd = (uint8_t *)vpx_calloc(
521 (cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1), sizeof(uint8_t));
527 sf->adaptive_rd_thresh = 4;
528 // Enable partition copy
529 if (!cpi->use_svc && !cpi->resize_pending && cpi->resize_state == ORIG &&
530 !cpi->external_resize && cpi->oxcf.resize_mode == RESIZE_NONE)
531 sf->copy_partition_flag = 1;
533 if (sf->copy_partition_flag) {
534 cpi->max_copied_frame = 4;
535 if (cpi->prev_partition == NULL) {
536 cpi->prev_partition = (BLOCK_SIZE *)vpx_calloc(
537 cm->mi_stride * cm->mi_rows, sizeof(BLOCK_SIZE));
539 if (cpi->prev_segment_id == NULL) {
540 cpi->prev_segment_id = (int8_t *)vpx_calloc(
541 (cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1), sizeof(int8_t));
543 if (cpi->prev_variance_low == NULL) {
544 cpi->prev_variance_low = (uint8_t *)vpx_calloc(
545 (cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1) * 25,
548 if (cpi->copied_frame_cnt == NULL) {
549 cpi->copied_frame_cnt = (uint8_t *)vpx_calloc(
550 (cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1), sizeof(uint8_t));
554 sf->mv.subpel_force_stop = (content == VP9E_CONTENT_SCREEN) ? 3 : 2;
555 if (content == VP9E_CONTENT_SCREEN) sf->lpf_pick = LPF_PICK_MINIMAL_LPF;
556 // Only keep INTRA_DC mode for speed 8.
559 for (i = 0; i < BLOCK_SIZES; ++i)
560 sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
562 if (!cpi->use_svc && cpi->oxcf.rc_mode == VPX_CBR &&
563 content != VP9E_CONTENT_SCREEN) {
564 // More aggressive short circuit for speed 8.
565 sf->short_circuit_low_temp_var = 3;
566 // Use level 2 for noisey cases as there is a regression in some
567 // noisy clips with level 3.
568 if (cpi->noise_estimate.enabled && cm->width >= 1280 &&
570 NOISE_LEVEL noise_level =
571 vp9_noise_estimate_extract_level(&cpi->noise_estimate);
572 if (noise_level >= kMedium) sf->short_circuit_low_temp_var = 2;
574 // Since the short_circuit_low_temp_var is used, reduce the
575 // adaptive_rd_thresh level.
576 sf->adaptive_rd_thresh = 1;
578 sf->limit_newmv_early_exit = 0;
579 if (cm->width > 320 && cm->height > 240) sf->use_simple_block_yrd = 1;
581 // Turn off adaptive_rd_thresh if row_mt is on for all the non-rd paths. This
582 // causes too many locks in realtime mode in certain platforms (Android ARM,
584 if (speed >= 5 && cpi->row_mt && cpi->num_workers > 1) {
585 sf->adaptive_rd_thresh = 0;
589 void vp9_set_speed_features_framesize_dependent(VP9_COMP *cpi) {
590 SPEED_FEATURES *const sf = &cpi->sf;
591 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
592 RD_OPT *const rd = &cpi->rd;
595 // best quality defaults
596 // Some speed-up features even for best quality as minimal impact on quality.
597 sf->partition_search_breakout_thr.dist = (1 << 19);
598 sf->partition_search_breakout_thr.rate = 80;
599 sf->ml_partition_search_early_termination = 0;
601 if (oxcf->mode == REALTIME) {
602 set_rt_speed_feature_framesize_dependent(cpi, sf, oxcf->speed);
603 } else if (oxcf->mode == GOOD) {
604 set_good_speed_feature_framesize_dependent(cpi, sf, oxcf->speed);
607 if (sf->disable_split_mask == DISABLE_ALL_SPLIT) {
608 sf->adaptive_pred_interp_filter = 0;
611 if (cpi->encode_breakout && oxcf->mode == REALTIME &&
612 sf->encode_breakout_thresh > cpi->encode_breakout) {
613 cpi->encode_breakout = sf->encode_breakout_thresh;
616 // Check for masked out split cases.
617 for (i = 0; i < MAX_REFS; ++i) {
618 if (sf->disable_split_mask & (1 << i)) {
619 rd->thresh_mult_sub8x8[i] = INT_MAX;
623 // With row based multi-threading, the following speed features
624 // have to be disabled to guarantee that bitstreams encoded with single thread
625 // and multiple threads match
626 if (cpi->oxcf.row_mt_bit_exact) {
627 sf->adaptive_rd_thresh = 0;
628 sf->allow_exhaustive_searches = 0;
629 sf->adaptive_pred_interp_filter = 0;
633 void vp9_set_speed_features_framesize_independent(VP9_COMP *cpi) {
634 SPEED_FEATURES *const sf = &cpi->sf;
635 VP9_COMMON *const cm = &cpi->common;
636 MACROBLOCK *const x = &cpi->td.mb;
637 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
640 // best quality defaults
641 sf->frame_parameter_update = 1;
642 sf->mv.search_method = NSTEP;
643 sf->recode_loop = ALLOW_RECODE_FIRST;
644 sf->mv.subpel_search_method = SUBPEL_TREE;
645 sf->mv.subpel_iters_per_step = 2;
646 sf->mv.subpel_force_stop = 0;
647 sf->optimize_coefficients = !is_lossless_requested(&cpi->oxcf);
648 sf->mv.reduce_first_step_size = 0;
649 sf->coeff_prob_appx_step = 1;
650 sf->mv.auto_mv_step_size = 0;
651 sf->mv.fullpel_search_step_param = 6;
652 sf->comp_inter_joint_search_thresh = BLOCK_4X4;
653 sf->tx_size_search_method = USE_FULL_RD;
654 sf->use_lp32x32fdct = 0;
655 sf->adaptive_motion_search = 0;
656 sf->adaptive_pred_interp_filter = 0;
657 sf->adaptive_mode_search = 0;
658 sf->cb_pred_filter_search = 0;
659 sf->cb_partition_search = 0;
660 sf->motion_field_mode_search = 0;
661 sf->alt_ref_search_fp = 0;
662 sf->use_quant_fp = 0;
663 sf->reference_masking = 0;
664 sf->partition_search_type = SEARCH_PARTITION;
665 sf->less_rectangular_check = 0;
666 sf->use_square_partition_only = 0;
667 sf->use_square_only_threshold = BLOCK_SIZES;
668 sf->auto_min_max_partition_size = NOT_IN_USE;
669 sf->rd_auto_partition_min_limit = BLOCK_4X4;
670 sf->default_max_partition_size = BLOCK_64X64;
671 sf->default_min_partition_size = BLOCK_4X4;
672 sf->adjust_partitioning_from_last_frame = 0;
673 sf->last_partitioning_redo_frequency = 4;
674 sf->disable_split_mask = 0;
675 sf->mode_search_skip_flags = 0;
676 sf->force_frame_boost = 0;
677 sf->max_delta_qindex = 0;
678 sf->disable_filter_search_var_thresh = 0;
679 sf->adaptive_interp_filter_search = 0;
680 sf->allow_partition_search_skip = 0;
681 sf->allow_txfm_domain_distortion = 0;
682 sf->tx_domain_thresh = 99.0;
683 sf->allow_quant_coeff_opt = sf->optimize_coefficients;
684 sf->quant_opt_thresh = 99.0;
687 for (i = 0; i < TX_SIZES; i++) {
688 sf->intra_y_mode_mask[i] = INTRA_ALL;
689 sf->intra_uv_mode_mask[i] = INTRA_ALL;
691 sf->use_rd_breakout = 0;
692 sf->skip_encode_sb = 0;
693 sf->use_uv_intra_rd_estimate = 0;
694 sf->allow_skip_recode = 0;
695 sf->lpf_pick = LPF_PICK_FROM_FULL_IMAGE;
696 sf->use_fast_coef_updates = TWO_LOOP;
697 sf->use_fast_coef_costing = 0;
698 sf->mode_skip_start = MAX_MODES; // Mode index at which mode skip mask set
699 sf->schedule_mode_search = 0;
700 sf->use_nonrd_pick_mode = 0;
701 for (i = 0; i < BLOCK_SIZES; ++i) sf->inter_mode_mask[i] = INTER_ALL;
702 sf->max_intra_bsize = BLOCK_64X64;
703 sf->reuse_inter_pred_sby = 0;
704 // This setting only takes effect when partition_search_type is set
705 // to FIXED_PARTITION.
706 sf->always_this_block_size = BLOCK_16X16;
707 sf->search_type_check_frequency = 50;
708 sf->encode_breakout_thresh = 0;
709 // Recode loop tolerance %.
710 sf->recode_tolerance_low = 12;
711 sf->recode_tolerance_high = 25;
712 sf->default_interp_filter = SWITCHABLE;
713 sf->simple_model_rd_from_var = 0;
714 sf->short_circuit_flat_blocks = 0;
715 sf->short_circuit_low_temp_var = 0;
716 sf->limit_newmv_early_exit = 0;
718 sf->base_mv_aggressive = 0;
720 // Some speed-up features even for best quality as minimal impact on quality.
721 sf->adaptive_rd_thresh = 1;
722 sf->tx_size_search_breakout = 1;
724 if (oxcf->mode == REALTIME)
725 set_rt_speed_feature_framesize_independent(cpi, sf, oxcf->speed,
727 else if (oxcf->mode == GOOD)
728 set_good_speed_feature_framesize_independent(cpi, cm, sf, oxcf->speed);
730 cpi->full_search_sad = vp9_full_search_sad;
731 cpi->diamond_search_sad = vp9_diamond_search_sad;
733 sf->allow_exhaustive_searches = 1;
734 if (oxcf->mode == BEST) {
735 if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION)
736 sf->exhaustive_searches_thresh = (1 << 20);
738 sf->exhaustive_searches_thresh = (1 << 21);
739 sf->max_exaustive_pct = 100;
740 for (i = 0; i < MAX_MESH_STEP; ++i) {
741 sf->mesh_patterns[i].range = best_quality_mesh_pattern[i].range;
742 sf->mesh_patterns[i].interval = best_quality_mesh_pattern[i].interval;
745 int speed = (oxcf->speed > MAX_MESH_SPEED) ? MAX_MESH_SPEED : oxcf->speed;
746 if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION)
747 sf->exhaustive_searches_thresh = (1 << 22);
749 sf->exhaustive_searches_thresh = (1 << 23);
750 sf->max_exaustive_pct = good_quality_max_mesh_pct[speed];
752 sf->exhaustive_searches_thresh = sf->exhaustive_searches_thresh << 1;
754 for (i = 0; i < MAX_MESH_STEP; ++i) {
755 sf->mesh_patterns[i].range = good_quality_mesh_patterns[speed][i].range;
756 sf->mesh_patterns[i].interval =
757 good_quality_mesh_patterns[speed][i].interval;
761 // Slow quant, dct and trellis not worthwhile for first pass
762 // so make sure they are always turned off.
763 if (oxcf->pass == 1) sf->optimize_coefficients = 0;
765 // No recode for 1 pass.
766 if (oxcf->pass == 0) {
767 sf->recode_loop = DISALLOW_RECODE;
768 sf->optimize_coefficients = 0;
771 if (sf->mv.subpel_force_stop == 3) {
773 cpi->find_fractional_mv_step = vp9_skip_sub_pixel_tree;
774 } else if (sf->mv.subpel_search_method == SUBPEL_TREE) {
775 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree;
776 } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED) {
777 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned;
778 } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_MORE) {
779 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_more;
780 } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_EVENMORE) {
781 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_evenmore;
784 x->optimize = sf->optimize_coefficients == 1 && oxcf->pass != 1;
786 x->min_partition_size = sf->default_min_partition_size;
787 x->max_partition_size = sf->default_max_partition_size;
789 if (!cpi->oxcf.frame_periodic_boost) {
790 sf->max_delta_qindex = 0;
793 // With row based multi-threading, the following speed features
794 // have to be disabled to guarantee that bitstreams encoded with single thread
795 // and multiple threads match
796 if (cpi->oxcf.row_mt_bit_exact) {
797 sf->adaptive_rd_thresh = 0;
798 sf->allow_exhaustive_searches = 0;
799 sf->adaptive_pred_interp_filter = 0;