OLD | NEW |
(Empty) | |
| 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_onyx_int.h" |
| 14 #include "vp9/encoder/vp9_speed_features.h" |
| 15 |
| 16 #define ALL_INTRA_MODES ((1 << DC_PRED) | \ |
| 17 (1 << V_PRED) | (1 << H_PRED) | \ |
| 18 (1 << D45_PRED) | (1 << D135_PRED) | \ |
| 19 (1 << D117_PRED) | (1 << D153_PRED) | \ |
| 20 (1 << D207_PRED) | (1 << D63_PRED) | \ |
| 21 (1 << TM_PRED)) |
| 22 #define INTRA_DC_ONLY (1 << DC_PRED) |
| 23 #define INTRA_DC_TM ((1 << TM_PRED) | (1 << DC_PRED)) |
| 24 #define INTRA_DC_H_V ((1 << DC_PRED) | (1 << V_PRED) | (1 << H_PRED)) |
| 25 #define INTRA_DC_TM_H_V (INTRA_DC_TM | (1 << V_PRED) | (1 << H_PRED)) |
| 26 |
| 27 // Masks for partially or completely disabling split mode |
| 28 #define DISABLE_ALL_INTER_SPLIT ((1 << THR_COMP_GA) | \ |
| 29 (1 << THR_COMP_LA) | \ |
| 30 (1 << THR_ALTR) | \ |
| 31 (1 << THR_GOLD) | \ |
| 32 (1 << THR_LAST)) |
| 33 |
| 34 #define DISABLE_ALL_SPLIT ((1 << THR_INTRA) | DISABLE_ALL_INTER_SPLIT) |
| 35 |
| 36 #define DISABLE_COMPOUND_SPLIT ((1 << THR_COMP_GA) | (1 << THR_COMP_LA)) |
| 37 |
| 38 #define LAST_AND_INTRA_SPLIT_ONLY ((1 << THR_COMP_GA) | \ |
| 39 (1 << THR_COMP_LA) | \ |
| 40 (1 << THR_ALTR) | \ |
| 41 (1 << THR_GOLD)) |
| 42 |
| 43 static void set_good_speed_feature(VP9_COMP *cpi, VP9_COMMON *cm, |
| 44 SPEED_FEATURES *sf, int speed) { |
| 45 sf->adaptive_rd_thresh = 1; |
| 46 sf->recode_loop = (speed < 1) ? ALLOW_RECODE : ALLOW_RECODE_KFMAXBW; |
| 47 sf->allow_skip_recode = 1; |
| 48 |
| 49 if (speed >= 1) { |
| 50 sf->use_square_partition_only = !frame_is_intra_only(cm); |
| 51 sf->less_rectangular_check = 1; |
| 52 sf->tx_size_search_method = vp9_frame_is_boosted(cpi) ? USE_FULL_RD |
| 53 : USE_LARGESTALL; |
| 54 |
| 55 if (MIN(cm->width, cm->height) >= 720) |
| 56 sf->disable_split_mask = cm->show_frame ? DISABLE_ALL_SPLIT |
| 57 : DISABLE_ALL_INTER_SPLIT; |
| 58 else |
| 59 sf->disable_split_mask = DISABLE_COMPOUND_SPLIT; |
| 60 sf->use_rd_breakout = 1; |
| 61 sf->adaptive_motion_search = 1; |
| 62 sf->auto_mv_step_size = 1; |
| 63 sf->adaptive_rd_thresh = 2; |
| 64 sf->subpel_iters_per_step = 1; |
| 65 sf->mode_skip_start = 10; |
| 66 sf->adaptive_pred_interp_filter = 1; |
| 67 |
| 68 sf->recode_loop = ALLOW_RECODE_KFARFGF; |
| 69 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V; |
| 70 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V; |
| 71 sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V; |
| 72 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V; |
| 73 } |
| 74 |
| 75 if (speed >= 2) { |
| 76 sf->tx_size_search_method = vp9_frame_is_boosted(cpi) ? USE_FULL_RD |
| 77 : USE_LARGESTALL; |
| 78 |
| 79 if (MIN(cm->width, cm->height) >= 720) |
| 80 sf->disable_split_mask = cm->show_frame ? DISABLE_ALL_SPLIT |
| 81 : DISABLE_ALL_INTER_SPLIT; |
| 82 else |
| 83 sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY; |
| 84 |
| 85 sf->adaptive_pred_interp_filter = 2; |
| 86 sf->reference_masking = 1; |
| 87 sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH | |
| 88 FLAG_SKIP_INTRA_BESTINTER | |
| 89 FLAG_SKIP_COMP_BESTINTRA | |
| 90 FLAG_SKIP_INTRA_LOWVAR; |
| 91 sf->disable_filter_search_var_thresh = 100; |
| 92 sf->comp_inter_joint_search_thresh = BLOCK_SIZES; |
| 93 sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX; |
| 94 sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_LOW_MOTION; |
| 95 sf->adjust_partitioning_from_last_frame = 1; |
| 96 sf->last_partitioning_redo_frequency = 3; |
| 97 } |
| 98 |
| 99 if (speed >= 3) { |
| 100 if (MIN(cm->width, cm->height) >= 720) |
| 101 sf->disable_split_mask = DISABLE_ALL_SPLIT; |
| 102 else |
| 103 sf->disable_split_mask = DISABLE_ALL_INTER_SPLIT; |
| 104 |
| 105 sf->recode_loop = ALLOW_RECODE_KFMAXBW; |
| 106 sf->adaptive_rd_thresh = 3; |
| 107 sf->mode_skip_start = 6; |
| 108 sf->use_fast_coef_updates = ONE_LOOP_REDUCED; |
| 109 sf->use_fast_coef_costing = 1; |
| 110 } |
| 111 |
| 112 if (speed >= 4) { |
| 113 sf->use_square_partition_only = 1; |
| 114 sf->tx_size_search_method = USE_LARGESTALL; |
| 115 sf->disable_split_mask = DISABLE_ALL_SPLIT; |
| 116 sf->adaptive_rd_thresh = 4; |
| 117 sf->mode_search_skip_flags |= FLAG_SKIP_COMP_REFMISMATCH | |
| 118 FLAG_EARLY_TERMINATE; |
| 119 sf->disable_filter_search_var_thresh = 200; |
| 120 sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_ALL; |
| 121 sf->use_lp32x32fdct = 1; |
| 122 } |
| 123 |
| 124 if (speed >= 5) { |
| 125 int i; |
| 126 |
| 127 sf->partition_search_type = FIXED_PARTITION; |
| 128 sf->optimize_coefficients = 0; |
| 129 sf->search_method = HEX; |
| 130 sf->disable_filter_search_var_thresh = 500; |
| 131 for (i = 0; i < TX_SIZES; ++i) { |
| 132 sf->intra_y_mode_mask[i] = INTRA_DC_ONLY; |
| 133 sf->intra_uv_mode_mask[i] = INTRA_DC_ONLY; |
| 134 } |
| 135 cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED; |
| 136 } |
| 137 } |
| 138 |
| 139 static void set_rt_speed_feature(VP9_COMMON *cm, SPEED_FEATURES *sf, |
| 140 int speed) { |
| 141 sf->static_segmentation = 0; |
| 142 sf->adaptive_rd_thresh = 1; |
| 143 sf->encode_breakout_thresh = 1; |
| 144 sf->use_fast_coef_costing = 1; |
| 145 |
| 146 if (speed == 1) { |
| 147 sf->use_square_partition_only = !frame_is_intra_only(cm); |
| 148 sf->less_rectangular_check = 1; |
| 149 sf->tx_size_search_method = frame_is_intra_only(cm) ? USE_FULL_RD |
| 150 : USE_LARGESTALL; |
| 151 |
| 152 if (MIN(cm->width, cm->height) >= 720) |
| 153 sf->disable_split_mask = cm->show_frame ? DISABLE_ALL_SPLIT |
| 154 : DISABLE_ALL_INTER_SPLIT; |
| 155 else |
| 156 sf->disable_split_mask = DISABLE_COMPOUND_SPLIT; |
| 157 |
| 158 sf->use_rd_breakout = 1; |
| 159 sf->adaptive_motion_search = 1; |
| 160 sf->adaptive_pred_interp_filter = 1; |
| 161 sf->auto_mv_step_size = 1; |
| 162 sf->adaptive_rd_thresh = 2; |
| 163 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V; |
| 164 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V; |
| 165 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V; |
| 166 sf->encode_breakout_thresh = 8; |
| 167 } |
| 168 |
| 169 if (speed >= 2) { |
| 170 sf->use_square_partition_only = !frame_is_intra_only(cm); |
| 171 sf->less_rectangular_check = 1; |
| 172 sf->tx_size_search_method = frame_is_intra_only(cm) ? USE_FULL_RD |
| 173 : USE_LARGESTALL; |
| 174 if (MIN(cm->width, cm->height) >= 720) |
| 175 sf->disable_split_mask = cm->show_frame ? |
| 176 DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT; |
| 177 else |
| 178 sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY; |
| 179 |
| 180 sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH | |
| 181 FLAG_SKIP_INTRA_BESTINTER | |
| 182 FLAG_SKIP_COMP_BESTINTRA | |
| 183 FLAG_SKIP_INTRA_LOWVAR; |
| 184 sf->use_rd_breakout = 1; |
| 185 sf->adaptive_motion_search = 1; |
| 186 sf->adaptive_pred_interp_filter = 2; |
| 187 sf->auto_mv_step_size = 1; |
| 188 sf->reference_masking = 1; |
| 189 |
| 190 sf->disable_filter_search_var_thresh = 50; |
| 191 sf->comp_inter_joint_search_thresh = BLOCK_SIZES; |
| 192 |
| 193 sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX; |
| 194 sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_LOW_MOTION; |
| 195 sf->adjust_partitioning_from_last_frame = 1; |
| 196 sf->last_partitioning_redo_frequency = 3; |
| 197 |
| 198 sf->adaptive_rd_thresh = 2; |
| 199 sf->use_lp32x32fdct = 1; |
| 200 sf->mode_skip_start = 11; |
| 201 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V; |
| 202 sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V; |
| 203 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V; |
| 204 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V; |
| 205 sf->encode_breakout_thresh = 200; |
| 206 } |
| 207 |
| 208 if (speed >= 3) { |
| 209 sf->use_square_partition_only = 1; |
| 210 sf->disable_filter_search_var_thresh = 100; |
| 211 sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_ALL; |
| 212 sf->constrain_copy_partition = 1; |
| 213 sf->use_uv_intra_rd_estimate = 1; |
| 214 sf->skip_encode_sb = 1; |
| 215 sf->subpel_iters_per_step = 1; |
| 216 sf->use_fast_coef_updates = ONE_LOOP_REDUCED; |
| 217 sf->adaptive_rd_thresh = 4; |
| 218 sf->mode_skip_start = 6; |
| 219 sf->allow_skip_recode = 0; |
| 220 sf->optimize_coefficients = 0; |
| 221 sf->disable_split_mask = DISABLE_ALL_SPLIT; |
| 222 sf->lpf_pick = LPF_PICK_FROM_Q; |
| 223 sf->encode_breakout_thresh = 700; |
| 224 } |
| 225 |
| 226 if (speed >= 4) { |
| 227 int i; |
| 228 sf->last_partitioning_redo_frequency = 4; |
| 229 sf->adaptive_rd_thresh = 5; |
| 230 sf->use_fast_coef_costing = 0; |
| 231 sf->auto_min_max_partition_size = STRICT_NEIGHBORING_MIN_MAX; |
| 232 sf->adjust_partitioning_from_last_frame = |
| 233 cm->last_frame_type != cm->frame_type || (0 == |
| 234 (cm->current_video_frame + 1) % sf->last_partitioning_redo_frequency); |
| 235 sf->subpel_force_stop = 1; |
| 236 for (i = 0; i < TX_SIZES; i++) { |
| 237 sf->intra_y_mode_mask[i] = INTRA_DC_H_V; |
| 238 sf->intra_uv_mode_mask[i] = INTRA_DC_ONLY; |
| 239 } |
| 240 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_ONLY; |
| 241 sf->frame_parameter_update = 0; |
| 242 sf->encode_breakout_thresh = 1000; |
| 243 sf->search_method = FAST_HEX; |
| 244 sf->disable_inter_mode_mask[BLOCK_32X32] = 1 << INTER_OFFSET(ZEROMV); |
| 245 sf->disable_inter_mode_mask[BLOCK_32X64] = ~(1 << INTER_OFFSET(NEARESTMV)); |
| 246 sf->disable_inter_mode_mask[BLOCK_64X32] = ~(1 << INTER_OFFSET(NEARESTMV)); |
| 247 sf->disable_inter_mode_mask[BLOCK_64X64] = ~(1 << INTER_OFFSET(NEARESTMV)); |
| 248 sf->max_intra_bsize = BLOCK_32X32; |
| 249 sf->allow_skip_recode = 1; |
| 250 } |
| 251 |
| 252 if (speed >= 5) { |
| 253 sf->max_partition_size = BLOCK_32X32; |
| 254 sf->min_partition_size = BLOCK_8X8; |
| 255 sf->partition_check = |
| 256 (cm->current_video_frame % sf->last_partitioning_redo_frequency == 1); |
| 257 sf->force_frame_boost = cm->frame_type == KEY_FRAME || |
| 258 (cm->current_video_frame % |
| 259 (sf->last_partitioning_redo_frequency << 1) == 1); |
| 260 sf->max_delta_qindex = (cm->frame_type == KEY_FRAME) ? 20 : 15; |
| 261 sf->partition_search_type = REFERENCE_PARTITION; |
| 262 sf->use_nonrd_pick_mode = 1; |
| 263 sf->search_method = FAST_DIAMOND; |
| 264 sf->allow_skip_recode = 0; |
| 265 } |
| 266 |
| 267 if (speed >= 6) { |
| 268 // Adaptively switch between SOURCE_VAR_BASED_PARTITION and FIXED_PARTITION. |
| 269 sf->partition_search_type = SOURCE_VAR_BASED_PARTITION; |
| 270 sf->search_type_check_frequency = 50; |
| 271 sf->source_var_thresh = 360; |
| 272 } |
| 273 |
| 274 if (speed >= 7) { |
| 275 int i; |
| 276 for (i = 0; i < BLOCK_SIZES; ++i) |
| 277 sf->disable_inter_mode_mask[i] = ~(1 << INTER_OFFSET(NEARESTMV)); |
| 278 } |
| 279 } |
| 280 |
| 281 void vp9_set_speed_features(VP9_COMP *cpi) { |
| 282 SPEED_FEATURES *const sf = &cpi->sf; |
| 283 VP9_COMMON *const cm = &cpi->common; |
| 284 const VP9_CONFIG *const oxcf = &cpi->oxcf; |
| 285 const int speed = cpi->speed < 0 ? -cpi->speed : cpi->speed; |
| 286 int i; |
| 287 |
| 288 // best quality defaults |
| 289 sf->frame_parameter_update = 1; |
| 290 sf->search_method = NSTEP; |
| 291 sf->recode_loop = ALLOW_RECODE; |
| 292 sf->subpel_search_method = SUBPEL_TREE; |
| 293 sf->subpel_iters_per_step = 2; |
| 294 sf->subpel_force_stop = 0; |
| 295 sf->optimize_coefficients = !oxcf->lossless; |
| 296 sf->reduce_first_step_size = 0; |
| 297 sf->auto_mv_step_size = 0; |
| 298 sf->max_step_search_steps = MAX_MVSEARCH_STEPS; |
| 299 sf->comp_inter_joint_search_thresh = BLOCK_4X4; |
| 300 sf->adaptive_rd_thresh = 0; |
| 301 sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_OFF; |
| 302 sf->tx_size_search_method = USE_FULL_RD; |
| 303 sf->use_lp32x32fdct = 0; |
| 304 sf->adaptive_motion_search = 0; |
| 305 sf->adaptive_pred_interp_filter = 0; |
| 306 sf->reference_masking = 0; |
| 307 sf->partition_search_type = SEARCH_PARTITION; |
| 308 sf->less_rectangular_check = 0; |
| 309 sf->use_square_partition_only = 0; |
| 310 sf->auto_min_max_partition_size = NOT_IN_USE; |
| 311 sf->max_partition_size = BLOCK_64X64; |
| 312 sf->min_partition_size = BLOCK_4X4; |
| 313 sf->adjust_partitioning_from_last_frame = 0; |
| 314 sf->last_partitioning_redo_frequency = 4; |
| 315 sf->constrain_copy_partition = 0; |
| 316 sf->disable_split_mask = 0; |
| 317 sf->mode_search_skip_flags = 0; |
| 318 sf->force_frame_boost = 0; |
| 319 sf->max_delta_qindex = 0; |
| 320 sf->disable_split_var_thresh = 0; |
| 321 sf->disable_filter_search_var_thresh = 0; |
| 322 for (i = 0; i < TX_SIZES; i++) { |
| 323 sf->intra_y_mode_mask[i] = ALL_INTRA_MODES; |
| 324 sf->intra_uv_mode_mask[i] = ALL_INTRA_MODES; |
| 325 } |
| 326 sf->use_rd_breakout = 0; |
| 327 sf->skip_encode_sb = 0; |
| 328 sf->use_uv_intra_rd_estimate = 0; |
| 329 sf->allow_skip_recode = 0; |
| 330 sf->lpf_pick = LPF_PICK_FROM_FULL_IMAGE; |
| 331 sf->use_fast_coef_updates = TWO_LOOP; |
| 332 sf->use_fast_coef_costing = 0; |
| 333 sf->mode_skip_start = MAX_MODES; // Mode index at which mode skip mask set |
| 334 sf->use_nonrd_pick_mode = 0; |
| 335 sf->encode_breakout_thresh = 0; |
| 336 for (i = 0; i < BLOCK_SIZES; ++i) |
| 337 sf->disable_inter_mode_mask[i] = 0; |
| 338 sf->max_intra_bsize = BLOCK_64X64; |
| 339 // This setting only takes effect when partition_search_type is set |
| 340 // to FIXED_PARTITION. |
| 341 sf->always_this_block_size = BLOCK_16X16; |
| 342 sf->search_type_check_frequency = 50; |
| 343 sf->source_var_thresh = 100; |
| 344 |
| 345 // Recode loop tolerence %. |
| 346 sf->recode_tolerance = 25; |
| 347 |
| 348 switch (oxcf->mode) { |
| 349 case MODE_BESTQUALITY: |
| 350 case MODE_SECONDPASS_BEST: // This is the best quality mode. |
| 351 cpi->diamond_search_sad = vp9_full_range_search; |
| 352 break; |
| 353 case MODE_FIRSTPASS: |
| 354 case MODE_GOODQUALITY: |
| 355 case MODE_SECONDPASS: |
| 356 set_good_speed_feature(cpi, cm, sf, speed); |
| 357 break; |
| 358 case MODE_REALTIME: |
| 359 set_rt_speed_feature(cm, sf, speed); |
| 360 break; |
| 361 } |
| 362 |
| 363 // Slow quant, dct and trellis not worthwhile for first pass |
| 364 // so make sure they are always turned off. |
| 365 if (cpi->pass == 1) |
| 366 sf->optimize_coefficients = 0; |
| 367 |
| 368 // No recode for 1 pass. |
| 369 if (cpi->pass == 0) { |
| 370 sf->recode_loop = DISALLOW_RECODE; |
| 371 sf->optimize_coefficients = 0; |
| 372 } |
| 373 |
| 374 if (sf->subpel_search_method == SUBPEL_TREE) { |
| 375 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree; |
| 376 cpi->find_fractional_mv_step_comp = vp9_find_best_sub_pixel_comp_tree; |
| 377 } |
| 378 |
| 379 cpi->mb.optimize = sf->optimize_coefficients == 1 && cpi->pass != 1; |
| 380 |
| 381 if (cpi->encode_breakout && oxcf->mode == MODE_REALTIME && |
| 382 sf->encode_breakout_thresh > cpi->encode_breakout) |
| 383 cpi->encode_breakout = sf->encode_breakout_thresh; |
| 384 |
| 385 if (sf->disable_split_mask == DISABLE_ALL_SPLIT) |
| 386 sf->adaptive_pred_interp_filter = 0; |
| 387 |
| 388 if (!cpi->oxcf.frame_periodic_boost) { |
| 389 sf->max_delta_qindex = 0; |
| 390 } |
| 391 } |
OLD | NEW |