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"
16 // Intra only frames, golden frames (except alt ref overlays) and
17 // alt ref frames tend to be coded at a higher than ambient quality
18 static int frame_is_boosted(const VP9_COMP *cpi) {
19 return frame_is_kf_gf_arf(cpi) || vp9_is_upper_layer_key_frame(cpi);
22 static void set_good_speed_feature_framesize_dependent(VP9_COMMON *cm,
26 if (MIN(cm->width, cm->height) >= 720) {
27 sf->disable_split_mask = cm->show_frame ? DISABLE_ALL_SPLIT
28 : DISABLE_ALL_INTER_SPLIT;
29 sf->partition_search_breakout_dist_thr = (1 << 23);
31 sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
32 sf->partition_search_breakout_dist_thr = (1 << 21);
37 if (MIN(cm->width, cm->height) >= 720) {
38 sf->disable_split_mask = cm->show_frame ? DISABLE_ALL_SPLIT
39 : DISABLE_ALL_INTER_SPLIT;
40 sf->adaptive_pred_interp_filter = 0;
41 sf->partition_search_breakout_dist_thr = (1 << 24);
42 sf->partition_search_breakout_rate_thr = 120;
44 sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY;
45 sf->partition_search_breakout_dist_thr = (1 << 22);
46 sf->partition_search_breakout_rate_thr = 100;
51 if (MIN(cm->width, cm->height) >= 720) {
52 sf->disable_split_mask = DISABLE_ALL_SPLIT;
53 sf->schedule_mode_search = cm->base_qindex < 220 ? 1 : 0;
54 sf->partition_search_breakout_dist_thr = (1 << 25);
55 sf->partition_search_breakout_rate_thr = 200;
57 sf->max_intra_bsize = BLOCK_32X32;
58 sf->disable_split_mask = DISABLE_ALL_INTER_SPLIT;
59 sf->schedule_mode_search = cm->base_qindex < 175 ? 1 : 0;
60 sf->partition_search_breakout_dist_thr = (1 << 23);
61 sf->partition_search_breakout_rate_thr = 120;
66 if (MIN(cm->width, cm->height) >= 720) {
67 sf->partition_search_breakout_dist_thr = (1 << 26);
69 sf->partition_search_breakout_dist_thr = (1 << 24);
71 sf->disable_split_mask = DISABLE_ALL_SPLIT;
75 static void set_good_speed_feature(VP9_COMP *cpi, VP9_COMMON *cm,
76 SPEED_FEATURES *sf, int speed) {
77 const int boosted = frame_is_boosted(cpi);
79 sf->adaptive_rd_thresh = 1;
80 sf->allow_skip_recode = 1;
83 sf->use_square_partition_only = !frame_is_intra_only(cm);
84 sf->less_rectangular_check = 1;
86 sf->use_rd_breakout = 1;
87 sf->adaptive_motion_search = 1;
88 sf->mv.auto_mv_step_size = 1;
89 sf->adaptive_rd_thresh = 2;
90 sf->mv.subpel_iters_per_step = 1;
91 sf->mode_skip_start = 10;
92 sf->adaptive_pred_interp_filter = 1;
94 sf->recode_loop = ALLOW_RECODE_KFARFGF;
95 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
96 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
97 sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
98 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
100 sf->tx_size_search_breakout = 1;
101 sf->partition_search_breakout_rate_thr = 80;
105 sf->tx_size_search_method = frame_is_boosted(cpi) ? USE_FULL_RD
108 // Reference masking is not supported in dynamic scaling mode.
109 sf->reference_masking = cpi->oxcf.resize_mode != RESIZE_DYNAMIC ? 1 : 0;
111 sf->mode_search_skip_flags = (cm->frame_type == KEY_FRAME) ? 0 :
112 FLAG_SKIP_INTRA_DIRMISMATCH |
113 FLAG_SKIP_INTRA_BESTINTER |
114 FLAG_SKIP_COMP_BESTINTRA |
115 FLAG_SKIP_INTRA_LOWVAR;
116 sf->disable_filter_search_var_thresh = 100;
117 sf->comp_inter_joint_search_thresh = BLOCK_SIZES;
118 sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
120 sf->allow_partition_search_skip = 1;
124 sf->tx_size_search_method = frame_is_intra_only(cm) ? USE_FULL_RD
126 sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED;
127 sf->adaptive_pred_interp_filter = 0;
128 sf->adaptive_mode_search = 1;
129 sf->cb_partition_search = !boosted;
130 sf->cb_pred_filter_search = 1;
131 sf->alt_ref_search_fp = 1;
132 sf->recode_loop = ALLOW_RECODE_KFMAXBW;
133 sf->adaptive_rd_thresh = 3;
134 sf->mode_skip_start = 6;
135 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
136 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC;
137 sf->adaptive_interp_filter_search = 1;
141 sf->use_square_partition_only = 1;
142 sf->tx_size_search_method = USE_LARGESTALL;
143 sf->mv.search_method = BIGDIA;
144 sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
145 sf->adaptive_rd_thresh = 4;
146 if (cm->frame_type != KEY_FRAME)
147 sf->mode_search_skip_flags |= FLAG_EARLY_TERMINATE;
148 sf->disable_filter_search_var_thresh = 200;
149 sf->use_lp32x32fdct = 1;
150 sf->use_fast_coef_updates = ONE_LOOP_REDUCED;
151 sf->use_fast_coef_costing = 1;
152 sf->motion_field_mode_search = !boosted;
153 sf->partition_search_breakout_rate_thr = 300;
158 sf->optimize_coefficients = 0;
159 sf->mv.search_method = HEX;
160 sf->disable_filter_search_var_thresh = 500;
161 for (i = 0; i < TX_SIZES; ++i) {
162 sf->intra_y_mode_mask[i] = INTRA_DC;
163 sf->intra_uv_mode_mask[i] = INTRA_DC;
165 sf->partition_search_breakout_rate_thr = 500;
166 sf->mv.reduce_first_step_size = 1;
170 static void set_rt_speed_feature_framesize_dependent(VP9_COMP *cpi,
171 SPEED_FEATURES *sf, int speed) {
172 VP9_COMMON *const cm = &cpi->common;
175 if (MIN(cm->width, cm->height) >= 720) {
176 sf->disable_split_mask = cm->show_frame ? DISABLE_ALL_SPLIT
177 : DISABLE_ALL_INTER_SPLIT;
179 sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
184 if (MIN(cm->width, cm->height) >= 720) {
185 sf->disable_split_mask = cm->show_frame ? DISABLE_ALL_SPLIT
186 : DISABLE_ALL_INTER_SPLIT;
188 sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY;
193 if (MIN(cm->width, cm->height) >= 720) {
194 sf->partition_search_breakout_dist_thr = (1 << 25);
196 sf->partition_search_breakout_dist_thr = (1 << 23);
201 sf->encode_breakout_thresh = (MIN(cm->width, cm->height) >= 720) ?
206 static void set_rt_speed_feature(VP9_COMP *cpi, SPEED_FEATURES *sf,
207 int speed, vp9e_tune_content content) {
208 VP9_COMMON *const cm = &cpi->common;
209 const int is_keyframe = cm->frame_type == KEY_FRAME;
210 const int frames_since_key = is_keyframe ? 0 : cpi->rc.frames_since_key;
211 sf->static_segmentation = 0;
212 sf->adaptive_rd_thresh = 1;
213 sf->use_fast_coef_costing = 1;
216 sf->use_square_partition_only = !frame_is_intra_only(cm);
217 sf->less_rectangular_check = 1;
218 sf->tx_size_search_method = frame_is_intra_only(cm) ? USE_FULL_RD
221 sf->use_rd_breakout = 1;
223 sf->adaptive_motion_search = 1;
224 sf->adaptive_pred_interp_filter = 1;
225 sf->mv.auto_mv_step_size = 1;
226 sf->adaptive_rd_thresh = 2;
227 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
228 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
229 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
233 sf->mode_search_skip_flags = (cm->frame_type == KEY_FRAME) ? 0 :
234 FLAG_SKIP_INTRA_DIRMISMATCH |
235 FLAG_SKIP_INTRA_BESTINTER |
236 FLAG_SKIP_COMP_BESTINTRA |
237 FLAG_SKIP_INTRA_LOWVAR;
238 sf->adaptive_pred_interp_filter = 2;
240 // Reference masking is not supported in dynamic scaling mode.
241 sf->reference_masking = cpi->oxcf.resize_mode != RESIZE_DYNAMIC ? 1 : 0;
243 sf->disable_filter_search_var_thresh = 50;
244 sf->comp_inter_joint_search_thresh = BLOCK_SIZES;
245 sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
246 sf->lf_motion_threshold = LOW_MOTION_THRESHOLD;
247 sf->adjust_partitioning_from_last_frame = 1;
248 sf->last_partitioning_redo_frequency = 3;
249 sf->use_lp32x32fdct = 1;
250 sf->mode_skip_start = 11;
251 sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
255 sf->use_square_partition_only = 1;
256 sf->disable_filter_search_var_thresh = 100;
257 sf->use_uv_intra_rd_estimate = 1;
258 sf->skip_encode_sb = 1;
259 sf->mv.subpel_iters_per_step = 1;
260 sf->adaptive_rd_thresh = 4;
261 sf->mode_skip_start = 6;
262 sf->allow_skip_recode = 0;
263 sf->optimize_coefficients = 0;
264 sf->disable_split_mask = DISABLE_ALL_SPLIT;
265 sf->lpf_pick = LPF_PICK_FROM_Q;
270 sf->last_partitioning_redo_frequency = 4;
271 sf->adaptive_rd_thresh = 5;
272 sf->use_fast_coef_costing = 0;
273 sf->auto_min_max_partition_size = STRICT_NEIGHBORING_MIN_MAX;
274 sf->adjust_partitioning_from_last_frame =
275 cm->last_frame_type != cm->frame_type || (0 ==
276 (frames_since_key + 1) % sf->last_partitioning_redo_frequency);
277 sf->mv.subpel_force_stop = 1;
278 for (i = 0; i < TX_SIZES; i++) {
279 sf->intra_y_mode_mask[i] = INTRA_DC_H_V;
280 sf->intra_uv_mode_mask[i] = INTRA_DC;
282 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
283 sf->frame_parameter_update = 0;
284 sf->mv.search_method = FAST_HEX;
286 sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEAR_NEW;
287 sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST;
288 sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST;
289 sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST;
290 sf->max_intra_bsize = BLOCK_32X32;
291 sf->allow_skip_recode = 1;
295 sf->use_quant_fp = !is_keyframe;
296 sf->auto_min_max_partition_size = is_keyframe ? RELAXED_NEIGHBORING_MIN_MAX
297 : STRICT_NEIGHBORING_MIN_MAX;
298 sf->default_max_partition_size = BLOCK_32X32;
299 sf->default_min_partition_size = BLOCK_8X8;
300 sf->force_frame_boost = is_keyframe ||
301 (frames_since_key % (sf->last_partitioning_redo_frequency << 1) == 1);
302 sf->max_delta_qindex = is_keyframe ? 20 : 15;
303 sf->partition_search_type = REFERENCE_PARTITION;
304 sf->use_nonrd_pick_mode = 1;
305 sf->allow_skip_recode = 0;
306 sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEW_ZERO;
307 sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST_NEW_ZERO;
308 sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST_NEW_ZERO;
309 sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST_NEW_ZERO;
310 sf->adaptive_rd_thresh = 2;
311 // This feature is only enabled when partition search is disabled.
312 sf->reuse_inter_pred_sby = 1;
313 sf->partition_search_breakout_rate_thr = 200;
314 sf->coeff_prob_appx_step = 4;
315 sf->use_fast_coef_updates = is_keyframe ? TWO_LOOP : ONE_LOOP_REDUCED;
316 sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH;
320 if (content == VP9E_CONTENT_SCREEN) {
321 for (i = 0; i < BLOCK_SIZES; ++i)
322 sf->intra_y_mode_bsize_mask[i] = INTRA_DC_TM_H_V;
324 for (i = 0; i < BLOCK_SIZES; ++i)
325 if (i >= BLOCK_16X16)
326 sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
328 // Use H and V intra mode for block sizes <= 16X16.
329 sf->intra_y_mode_bsize_mask[i] = INTRA_DC_H_V;
335 // Adaptively switch between SOURCE_VAR_BASED_PARTITION and FIXED_PARTITION.
336 sf->partition_search_type = VAR_BASED_PARTITION;
337 // Turn on this to use non-RD key frame coding mode.
338 sf->use_nonrd_pick_mode = 1;
339 sf->mv.search_method = NSTEP;
340 sf->tx_size_search_method = is_keyframe ? USE_LARGESTALL : USE_TX_8X8;
341 sf->mv.reduce_first_step_size = 1;
342 sf->skip_encode_sb = 0;
346 sf->adaptive_rd_thresh = 3;
347 sf->mv.search_method = FAST_DIAMOND;
348 sf->mv.fullpel_search_step_param = 10;
351 sf->adaptive_rd_thresh = 4;
352 sf->mv.subpel_force_stop = 2;
353 sf->lpf_pick = LPF_PICK_MINIMAL_LPF;
357 void vp9_set_speed_features_framesize_dependent(VP9_COMP *cpi) {
358 SPEED_FEATURES *const sf = &cpi->sf;
359 VP9_COMMON *const cm = &cpi->common;
360 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
361 RD_OPT *const rd = &cpi->rd;
364 if (oxcf->mode == REALTIME) {
365 set_rt_speed_feature_framesize_dependent(cpi, sf, oxcf->speed);
366 } else if (oxcf->mode == GOOD) {
367 set_good_speed_feature_framesize_dependent(cm, sf, oxcf->speed);
370 if (sf->disable_split_mask == DISABLE_ALL_SPLIT) {
371 sf->adaptive_pred_interp_filter = 0;
374 if (cpi->encode_breakout && oxcf->mode == REALTIME &&
375 sf->encode_breakout_thresh > cpi->encode_breakout) {
376 cpi->encode_breakout = sf->encode_breakout_thresh;
379 // Check for masked out split cases.
380 for (i = 0; i < MAX_REFS; ++i) {
381 if (sf->disable_split_mask & (1 << i)) {
382 rd->thresh_mult_sub8x8[i] = INT_MAX;
387 void vp9_set_speed_features_framesize_independent(VP9_COMP *cpi) {
388 SPEED_FEATURES *const sf = &cpi->sf;
389 VP9_COMMON *const cm = &cpi->common;
390 MACROBLOCK *const x = &cpi->td.mb;
391 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
394 // best quality defaults
395 sf->frame_parameter_update = 1;
396 sf->mv.search_method = NSTEP;
397 sf->recode_loop = ALLOW_RECODE;
398 sf->mv.subpel_search_method = SUBPEL_TREE;
399 sf->mv.subpel_iters_per_step = 2;
400 sf->mv.subpel_force_stop = 0;
401 sf->optimize_coefficients = !is_lossless_requested(&cpi->oxcf);
402 sf->mv.reduce_first_step_size = 0;
403 sf->coeff_prob_appx_step = 1;
404 sf->mv.auto_mv_step_size = 0;
405 sf->mv.fullpel_search_step_param = 6;
406 sf->comp_inter_joint_search_thresh = BLOCK_4X4;
407 sf->adaptive_rd_thresh = 0;
408 sf->tx_size_search_method = USE_FULL_RD;
409 sf->use_lp32x32fdct = 0;
410 sf->adaptive_motion_search = 0;
411 sf->adaptive_pred_interp_filter = 0;
412 sf->adaptive_mode_search = 0;
413 sf->cb_pred_filter_search = 0;
414 sf->cb_partition_search = 0;
415 sf->motion_field_mode_search = 0;
416 sf->alt_ref_search_fp = 0;
417 sf->use_quant_fp = 0;
418 sf->reference_masking = 0;
419 sf->partition_search_type = SEARCH_PARTITION;
420 sf->less_rectangular_check = 0;
421 sf->use_square_partition_only = 0;
422 sf->auto_min_max_partition_size = NOT_IN_USE;
423 sf->default_max_partition_size = BLOCK_64X64;
424 sf->default_min_partition_size = BLOCK_4X4;
425 sf->adjust_partitioning_from_last_frame = 0;
426 sf->last_partitioning_redo_frequency = 4;
427 sf->disable_split_mask = 0;
428 sf->mode_search_skip_flags = 0;
429 sf->force_frame_boost = 0;
430 sf->max_delta_qindex = 0;
431 sf->disable_filter_search_var_thresh = 0;
432 sf->adaptive_interp_filter_search = 0;
433 sf->allow_partition_search_skip = 0;
435 for (i = 0; i < TX_SIZES; i++) {
436 sf->intra_y_mode_mask[i] = INTRA_ALL;
437 sf->intra_uv_mode_mask[i] = INTRA_ALL;
439 sf->use_rd_breakout = 0;
440 sf->skip_encode_sb = 0;
441 sf->use_uv_intra_rd_estimate = 0;
442 sf->allow_skip_recode = 0;
443 sf->lpf_pick = LPF_PICK_FROM_FULL_IMAGE;
444 sf->use_fast_coef_updates = TWO_LOOP;
445 sf->use_fast_coef_costing = 0;
446 sf->mode_skip_start = MAX_MODES; // Mode index at which mode skip mask set
447 sf->schedule_mode_search = 0;
448 sf->use_nonrd_pick_mode = 0;
449 for (i = 0; i < BLOCK_SIZES; ++i)
450 sf->inter_mode_mask[i] = INTER_ALL;
451 sf->max_intra_bsize = BLOCK_64X64;
452 sf->reuse_inter_pred_sby = 0;
453 // This setting only takes effect when partition_search_type is set
454 // to FIXED_PARTITION.
455 sf->always_this_block_size = BLOCK_16X16;
456 sf->search_type_check_frequency = 50;
457 sf->encode_breakout_thresh = 0;
458 // Recode loop tolerance %.
459 sf->recode_tolerance = 25;
460 sf->default_interp_filter = SWITCHABLE;
461 sf->tx_size_search_breakout = 0;
462 sf->partition_search_breakout_dist_thr = 0;
463 sf->partition_search_breakout_rate_thr = 0;
465 if (oxcf->mode == REALTIME)
466 set_rt_speed_feature(cpi, sf, oxcf->speed, oxcf->content);
467 else if (oxcf->mode == GOOD)
468 set_good_speed_feature(cpi, cm, sf, oxcf->speed);
470 cpi->full_search_sad = vp9_full_search_sad;
471 cpi->diamond_search_sad = oxcf->mode == BEST ? vp9_full_range_search
472 : vp9_diamond_search_sad;
474 // Slow quant, dct and trellis not worthwhile for first pass
475 // so make sure they are always turned off.
477 sf->optimize_coefficients = 0;
479 // No recode for 1 pass.
480 if (oxcf->pass == 0) {
481 sf->recode_loop = DISALLOW_RECODE;
482 sf->optimize_coefficients = 0;
485 if (sf->mv.subpel_search_method == SUBPEL_TREE) {
486 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree;
487 } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED) {
488 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned;
489 } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_MORE) {
490 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_more;
491 } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_EVENMORE) {
492 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_evenmore;
495 x->optimize = sf->optimize_coefficients == 1 && oxcf->pass != 1;
497 x->min_partition_size = sf->default_min_partition_size;
498 x->max_partition_size = sf->default_max_partition_size;
500 if (!cpi->oxcf.frame_periodic_boost) {
501 sf->max_delta_qindex = 0;