• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #define MAX_MESH_STEP 4
22 
23 typedef struct MESH_PATTERN {
24   int range;
25   int interval;
26 } MESH_PATTERN;
27 
28 enum {
29   GM_FULL_SEARCH,
30   GM_REDUCED_REF_SEARCH_SKIP_L2_L3,
31   GM_REDUCED_REF_SEARCH_SKIP_L2_L3_ARF2,
32   GM_DISABLE_SEARCH
33 } UENUM1BYTE(GM_SEARCH_TYPE);
34 
35 enum {
36   GM_ERRORADV_TR_0,
37   GM_ERRORADV_TR_1,
38   GM_ERRORADV_TR_2,
39   GM_ERRORADV_TR_TYPES,
40 } UENUM1BYTE(GM_ERRORADV_TYPE);
41 
42 enum {
43   FULL_TXFM_RD,
44   LOW_TXFM_RD,
45 } UENUM1BYTE(TXFM_RD_MODEL);
46 
47 enum {
48   DIST_WTD_COMP_ENABLED,
49   DIST_WTD_COMP_SKIP_MV_SEARCH,
50   DIST_WTD_COMP_DISABLED,
51 } UENUM1BYTE(DIST_WTD_COMP_FLAG);
52 
53 enum {
54   INTRA_ALL = (1 << DC_PRED) | (1 << V_PRED) | (1 << H_PRED) | (1 << D45_PRED) |
55               (1 << D135_PRED) | (1 << D113_PRED) | (1 << D157_PRED) |
56               (1 << D203_PRED) | (1 << D67_PRED) | (1 << SMOOTH_PRED) |
57               (1 << SMOOTH_V_PRED) | (1 << SMOOTH_H_PRED) | (1 << PAETH_PRED),
58   UV_INTRA_ALL =
59       (1 << UV_DC_PRED) | (1 << UV_V_PRED) | (1 << UV_H_PRED) |
60       (1 << UV_D45_PRED) | (1 << UV_D135_PRED) | (1 << UV_D113_PRED) |
61       (1 << UV_D157_PRED) | (1 << UV_D203_PRED) | (1 << UV_D67_PRED) |
62       (1 << UV_SMOOTH_PRED) | (1 << UV_SMOOTH_V_PRED) |
63       (1 << UV_SMOOTH_H_PRED) | (1 << UV_PAETH_PRED) | (1 << UV_CFL_PRED),
64   UV_INTRA_DC = (1 << UV_DC_PRED),
65   UV_INTRA_DC_CFL = (1 << UV_DC_PRED) | (1 << UV_CFL_PRED),
66   UV_INTRA_DC_TM = (1 << UV_DC_PRED) | (1 << UV_PAETH_PRED),
67   UV_INTRA_DC_PAETH_CFL =
68       (1 << UV_DC_PRED) | (1 << UV_PAETH_PRED) | (1 << UV_CFL_PRED),
69   UV_INTRA_DC_H_V = (1 << UV_DC_PRED) | (1 << UV_V_PRED) | (1 << UV_H_PRED),
70   UV_INTRA_DC_H_V_CFL = (1 << UV_DC_PRED) | (1 << UV_V_PRED) |
71                         (1 << UV_H_PRED) | (1 << UV_CFL_PRED),
72   UV_INTRA_DC_PAETH_H_V = (1 << UV_DC_PRED) | (1 << UV_PAETH_PRED) |
73                           (1 << UV_V_PRED) | (1 << UV_H_PRED),
74   UV_INTRA_DC_PAETH_H_V_CFL = (1 << UV_DC_PRED) | (1 << UV_PAETH_PRED) |
75                               (1 << UV_V_PRED) | (1 << UV_H_PRED) |
76                               (1 << UV_CFL_PRED),
77   INTRA_DC = (1 << DC_PRED),
78   INTRA_DC_TM = (1 << DC_PRED) | (1 << PAETH_PRED),
79   INTRA_DC_H_V = (1 << DC_PRED) | (1 << V_PRED) | (1 << H_PRED),
80   INTRA_DC_PAETH_H_V =
81       (1 << DC_PRED) | (1 << PAETH_PRED) | (1 << V_PRED) | (1 << H_PRED)
82 };
83 
84 enum {
85   INTER_ALL = (1 << NEARESTMV) | (1 << NEARMV) | (1 << GLOBALMV) |
86               (1 << NEWMV) | (1 << NEAREST_NEARESTMV) | (1 << NEAR_NEARMV) |
87               (1 << NEW_NEWMV) | (1 << NEAREST_NEWMV) | (1 << NEAR_NEWMV) |
88               (1 << NEW_NEARMV) | (1 << NEW_NEARESTMV) | (1 << GLOBAL_GLOBALMV),
89   INTER_NEAREST_NEAR_ZERO = (1 << NEARESTMV) | (1 << NEARMV) | (1 << GLOBALMV) |
90                             (1 << NEAREST_NEARESTMV) | (1 << GLOBAL_GLOBALMV) |
91                             (1 << NEAREST_NEWMV) | (1 << NEW_NEARESTMV) |
92                             (1 << NEW_NEARMV) | (1 << NEAR_NEWMV) |
93                             (1 << NEAR_NEARMV),
94 };
95 
96 enum {
97   DISABLE_ALL_INTER_SPLIT = (1 << THR_COMP_GA) | (1 << THR_COMP_LA) |
98                             (1 << THR_ALTR) | (1 << THR_GOLD) | (1 << THR_LAST),
99 
100   DISABLE_ALL_SPLIT = (1 << THR_INTRA) | DISABLE_ALL_INTER_SPLIT,
101 
102   DISABLE_COMPOUND_SPLIT = (1 << THR_COMP_GA) | (1 << THR_COMP_LA),
103 
104   LAST_AND_INTRA_SPLIT_ONLY = (1 << THR_COMP_GA) | (1 << THR_COMP_LA) |
105                               (1 << THR_ALTR) | (1 << THR_GOLD)
106 };
107 
108 enum {
109   TXFM_CODING_SF = 1,
110   INTER_PRED_SF = 2,
111   INTRA_PRED_SF = 4,
112   PARTITION_SF = 8,
113   LOOP_FILTER_SF = 16,
114   RD_SKIP_SF = 32,
115   RESERVE_2_SF = 64,
116   RESERVE_3_SF = 128,
117 } UENUM1BYTE(DEV_SPEED_FEATURES);
118 
119 enum {
120   // No recode.
121   DISALLOW_RECODE = 0,
122   // Allow recode for KF and exceeding maximum frame bandwidth.
123   ALLOW_RECODE_KFMAXBW = 1,
124   // Allow recode only for KF/ARF/GF frames.
125   ALLOW_RECODE_KFARFGF = 2,
126   // Allow recode for all frames based on bitrate constraints.
127   ALLOW_RECODE = 3,
128 } UENUM1BYTE(RECODE_LOOP_TYPE);
129 
130 enum {
131   SUBPEL_TREE = 0,
132   SUBPEL_TREE_PRUNED = 1,           // Prunes 1/2-pel searches
133   SUBPEL_TREE_PRUNED_MORE = 2,      // Prunes 1/2-pel searches more aggressively
134   SUBPEL_TREE_PRUNED_EVENMORE = 3,  // Prunes 1/2- and 1/4-pel searches
135   // Other methods to come
136 } UENUM1BYTE(SUBPEL_SEARCH_METHODS);
137 
138 enum {
139   USE_FULL_RD = 0,
140   USE_FAST_RD,
141   USE_LARGESTALL,
142 } UENUM1BYTE(TX_SIZE_SEARCH_METHOD);
143 
144 enum {
145   // Try the full image with different values.
146   LPF_PICK_FROM_FULL_IMAGE,
147   // Try the full image filter search with non-dual filter only.
148   LPF_PICK_FROM_FULL_IMAGE_NON_DUAL,
149   // Try a small portion of the image with different values.
150   LPF_PICK_FROM_SUBIMAGE,
151   // Estimate the level based on quantizer and frame type
152   LPF_PICK_FROM_Q,
153   // Pick 0 to disable LPF if LPF was enabled last frame
154   LPF_PICK_MINIMAL_LPF
155 } UENUM1BYTE(LPF_PICK_METHOD);
156 
157 enum {
158   CDEF_FULL_SEARCH,
159   CDEF_FAST_SEARCH_LVL1,  // Search among a subset of all possible filters.
160   CDEF_FAST_SEARCH_LVL2,  // Search reduced subset of filters than Level 1.
161   CDEF_PICK_FROM_Q,       // Estimate filter strength based on quantizer.
162   CDEF_PICK_METHODS
163 } UENUM1BYTE(CDEF_PICK_METHOD);
164 
165 enum {
166   // Terminate search early based on distortion so far compared to
167   // qp step, distortion in the neighborhood of the frame, etc.
168   FLAG_EARLY_TERMINATE = 1 << 0,
169 
170   // Skips comp inter modes if the best so far is an intra mode.
171   FLAG_SKIP_COMP_BESTINTRA = 1 << 1,
172 
173   // Skips oblique intra modes if the best so far is an inter mode.
174   FLAG_SKIP_INTRA_BESTINTER = 1 << 3,
175 
176   // Skips oblique intra modes  at angles 27, 63, 117, 153 if the best
177   // intra so far is not one of the neighboring directions.
178   FLAG_SKIP_INTRA_DIRMISMATCH = 1 << 4,
179 
180   // Skips intra modes other than DC_PRED if the source variance is small
181   FLAG_SKIP_INTRA_LOWVAR = 1 << 5,
182 } UENUM1BYTE(MODE_SEARCH_SKIP_LOGIC);
183 
184 enum {
185   NO_PRUNE = 0,
186   // adaptively prunes the least perspective tx types out of all 16
187   // (tuned to provide negligible quality loss)
188   PRUNE_2D_ACCURATE = 1,
189   // similar, but applies much more aggressive pruning to get better speed-up
190   PRUNE_2D_FAST = 2,
191   PRUNE_2D_MORE = 3,
192   // More aggressive pruning based on tx type score and allowed tx count
193   PRUNE_2D_AGGRESSIVE = 4,
194 } UENUM1BYTE(TX_TYPE_PRUNE_MODE);
195 
196 typedef struct {
197   TX_TYPE_PRUNE_MODE prune_mode;
198   int fast_intra_tx_type_search;
199   int fast_inter_tx_type_search;
200 
201   // prune two least frequently chosen transforms for each intra mode
202   int use_reduced_intra_txset;
203 
204   // Use a skip flag prediction model to detect blocks with skip = 1 early
205   // and avoid doing full TX type search for such blocks.
206   int use_skip_flag_prediction;
207 
208   // Threshold used by the ML based method to predict TX block split decisions.
209   int ml_tx_split_thresh;
210 
211   // skip remaining transform type search when we found the rdcost of skip is
212   // better than applying transform
213   int skip_tx_search;
214 
215   // Prune tx type search using previous frame stats.
216   int prune_tx_type_using_stats;
217   // Prune tx type search using estimated RDcost
218   int prune_tx_type_est_rd;
219 
220   // Flag used to control the winner mode processing for tx type pruning for
221   // inter blocks. It enables further tx type mode pruning based on ML model for
222   // mode evaluation and disables tx type mode pruning for winner mode
223   // processing.
224   int enable_winner_mode_tx_type_pruning;
225 } TX_TYPE_SEARCH;
226 
227 enum {
228   // Search partitions using RD criterion
229   SEARCH_PARTITION,
230 
231   // Always use a fixed size partition
232   FIXED_PARTITION,
233 
234   REFERENCE_PARTITION,
235 
236   VAR_BASED_PARTITION
237 } UENUM1BYTE(PARTITION_SEARCH_TYPE);
238 
239 enum {
240   NOT_IN_USE,
241   DIRECT_PRED,
242   RELAXED_PRED,
243   ADAPT_PRED
244 } UENUM1BYTE(MAX_PART_PRED_MODE);
245 
246 enum {
247   LAST_MV_DATA,
248   CURRENT_Q,
249   QTR_ONLY,
250 } UENUM1BYTE(MV_PREC_LOGIC);
251 
252 typedef struct HIGH_LEVEL_SPEED_FEATURES {
253   // Frame level coding parameter update
254   int frame_parameter_update;
255 
256   RECODE_LOOP_TYPE recode_loop;
257 
258   // This feature controls the tolerence vs target used in deciding whether to
259   // recode a frame. It has no meaning if recode is disabled.
260   int recode_tolerance;
261 
262   // Determine how motion vector precision is chosen. The possibilities are:
263   // LAST_MV_DATA: use the mv data from the last coded frame
264   // CURRENT_Q: use the current q as a threshold
265   // QTR_ONLY: use quarter pel precision only.
266   MV_PREC_LOGIC high_precision_mv_usage;
267 
268   // Whether to disable overlay frames for filtered Altref frames,
269   // overiding oxcf->enable_overlay flag set as 1.
270   int disable_overlay_frames;
271 
272   // Enable/disable adaptively deciding whether or not to encode ALTREF overlay
273   // frame.
274   int adaptive_overlay_encoding;
275 
276   // Always set to 0. If on it enables 0 cost background transmission
277   // (except for the initial transmission of the segmentation). The feature is
278   // disabled because the addition of very large block sizes make the
279   // backgrounds very to cheap to encode, and the segmentation we have
280   // adds overhead.
281   int static_segmentation;
282 
283   // Enable/disable second_alt_ref temporal filtering.
284   int second_alt_ref_filtering;
285 } HIGH_LEVEL_SPEED_FEATURES;
286 
287 typedef struct TPL_SPEED_FEATURES {
288   // Prune the intra modes search by tpl.
289   // If set to 0, we will search all intra modes from DC_PRED to PAETH_PRED.
290   // If set to 1, we only search DC_PRED, V_PRED, and H_PRED.
291   int prune_intra_modes;
292   // This parameter controls which step in the n-step process we start at.
293   int reduce_first_step_size;
294   // Skip motion estimation based on the precision of center MVs and the
295   // difference between center MVs.
296   // If set to 0, motion estimation is skipped for duplicate center MVs
297   // (default). If set to 1, motion estimation is skipped for duplicate
298   // full-pixel center MVs. If set to 2, motion estimation is skipped if the
299   // difference between center MVs is less than the threshold.
300   int skip_alike_starting_mv;
301 
302   // When to stop subpel search.
303   SUBPEL_FORCE_STOP subpel_force_stop;
304 } TPL_SPEED_FEATURES;
305 
306 typedef struct GLOBAL_MOTION_SPEED_FEATURES {
307   // Global motion warp error threshold
308   GM_ERRORADV_TYPE gm_erroradv_type;
309 
310   // Disable adaptive threshold for global motion warp error
311   int disable_adaptive_warp_error_thresh;
312 
313   // Do not compute the global motion parameters for a LAST2_FRAME or
314   // LAST3_FRAME if the GOLDEN_FRAME is closer and it has a non identity
315   // global model.
316   int selective_ref_gm;
317 
318   GM_SEARCH_TYPE gm_search_type;
319 
320   // whether to disable the global motion recode loop
321   int gm_disable_recode;
322 
323   // During global motion estimation, prune remaining reference frames in a
324   // given direction(past/future), if the evaluated ref_frame in that direction
325   // yields gm_type as INVALID/TRANSLATION/IDENTITY
326   int prune_ref_frame_for_gm_search;
327 } GLOBAL_MOTION_SPEED_FEATURES;
328 
329 typedef struct PARTITION_SPEED_FEATURES {
330   PARTITION_SEARCH_TYPE partition_search_type;
331 
332   // Used if partition_search_type = FIXED_SIZE_PARTITION
333   BLOCK_SIZE always_this_block_size;
334 
335   // Prune extended partition types search
336   // Can take values 0 - 2, 0 referring to no pruning, and 1 - 2 increasing
337   // aggressiveness of pruning in order.
338   int prune_ext_partition_types_search_level;
339 
340   // Use a ML model to prune horz and vert partitions
341   int ml_prune_rect_partition;
342 
343   // Use a ML model to prune horz_a, horz_b, vert_a and vert_b partitions.
344   int ml_prune_ab_partition;
345 
346   // Use a ML model to prune horz4 and vert4 partitions.
347   int ml_prune_4_partition;
348 
349   // Use a ML model to adaptively terminate partition search after trying
350   // PARTITION_SPLIT. Can take values 0 - 2, 0 meaning not being enabled, and
351   // 1 - 2 increasing aggressiveness in order.
352   int ml_early_term_after_part_split_level;
353 
354   // Skip rectangular partition test when partition type none gives better
355   // rd than partition type split. Can take values 0 - 2, 0 referring to no
356   // skipping, and 1 - 2 increasing aggressiveness of skipping in order.
357   int less_rectangular_check_level;
358 
359   // Use square partition only beyond this block size.
360   BLOCK_SIZE use_square_partition_only_threshold;
361 
362   // Sets min and max square partition levels for this superblock based on
363   // motion vector and prediction error distribution produced from 16x16
364   // simple motion search
365   MAX_PART_PRED_MODE auto_max_partition_based_on_simple_motion;
366   int auto_min_partition_based_on_simple_motion;
367 
368   // Min and max square partition size we enable (block_size) as per auto
369   // min max, but also used by adjust partitioning, and pick_partitioning.
370   BLOCK_SIZE default_min_partition_size;
371   BLOCK_SIZE default_max_partition_size;
372 
373   // Sets level of adjustmet of variace-based partitioning during
374   // rd_use_partition 0 - no partition adjusment, 1 - try to merge partitions
375   // for small blocks and high QP, 2 - always try to merge leaf partitions, 3 -
376   // try to merge and split leaf partitions
377   int adjust_var_based_rd_partitioning;
378 
379   // Partition search early breakout thresholds.
380   int64_t partition_search_breakout_dist_thr;
381   int partition_search_breakout_rate_thr;
382 
383   // Thresholds for ML based partition search breakout.
384   int ml_partition_search_breakout_thresh[PARTITION_BLOCK_SIZES];
385 
386   // Allow skipping partition search for still image frame
387   int allow_partition_search_skip;
388 
389   // The aggresiveness of pruning with simple_motion_search.
390   // Currently 0 is the lowest, and 2 the highest.
391   int simple_motion_search_prune_agg;
392 
393   // Perform simple_motion_search on each possible subblock and use it to prune
394   // PARTITION_HORZ and PARTITION_VERT.
395   int simple_motion_search_prune_rect;
396 
397   // Perform simple motion search before none_partition to decide if we
398   // want to remove all partitions other than PARTITION_SPLIT. If set to 0, this
399   // model is disabled. If set to 1, the model attempts to perform
400   // PARTITION_SPLIT only. If set to 2, the model also attempts to prune
401   // PARTITION_SPLIT.
402   int simple_motion_search_split;
403 
404   // Use features from simple_motion_search to terminate prediction block
405   // partition after PARTITION_NONE
406   int simple_motion_search_early_term_none;
407 
408   // This variable controls the maximum block size where intra blocks can be
409   // used in inter frames.
410   // TODO(aconverse): Fold this into one of the other many mode skips
411   BLOCK_SIZE max_intra_bsize;
412 
413   // Use CNN with luma pixels on source frame on each of the 64x64 subblock to
414   // perform split/no_split decision on intra-frames.
415   int intra_cnn_split;
416 
417   // Disable extended partition search for lower block sizes.
418   int ext_partition_eval_thresh;
419 
420   // Prune 1:4 partition search based on winner info from split partitions
421   int prune_4_partition_using_split_info;
422 
423   // Prune AB partition search using split and HORZ/VERT info
424   int prune_ab_partition_using_split_info;
425 } PARTITION_SPEED_FEATURES;
426 
427 typedef struct MV_SPEED_FEATURES {
428   // Motion search method (Diamond, NSTEP, Hex, Big Diamond, Square, etc).
429   SEARCH_METHODS search_method;
430 
431   // If this is set to 1, we limit the motion search range to 2 times the
432   // largest motion vector found in the last frame.
433   int auto_mv_step_size;
434 
435   // Subpel_search_method can only be subpel_tree which does a subpixel
436   // logarithmic search that keeps stepping at 1/2 pixel units until
437   // you stop getting a gain, and then goes on to 1/4 and repeats
438   // the same process. Along the way it skips many diagonals.
439   SUBPEL_SEARCH_METHODS subpel_search_method;
440 
441   // Maximum number of steps in logarithmic subpel search before giving up.
442   int subpel_iters_per_step;
443 
444   // When to stop subpel search.
445   SUBPEL_FORCE_STOP subpel_force_stop;
446 
447   // When to stop subpel search in simple motion search.
448   SUBPEL_FORCE_STOP simple_motion_subpel_force_stop;
449 
450   // If true, sub-pixel search uses the exact convolve function used for final
451   // encoding and decoding; otherwise, it uses bilinear interpolation.
452   SUBPEL_SEARCH_TYPE use_accurate_subpel_search;
453 
454   // TODO(jingning): combine the related motion search speed features
455   // This allows us to use motion search at other sizes as a starting
456   // point for this motion search and limits the search range around it.
457   int adaptive_motion_search;
458 
459   // Threshold for allowing exhaustive motion search.
460   int exhaustive_searches_thresh;
461 
462   // Pattern to be used for any exhaustive mesh searches (except intraBC ME).
463   MESH_PATTERN mesh_patterns[MAX_MESH_STEP];
464 
465   // Pattern to be used for exhaustive mesh searches of intraBC ME.
466   MESH_PATTERN intrabc_mesh_patterns[MAX_MESH_STEP];
467 
468   // Reduce single motion search range based on MV result of prior ref_mv_idx.
469   int reduce_search_range;
470 
471   // Prune mesh search.
472   int prune_mesh_search;
473 
474   // Use the rd cost around the best FULLPEL_MV to speed up subpel search
475   int use_fullpel_costlist;
476 
477   // Set the full pixel search level of obmc
478   // 0: obmc_full_pixel_diamond
479   // 1: obmc_refining_search_sad (faster)
480   int obmc_full_pixel_search_level;
481 
482   // Accurate full pixel motion search based on TPL stats.
483   int full_pixel_search_level;
484 } MV_SPEED_FEATURES;
485 
486 typedef struct INTER_MODE_SPEED_FEATURES {
487   // 2-pass inter mode model estimation where the preliminary pass skips
488   // transform search and uses a model to estimate rd, while the final pass
489   // computes the full transform search. Two types of models are supported:
490   // 0: not used
491   // 1: used with online dynamic rd model
492   // 2: used with static rd model
493   int inter_mode_rd_model_estimation;
494 
495   // Bypass transform search based on skip rd
496   int txfm_rd_gate_level;
497 
498   // Limit the inter mode tested in the RD loop
499   int reduce_inter_modes;
500 
501   // Adaptive prediction mode search
502   int adaptive_mode_search;
503 
504   // This variable is used to cap the maximum number of times we skip testing a
505   // mode to be evaluated. A high value means we will be faster.
506   int adaptive_rd_thresh;
507 
508   // Aggressively prune inter modes when best mode is skippable.
509   int prune_inter_modes_if_skippable;
510 
511   // Drop less likely to be picked reference frames in the RD search.
512   // Has five levels for now: 0, 1, 2, 3 and 4, where higher levels prune more
513   // aggressively than lower ones. (0 means no pruning).
514   int selective_ref_frame;
515 
516   // Prune reference frames for rectangular partitions.
517   // 0 implies no pruning
518   // 1 implies prune for extended partition
519   // 2 implies prune horiz, vert and extended partition
520   int prune_ref_frame_for_rect_partitions;
521 
522   int alt_ref_search_fp;
523 
524   // flag to skip NEWMV mode in drl if the motion search result is the same
525   int skip_repeated_newmv;
526 
527   // Skip the current ref_mv in NEW_MV mode if we have already encountered
528   // another ref_mv in the drl such that:
529   //  1. The other drl has the same fullpel_mv during the SIMPLE_TRANSLATION
530   //     search process as the current fullpel_mv.
531   //  2. The rate needed to encode the current fullpel_mv is larger than that
532   //     for the other ref_mv.
533   int skip_repeated_full_newmv;
534 
535   // This speed feature checks duplicate ref MVs among NEARESTMV, NEARMV,
536   // GLOBALMV and skips NEARMV or GLOBALMV (in order) if a duplicate is found
537   // TODO(any): Instead of skipping repeated ref mv, use the recalculated
538   // rd-cost based on mode rate and skip the mode evaluation
539   int skip_repeated_ref_mv;
540 
541   // Flag used to control the ref_best_rd based gating for chroma
542   int perform_best_rd_based_gating_for_chroma;
543 
544   // Skip certain motion modes (OBMC, warped, interintra) for single reference
545   // motion search, using the results of single ref SIMPLE_TRANSLATION
546   int prune_single_motion_modes_by_simple_trans;
547 
548   // Reuse the inter_intra_mode search result from NEARESTMV mode to other
549   // single ref modes
550   int reuse_inter_intra_mode;
551 
552   // prune wedge and compound segment approximate rd evaluation based on
553   // compound average modeled rd
554   int prune_comp_type_by_model_rd;
555 
556   // prune wedge and compound segment approximate rd evaluation based on
557   // compound average rd/ref_best_rd
558   int prune_comp_type_by_comp_avg;
559 
560   // Skip some ref frames in compound motion search by single motion search
561   // result. Has three levels for now: 0 referring to no skipping, and 1 - 3
562   // increasing aggressiveness of skipping in order.
563   // Note: The search order might affect the result. It assumes that the single
564   // reference modes are searched before compound modes. It is better to search
565   // same single inter mode as a group.
566   int prune_comp_search_by_single_result;
567 
568   // If 1 we iterate finding a best reference for 2 ref frames together - via
569   // a log search that iterates 4 times (check around mv for last for best
570   // error of combined predictor then check around mv for alt). If 0 we
571   // we just use the best motion vector found for each frame by itself.
572   BLOCK_SIZE comp_inter_joint_search_thresh;
573 
574   // Instead of performing a full MV search, do a simple translation first
575   // and only perform a full MV search on the motion vectors that performed
576   // well.
577   int prune_mode_search_simple_translation;
578 
579   // Only search compound modes with at least one "good" reference frame.
580   // A reference frame is good if, after looking at its performance among
581   // the single reference modes, it is one of the two best performers.
582   int prune_compound_using_single_ref;
583 
584   // Skip extended compound mode using ref frames of above and left neighbor
585   // blocks.
586   // 0 : no pruning
587   // 1 : prune extended compound mode (less aggressiveness)
588   // 2 : prune extended compound mode (high aggressiveness)
589   int prune_compound_using_neighbors;
590 
591   // Based on previous ref_mv_idx search result, prune the following search.
592   int prune_ref_mv_idx_search;
593 
594   // Disable one sided compound modes.
595   int disable_onesided_comp;
596 
597   // Prune/gate motion mode evaluation based on token based rd
598   // during transform search for inter blocks
599   // Values are 0 (not used) , 1 - 3 with progressively increasing
600   // aggressiveness
601   int prune_motion_mode_level;
602 
603   // Prune obmc search using previous frame stats.
604   int prune_obmc_prob_thresh;
605 
606   // Disable obmc.
607   int disable_obmc;
608 
609   // Gate warp evaluation for motions of type IDENTITY,
610   // TRANSLATION and AFFINE(based on number of warp neighbors)
611   int prune_warp_using_wmtype;
612 
613   // Prune warped motion search using previous frame stats.
614   int prune_warped_prob_thresh;
615 
616   // Enable/disable interintra wedge search.
617   int disable_wedge_interintra_search;
618 
619   // De-couple wedge and mode search during interintra RDO.
620   int fast_interintra_wedge_search;
621 
622   // Only enable wedge search if the edge strength is greater than
623   // this threshold. A value of 0 signals that this check is disabled.
624   unsigned int disable_wedge_search_edge_thresh;
625 
626   // Only enable wedge search if the variance is above this threshold.
627   unsigned int disable_wedge_search_var_thresh;
628 
629   // Whether fast wedge sign estimate is used
630   int fast_wedge_sign_estimate;
631 
632   // Whether to prune wedge search based on predictor difference
633   int prune_wedge_pred_diff_based;
634 
635   // Enable/disable ME for interinter wedge search.
636   int disable_interinter_wedge_newmv_search;
637 
638   // Enable/disable ME for interinter diffwtd search. PSNR BD-rate gain of
639   // ~0.1 on the lowres test set, but ~15% slower computation.
640   int enable_interinter_diffwtd_newmv_search;
641 
642   // Enable/disable smooth inter-intra mode
643   int disable_smooth_interintra;
644 
645   // Disable interinter_wedge
646   int disable_interinter_wedge;
647 
648   // Decide when and how to use joint_comp.
649   DIST_WTD_COMP_FLAG use_dist_wtd_comp_flag;
650 
651   // Whether to override and disable sb level coeff cost updates, if
652   // cpi->oxcf.coeff_cost_upd_freq = COST_UPD_SB (i.e. set at SB level)
653   int disable_sb_level_coeff_cost_upd;
654 
655   // Whether to override and disable sb level mv cost updates, if
656   // cpi->oxcf.coeff_cost_upd_freq = COST_UPD_SB (i.e. set at SB level)
657   int disable_sb_level_mv_cost_upd;
658 
659   // Prune inter modes based on tpl stats
660   // 0 : no pruning
661   // 1 - 3 indicate increasing aggressiveness in order.
662   int prune_inter_modes_based_on_tpl;
663 
664   // Model based breakout after interpolation filter search
665   // 0: no breakout
666   // 1: use model based rd breakout
667   int model_based_post_interp_filter_breakout;
668 
669   // Reuse compound type rd decision when exact match is found
670   // 0: No reuse
671   // 1: Reuse the compound type decision
672   int reuse_compound_type_decision;
673 } INTER_MODE_SPEED_FEATURES;
674 
675 typedef struct INTERP_FILTER_SPEED_FEATURES {
676   // A source variance threshold below which filter search is disabled
677   // Choose a very large value (UINT_MAX) to use 8-tap always
678   unsigned int disable_filter_search_var_thresh;
679 
680   // Do limited interpolation filter search for dual filters, since best choice
681   // usually includes EIGHTTAP_REGULAR.
682   int use_fast_interpolation_filter_search;
683 
684   // Disable dual filter
685   int disable_dual_filter;
686 
687   // Save results of av1_interpolation_filter_search for a block
688   // Check mv and ref_frames before search, if they are very close with previous
689   // saved results, filter search can be skipped.
690   int use_interp_filter;
691 
692   // skip sharp_filter evaluation based on regular and smooth filter rd for
693   // dual_filter=0 case
694   int skip_sharp_interp_filter_search;
695 
696   int cb_pred_filter_search;
697 
698   // adaptive interp_filter search to allow skip of certain filter types.
699   int adaptive_interp_filter_search;
700 } INTERP_FILTER_SPEED_FEATURES;
701 
702 typedef struct INTRA_MODE_SPEED_FEATURES {
703   // These bit masks allow you to enable or disable intra modes for each
704   // transform size separately.
705   int intra_y_mode_mask[TX_SIZES];
706   int intra_uv_mode_mask[TX_SIZES];
707 
708   // flag to allow skipping intra mode for inter frame prediction
709   int skip_intra_in_interframe;
710 
711   // variance threshold for intra mode gating when inter turned out to be skip
712   // in inter frame prediction
713   unsigned int src_var_thresh_intra_skip;
714 
715   // Prune intra mode candidates based on source block histogram of gradient.
716   int intra_pruning_with_hog;
717 
718   // TODO(anyone): tune intra_pruning_with_hog_thresh for various speeds.
719   float intra_pruning_with_hog_thresh;
720 
721   // Enable/disable smooth intra modes.
722   int disable_smooth_intra;
723 
724   // prune palette search
725   // 0: No pruning
726   // 1: Perform coarse search to prune the palette colors. For winner colors,
727   // neighbors are also evaluated using a finer search.
728   // 2: Perform 2 way palette search from max colors to min colors (and min
729   // colors to remaining colors) and terminate the search if current number of
730   // palette colors is not the winner.
731   int prune_palette_search_level;
732 } INTRA_MODE_SPEED_FEATURES;
733 
734 typedef struct TX_SPEED_FEATURES {
735   // Init search depth for square and rectangular transform partitions.
736   // Values:
737   // 0 - search full tree, 1: search 1 level, 2: search the highest level only
738   int inter_tx_size_search_init_depth_sqr;
739   int inter_tx_size_search_init_depth_rect;
740   int intra_tx_size_search_init_depth_sqr;
741   int intra_tx_size_search_init_depth_rect;
742 
743   // If any dimension of a coding block size above 64, always search the
744   // largest transform only, since the largest transform block size is 64x64.
745   int tx_size_search_lgr_block;
746 
747   TX_TYPE_SEARCH tx_type_search;
748 
749   // Skip split transform block partition when the collocated bigger block
750   // is selected as all zero coefficients.
751   int txb_split_cap;
752 
753   // Shortcut the transform block partition and type search when the target
754   // rdcost is relatively lower.
755   // Values are 0 (not used) , or 1 - 2 with progressively increasing
756   // aggressiveness
757   int adaptive_txb_search_level;
758 
759   // Prune level for tx_size_type search for inter based on rd model
760   // 0: no pruning
761   // 1-2: progressively increasing aggressiveness of pruning
762   int model_based_prune_tx_search_level;
763 
764   // Use hash table to store intra(keyframe only) txb transform search results
765   // to avoid repeated search on the same residue signal.
766   int use_intra_txb_hash;
767 
768   // Use hash table to store inter txb transform search results
769   // to avoid repeated search on the same residue signal.
770   int use_inter_txb_hash;
771 
772   // Refine TX type after fast TX search.
773   int refine_fast_tx_search_results;
774 } TX_SPEED_FEATURES;
775 
776 typedef struct RD_CALC_SPEED_FEATURES {
777   // This feature controls whether we do the expensive context update and
778   // calculation in the rd coefficient costing loop.
779   int use_fast_coef_costing;
780 
781   // Fast approximation of av1_model_rd_from_var_lapndz
782   int simple_model_rd_from_var;
783 
784   // Whether to compute distortion in the image domain (slower but
785   // more accurate), or in the transform domain (faster but less acurate).
786   // 0: use image domain
787   // 1: use transform domain in tx_type search, and use image domain for
788   // RD_STATS
789   // 2: use transform domain
790   int tx_domain_dist_level;
791 
792   // Transform domain distortion threshold level
793   int tx_domain_dist_thres_level;
794 
795   // Trellis (dynamic programming) optimization of quantized values
796   TRELLIS_OPT_TYPE optimize_coefficients;
797 
798   // Use a hash table to store previously computed optimized qcoeffs from
799   // expensive calls to optimize_txb.
800   int use_hash_based_trellis;
801 
802   // Use hash table to store macroblock RD search results
803   // to avoid repeated search on the same residue signal.
804   int use_mb_rd_hash;
805 
806   // Flag used to control the speed of the eob selection in trellis.
807   int trellis_eob_fast;
808 
809   // Calculate RD cost before doing optimize_b, and skip if the cost is large.
810   int optimize_b_precheck;
811 
812   // Flag used to control the extent of coeff R-D optimization
813   int perform_coeff_opt;
814 } RD_CALC_SPEED_FEATURES;
815 
816 typedef struct WINNER_MODE_SPEED_FEATURES {
817   // Flag used to control the winner mode processing for better R-D optimization
818   // of quantized coeffs
819   int enable_winner_mode_for_coeff_opt;
820 
821   // Flag used to control the winner mode processing for transform size
822   // search method
823   int enable_winner_mode_for_tx_size_srch;
824 
825   // Control transform size search level
826   // Eval type: Default       Mode        Winner
827   // Level 0  : FULL RD     LARGEST ALL   FULL RD
828   // Level 1  : FAST RD     LARGEST ALL   FULL RD
829   // Level 2  : LARGEST ALL LARGEST ALL   FULL RD
830   int tx_size_search_level;
831 
832   // Flag used to control the winner mode processing for use transform
833   // domain distortion
834   int enable_winner_mode_for_use_tx_domain_dist;
835 
836   // Flag used to enable processing of multiple winner modes
837   int enable_multiwinner_mode_process;
838 
839   // Motion mode for winner candidates:
840   // 0: speed feature OFF
841   // 1 / 2 : Use configured number of winner candidates
842   int motion_mode_for_winner_cand;
843 } WINNER_MODE_SPEED_FEATURES;
844 
845 typedef struct LOOP_FILTER_SPEED_FEATURES {
846   // This feature controls how the loop filter level is determined.
847   LPF_PICK_METHOD lpf_pick;
848 
849   // Control how the CDEF strength is determined.
850   CDEF_PICK_METHOD cdef_pick_method;
851 
852   // Decoder side speed feature to add penalty for use of dual-sgr filters.
853   // Takes values 0 - 10, 0 indicating no penalty and each additional level
854   // adding a penalty of 1%
855   int dual_sgr_penalty_level;
856 
857   // prune sgr ep using binary search like mechanism
858   int enable_sgr_ep_pruning;
859 
860   // Disable loop restoration for Chroma plane
861   int disable_loop_restoration_chroma;
862 
863   // Prune RESTORE_WIENER evaluation based on source variance
864   // 0 : no pruning
865   // 1 : conservative pruning
866   // 2 : aggressive pruning
867   int prune_wiener_based_on_src_var;
868 
869   // Prune self-guided loop restoration based on wiener search results
870   // 0 : no pruning
871   // 1 : pruning based on rdcost ratio of RESTORE_WIENER and RESTORE_NONE
872   // 2 : pruning based on winner restoration type among RESTORE_WIENER and
873   // RESTORE_NONE
874   int prune_sgr_based_on_wiener;
875 
876   // Reduce the wiener filter win size for luma
877   int reduce_wiener_window_size;
878 
879   // Disable loop restoration filter
880   int disable_lr_filter;
881 } LOOP_FILTER_SPEED_FEATURES;
882 
883 typedef struct REAL_TIME_SPEED_FEATURES {
884   // check intra prediction for non-RD mode.
885   int check_intra_pred_nonrd;
886 
887   // Perform coarse ME before calculating variance in variance-based partition
888   int estimate_motion_for_var_based_partition;
889 
890   // For nonrd_use_partition: mode of extra check of leaf partition
891   // 0 - don't check merge
892   // 1 - always check merge
893   // 2 - check merge and prune checking final split
894   int nonrd_check_partition_merge_mode;
895 
896   // For nonrd_use_partition: check of leaf partition extra split
897   int nonrd_check_partition_split;
898 
899   // Implements various heuristics to skip searching modes
900   // The heuristics selected are based on  flags
901   // defined in the MODE_SEARCH_SKIP_HEURISTICS enum
902   unsigned int mode_search_skip_flags;
903 
904   // For nonrd: Reduces ref frame search.
905   // 0 - low level of search prune in non last frames
906   // 1 - pruned search in non last frames
907   // 2 - more pruned search in non last frames
908   int nonrd_prune_ref_frame_search;
909 
910   // This flag controls the use of non-RD mode decision.
911   int use_nonrd_pick_mode;
912 
913   // Use ALTREF frame in non-RD mode decision.
914   int use_nonrd_altref_frame;
915 
916   // Use compound reference for non-RD mode.
917   int use_comp_ref_nonrd;
918 
919   // use reduced ref set for real-time mode
920   int use_real_time_ref_set;
921 
922   // Skip a number of expensive mode evaluations for blocks with very low
923   // temporal variance.
924   int short_circuit_low_temp_var;
925 
926   // Use modeled (currently CurvFit model) RDCost for fast non-RD mode
927   int use_modeled_non_rd_cost;
928 
929   // Reuse inter prediction in fast non-rd mode.
930   int reuse_inter_pred_nonrd;
931 
932   // Number of best inter modes to search transform. INT_MAX - search all.
933   int num_inter_modes_for_tx_search;
934 
935   // Forces TX search off for RDCost calulation.
936   int force_tx_search_off;
937 
938   // Use interpolation filter search in non-RD mode decision.
939   int use_nonrd_filter_search;
940 
941   // Use simplified RD model for interpolation search and Intra
942   int use_simple_rd_model;
943 
944   // If set forces interpolation filter to EIGHTTAP_REGULAR
945   int skip_interp_filter_search;
946 
947   // Use hybrid (rd for bsize < 16x16, otherwise nonrd) intra search for intra
948   // only frames.
949   int hybrid_intra_pickmode;
950 
951   // Compute variance/sse on source difference, prior to encoding superblock.
952   int source_metrics_sb_nonrd;
953 } REAL_TIME_SPEED_FEATURES;
954 
955 typedef struct SPEED_FEATURES {
956   /*
957    * Sequence/frame level speed features:
958    */
959   HIGH_LEVEL_SPEED_FEATURES hl_sf;
960 
961   /*
962    * Speed features related to how tpl's searches are done.
963    */
964   TPL_SPEED_FEATURES tpl_sf;
965 
966   /*
967    * Global motion speed features:
968    */
969   GLOBAL_MOTION_SPEED_FEATURES gm_sf;
970 
971   /*
972    * Partition search speed features:
973    */
974   PARTITION_SPEED_FEATURES part_sf;
975 
976   /*
977    * Motion search speed features:
978    */
979   MV_SPEED_FEATURES mv_sf;
980 
981   /*
982    * Inter mode search speed features:
983    */
984   INTER_MODE_SPEED_FEATURES inter_sf;
985 
986   /*
987    * Interpolation filter search speed features:
988    */
989   INTERP_FILTER_SPEED_FEATURES interp_sf;
990 
991   /*
992    * Intra mode search speed features:
993    */
994   INTRA_MODE_SPEED_FEATURES intra_sf;
995 
996   /*
997    * Transform size/type search speed features:
998    */
999   TX_SPEED_FEATURES tx_sf;
1000 
1001   /*
1002    * RD calculation speed features:
1003    */
1004   RD_CALC_SPEED_FEATURES rd_sf;
1005 
1006   /*
1007    * Two-pass mode evaluation features:
1008    */
1009   WINNER_MODE_SPEED_FEATURES winner_mode_sf;
1010 
1011   /*
1012    * In-loop filter speed features:
1013    */
1014   LOOP_FILTER_SPEED_FEATURES lpf_sf;
1015 
1016   /*
1017    * Real-time mode speed features:
1018    */
1019   REAL_TIME_SPEED_FEATURES rt_sf;
1020 } SPEED_FEATURES;
1021 
1022 struct AV1_COMP;
1023 
1024 void av1_set_speed_features_framesize_independent(struct AV1_COMP *cpi,
1025                                                   int speed);
1026 void av1_set_speed_features_framesize_dependent(struct AV1_COMP *cpi,
1027                                                 int speed);
1028 void av1_set_speed_features_qindex_dependent(struct AV1_COMP *cpi, int speed);
1029 
1030 #ifdef __cplusplus
1031 }  // extern "C"
1032 #endif
1033 
1034 #endif  // AOM_AV1_ENCODER_SPEED_FEATURES_H_
1035