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.
11 #ifndef VPX_VP9_ENCODER_VP9_SPEED_FEATURES_H_
12 #define VPX_VP9_ENCODER_VP9_SPEED_FEATURES_H_
14 #include "vp9/common/vp9_enums.h"
21 INTRA_ALL = (1 << DC_PRED) | (1 << V_PRED) | (1 << H_PRED) | (1 << D45_PRED) |
22 (1 << D135_PRED) | (1 << D117_PRED) | (1 << D153_PRED) |
23 (1 << D207_PRED) | (1 << D63_PRED) | (1 << TM_PRED),
24 INTRA_DC = (1 << DC_PRED),
25 INTRA_DC_TM = (1 << DC_PRED) | (1 << TM_PRED),
26 INTRA_DC_H_V = (1 << DC_PRED) | (1 << V_PRED) | (1 << H_PRED),
28 (1 << DC_PRED) | (1 << TM_PRED) | (1 << V_PRED) | (1 << H_PRED)
32 INTER_ALL = (1 << NEARESTMV) | (1 << NEARMV) | (1 << ZEROMV) | (1 << NEWMV),
33 INTER_NEAREST = (1 << NEARESTMV),
34 INTER_NEAREST_NEW = (1 << NEARESTMV) | (1 << NEWMV),
35 INTER_NEAREST_ZERO = (1 << NEARESTMV) | (1 << ZEROMV),
36 INTER_NEAREST_NEW_ZERO = (1 << NEARESTMV) | (1 << ZEROMV) | (1 << NEWMV),
37 INTER_NEAREST_NEAR_NEW = (1 << NEARESTMV) | (1 << NEARMV) | (1 << NEWMV),
38 INTER_NEAREST_NEAR_ZERO = (1 << NEARESTMV) | (1 << NEARMV) | (1 << ZEROMV),
42 DISABLE_ALL_INTER_SPLIT = (1 << THR_COMP_GA) | (1 << THR_COMP_LA) |
43 (1 << THR_ALTR) | (1 << THR_GOLD) | (1 << THR_LAST),
45 DISABLE_ALL_SPLIT = (1 << THR_INTRA) | DISABLE_ALL_INTER_SPLIT,
47 DISABLE_COMPOUND_SPLIT = (1 << THR_COMP_GA) | (1 << THR_COMP_LA),
49 LAST_AND_INTRA_SPLIT_ONLY = (1 << THR_COMP_GA) | (1 << THR_COMP_LA) |
50 (1 << THR_ALTR) | (1 << THR_GOLD)
67 // Allow recode for KF and exceeding maximum frame bandwidth.
68 ALLOW_RECODE_KFMAXBW = 1,
69 // Allow recode only for KF/ARF/GF frames.
70 ALLOW_RECODE_KFARFGF = 2,
71 // Allow recode for ARF/GF/KF and first normal frame in each group.
72 ALLOW_RECODE_FIRST = 3,
73 // Allow recode for all frames based on bitrate constraints.
79 SUBPEL_TREE_PRUNED = 1, // Prunes 1/2-pel searches
80 SUBPEL_TREE_PRUNED_MORE = 2, // Prunes 1/2-pel searches more aggressively
81 SUBPEL_TREE_PRUNED_EVENMORE = 3, // Prunes 1/2- and 1/4-pel searches
82 // Other methods to come
83 } SUBPEL_SEARCH_METHODS;
86 NO_MOTION_THRESHOLD = 0,
87 LOW_MOTION_THRESHOLD = 7
94 } TX_SIZE_SEARCH_METHOD;
98 RELAXED_NEIGHBORING_MIN_MAX = 1,
99 STRICT_NEIGHBORING_MIN_MAX = 2
103 // Try the full image with different values.
104 LPF_PICK_FROM_FULL_IMAGE,
105 // Try a small portion of the image with different values.
106 LPF_PICK_FROM_SUBIMAGE,
107 // Estimate the level based on quantizer and frame type
109 // Pick 0 to disable LPF if LPF was enabled last frame
114 // Terminate search early based on distortion so far compared to
115 // qp step, distortion in the neighborhood of the frame, etc.
116 FLAG_EARLY_TERMINATE = 1 << 0,
118 // Skips comp inter modes if the best so far is an intra mode.
119 FLAG_SKIP_COMP_BESTINTRA = 1 << 1,
121 // Skips oblique intra modes if the best so far is an inter mode.
122 FLAG_SKIP_INTRA_BESTINTER = 1 << 3,
124 // Skips oblique intra modes at angles 27, 63, 117, 153 if the best
125 // intra so far is not one of the neighboring directions.
126 FLAG_SKIP_INTRA_DIRMISMATCH = 1 << 4,
128 // Skips intra modes other than DC_PRED if the source variance is small
129 FLAG_SKIP_INTRA_LOWVAR = 1 << 5,
130 } MODE_SEARCH_SKIP_LOGIC;
133 FLAG_SKIP_EIGHTTAP = 1 << EIGHTTAP,
134 FLAG_SKIP_EIGHTTAP_SMOOTH = 1 << EIGHTTAP_SMOOTH,
135 FLAG_SKIP_EIGHTTAP_SHARP = 1 << EIGHTTAP_SHARP,
136 } INTERP_FILTER_MASK;
139 // Search partitions using RD/NONRD criterion.
142 // Always use a fixed size partition.
147 // Use an arbitrary partitioning scheme based on source variance within
151 // Use non-fixed partitions based on source variance.
152 SOURCE_VAR_BASED_PARTITION,
154 // Make partition decisions with machine learning models.
156 } PARTITION_SEARCH_TYPE;
159 // Does a dry run to see if any of the contexts need to be updated or not,
160 // before the final run.
163 // No dry run, also only half the coef contexts and bands are updated.
164 // The rest are not updated at all.
168 typedef enum { EIGHTH_PEL, QUARTER_PEL, HALF_PEL, FULL_PEL } SUBPEL_FORCE_STOP;
170 typedef struct ADAPT_SUBPEL_FORCE_STOP {
171 // Threshold for full pixel motion vector;
174 // subpel_force_stop if full pixel MV is below the threshold.
175 SUBPEL_FORCE_STOP force_stop_below;
177 // subpel_force_stop if full pixel MV is equal to or above the threshold.
178 SUBPEL_FORCE_STOP force_stop_above;
179 } ADAPT_SUBPEL_FORCE_STOP;
181 typedef struct MV_SPEED_FEATURES {
182 // Motion search method (Diamond, NSTEP, Hex, Big Diamond, Square, etc).
183 SEARCH_METHODS search_method;
185 // This parameter controls which step in the n-step process we start at.
186 // It's changed adaptively based on circumstances.
187 int reduce_first_step_size;
189 // If this is set to 1, we limit the motion search range to 2 times the
190 // largest motion vector found in the last frame.
191 int auto_mv_step_size;
193 // Subpel_search_method can only be subpel_tree which does a subpixel
194 // logarithmic search that keeps stepping at 1/2 pixel units until
195 // you stop getting a gain, and then goes on to 1/4 and repeats
196 // the same process. Along the way it skips many diagonals.
197 SUBPEL_SEARCH_METHODS subpel_search_method;
199 // Subpel MV search level. Can take values 0 - 2. Higher values mean more
200 // extensive subpel search.
201 int subpel_search_level;
203 // When to stop subpel motion search.
204 SUBPEL_FORCE_STOP subpel_force_stop;
206 // If it's enabled, different subpel_force_stop will be used for different MV.
207 int enable_adaptive_subpel_force_stop;
209 ADAPT_SUBPEL_FORCE_STOP adapt_subpel_force_stop;
211 // This variable sets the step_param used in full pel motion search.
212 int fullpel_search_step_param;
215 typedef struct PARTITION_SEARCH_BREAKOUT_THR {
218 } PARTITION_SEARCH_BREAKOUT_THR;
220 #define MAX_MESH_STEP 4
222 typedef struct MESH_PATTERN {
228 // No reaction to rate control on a detected slide/scene change.
231 // Set to larger Q (max_q set by user) based only on the
232 // detected slide/scene change and current/past Q.
233 FAST_DETECTION_MAXQ = 1,
235 // Based on (first pass) encoded frame, if large frame size is detected
236 // then set to higher Q for the second re-encode. This involves 2 pass
237 // encoding on slide change, so slower than 1, but more accurate for
238 // detecting overshoot.
240 } OVERSHOOT_DETECTION_CBR_RT;
247 } SUBPEL_SEARCH_TYPE;
249 typedef struct SPEED_FEATURES {
250 MV_SPEED_FEATURES mv;
252 // Frame level coding parameter update
253 int frame_parameter_update;
255 RECODE_LOOP_TYPE recode_loop;
257 // Trellis (dynamic programming) optimization of quantized values (+1, 0).
258 int optimize_coefficients;
260 // Always set to 0. If on it enables 0 cost background transmission
261 // (except for the initial transmission of the segmentation). The feature is
262 // disabled because the addition of very large block sizes make the
263 // backgrounds very to cheap to encode, and the segmentation we have
265 int static_segmentation;
267 // If 1 we iterate finding a best reference for 2 ref frames together - via
268 // a log search that iterates 4 times (check around mv for last for best
269 // error of combined predictor then check around mv for alt). If 0 we
270 // we just use the best motion vector found for each frame by itself.
271 BLOCK_SIZE comp_inter_joint_search_thresh;
273 // This variable is used to cap the maximum number of times we skip testing a
274 // mode to be evaluated. A high value means we will be faster.
275 // Turned off when (row_mt_bit_exact == 1 && adaptive_rd_thresh_row_mt == 0).
276 int adaptive_rd_thresh;
278 // Flag to use adaptive_rd_thresh when row-mt it enabled, only for non-rd
280 int adaptive_rd_thresh_row_mt;
282 // Enables skipping the reconstruction step (idct, recon) in the
283 // intermediate steps assuming the last frame didn't have too many intra
284 // blocks and the q is less than a threshold.
286 int skip_encode_frame;
287 // Speed feature to allow or disallow skipping of recode at block
288 // level within a frame.
289 int allow_skip_recode;
291 // Enable Wiener filter based block complexity analysis.
292 int enable_wiener_variance;
294 // Coefficient probability model approximation step size
295 int coeff_prob_appx_step;
297 // Enable uniform quantizer followed by trellis coefficient optimization
298 int allow_quant_coeff_opt;
299 double quant_opt_thresh;
301 // Enable asymptotic closed-loop encoding decision for key frame and
302 // alternate reference frames.
305 // Temporal dependency model based encoding mode optimization
306 int enable_tpl_model;
308 // Use transform domain distortion. Use pixel domain distortion in speed 0
309 // and certain situations in higher speed to improve the RD model precision.
310 int allow_txfm_domain_distortion;
311 double tx_domain_thresh;
313 // The threshold is to determine how slow the motino is, it is used when
314 // use_lastframe_partitioning is set to LAST_FRAME_PARTITION_LOW_MOTION
315 MOTION_THRESHOLD lf_motion_threshold;
317 // Determine which method we use to determine transform size. We can choose
318 // between options like full rd, largest for prediction size, largest
319 // for intra and model coefs for the rest.
320 TX_SIZE_SEARCH_METHOD tx_size_search_method;
322 // How many levels of tx size to search, starting from the largest.
323 int tx_size_search_depth;
325 // Low precision 32x32 fdct keeps everything in 16 bits and thus is less
326 // precise but significantly faster than the non lp version.
329 // After looking at the first set of modes (set by index here), skip
330 // checking modes for reference frames that don't match the reference frame
331 // of the best so far.
334 // TODO(JBB): Remove this.
335 int reference_masking;
337 PARTITION_SEARCH_TYPE partition_search_type;
339 // Used if partition_search_type = FIXED_SIZE_PARTITION
340 BLOCK_SIZE always_this_block_size;
342 // Skip rectangular partition test when partition type none gives better
343 // rd than partition type split.
344 int less_rectangular_check;
346 // Disable testing non square partitions(eg 16x32) for block sizes larger than
347 // use_square_only_thresh_high or smaller than use_square_only_thresh_low.
348 int use_square_partition_only;
349 BLOCK_SIZE use_square_only_thresh_high;
350 BLOCK_SIZE use_square_only_thresh_low;
352 // Prune reference frames for rectangular partitions.
353 int prune_ref_frame_for_rect_partitions;
355 // Sets min and max partition sizes for this 64x64 region based on the
356 // same 64x64 in last encoded frame, and the left and above neighbor.
357 AUTO_MIN_MAX_MODE auto_min_max_partition_size;
358 // Ensures the rd based auto partition search will always
359 // go down at least to the specified level.
360 BLOCK_SIZE rd_auto_partition_min_limit;
362 // Min and max partition size we enable (block_size) as per auto
363 // min max, but also used by adjust partitioning, and pick_partitioning.
364 BLOCK_SIZE default_min_partition_size;
365 BLOCK_SIZE default_max_partition_size;
367 // Whether or not we allow partitions one smaller or one greater than the last
368 // frame's partitioning. Only used if use_lastframe_partitioning is set.
369 int adjust_partitioning_from_last_frame;
371 // How frequently we re do the partitioning from scratch. Only used if
372 // use_lastframe_partitioning is set.
373 int last_partitioning_redo_frequency;
375 // Disables sub 8x8 blocksizes in different scenarios: Choices are to disable
376 // it always, to allow it for only Last frame and Intra, disable it for all
377 // inter modes or to enable it always.
378 int disable_split_mask;
380 // TODO(jingning): combine the related motion search speed features
381 // This allows us to use motion search at other sizes as a starting
382 // point for this motion search and limits the search range around it.
383 int adaptive_motion_search;
385 // Do extra full pixel motion search to obtain better motion vector.
386 int enhanced_full_pixel_motion_search;
388 // Threshold for allowing exhaistive motion search.
389 int exhaustive_searches_thresh;
391 // Pattern to be used for any exhaustive mesh searches.
392 MESH_PATTERN mesh_patterns[MAX_MESH_STEP];
394 int schedule_mode_search;
396 // Allows sub 8x8 modes to use the prediction filter that was determined
397 // best for 8x8 mode. If set to 0 we always re check all the filters for
398 // sizes less than 8x8, 1 means we check all filter modes if no 8x8 filter
399 // was selected, and 2 means we use 8 tap if no 8x8 filter mode was selected.
400 int adaptive_pred_interp_filter;
402 // Adaptive prediction mode search
403 int adaptive_mode_search;
405 // Chessboard pattern prediction filter type search
406 int cb_pred_filter_search;
408 int cb_partition_search;
410 int motion_field_mode_search;
412 int alt_ref_search_fp;
414 // Fast quantization process path
417 // Use finer quantizer in every other few frames that run variable block
418 // partition type search.
419 int force_frame_boost;
421 // Maximally allowed base quantization index fluctuation.
422 int max_delta_qindex;
424 // Implements various heuristics to skip searching modes
425 // The heuristics selected are based on flags
426 // defined in the MODE_SEARCH_SKIP_HEURISTICS enum
427 unsigned int mode_search_skip_flags;
429 // A source variance threshold below which filter search is disabled
430 // Choose a very large value (UINT_MAX) to use 8-tap always
431 unsigned int disable_filter_search_var_thresh;
433 // These bit masks allow you to enable or disable intra modes for each
434 // transform size separately.
435 int intra_y_mode_mask[TX_SIZES];
436 int intra_uv_mode_mask[TX_SIZES];
438 // These bit masks allow you to enable or disable intra modes for each
439 // prediction block size separately.
440 int intra_y_mode_bsize_mask[BLOCK_SIZES];
442 // This variable enables an early break out of mode testing if the model for
443 // rd built from the prediction signal indicates a value that's much
444 // higher than the best rd we've seen so far.
447 // This enables us to use an estimate for intra rd based on dc mode rather
448 // than choosing an actual uv mode in the stage of encoding before the actual
450 int use_uv_intra_rd_estimate;
452 // This feature controls how the loop filter level is determined.
453 LPF_PICK_METHOD lpf_pick;
455 // This feature limits the number of coefficients updates we actually do
456 // by only looking at counts from 1/2 the bands.
457 FAST_COEFF_UPDATE use_fast_coef_updates;
459 // This flag controls the use of non-RD mode decision.
460 int use_nonrd_pick_mode;
462 // A binary mask indicating if NEARESTMV, NEARMV, ZEROMV, NEWMV
463 // modes are used in order from LSB to MSB for each BLOCK_SIZE.
464 int inter_mode_mask[BLOCK_SIZES];
466 // This feature controls whether we do the expensive context update and
467 // calculation in the rd coefficient costing loop.
468 int use_fast_coef_costing;
470 // This feature controls the tolerence vs target used in deciding whether to
471 // recode a frame. It has no meaning if recode is disabled.
472 int recode_tolerance_low;
473 int recode_tolerance_high;
475 // This variable controls the maximum block size where intra blocks can be
476 // used in inter frames.
477 // TODO(aconverse): Fold this into one of the other many mode skips
478 BLOCK_SIZE max_intra_bsize;
480 // The frequency that we check if SOURCE_VAR_BASED_PARTITION or
481 // FIXED_PARTITION search type should be used.
482 int search_type_check_frequency;
484 // When partition is pre-set, the inter prediction result from pick_inter_mode
485 // can be reused in final block encoding process. It is enabled only for real-
486 // time mode speed 6.
487 int reuse_inter_pred_sby;
489 // This variable sets the encode_breakout threshold. Currently, it is only
490 // enabled in real time mode.
491 int encode_breakout_thresh;
493 // default interp filter choice
494 INTERP_FILTER default_interp_filter;
496 // Early termination in transform size search, which only applies while
497 // tx_size_search_method is USE_FULL_RD.
498 int tx_size_search_breakout;
500 // adaptive interp_filter search to allow skip of certain filter types.
501 int adaptive_interp_filter_search;
503 // mask for skip evaluation of certain interp_filter type.
504 INTERP_FILTER_MASK interp_filter_search_mask;
506 // Partition search early breakout thresholds.
507 PARTITION_SEARCH_BREAKOUT_THR partition_search_breakout_thr;
510 // Use ML-based partition search early breakout.
512 // Higher values mean more aggressiveness for partition search breakout that
513 // results in better encoding speed but worse compression performance.
514 float search_breakout_thresh[3];
516 // Machine-learning based partition search early termination
517 int search_early_termination;
519 // Machine-learning based partition search pruning using prediction residue
523 // Threshold values used for ML based rectangular partition search pruning.
524 // If < 0, the feature is turned off.
525 // Higher values mean more aggressiveness to skip rectangular partition
526 // search that results in better encoding speed but worse coding
528 int prune_rect_thresh[4];
531 // Allow skipping partition search for still image frame
532 int allow_partition_search_skip;
534 // Fast approximation of vp9_model_rd_from_var_lapndz
535 int simple_model_rd_from_var;
537 // Skip a number of expensive mode evaluations for blocks with zero source
539 int short_circuit_flat_blocks;
541 // Skip a number of expensive mode evaluations for blocks with very low
542 // temporal variance. If the low temporal variance flag is set for a block,
544 // 1: Skip all golden modes and ALL INTRA for bsize >= 32x32.
545 // 2: Skip golden non-zeromv and newmv-last for bsize >= 16x16, skip ALL
546 // INTRA for bsize >= 32x32 and vert/horz INTRA for bsize 16x16, 16x32 and
548 // 3: Same as (2), but also skip golden zeromv.
549 int short_circuit_low_temp_var;
551 // Limits the rd-threshold update for early exit for the newmv-last mode,
553 int limit_newmv_early_exit;
555 // Adds a bias against golden reference, for non-rd mode.
558 // Bias to use base mv and skip 1/4 subpel search when use base mv in
559 // enhancement layer.
560 int base_mv_aggressive;
562 // Global flag to enable partition copy from the previous frame.
563 int copy_partition_flag;
565 // Compute the source sad for every superblock of the frame,
566 // prior to encoding the frame, to be used to bypass some encoder decisions.
569 int use_simple_block_yrd;
571 // If source sad of superblock is high (> adapt_partition_thresh), will switch
572 // from VARIANCE_PARTITION to REFERENCE_PARTITION (which selects partition
573 // based on the nonrd-pickmode).
574 int adapt_partition_source_sad;
575 int adapt_partition_thresh;
577 // Enable use of alt-refs in 1 pass VBR.
578 int use_altref_onepass;
580 // Enable use of compound prediction, for nonrd_pickmode with nonzero lag.
581 int use_compound_nonrd_pickmode;
583 // Always use nonrd_pick_intra for all block sizes on keyframes.
586 // For SVC: enables use of partition from lower spatial resolution.
587 int svc_use_lowres_part;
589 // Flag to indicate process for handling overshoot on slide/scene change,
590 // for real-time CBR mode.
591 OVERSHOOT_DETECTION_CBR_RT overshoot_detection_cbr_rt;
593 // Disable partitioning of 16x16 blocks.
594 int disable_16x16part_nonkey;
596 // Allow for disabling golden reference.
597 int disable_golden_ref;
599 // Allow sub-pixel search to use interpolation filters with different taps in
600 // order to achieve accurate motion search result.
601 SUBPEL_SEARCH_TYPE use_accurate_subpel_search;
603 // Search method used by temporal filtering in full_pixel_motion_search.
604 SEARCH_METHODS temporal_filter_search_method;
606 // Use machine learning based partition search.
607 int nonrd_use_ml_partition;
609 // Multiplier for base thresold for variance partitioning.
610 int variance_part_thresh_mult;
615 void vp9_set_speed_features_framesize_independent(struct VP9_COMP *cpi,
617 void vp9_set_speed_features_framesize_dependent(struct VP9_COMP *cpi,
624 #endif // VPX_VP9_ENCODER_VP9_SPEED_FEATURES_H_