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->adaptive_rd_thresh_row_mt = 0;
327 sf->use_fast_coef_costing = 1;
328 sf->allow_exhaustive_searches = 0;
329 sf->exhaustive_searches_thresh = INT_MAX;
331 sf->copy_partition_flag = 0;
332 sf->use_source_sad = 0;
333 sf->use_simple_block_yrd = 0;
336 sf->allow_txfm_domain_distortion = 1;
337 sf->tx_domain_thresh = 0.0;
338 sf->allow_quant_coeff_opt = 0;
339 sf->quant_opt_thresh = 0.0;
340 sf->use_square_partition_only = !frame_is_intra_only(cm);
341 sf->less_rectangular_check = 1;
342 sf->tx_size_search_method =
343 frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL;
345 sf->use_rd_breakout = 1;
347 sf->adaptive_motion_search = 1;
348 sf->adaptive_pred_interp_filter = 1;
349 sf->mv.auto_mv_step_size = 1;
350 sf->adaptive_rd_thresh = 2;
351 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
352 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
353 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
357 sf->mode_search_skip_flags =
358 (cm->frame_type == KEY_FRAME)
360 : FLAG_SKIP_INTRA_DIRMISMATCH | FLAG_SKIP_INTRA_BESTINTER |
361 FLAG_SKIP_COMP_BESTINTRA | FLAG_SKIP_INTRA_LOWVAR;
362 sf->adaptive_pred_interp_filter = 2;
364 // Reference masking only enabled for 1 spatial layer, and if none of the
365 // references have been scaled. The latter condition needs to be checked
366 // for external or internal dynamic resize.
367 sf->reference_masking = (cpi->svc.number_spatial_layers == 1);
368 if (sf->reference_masking == 1 &&
369 (cpi->external_resize == 1 ||
370 cpi->oxcf.resize_mode == RESIZE_DYNAMIC)) {
371 MV_REFERENCE_FRAME ref_frame;
372 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG,
374 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
375 const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame);
376 if (yv12 != NULL && (cpi->ref_frame_flags & flag_list[ref_frame])) {
377 const struct scale_factors *const scale_fac =
378 &cm->frame_refs[ref_frame - 1].sf;
379 if (vp9_is_scaled(scale_fac)) sf->reference_masking = 0;
384 sf->disable_filter_search_var_thresh = 50;
385 sf->comp_inter_joint_search_thresh = BLOCK_SIZES;
386 sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
387 sf->lf_motion_threshold = LOW_MOTION_THRESHOLD;
388 sf->adjust_partitioning_from_last_frame = 1;
389 sf->last_partitioning_redo_frequency = 3;
390 sf->use_lp32x32fdct = 1;
391 sf->mode_skip_start = 11;
392 sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
396 sf->use_square_partition_only = 1;
397 sf->disable_filter_search_var_thresh = 100;
398 sf->use_uv_intra_rd_estimate = 1;
399 sf->skip_encode_sb = 1;
400 sf->mv.subpel_iters_per_step = 1;
401 sf->adaptive_rd_thresh = 4;
402 sf->mode_skip_start = 6;
403 sf->allow_skip_recode = 0;
404 sf->optimize_coefficients = 0;
405 sf->disable_split_mask = DISABLE_ALL_SPLIT;
406 sf->lpf_pick = LPF_PICK_FROM_Q;
411 sf->last_partitioning_redo_frequency = 4;
412 sf->adaptive_rd_thresh = 5;
413 sf->use_fast_coef_costing = 0;
414 sf->auto_min_max_partition_size = STRICT_NEIGHBORING_MIN_MAX;
415 sf->adjust_partitioning_from_last_frame =
416 cm->last_frame_type != cm->frame_type ||
417 (0 == (frames_since_key + 1) % sf->last_partitioning_redo_frequency);
418 sf->mv.subpel_force_stop = 1;
419 for (i = 0; i < TX_SIZES; i++) {
420 sf->intra_y_mode_mask[i] = INTRA_DC_H_V;
421 sf->intra_uv_mode_mask[i] = INTRA_DC;
423 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
424 sf->frame_parameter_update = 0;
425 sf->mv.search_method = FAST_HEX;
427 sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEAR_NEW;
428 sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST;
429 sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST;
430 sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST;
431 sf->max_intra_bsize = BLOCK_32X32;
432 sf->allow_skip_recode = 1;
436 sf->use_quant_fp = !is_keyframe;
437 sf->auto_min_max_partition_size =
438 is_keyframe ? RELAXED_NEIGHBORING_MIN_MAX : STRICT_NEIGHBORING_MIN_MAX;
439 sf->default_max_partition_size = BLOCK_32X32;
440 sf->default_min_partition_size = BLOCK_8X8;
441 sf->force_frame_boost =
443 (frames_since_key % (sf->last_partitioning_redo_frequency << 1) == 1);
444 sf->max_delta_qindex = is_keyframe ? 20 : 15;
445 sf->partition_search_type = REFERENCE_PARTITION;
446 if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0 &&
447 cpi->rc.is_src_frame_alt_ref) {
448 sf->partition_search_type = VAR_BASED_PARTITION;
450 sf->use_nonrd_pick_mode = 1;
451 sf->allow_skip_recode = 0;
452 sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEW_ZERO;
453 sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST_NEW_ZERO;
454 sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST_NEW_ZERO;
455 sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST_NEW_ZERO;
456 sf->adaptive_rd_thresh = 2;
457 // This feature is only enabled when partition search is disabled.
458 sf->reuse_inter_pred_sby = 1;
459 sf->coeff_prob_appx_step = 4;
460 sf->use_fast_coef_updates = is_keyframe ? TWO_LOOP : ONE_LOOP_REDUCED;
461 sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH;
462 sf->tx_size_search_method = is_keyframe ? USE_LARGESTALL : USE_TX_8X8;
463 sf->simple_model_rd_from_var = 1;
464 if (cpi->oxcf.rc_mode == VPX_VBR) sf->mv.search_method = NSTEP;
468 if (content == VP9E_CONTENT_SCREEN) {
469 for (i = 0; i < BLOCK_SIZES; ++i)
470 sf->intra_y_mode_bsize_mask[i] = INTRA_DC_TM_H_V;
472 for (i = 0; i < BLOCK_SIZES; ++i)
474 sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
476 // Use H and V intra mode for block sizes <= 16X16.
477 sf->intra_y_mode_bsize_mask[i] = INTRA_DC_H_V;
480 if (content == VP9E_CONTENT_SCREEN) {
481 sf->short_circuit_flat_blocks = 1;
483 if (cpi->oxcf.rc_mode == VPX_CBR &&
484 cpi->oxcf.content != VP9E_CONTENT_SCREEN) {
485 sf->limit_newmv_early_exit = 1;
486 if (!cpi->use_svc) sf->bias_golden = 1;
491 sf->partition_search_type = VAR_BASED_PARTITION;
492 // Turn on this to use non-RD key frame coding mode.
493 sf->use_nonrd_pick_mode = 1;
494 sf->mv.search_method = NSTEP;
495 sf->mv.reduce_first_step_size = 1;
496 sf->skip_encode_sb = 0;
497 if (cpi->oxcf.rc_mode == VPX_CBR && content != VP9E_CONTENT_SCREEN) {
498 // Enable short circuit for low temporal variance.
499 sf->short_circuit_low_temp_var = 1;
501 if (cpi->use_svc) sf->base_mv_aggressive = 1;
505 sf->adaptive_rd_thresh = 3;
506 sf->mv.search_method = FAST_DIAMOND;
507 sf->mv.fullpel_search_step_param = 10;
508 if (cpi->svc.number_temporal_layers > 2 &&
509 cpi->svc.temporal_layer_id == 0) {
510 sf->mv.search_method = NSTEP;
511 sf->mv.fullpel_search_step_param = 6;
513 if (!cpi->external_resize) sf->use_source_sad = 1;
514 if (sf->use_source_sad) {
515 // For SVC allocate for top layer.
516 if (cpi->content_state_sb == NULL &&
518 cpi->svc.spatial_layer_id == cpi->svc.number_spatial_layers - 1)) {
519 cpi->content_state_sb = (uint8_t *)vpx_calloc(
520 (cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1), sizeof(uint8_t));
521 cpi->content_state_sb_fd = (uint8_t *)vpx_calloc(
522 (cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1), sizeof(uint8_t));
528 sf->adaptive_rd_thresh = 4;
529 // Enable partition copy
530 if (!cpi->use_svc && !cpi->resize_pending && cpi->resize_state == ORIG &&
531 !cpi->external_resize && cpi->oxcf.resize_mode == RESIZE_NONE)
532 sf->copy_partition_flag = 1;
534 if (sf->copy_partition_flag) {
535 cpi->max_copied_frame = 4;
536 if (cpi->prev_partition == NULL) {
537 cpi->prev_partition = (BLOCK_SIZE *)vpx_calloc(
538 cm->mi_stride * cm->mi_rows, sizeof(BLOCK_SIZE));
540 if (cpi->prev_segment_id == NULL) {
541 cpi->prev_segment_id = (int8_t *)vpx_calloc(
542 (cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1), sizeof(int8_t));
544 if (cpi->prev_variance_low == NULL) {
545 cpi->prev_variance_low = (uint8_t *)vpx_calloc(
546 (cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1) * 25,
549 if (cpi->copied_frame_cnt == NULL) {
550 cpi->copied_frame_cnt = (uint8_t *)vpx_calloc(
551 (cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1), sizeof(uint8_t));
555 if (cpi->row_mt && cpi->oxcf.max_threads > 1)
556 sf->adaptive_rd_thresh_row_mt = 1;
558 sf->mv.subpel_force_stop = (content == VP9E_CONTENT_SCREEN) ? 3 : 2;
559 if (content == VP9E_CONTENT_SCREEN) sf->lpf_pick = LPF_PICK_MINIMAL_LPF;
560 // Only keep INTRA_DC mode for speed 8.
563 for (i = 0; i < BLOCK_SIZES; ++i)
564 sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
566 if (!cpi->use_svc && cpi->oxcf.rc_mode == VPX_CBR &&
567 content != VP9E_CONTENT_SCREEN) {
568 // More aggressive short circuit for speed 8.
569 sf->short_circuit_low_temp_var = 3;
570 // Use level 2 for noisey cases as there is a regression in some
571 // noisy clips with level 3.
572 if (cpi->noise_estimate.enabled && cm->width >= 1280 &&
574 NOISE_LEVEL noise_level =
575 vp9_noise_estimate_extract_level(&cpi->noise_estimate);
576 if (noise_level >= kMedium) sf->short_circuit_low_temp_var = 2;
578 // Since the short_circuit_low_temp_var is used, reduce the
579 // adaptive_rd_thresh level.
580 sf->adaptive_rd_thresh = 1;
582 sf->limit_newmv_early_exit = 0;
583 if (cm->width > 320 && cm->height > 240) sf->use_simple_block_yrd = 1;
585 // Turn off adaptive_rd_thresh if row_mt is on for speed 5, 6, 7.
586 if (speed >= 5 && speed < 8 && cpi->row_mt && cpi->num_workers > 1) {
587 sf->adaptive_rd_thresh = 0;
588 sf->adaptive_rd_thresh_row_mt = 0;
592 void vp9_set_speed_features_framesize_dependent(VP9_COMP *cpi) {
593 SPEED_FEATURES *const sf = &cpi->sf;
594 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
595 RD_OPT *const rd = &cpi->rd;
598 // best quality defaults
599 // Some speed-up features even for best quality as minimal impact on quality.
600 sf->partition_search_breakout_thr.dist = (1 << 19);
601 sf->partition_search_breakout_thr.rate = 80;
602 sf->ml_partition_search_early_termination = 0;
604 if (oxcf->mode == REALTIME) {
605 set_rt_speed_feature_framesize_dependent(cpi, sf, oxcf->speed);
606 } else if (oxcf->mode == GOOD) {
607 set_good_speed_feature_framesize_dependent(cpi, sf, oxcf->speed);
610 if (sf->disable_split_mask == DISABLE_ALL_SPLIT) {
611 sf->adaptive_pred_interp_filter = 0;
614 if (cpi->encode_breakout && oxcf->mode == REALTIME &&
615 sf->encode_breakout_thresh > cpi->encode_breakout) {
616 cpi->encode_breakout = sf->encode_breakout_thresh;
619 // Check for masked out split cases.
620 for (i = 0; i < MAX_REFS; ++i) {
621 if (sf->disable_split_mask & (1 << i)) {
622 rd->thresh_mult_sub8x8[i] = INT_MAX;
626 // With row based multi-threading, the following speed features
627 // have to be disabled to guarantee that bitstreams encoded with single thread
628 // and multiple threads match
629 if (cpi->oxcf.row_mt_bit_exact) {
630 sf->adaptive_rd_thresh = 0;
631 sf->allow_exhaustive_searches = 0;
632 sf->adaptive_pred_interp_filter = 0;
636 void vp9_set_speed_features_framesize_independent(VP9_COMP *cpi) {
637 SPEED_FEATURES *const sf = &cpi->sf;
638 VP9_COMMON *const cm = &cpi->common;
639 MACROBLOCK *const x = &cpi->td.mb;
640 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
643 // best quality defaults
644 sf->frame_parameter_update = 1;
645 sf->mv.search_method = NSTEP;
646 sf->recode_loop = ALLOW_RECODE_FIRST;
647 sf->mv.subpel_search_method = SUBPEL_TREE;
648 sf->mv.subpel_iters_per_step = 2;
649 sf->mv.subpel_force_stop = 0;
650 sf->optimize_coefficients = !is_lossless_requested(&cpi->oxcf);
651 sf->mv.reduce_first_step_size = 0;
652 sf->coeff_prob_appx_step = 1;
653 sf->mv.auto_mv_step_size = 0;
654 sf->mv.fullpel_search_step_param = 6;
655 sf->comp_inter_joint_search_thresh = BLOCK_4X4;
656 sf->tx_size_search_method = USE_FULL_RD;
657 sf->use_lp32x32fdct = 0;
658 sf->adaptive_motion_search = 0;
659 sf->adaptive_pred_interp_filter = 0;
660 sf->adaptive_mode_search = 0;
661 sf->cb_pred_filter_search = 0;
662 sf->cb_partition_search = 0;
663 sf->motion_field_mode_search = 0;
664 sf->alt_ref_search_fp = 0;
665 sf->use_quant_fp = 0;
666 sf->reference_masking = 0;
667 sf->partition_search_type = SEARCH_PARTITION;
668 sf->less_rectangular_check = 0;
669 sf->use_square_partition_only = 0;
670 sf->use_square_only_threshold = BLOCK_SIZES;
671 sf->auto_min_max_partition_size = NOT_IN_USE;
672 sf->rd_auto_partition_min_limit = BLOCK_4X4;
673 sf->default_max_partition_size = BLOCK_64X64;
674 sf->default_min_partition_size = BLOCK_4X4;
675 sf->adjust_partitioning_from_last_frame = 0;
676 sf->last_partitioning_redo_frequency = 4;
677 sf->disable_split_mask = 0;
678 sf->mode_search_skip_flags = 0;
679 sf->force_frame_boost = 0;
680 sf->max_delta_qindex = 0;
681 sf->disable_filter_search_var_thresh = 0;
682 sf->adaptive_interp_filter_search = 0;
683 sf->allow_partition_search_skip = 0;
684 sf->allow_txfm_domain_distortion = 0;
685 sf->tx_domain_thresh = 99.0;
686 sf->allow_quant_coeff_opt = sf->optimize_coefficients;
687 sf->quant_opt_thresh = 99.0;
690 for (i = 0; i < TX_SIZES; i++) {
691 sf->intra_y_mode_mask[i] = INTRA_ALL;
692 sf->intra_uv_mode_mask[i] = INTRA_ALL;
694 sf->use_rd_breakout = 0;
695 sf->skip_encode_sb = 0;
696 sf->use_uv_intra_rd_estimate = 0;
697 sf->allow_skip_recode = 0;
698 sf->lpf_pick = LPF_PICK_FROM_FULL_IMAGE;
699 sf->use_fast_coef_updates = TWO_LOOP;
700 sf->use_fast_coef_costing = 0;
701 sf->mode_skip_start = MAX_MODES; // Mode index at which mode skip mask set
702 sf->schedule_mode_search = 0;
703 sf->use_nonrd_pick_mode = 0;
704 for (i = 0; i < BLOCK_SIZES; ++i) sf->inter_mode_mask[i] = INTER_ALL;
705 sf->max_intra_bsize = BLOCK_64X64;
706 sf->reuse_inter_pred_sby = 0;
707 // This setting only takes effect when partition_search_type is set
708 // to FIXED_PARTITION.
709 sf->always_this_block_size = BLOCK_16X16;
710 sf->search_type_check_frequency = 50;
711 sf->encode_breakout_thresh = 0;
712 // Recode loop tolerance %.
713 sf->recode_tolerance_low = 12;
714 sf->recode_tolerance_high = 25;
715 sf->default_interp_filter = SWITCHABLE;
716 sf->simple_model_rd_from_var = 0;
717 sf->short_circuit_flat_blocks = 0;
718 sf->short_circuit_low_temp_var = 0;
719 sf->limit_newmv_early_exit = 0;
721 sf->base_mv_aggressive = 0;
723 // Some speed-up features even for best quality as minimal impact on quality.
724 sf->adaptive_rd_thresh = 1;
725 sf->tx_size_search_breakout = 1;
727 if (oxcf->mode == REALTIME)
728 set_rt_speed_feature_framesize_independent(cpi, sf, oxcf->speed,
730 else if (oxcf->mode == GOOD)
731 set_good_speed_feature_framesize_independent(cpi, cm, sf, oxcf->speed);
733 cpi->full_search_sad = vp9_full_search_sad;
734 cpi->diamond_search_sad = vp9_diamond_search_sad;
736 sf->allow_exhaustive_searches = 1;
737 if (oxcf->mode == BEST) {
738 if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION)
739 sf->exhaustive_searches_thresh = (1 << 20);
741 sf->exhaustive_searches_thresh = (1 << 21);
742 sf->max_exaustive_pct = 100;
743 for (i = 0; i < MAX_MESH_STEP; ++i) {
744 sf->mesh_patterns[i].range = best_quality_mesh_pattern[i].range;
745 sf->mesh_patterns[i].interval = best_quality_mesh_pattern[i].interval;
748 int speed = (oxcf->speed > MAX_MESH_SPEED) ? MAX_MESH_SPEED : oxcf->speed;
749 if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION)
750 sf->exhaustive_searches_thresh = (1 << 22);
752 sf->exhaustive_searches_thresh = (1 << 23);
753 sf->max_exaustive_pct = good_quality_max_mesh_pct[speed];
755 sf->exhaustive_searches_thresh = sf->exhaustive_searches_thresh << 1;
757 for (i = 0; i < MAX_MESH_STEP; ++i) {
758 sf->mesh_patterns[i].range = good_quality_mesh_patterns[speed][i].range;
759 sf->mesh_patterns[i].interval =
760 good_quality_mesh_patterns[speed][i].interval;
764 // Slow quant, dct and trellis not worthwhile for first pass
765 // so make sure they are always turned off.
766 if (oxcf->pass == 1) sf->optimize_coefficients = 0;
768 // No recode for 1 pass.
769 if (oxcf->pass == 0) {
770 sf->recode_loop = DISALLOW_RECODE;
771 sf->optimize_coefficients = 0;
774 if (sf->mv.subpel_force_stop == 3) {
776 cpi->find_fractional_mv_step = vp9_skip_sub_pixel_tree;
777 } else if (sf->mv.subpel_search_method == SUBPEL_TREE) {
778 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree;
779 } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED) {
780 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned;
781 } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_MORE) {
782 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_more;
783 } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_EVENMORE) {
784 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_evenmore;
787 x->optimize = sf->optimize_coefficients == 1 && oxcf->pass != 1;
789 x->min_partition_size = sf->default_min_partition_size;
790 x->max_partition_size = sf->default_max_partition_size;
792 if (!cpi->oxcf.frame_periodic_boost) {
793 sf->max_delta_qindex = 0;
796 // With row based multi-threading, the following speed features
797 // have to be disabled to guarantee that bitstreams encoded with single thread
798 // and multiple threads match
799 if (cpi->oxcf.row_mt_bit_exact) {
800 sf->adaptive_rd_thresh = 0;
801 sf->allow_exhaustive_searches = 0;
802 sf->adaptive_pred_interp_filter = 0;