AOMedia AV1 Codec
speed_features.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3  *
4  * This source code is subject to the terms of the BSD 2 Clause License and
5  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6  * was not distributed with this source code in the LICENSE file, you can
7  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8  * Media Patent License 1.0 was not distributed with this source code in the
9  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10  */
11 
12 #ifndef AOM_AV1_ENCODER_SPEED_FEATURES_H_
13 #define AOM_AV1_ENCODER_SPEED_FEATURES_H_
14 
15 #include "av1/common/enums.h"
16 #include "av1/encoder/enc_enums.h"
17 #include "av1/encoder/mcomp.h"
18 #include "av1/encoder/encodemb.h"
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
27 #define MAX_MESH_STEP 4
28 
29 typedef struct MESH_PATTERN {
30  int range;
31  int interval;
32 } MESH_PATTERN;
33 
34 enum {
35  GM_FULL_SEARCH,
36  GM_REDUCED_REF_SEARCH_SKIP_L2_L3,
37  GM_REDUCED_REF_SEARCH_SKIP_L2_L3_ARF2,
38  GM_DISABLE_SEARCH
39 } UENUM1BYTE(GM_SEARCH_TYPE);
40 
41 enum {
42  DIST_WTD_COMP_ENABLED,
43  DIST_WTD_COMP_SKIP_MV_SEARCH,
44  DIST_WTD_COMP_DISABLED,
45 } UENUM1BYTE(DIST_WTD_COMP_FLAG);
46 
47 enum {
48  INTRA_ALL = (1 << DC_PRED) | (1 << V_PRED) | (1 << H_PRED) | (1 << D45_PRED) |
49  (1 << D135_PRED) | (1 << D113_PRED) | (1 << D157_PRED) |
50  (1 << D203_PRED) | (1 << D67_PRED) | (1 << SMOOTH_PRED) |
51  (1 << SMOOTH_V_PRED) | (1 << SMOOTH_H_PRED) | (1 << PAETH_PRED),
52  UV_INTRA_ALL =
53  (1 << UV_DC_PRED) | (1 << UV_V_PRED) | (1 << UV_H_PRED) |
54  (1 << UV_D45_PRED) | (1 << UV_D135_PRED) | (1 << UV_D113_PRED) |
55  (1 << UV_D157_PRED) | (1 << UV_D203_PRED) | (1 << UV_D67_PRED) |
56  (1 << UV_SMOOTH_PRED) | (1 << UV_SMOOTH_V_PRED) |
57  (1 << UV_SMOOTH_H_PRED) | (1 << UV_PAETH_PRED) | (1 << UV_CFL_PRED),
58  UV_INTRA_DC = (1 << UV_DC_PRED),
59  UV_INTRA_DC_CFL = (1 << UV_DC_PRED) | (1 << UV_CFL_PRED),
60  UV_INTRA_DC_TM = (1 << UV_DC_PRED) | (1 << UV_PAETH_PRED),
61  UV_INTRA_DC_PAETH_CFL =
62  (1 << UV_DC_PRED) | (1 << UV_PAETH_PRED) | (1 << UV_CFL_PRED),
63  UV_INTRA_DC_H_V = (1 << UV_DC_PRED) | (1 << UV_V_PRED) | (1 << UV_H_PRED),
64  UV_INTRA_DC_H_V_CFL = (1 << UV_DC_PRED) | (1 << UV_V_PRED) |
65  (1 << UV_H_PRED) | (1 << UV_CFL_PRED),
66  UV_INTRA_DC_PAETH_H_V = (1 << UV_DC_PRED) | (1 << UV_PAETH_PRED) |
67  (1 << UV_V_PRED) | (1 << UV_H_PRED),
68  UV_INTRA_DC_PAETH_H_V_CFL = (1 << UV_DC_PRED) | (1 << UV_PAETH_PRED) |
69  (1 << UV_V_PRED) | (1 << UV_H_PRED) |
70  (1 << UV_CFL_PRED),
71  INTRA_DC = (1 << DC_PRED),
72  INTRA_DC_TM = (1 << DC_PRED) | (1 << PAETH_PRED),
73  INTRA_DC_H_V = (1 << DC_PRED) | (1 << V_PRED) | (1 << H_PRED),
74  INTRA_DC_H_V_SMOOTH =
75  (1 << DC_PRED) | (1 << V_PRED) | (1 << H_PRED) | (1 << SMOOTH_PRED),
76  INTRA_DC_PAETH_H_V =
77  (1 << DC_PRED) | (1 << PAETH_PRED) | (1 << V_PRED) | (1 << H_PRED)
78 };
79 
80 enum {
81  INTER_ALL = (1 << NEARESTMV) | (1 << NEARMV) | (1 << GLOBALMV) |
82  (1 << NEWMV) | (1 << NEAREST_NEARESTMV) | (1 << NEAR_NEARMV) |
83  (1 << NEW_NEWMV) | (1 << NEAREST_NEWMV) | (1 << NEAR_NEWMV) |
84  (1 << NEW_NEARMV) | (1 << NEW_NEARESTMV) | (1 << GLOBAL_GLOBALMV),
85  INTER_NEAREST_NEAR_ZERO = (1 << NEARESTMV) | (1 << NEARMV) | (1 << GLOBALMV) |
86  (1 << NEAREST_NEARESTMV) | (1 << GLOBAL_GLOBALMV) |
87  (1 << NEAREST_NEWMV) | (1 << NEW_NEARESTMV) |
88  (1 << NEW_NEARMV) | (1 << NEAR_NEWMV) |
89  (1 << NEAR_NEARMV),
90 };
91 
92 enum {
93  DISABLE_ALL_INTER_SPLIT = (1 << THR_COMP_GA) | (1 << THR_COMP_LA) |
94  (1 << THR_ALTR) | (1 << THR_GOLD) | (1 << THR_LAST),
95 
96  DISABLE_ALL_SPLIT = (1 << THR_INTRA) | DISABLE_ALL_INTER_SPLIT,
97 
98  DISABLE_COMPOUND_SPLIT = (1 << THR_COMP_GA) | (1 << THR_COMP_LA),
99 
100  LAST_AND_INTRA_SPLIT_ONLY = (1 << THR_COMP_GA) | (1 << THR_COMP_LA) |
101  (1 << THR_ALTR) | (1 << THR_GOLD)
102 };
103 
104 enum {
105  TXFM_CODING_SF = 1,
106  INTER_PRED_SF = 2,
107  INTRA_PRED_SF = 4,
108  PARTITION_SF = 8,
109  LOOP_FILTER_SF = 16,
110  RD_SKIP_SF = 32,
111  RESERVE_2_SF = 64,
112  RESERVE_3_SF = 128,
113 } UENUM1BYTE(DEV_SPEED_FEATURES);
114 
115 /* This enumeration defines when the rate control recode loop will be
116  * enabled.
117  */
118 enum {
119  /*
120  * No recodes allowed
121  */
122  DISALLOW_RECODE = 0,
123  /*
124  * Allow recode only for KF/ARF/GF frames
125  */
126  ALLOW_RECODE_KFARFGF = 1,
127  /*
128  * Allow recode for all frame types based on bitrate constraints.
129  */
130  ALLOW_RECODE = 2,
131 } UENUM1BYTE(RECODE_LOOP_TYPE);
132 
133 enum {
134  SUBPEL_TREE = 0,
135  SUBPEL_TREE_PRUNED = 1, // Prunes 1/2-pel searches
136  SUBPEL_TREE_PRUNED_MORE = 2, // Prunes 1/2-pel searches more aggressively
137 } UENUM1BYTE(SUBPEL_SEARCH_METHODS);
138 
139 enum {
140  // Try the full image with different values.
141  LPF_PICK_FROM_FULL_IMAGE,
142  // Try the full image filter search with non-dual filter only.
143  LPF_PICK_FROM_FULL_IMAGE_NON_DUAL,
144  // Try a small portion of the image with different values.
145  LPF_PICK_FROM_SUBIMAGE,
146  // Estimate the level based on quantizer and frame type
147  LPF_PICK_FROM_Q,
148  // Pick 0 to disable LPF if LPF was enabled last frame
149  LPF_PICK_MINIMAL_LPF
150 } UENUM1BYTE(LPF_PICK_METHOD);
156 typedef enum {
164  CDEF_PICK_METHODS
166 
168 enum {
169  // Terminate search early based on distortion so far compared to
170  // qp step, distortion in the neighborhood of the frame, etc.
171  FLAG_EARLY_TERMINATE = 1 << 0,
172 
173  // Skips comp inter modes if the best so far is an intra mode.
174  FLAG_SKIP_COMP_BESTINTRA = 1 << 1,
175 
176  // Skips oblique intra modes if the best so far is an inter mode.
177  FLAG_SKIP_INTRA_BESTINTER = 1 << 3,
178 
179  // Skips oblique intra modes at angles 27, 63, 117, 153 if the best
180  // intra so far is not one of the neighboring directions.
181  FLAG_SKIP_INTRA_DIRMISMATCH = 1 << 4,
182 
183  // Skips intra modes other than DC_PRED if the source variance is small
184  FLAG_SKIP_INTRA_LOWVAR = 1 << 5,
185 } UENUM1BYTE(MODE_SEARCH_SKIP_LOGIC);
186 
187 enum {
188  // No tx type pruning
189  TX_TYPE_PRUNE_0 = 0,
190  // adaptively prunes the least perspective tx types out of all 16
191  // (tuned to provide negligible quality loss)
192  TX_TYPE_PRUNE_1 = 1,
193  // similar, but applies much more aggressive pruning to get better speed-up
194  TX_TYPE_PRUNE_2 = 2,
195  TX_TYPE_PRUNE_3 = 3,
196  // More aggressive pruning based on tx type score and allowed tx count
197  TX_TYPE_PRUNE_4 = 4,
198  TX_TYPE_PRUNE_5 = 5,
199 } UENUM1BYTE(TX_TYPE_PRUNE_MODE);
200 
201 enum {
202  // No reaction to rate control on a detected slide/scene change.
203  NO_DETECTION = 0,
204 
205  // Set to larger Q based only on the detected slide/scene change and
206  // current/past Q.
207  FAST_DETECTION_MAXQ = 1,
208 } UENUM1BYTE(OVERSHOOT_DETECTION_CBR);
209 
210 enum {
211  // Turns off multi-winner mode. So we will do txfm search on either all modes
212  // if winner mode is off, or we will only on txfm search on a single winner
213  // mode.
214  MULTI_WINNER_MODE_OFF = 0,
215 
216  // Limits the number of winner modes to at most 2
217  MULTI_WINNER_MODE_FAST = 1,
218 
219  // Uses the default number of winner modes, which is 3 for intra mode, and 1
220  // for inter mode.
221  MULTI_WINNER_MODE_DEFAULT = 2,
222 } UENUM1BYTE(MULTI_WINNER_MODE_TYPE);
223 
224 typedef struct {
225  TX_TYPE_PRUNE_MODE prune_2d_txfm_mode;
226  int fast_intra_tx_type_search;
227  int fast_inter_tx_type_search;
228 
229  // prune two least frequently chosen transforms for each intra mode
230  int use_reduced_intra_txset;
231 
232  // Use a skip flag prediction model to detect blocks with skip = 1 early
233  // and avoid doing full TX type search for such blocks.
234  int use_skip_flag_prediction;
235 
236  // Threshold used by the ML based method to predict TX block split decisions.
237  int ml_tx_split_thresh;
238 
239  // skip remaining transform type search when we found the rdcost of skip is
240  // better than applying transform
241  int skip_tx_search;
242 
243  // Prune tx type search using previous frame stats.
244  int prune_tx_type_using_stats;
245  // Prune tx type search using estimated RDcost
246  int prune_tx_type_est_rd;
247 
248  // Flag used to control the winner mode processing for tx type pruning for
249  // inter blocks. It enables further tx type mode pruning based on ML model for
250  // mode evaluation and disables tx type mode pruning for winner mode
251  // processing.
252  int winner_mode_tx_type_pruning;
253 } TX_TYPE_SEARCH;
254 
255 enum {
256  // Search partitions using RD criterion
257  SEARCH_PARTITION,
258 
259  // Always use a fixed size partition
260  FIXED_PARTITION,
261 
262  // Partition using source variance
263  VAR_BASED_PARTITION,
264 
265 #if CONFIG_RT_ML_PARTITIONING
266  // Partition using ML model
267  ML_BASED_PARTITION
268 #endif
269 } UENUM1BYTE(PARTITION_SEARCH_TYPE);
270 
271 enum {
272  NOT_IN_USE,
273  DIRECT_PRED,
274  RELAXED_PRED,
275  ADAPT_PRED
276 } UENUM1BYTE(MAX_PART_PRED_MODE);
277 
278 enum {
279  LAST_MV_DATA,
280  CURRENT_Q,
281  QTR_ONLY,
282 } UENUM1BYTE(MV_PREC_LOGIC);
283 
284 enum {
285  SUPERRES_AUTO_ALL, // Tries all possible superres ratios
286  SUPERRES_AUTO_DUAL, // Tries no superres and q-based superres ratios
287  SUPERRES_AUTO_SOLO, // Only apply the q-based superres ratio
288 } UENUM1BYTE(SUPERRES_AUTO_SEARCH_TYPE);
289 
296  // Frame level coding parameter update
297  int frame_parameter_update;
298 
303  RECODE_LOOP_TYPE recode_loop;
304 
310 
312  // Determine how motion vector precision is chosen. The possibilities are:
313  // LAST_MV_DATA: use the mv data from the last coded frame
314  // CURRENT_Q: use the current q as a threshold
315  // QTR_ONLY: use quarter pel precision only.
316  MV_PREC_LOGIC high_precision_mv_usage;
317 
318  // Always set to 0. If on it enables 0 cost background transmission
319  // (except for the initial transmission of the segmentation). The feature is
320  // disabled because the addition of very large block sizes make the
321  // backgrounds very to cheap to encode, and the segmentation we have
322  // adds overhead.
323  int static_segmentation;
324 
328  SUPERRES_AUTO_SEARCH_TYPE superres_auto_search_type;
335 
341 
343 typedef struct TPL_SPEED_FEATURES {
344  // Enable/disable GOP length adaptive decision.
345  int disable_gop_length_decision;
346  // Prune the intra modes search by tpl.
347  // If set to 0, we will search all intra modes from DC_PRED to PAETH_PRED.
348  // If set to 1, we only search DC_PRED, V_PRED, and H_PRED.
349  int prune_intra_modes;
350  // This parameter controls which step in the n-step process we start at.
351  int reduce_first_step_size;
352  // Skip motion estimation based on the precision of center MVs and the
353  // difference between center MVs.
354  // If set to 0, motion estimation is skipped for duplicate center MVs
355  // (default). If set to 1, motion estimation is skipped for duplicate
356  // full-pixel center MVs. If set to 2, motion estimation is skipped if the
357  // difference between center MVs is less than the threshold.
358  int skip_alike_starting_mv;
359 
360  // When to stop subpel search.
361  SUBPEL_FORCE_STOP subpel_force_stop;
362 
363  // Which search method to use.
364  SEARCH_METHODS search_method;
365 
366  // Prune starting mvs in TPL based on sad scores.
367  int prune_starting_mv;
368 
369  // Not run TPL for filtered Key frame.
370  int disable_filtered_key_tpl;
371 
372  // Prune reference frames in TPL.
373  int prune_ref_frames_in_tpl;
374 
375  // Support compound predictions.
376  int allow_compound_pred;
377 } TPL_SPEED_FEATURES;
378 
379 typedef struct GLOBAL_MOTION_SPEED_FEATURES {
380  GM_SEARCH_TYPE gm_search_type;
381 
382  // During global motion estimation, prune remaining reference frames in a
383  // given direction(past/future), if the evaluated ref_frame in that direction
384  // yields gm_type as INVALID/TRANSLATION/IDENTITY
385  int prune_ref_frame_for_gm_search;
386 } GLOBAL_MOTION_SPEED_FEATURES;
387 
388 typedef struct PARTITION_SPEED_FEATURES {
389  PARTITION_SEARCH_TYPE partition_search_type;
390 
391  // Used if partition_search_type = FIXED_PARTITION
392  BLOCK_SIZE fixed_partition_size;
393 
394  // Prune extended partition types search
395  // Can take values 0 - 2, 0 referring to no pruning, and 1 - 2 increasing
396  // aggressiveness of pruning in order.
397  int prune_ext_partition_types_search_level;
398 
399  // Prune part4 based on block size
400  int prune_part4_search;
401 
402  // Use a ML model to prune rectangular, ab and 4-way horz
403  // and vert partitions
404  int ml_prune_partition;
405 
406  // Use a ML model to adaptively terminate partition search after trying
407  // PARTITION_SPLIT. Can take values 0 - 2, 0 meaning not being enabled, and
408  // 1 - 2 increasing aggressiveness in order.
409  int ml_early_term_after_part_split_level;
410 
411  // Skip rectangular partition test when partition type none gives better
412  // rd than partition type split. Can take values 0 - 2, 0 referring to no
413  // skipping, and 1 - 2 increasing aggressiveness of skipping in order.
414  int less_rectangular_check_level;
415 
416  // Use square partition only beyond this block size.
417  BLOCK_SIZE use_square_partition_only_threshold;
418 
419  // Sets max square partition levels for this superblock based on
420  // motion vector and prediction error distribution produced from 16x16
421  // simple motion search
422  MAX_PART_PRED_MODE auto_max_partition_based_on_simple_motion;
423 
424  // Min and max square partition size we enable (block_size) as per auto
425  // min max, but also used by adjust partitioning, and pick_partitioning.
426  BLOCK_SIZE default_min_partition_size;
427  BLOCK_SIZE default_max_partition_size;
428 
429  // Sets level of adjustment of variance-based partitioning during
430  // rd_use_partition 0 - no partition adjustment, 1 - try to merge partitions
431  // for small blocks and high QP, 2 - always try to merge leaf partitions, 3 -
432  // try to merge and split leaf partitions
433  int adjust_var_based_rd_partitioning;
434 
435  // Partition search early breakout thresholds.
436  int64_t partition_search_breakout_dist_thr;
437  int partition_search_breakout_rate_thr;
438 
439  // Thresholds for ML based partition search breakout.
440  int ml_partition_search_breakout_thresh[PARTITION_BLOCK_SIZES];
441 
442  // Allow skipping partition search for still image frame
443  int allow_partition_search_skip;
444 
445  // The aggressiveness of pruning with simple_motion_search.
446  // Currently 0 is the lowest, and 2 the highest.
447  int simple_motion_search_prune_agg;
448 
449  // Perform simple_motion_search on each possible subblock and use it to prune
450  // PARTITION_HORZ and PARTITION_VERT.
451  int simple_motion_search_prune_rect;
452 
453  // Perform simple motion search before none_partition to decide if we
454  // want to remove all partitions other than PARTITION_SPLIT. If set to 0, this
455  // model is disabled. If set to 1, the model attempts to perform
456  // PARTITION_SPLIT only. If set to 2, the model also attempts to prune
457  // PARTITION_SPLIT.
458  int simple_motion_search_split;
459 
460  // Use features from simple_motion_search to terminate prediction block
461  // partition after PARTITION_NONE
462  int simple_motion_search_early_term_none;
463 
464  // Controls whether to reduce the number of motion search steps. If this is 0,
465  // then simple_motion_search has the same number of steps as
466  // single_motion_search (assuming no other speed features). Otherwise, reduce
467  // the number of steps by the value contained in this variable.
468  int simple_motion_search_reduce_search_steps;
469 
470  // This variable controls the maximum block size where intra blocks can be
471  // used in inter frames.
472  // TODO(aconverse): Fold this into one of the other many mode skips
473  BLOCK_SIZE max_intra_bsize;
474 
475  // Use CNN with luma pixels on source frame on each of the 64x64 subblock to
476  // perform split/no_split decision on intra-frames.
477  int intra_cnn_split;
478 
479  // Disable extended partition search for lower block sizes.
480  int ext_partition_eval_thresh;
481 
482  // prune extended partition search
483  // 0 : no pruning
484  // 1 : prune 1:4 partition search using winner info from split partitions
485  // 2 : prune 1:4 and AB partition search using split and HORZ/VERT info
486  int prune_ext_part_using_split_info;
487 
488  // Prunt rectangular, AB and 4-way partition based on q index and block size
489  int prune_rectangular_split_based_on_qidx;
490 
491  // Terminate partition search for child partition,
492  // when NONE and SPLIT partition rd_costs are INT64_MAX.
493  int early_term_after_none_split;
494 
495  // Level used to adjust threshold for av1_ml_predict_breakout(). At lower
496  // levels, more conservative threshold is used, and value of 0 indicates
497  // av1_ml_predict_breakout() is disabled. Value of 3 corresponds to default
498  // case with no adjustment to lbd thresholds.
499  int ml_predict_breakout_level;
500 
501  // Prune sub_8x8 (BLOCK_4X4, BLOCK_4X8 and BLOCK_8X4) partitions.
502  // 0 : no pruning
503  // 1 : pruning based on neighbour block information
504  // 2 : prune always
505  int prune_sub_8x8_partition_level;
506 } PARTITION_SPEED_FEATURES;
507 
508 typedef struct MV_SPEED_FEATURES {
509  // Motion search method (Diamond, NSTEP, Hex, Big Diamond, Square, etc).
510  SEARCH_METHODS search_method;
511 
512  // Enable the use of faster, less accurate mv search method on bsize >=
513  // BLOCK_32X32.
514  // TODO(chiyotsai@google.com): Take the clip's resolution and mv activity into
515  // account.
516  int use_bsize_dependent_search_method;
517 
518  // If this is set to 1, we limit the motion search range to 2 times the
519  // largest motion vector found in the last frame.
520  int auto_mv_step_size;
521 
522  // Subpel_search_method can only be subpel_tree which does a subpixel
523  // logarithmic search that keeps stepping at 1/2 pixel units until
524  // you stop getting a gain, and then goes on to 1/4 and repeats
525  // the same process. Along the way it skips many diagonals.
526  SUBPEL_SEARCH_METHODS subpel_search_method;
527 
528  // Maximum number of steps in logarithmic subpel search before giving up.
529  int subpel_iters_per_step;
530 
531  // When to stop subpel search.
532  SUBPEL_FORCE_STOP subpel_force_stop;
533 
534  // When to stop subpel search in simple motion search.
535  SUBPEL_FORCE_STOP simple_motion_subpel_force_stop;
536 
537  // If true, sub-pixel search uses the exact convolve function used for final
538  // encoding and decoding; otherwise, it uses bilinear interpolation.
539  SUBPEL_SEARCH_TYPE use_accurate_subpel_search;
540 
541  // Threshold for allowing exhaustive motion search.
542  int exhaustive_searches_thresh;
543 
544  // Pattern to be used for any exhaustive mesh searches (except intraBC ME).
545  MESH_PATTERN mesh_patterns[MAX_MESH_STEP];
546 
547  // Pattern to be used for exhaustive mesh searches of intraBC ME.
548  MESH_PATTERN intrabc_mesh_patterns[MAX_MESH_STEP];
549 
550  // Reduce single motion search range based on MV result of prior ref_mv_idx.
551  int reduce_search_range;
552 
553  // Prune mesh search.
554  int prune_mesh_search;
555 
556  // Use the rd cost around the best FULLPEL_MV to speed up subpel search
557  int use_fullpel_costlist;
558 
559  // Set the full pixel search level of obmc
560  // 0: obmc_full_pixel_diamond
561  // 1: obmc_refining_search_sad (faster)
562  int obmc_full_pixel_search_level;
563 
564  // Accurate full pixel motion search based on TPL stats.
565  int full_pixel_search_level;
566 
567  // Whether to downsample the rows in sad calculation during motion search.
568  // This is only active when there are at least 16 rows.
569  int use_downsampled_sad;
570 
571  // Enable/disable extensive joint motion search.
572  int disable_extensive_joint_motion_search;
573 
574  // Enable second best mv check in joint mv search.
575  int enable_second_mv;
576 } MV_SPEED_FEATURES;
577 
578 typedef struct INTER_MODE_SPEED_FEATURES {
579  // 2-pass inter mode model estimation where the preliminary pass skips
580  // transform search and uses a model to estimate rd, while the final pass
581  // computes the full transform search. Two types of models are supported:
582  // 0: not used
583  // 1: used with online dynamic rd model
584  // 2: used with static rd model
585  int inter_mode_rd_model_estimation;
586 
587  // Bypass transform search based on skip rd
588  int txfm_rd_gate_level;
589 
590  // Limit the inter mode tested in the RD loop
591  int reduce_inter_modes;
592 
593  // This variable is used to cap the maximum number of times we skip testing a
594  // mode to be evaluated. A high value means we will be faster.
595  int adaptive_rd_thresh;
596 
597  // Aggressively prune inter modes when best mode is skippable.
598  int prune_inter_modes_if_skippable;
599 
600  // Drop less likely to be picked reference frames in the RD search.
601  // Has six levels for now: 0, 1, 2, 3, 4 and 5, where higher levels prune
602  // more aggressively than lower ones. (0 means no pruning).
603  int selective_ref_frame;
604 
605  // Prune reference frames for rectangular partitions.
606  // 0 implies no pruning
607  // 1 implies prune for extended partition
608  // 2 implies prune horiz, vert and extended partition
609  int prune_ref_frame_for_rect_partitions;
610 
611  int alt_ref_search_fp;
612 
613  // flag to skip NEWMV mode in drl if the motion search result is the same
614  int skip_repeated_newmv;
615 
616  // Skip the current ref_mv in NEW_MV mode if we have already encountered
617  // another ref_mv in the drl such that:
618  // 1. The other drl has the same fullpel_mv during the SIMPLE_TRANSLATION
619  // search process as the current fullpel_mv.
620  // 2. The rate needed to encode the current fullpel_mv is larger than that
621  // for the other ref_mv.
622  int skip_repeated_full_newmv;
623 
624  // This speed feature checks duplicate ref MVs among NEARESTMV, NEARMV,
625  // GLOBALMV and skips NEARMV or GLOBALMV (in order) if a duplicate is found
626  // TODO(any): Instead of skipping repeated ref mv, use the recalculated
627  // rd-cost based on mode rate and skip the mode evaluation
628  int skip_repeated_ref_mv;
629 
630  // Flag used to control the ref_best_rd based gating for chroma
631  int perform_best_rd_based_gating_for_chroma;
632 
633  // Reuse the inter_intra_mode search result from NEARESTMV mode to other
634  // single ref modes
635  int reuse_inter_intra_mode;
636 
637  // prune wedge and compound segment approximate rd evaluation based on
638  // compound average modeled rd
639  int prune_comp_type_by_model_rd;
640 
641  // prune wedge and compound segment approximate rd evaluation based on
642  // compound average rd/ref_best_rd
643  int prune_comp_type_by_comp_avg;
644 
645  // Skip some ref frames in compound motion search by single motion search
646  // result. Has three levels for now: 0 referring to no skipping, and 1 - 3
647  // increasing aggressiveness of skipping in order.
648  // Note: The search order might affect the result. It assumes that the single
649  // reference modes are searched before compound modes. It is better to search
650  // same single inter mode as a group.
651  int prune_comp_search_by_single_result;
652 
653  // If 1 we iterate finding a best reference for 2 ref frames together - via
654  // a log search that iterates 4 times (check around mv for last for best
655  // error of combined predictor then check around mv for alt). If 0 we
656  // we just use the best motion vector found for each frame by itself.
657  BLOCK_SIZE comp_inter_joint_search_thresh;
658 
659  // Instead of performing a full MV search, do a simple translation first
660  // and only perform a full MV search on the motion vectors that performed
661  // well.
662  int prune_mode_search_simple_translation;
663 
664  // Only search compound modes with at least one "good" reference frame.
665  // A reference frame is good if, after looking at its performance among
666  // the single reference modes, it is one of the two best performers.
667  int prune_compound_using_single_ref;
668 
669  // Skip extended compound mode using ref frames of above and left neighbor
670  // blocks.
671  // 0 : no pruning
672  // 1 : prune extended compound mode (less aggressiveness)
673  // 2 : prune extended compound mode (high aggressiveness)
674  int prune_compound_using_neighbors;
675 
676  // Skip extended compound mode when ref frame corresponding to NEWMV does not
677  // have NEWMV as single mode winner.
678  // 0 : no pruning
679  // 1 : prune extended compound mode (less aggressiveness)
680  // 2 : prune extended compound mode (high aggressiveness)
681  int prune_comp_using_best_single_mode_ref;
682 
683  // Based on previous ref_mv_idx search result, prune the following search.
684  int prune_ref_mv_idx_search;
685 
686  // Disable one sided compound modes.
687  int disable_onesided_comp;
688 
689  // Prune obmc search using previous frame stats.
690  // INT_MAX : disable obmc search
691  int prune_obmc_prob_thresh;
692 
693  // Prune warped motion search using previous frame stats.
694  int prune_warped_prob_thresh;
695 
696  // Variance threshold to enable/disable Interintra wedge search
697  unsigned int disable_interintra_wedge_var_thresh;
698 
699  // Variance threshold to enable/disable Interinter wedge search
700  unsigned int disable_interinter_wedge_var_thresh;
701 
702  // De-couple wedge and mode search during interintra RDO.
703  int fast_interintra_wedge_search;
704 
705  // Whether fast wedge sign estimate is used
706  int fast_wedge_sign_estimate;
707 
708  // Enable/disable ME for interinter wedge search.
709  int disable_interinter_wedge_newmv_search;
710 
711  // Decide when and how to use joint_comp.
712  DIST_WTD_COMP_FLAG use_dist_wtd_comp_flag;
713 
714  // To skip cost update for mv.
715  // mv_cost_upd_level indicates the aggressiveness of skipping.
716  // 0: update happens at each sb level.
717  // 1: update happens once for each sb row.
718  // 2: update happens once for a set of rows.
719  int mv_cost_upd_level;
720  // Prune inter modes based on tpl stats
721  // 0 : no pruning
722  // 1 - 3 indicate increasing aggressiveness in order.
723  int prune_inter_modes_based_on_tpl;
724 
725  // Skip NEARMV and NEAR_NEARMV modes using ref frames of above and left
726  // neighbor blocks and qindex.
727  int prune_nearmv_using_neighbors;
728 
729  // Model based breakout after interpolation filter search
730  // 0: no breakout
731  // 1: use model based rd breakout
732  int model_based_post_interp_filter_breakout;
733 
734  // Reuse compound type rd decision when exact match is found
735  // 0: No reuse
736  // 1: Reuse the compound type decision
737  int reuse_compound_type_decision;
738 
739  // Enable/disable masked compound.
740  int disable_masked_comp;
741 
742  // Reuse the best prediction modes found in PARTITION_SPLIT and PARTITION_RECT
743  // when encoding PARTITION_AB.
744  int reuse_best_prediction_for_part_ab;
745 
746  // Enable/disable the fast compound mode search.
747  int enable_fast_compound_mode_search;
748 } INTER_MODE_SPEED_FEATURES;
749 
750 typedef struct INTERP_FILTER_SPEED_FEATURES {
751  // Do limited interpolation filter search for dual filters, since best choice
752  // usually includes EIGHTTAP_REGULAR.
753  int use_fast_interpolation_filter_search;
754 
755  // Disable dual filter
756  int disable_dual_filter;
757 
758  // Save results of av1_interpolation_filter_search for a block
759  // Check mv and ref_frames before search, if they are very close with previous
760  // saved results, filter search can be skipped.
761  int use_interp_filter;
762 
763  // skip sharp_filter evaluation based on regular and smooth filter rd for
764  // dual_filter=0 case
765  int skip_sharp_interp_filter_search;
766 
767  int cb_pred_filter_search;
768 
769  // adaptive interp_filter search to allow skip of certain filter types.
770  int adaptive_interp_filter_search;
771 } INTERP_FILTER_SPEED_FEATURES;
772 
773 typedef struct INTRA_MODE_SPEED_FEATURES {
774  // These bit masks allow you to enable or disable intra modes for each
775  // transform size separately.
776  int intra_y_mode_mask[TX_SIZES];
777  int intra_uv_mode_mask[TX_SIZES];
778 
779  // flag to allow skipping intra mode for inter frame prediction
780  int skip_intra_in_interframe;
781 
782  // Prune intra mode candidates based on source block histogram of gradient.
783  // Applies to luma plane only.
784  int intra_pruning_with_hog;
785 
786  // Prune intra mode candidates based on source block histogram of gradient.
787  // Applies to chroma plane only.
788  int chroma_intra_pruning_with_hog;
789 
790  // Enable/disable smooth intra modes.
791  int disable_smooth_intra;
792 
793  // prune palette search
794  // 0: No pruning
795  // 1: Perform coarse search to prune the palette colors. For winner colors,
796  // neighbors are also evaluated using a finer search.
797  // 2: Perform 2 way palette search from max colors to min colors (and min
798  // colors to remaining colors) and terminate the search if current number of
799  // palette colors is not the winner.
800  int prune_palette_search_level;
801 } INTRA_MODE_SPEED_FEATURES;
802 
803 typedef struct TX_SPEED_FEATURES {
804  // Init search depth for square and rectangular transform partitions.
805  // Values:
806  // 0 - search full tree, 1: search 1 level, 2: search the highest level only
807  int inter_tx_size_search_init_depth_sqr;
808  int inter_tx_size_search_init_depth_rect;
809  int intra_tx_size_search_init_depth_sqr;
810  int intra_tx_size_search_init_depth_rect;
811 
812  // If any dimension of a coding block size above 64, always search the
813  // largest transform only, since the largest transform block size is 64x64.
814  int tx_size_search_lgr_block;
815 
816  TX_TYPE_SEARCH tx_type_search;
817 
818  // Skip split transform block partition when the collocated bigger block
819  // is selected as all zero coefficients.
820  int txb_split_cap;
821 
822  // Shortcut the transform block partition and type search when the target
823  // rdcost is relatively lower.
824  // Values are 0 (not used) , or 1 - 2 with progressively increasing
825  // aggressiveness
826  int adaptive_txb_search_level;
827 
828  // Prune level for tx_size_type search for inter based on rd model
829  // 0: no pruning
830  // 1-2: progressively increasing aggressiveness of pruning
831  int model_based_prune_tx_search_level;
832 
833  // Use hash table to store intra(keyframe only) txb transform search results
834  // to avoid repeated search on the same residue signal. This is currently not
835  // compatible with multi-winner mode as the hash states are reset during
836  // winner mode processing.
837  int use_intra_txb_hash;
838 
839  // Use hash table to store inter txb transform search results
840  // to avoid repeated search on the same residue signal.
841  int use_inter_txb_hash;
842 
843  // Refine TX type after fast TX search.
844  int refine_fast_tx_search_results;
845 
846  // Prune transform split/no_split eval based on residual properties. A value
847  // of 0 indicates no pruning, and the aggressiveness of pruning progressively
848  // increases from levels 1 to 3.
849  int prune_tx_size_level;
850 } TX_SPEED_FEATURES;
851 
852 typedef struct RD_CALC_SPEED_FEATURES {
853  // Fast approximation of av1_model_rd_from_var_lapndz
854  int simple_model_rd_from_var;
855 
856  // Whether to compute distortion in the image domain (slower but
857  // more accurate), or in the transform domain (faster but less acurate).
858  // 0: use image domain
859  // 1: use transform domain in tx_type search, and use image domain for
860  // RD_STATS
861  // 2: use transform domain
862  int tx_domain_dist_level;
863 
864  // Transform domain distortion threshold level
865  int tx_domain_dist_thres_level;
866 
867  // Trellis (dynamic programming) optimization of quantized values
868  TRELLIS_OPT_TYPE optimize_coefficients;
869 
870  // Use hash table to store macroblock RD search results
871  // to avoid repeated search on the same residue signal.
872  int use_mb_rd_hash;
873 
874  // Flag used to control the extent of coeff R-D optimization
875  int perform_coeff_opt;
876 } RD_CALC_SPEED_FEATURES;
877 
878 typedef struct WINNER_MODE_SPEED_FEATURES {
879  // Flag used to control the winner mode processing for better R-D optimization
880  // of quantized coeffs
881  int enable_winner_mode_for_coeff_opt;
882 
883  // Flag used to control the winner mode processing for transform size
884  // search method
885  int enable_winner_mode_for_tx_size_srch;
886 
887  // Control transform size search level
888  // Eval type: Default Mode Winner
889  // Level 0 : FULL RD LARGEST ALL FULL RD
890  // Level 1 : FAST RD LARGEST ALL FULL RD
891  // Level 2 : LARGEST ALL LARGEST ALL FULL RD
892  int tx_size_search_level;
893 
894  // Flag used to control the winner mode processing for use transform
895  // domain distortion
896  int enable_winner_mode_for_use_tx_domain_dist;
897 
898  // Flag used to enable processing of multiple winner modes
899  MULTI_WINNER_MODE_TYPE multi_winner_mode_type;
900 
901  // Motion mode for winner candidates:
902  // 0: speed feature OFF
903  // 1 / 2 : Use configured number of winner candidates
904  int motion_mode_for_winner_cand;
905 
906  // Early DC only txfm block prediction
907  // 0: speed feature OFF
908  // 1 / 2 : Use the configured level for different modes
909  int dc_blk_pred_level;
910 } WINNER_MODE_SPEED_FEATURES;
911 
912 typedef struct LOOP_FILTER_SPEED_FEATURES {
913  // This feature controls how the loop filter level is determined.
914  LPF_PICK_METHOD lpf_pick;
915 
916  // Skip some final iterations in the determination of the best loop filter
917  // level.
918  int use_coarse_filter_level_search;
919 
920  // Control how the CDEF strength is determined.
921  CDEF_PICK_METHOD cdef_pick_method;
922 
923  // Decoder side speed feature to add penalty for use of dual-sgr filters.
924  // Takes values 0 - 10, 0 indicating no penalty and each additional level
925  // adding a penalty of 1%
926  int dual_sgr_penalty_level;
927 
928  // prune sgr ep using binary search like mechanism
929  int enable_sgr_ep_pruning;
930 
931  // Disable loop restoration for Chroma plane
932  int disable_loop_restoration_chroma;
933 
934  // Prune RESTORE_WIENER evaluation based on source variance
935  // 0 : no pruning
936  // 1 : conservative pruning
937  // 2 : aggressive pruning
938  int prune_wiener_based_on_src_var;
939 
940  // Prune self-guided loop restoration based on wiener search results
941  // 0 : no pruning
942  // 1 : pruning based on rdcost ratio of RESTORE_WIENER and RESTORE_NONE
943  // 2 : pruning based on winner restoration type among RESTORE_WIENER and
944  // RESTORE_NONE
945  int prune_sgr_based_on_wiener;
946 
947  // Reduce the wiener filter win size for luma
948  int reduce_wiener_window_size;
949 
950  // Disable loop restoration filter
951  int disable_lr_filter;
952 } LOOP_FILTER_SPEED_FEATURES;
953 
954 typedef struct REAL_TIME_SPEED_FEATURES {
955  // check intra prediction for non-RD mode.
956  int check_intra_pred_nonrd;
957 
958  // skip checking intra prediction if TX is skipped
959  int skip_intra_pred_if_tx_skip;
960 
961  // Perform coarse ME before calculating variance in variance-based partition
962  int estimate_motion_for_var_based_partition;
963 
964  // For nonrd_use_partition: mode of extra check of leaf partition
965  // 0 - don't check merge
966  // 1 - always check merge
967  // 2 - check merge and prune checking final split
968  int nonrd_check_partition_merge_mode;
969 
970  // For nonrd_use_partition: check of leaf partition extra split
971  int nonrd_check_partition_split;
972 
973  // Implements various heuristics to skip searching modes
974  // The heuristics selected are based on flags
975  // defined in the MODE_SEARCH_SKIP_HEURISTICS enum
976  unsigned int mode_search_skip_flags;
977 
978  // For nonrd: Reduces ref frame search.
979  // 0 - low level of search prune in non last frames
980  // 1 - pruned search in non last frames
981  // 2 - more pruned search in non last frames
982  int nonrd_prune_ref_frame_search;
983 
984  // This flag controls the use of non-RD mode decision.
985  int use_nonrd_pick_mode;
986 
987  // Use ALTREF frame in non-RD mode decision.
988  int use_nonrd_altref_frame;
989 
990  // Use compound reference for non-RD mode.
991  int use_comp_ref_nonrd;
992 
993  // use reduced ref set for real-time mode
994  int use_real_time_ref_set;
995 
996  // Skip a number of expensive mode evaluations for blocks with very low
997  // temporal variance.
998  int short_circuit_low_temp_var;
999 
1000  // Use modeled (currently CurvFit model) RDCost for fast non-RD mode
1001  int use_modeled_non_rd_cost;
1002 
1003  // Reuse inter prediction in fast non-rd mode.
1004  int reuse_inter_pred_nonrd;
1005 
1006  // Number of best inter modes to search transform. INT_MAX - search all.
1007  int num_inter_modes_for_tx_search;
1008 
1009  // Forces TX search off for RDCost calulation.
1010  int force_tx_search_off;
1011 
1012  // Use interpolation filter search in non-RD mode decision.
1013  int use_nonrd_filter_search;
1014 
1015  // Use simplified RD model for interpolation search and Intra
1016  int use_simple_rd_model;
1017 
1018  // If set forces interpolation filter to EIGHTTAP_REGULAR
1019  int skip_interp_filter_search;
1020 
1021  // Use hybrid (rd for bsize < 16x16, otherwise nonrd) intra search for intra
1022  // only frames.
1023  int hybrid_intra_pickmode;
1024 
1025  // Compute variance/sse on source difference, prior to encoding superblock.
1026  int source_metrics_sb_nonrd;
1027 
1028  // Flag to indicate process for handling overshoot on slide/scene change,
1029  // for real-time CBR mode.
1030  OVERSHOOT_DETECTION_CBR overshoot_detection_cbr;
1031 
1032  // Check for scene/content change detection on every frame before encoding.
1033  int check_scene_detection;
1034 
1035  // Forces larger partition blocks in variance based partitioning
1036  int force_large_partition_blocks;
1037 
1038  // uses results of temporal noise estimate
1039  int use_temporal_noise_estimate;
1040 
1041  // Parameter indicating initial search window to be used in full-pixel search
1042  // for nonrd_pickmode. Range [0, MAX_MVSEARCH_STEPS - 1]. Lower value
1043  // indicates larger window. If set to 0, step_param is set based on internal
1044  // logic in set_mv_search_params().
1045  int fullpel_search_step_param;
1046 
1047  // Skip loopfilter (and cdef) in svc real-time mode for
1048  // non_reference/droppable frames.
1049  int skip_loopfilter_non_reference;
1050 
1051  // Bit mask to enable or disable intra modes for each prediction block size
1052  // separately, for nonrd pickmode.
1053  int intra_y_mode_bsize_mask_nrd[BLOCK_SIZES];
1054 
1055  // Skips mode checks more agressively in nonRD mode
1056  int nonrd_agressive_skip;
1057 } REAL_TIME_SPEED_FEATURES;
1058 
1064 typedef struct SPEED_FEATURES {
1069 
1073  TPL_SPEED_FEATURES tpl_sf;
1074 
1078  GLOBAL_MOTION_SPEED_FEATURES gm_sf;
1079 
1083  PARTITION_SPEED_FEATURES part_sf;
1084 
1088  MV_SPEED_FEATURES mv_sf;
1089 
1093  INTER_MODE_SPEED_FEATURES inter_sf;
1094 
1098  INTERP_FILTER_SPEED_FEATURES interp_sf;
1099 
1103  INTRA_MODE_SPEED_FEATURES intra_sf;
1104 
1108  TX_SPEED_FEATURES tx_sf;
1109 
1113  RD_CALC_SPEED_FEATURES rd_sf;
1114 
1118  WINNER_MODE_SPEED_FEATURES winner_mode_sf;
1119 
1123  LOOP_FILTER_SPEED_FEATURES lpf_sf;
1124 
1128  REAL_TIME_SPEED_FEATURES rt_sf;
1132 struct AV1_COMP;
1133 
1147  int speed);
1148 
1161  int speed);
1174 
1175 #ifdef __cplusplus
1176 } // extern "C"
1177 #endif
1178 
1179 #endif // AOM_AV1_ENCODER_SPEED_FEATURES_H_
void av1_set_speed_features_framesize_independent(struct AV1_COMP *cpi, int speed)
Frame size independent speed vs quality trade off flags.
void av1_set_speed_features_qindex_dependent(struct AV1_COMP *cpi, int speed)
Q index dependent speed vs quality trade off flags.
void av1_set_speed_features_framesize_dependent(struct AV1_COMP *cpi, int speed)
Frame size dependent speed vs quality trade off flags.
struct SPEED_FEATURES SPEED_FEATURES
Top level speed vs quality trade off data struture.
struct HIGH_LEVEL_SPEED_FEATURES HIGH_LEVEL_SPEED_FEATURES
Sequence/frame level speed vs quality features.
CDEF_PICK_METHOD
This enumeration defines a variety of CDEF pick methods.
Definition: speed_features.h:156
@ CDEF_FAST_SEARCH_LVL2
Definition: speed_features.h:159
@ CDEF_FAST_SEARCH_LVL1
Definition: speed_features.h:158
@ CDEF_FULL_SEARCH
Definition: speed_features.h:157
@ CDEF_PICK_FROM_Q
Definition: speed_features.h:163
@ CDEF_FAST_SEARCH_LVL4
Definition: speed_features.h:162
@ CDEF_FAST_SEARCH_LVL3
Definition: speed_features.h:160
Top level encoder structure.
Definition: encoder.h:2042
int speed
Definition: encoder.h:2259
Sequence/frame level speed vs quality features.
Definition: speed_features.h:294
int second_alt_ref_filtering
Definition: speed_features.h:339
int disable_extra_sc_testing
Definition: speed_features.h:334
int recode_tolerance
Definition: speed_features.h:309
RECODE_LOOP_TYPE recode_loop
Definition: speed_features.h:303
Top level speed vs quality trade off data struture.
Definition: speed_features.h:1064
MV_SPEED_FEATURES mv_sf
Definition: speed_features.h:1088
TPL_SPEED_FEATURES tpl_sf
Definition: speed_features.h:1073
LOOP_FILTER_SPEED_FEATURES lpf_sf
Definition: speed_features.h:1123
TX_SPEED_FEATURES tx_sf
Definition: speed_features.h:1108
INTER_MODE_SPEED_FEATURES inter_sf
Definition: speed_features.h:1093
RD_CALC_SPEED_FEATURES rd_sf
Definition: speed_features.h:1113
PARTITION_SPEED_FEATURES part_sf
Definition: speed_features.h:1083
GLOBAL_MOTION_SPEED_FEATURES gm_sf
Definition: speed_features.h:1078
INTERP_FILTER_SPEED_FEATURES interp_sf
Definition: speed_features.h:1098
INTRA_MODE_SPEED_FEATURES intra_sf
Definition: speed_features.h:1103
WINNER_MODE_SPEED_FEATURES winner_mode_sf
Definition: speed_features.h:1118
REAL_TIME_SPEED_FEATURES rt_sf
Definition: speed_features.h:1128
HIGH_LEVEL_SPEED_FEATURES hl_sf
Definition: speed_features.h:1068