LCOV - code coverage report
Current view: top level - media/libvpx/libvpx/vp9/encoder - vp9_speed_features.c (source / functions) Hit Total Coverage
Test: output.info Lines: 0 479 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
       3             :  *
       4             :  *  Use of this source code is governed by a BSD-style license
       5             :  *  that can be found in the LICENSE file in the root of the source
       6             :  *  tree. An additional intellectual property rights grant can be found
       7             :  *  in the file PATENTS.  All contributing project authors may
       8             :  *  be found in the AUTHORS file in the root of the source tree.
       9             :  */
      10             : 
      11             : #include <limits.h>
      12             : 
      13             : #include "vp9/encoder/vp9_encoder.h"
      14             : #include "vp9/encoder/vp9_speed_features.h"
      15             : #include "vp9/encoder/vp9_rdopt.h"
      16             : #include "vpx_dsp/vpx_dsp_common.h"
      17             : 
      18             : // Mesh search patters for various speed settings
      19             : static MESH_PATTERN best_quality_mesh_pattern[MAX_MESH_STEP] = {
      20             :   { 64, 4 }, { 28, 2 }, { 15, 1 }, { 7, 1 }
      21             : };
      22             : 
      23             : #define MAX_MESH_SPEED 5  // Max speed setting for mesh motion method
      24             : static MESH_PATTERN
      25             :     good_quality_mesh_patterns[MAX_MESH_SPEED + 1][MAX_MESH_STEP] = {
      26             :       { { 64, 8 }, { 28, 4 }, { 15, 1 }, { 7, 1 } },
      27             :       { { 64, 8 }, { 28, 4 }, { 15, 1 }, { 7, 1 } },
      28             :       { { 64, 8 }, { 14, 2 }, { 7, 1 }, { 7, 1 } },
      29             :       { { 64, 16 }, { 24, 8 }, { 12, 4 }, { 7, 1 } },
      30             :       { { 64, 16 }, { 24, 8 }, { 12, 4 }, { 7, 1 } },
      31             :       { { 64, 16 }, { 24, 8 }, { 12, 4 }, { 7, 1 } },
      32             :     };
      33             : static unsigned char good_quality_max_mesh_pct[MAX_MESH_SPEED + 1] = {
      34             :   50, 25, 15, 5, 1, 1
      35             : };
      36             : 
      37             : // Intra only frames, golden frames (except alt ref overlays) and
      38             : // alt ref frames tend to be coded at a higher than ambient quality
      39           0 : static int frame_is_boosted(const VP9_COMP *cpi) {
      40           0 :   return frame_is_kf_gf_arf(cpi) || vp9_is_upper_layer_key_frame(cpi);
      41             : }
      42             : 
      43             : // Sets a partition size down to which the auto partition code will always
      44             : // search (can go lower), based on the image dimensions. The logic here
      45             : // is that the extent to which ringing artefacts are offensive, depends
      46             : // partly on the screen area that over which they propogate. Propogation is
      47             : // limited by transform block size but the screen area take up by a given block
      48             : // size will be larger for a small image format stretched to full screen.
      49           0 : static BLOCK_SIZE set_partition_min_limit(VP9_COMMON *const cm) {
      50           0 :   unsigned int screen_area = (cm->width * cm->height);
      51             : 
      52             :   // Select block size based on image format size.
      53           0 :   if (screen_area < 1280 * 720) {
      54             :     // Formats smaller in area than 720P
      55           0 :     return BLOCK_4X4;
      56           0 :   } else if (screen_area < 1920 * 1080) {
      57             :     // Format >= 720P and < 1080P
      58           0 :     return BLOCK_8X8;
      59             :   } else {
      60             :     // Formats 1080P and up
      61           0 :     return BLOCK_16X16;
      62             :   }
      63             : }
      64             : 
      65           0 : static void set_good_speed_feature_framesize_dependent(VP9_COMP *cpi,
      66             :                                                        SPEED_FEATURES *sf,
      67             :                                                        int speed) {
      68           0 :   VP9_COMMON *const cm = &cpi->common;
      69             : 
      70           0 :   if (speed >= 1) {
      71           0 :     if (VPXMIN(cm->width, cm->height) >= 720) {
      72           0 :       sf->disable_split_mask =
      73           0 :           cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
      74           0 :       sf->partition_search_breakout_dist_thr = (1 << 23);
      75             :     } else {
      76           0 :       sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
      77           0 :       sf->partition_search_breakout_dist_thr = (1 << 21);
      78             :     }
      79             :   }
      80             : 
      81           0 :   if (speed >= 2) {
      82           0 :     if (VPXMIN(cm->width, cm->height) >= 720) {
      83           0 :       sf->disable_split_mask =
      84           0 :           cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
      85           0 :       sf->adaptive_pred_interp_filter = 0;
      86           0 :       sf->partition_search_breakout_dist_thr = (1 << 24);
      87           0 :       sf->partition_search_breakout_rate_thr = 120;
      88             :     } else {
      89           0 :       sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY;
      90           0 :       sf->partition_search_breakout_dist_thr = (1 << 22);
      91           0 :       sf->partition_search_breakout_rate_thr = 100;
      92             :     }
      93           0 :     sf->rd_auto_partition_min_limit = set_partition_min_limit(cm);
      94             : 
      95             :     // Use a set of speed features for 4k videos.
      96           0 :     if (VPXMIN(cm->width, cm->height) >= 2160) {
      97           0 :       sf->use_square_partition_only = 1;
      98           0 :       sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
      99           0 :       sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC;
     100           0 :       sf->alt_ref_search_fp = 1;
     101           0 :       sf->cb_pred_filter_search = 1;
     102           0 :       sf->adaptive_interp_filter_search = 1;
     103           0 :       sf->disable_split_mask = DISABLE_ALL_SPLIT;
     104             :     }
     105             :   }
     106             : 
     107           0 :   if (speed >= 3) {
     108           0 :     if (VPXMIN(cm->width, cm->height) >= 720) {
     109           0 :       sf->disable_split_mask = DISABLE_ALL_SPLIT;
     110           0 :       sf->schedule_mode_search = cm->base_qindex < 220 ? 1 : 0;
     111           0 :       sf->partition_search_breakout_dist_thr = (1 << 25);
     112           0 :       sf->partition_search_breakout_rate_thr = 200;
     113             :     } else {
     114           0 :       sf->max_intra_bsize = BLOCK_32X32;
     115           0 :       sf->disable_split_mask = DISABLE_ALL_INTER_SPLIT;
     116           0 :       sf->schedule_mode_search = cm->base_qindex < 175 ? 1 : 0;
     117           0 :       sf->partition_search_breakout_dist_thr = (1 << 23);
     118           0 :       sf->partition_search_breakout_rate_thr = 120;
     119             :     }
     120             :   }
     121             : 
     122             :   // If this is a two pass clip that fits the criteria for animated or
     123             :   // graphics content then reset disable_split_mask for speeds 1-4.
     124             :   // Also if the image edge is internal to the coded area.
     125           0 :   if ((speed >= 1) && (cpi->oxcf.pass == 2) &&
     126           0 :       ((cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ||
     127           0 :        (vp9_internal_image_edge(cpi)))) {
     128           0 :     sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
     129             :   }
     130             : 
     131           0 :   if (speed >= 4) {
     132           0 :     if (VPXMIN(cm->width, cm->height) >= 720) {
     133           0 :       sf->partition_search_breakout_dist_thr = (1 << 26);
     134             :     } else {
     135           0 :       sf->partition_search_breakout_dist_thr = (1 << 24);
     136             :     }
     137           0 :     sf->disable_split_mask = DISABLE_ALL_SPLIT;
     138             :   }
     139           0 : }
     140             : 
     141             : static double tx_dom_thresholds[6] = { 99.0, 14.0, 12.0, 8.0, 4.0, 0.0 };
     142             : static double qopt_thresholds[6] = { 99.0, 12.0, 10.0, 4.0, 2.0, 0.0 };
     143             : 
     144           0 : static void set_good_speed_feature(VP9_COMP *cpi, VP9_COMMON *cm,
     145             :                                    SPEED_FEATURES *sf, int speed) {
     146           0 :   const int boosted = frame_is_boosted(cpi);
     147             : 
     148           0 :   sf->partition_search_breakout_dist_thr = (1 << 20);
     149           0 :   sf->partition_search_breakout_rate_thr = 80;
     150           0 :   sf->tx_size_search_breakout = 1;
     151           0 :   sf->adaptive_rd_thresh = 1;
     152           0 :   sf->allow_skip_recode = 1;
     153           0 :   sf->less_rectangular_check = 1;
     154           0 :   sf->use_square_partition_only = !frame_is_boosted(cpi);
     155           0 :   sf->use_square_only_threshold = BLOCK_16X16;
     156             : 
     157           0 :   if (speed >= 1) {
     158           0 :     if (cpi->oxcf.pass == 2) {
     159           0 :       TWO_PASS *const twopass = &cpi->twopass;
     160           0 :       if ((twopass->fr_content_type == FC_GRAPHICS_ANIMATION) ||
     161           0 :           vp9_internal_image_edge(cpi)) {
     162           0 :         sf->use_square_partition_only = !frame_is_boosted(cpi);
     163             :       } else {
     164           0 :         sf->use_square_partition_only = !frame_is_intra_only(cm);
     165             :       }
     166             :     } else {
     167           0 :       sf->use_square_partition_only = !frame_is_intra_only(cm);
     168             :     }
     169             : 
     170           0 :     sf->allow_txfm_domain_distortion = 1;
     171           0 :     sf->tx_domain_thresh = tx_dom_thresholds[(speed < 6) ? speed : 5];
     172           0 :     sf->allow_quant_coeff_opt = sf->optimize_coefficients;
     173           0 :     sf->quant_opt_thresh = qopt_thresholds[(speed < 6) ? speed : 5];
     174             : 
     175           0 :     sf->use_square_only_threshold = BLOCK_4X4;
     176           0 :     sf->less_rectangular_check = 1;
     177             : 
     178           0 :     sf->use_rd_breakout = 1;
     179           0 :     sf->adaptive_motion_search = 1;
     180           0 :     sf->mv.auto_mv_step_size = 1;
     181           0 :     sf->adaptive_rd_thresh = 2;
     182           0 :     sf->mv.subpel_iters_per_step = 1;
     183           0 :     sf->mode_skip_start = 10;
     184           0 :     sf->adaptive_pred_interp_filter = 1;
     185           0 :     sf->allow_acl = 0;
     186             : 
     187           0 :     sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
     188           0 :     sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
     189           0 :     sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
     190           0 :     sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
     191             : 
     192           0 :     sf->recode_tolerance_low = 15;
     193           0 :     sf->recode_tolerance_high = 30;
     194             :   }
     195             : 
     196           0 :   if (speed >= 2) {
     197           0 :     sf->recode_loop = ALLOW_RECODE_KFARFGF;
     198           0 :     sf->tx_size_search_method =
     199           0 :         frame_is_boosted(cpi) ? USE_FULL_RD : USE_LARGESTALL;
     200             : 
     201             :     // Reference masking is not supported in dynamic scaling mode.
     202           0 :     sf->reference_masking = cpi->oxcf.resize_mode != RESIZE_DYNAMIC ? 1 : 0;
     203             : 
     204           0 :     sf->mode_search_skip_flags =
     205           0 :         (cm->frame_type == KEY_FRAME) ? 0 : FLAG_SKIP_INTRA_DIRMISMATCH |
     206             :                                                 FLAG_SKIP_INTRA_BESTINTER |
     207             :                                                 FLAG_SKIP_COMP_BESTINTRA |
     208             :                                                 FLAG_SKIP_INTRA_LOWVAR;
     209           0 :     sf->disable_filter_search_var_thresh = 100;
     210           0 :     sf->comp_inter_joint_search_thresh = BLOCK_SIZES;
     211           0 :     sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
     212           0 :     sf->allow_partition_search_skip = 1;
     213           0 :     sf->recode_tolerance_low = 15;
     214           0 :     sf->recode_tolerance_high = 45;
     215             :   }
     216             : 
     217           0 :   if (speed >= 3) {
     218           0 :     sf->use_square_partition_only = !frame_is_intra_only(cm);
     219           0 :     sf->tx_size_search_method =
     220           0 :         frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL;
     221           0 :     sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED;
     222           0 :     sf->adaptive_pred_interp_filter = 0;
     223           0 :     sf->adaptive_mode_search = 1;
     224           0 :     sf->cb_partition_search = !boosted;
     225           0 :     sf->cb_pred_filter_search = 1;
     226           0 :     sf->alt_ref_search_fp = 1;
     227           0 :     sf->recode_loop = ALLOW_RECODE_KFMAXBW;
     228           0 :     sf->adaptive_rd_thresh = 3;
     229           0 :     sf->mode_skip_start = 6;
     230           0 :     sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
     231           0 :     sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC;
     232           0 :     sf->adaptive_interp_filter_search = 1;
     233             :   }
     234             : 
     235           0 :   if (speed >= 4) {
     236           0 :     sf->use_square_partition_only = 1;
     237           0 :     sf->tx_size_search_method = USE_LARGESTALL;
     238           0 :     sf->mv.search_method = BIGDIA;
     239           0 :     sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
     240           0 :     sf->adaptive_rd_thresh = 4;
     241           0 :     if (cm->frame_type != KEY_FRAME)
     242           0 :       sf->mode_search_skip_flags |= FLAG_EARLY_TERMINATE;
     243           0 :     sf->disable_filter_search_var_thresh = 200;
     244           0 :     sf->use_lp32x32fdct = 1;
     245           0 :     sf->use_fast_coef_updates = ONE_LOOP_REDUCED;
     246           0 :     sf->use_fast_coef_costing = 1;
     247           0 :     sf->motion_field_mode_search = !boosted;
     248           0 :     sf->partition_search_breakout_rate_thr = 300;
     249             :   }
     250             : 
     251           0 :   if (speed >= 5) {
     252             :     int i;
     253           0 :     sf->optimize_coefficients = 0;
     254           0 :     sf->mv.search_method = HEX;
     255           0 :     sf->disable_filter_search_var_thresh = 500;
     256           0 :     for (i = 0; i < TX_SIZES; ++i) {
     257           0 :       sf->intra_y_mode_mask[i] = INTRA_DC;
     258           0 :       sf->intra_uv_mode_mask[i] = INTRA_DC;
     259             :     }
     260           0 :     sf->partition_search_breakout_rate_thr = 500;
     261           0 :     sf->mv.reduce_first_step_size = 1;
     262           0 :     sf->simple_model_rd_from_var = 1;
     263             :   }
     264           0 : }
     265             : 
     266           0 : static void set_rt_speed_feature_framesize_dependent(VP9_COMP *cpi,
     267             :                                                      SPEED_FEATURES *sf,
     268             :                                                      int speed) {
     269           0 :   VP9_COMMON *const cm = &cpi->common;
     270             : 
     271           0 :   if (speed >= 1) {
     272           0 :     if (VPXMIN(cm->width, cm->height) >= 720) {
     273           0 :       sf->disable_split_mask =
     274           0 :           cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
     275             :     } else {
     276           0 :       sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
     277             :     }
     278             :   }
     279             : 
     280           0 :   if (speed >= 2) {
     281           0 :     if (VPXMIN(cm->width, cm->height) >= 720) {
     282           0 :       sf->disable_split_mask =
     283           0 :           cm->show_frame ? DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
     284             :     } else {
     285           0 :       sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY;
     286             :     }
     287             :   }
     288             : 
     289           0 :   if (speed >= 5) {
     290           0 :     if (VPXMIN(cm->width, cm->height) >= 720) {
     291           0 :       sf->partition_search_breakout_dist_thr = (1 << 25);
     292             :     } else {
     293           0 :       sf->partition_search_breakout_dist_thr = (1 << 23);
     294             :     }
     295             :   }
     296             : 
     297           0 :   if (speed >= 7) {
     298           0 :     sf->encode_breakout_thresh =
     299           0 :         (VPXMIN(cm->width, cm->height) >= 720) ? 800 : 300;
     300             :   }
     301           0 : }
     302             : 
     303           0 : static void set_rt_speed_feature(VP9_COMP *cpi, SPEED_FEATURES *sf, int speed,
     304             :                                  vp9e_tune_content content) {
     305           0 :   VP9_COMMON *const cm = &cpi->common;
     306           0 :   const int is_keyframe = cm->frame_type == KEY_FRAME;
     307           0 :   const int frames_since_key = is_keyframe ? 0 : cpi->rc.frames_since_key;
     308           0 :   sf->static_segmentation = 0;
     309           0 :   sf->adaptive_rd_thresh = 1;
     310           0 :   sf->use_fast_coef_costing = 1;
     311           0 :   sf->allow_exhaustive_searches = 0;
     312           0 :   sf->exhaustive_searches_thresh = INT_MAX;
     313           0 :   sf->allow_acl = 0;
     314           0 :   sf->copy_partition_flag = 0;
     315             : 
     316           0 :   if (speed >= 1) {
     317           0 :     sf->allow_txfm_domain_distortion = 1;
     318           0 :     sf->tx_domain_thresh = 0.0;
     319           0 :     sf->allow_quant_coeff_opt = 0;
     320           0 :     sf->quant_opt_thresh = 0.0;
     321           0 :     sf->use_square_partition_only = !frame_is_intra_only(cm);
     322           0 :     sf->less_rectangular_check = 1;
     323           0 :     sf->tx_size_search_method =
     324           0 :         frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL;
     325             : 
     326           0 :     sf->use_rd_breakout = 1;
     327             : 
     328           0 :     sf->adaptive_motion_search = 1;
     329           0 :     sf->adaptive_pred_interp_filter = 1;
     330           0 :     sf->mv.auto_mv_step_size = 1;
     331           0 :     sf->adaptive_rd_thresh = 2;
     332           0 :     sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
     333           0 :     sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
     334           0 :     sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
     335             :   }
     336             : 
     337           0 :   if (speed >= 2) {
     338           0 :     sf->mode_search_skip_flags =
     339           0 :         (cm->frame_type == KEY_FRAME) ? 0 : FLAG_SKIP_INTRA_DIRMISMATCH |
     340             :                                                 FLAG_SKIP_INTRA_BESTINTER |
     341             :                                                 FLAG_SKIP_COMP_BESTINTRA |
     342             :                                                 FLAG_SKIP_INTRA_LOWVAR;
     343           0 :     sf->adaptive_pred_interp_filter = 2;
     344             : 
     345             :     // Reference masking only enabled for 1 spatial layer, and if none of the
     346             :     // references have been scaled. The latter condition needs to be checked
     347             :     // for external or internal dynamic resize.
     348           0 :     sf->reference_masking = (cpi->svc.number_spatial_layers == 1);
     349           0 :     if (sf->reference_masking == 1 &&
     350           0 :         (cpi->external_resize == 1 ||
     351           0 :          cpi->oxcf.resize_mode == RESIZE_DYNAMIC)) {
     352             :       MV_REFERENCE_FRAME ref_frame;
     353             :       static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG,
     354             :                                         VP9_ALT_FLAG };
     355           0 :       for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
     356           0 :         const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, ref_frame);
     357           0 :         if (yv12 != NULL && (cpi->ref_frame_flags & flag_list[ref_frame])) {
     358           0 :           const struct scale_factors *const scale_fac =
     359           0 :               &cm->frame_refs[ref_frame - 1].sf;
     360           0 :           if (vp9_is_scaled(scale_fac)) sf->reference_masking = 0;
     361             :         }
     362             :       }
     363             :     }
     364             : 
     365           0 :     sf->disable_filter_search_var_thresh = 50;
     366           0 :     sf->comp_inter_joint_search_thresh = BLOCK_SIZES;
     367           0 :     sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
     368           0 :     sf->lf_motion_threshold = LOW_MOTION_THRESHOLD;
     369           0 :     sf->adjust_partitioning_from_last_frame = 1;
     370           0 :     sf->last_partitioning_redo_frequency = 3;
     371           0 :     sf->use_lp32x32fdct = 1;
     372           0 :     sf->mode_skip_start = 11;
     373           0 :     sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
     374             :   }
     375             : 
     376           0 :   if (speed >= 3) {
     377           0 :     sf->use_square_partition_only = 1;
     378           0 :     sf->disable_filter_search_var_thresh = 100;
     379           0 :     sf->use_uv_intra_rd_estimate = 1;
     380           0 :     sf->skip_encode_sb = 1;
     381           0 :     sf->mv.subpel_iters_per_step = 1;
     382           0 :     sf->adaptive_rd_thresh = 4;
     383           0 :     sf->mode_skip_start = 6;
     384           0 :     sf->allow_skip_recode = 0;
     385           0 :     sf->optimize_coefficients = 0;
     386           0 :     sf->disable_split_mask = DISABLE_ALL_SPLIT;
     387           0 :     sf->lpf_pick = LPF_PICK_FROM_Q;
     388             :   }
     389             : 
     390           0 :   if (speed >= 4) {
     391             :     int i;
     392           0 :     sf->last_partitioning_redo_frequency = 4;
     393           0 :     sf->adaptive_rd_thresh = 5;
     394           0 :     sf->use_fast_coef_costing = 0;
     395           0 :     sf->auto_min_max_partition_size = STRICT_NEIGHBORING_MIN_MAX;
     396           0 :     sf->adjust_partitioning_from_last_frame =
     397           0 :         cm->last_frame_type != cm->frame_type ||
     398           0 :         (0 == (frames_since_key + 1) % sf->last_partitioning_redo_frequency);
     399           0 :     sf->mv.subpel_force_stop = 1;
     400           0 :     for (i = 0; i < TX_SIZES; i++) {
     401           0 :       sf->intra_y_mode_mask[i] = INTRA_DC_H_V;
     402           0 :       sf->intra_uv_mode_mask[i] = INTRA_DC;
     403             :     }
     404           0 :     sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
     405           0 :     sf->frame_parameter_update = 0;
     406           0 :     sf->mv.search_method = FAST_HEX;
     407             : 
     408           0 :     sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEAR_NEW;
     409           0 :     sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST;
     410           0 :     sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST;
     411           0 :     sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST;
     412           0 :     sf->max_intra_bsize = BLOCK_32X32;
     413           0 :     sf->allow_skip_recode = 1;
     414             :   }
     415             : 
     416           0 :   if (speed >= 5) {
     417           0 :     sf->use_quant_fp = !is_keyframe;
     418           0 :     sf->auto_min_max_partition_size =
     419           0 :         is_keyframe ? RELAXED_NEIGHBORING_MIN_MAX : STRICT_NEIGHBORING_MIN_MAX;
     420           0 :     sf->default_max_partition_size = BLOCK_32X32;
     421           0 :     sf->default_min_partition_size = BLOCK_8X8;
     422           0 :     sf->force_frame_boost =
     423           0 :         is_keyframe ||
     424           0 :         (frames_since_key % (sf->last_partitioning_redo_frequency << 1) == 1);
     425           0 :     sf->max_delta_qindex = is_keyframe ? 20 : 15;
     426           0 :     sf->partition_search_type = REFERENCE_PARTITION;
     427           0 :     if (cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0 &&
     428           0 :         cpi->rc.is_src_frame_alt_ref) {
     429           0 :       sf->partition_search_type = VAR_BASED_PARTITION;
     430             :     }
     431           0 :     sf->use_nonrd_pick_mode = 1;
     432           0 :     sf->allow_skip_recode = 0;
     433           0 :     sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEW_ZERO;
     434           0 :     sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST_NEW_ZERO;
     435           0 :     sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST_NEW_ZERO;
     436           0 :     sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST_NEW_ZERO;
     437           0 :     sf->adaptive_rd_thresh = 2;
     438             :     // This feature is only enabled when partition search is disabled.
     439           0 :     sf->reuse_inter_pred_sby = 1;
     440           0 :     sf->partition_search_breakout_rate_thr = 200;
     441           0 :     sf->coeff_prob_appx_step = 4;
     442           0 :     sf->use_fast_coef_updates = is_keyframe ? TWO_LOOP : ONE_LOOP_REDUCED;
     443           0 :     sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH;
     444           0 :     sf->tx_size_search_method = is_keyframe ? USE_LARGESTALL : USE_TX_8X8;
     445           0 :     sf->simple_model_rd_from_var = 1;
     446           0 :     if (cpi->oxcf.rc_mode == VPX_VBR) sf->mv.search_method = NSTEP;
     447             : 
     448           0 :     if (!is_keyframe) {
     449             :       int i;
     450           0 :       if (content == VP9E_CONTENT_SCREEN) {
     451           0 :         for (i = 0; i < BLOCK_SIZES; ++i)
     452           0 :           sf->intra_y_mode_bsize_mask[i] = INTRA_DC_TM_H_V;
     453             :       } else {
     454           0 :         for (i = 0; i < BLOCK_SIZES; ++i)
     455           0 :           if (i > BLOCK_16X16)
     456           0 :             sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
     457             :           else
     458             :             // Use H and V intra mode for block sizes <= 16X16.
     459           0 :             sf->intra_y_mode_bsize_mask[i] = INTRA_DC_H_V;
     460             :       }
     461             :     }
     462           0 :     if (content == VP9E_CONTENT_SCREEN) {
     463           0 :       sf->short_circuit_flat_blocks = 1;
     464             :     }
     465           0 :     if (cpi->oxcf.rc_mode == VPX_CBR &&
     466           0 :         cpi->oxcf.content != VP9E_CONTENT_SCREEN && !cpi->use_svc) {
     467           0 :       sf->limit_newmv_early_exit = 1;
     468           0 :       sf->bias_golden = 1;
     469             :     }
     470             :   }
     471             : 
     472           0 :   if (speed >= 6) {
     473           0 :     sf->partition_search_type = VAR_BASED_PARTITION;
     474             :     // Turn on this to use non-RD key frame coding mode.
     475           0 :     sf->use_nonrd_pick_mode = 1;
     476           0 :     sf->mv.search_method = NSTEP;
     477           0 :     sf->mv.reduce_first_step_size = 1;
     478           0 :     sf->skip_encode_sb = 0;
     479           0 :     if (!cpi->use_svc && cpi->oxcf.rc_mode == VPX_CBR &&
     480             :         content != VP9E_CONTENT_SCREEN) {
     481             :       // Enable short circuit for low temporal variance.
     482           0 :       sf->short_circuit_low_temp_var = 1;
     483             :     }
     484           0 :     if (cpi->use_svc) sf->base_mv_aggressive = 1;
     485             :   }
     486             : 
     487           0 :   if (speed >= 7) {
     488           0 :     sf->adaptive_rd_thresh = 3;
     489           0 :     sf->mv.search_method = FAST_DIAMOND;
     490           0 :     sf->mv.fullpel_search_step_param = 10;
     491           0 :     if (cpi->svc.number_temporal_layers > 2 &&
     492           0 :         cpi->svc.temporal_layer_id == 0) {
     493           0 :       sf->mv.search_method = NSTEP;
     494           0 :       sf->mv.fullpel_search_step_param = 6;
     495             :     }
     496             :   }
     497             : 
     498           0 :   if (speed >= 8) {
     499           0 :     sf->adaptive_rd_thresh = 4;
     500             :     // Disabled for now until the threshold is tuned.
     501           0 :     sf->copy_partition_flag = 0;
     502           0 :     if (sf->copy_partition_flag) {
     503           0 :       if (cpi->prev_partition == NULL) {
     504           0 :         cpi->prev_partition = (BLOCK_SIZE *)vpx_calloc(
     505           0 :             cm->mi_stride * cm->mi_rows, sizeof(BLOCK_SIZE));
     506             :       }
     507           0 :       if (cpi->prev_segment_id == NULL) {
     508           0 :         cpi->prev_segment_id =
     509           0 :             (int8_t *)vpx_calloc(cm->mi_stride * cm->mi_rows, sizeof(int8_t));
     510             :       }
     511             :     }
     512           0 :     sf->mv.subpel_force_stop = (content == VP9E_CONTENT_SCREEN) ? 3 : 2;
     513           0 :     if (content == VP9E_CONTENT_SCREEN) sf->lpf_pick = LPF_PICK_MINIMAL_LPF;
     514             :     // Only keep INTRA_DC mode for speed 8.
     515           0 :     if (!is_keyframe) {
     516           0 :       int i = 0;
     517           0 :       for (i = 0; i < BLOCK_SIZES; ++i)
     518           0 :         sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
     519             :     }
     520           0 :     if (!cpi->use_svc && cpi->oxcf.rc_mode == VPX_CBR &&
     521             :         content != VP9E_CONTENT_SCREEN) {
     522             :       // More aggressive short circuit for speed 8.
     523           0 :       sf->short_circuit_low_temp_var = 3;
     524             :     }
     525           0 :     sf->limit_newmv_early_exit = 0;
     526             :   }
     527           0 : }
     528             : 
     529           0 : void vp9_set_speed_features_framesize_dependent(VP9_COMP *cpi) {
     530           0 :   SPEED_FEATURES *const sf = &cpi->sf;
     531           0 :   const VP9EncoderConfig *const oxcf = &cpi->oxcf;
     532           0 :   RD_OPT *const rd = &cpi->rd;
     533             :   int i;
     534             : 
     535           0 :   if (oxcf->mode == REALTIME) {
     536           0 :     set_rt_speed_feature_framesize_dependent(cpi, sf, oxcf->speed);
     537           0 :   } else if (oxcf->mode == GOOD) {
     538           0 :     set_good_speed_feature_framesize_dependent(cpi, sf, oxcf->speed);
     539             :   }
     540             : 
     541           0 :   if (sf->disable_split_mask == DISABLE_ALL_SPLIT) {
     542           0 :     sf->adaptive_pred_interp_filter = 0;
     543             :   }
     544             : 
     545           0 :   if (cpi->encode_breakout && oxcf->mode == REALTIME &&
     546           0 :       sf->encode_breakout_thresh > cpi->encode_breakout) {
     547           0 :     cpi->encode_breakout = sf->encode_breakout_thresh;
     548             :   }
     549             : 
     550             :   // Check for masked out split cases.
     551           0 :   for (i = 0; i < MAX_REFS; ++i) {
     552           0 :     if (sf->disable_split_mask & (1 << i)) {
     553           0 :       rd->thresh_mult_sub8x8[i] = INT_MAX;
     554             :     }
     555             :   }
     556           0 : }
     557             : 
     558           0 : void vp9_set_speed_features_framesize_independent(VP9_COMP *cpi) {
     559           0 :   SPEED_FEATURES *const sf = &cpi->sf;
     560           0 :   VP9_COMMON *const cm = &cpi->common;
     561           0 :   MACROBLOCK *const x = &cpi->td.mb;
     562           0 :   const VP9EncoderConfig *const oxcf = &cpi->oxcf;
     563             :   int i;
     564             : 
     565             :   // best quality defaults
     566           0 :   sf->frame_parameter_update = 1;
     567           0 :   sf->mv.search_method = NSTEP;
     568           0 :   sf->recode_loop = ALLOW_RECODE_FIRST;
     569           0 :   sf->mv.subpel_search_method = SUBPEL_TREE;
     570           0 :   sf->mv.subpel_iters_per_step = 2;
     571           0 :   sf->mv.subpel_force_stop = 0;
     572           0 :   sf->optimize_coefficients = !is_lossless_requested(&cpi->oxcf);
     573           0 :   sf->mv.reduce_first_step_size = 0;
     574           0 :   sf->coeff_prob_appx_step = 1;
     575           0 :   sf->mv.auto_mv_step_size = 0;
     576           0 :   sf->mv.fullpel_search_step_param = 6;
     577           0 :   sf->comp_inter_joint_search_thresh = BLOCK_4X4;
     578           0 :   sf->tx_size_search_method = USE_FULL_RD;
     579           0 :   sf->use_lp32x32fdct = 0;
     580           0 :   sf->adaptive_motion_search = 0;
     581           0 :   sf->adaptive_pred_interp_filter = 0;
     582           0 :   sf->adaptive_mode_search = 0;
     583           0 :   sf->cb_pred_filter_search = 0;
     584           0 :   sf->cb_partition_search = 0;
     585           0 :   sf->motion_field_mode_search = 0;
     586           0 :   sf->alt_ref_search_fp = 0;
     587           0 :   sf->use_quant_fp = 0;
     588           0 :   sf->reference_masking = 0;
     589           0 :   sf->partition_search_type = SEARCH_PARTITION;
     590           0 :   sf->less_rectangular_check = 0;
     591           0 :   sf->use_square_partition_only = 0;
     592           0 :   sf->use_square_only_threshold = BLOCK_SIZES;
     593           0 :   sf->auto_min_max_partition_size = NOT_IN_USE;
     594           0 :   sf->rd_auto_partition_min_limit = BLOCK_4X4;
     595           0 :   sf->default_max_partition_size = BLOCK_64X64;
     596           0 :   sf->default_min_partition_size = BLOCK_4X4;
     597           0 :   sf->adjust_partitioning_from_last_frame = 0;
     598           0 :   sf->last_partitioning_redo_frequency = 4;
     599           0 :   sf->disable_split_mask = 0;
     600           0 :   sf->mode_search_skip_flags = 0;
     601           0 :   sf->force_frame_boost = 0;
     602           0 :   sf->max_delta_qindex = 0;
     603           0 :   sf->disable_filter_search_var_thresh = 0;
     604           0 :   sf->adaptive_interp_filter_search = 0;
     605           0 :   sf->allow_partition_search_skip = 0;
     606           0 :   sf->allow_txfm_domain_distortion = 0;
     607           0 :   sf->tx_domain_thresh = 99.0;
     608           0 :   sf->allow_quant_coeff_opt = sf->optimize_coefficients;
     609           0 :   sf->quant_opt_thresh = 99.0;
     610           0 :   sf->allow_acl = 1;
     611             : 
     612           0 :   for (i = 0; i < TX_SIZES; i++) {
     613           0 :     sf->intra_y_mode_mask[i] = INTRA_ALL;
     614           0 :     sf->intra_uv_mode_mask[i] = INTRA_ALL;
     615             :   }
     616           0 :   sf->use_rd_breakout = 0;
     617           0 :   sf->skip_encode_sb = 0;
     618           0 :   sf->use_uv_intra_rd_estimate = 0;
     619           0 :   sf->allow_skip_recode = 0;
     620           0 :   sf->lpf_pick = LPF_PICK_FROM_FULL_IMAGE;
     621           0 :   sf->use_fast_coef_updates = TWO_LOOP;
     622           0 :   sf->use_fast_coef_costing = 0;
     623           0 :   sf->mode_skip_start = MAX_MODES;  // Mode index at which mode skip mask set
     624           0 :   sf->schedule_mode_search = 0;
     625           0 :   sf->use_nonrd_pick_mode = 0;
     626           0 :   for (i = 0; i < BLOCK_SIZES; ++i) sf->inter_mode_mask[i] = INTER_ALL;
     627           0 :   sf->max_intra_bsize = BLOCK_64X64;
     628           0 :   sf->reuse_inter_pred_sby = 0;
     629             :   // This setting only takes effect when partition_search_type is set
     630             :   // to FIXED_PARTITION.
     631           0 :   sf->always_this_block_size = BLOCK_16X16;
     632           0 :   sf->search_type_check_frequency = 50;
     633           0 :   sf->encode_breakout_thresh = 0;
     634             :   // Recode loop tolerance %.
     635           0 :   sf->recode_tolerance_low = 12;
     636           0 :   sf->recode_tolerance_high = 25;
     637           0 :   sf->default_interp_filter = SWITCHABLE;
     638           0 :   sf->simple_model_rd_from_var = 0;
     639           0 :   sf->short_circuit_flat_blocks = 0;
     640           0 :   sf->short_circuit_low_temp_var = 0;
     641           0 :   sf->limit_newmv_early_exit = 0;
     642           0 :   sf->bias_golden = 0;
     643           0 :   sf->base_mv_aggressive = 0;
     644             : 
     645             :   // Some speed-up features even for best quality as minimal impact on quality.
     646           0 :   sf->adaptive_rd_thresh = 1;
     647           0 :   sf->tx_size_search_breakout = 1;
     648           0 :   sf->partition_search_breakout_dist_thr = (1 << 19);
     649           0 :   sf->partition_search_breakout_rate_thr = 80;
     650             : 
     651           0 :   if (oxcf->mode == REALTIME)
     652           0 :     set_rt_speed_feature(cpi, sf, oxcf->speed, oxcf->content);
     653           0 :   else if (oxcf->mode == GOOD)
     654           0 :     set_good_speed_feature(cpi, cm, sf, oxcf->speed);
     655             : 
     656           0 :   cpi->full_search_sad = vp9_full_search_sad;
     657           0 :   cpi->diamond_search_sad = vp9_diamond_search_sad;
     658             : 
     659           0 :   sf->allow_exhaustive_searches = 1;
     660           0 :   if (oxcf->mode == BEST) {
     661           0 :     if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION)
     662           0 :       sf->exhaustive_searches_thresh = (1 << 20);
     663             :     else
     664           0 :       sf->exhaustive_searches_thresh = (1 << 21);
     665           0 :     sf->max_exaustive_pct = 100;
     666           0 :     for (i = 0; i < MAX_MESH_STEP; ++i) {
     667           0 :       sf->mesh_patterns[i].range = best_quality_mesh_pattern[i].range;
     668           0 :       sf->mesh_patterns[i].interval = best_quality_mesh_pattern[i].interval;
     669             :     }
     670             :   } else {
     671           0 :     int speed = (oxcf->speed > MAX_MESH_SPEED) ? MAX_MESH_SPEED : oxcf->speed;
     672           0 :     if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION)
     673           0 :       sf->exhaustive_searches_thresh = (1 << 22);
     674             :     else
     675           0 :       sf->exhaustive_searches_thresh = (1 << 23);
     676           0 :     sf->max_exaustive_pct = good_quality_max_mesh_pct[speed];
     677           0 :     if (speed > 0)
     678           0 :       sf->exhaustive_searches_thresh = sf->exhaustive_searches_thresh << 1;
     679             : 
     680           0 :     for (i = 0; i < MAX_MESH_STEP; ++i) {
     681           0 :       sf->mesh_patterns[i].range = good_quality_mesh_patterns[speed][i].range;
     682           0 :       sf->mesh_patterns[i].interval =
     683           0 :           good_quality_mesh_patterns[speed][i].interval;
     684             :     }
     685             :   }
     686             : 
     687             :   // Slow quant, dct and trellis not worthwhile for first pass
     688             :   // so make sure they are always turned off.
     689           0 :   if (oxcf->pass == 1) sf->optimize_coefficients = 0;
     690             : 
     691             :   // No recode for 1 pass.
     692           0 :   if (oxcf->pass == 0) {
     693           0 :     sf->recode_loop = DISALLOW_RECODE;
     694           0 :     sf->optimize_coefficients = 0;
     695             :   }
     696             : 
     697           0 :   if (sf->mv.subpel_force_stop == 3) {
     698             :     // Whole pel only
     699           0 :     cpi->find_fractional_mv_step = vp9_skip_sub_pixel_tree;
     700           0 :   } else if (sf->mv.subpel_search_method == SUBPEL_TREE) {
     701           0 :     cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree;
     702           0 :   } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED) {
     703           0 :     cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned;
     704           0 :   } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_MORE) {
     705           0 :     cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_more;
     706           0 :   } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_EVENMORE) {
     707           0 :     cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_evenmore;
     708             :   }
     709             : 
     710           0 :   x->optimize = sf->optimize_coefficients == 1 && oxcf->pass != 1;
     711             : 
     712           0 :   x->min_partition_size = sf->default_min_partition_size;
     713           0 :   x->max_partition_size = sf->default_max_partition_size;
     714             : 
     715           0 :   if (!cpi->oxcf.frame_periodic_boost) {
     716           0 :     sf->max_delta_qindex = 0;
     717             :   }
     718           0 : }

Generated by: LCOV version 1.13