]> granicus.if.org Git - libvpx/blob - vp10/encoder/speed_features.c
b3ae6871eabb2742556d931e740aa5fb5728db7e
[libvpx] / vp10 / encoder / speed_features.c
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 "vp10/encoder/encoder.h"
14 #include "vp10/encoder/speed_features.h"
15 #include "vp10/encoder/rdopt.h"
16
17
18 // Intra only frames, golden frames (except alt ref overlays) and
19 // alt ref frames tend to be coded at a higher than ambient quality
20 static int frame_is_boosted(const VP9_COMP *cpi) {
21   return frame_is_kf_gf_arf(cpi) || vp10_is_upper_layer_key_frame(cpi);
22 }
23
24 // Sets a partition size down to which the auto partition code will always
25 // search (can go lower), based on the image dimensions. The logic here
26 // is that the extent to which ringing artefacts are offensive, depends
27 // partly on the screen area that over which they propogate. Propogation is
28 // limited by transform block size but the screen area take up by a given block
29 // size will be larger for a small image format stretched to full screen.
30 static BLOCK_SIZE set_partition_min_limit(VP10_COMMON *const cm) {
31   unsigned int screen_area = (cm->width * cm->height);
32
33   // Select block size based on image format size.
34   if (screen_area < 1280 * 720) {
35     // Formats smaller in area than 720P
36     return BLOCK_4X4;
37   } else if (screen_area < 1920 * 1080) {
38     // Format >= 720P and < 1080P
39     return BLOCK_8X8;
40   } else {
41     // Formats 1080P and up
42     return BLOCK_16X16;
43   }
44 }
45
46 static void set_good_speed_feature_framesize_dependent(VP9_COMP *cpi,
47                                                        SPEED_FEATURES *sf,
48                                                        int speed) {
49   VP10_COMMON *const cm = &cpi->common;
50
51   if (speed >= 1) {
52     if (MIN(cm->width, cm->height) >= 720) {
53       sf->disable_split_mask = cm->show_frame ? DISABLE_ALL_SPLIT
54                                               : DISABLE_ALL_INTER_SPLIT;
55       sf->partition_search_breakout_dist_thr = (1 << 23);
56     } else {
57       sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
58       sf->partition_search_breakout_dist_thr = (1 << 21);
59     }
60   }
61
62   if (speed >= 2) {
63     if (MIN(cm->width, cm->height) >= 720) {
64       sf->disable_split_mask = cm->show_frame ? DISABLE_ALL_SPLIT
65                                               : DISABLE_ALL_INTER_SPLIT;
66       sf->adaptive_pred_interp_filter = 0;
67       sf->partition_search_breakout_dist_thr = (1 << 24);
68       sf->partition_search_breakout_rate_thr = 120;
69     } else {
70       sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY;
71       sf->partition_search_breakout_dist_thr = (1 << 22);
72       sf->partition_search_breakout_rate_thr = 100;
73     }
74     sf->rd_auto_partition_min_limit = set_partition_min_limit(cm);
75   }
76
77   if (speed >= 3) {
78     if (MIN(cm->width, cm->height) >= 720) {
79       sf->disable_split_mask = DISABLE_ALL_SPLIT;
80       sf->schedule_mode_search = cm->base_qindex < 220 ? 1 : 0;
81       sf->partition_search_breakout_dist_thr = (1 << 25);
82       sf->partition_search_breakout_rate_thr = 200;
83     } else {
84       sf->max_intra_bsize = BLOCK_32X32;
85       sf->disable_split_mask = DISABLE_ALL_INTER_SPLIT;
86       sf->schedule_mode_search = cm->base_qindex < 175 ? 1 : 0;
87       sf->partition_search_breakout_dist_thr = (1 << 23);
88       sf->partition_search_breakout_rate_thr = 120;
89     }
90   }
91
92   // If this is a two pass clip that fits the criteria for animated or
93   // graphics content then reset disable_split_mask for speeds 1-4.
94   // Also if the image edge is internal to the coded area.
95   if ((speed >= 1) && (cpi->oxcf.pass == 2) &&
96       ((cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ||
97        (vp10_internal_image_edge(cpi)))) {
98     sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
99   }
100
101   if (speed >= 4) {
102     if (MIN(cm->width, cm->height) >= 720) {
103       sf->partition_search_breakout_dist_thr = (1 << 26);
104     } else {
105       sf->partition_search_breakout_dist_thr = (1 << 24);
106     }
107     sf->disable_split_mask = DISABLE_ALL_SPLIT;
108   }
109 }
110
111 static void set_good_speed_feature(VP9_COMP *cpi, VP10_COMMON *cm,
112                                    SPEED_FEATURES *sf, int speed) {
113   const int boosted = frame_is_boosted(cpi);
114
115   sf->adaptive_rd_thresh = 1;
116   sf->allow_skip_recode = 1;
117
118   if (speed >= 1) {
119     if ((cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ||
120         vp10_internal_image_edge(cpi)) {
121       sf->use_square_partition_only = !frame_is_boosted(cpi);
122     } else {
123       sf->use_square_partition_only = !frame_is_intra_only(cm);
124     }
125
126     sf->less_rectangular_check  = 1;
127
128     sf->use_rd_breakout = 1;
129     sf->adaptive_motion_search = 1;
130     sf->mv.auto_mv_step_size = 1;
131     sf->adaptive_rd_thresh = 2;
132     sf->mv.subpel_iters_per_step = 1;
133     sf->mode_skip_start = 10;
134     sf->adaptive_pred_interp_filter = 1;
135
136     sf->recode_loop = ALLOW_RECODE_KFARFGF;
137     sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
138     sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
139     sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
140     sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
141
142     sf->tx_size_search_breakout = 1;
143     sf->partition_search_breakout_rate_thr = 80;
144   }
145
146   if (speed >= 2) {
147     sf->tx_size_search_method = frame_is_boosted(cpi) ? USE_FULL_RD
148                                                       : USE_LARGESTALL;
149
150     // Reference masking is not supported in dynamic scaling mode.
151     sf->reference_masking = cpi->oxcf.resize_mode != RESIZE_DYNAMIC ? 1 : 0;
152
153     sf->mode_search_skip_flags = (cm->frame_type == KEY_FRAME) ? 0 :
154                                  FLAG_SKIP_INTRA_DIRMISMATCH |
155                                  FLAG_SKIP_INTRA_BESTINTER |
156                                  FLAG_SKIP_COMP_BESTINTRA |
157                                  FLAG_SKIP_INTRA_LOWVAR;
158     sf->disable_filter_search_var_thresh = 100;
159     sf->comp_inter_joint_search_thresh = BLOCK_SIZES;
160     sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
161     sf->allow_partition_search_skip = 1;
162   }
163
164   if (speed >= 3) {
165     sf->use_square_partition_only = !frame_is_intra_only(cm);
166     sf->tx_size_search_method = frame_is_intra_only(cm) ? USE_FULL_RD
167                                                         : USE_LARGESTALL;
168     sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED;
169     sf->adaptive_pred_interp_filter = 0;
170     sf->adaptive_mode_search = 1;
171     sf->cb_partition_search = !boosted;
172     sf->cb_pred_filter_search = 1;
173     sf->alt_ref_search_fp = 1;
174     sf->recode_loop = ALLOW_RECODE_KFMAXBW;
175     sf->adaptive_rd_thresh = 3;
176     sf->mode_skip_start = 6;
177     sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
178     sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC;
179     sf->adaptive_interp_filter_search = 1;
180   }
181
182   if (speed >= 4) {
183     sf->use_square_partition_only = 1;
184     sf->tx_size_search_method = USE_LARGESTALL;
185     sf->mv.search_method = BIGDIA;
186     sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
187     sf->adaptive_rd_thresh = 4;
188     if (cm->frame_type != KEY_FRAME)
189       sf->mode_search_skip_flags |= FLAG_EARLY_TERMINATE;
190     sf->disable_filter_search_var_thresh = 200;
191     sf->use_lp32x32fdct = 1;
192     sf->use_fast_coef_updates = ONE_LOOP_REDUCED;
193     sf->use_fast_coef_costing = 1;
194     sf->motion_field_mode_search = !boosted;
195     sf->partition_search_breakout_rate_thr = 300;
196   }
197
198   if (speed >= 5) {
199     int i;
200     sf->optimize_coefficients = 0;
201     sf->mv.search_method = HEX;
202     sf->disable_filter_search_var_thresh = 500;
203     for (i = 0; i < TX_SIZES; ++i) {
204       sf->intra_y_mode_mask[i] = INTRA_DC;
205       sf->intra_uv_mode_mask[i] = INTRA_DC;
206     }
207     sf->partition_search_breakout_rate_thr = 500;
208     sf->mv.reduce_first_step_size = 1;
209     sf->simple_model_rd_from_var = 1;
210   }
211 }
212
213 static void set_rt_speed_feature_framesize_dependent(VP9_COMP *cpi,
214     SPEED_FEATURES *sf, int speed) {
215   VP10_COMMON *const cm = &cpi->common;
216
217   if (speed >= 1) {
218     if (MIN(cm->width, cm->height) >= 720) {
219       sf->disable_split_mask = cm->show_frame ? DISABLE_ALL_SPLIT
220                                               : DISABLE_ALL_INTER_SPLIT;
221     } else {
222       sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
223     }
224   }
225
226   if (speed >= 2) {
227     if (MIN(cm->width, cm->height) >= 720) {
228       sf->disable_split_mask = cm->show_frame ? DISABLE_ALL_SPLIT
229                                               : DISABLE_ALL_INTER_SPLIT;
230     } else {
231       sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY;
232     }
233   }
234
235   if (speed >= 5) {
236     if (MIN(cm->width, cm->height) >= 720) {
237       sf->partition_search_breakout_dist_thr = (1 << 25);
238     } else {
239       sf->partition_search_breakout_dist_thr = (1 << 23);
240     }
241   }
242
243   if (speed >= 7) {
244     sf->encode_breakout_thresh = (MIN(cm->width, cm->height) >= 720) ?
245         800 : 300;
246   }
247 }
248
249 static void set_rt_speed_feature(VP9_COMP *cpi, SPEED_FEATURES *sf,
250                                  int speed, vp9e_tune_content content) {
251   VP10_COMMON *const cm = &cpi->common;
252   const int is_keyframe = cm->frame_type == KEY_FRAME;
253   const int frames_since_key = is_keyframe ? 0 : cpi->rc.frames_since_key;
254   sf->static_segmentation = 0;
255   sf->adaptive_rd_thresh = 1;
256   sf->use_fast_coef_costing = 1;
257
258   if (speed >= 1) {
259     sf->use_square_partition_only = !frame_is_intra_only(cm);
260     sf->less_rectangular_check = 1;
261     sf->tx_size_search_method = frame_is_intra_only(cm) ? USE_FULL_RD
262                                                         : USE_LARGESTALL;
263
264     sf->use_rd_breakout = 1;
265
266     sf->adaptive_motion_search = 1;
267     sf->adaptive_pred_interp_filter = 1;
268     sf->mv.auto_mv_step_size = 1;
269     sf->adaptive_rd_thresh = 2;
270     sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
271     sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
272     sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
273   }
274
275   if (speed >= 2) {
276     sf->mode_search_skip_flags = (cm->frame_type == KEY_FRAME) ? 0 :
277                                  FLAG_SKIP_INTRA_DIRMISMATCH |
278                                  FLAG_SKIP_INTRA_BESTINTER |
279                                  FLAG_SKIP_COMP_BESTINTRA |
280                                  FLAG_SKIP_INTRA_LOWVAR;
281     sf->adaptive_pred_interp_filter = 2;
282
283     // Disable reference masking if using spatial scaling since
284     // pred_mv_sad will not be set (since vp10_mv_pred will not
285     // be called).
286     // TODO(marpan/agrange): Fix this condition.
287     sf->reference_masking = (cpi->oxcf.resize_mode != RESIZE_DYNAMIC &&
288                              cpi->svc.number_spatial_layers == 1) ? 1 : 0;
289
290     sf->disable_filter_search_var_thresh = 50;
291     sf->comp_inter_joint_search_thresh = BLOCK_SIZES;
292     sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
293     sf->lf_motion_threshold = LOW_MOTION_THRESHOLD;
294     sf->adjust_partitioning_from_last_frame = 1;
295     sf->last_partitioning_redo_frequency = 3;
296     sf->use_lp32x32fdct = 1;
297     sf->mode_skip_start = 11;
298     sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
299   }
300
301   if (speed >= 3) {
302     sf->use_square_partition_only = 1;
303     sf->disable_filter_search_var_thresh = 100;
304     sf->use_uv_intra_rd_estimate = 1;
305     sf->skip_encode_sb = 1;
306     sf->mv.subpel_iters_per_step = 1;
307     sf->adaptive_rd_thresh = 4;
308     sf->mode_skip_start = 6;
309     sf->allow_skip_recode = 0;
310     sf->optimize_coefficients = 0;
311     sf->disable_split_mask = DISABLE_ALL_SPLIT;
312     sf->lpf_pick = LPF_PICK_FROM_Q;
313   }
314
315   if (speed >= 4) {
316     int i;
317     sf->last_partitioning_redo_frequency = 4;
318     sf->adaptive_rd_thresh = 5;
319     sf->use_fast_coef_costing = 0;
320     sf->auto_min_max_partition_size = STRICT_NEIGHBORING_MIN_MAX;
321     sf->adjust_partitioning_from_last_frame =
322         cm->last_frame_type != cm->frame_type || (0 ==
323         (frames_since_key + 1) % sf->last_partitioning_redo_frequency);
324     sf->mv.subpel_force_stop = 1;
325     for (i = 0; i < TX_SIZES; i++) {
326       sf->intra_y_mode_mask[i] = INTRA_DC_H_V;
327       sf->intra_uv_mode_mask[i] = INTRA_DC;
328     }
329     sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
330     sf->frame_parameter_update = 0;
331     sf->mv.search_method = FAST_HEX;
332
333     sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEAR_NEW;
334     sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST;
335     sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST;
336     sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST;
337     sf->max_intra_bsize = BLOCK_32X32;
338     sf->allow_skip_recode = 1;
339   }
340
341   if (speed >= 5) {
342     sf->use_quant_fp = !is_keyframe;
343     sf->auto_min_max_partition_size = is_keyframe ? RELAXED_NEIGHBORING_MIN_MAX
344                                                   : STRICT_NEIGHBORING_MIN_MAX;
345     sf->default_max_partition_size = BLOCK_32X32;
346     sf->default_min_partition_size = BLOCK_8X8;
347     sf->force_frame_boost = is_keyframe ||
348         (frames_since_key % (sf->last_partitioning_redo_frequency << 1) == 1);
349     sf->max_delta_qindex = is_keyframe ? 20 : 15;
350     sf->partition_search_type = REFERENCE_PARTITION;
351     sf->use_nonrd_pick_mode = 1;
352     sf->allow_skip_recode = 0;
353     sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEW_ZERO;
354     sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST_NEW_ZERO;
355     sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST_NEW_ZERO;
356     sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST_NEW_ZERO;
357     sf->adaptive_rd_thresh = 2;
358     // This feature is only enabled when partition search is disabled.
359     sf->reuse_inter_pred_sby = 1;
360     sf->partition_search_breakout_rate_thr = 200;
361     sf->coeff_prob_appx_step = 4;
362     sf->use_fast_coef_updates = is_keyframe ? TWO_LOOP : ONE_LOOP_REDUCED;
363     sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH;
364     sf->tx_size_search_method = is_keyframe ? USE_LARGESTALL : USE_TX_8X8;
365     sf->simple_model_rd_from_var = 1;
366
367     if (!is_keyframe) {
368       int i;
369       if (content == VP9E_CONTENT_SCREEN) {
370         for (i = 0; i < BLOCK_SIZES; ++i)
371           sf->intra_y_mode_bsize_mask[i] = INTRA_DC_TM_H_V;
372       } else {
373         for (i = 0; i < BLOCK_SIZES; ++i)
374           if (i >= BLOCK_16X16)
375             sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
376           else
377             // Use H and V intra mode for block sizes <= 16X16.
378             sf->intra_y_mode_bsize_mask[i] = INTRA_DC_H_V;
379       }
380     }
381   }
382
383   if (speed >= 6) {
384     // Adaptively switch between SOURCE_VAR_BASED_PARTITION and FIXED_PARTITION.
385     sf->partition_search_type = VAR_BASED_PARTITION;
386     // Turn on this to use non-RD key frame coding mode.
387     sf->use_nonrd_pick_mode = 1;
388     sf->mv.search_method = NSTEP;
389     sf->mv.reduce_first_step_size = 1;
390     sf->skip_encode_sb = 0;
391   }
392
393   if (speed >= 7) {
394     sf->adaptive_rd_thresh = 3;
395     sf->mv.search_method = FAST_DIAMOND;
396     sf->mv.fullpel_search_step_param = 10;
397   }
398   if (speed >= 8) {
399     sf->adaptive_rd_thresh = 4;
400     sf->mv.subpel_force_stop = 2;
401     sf->lpf_pick = LPF_PICK_MINIMAL_LPF;
402   }
403 }
404
405 void vp10_set_speed_features_framesize_dependent(VP9_COMP *cpi) {
406   SPEED_FEATURES *const sf = &cpi->sf;
407   const VP9EncoderConfig *const oxcf = &cpi->oxcf;
408   RD_OPT *const rd = &cpi->rd;
409   int i;
410
411   if (oxcf->mode == REALTIME) {
412     set_rt_speed_feature_framesize_dependent(cpi, sf, oxcf->speed);
413   } else if (oxcf->mode == GOOD) {
414     set_good_speed_feature_framesize_dependent(cpi, sf, oxcf->speed);
415   }
416
417   if (sf->disable_split_mask == DISABLE_ALL_SPLIT) {
418     sf->adaptive_pred_interp_filter = 0;
419   }
420
421   if (cpi->encode_breakout && oxcf->mode == REALTIME &&
422       sf->encode_breakout_thresh > cpi->encode_breakout) {
423     cpi->encode_breakout = sf->encode_breakout_thresh;
424   }
425
426   // Check for masked out split cases.
427   for (i = 0; i < MAX_REFS; ++i) {
428     if (sf->disable_split_mask & (1 << i)) {
429       rd->thresh_mult_sub8x8[i] = INT_MAX;
430     }
431   }
432 }
433
434 void vp10_set_speed_features_framesize_independent(VP9_COMP *cpi) {
435   SPEED_FEATURES *const sf = &cpi->sf;
436   VP10_COMMON *const cm = &cpi->common;
437   MACROBLOCK *const x = &cpi->td.mb;
438   const VP9EncoderConfig *const oxcf = &cpi->oxcf;
439   int i;
440
441   // best quality defaults
442   sf->frame_parameter_update = 1;
443   sf->mv.search_method = NSTEP;
444   sf->recode_loop = ALLOW_RECODE;
445   sf->mv.subpel_search_method = SUBPEL_TREE;
446   sf->mv.subpel_iters_per_step = 2;
447   sf->mv.subpel_force_stop = 0;
448   sf->optimize_coefficients = !is_lossless_requested(&cpi->oxcf);
449   sf->mv.reduce_first_step_size = 0;
450   sf->coeff_prob_appx_step = 1;
451   sf->mv.auto_mv_step_size = 0;
452   sf->mv.fullpel_search_step_param = 6;
453   sf->comp_inter_joint_search_thresh = BLOCK_4X4;
454   sf->adaptive_rd_thresh = 0;
455   sf->tx_size_search_method = USE_FULL_RD;
456   sf->use_lp32x32fdct = 0;
457   sf->adaptive_motion_search = 0;
458   sf->adaptive_pred_interp_filter = 0;
459   sf->adaptive_mode_search = 0;
460   sf->cb_pred_filter_search = 0;
461   sf->cb_partition_search = 0;
462   sf->motion_field_mode_search = 0;
463   sf->alt_ref_search_fp = 0;
464   sf->use_quant_fp = 0;
465   sf->reference_masking = 0;
466   sf->partition_search_type = SEARCH_PARTITION;
467   sf->less_rectangular_check = 0;
468   sf->use_square_partition_only = 0;
469   sf->auto_min_max_partition_size = NOT_IN_USE;
470   sf->rd_auto_partition_min_limit = BLOCK_4X4;
471   sf->default_max_partition_size = BLOCK_64X64;
472   sf->default_min_partition_size = BLOCK_4X4;
473   sf->adjust_partitioning_from_last_frame = 0;
474   sf->last_partitioning_redo_frequency = 4;
475   sf->disable_split_mask = 0;
476   sf->mode_search_skip_flags = 0;
477   sf->force_frame_boost = 0;
478   sf->max_delta_qindex = 0;
479   sf->disable_filter_search_var_thresh = 0;
480   sf->adaptive_interp_filter_search = 0;
481   sf->allow_partition_search_skip = 0;
482
483   for (i = 0; i < TX_SIZES; i++) {
484     sf->intra_y_mode_mask[i] = INTRA_ALL;
485     sf->intra_uv_mode_mask[i] = INTRA_ALL;
486   }
487   sf->use_rd_breakout = 0;
488   sf->skip_encode_sb = 0;
489   sf->use_uv_intra_rd_estimate = 0;
490   sf->allow_skip_recode = 0;
491   sf->lpf_pick = LPF_PICK_FROM_FULL_IMAGE;
492   sf->use_fast_coef_updates = TWO_LOOP;
493   sf->use_fast_coef_costing = 0;
494   sf->mode_skip_start = MAX_MODES;  // Mode index at which mode skip mask set
495   sf->schedule_mode_search = 0;
496   sf->use_nonrd_pick_mode = 0;
497   for (i = 0; i < BLOCK_SIZES; ++i)
498     sf->inter_mode_mask[i] = INTER_ALL;
499   sf->max_intra_bsize = BLOCK_64X64;
500   sf->reuse_inter_pred_sby = 0;
501   // This setting only takes effect when partition_search_type is set
502   // to FIXED_PARTITION.
503   sf->always_this_block_size = BLOCK_16X16;
504   sf->search_type_check_frequency = 50;
505   sf->encode_breakout_thresh = 0;
506   // Recode loop tolerance %.
507   sf->recode_tolerance = 25;
508   sf->default_interp_filter = SWITCHABLE;
509   sf->tx_size_search_breakout = 0;
510   sf->partition_search_breakout_dist_thr = 0;
511   sf->partition_search_breakout_rate_thr = 0;
512   sf->simple_model_rd_from_var = 0;
513
514   if (oxcf->mode == REALTIME)
515     set_rt_speed_feature(cpi, sf, oxcf->speed, oxcf->content);
516   else if (oxcf->mode == GOOD)
517     set_good_speed_feature(cpi, cm, sf, oxcf->speed);
518
519   cpi->full_search_sad = vp10_full_search_sad;
520   cpi->diamond_search_sad = oxcf->mode == BEST ? vp10_full_range_search
521                                                : vp10_diamond_search_sad;
522
523   // Slow quant, dct and trellis not worthwhile for first pass
524   // so make sure they are always turned off.
525   if (oxcf->pass == 1)
526     sf->optimize_coefficients = 0;
527
528   // No recode for 1 pass.
529   if (oxcf->pass == 0) {
530     sf->recode_loop = DISALLOW_RECODE;
531     sf->optimize_coefficients = 0;
532   }
533
534   if (sf->mv.subpel_search_method == SUBPEL_TREE) {
535     cpi->find_fractional_mv_step = vp10_find_best_sub_pixel_tree;
536   } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED) {
537     cpi->find_fractional_mv_step = vp10_find_best_sub_pixel_tree_pruned;
538   } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_MORE) {
539     cpi->find_fractional_mv_step = vp10_find_best_sub_pixel_tree_pruned_more;
540   } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_EVENMORE) {
541     cpi->find_fractional_mv_step = vp10_find_best_sub_pixel_tree_pruned_evenmore;
542   }
543
544   x->optimize = sf->optimize_coefficients == 1 && oxcf->pass != 1;
545
546   x->min_partition_size = sf->default_min_partition_size;
547   x->max_partition_size = sf->default_max_partition_size;
548
549   if (!cpi->oxcf.frame_periodic_boost) {
550     sf->max_delta_qindex = 0;
551   }
552 }