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