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 {
165  CDEF_PICK_METHODS
167 
169 enum {
170  // Terminate search early based on distortion so far compared to
171  // qp step, distortion in the neighborhood of the frame, etc.
172  FLAG_EARLY_TERMINATE = 1 << 0,
173 
174  // Skips comp inter modes if the best so far is an intra mode.
175  FLAG_SKIP_COMP_BESTINTRA = 1 << 1,
176 
177  // Skips oblique intra modes if the best so far is an inter mode.
178  FLAG_SKIP_INTRA_BESTINTER = 1 << 3,
179 
180  // Skips oblique intra modes at angles 27, 63, 117, 153 if the best
181  // intra so far is not one of the neighboring directions.
182  FLAG_SKIP_INTRA_DIRMISMATCH = 1 << 4,
183 
184  // Skips intra modes other than DC_PRED if the source variance is small
185  FLAG_SKIP_INTRA_LOWVAR = 1 << 5,
186 } UENUM1BYTE(MODE_SEARCH_SKIP_LOGIC);
187 
188 enum {
189  // No tx type pruning
190  TX_TYPE_PRUNE_0 = 0,
191  // adaptively prunes the least perspective tx types out of all 16
192  // (tuned to provide negligible quality loss)
193  TX_TYPE_PRUNE_1 = 1,
194  // similar, but applies much more aggressive pruning to get better speed-up
195  TX_TYPE_PRUNE_2 = 2,
196  TX_TYPE_PRUNE_3 = 3,
197  // More aggressive pruning based on tx type score and allowed tx count
198  TX_TYPE_PRUNE_4 = 4,
199  TX_TYPE_PRUNE_5 = 5,
200 } UENUM1BYTE(TX_TYPE_PRUNE_MODE);
201 
202 enum {
203  // No reaction to rate control on a detected slide/scene change.
204  NO_DETECTION = 0,
205 
206  // Set to larger Q based only on the detected slide/scene change and
207  // current/past Q.
208  FAST_DETECTION_MAXQ = 1,
209 } UENUM1BYTE(OVERSHOOT_DETECTION_CBR);
210 
211 enum {
212  // Turns off multi-winner mode. So we will do txfm search on either all modes
213  // if winner mode is off, or we will only on txfm search on a single winner
214  // mode.
215  MULTI_WINNER_MODE_OFF = 0,
216 
217  // Limits the number of winner modes to at most 2
218  MULTI_WINNER_MODE_FAST = 1,
219 
220  // Uses the default number of winner modes, which is 3 for intra mode, and 1
221  // for inter mode.
222  MULTI_WINNER_MODE_DEFAULT = 2,
223 
224  // Maximum number of winner modes allowed.
225  MULTI_WINNER_MODE_LEVELS,
226 } UENUM1BYTE(MULTI_WINNER_MODE_TYPE);
227 
228 enum {
229  PRUNE_NEARMV_OFF = 0, // Turn off nearmv pruning
230  PRUNE_NEARMV_LEVEL1 = 1, // Prune nearmv for qindex (0-85)
231  PRUNE_NEARMV_LEVEL2 = 2, // Prune nearmv for qindex (0-170)
232  PRUNE_NEARMV_LEVEL3 = 3, // Prune nearmv more aggressively for qindex (0-170)
233  PRUNE_NEARMV_MAX = PRUNE_NEARMV_LEVEL3,
234 } UENUM1BYTE(PRUNE_NEARMV_LEVEL);
235 
236 typedef struct {
237  TX_TYPE_PRUNE_MODE prune_2d_txfm_mode;
238  int fast_intra_tx_type_search;
239 
240  // INT_MAX: Disable fast search.
241  // 1 - 1024: Probability threshold used for conditionally forcing tx type,
242  // during mode search.
243  // 0: Force tx type to be DCT_DCT unconditionally, during
244  // mode search.
245  int fast_inter_tx_type_prob_thresh;
246 
247  // Prune less likely chosen transforms for each intra mode. The speed
248  // feature ranges from 0 to 2, for different speed / compression trade offs.
249  int use_reduced_intra_txset;
250 
251  // Use a skip flag prediction model to detect blocks with skip = 1 early
252  // and avoid doing full TX type search for such blocks.
253  int use_skip_flag_prediction;
254 
255  // Threshold used by the ML based method to predict TX block split decisions.
256  int ml_tx_split_thresh;
257 
258  // skip remaining transform type search when we found the rdcost of skip is
259  // better than applying transform
260  int skip_tx_search;
261 
262  // Prune tx type search using previous frame stats.
263  int prune_tx_type_using_stats;
264  // Prune tx type search using estimated RDcost
265  int prune_tx_type_est_rd;
266 
267  // Flag used to control the winner mode processing for tx type pruning for
268  // inter blocks. It enables further tx type mode pruning based on ML model for
269  // mode evaluation and disables tx type mode pruning for winner mode
270  // processing.
271  int winner_mode_tx_type_pruning;
272 } TX_TYPE_SEARCH;
273 
274 enum {
275  // Search partitions using RD criterion
276  SEARCH_PARTITION,
277 
278  // Always use a fixed size partition
279  FIXED_PARTITION,
280 
281  // Partition using source variance
282  VAR_BASED_PARTITION,
283 
284 #if CONFIG_RT_ML_PARTITIONING
285  // Partition using ML model
286  ML_BASED_PARTITION
287 #endif
288 } UENUM1BYTE(PARTITION_SEARCH_TYPE);
289 
290 enum {
291  NOT_IN_USE,
292  DIRECT_PRED,
293  RELAXED_PRED,
294  ADAPT_PRED
295 } UENUM1BYTE(MAX_PART_PRED_MODE);
296 
297 enum {
298  LAST_MV_DATA,
299  CURRENT_Q,
300  QTR_ONLY,
301 } UENUM1BYTE(MV_PREC_LOGIC);
302 
303 enum {
304  SUPERRES_AUTO_ALL, // Tries all possible superres ratios
305  SUPERRES_AUTO_DUAL, // Tries no superres and q-based superres ratios
306  SUPERRES_AUTO_SOLO, // Only apply the q-based superres ratio
307 } UENUM1BYTE(SUPERRES_AUTO_SEARCH_TYPE);
325 typedef enum {
332 
337 typedef enum {
338  NO_PRUNING = -1,
355 
359 typedef enum {
364 
369 typedef enum {
371  0,
373  1,
375  2,
377  3,
379  4,
382 
389 
393  RECODE_LOOP_TYPE recode_loop;
394 
400 
407  MV_PREC_LOGIC high_precision_mv_usage;
408 
417 
421  SUPERRES_AUTO_SEARCH_TYPE superres_auto_search_type;
422 
427 
432 
439 
451 
456 
461 
467 
469 typedef struct TPL_SPEED_FEATURES {
470  // GOP length adaptive decision.
471  // If set to 0, tpl model decides whether a shorter gf interval is better.
472  // If set to 1, tpl stats of ARFs from base layer, (base+1) layer and
473  // (base+2) layer decide whether a shorter gf interval is better.
474  // If set to 2, tpl stats of ARFs from base layer, (base+1) layer and GF boost
475  // decide whether a shorter gf interval is better.
476  // If set to 3, gop length adaptive decision is disabled.
477  int gop_length_decision_method;
478  // Prune the intra modes search by tpl.
479  // If set to 0, we will search all intra modes from DC_PRED to PAETH_PRED.
480  // If set to 1, we only search DC_PRED, V_PRED, and H_PRED.
481  int prune_intra_modes;
482  // This parameter controls which step in the n-step process we start at.
483  int reduce_first_step_size;
484  // Skip motion estimation based on the precision of center MVs and the
485  // difference between center MVs.
486  // If set to 0, motion estimation is skipped for duplicate center MVs
487  // (default). If set to 1, motion estimation is skipped for duplicate
488  // full-pixel center MVs. If set to 2, motion estimation is skipped if the
489  // difference between center MVs is less than the threshold.
490  int skip_alike_starting_mv;
491 
492  // When to stop subpel search.
493  SUBPEL_FORCE_STOP subpel_force_stop;
494 
495  // Which search method to use.
496  SEARCH_METHODS search_method;
497 
498  // Prune starting mvs in TPL based on sad scores.
499  int prune_starting_mv;
500 
501  // Not run TPL for filtered Key frame.
502  int disable_filtered_key_tpl;
503 
504  // Prune reference frames in TPL.
505  int prune_ref_frames_in_tpl;
506 
507  // Support compound predictions.
508  int allow_compound_pred;
509 
510  // Calculate rate and distortion based on Y plane only.
511  int use_y_only_rate_distortion;
512 } TPL_SPEED_FEATURES;
513 
514 typedef struct GLOBAL_MOTION_SPEED_FEATURES {
515  GM_SEARCH_TYPE gm_search_type;
516 
517  // During global motion estimation, prune remaining reference frames in a
518  // given direction(past/future), if the evaluated ref_frame in that direction
519  // yields gm_type as INVALID/TRANSLATION/IDENTITY
520  int prune_ref_frame_for_gm_search;
521 
522  // When the current GM type is set to ZEROMV, prune ZEROMV if its performance
523  // is worse than NEWMV under SSE metric.
524  // 0 : no pruning
525  // 1 : conservative pruning
526  // 2 : aggressive pruning
528 
529  // Disable global motion estimation based on stats of previous frames in the
530  // GF group
531  int disable_gm_search_based_on_stats;
532 } GLOBAL_MOTION_SPEED_FEATURES;
533 
534 typedef struct PARTITION_SPEED_FEATURES {
535  PARTITION_SEARCH_TYPE partition_search_type;
536 
537  // Used if partition_search_type = FIXED_PARTITION
538  BLOCK_SIZE fixed_partition_size;
539 
540  // Prune extended partition types search
541  // Can take values 0 - 2, 0 referring to no pruning, and 1 - 2 increasing
542  // aggressiveness of pruning in order.
543  int prune_ext_partition_types_search_level;
544 
545  // Prune part4 based on block size
546  int prune_part4_search;
547 
548  // Use a ML model to prune rectangular, ab and 4-way horz
549  // and vert partitions
550  int ml_prune_partition;
551 
552  // Use a ML model to adaptively terminate partition search after trying
553  // PARTITION_SPLIT. Can take values 0 - 2, 0 meaning not being enabled, and
554  // 1 - 2 increasing aggressiveness in order.
555  int ml_early_term_after_part_split_level;
556 
557  // Skip rectangular partition test when partition type none gives better
558  // rd than partition type split. Can take values 0 - 2, 0 referring to no
559  // skipping, and 1 - 2 increasing aggressiveness of skipping in order.
560  int less_rectangular_check_level;
561 
562  // Use square partition only beyond this block size.
563  BLOCK_SIZE use_square_partition_only_threshold;
564 
565  // Sets max square partition levels for this superblock based on
566  // motion vector and prediction error distribution produced from 16x16
567  // simple motion search
568  MAX_PART_PRED_MODE auto_max_partition_based_on_simple_motion;
569 
570  // Min and max square partition size we enable (block_size) as per auto
571  // min max, but also used by adjust partitioning, and pick_partitioning.
572  BLOCK_SIZE default_min_partition_size;
573  BLOCK_SIZE default_max_partition_size;
574 
575  // Sets level of adjustment of variance-based partitioning during
576  // rd_use_partition 0 - no partition adjustment, 1 - try to merge partitions
577  // for small blocks and high QP, 2 - try to merge partitions, 3 - try to merge
578  // and split leaf partitions and 0 - 3 decreasing aggressiveness in order.
579  int adjust_var_based_rd_partitioning;
580 
581  // Partition search early breakout thresholds.
582  int64_t partition_search_breakout_dist_thr;
583  int partition_search_breakout_rate_thr;
584 
585  // Thresholds for ML based partition search breakout.
586  int ml_partition_search_breakout_thresh[PARTITION_BLOCK_SIZES];
587 
588  // Aggressiveness levels for pruning split and rectangular partitions based on
589  // simple_motion_search. SIMPLE_AGG_LVL0 to SIMPLE_AGG_LVL3 correspond to
590  // simple motion search based pruning. QIDX_BASED_AGG_LVL1 corresponds to
591  // qindex based and simple motion search based pruning.
592  int simple_motion_search_prune_agg;
593 
594  // Perform simple_motion_search on each possible subblock and use it to prune
595  // PARTITION_HORZ and PARTITION_VERT.
596  int simple_motion_search_prune_rect;
597 
598  // Perform simple motion search before none_partition to decide if we
599  // want to remove all partitions other than PARTITION_SPLIT. If set to 0, this
600  // model is disabled. If set to 1, the model attempts to perform
601  // PARTITION_SPLIT only. If set to 2, the model also attempts to prune
602  // PARTITION_SPLIT.
603  int simple_motion_search_split;
604 
605  // Use features from simple_motion_search to terminate prediction block
606  // partition after PARTITION_NONE
607  int simple_motion_search_early_term_none;
608 
609  // Controls whether to reduce the number of motion search steps. If this is 0,
610  // then simple_motion_search has the same number of steps as
611  // single_motion_search (assuming no other speed features). Otherwise, reduce
612  // the number of steps by the value contained in this variable.
613  int simple_motion_search_reduce_search_steps;
614 
615  // This variable controls the maximum block size where intra blocks can be
616  // used in inter frames.
617  // TODO(aconverse): Fold this into one of the other many mode skips
618  BLOCK_SIZE max_intra_bsize;
619 
620  // Use CNN with luma pixels on source frame on each of the 64x64 subblock to
621  // perform partition pruning in intra frames.
622  // 0: No Pruning
623  // 1: Prune split and rectangular partitions only
624  // 2: Prune none, split and rectangular partitions
625  int intra_cnn_based_part_prune_level;
626 
627  // Disable extended partition search for lower block sizes.
628  int ext_partition_eval_thresh;
629 
630  // Disable rectangular partitions for larger block sizes.
631  int rect_partition_eval_thresh;
632 
633  // prune extended partition search
634  // 0 : no pruning
635  // 1 : prune 1:4 partition search using winner info from split partitions
636  // 2 : prune 1:4 and AB partition search using split and HORZ/VERT info
637  int prune_ext_part_using_split_info;
638 
639  // Prunt rectangular, AB and 4-way partition based on q index and block size
640  // 0 : no pruning
641  // 1 : prune sub_8x8 at very low quantizers
642  // 2 : prune all block size based on qindex
643  int prune_rectangular_split_based_on_qidx;
644 
645  // Terminate partition search for child partition,
646  // when NONE and SPLIT partition rd_costs are INT64_MAX.
647  int early_term_after_none_split;
648 
649  // Level used to adjust threshold for av1_ml_predict_breakout(). At lower
650  // levels, more conservative threshold is used, and value of 0 indicates
651  // av1_ml_predict_breakout() is disabled. Value of 3 corresponds to default
652  // case with no adjustment to lbd thresholds.
653  int ml_predict_breakout_level;
654 
655  // Prune sub_8x8 (BLOCK_4X4, BLOCK_4X8 and BLOCK_8X4) partitions.
656  // 0 : no pruning
657  // 1 : pruning based on neighbour block information
658  // 2 : prune always
659  int prune_sub_8x8_partition_level;
660 
661  // Prune rectangular split based on simple motion search split/no_split score.
662  // 0: disable pruning, 1: enable pruning
663  int simple_motion_search_rect_split;
664 
665  // The current encoder adopts a DFS search for block partitions.
666  // Therefore the mode selection and associated rdcost is ready for smaller
667  // blocks before the mode selection for some partition types.
668  // AB partition could use previous rd information and skip mode search.
669  // An example is:
670  //
671  // current block
672  // +---+---+
673  // | |
674  // + +
675  // | |
676  // +-------+
677  //
678  // SPLIT partition has been searched first before trying HORZ_A
679  // +---+---+
680  // | R | R |
681  // +---+---+
682  // | R | R |
683  // +---+---+
684  //
685  // HORZ_A
686  // +---+---+
687  // | | |
688  // +---+---+
689  // | |
690  // +-------+
691  //
692  // With this speed feature, the top two sub blocks can directly use rdcost
693  // searched in split partition, and the mode info is also copied from
694  // saved info. Similarly, the bottom rectangular block can also use
695  // the available information from previous rectangular search.
696  int reuse_prev_rd_results_for_part_ab;
697 
698  // Reuse the best prediction modes found in PARTITION_SPLIT and PARTITION_RECT
699  // when encoding PARTITION_AB.
700  int reuse_best_prediction_for_part_ab;
701 
702  // The current partition search records the best rdcost so far and uses it
703  // in mode search and transform search to early skip when some criteria is
704  // met. For example, when the current rdcost is larger than the best rdcost,
705  // or the model rdcost is larger than the best rdcost times some thresholds.
706  // By default, this feature is turned on to speed up the encoder partition
707  // search.
708  // If disabling it, at speed 0, 30 frames, we could get
709  // about -0.25% quality gain (psnr, ssim, vmaf), with about 13% slowdown.
710  int use_best_rd_for_pruning;
711 
712  // Skip evaluation of non-square partitions based on the corresponding NONE
713  // partition.
714  // 0: no pruning
715  // 1: prune extended partitions if NONE is skippable
716  // 2: on top of 1, prune rectangular partitions if NONE is inter, not a newmv
717  // mode and skippable
718  int skip_non_sq_part_based_on_none;
719 } PARTITION_SPEED_FEATURES;
720 
721 typedef struct MV_SPEED_FEATURES {
722  // Motion search method (Diamond, NSTEP, Hex, Big Diamond, Square, etc).
723  SEARCH_METHODS search_method;
724 
725  // Enable the use of faster, less accurate mv search method on bsize >=
726  // BLOCK_32X32.
727  // TODO(chiyotsai@google.com): Take the clip's resolution and mv activity into
728  // account.
729  int use_bsize_dependent_search_method;
730 
731  // If this is set to 1, we limit the motion search range to 2 times the
732  // largest motion vector found in the last frame.
733  int auto_mv_step_size;
734 
735  // Subpel_search_method can only be subpel_tree which does a subpixel
736  // logarithmic search that keeps stepping at 1/2 pixel units until
737  // you stop getting a gain, and then goes on to 1/4 and repeats
738  // the same process. Along the way it skips many diagonals.
739  SUBPEL_SEARCH_METHODS subpel_search_method;
740 
741  // Maximum number of steps in logarithmic subpel search before giving up.
742  int subpel_iters_per_step;
743 
744  // When to stop subpel search.
745  SUBPEL_FORCE_STOP subpel_force_stop;
746 
747  // When to stop subpel search in simple motion search.
748  SUBPEL_FORCE_STOP simple_motion_subpel_force_stop;
749 
750  // If true, sub-pixel search uses the exact convolve function used for final
751  // encoding and decoding; otherwise, it uses bilinear interpolation.
752  SUBPEL_SEARCH_TYPE use_accurate_subpel_search;
753 
754  // Threshold for allowing exhaustive motion search.
755  int exhaustive_searches_thresh;
756 
757  // Pattern to be used for any exhaustive mesh searches (except intraBC ME).
758  MESH_PATTERN mesh_patterns[MAX_MESH_STEP];
759 
760  // Pattern to be used for exhaustive mesh searches of intraBC ME.
761  MESH_PATTERN intrabc_mesh_patterns[MAX_MESH_STEP];
762 
763  // Reduce single motion search range based on MV result of prior ref_mv_idx.
764  int reduce_search_range;
765 
766  // Prune mesh search.
767  PRUNE_MESH_SEARCH_LEVEL prune_mesh_search;
768 
769  // Use the rd cost around the best FULLPEL_MV to speed up subpel search
770  int use_fullpel_costlist;
771 
772  // Set the full pixel search level of obmc
773  // 0: obmc_full_pixel_diamond
774  // 1: obmc_refining_search_sad (faster)
775  int obmc_full_pixel_search_level;
776 
777  // Accurate full pixel motion search based on TPL stats.
778  int full_pixel_search_level;
779 
780  // Whether to downsample the rows in sad calculation during motion search.
781  // This is only active when there are at least 16 rows.
782  int use_downsampled_sad;
783 
784  // Enable/disable extensive joint motion search.
785  int disable_extensive_joint_motion_search;
786 
787  // Enable second best mv check in joint mv search.
788  // 0: allow second MV (use rd cost as the metric)
789  // 1: use var as the metric
790  // 2: disable second MV
791  int disable_second_mv;
792 
793  // Skips full pixel search based on start mv of prior ref_mv_idx.
794  int skip_fullpel_search_using_startmv;
795 } MV_SPEED_FEATURES;
796 
797 typedef struct INTER_MODE_SPEED_FEATURES {
798  // 2-pass inter mode model estimation where the preliminary pass skips
799  // transform search and uses a model to estimate rd, while the final pass
800  // computes the full transform search. Two types of models are supported:
801  // 0: not used
802  // 1: used with online dynamic rd model
803  // 2: used with static rd model
804  int inter_mode_rd_model_estimation;
805 
806  // Bypass transform search based on skip rd
807  int txfm_rd_gate_level;
808 
809  // Limit the inter mode tested in the RD loop
810  int reduce_inter_modes;
811 
812  // This variable is used to cap the maximum number of times we skip testing a
813  // mode to be evaluated. A high value means we will be faster.
814  int adaptive_rd_thresh;
815 
816  // Aggressively prune inter modes when best mode is skippable.
817  int prune_inter_modes_if_skippable;
818 
819  // Drop less likely to be picked reference frames in the RD search.
820  // Has seven levels for now: 0, 1, 2, 3, 4, 5 and 6 where higher levels prune
821  // more aggressively than lower ones. (0 means no pruning).
822  int selective_ref_frame;
823 
824  // Prune reference frames for rectangular partitions.
825  // 0 implies no pruning
826  // 1 implies prune for extended partition
827  // 2 implies prune horiz, vert and extended partition
828  int prune_ref_frame_for_rect_partitions;
829 
830  // Prune inter modes w.r.t past reference frames
831  // 0 no pruning
832  // 1 prune inter modes w.r.t ALTREF2 and ALTREF reference frames
833  // 2 prune inter modes w.r.t BWDREF, ALTREF2 and ALTREF reference frames
834  int alt_ref_search_fp;
835 
836  // Prune compound reference frames
837  // 0 no pruning
838  // 1 prune compound references which do not satisfy the two conditions:
839  // a) The references are at a nearest distance from the current frame in
840  // both past and future direction.
841  // b) The references have minimum pred_mv_sad in both past and future
842  // direction.
843  // 2 prune compound references except the one with nearest distance from the
844  // current frame in both past and future direction.
845  int prune_comp_ref_frames;
846 
847  // Skip the current ref_mv in NEW_MV mode based on mv, rate cost, etc.
848  // This speed feature equaling 0 means no skipping.
849  // If the speed feature equals 1 or 2, skip the current ref_mv in NEW_MV mode
850  // if we have already encountered ref_mv in the drl such that:
851  // 1. The other drl has the same mv during the SIMPLE_TRANSLATION search
852  // process as the current mv.
853  // 2. The rate needed to encode the current mv is larger than that for the
854  // other ref_mv.
855  // The speed feature equaling 1 means using subpel mv in the comparison.
856  // The speed feature equaling 2 means using fullpel mv in the comparison.
857  // If the speed feature >= 3, skip the current ref_mv in NEW_MV mode based on
858  // known full_mv bestsme and drl cost.
859  int skip_newmv_in_drl;
860 
861  // This speed feature checks duplicate ref MVs among NEARESTMV, NEARMV,
862  // GLOBALMV and skips NEARMV or GLOBALMV (in order) if a duplicate is found
863  // TODO(any): Instead of skipping repeated ref mv, use the recalculated
864  // rd-cost based on mode rate and skip the mode evaluation
865  int skip_repeated_ref_mv;
866 
867  // Flag used to control the ref_best_rd based gating for chroma
868  int perform_best_rd_based_gating_for_chroma;
869 
870  // Reuse the inter_intra_mode search result from NEARESTMV mode to other
871  // single ref modes
872  int reuse_inter_intra_mode;
873 
874  // prune wedge and compound segment approximate rd evaluation based on
875  // compound average modeled rd
876  int prune_comp_type_by_model_rd;
877 
878  // prune wedge and compound segment approximate rd evaluation based on
879  // compound average rd/ref_best_rd
880  int prune_comp_type_by_comp_avg;
881 
882  // Skip some ref frames in compound motion search by single motion search
883  // result. Has three levels for now: 0 referring to no skipping, and 1 - 3
884  // increasing aggressiveness of skipping in order.
885  // Note: The search order might affect the result. It assumes that the single
886  // reference modes are searched before compound modes. It is better to search
887  // same single inter mode as a group.
888  int prune_comp_search_by_single_result;
889 
890  // Instead of performing a full MV search, do a simple translation first
891  // and only perform a full MV search on the motion vectors that performed
892  // well.
893  int prune_mode_search_simple_translation;
894 
895  // Only search compound modes with at least one "good" reference frame.
896  // A reference frame is good if, after looking at its performance among
897  // the single reference modes, it is one of the two best performers.
898  int prune_compound_using_single_ref;
899 
900  // Skip extended compound mode (NEAREST_NEWMV, NEW_NEARESTMV, NEAR_NEWMV,
901  // NEW_NEARMV) using ref frames of above and left neighbor
902  // blocks.
903  // 0 : no pruning
904  // 1 : prune ext compound modes using neighbor blocks (less aggressiveness)
905  // 2 : prune ext compound modes using neighbor blocks (high aggressiveness)
906  // 3 : prune ext compound modes unconditionally (highest aggressiveness)
907  int prune_ext_comp_using_neighbors;
908 
909  // Skip NEW_NEARMV and NEAR_NEWMV extended compound modes
910  int skip_ext_comp_nearmv_mode;
911 
912  // Skip extended compound mode when ref frame corresponding to NEWMV does not
913  // have NEWMV as single mode winner.
914  // 0 : no pruning
915  // 1 : prune extended compound mode (less aggressiveness)
916  // 2 : prune extended compound mode (high aggressiveness)
917  int prune_comp_using_best_single_mode_ref;
918 
919  // Skip NEARESTMV and NEARMV using weight computed in ref mv list population
920  int prune_nearest_near_mv_using_refmv_weight;
921 
922  // Based on previous ref_mv_idx search result, prune the following search.
923  int prune_ref_mv_idx_search;
924 
925  // Disable one sided compound modes.
926  int disable_onesided_comp;
927 
928  // Prune obmc search using previous frame stats.
929  // INT_MAX : disable obmc search
930  int prune_obmc_prob_thresh;
931 
932  // Prune warped motion search using previous frame stats.
933  int prune_warped_prob_thresh;
934 
935  // Variance threshold to enable/disable Interintra wedge search
936  unsigned int disable_interintra_wedge_var_thresh;
937 
938  // Variance threshold to enable/disable Interinter wedge search
939  unsigned int disable_interinter_wedge_var_thresh;
940 
941  // De-couple wedge and mode search during interintra RDO.
942  int fast_interintra_wedge_search;
943 
944  // Whether fast wedge sign estimate is used
945  int fast_wedge_sign_estimate;
946 
947  // Enable/disable ME for interinter wedge search.
948  int disable_interinter_wedge_newmv_search;
949 
950  // Decide when and how to use joint_comp.
951  DIST_WTD_COMP_FLAG use_dist_wtd_comp_flag;
952 
953  // Clip the frequency of updating the mv cost.
954  INTERNAL_COST_UPDATE_TYPE mv_cost_upd_level;
955 
956  // Clip the frequency of updating the coeff cost.
957  INTERNAL_COST_UPDATE_TYPE coeff_cost_upd_level;
958 
959  // Clip the frequency of updating the mode cost.
960  INTERNAL_COST_UPDATE_TYPE mode_cost_upd_level;
961 
962  // Prune inter modes based on tpl stats
963  // 0 : no pruning
964  // 1 - 3 indicate increasing aggressiveness in order.
965  int prune_inter_modes_based_on_tpl;
966 
967  // Skip NEARMV and NEAR_NEARMV modes using ref frames of above and left
968  // neighbor blocks and qindex.
969  PRUNE_NEARMV_LEVEL prune_nearmv_using_neighbors;
970 
971  // Model based breakout after interpolation filter search
972  // 0: no breakout
973  // 1: use model based rd breakout
974  int model_based_post_interp_filter_breakout;
975 
976  // Reuse compound type rd decision when exact match is found
977  // 0: No reuse
978  // 1: Reuse the compound type decision
979  int reuse_compound_type_decision;
980 
981  // Enable/disable masked compound.
982  int disable_masked_comp;
983 
984  // Enable/disable the fast compound mode search.
985  int enable_fast_compound_mode_search;
986 
987  // Reuse masked compound type search results
988  int reuse_mask_search_results;
989 
990  // Enable/disable fast search for wedge masks
991  int enable_fast_wedge_mask_search;
992 
993  // Early breakout from transform search of inter modes
994  int inter_mode_txfm_breakout;
995 
996  // Limit number of inter modes for txfm search if a newmv mode gets
997  // evaluated among the top modes.
998  // 0: no pruning
999  // 1 to 3 indicate increasing order of aggressiveness
1000  int limit_inter_mode_cands;
1001 
1002  // Cap the no. of txfm searches for a given prediction mode.
1003  // 0: no cap, 1: cap beyond first 4 searches, 2: cap beyond first 3 searches.
1004  int limit_txfm_eval_per_mode;
1005 
1006  // Prune warped motion search based on block size.
1007  int extra_prune_warped;
1008 
1009  // Do not search compound modes for ARF.
1010  // The intuition is that ARF is predicted by frames far away from it,
1011  // whose temporal correlations with the ARF are likely low.
1012  // It is therefore likely that compound modes do not work as well for ARF
1013  // as other inter frames.
1014  // Speed/quality impact:
1015  // Speed 1: 12% faster, 0.1% psnr loss.
1016  // Speed 2: 2% faster, 0.05% psnr loss.
1017  // No change for speed 3 and up, because |disable_onesided_comp| is true.
1018  int skip_arf_compound;
1019 } INTER_MODE_SPEED_FEATURES;
1020 
1021 typedef struct INTERP_FILTER_SPEED_FEATURES {
1022  // Do limited interpolation filter search for dual filters, since best choice
1023  // usually includes EIGHTTAP_REGULAR.
1024  int use_fast_interpolation_filter_search;
1025 
1026  // Disable dual filter
1027  int disable_dual_filter;
1028 
1029  // Save results of av1_interpolation_filter_search for a block
1030  // Check mv and ref_frames before search, if they are very close with previous
1031  // saved results, filter search can be skipped.
1032  int use_interp_filter;
1033 
1034  // skip sharp_filter evaluation based on regular and smooth filter rd for
1035  // dual_filter=0 case
1036  int skip_sharp_interp_filter_search;
1037 
1038  int cb_pred_filter_search;
1039 
1040  // adaptive interp_filter search to allow skip of certain filter types.
1041  int adaptive_interp_filter_search;
1042 } INTERP_FILTER_SPEED_FEATURES;
1043 
1044 typedef struct INTRA_MODE_SPEED_FEATURES {
1045  // These bit masks allow you to enable or disable intra modes for each
1046  // transform size separately.
1047  int intra_y_mode_mask[TX_SIZES];
1048  int intra_uv_mode_mask[TX_SIZES];
1049 
1050  // flag to allow skipping intra mode for inter frame prediction
1051  int skip_intra_in_interframe;
1052 
1053  // Prune intra mode candidates based on source block histogram of gradient.
1054  // Applies to luma plane only.
1055  // Feasible values are 0..4. The feature is disabled for 0. An increasing
1056  // value indicates more aggressive pruning threshold.
1057  int intra_pruning_with_hog;
1058 
1059  // Prune intra mode candidates based on source block histogram of gradient.
1060  // Applies to chroma plane only.
1061  // Feasible values are 0..4. The feature is disabled for 0. An increasing
1062  // value indicates more aggressive pruning threshold.
1063  int chroma_intra_pruning_with_hog;
1064 
1065  // Enable/disable smooth intra modes.
1066  int disable_smooth_intra;
1067 
1068  // Prune filter intra modes in intra frames.
1069  // 0 : No pruning
1070  // 1 : Evaluate applicable filter intra modes based on best intra mode so far
1071  // 2 : Do not evaluate filter intra modes
1072  int prune_filter_intra_level;
1073 
1074  // prune palette search
1075  // 0: No pruning
1076  // 1: Perform coarse search to prune the palette colors. For winner colors,
1077  // neighbors are also evaluated using a finer search.
1078  // 2: Perform 2 way palette search from max colors to min colors (and min
1079  // colors to remaining colors) and terminate the search if current number of
1080  // palette colors is not the winner.
1081  int prune_palette_search_level;
1082 
1083  // Terminate early in luma palette_size search. Speed feature values indicate
1084  // increasing level of pruning.
1085  // 0: No early termination
1086  // 1: Terminate early for higher luma palette_size, if header rd cost of lower
1087  // palette_size is more than 2 * best_rd. This level of pruning is more
1088  // conservative when compared to sf level 2 as the cases which will get pruned
1089  // with sf level 1 is a subset of the cases which will get pruned with sf
1090  // level 2.
1091  // 2: Terminate early for higher luma palette_size, if header rd cost of lower
1092  // palette_size is more than best_rd.
1093  // For allintra encode, this sf reduces instruction count by 2.49%, 1.07%,
1094  // 2.76%, 2.30%, 1.84%, 2.69%, 2.04%, 2.05% and 1.44% for speed 0, 1, 2, 3, 4,
1095  // 5, 6, 7 and 8 on screen content set with coding performance change less
1096  // than 0.01% for speed <= 2 and less than 0.03% for speed >= 3. For AVIF
1097  // image encode, this sf reduces instruction count by 1.94%, 1.13%, 1.29%,
1098  // 0.93%, 0.89%, 1.03%, 1.07%, 1.20% and 0.18% for speed 0, 1, 2, 3, 4, 5, 6,
1099  // 7 and 8 on a typical image dataset with coding performance change less than
1100  // 0.01%.
1101  int prune_luma_palette_size_search_level;
1102 
1103  // Prune chroma intra modes based on luma intra mode winner.
1104  // 0: No pruning
1105  // 1: Prune chroma intra modes other than UV_DC_PRED, UV_SMOOTH_PRED,
1106  // UV_CFL_PRED and the mode that corresponds to luma intra mode winner.
1107  int prune_chroma_modes_using_luma_winner;
1108 
1109  // Clip the frequency of updating the mv cost for intrabc.
1110  INTERNAL_COST_UPDATE_TYPE dv_cost_upd_level;
1111 
1112  // We use DCT_DCT transform followed by computing SATD (Sum of Absolute
1113  // Transformed Differences) as an estimation of RD score to quickly find the
1114  // best possible Chroma from Luma (CFL) parameter. Then we do a full RD search
1115  // near the best possible parameter. The search range is set here.
1116  // The range of cfl_searh_range should be [1, 33], and the following are the
1117  // recommended values.
1118  // 1: Fastest mode.
1119  // 3: Default mode that provides good speedup without losing compression
1120  // performance at speed 0.
1121  // 33: Exhaustive rd search (33 == CFL_MAGS_SIZE). This mode should only
1122  // be used for debugging purpose.
1123  int cfl_search_range;
1124 
1125  // TOP_INTRA_MODEL_COUNT is 4 that is the number of top model rd to store in
1126  // intra mode decision. Here, add a speed feature to reduce this number for
1127  // higher speeds.
1128  int top_intra_model_count_allowed;
1129 
1130  // Adapt top_intra_model_count_allowed locally to prune luma intra modes using
1131  // neighbor block and quantizer information.
1132  int adapt_top_model_rd_count_using_neighbors;
1133 
1134  // Terminate early in chroma palette_size search.
1135  // 0: No early termination
1136  // 1: Terminate early for higher palette_size, if header rd cost of lower
1137  // palette_size is more than best_rd.
1138  // For allintra encode, this sf reduces instruction count by 0.45%,
1139  // 0.62%, 1.73%, 2.50%, 2.89%, 3.09% and 3.86% for speed 0 to 6 on screen
1140  // content set with coding performance change less than 0.01%.
1141  // For AVIF image encode, this sf reduces instruction count by 0.45%, 0.81%,
1142  // 0.85%, 1.05%, 1.45%, 1.66% and 1.95% for speed 0 to 6 on a typical image
1143  // dataset with no quality drop.
1144  int early_term_chroma_palette_size_search;
1145 
1146  // Skips the evaluation of filter intra modes in inter frames if rd evaluation
1147  // of luma intra dc mode results in invalid rd stats.
1148  int skip_filter_intra_in_inter_frames;
1149 } INTRA_MODE_SPEED_FEATURES;
1150 
1151 typedef struct TX_SPEED_FEATURES {
1152  // Init search depth for square and rectangular transform partitions.
1153  // Values:
1154  // 0 - search full tree, 1: search 1 level, 2: search the highest level only
1155  int inter_tx_size_search_init_depth_sqr;
1156  int inter_tx_size_search_init_depth_rect;
1157  int intra_tx_size_search_init_depth_sqr;
1158  int intra_tx_size_search_init_depth_rect;
1159 
1160  // If any dimension of a coding block size above 64, always search the
1161  // largest transform only, since the largest transform block size is 64x64.
1162  int tx_size_search_lgr_block;
1163 
1164  TX_TYPE_SEARCH tx_type_search;
1165 
1166  // Skip split transform block partition when the collocated bigger block
1167  // is selected as all zero coefficients.
1168  int txb_split_cap;
1169 
1170  // Shortcut the transform block partition and type search when the target
1171  // rdcost is relatively lower.
1172  // Values are 0 (not used) , or 1 - 2 with progressively increasing
1173  // aggressiveness
1174  int adaptive_txb_search_level;
1175 
1176  // Prune level for tx_size_type search for inter based on rd model
1177  // 0: no pruning
1178  // 1-2: progressively increasing aggressiveness of pruning
1179  int model_based_prune_tx_search_level;
1180 
1181  // Refine TX type after fast TX search.
1182  int refine_fast_tx_search_results;
1183 
1184  // Prune transform split/no_split eval based on residual properties. A value
1185  // of 0 indicates no pruning, and the aggressiveness of pruning progressively
1186  // increases from levels 1 to 3.
1187  int prune_tx_size_level;
1188 } TX_SPEED_FEATURES;
1189 
1190 typedef struct RD_CALC_SPEED_FEATURES {
1191  // Fast approximation of av1_model_rd_from_var_lapndz
1192  int simple_model_rd_from_var;
1193 
1194  // Whether to compute distortion in the image domain (slower but
1195  // more accurate), or in the transform domain (faster but less acurate).
1196  // 0: use image domain
1197  // 1: use transform domain in tx_type search, and use image domain for
1198  // RD_STATS
1199  // 2: use transform domain
1200  int tx_domain_dist_level;
1201 
1202  // Transform domain distortion threshold level
1203  int tx_domain_dist_thres_level;
1204 
1205  // Trellis (dynamic programming) optimization of quantized values
1206  TRELLIS_OPT_TYPE optimize_coefficients;
1207 
1208  // Use hash table to store macroblock RD search results
1209  // to avoid repeated search on the same residue signal.
1210  int use_mb_rd_hash;
1211 
1212  // Flag used to control the extent of coeff R-D optimization
1213  int perform_coeff_opt;
1214 } RD_CALC_SPEED_FEATURES;
1215 
1216 typedef struct WINNER_MODE_SPEED_FEATURES {
1217  // Flag used to control the winner mode processing for better R-D optimization
1218  // of quantized coeffs
1219  int enable_winner_mode_for_coeff_opt;
1220 
1221  // Flag used to control the winner mode processing for transform size
1222  // search method
1223  int enable_winner_mode_for_tx_size_srch;
1224 
1225  // Control transform size search level
1226  // Eval type: Default Mode Winner
1227  // Level 0 : FULL RD LARGEST ALL FULL RD
1228  // Level 1 : FAST RD LARGEST ALL FULL RD
1229  // Level 2 : LARGEST ALL LARGEST ALL FULL RD
1230  // Level 3 : LARGEST ALL LARGEST ALL LARGEST ALL
1231  int tx_size_search_level;
1232 
1233  // Flag used to control the winner mode processing for use transform
1234  // domain distortion
1235  int enable_winner_mode_for_use_tx_domain_dist;
1236 
1237  // Flag used to enable processing of multiple winner modes
1238  MULTI_WINNER_MODE_TYPE multi_winner_mode_type;
1239 
1240  // Motion mode for winner candidates:
1241  // 0: speed feature OFF
1242  // 1 / 2 : Use configured number of winner candidates
1243  int motion_mode_for_winner_cand;
1244 
1245  // Early DC only txfm block prediction
1246  // 0: speed feature OFF
1247  // 1 / 2 : Use the configured level for different modes
1248  int dc_blk_pred_level;
1249 
1250  // If on, disables interpolation filter search in handle_inter_mode loop, and
1251  // performs it during winner mode processing by \ref
1252  // tx_search_best_inter_candidates.
1253  int winner_mode_ifs;
1254 
1255  // Controls the disabling of winner mode processing. Speed feature levels
1256  // are ordered in increasing aggressiveness of pruning. The method considered
1257  // for disabling, depends on the sf level value and it is described as below.
1258  // 0: Do not disable
1259  // 1: Disable for blocks with low source variance.
1260  // 2: Disable for blocks which turn out to be transform skip (skipped based on
1261  // eob) during MODE_EVAL stage except NEWMV mode.
1262  // 3: Disable for blocks which turn out to be transform skip during MODE_EVAL
1263  // stage except NEWMV mode. For high quantizers, prune conservatively based on
1264  // transform skip (skipped based on eob) except for NEWMV mode.
1265  // 4: Disable for blocks which turn out to be transform skip during MODE_EVAL
1266  // stage.
1267  int prune_winner_mode_eval_level;
1268 } WINNER_MODE_SPEED_FEATURES;
1269 
1270 typedef struct LOOP_FILTER_SPEED_FEATURES {
1271  // This feature controls how the loop filter level is determined.
1272  LPF_PICK_METHOD lpf_pick;
1273 
1274  // Skip some final iterations in the determination of the best loop filter
1275  // level.
1276  int use_coarse_filter_level_search;
1277 
1278  // Control how the CDEF strength is determined.
1279  CDEF_PICK_METHOD cdef_pick_method;
1280 
1281  // Decoder side speed feature to add penalty for use of dual-sgr filters.
1282  // Takes values 0 - 10, 0 indicating no penalty and each additional level
1283  // adding a penalty of 1%
1284  int dual_sgr_penalty_level;
1285 
1286  // prune sgr ep using binary search like mechanism
1287  int enable_sgr_ep_pruning;
1288 
1289  // Disable loop restoration for Chroma plane
1290  int disable_loop_restoration_chroma;
1291 
1292  // Disable loop restoration for luma plane
1293  int disable_loop_restoration_luma;
1294 
1295  // Prune RESTORE_WIENER evaluation based on source variance
1296  // 0 : no pruning
1297  // 1 : conservative pruning
1298  // 2 : aggressive pruning
1299  int prune_wiener_based_on_src_var;
1300 
1301  // Prune self-guided loop restoration based on wiener search results
1302  // 0 : no pruning
1303  // 1 : pruning based on rdcost ratio of RESTORE_WIENER and RESTORE_NONE
1304  // 2 : pruning based on winner restoration type among RESTORE_WIENER and
1305  // RESTORE_NONE
1306  int prune_sgr_based_on_wiener;
1307 
1308  // Reduce the wiener filter win size for luma
1309  int reduce_wiener_window_size;
1310 
1311  // Disable loop restoration filter
1312  int disable_lr_filter;
1313 
1314  // Whether to downsample the rows in computation of wiener stats.
1315  int use_downsampled_wiener_stats;
1316 } LOOP_FILTER_SPEED_FEATURES;
1317 
1318 typedef struct REAL_TIME_SPEED_FEATURES {
1319  // check intra prediction for non-RD mode.
1320  int check_intra_pred_nonrd;
1321 
1322  // Skip checking intra prediction.
1323  // 0 - don't skip
1324  // 1 - skip if TX is skipped and best mode is not NEWMV
1325  // 2 - skip if TX is skipped
1326  // Skipping aggressiveness increases from level 1 to 2.
1327  int skip_intra_pred;
1328 
1329  // Perform coarse ME before calculating variance in variance-based partition
1330  int estimate_motion_for_var_based_partition;
1331 
1332  // For nonrd_use_partition: mode of extra check of leaf partition
1333  // 0 - don't check merge
1334  // 1 - always check merge
1335  // 2 - check merge and prune checking final split
1336  // 3 - check merge and prune checking final split based on bsize and qindex
1337  int nonrd_check_partition_merge_mode;
1338 
1339  // For nonrd_use_partition: check of leaf partition extra split
1340  int nonrd_check_partition_split;
1341 
1342  // Implements various heuristics to skip searching modes
1343  // The heuristics selected are based on flags
1344  // defined in the MODE_SEARCH_SKIP_HEURISTICS enum
1345  unsigned int mode_search_skip_flags;
1346 
1347  // For nonrd: Reduces ref frame search.
1348  // 0 - low level of search prune in non last frames
1349  // 1 - pruned search in non last frames
1350  // 2 - more pruned search in non last frames
1351  int nonrd_prune_ref_frame_search;
1352 
1353  // This flag controls the use of non-RD mode decision.
1354  int use_nonrd_pick_mode;
1355 
1356  // Use ALTREF frame in non-RD mode decision.
1357  int use_nonrd_altref_frame;
1358 
1359  // Use compound reference for non-RD mode.
1360  int use_comp_ref_nonrd;
1361 
1362  // Reference frames for compound prediction for nonrd pickmode:
1363  // LAST_GOLDEN (0), LAST_LAST2 (1), or LAST_ALTREF (2).
1364  int ref_frame_comp_nonrd[3];
1365 
1366  // use reduced ref set for real-time mode
1367  int use_real_time_ref_set;
1368 
1369  // Skip a number of expensive mode evaluations for blocks with very low
1370  // temporal variance.
1371  int short_circuit_low_temp_var;
1372 
1373  // Use modeled (currently CurvFit model) RDCost for fast non-RD mode
1374  int use_modeled_non_rd_cost;
1375 
1376  // Reuse inter prediction in fast non-rd mode.
1377  int reuse_inter_pred_nonrd;
1378 
1379  // Number of best inter modes to search transform. INT_MAX - search all.
1380  int num_inter_modes_for_tx_search;
1381 
1382  // Use interpolation filter search in non-RD mode decision.
1383  int use_nonrd_filter_search;
1384 
1385  // Use simplified RD model for interpolation search and Intra
1386  int use_simple_rd_model;
1387 
1388  // If set forces interpolation filter to EIGHTTAP_REGULAR
1389  int skip_interp_filter_search;
1390 
1391  // For nonrd mode: use hybrid intra mode search for intra only frames based on
1392  // block properties.
1393  // 0 : use nonrd pick intra for all blocks
1394  // 1 : use rd for bsize < 16x16, nonrd otherwise
1395  // 2 : use rd for bsize < 16x16 and src var >= 101, nonrd otherwise
1396  int hybrid_intra_pickmode;
1397 
1398  // Compute variance/sse on source difference, prior to encoding superblock.
1399  int source_metrics_sb_nonrd;
1400 
1401  // Flag to indicate process for handling overshoot on slide/scene change,
1402  // for real-time CBR mode.
1403  OVERSHOOT_DETECTION_CBR overshoot_detection_cbr;
1404 
1405  // Check for scene/content change detection on every frame before encoding.
1406  int check_scene_detection;
1407 
1408  // Forces larger partition blocks in variance based partitioning
1409  int force_large_partition_blocks;
1410 
1411  // uses results of temporal noise estimate
1412  int use_temporal_noise_estimate;
1413 
1414  // Parameter indicating initial search window to be used in full-pixel search
1415  // for nonrd_pickmode. Range [0, MAX_MVSEARCH_STEPS - 1]. Lower value
1416  // indicates larger window. If set to 0, step_param is set based on internal
1417  // logic in set_mv_search_params().
1418  int fullpel_search_step_param;
1419 
1420  // Bit mask to enable or disable intra modes for each prediction block size
1421  // separately, for nonrd pickmode.
1422  int intra_y_mode_bsize_mask_nrd[BLOCK_SIZES];
1423 
1424  // Skips mode checks more agressively in nonRD mode
1425  int nonrd_agressive_skip;
1426 
1427  // Skip cdef on 64x64 blocks when NEWMV or INTRA is not picked or color
1428  // sensitivity is off. When color sensitivity is on for a superblock, all
1429  // 64x64 blocks within will not skip.
1430  int skip_cdef_sb;
1431 
1432  // Forces larger partition blocks in variance based partitioning for intra
1433  // frames
1434  int force_large_partition_blocks_intra;
1435 
1436  // Skip evaluation of no split in tx size selection for merge partition
1437  int skip_tx_no_split_var_based_partition;
1438 
1439  // Intermediate termination of newMV mode evaluation based on so far best mode
1440  // sse
1441  int skip_newmv_mode_based_on_sse;
1442 
1443  // Define gf length multiplier.
1444  // Level 0: use large multiplier, level 1: use medium multiplier.
1445  int gf_length_lvl;
1446 
1447  // Prune inter modes with golden frame as reference for NEARMV and NEWMV modes
1448  int prune_inter_modes_with_golden_ref;
1449 
1450  // Prune inter modes w.r.t golden or alt-ref frame based on sad
1451  int prune_inter_modes_wrt_gf_arf_based_on_sad;
1452 
1453  // Prune inter mode search in rd path based on current block's temporal
1454  // variance wrt LAST reference.
1455  int prune_inter_modes_using_temp_var;
1456 
1457  // Force half_pel at block level.
1458  int force_half_pel_block;
1459 
1460  // Prune intra mode evaluation in inter frames based on mv range.
1461  BLOCK_SIZE prune_intra_mode_based_on_mv_range;
1462  // The number of times to left shift the splitting thresholds in variance
1463  // based partitioning. The minimum values should be 7 to avoid left shifting
1464  // by a negative number.
1465  int var_part_split_threshold_shift;
1466 
1467  // Qindex based variance partition threshold index, which determines
1468  // the aggressiveness of partition pruning
1469  // 0: disabled for speeds 9,10
1470  // 1,2: (rd-path) lowers qindex thresholds conditionally (for low SAD sb)
1471  // 3,4: (non-rd path) uses pre-tuned qindex thresholds
1472  int var_part_based_on_qidx;
1473 
1474  // Enable GF refresh based on Q value.
1475  int gf_refresh_based_on_qp;
1476 
1477  // Temporal filtering
1478  int use_rtc_tf;
1479 
1480  // Prune the use of the identity transform in nonrd_pickmode,
1481  // used for screen content mode: only for smaller blocks
1482  // and higher spatial variance, and when skip_txfm is not
1483  // already set.
1484  int prune_idtx_nonrd;
1485 
1486  // Skip loopfilter, for static content after slide change
1487  // or key frame, once quality has ramped up.
1488  int skip_lf_screen;
1489 
1490  // For nonrd: early exit out of variance partition that sets the
1491  // block size to superblock size, and sets mode to zeromv-last skip.
1492  int part_early_exit_zeromv;
1493 
1494  // Early terminate inter mode search based on sse in non-rd path.
1495  INTER_SEARCH_EARLY_TERM_IDX sse_early_term_inter_search;
1496 
1497  // SAD based adaptive altref selection
1498  int sad_based_adp_altref_lag;
1499 
1500  // Enable/disable partition direct merging.
1501  int partition_direct_merging;
1502 
1503  // SAD based compound mode pruning
1504  int sad_based_comp_prune;
1505 
1506  // Level of aggressiveness for obtaining tx size based on qstep
1507  int tx_size_level_based_on_qstep;
1508 
1509  // Reduce the mv resolution for zero mv if the variance is low.
1510  bool reduce_zeromv_mvres;
1511 
1512  // Avoid the partitioning of a 16x16 block in variance based partitioning
1513  // (VBP) by making use of minimum and maximum sub-block variances.
1514  // For allintra encode, this speed feature reduces instruction count by 5.39%
1515  // for speed 9 on a typical video dataset with coding performance gain
1516  // of 1.44%.
1517  // For AVIF image encode, this speed feature reduces encode time
1518  // by 8.44% for speed 9 on a typical image dataset with coding performance
1519  // gain of 0.78%.
1520  bool vbp_prune_16x16_split_using_min_max_sub_blk_var;
1521 } REAL_TIME_SPEED_FEATURES;
1522 
1528 typedef struct SPEED_FEATURES {
1533 
1538 
1542  TPL_SPEED_FEATURES tpl_sf;
1543 
1547  GLOBAL_MOTION_SPEED_FEATURES gm_sf;
1548 
1552  PARTITION_SPEED_FEATURES part_sf;
1553 
1557  MV_SPEED_FEATURES mv_sf;
1558 
1562  INTER_MODE_SPEED_FEATURES inter_sf;
1563 
1567  INTERP_FILTER_SPEED_FEATURES interp_sf;
1568 
1572  INTRA_MODE_SPEED_FEATURES intra_sf;
1573 
1577  TX_SPEED_FEATURES tx_sf;
1578 
1582  RD_CALC_SPEED_FEATURES rd_sf;
1583 
1587  WINNER_MODE_SPEED_FEATURES winner_mode_sf;
1588 
1592  LOOP_FILTER_SPEED_FEATURES lpf_sf;
1593 
1597  REAL_TIME_SPEED_FEATURES rt_sf;
1601 struct AV1_COMP;
1602 
1616  int speed);
1617 
1630  int speed);
1643 
1644 #ifdef __cplusplus
1645 } // extern "C"
1646 #endif
1647 
1648 #endif // AOM_AV1_ENCODER_SPEED_FEATURES_H_
static int prune_zero_mv_with_sse(const aom_variance_fn_ptr_t *fn_ptr, const MACROBLOCK *x, BLOCK_SIZE bsize, const HandleInterModeArgs *args, int prune_zero_mv_with_sse)
Prunes ZeroMV Search Using Best NEWMV's SSE.
Definition: rdopt.c:2476
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.
INTERNAL_COST_UPDATE_TYPE
This enum decides internally how often to update the entropy costs.
Definition: speed_features.h:325
@ INTERNAL_COST_UPD_OFF
Definition: speed_features.h:326
@ INTERNAL_COST_UPD_SBROW_SET
Definition: speed_features.h:328
@ INTERNAL_COST_UPD_SBROW
Definition: speed_features.h:329
@ INTERNAL_COST_UPD_SB
Definition: speed_features.h:330
@ INTERNAL_COST_UPD_TILE
Definition: speed_features.h:327
INTER_SEARCH_EARLY_TERM_IDX
This enumeration defines inter search early termination index in non-rd path based on sse value.
Definition: speed_features.h:369
@ EARLY_TERM_INDICES
Definition: speed_features.h:380
@ EARLY_TERM_IDX_1
Definition: speed_features.h:372
@ EARLY_TERM_IDX_4
Definition: speed_features.h:378
@ EARLY_TERM_IDX_2
Definition: speed_features.h:374
@ EARLY_TERM_DISABLED
Definition: speed_features.h:370
@ EARLY_TERM_IDX_3
Definition: speed_features.h:376
SIMPLE_MOTION_SEARCH_PRUNE_LEVEL
This enumeration defines a variety of simple motion search based partition prune levels.
Definition: speed_features.h:337
@ QIDX_BASED_AGG_LVL1
Definition: speed_features.h:343
@ SIMPLE_AGG_LVL3
Definition: speed_features.h:342
@ TOTAL_SIMPLE_AGG_LVLS
Definition: speed_features.h:346
@ SIMPLE_AGG_LVL1
Definition: speed_features.h:340
@ SIMPLE_AGG_LVL0
Definition: speed_features.h:339
@ TOTAL_AGG_LVLS
Definition: speed_features.h:352
@ SIMPLE_AGG_LVL2
Definition: speed_features.h:341
@ TOTAL_QINDEX_BASED_AGG_LVLS
Definition: speed_features.h:348
struct SPEED_FEATURES SPEED_FEATURES
Top level speed vs quality trade off data struture.
PRUNE_MESH_SEARCH_LEVEL
This enumeration defines a variety of mesh search prune levels.
Definition: speed_features.h:359
@ PRUNE_MESH_SEARCH_LVL_1
Definition: speed_features.h:361
@ PRUNE_MESH_SEARCH_LVL_2
Definition: speed_features.h:362
@ PRUNE_MESH_SEARCH_DISABLED
Definition: speed_features.h:360
struct HIGH_LEVEL_SPEED_FEATURES HIGH_LEVEL_SPEED_FEATURES
Sequence/frame level speed vs quality features.
struct FIRST_PASS_SPEED_FEATURES FIRST_PASS_SPEED_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_LVL5
Definition: speed_features.h:163
@ 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:164
@ 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:2664
int speed
Definition: encoder.h:2876
Definition: speed_features.h:443
int disable_recon
Skips reconstruction by using source buffers for prediction.
Definition: speed_features.h:460
int reduce_mv_step_param
Reduces the mv search window. By default, the initial search window is around MIN(MIN(dims),...
Definition: speed_features.h:450
int skip_zeromv_motion_search
Skips the motion search centered on 0,0 mv.
Definition: speed_features.h:465
int skip_motion_search_threshold
Skips the motion search when the zero mv has small sse.
Definition: speed_features.h:455
Sequence/frame level speed vs quality features.
Definition: speed_features.h:386
int second_alt_ref_filtering
Definition: speed_features.h:431
int frame_parameter_update
Definition: speed_features.h:388
MV_PREC_LOGIC high_precision_mv_usage
Definition: speed_features.h:407
int disable_extra_sc_testing
Definition: speed_features.h:426
int recode_tolerance
Definition: speed_features.h:399
SUPERRES_AUTO_SEARCH_TYPE superres_auto_search_type
Definition: speed_features.h:421
int static_segmentation
Definition: speed_features.h:416
int num_frames_used_in_tf
Definition: speed_features.h:437
RECODE_LOOP_TYPE recode_loop
Definition: speed_features.h:393
Top level speed vs quality trade off data struture.
Definition: speed_features.h:1528
MV_SPEED_FEATURES mv_sf
Definition: speed_features.h:1557
TPL_SPEED_FEATURES tpl_sf
Definition: speed_features.h:1542
LOOP_FILTER_SPEED_FEATURES lpf_sf
Definition: speed_features.h:1592
TX_SPEED_FEATURES tx_sf
Definition: speed_features.h:1577
INTER_MODE_SPEED_FEATURES inter_sf
Definition: speed_features.h:1562
RD_CALC_SPEED_FEATURES rd_sf
Definition: speed_features.h:1582
PARTITION_SPEED_FEATURES part_sf
Definition: speed_features.h:1552
GLOBAL_MOTION_SPEED_FEATURES gm_sf
Definition: speed_features.h:1547
INTERP_FILTER_SPEED_FEATURES interp_sf
Definition: speed_features.h:1567
FIRST_PASS_SPEED_FEATURES fp_sf
Definition: speed_features.h:1537
INTRA_MODE_SPEED_FEATURES intra_sf
Definition: speed_features.h:1572
WINNER_MODE_SPEED_FEATURES winner_mode_sf
Definition: speed_features.h:1587
REAL_TIME_SPEED_FEATURES rt_sf
Definition: speed_features.h:1597
HIGH_LEVEL_SPEED_FEATURES hl_sf
Definition: speed_features.h:1532